diff --git a/.github/testflinger-assets/test_binary_device_script.sh b/.github/testflinger-assets/test_binary_device_script.sh index ce19e986..54516f22 100755 --- a/.github/testflinger-assets/test_binary_device_script.sh +++ b/.github/testflinger-assets/test_binary_device_script.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -x +set -euxo pipefail echo "INFO: Installing dependencies" sudo env DEBIAN_FRONTEND=noninteractive apt update && sudo env DEBIAN_FRONTEND=noninteractive apt install build-essential -y @@ -18,5 +18,15 @@ cd fpgad mkdir -p artifacts sudo journalctl -f -n0 > artifacts/journal.log 2>&1 & JOURNAL_PID=$! + +# Temporarily disable -e to capture the test exit status even on failure +set +e ./tests/coverage_test.sh 2>&1 | tee artifacts/coverage_test.log -sudo kill ${JOURNAL_PID} || true +TEST_EXIT_STATUS=${PIPESTATUS[0]} +set -e + +# Cleanup regardless of test result +sudo kill ${JOURNAL_PID} || true + +# Exit with the test's exit status +exit $TEST_EXIT_STATUS diff --git a/.github/testflinger-assets/testflinger_job.yaml b/.github/testflinger-assets/testflinger_job.yaml index 85a98029..e52b250b 100644 --- a/.github/testflinger-assets/testflinger_job.yaml +++ b/.github/testflinger-assets/testflinger_job.yaml @@ -34,6 +34,7 @@ test_data: - agent: device_script.sh local: ./device_script.sh test_cmds: | + set -e # get hw-cert-team helper tools echo "INFO: setting up scriptlets" export TOOLS_PATH=tools @@ -47,8 +48,16 @@ test_data: echo "INFO: Running script on DUT" _run 'chmod +x /home/ubuntu/device_script.sh' + + # Run the test script, but always retrieve artifacts even if it fails + set +e _run '/home/ubuntu/device_script.sh' + TEST_SCRIPT_EXIT=$? + set -e echo "INFO: Retrieving artifacts" mkdir -p artifacts _get fpgad/artifacts/* artifacts + + # Fail the job if the test script failed + exit $TEST_SCRIPT_EXIT diff --git a/tests/coverage_test.sh b/tests/coverage_test.sh index b8a23b60..f1412a8b 100755 --- a/tests/coverage_test.sh +++ b/tests/coverage_test.sh @@ -15,9 +15,9 @@ set -xeu # Enable llvm-coverage build results -eval "$(cargo llvm-cov show-env --export-prefix)" +eval "$(cargo llvm-cov show-env --sh)" -export RUSTFLAGS="$RUSTFLAGS -C llvm-args=-runtime-counter-relocation" +export RUSTFLAGS="${RUSTFLAGS:-} -C llvm-args=-runtime-counter-relocation" # build the daemon only, to avoid getting coverage for cli (no tests written) cargo build --bin daemon