Skip to content

Commit b85d387

Browse files
bonzinishuahkh
authored andcommitted
kselftest: fix TAP output for skipped tests
According to the TAP specification, a skipped test must be marked as "ok" and annotated with the SKIP directive, for example ok 23 # skip Insufficient flogiston pressure. (https://testanything.org/tap-specification.html) Fix the kselftest infrastructure to match this. For ksft_exit_skip, it is preferrable to emit a dummy plan line that indicates the whole test was skipped, but this is not always possible because of ksft_exit_skip being used as a "shortcut" by the tests. In that case, print the test counts and a normal "ok" line. The format is now the same independent of whether msg is NULL or not (but it is never NULL in any caller right now). Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 9ebcfad commit b85d387

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

tools/testing/selftests/kselftest.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static inline void ksft_test_result_skip(const char *msg, ...)
128128
ksft_cnt.ksft_xskip++;
129129

130130
va_start(args, msg);
131-
printf("not ok %d # SKIP ", ksft_test_num());
131+
printf("ok %d # SKIP ", ksft_test_num());
132132
errno = saved_errno;
133133
vprintf(msg, args);
134134
va_end(args);
@@ -190,18 +190,30 @@ static inline int ksft_exit_xpass(void)
190190

191191
static inline int ksft_exit_skip(const char *msg, ...)
192192
{
193-
if (msg) {
194-
int saved_errno = errno;
195-
va_list args;
193+
int saved_errno = errno;
194+
va_list args;
196195

197-
va_start(args, msg);
198-
printf("not ok %d # SKIP ", 1 + ksft_test_num());
196+
va_start(args, msg);
197+
198+
/*
199+
* FIXME: several tests misuse ksft_exit_skip so produce
200+
* something sensible if some tests have already been run
201+
* or a plan has been printed. Those tests should use
202+
* ksft_test_result_skip or ksft_exit_fail_msg instead.
203+
*/
204+
if (ksft_plan || ksft_test_num()) {
205+
ksft_cnt.ksft_xskip++;
206+
printf("ok %d # SKIP ", 1 + ksft_test_num());
207+
} else {
208+
printf("1..0 # SKIP ");
209+
}
210+
if (msg) {
199211
errno = saved_errno;
200212
vprintf(msg, args);
201213
va_end(args);
202-
} else {
203-
ksft_print_cnts();
204214
}
215+
if (ksft_test_num())
216+
ksft_print_cnts();
205217
exit(KSFT_SKIP);
206218
}
207219

tools/testing/selftests/kselftest/runner.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ run_one()
7777
echo "ok $test_num $TEST_HDR_MSG") ||
7878
(rc=$?; \
7979
if [ $rc -eq $skip_rc ]; then \
80-
echo "not ok $test_num $TEST_HDR_MSG # SKIP"
80+
echo "ok $test_num $TEST_HDR_MSG # SKIP"
8181
elif [ $rc -eq $timeout_rc ]; then \
8282
echo "#"
8383
echo "not ok $test_num $TEST_HDR_MSG # TIMEOUT"

0 commit comments

Comments
 (0)