Skip to content

Commit

Permalink
mstarch: revised CI testing
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStarch committed Feb 27, 2020
1 parent bc4b28f commit 588b130
Show file tree
Hide file tree
Showing 16 changed files with 250 additions and 155 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
@@ -0,0 +1,4 @@
.git
**.mdxml
**/docs
**build
14 changes: 14 additions & 0 deletions mk/ci/bootstrap.bash
@@ -0,0 +1,14 @@
#!/bin/bash
####
# bootstrap.bash:
#
# ** Assumes that the user is in the F prime root directory for F prime CI **
#
# Sets up the python environment for the CI system. This will read the latest Python and ensure
# that we are ready to run all tools.
####
# Clean the repository as part of setup
echo -e "${BLUE}Cleaning Repository and Installing PIP Package${NOCOLOR}"
git clean -xdf .
pip install ./Fw/Python
pip install ./Gds[test-api-xls]
38 changes: 0 additions & 38 deletions mk/ci/cmake-based-ci.bash

This file was deleted.

25 changes: 25 additions & 0 deletions mk/ci/helpers.bash
@@ -0,0 +1,25 @@
#!/bin/bash
####
# helpers.bash:
#
# Helpers used to make the CI system a bit nicer. It defines some methods, like pretty colors for
# usage elsewhere.
####
export BLUE='\033[0;34m'
export RED='\033[0;31m'
export NOCOLOR='\033[0m' # No Color

####
# fail_and_stop:
#
# This function, when called ouside a subsehll, should print an error and stop the test. This will
# allow fairly easy test failures.
# :param message ($1): message to print to the error log
####
function fail_and_stop()
{
echo -e "${RED}---------------- ERROR ----------------" 1>&2
echo " CI Failed with error: ${1}" 1>&2
echo -e "---------------------------------------${NOCOLOR}" 1 >&2
exit 1
}
20 changes: 20 additions & 0 deletions mk/ci/master.bash
@@ -0,0 +1,20 @@
#!/bin/bash
####
# master.bash:
#
# Master script to run the CI process. This will setup and run the tests for the CI system.
####
export SCRIPT_DIR="$(dirname ${BASH_SOURCE})"
. "${SCRIPT_DIR}/helpers.bash"

#### NEEDED ENVIRONMENT ####
export FPRIME_DIR="$(pwd)"
export LOG_DIR="${FPRIME_DIR}/ci-logs-$(date +"%Y-%m-%dT%H%M%S")"
mkdir -p "${LOG_DIR}"

# Loop through all scripts in tests directory and run them
for test_script in "${SCRIPT_DIR}/tests"/*
do
"${SCriPT_DIR}/bootstrap.bash" || fail_and_stop "Cleaning and PIP install Failed"
"${test_script}" || fail_and_stop "${test_script} failed"
done
32 changes: 0 additions & 32 deletions mk/ci/scripts/cmake-build.bash

This file was deleted.

7 changes: 0 additions & 7 deletions mk/ci/scripts/cmake-cmaketest.bash

This file was deleted.

31 changes: 0 additions & 31 deletions mk/ci/scripts/cmake-int.bash

This file was deleted.

29 changes: 0 additions & 29 deletions mk/ci/scripts/cmake-ut.bash

This file was deleted.

11 changes: 11 additions & 0 deletions mk/ci/tests/00-fw-uts.bash
@@ -0,0 +1,11 @@
#!/bin/bash
####
# 00-fw-uts.bash:
#
# FW Unit Tests for the pythonm code. Performed upfront as it will inform the stability of the rest
# of the build.
####
export SCRIPT_DIR="$(dirname ${BASH_SOURCE})/.."
. "${SCRIPT_DIR}/helpers.bash"

pytest Fw/Python || fail_and_stop "Failed to run F prime framework UTs"
16 changes: 16 additions & 0 deletions mk/ci/tests/05-ptf.bash
@@ -0,0 +1,16 @@
#!/bin/bash
####
# 05-ptf.bash:
#
# Heritage PTF UTs tests
####
export SCRIPT_DIR="$(dirname ${BASH_SOURCE})/.."
. "${SCRIPT_DIR}/helpers.bash"
(
cd ptf
./run_all_unit_tests.sh
) || fail_and_stop "F prime UTs failed via PTF"
(
cd ptf
./run_ac_tests.sh
) || fail_and_stop "F prime UTs failed via PTF"
10 changes: 10 additions & 0 deletions mk/ci/tests/10-cmake-uts.bash
@@ -0,0 +1,10 @@
#!/bin/bash
####
# 10-cmake-uts.bash:
#
# Run the CMake UTs.
####
export SCRIPT_DIR="$(dirname ${BASH_SOURCE})/.."
. "${SCRIPT_DIR}/helpers.bash"

pytest cmake/ -v --ignore test_ut.py --ignore test_validation.py || fail_and_stop "Failed to run CMake UTs"
19 changes: 19 additions & 0 deletions mk/ci/tests/20-fputil.bash
@@ -0,0 +1,19 @@
#!/bin/bash
####
# 20-fputil.bash:
#
# Run the tests on the software through fp-util.
####
export SCRIPT_DIR="$(dirname ${BASH_SOURCE})/.."
. "${SCRIPT_DIR}/helpers.bash"

. ${SCRIPT_DIR}/tests/fputil.bash
# Loop over deployments and targets
for deployment in ${FPUTIL_DEPLOYS}
do
echo -e "${BLUE}Testing ${deployment} against fprime-util targets: ${FPUTIL_TARGET}${NOCOLOR}"
for target in ${FPUTIL_TARGET}
do
fputil_action "${deployment}" "${target}"
done
done
16 changes: 16 additions & 0 deletions mk/ci/tests/30-ints.bash
@@ -0,0 +1,16 @@
#!/bin/bash
####
# 30-ints.bash:
#
# Integration tests for CI
####
export SCRIPT_DIR="$(dirname ${BASH_SOURCE})/.."
. "${SCRIPT_DIR}/helpers.bash"

. ${SCRIPT_DIR}/tests/fputil.bash
# Loop over deployments and targets
for deployment in ${INTS_DEPLOYS}
do
echo -e "${BLUE}Testing ${deployment} against integration tests${NOCOLOR}"
integration_test "${deployment}"
done
72 changes: 72 additions & 0 deletions mk/ci/tests/fputil.bash
@@ -0,0 +1,72 @@
#!/bin/bash
####
# fputil.bash:
#
# Helpers to test via FP util
####
export FPUTIL_TARGETS="generate build build-uts check-all install build-all coverage"
export FPUTIL_DEPLOYS="${FPRIME_DIR}/Ref ${FPRIME_DIR}/RPI"

export INT_DEPLOYS="${FPRIME_DIR}/Ref"
####
# fputil_action:
#
# Runs an action for the FP util. This takes two parameters a target and a deployment. This assumes
# prequsite actions already exist.
# :param target($1): command to run with FP util
# :param deploy($2): deployment to run on
####
function fputil_action
do
export TARGET="${1}"
export WORKDIR="${2}"
let JOBS="${JOBS:-$(( ( RANDOM % 100 ) + 1 ))}"
(
cd "${WORKDIR}"
# Generate is only needed when it isn't being tested
if [[ "${TARGET}" != "generate" ]]
then
echo "[INFO] Generating build cache before ${WORKDIR//\//_} '${TARGET}' execution"
fprime-util "generate" --jobs "${JOBS}" > "${LOG_DIR}/${WORKDIR//\//_}_pregen.out.log" 2> "${LOG_DIR}/${WORKDIR//\//_}_pregen.err.log" \
|| fail_and_stop "Failed to generate before ${WORKDIR//\//_} '${TARGET}' execution"
fi
echo "[INFO] FP Util in ${WORKDIR} running ${target} with ${JOBS} jobs"
fprime-util "${target}" --jobs "${JOBS}" > "${LOG_DIR}/${WORKDIR//\//_}_pregen.out.log" 2> "${LOG_DIR}/${WORKDIR//\//_}_pregen.err.log" \
|| fail_and_stop "Failed to run '${TARGET}' in ${WORKDIR}"
) || exit 1
done

####
# integration_test:
#
# Runs the FPrime GDS and integration test layer for a deployment.
# :param deploy($1): deployment to run on.
####
function integration_test
do
let SLEEP_TIME=10
export WORKDIR="${1}"
fputil_action "${WORKDIR}" "install" || fail_and_stop "Failed to install before integration test"
(
mkdir -p "${LOG_DIR}/gds-logs"
# Start the GDS layer and give it time to run
echo "[INFO] Starting headless GDS layer"
fprime-gds -d "${WORKDIR}" -g none -l "${LOG_DIR}/gds-logs" 1>${LOG_DIR}/gds-logs/fprime-gds.stdout.log 2>${LOG_DIR}/gds-logs/fprime-gds.stderr.log &
GDS_PID=$!
echo "[INFO] Allowing GDS ${SLEEP_TIME} seconds to start"
sleep ${SLEEP_TIME}
# Check the above started successfully
ps -p ${GDS_PID} 2> /dev/null 1> /dev/null || fail_and_stop "Failed to start GDS layer headlessly"
# Run integration tests
(
cd "${WORKDIR}"
echo "[INFO] Running $1's pytest integration tests"
pytest "${LOG_DIR}/${WORKDIR//\//_}_pytest_ints.out.log" 2> "${LOG_DIR}/${WORKDIR//\//_}_pytest_ints.err.log"
)
RET_PYTEST=$?
kill $GDS_PID
sleep 2
pkill -KILL Ref
exit ${RET_PYTEST}
) || fail_and_stop "Failed integration tests on ${WORKDIR}"
done

0 comments on commit 588b130

Please sign in to comment.