Skip to content

Commit 758b890

Browse files
t-8chshuahkh
authored andcommitted
selftests: harness: Validate that explicit kselftest exitcodes are handled
The test programs can directly call exit with one of the KSFT_* constants. Add tests for this functionality. Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Link: https://lore.kernel.org/r/20260302-kselftest-harness-v2-2-3143aa41d989@linutronix.de Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent fd1b4eb commit 758b890

2 files changed

Lines changed: 46 additions & 9 deletions

File tree

tools/testing/selftests/kselftest_harness/harness-selftest.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,26 @@ TEST_F(fixture_setup_failure, pass) {
118118
TH_LOG("after");
119119
}
120120

121+
TEST(exit_pass) {
122+
exit(KSFT_PASS);
123+
}
124+
125+
TEST(exit_xpass) {
126+
exit(KSFT_XPASS);
127+
}
128+
129+
TEST(exit_fail) {
130+
exit(KSFT_FAIL);
131+
}
132+
133+
TEST(exit_xfail) {
134+
exit(KSFT_XFAIL);
135+
}
136+
137+
TEST(exit_skip) {
138+
exit(KSFT_SKIP);
139+
}
140+
121141
int main(int argc, char **argv)
122142
{
123143
/*

tools/testing/selftests/kselftest_harness/harness-selftest.expected

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
TAP version 13
2-
1..9
3-
# Starting 9 tests from 4 test cases.
2+
1..14
3+
# Starting 14 tests from 4 test cases.
44
# RUN global.standalone_pass ...
55
# harness-selftest.c:19:standalone_pass:before
66
# harness-selftest.c:23:standalone_pass:after
@@ -24,6 +24,22 @@ ok 3 global.signal_pass
2424
# signal_fail: Test terminated by assertion
2525
# FAIL global.signal_fail
2626
not ok 4 global.signal_fail
27+
# RUN global.exit_pass ...
28+
# OK global.exit_pass
29+
ok 5 global.exit_pass
30+
# RUN global.exit_xpass ...
31+
# OK global.exit_xpass
32+
ok 6 global.exit_xpass # XPASS unknown
33+
# RUN global.exit_fail ...
34+
# exit_fail: Test failed
35+
# FAIL global.exit_fail
36+
not ok 7 global.exit_fail
37+
# RUN global.exit_xfail ...
38+
# OK global.exit_xfail
39+
ok 8 global.exit_xfail # XFAIL unknown
40+
# RUN global.exit_skip ...
41+
# OK global.exit_skip
42+
ok 9 global.exit_skip # SKIP unknown
2743
# RUN fixture.pass ...
2844
# harness-selftest.c:53:pass:setup
2945
# harness-selftest.c:62:pass:before
@@ -32,33 +48,34 @@ not ok 4 global.signal_fail
3248
# harness-selftest.c:66:pass:after
3349
# harness-selftest.c:58:pass:teardown same-process=1
3450
# OK fixture.pass
35-
ok 5 fixture.pass
51+
ok 10 fixture.pass
3652
# RUN fixture.fail ...
3753
# harness-selftest.c:53:fail:setup
3854
# harness-selftest.c:70:fail:before
3955
# harness-selftest.c:71:fail:Expected 0 (0) == 1 (1)
4056
# harness-selftest.c:58:fail:teardown same-process=1
4157
# fail: Test terminated by assertion
4258
# FAIL fixture.fail
43-
not ok 6 fixture.fail
59+
not ok 11 fixture.fail
4460
# RUN fixture.timeout ...
4561
# harness-selftest.c:53:timeout:setup
4662
# harness-selftest.c:77:timeout:before
4763
# timeout: Test terminated by timeout
4864
# FAIL fixture.timeout
49-
not ok 7 fixture.timeout
65+
not ok 12 fixture.timeout
5066
# RUN fixture_parent.pass ...
5167
# harness-selftest.c:87:pass:setup
5268
# harness-selftest.c:96:pass:before
5369
# harness-selftest.c:98:pass:after
5470
# harness-selftest.c:92:pass:teardown same-process=0
5571
# OK fixture_parent.pass
56-
ok 8 fixture_parent.pass
72+
ok 13 fixture_parent.pass
5773
# RUN fixture_setup_failure.pass ...
5874
# harness-selftest.c:106:pass:setup
5975
# harness-selftest.c:108:pass:Expected 0 (0) == 1 (1)
6076
# pass: Test terminated by assertion
6177
# FAIL fixture_setup_failure.pass
62-
not ok 9 fixture_setup_failure.pass
63-
# FAILED: 4 / 9 tests passed.
64-
# Totals: pass:4 fail:5 xfail:0 xpass:0 skip:0 error:0
78+
not ok 14 fixture_setup_failure.pass
79+
# FAILED: 8 / 14 tests passed.
80+
# 1 skipped test(s) detected. Consider enabling relevant config options to improve coverage.
81+
# Totals: pass:5 fail:6 xfail:1 xpass:1 skip:1 error:0

0 commit comments

Comments
 (0)