Skip to content

Commit 796a344

Browse files
kuba-moodavem330
authored andcommitted
selftests: kselftest_harness: use exit code to store skip
We always use skip in combination with exit_code being 0 (KSFT_PASS). This are basic KSFT / KTAP semantics. Store the right KSFT_* code in exit_code directly. This makes it easier to support tests reporting other extended KSFT_* codes like XFAIL / XPASS. Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 69fe8ec commit 796a344

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

tools/testing/selftests/kselftest_harness.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@
128128
fprintf(TH_LOG_STREAM, "# SKIP %s\n", \
129129
_metadata->results->reason); \
130130
} \
131-
_metadata->exit_code = KSFT_PASS; \
132-
_metadata->skip = 1; \
131+
_metadata->exit_code = KSFT_SKIP; \
133132
_metadata->trigger = 0; \
134133
statement; \
135134
} while (0)
@@ -387,7 +386,7 @@
387386
if (setjmp(_metadata->env) == 0) { \
388387
fixture_name##_setup(_metadata, &self, variant->data); \
389388
/* Let setup failure terminate early. */ \
390-
if (!__test_passed(_metadata) || _metadata->skip) \
389+
if (_metadata->exit_code) \
391390
return; \
392391
_metadata->setup_completed = true; \
393392
/* Use the same _metadata. */ \
@@ -837,7 +836,6 @@ struct __test_metadata {
837836
struct __fixture_metadata *fixture;
838837
int termsig;
839838
int exit_code;
840-
int skip; /* did SKIP get used? */
841839
int trigger; /* extra handler after the evaluation */
842840
int timeout; /* seconds to wait for test timeout */
843841
bool timed_out; /* did this test timeout instead of exiting? */
@@ -944,9 +942,7 @@ void __wait_for_test(struct __test_metadata *t)
944942
"# %s: Test terminated by timeout\n", t->name);
945943
} else if (WIFEXITED(status)) {
946944
if (WEXITSTATUS(status) == KSFT_SKIP) {
947-
/* SKIP */
948-
t->exit_code = KSFT_PASS;
949-
t->skip = 1;
945+
t->exit_code = WEXITSTATUS(status);
950946
} else if (t->termsig != -1) {
951947
t->exit_code = KSFT_FAIL;
952948
fprintf(TH_LOG_STREAM,
@@ -1118,7 +1114,6 @@ void __run_test(struct __fixture_metadata *f,
11181114

11191115
/* reset test struct */
11201116
t->exit_code = KSFT_PASS;
1121-
t->skip = 0;
11221117
t->trigger = 0;
11231118
memset(t->results->reason, 0, sizeof(t->results->reason));
11241119

@@ -1138,18 +1133,14 @@ void __run_test(struct __fixture_metadata *f,
11381133
} else if (t->pid == 0) {
11391134
setpgrp();
11401135
t->fn(t, variant);
1141-
if (t->skip)
1142-
_exit(KSFT_SKIP);
1143-
if (__test_passed(t))
1144-
_exit(KSFT_PASS);
1145-
_exit(KSFT_FAIL);
1136+
_exit(t->exit_code);
11461137
} else {
11471138
__wait_for_test(t);
11481139
}
11491140
ksft_print_msg(" %4s %s\n",
11501141
__test_passed(t) ? "OK" : "FAIL", test_name);
11511142

1152-
if (t->skip)
1143+
if (t->exit_code == KSFT_SKIP)
11531144
ksft_test_result_skip("%s\n", t->results->reason[0] ?
11541145
t->results->reason : "unknown");
11551146
else

0 commit comments

Comments
 (0)