Skip to content

Commit 2dd0b5a

Browse files
nfrapradoshuahkh
authored andcommitted
selftests: ktap_helpers: Add a helper to finish the test
Similar to the C counterpart, keep track of the number of test cases in the test plan and add a helper function to be called at the end of the test to print the results and exit with the corresponding exit code. Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent d63fde9 commit 2dd0b5a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

tools/testing/selftests/kselftest/ktap_helpers.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ KSFT_XFAIL=2
1515
KSFT_XPASS=3
1616
KSFT_SKIP=4
1717

18+
KSFT_NUM_TESTS=0
19+
1820
ktap_print_header() {
1921
echo "TAP version 13"
2022
}
@@ -25,9 +27,9 @@ ktap_print_msg()
2527
}
2628

2729
ktap_set_plan() {
28-
num_tests="$1"
30+
KSFT_NUM_TESTS="$1"
2931

30-
echo "1..$num_tests"
32+
echo "1..$KSFT_NUM_TESTS"
3133
}
3234

3335
ktap_skip_all() {
@@ -94,6 +96,16 @@ ktap_exit_fail_msg() {
9496
exit "$KSFT_FAIL"
9597
}
9698

99+
ktap_finished() {
100+
ktap_print_totals
101+
102+
if [ $(("$KTAP_CNT_PASS" + "$KTAP_CNT_SKIP")) -eq "$KSFT_NUM_TESTS" ]; then
103+
exit "$KSFT_PASS"
104+
else
105+
exit "$KSFT_FAIL"
106+
fi
107+
}
108+
97109
ktap_print_totals() {
98110
echo "# Totals: pass:$KTAP_CNT_PASS fail:$KTAP_CNT_FAIL xfail:0 xpass:0 skip:$KTAP_CNT_SKIP error:0"
99111
}

0 commit comments

Comments
 (0)