Skip to content

Commit 28dec56

Browse files
authored
tests: fix binary test passing when failed and llvm-cov deprecated flag (#165)
* tests: coverage - fix llvm-cov deprecated --export-prefix solves [#164](#164) Signed-off-by: Artie Poole <stuart.poole@canonical.com> * tests: workflows: fix binary test passing even if the script errored sets pipefail flag and catches sub-script return state disable -e only around coverage pipeline Signed-off-by: Artie Poole <stuart.poole@canonical.com> * tests: binary - the TF job did not catch the error from _run it seems Signed-off-by: Artie Poole <stuart.poole@canonical.com> * tests: coverage-test default RUSTFLAGS to empty in export call Signed-off-by: Artie Poole <stuart.poole@canonical.com> --------- Signed-off-by: Artie Poole <stuart.poole@canonical.com>
1 parent 77dca34 commit 28dec56

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

.github/testflinger-assets/test_binary_device_script.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
set -x
3+
set -euxo pipefail
44

55
echo "INFO: Installing dependencies"
66
sudo env DEBIAN_FRONTEND=noninteractive apt update && sudo env DEBIAN_FRONTEND=noninteractive apt install build-essential -y
@@ -18,5 +18,15 @@ cd fpgad
1818
mkdir -p artifacts
1919
sudo journalctl -f -n0 > artifacts/journal.log 2>&1 &
2020
JOURNAL_PID=$!
21+
22+
# Temporarily disable -e to capture the test exit status even on failure
23+
set +e
2124
./tests/coverage_test.sh 2>&1 | tee artifacts/coverage_test.log
22-
sudo kill ${JOURNAL_PID} || true
25+
TEST_EXIT_STATUS=${PIPESTATUS[0]}
26+
set -e
27+
28+
# Cleanup regardless of test result
29+
sudo kill ${JOURNAL_PID} || true
30+
31+
# Exit with the test's exit status
32+
exit $TEST_EXIT_STATUS

.github/testflinger-assets/testflinger_job.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ test_data:
3434
- agent: device_script.sh
3535
local: ./device_script.sh
3636
test_cmds: |
37+
set -e
3738
# get hw-cert-team helper tools
3839
echo "INFO: setting up scriptlets"
3940
export TOOLS_PATH=tools
@@ -47,8 +48,16 @@ test_data:
4748
4849
echo "INFO: Running script on DUT"
4950
_run 'chmod +x /home/ubuntu/device_script.sh'
51+
52+
# Run the test script, but always retrieve artifacts even if it fails
53+
set +e
5054
_run '/home/ubuntu/device_script.sh'
55+
TEST_SCRIPT_EXIT=$?
56+
set -e
5157
5258
echo "INFO: Retrieving artifacts"
5359
mkdir -p artifacts
5460
_get fpgad/artifacts/* artifacts
61+
62+
# Fail the job if the test script failed
63+
exit $TEST_SCRIPT_EXIT

tests/coverage_test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
set -xeu
1616

1717
# Enable llvm-coverage build results
18-
eval "$(cargo llvm-cov show-env --export-prefix)"
18+
eval "$(cargo llvm-cov show-env --sh)"
1919

20-
export RUSTFLAGS="$RUSTFLAGS -C llvm-args=-runtime-counter-relocation"
20+
export RUSTFLAGS="${RUSTFLAGS:-} -C llvm-args=-runtime-counter-relocation"
2121

2222
# build the daemon only, to avoid getting coverage for cli (no tests written)
2323
cargo build --bin daemon

0 commit comments

Comments
 (0)