summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/kselftest_harness.h
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2024-02-29 03:59:14 +0300
committerDavid S. Miller <davem@davemloft.net>2024-03-01 13:30:28 +0300
commitfa1a53d83674b3aa089b8661ee9f884c024f6e95 (patch)
treefb69dd3ae0469ecb5155b908d16527bff8f0e6bd /tools/testing/selftests/kselftest_harness.h
parent796a344fa4315f9c1f2258de14c1d20cbbef79a8 (diff)
downloadlinux-fa1a53d83674b3aa089b8661ee9f884c024f6e95.tar.xz
selftests: kselftest: add ksft_test_result_code(), handling all exit codes
For generic test harness code it's more useful to deal with exit codes directly, rather than having to switch on them and call the right ksft_test_result_*() helper. Add such function to kselftest.h. Note that "directive" and "diagnostic" are what ktap docs call those parts of the message. Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools/testing/selftests/kselftest_harness.h')
-rw-r--r--tools/testing/selftests/kselftest_harness.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 5a48177c8c00..4fb30fcc7774 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -1111,6 +1111,7 @@ void __run_test(struct __fixture_metadata *f,
struct __test_metadata *t)
{
char test_name[LINE_MAX];
+ const char *diagnostic;
/* reset test struct */
t->exit_code = KSFT_PASS;
@@ -1140,9 +1141,13 @@ void __run_test(struct __fixture_metadata *f,
ksft_print_msg(" %4s %s\n",
__test_passed(t) ? "OK" : "FAIL", test_name);
+ if (t->results->reason[0])
+ diagnostic = t->results->reason;
+ else
+ diagnostic = "unknown";
+
if (t->exit_code == KSFT_SKIP)
- ksft_test_result_skip("%s\n", t->results->reason[0] ?
- t->results->reason : "unknown");
+ ksft_test_result_code(t->exit_code, "%s\n", diagnostic);
else
ksft_test_result(__test_passed(t), "%s\n", test_name);
}