Skip to content

Commit a0877a3

Browse files
t-8chshuahkh
authored andcommitted
selftests: harness: Detect illegal mixing of kselftest and harness functionality
Users may accidentally use the kselftest_test_result_*() functions in their harness tests. If ksft_finished() is not used, the results reported in this way are silently ignored. Detect such false-positive cases and fail the test. A more correct test would be to reject *any* usage of the ksft APIs but that would force code churn on users. Correct usages, which do use ksft_finished() will not trigger this validation as the test will exit before it. Reported-by: Yuwen Chen <ywen.chen@foxmail.com> Link: https://lore.kernel.org/lkml/tencent_56D79AF3D23CEFAF882E83A2196EC1F12107@qq.com/ Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Link: https://lore.kernel.org/r/20260302-kselftest-harness-v2-4-3143aa41d989@linutronix.de Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent d431ea8 commit a0877a3

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

tools/testing/selftests/kselftest_harness.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,16 @@ static void __run_test(struct __fixture_metadata *f,
12221222
t->exit_code = KSFT_FAIL;
12231223
} else if (child == 0) {
12241224
setpgrp();
1225+
1226+
/* Reset state inherited from the harness */
1227+
ksft_reset_state();
1228+
12251229
t->fn(t, variant);
1230+
1231+
if (__test_passed(t) && (ksft_get_fail_cnt() || ksft_get_error_cnt())) {
1232+
ksft_print_msg("Illegal usage of low-level ksft APIs in harness test\n");
1233+
t->exit_code = KSFT_FAIL;
1234+
}
12261235
_exit(t->exit_code);
12271236
} else {
12281237
t->pid = child;

0 commit comments

Comments
 (0)