Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: kselftest_harness: save full exit code in metadata

Instead of tracking passed = 0/1 rename the field to exit_code
and invert the values so that they match the KSFT_* exit codes.
This will allow us to fold SKIP / XFAIL into the same value.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jakub Kicinski and committed by
David S. Miller
69fe8ec4 38c957f0

+41 -35
+27 -21
tools/testing/selftests/kselftest_harness.h
··· 128 128 fprintf(TH_LOG_STREAM, "# SKIP %s\n", \ 129 129 _metadata->results->reason); \ 130 130 } \ 131 - _metadata->passed = 1; \ 131 + _metadata->exit_code = KSFT_PASS; \ 132 132 _metadata->skip = 1; \ 133 133 _metadata->trigger = 0; \ 134 134 statement; \ ··· 387 387 if (setjmp(_metadata->env) == 0) { \ 388 388 fixture_name##_setup(_metadata, &self, variant->data); \ 389 389 /* Let setup failure terminate early. */ \ 390 - if (!_metadata->passed || _metadata->skip) \ 390 + if (!__test_passed(_metadata) || _metadata->skip) \ 391 391 return; \ 392 392 _metadata->setup_completed = true; \ 393 393 /* Use the same _metadata. */ \ ··· 398 398 } \ 399 399 if (child < 0) { \ 400 400 ksft_print_msg("ERROR SPAWNING TEST GRANDCHILD\n"); \ 401 - _metadata->passed = 0; \ 401 + _metadata->exit_code = KSFT_FAIL; \ 402 402 } \ 403 403 } \ 404 404 if (child == 0) \ ··· 747 747 break; \ 748 748 } \ 749 749 } \ 750 - _metadata->passed = 0; \ 750 + _metadata->exit_code = KSFT_FAIL; \ 751 751 /* Ensure the optional handler is triggered */ \ 752 752 _metadata->trigger = 1; \ 753 753 } \ ··· 758 758 const char *__seen = (_seen); \ 759 759 if (!(strcmp(__exp, __seen) _t 0)) { \ 760 760 __TH_LOG("Expected '%s' %s '%s'.", __exp, #_t, __seen); \ 761 - _metadata->passed = 0; \ 761 + _metadata->exit_code = KSFT_FAIL; \ 762 762 _metadata->trigger = 1; \ 763 763 } \ 764 764 } while (0); OPTIONAL_HANDLER(_assert) ··· 836 836 pid_t pid; /* pid of test when being run */ 837 837 struct __fixture_metadata *fixture; 838 838 int termsig; 839 - int passed; 839 + int exit_code; 840 840 int skip; /* did SKIP get used? */ 841 841 int trigger; /* extra handler after the evaluation */ 842 842 int timeout; /* seconds to wait for test timeout */ ··· 847 847 struct __test_results *results; 848 848 struct __test_metadata *prev, *next; 849 849 }; 850 + 851 + static inline bool __test_passed(struct __test_metadata *metadata) 852 + { 853 + return metadata->exit_code != KSFT_FAIL && 854 + metadata->exit_code <= KSFT_SKIP; 855 + } 850 856 851 857 /* 852 858 * Since constructors are called in reverse order, reverse the test ··· 918 912 int status; 919 913 920 914 if (sigaction(SIGALRM, &action, &saved_action)) { 921 - t->passed = 0; 915 + t->exit_code = KSFT_FAIL; 922 916 fprintf(TH_LOG_STREAM, 923 917 "# %s: unable to install SIGALRM handler\n", 924 918 t->name); ··· 930 924 waitpid(t->pid, &status, 0); 931 925 alarm(0); 932 926 if (sigaction(SIGALRM, &saved_action, NULL)) { 933 - t->passed = 0; 927 + t->exit_code = KSFT_FAIL; 934 928 fprintf(TH_LOG_STREAM, 935 929 "# %s: unable to uninstall SIGALRM handler\n", 936 930 t->name); ··· 939 933 __active_test = NULL; 940 934 941 935 if (t->timed_out) { 942 - t->passed = 0; 936 + t->exit_code = KSFT_FAIL; 943 937 fprintf(TH_LOG_STREAM, 944 938 "# %s: Test terminated by timeout\n", t->name); 945 939 } else if (WIFEXITED(status)) { 946 940 if (WEXITSTATUS(status) == KSFT_SKIP) { 947 941 /* SKIP */ 948 - t->passed = 1; 942 + t->exit_code = KSFT_PASS; 949 943 t->skip = 1; 950 944 } else if (t->termsig != -1) { 951 - t->passed = 0; 945 + t->exit_code = KSFT_FAIL; 952 946 fprintf(TH_LOG_STREAM, 953 947 "# %s: Test exited normally instead of by signal (code: %d)\n", 954 948 t->name, ··· 957 951 switch (WEXITSTATUS(status)) { 958 952 /* Success */ 959 953 case KSFT_PASS: 960 - t->passed = 1; 954 + t->exit_code = KSFT_PASS; 961 955 break; 962 956 /* Failure */ 963 957 default: 964 - t->passed = 0; 958 + t->exit_code = KSFT_FAIL; 965 959 fprintf(TH_LOG_STREAM, 966 960 "# %s: Test failed\n", 967 961 t->name); 968 962 } 969 963 } 970 964 } else if (WIFSIGNALED(status)) { 971 - t->passed = 0; 965 + t->exit_code = KSFT_FAIL; 972 966 if (WTERMSIG(status) == SIGABRT) { 973 967 fprintf(TH_LOG_STREAM, 974 968 "# %s: Test terminated by assertion\n", 975 969 t->name); 976 970 } else if (WTERMSIG(status) == t->termsig) { 977 - t->passed = 1; 971 + t->exit_code = KSFT_PASS; 978 972 } else { 979 973 fprintf(TH_LOG_STREAM, 980 974 "# %s: Test terminated unexpectedly by signal %d\n", ··· 1117 1111 char test_name[LINE_MAX]; 1118 1112 1119 1113 /* reset test struct */ 1120 - t->passed = 1; 1114 + t->exit_code = KSFT_PASS; 1121 1115 t->skip = 0; 1122 1116 t->trigger = 0; 1123 1117 memset(t->results->reason, 0, sizeof(t->results->reason)); ··· 1134 1128 t->pid = fork(); 1135 1129 if (t->pid < 0) { 1136 1130 ksft_print_msg("ERROR SPAWNING TEST CHILD\n"); 1137 - t->passed = 0; 1131 + t->exit_code = KSFT_FAIL; 1138 1132 } else if (t->pid == 0) { 1139 1133 setpgrp(); 1140 1134 t->fn(t, variant); 1141 1135 if (t->skip) 1142 1136 _exit(KSFT_SKIP); 1143 - if (t->passed) 1137 + if (__test_passed(t)) 1144 1138 _exit(KSFT_PASS); 1145 1139 _exit(KSFT_FAIL); 1146 1140 } else { 1147 1141 __wait_for_test(t); 1148 1142 } 1149 1143 ksft_print_msg(" %4s %s\n", 1150 - t->passed ? "OK" : "FAIL", test_name); 1144 + __test_passed(t) ? "OK" : "FAIL", test_name); 1151 1145 1152 1146 if (t->skip) 1153 1147 ksft_test_result_skip("%s\n", t->results->reason[0] ? 1154 1148 t->results->reason : "unknown"); 1155 1149 else 1156 - ksft_test_result(t->passed, "%s\n", test_name); 1150 + ksft_test_result(__test_passed(t), "%s\n", test_name); 1157 1151 } 1158 1152 1159 1153 static int test_harness_run(int argc, char **argv) ··· 1201 1195 t->results = results; 1202 1196 __run_test(f, v, t); 1203 1197 t->results = NULL; 1204 - if (t->passed) 1198 + if (__test_passed(t)) 1205 1199 pass_count++; 1206 1200 else 1207 1201 ret = 1;
+1 -1
tools/testing/selftests/landlock/base_test.c
··· 307 307 dir_fd = open("/tmp", O_RDONLY | O_DIRECTORY | O_CLOEXEC); 308 308 ASSERT_LE(0, dir_fd); 309 309 ASSERT_EQ(0, close(dir_fd)); 310 - _exit(_metadata->passed ? EXIT_SUCCESS : EXIT_FAILURE); 310 + _exit(_metadata->exit_code); 311 311 return; 312 312 } 313 313
+2 -2
tools/testing/selftests/landlock/fs_test.c
··· 1964 1964 strerror(errno)); 1965 1965 }; 1966 1966 ASSERT_EQ(err, errno); 1967 - _exit(_metadata->passed ? 2 : 1); 1967 + _exit(__test_passed(_metadata) ? 2 : 1); 1968 1968 return; 1969 1969 } 1970 1970 ASSERT_EQ(child, waitpid(child, &status, 0)); ··· 3807 3807 3808 3808 ASSERT_EQ(0, close(socket_fds[0])); 3809 3809 3810 - _exit(_metadata->passed ? EXIT_SUCCESS : EXIT_FAILURE); 3810 + _exit(_metadata->exit_code); 3811 3811 return; 3812 3812 } 3813 3813
+2 -2
tools/testing/selftests/landlock/net_test.c
··· 539 539 } 540 540 541 541 EXPECT_EQ(0, close(connect_fd)); 542 - _exit(_metadata->passed ? EXIT_SUCCESS : EXIT_FAILURE); 542 + _exit(_metadata->exit_code); 543 543 return; 544 544 } 545 545 ··· 834 834 } 835 835 836 836 EXPECT_EQ(0, close(connect_fd)); 837 - _exit(_metadata->passed ? EXIT_SUCCESS : EXIT_FAILURE); 837 + _exit(_metadata->exit_code); 838 838 return; 839 839 } 840 840
+4 -3
tools/testing/selftests/landlock/ptrace_test.c
··· 314 314 ASSERT_EQ(0, pipe2(pipe_parent, O_CLOEXEC)); 315 315 if (variant->domain_both) { 316 316 create_domain(_metadata); 317 - if (!_metadata->passed) 317 + if (!__test_passed(_metadata)) 318 318 /* Aborts before forking. */ 319 319 return; 320 320 } ··· 375 375 376 376 /* Waits for the parent PTRACE_ATTACH test. */ 377 377 ASSERT_EQ(1, read(pipe_parent[0], &buf_child, 1)); 378 - _exit(_metadata->passed ? EXIT_SUCCESS : EXIT_FAILURE); 378 + _exit(_metadata->exit_code); 379 379 return; 380 380 } 381 381 ··· 430 430 /* Signals that the parent PTRACE_ATTACH test is done. */ 431 431 ASSERT_EQ(1, write(pipe_parent[1], ".", 1)); 432 432 ASSERT_EQ(child, waitpid(child, &status, 0)); 433 + 433 434 if (WIFSIGNALED(status) || !WIFEXITED(status) || 434 435 WEXITSTATUS(status) != EXIT_SUCCESS) 435 - _metadata->passed = 0; 436 + _metadata->exit_code = KSFT_FAIL; 436 437 } 437 438 438 439 TEST_HARNESS_MAIN
+1 -1
tools/testing/selftests/net/tls.c
··· 1927 1927 pfd.events = POLLIN; 1928 1928 EXPECT_EQ(poll(&pfd, 1, 20), 1); 1929 1929 1930 - exit(!_metadata->passed); 1930 + exit(!__test_passed(_metadata)); 1931 1931 } 1932 1932 } 1933 1933
+4 -5
tools/testing/selftests/seccomp/seccomp_bpf.c
··· 1576 1576 ASSERT_EQ(0, ret); 1577 1577 } 1578 1578 /* Directly report the status of our test harness results. */ 1579 - syscall(__NR_exit, _metadata->passed ? EXIT_SUCCESS : EXIT_FAILURE); 1579 + syscall(__NR_exit, _metadata->exit_code); 1580 1580 } 1581 1581 1582 1582 /* Common tracer setup/teardown functions. */ ··· 1623 1623 ASSERT_EQ(0, kill(tracer, SIGUSR1)); 1624 1624 ASSERT_EQ(tracer, waitpid(tracer, &status, 0)); 1625 1625 if (WEXITSTATUS(status)) 1626 - _metadata->passed = 0; 1626 + _metadata->exit_code = KSFT_FAIL; 1627 1627 } 1628 1628 } 1629 1629 ··· 3088 3088 } 3089 3089 3090 3090 /* Directly report the status of our test harness results. */ 3091 - syscall(__NR_exit, _metadata->passed ? EXIT_SUCCESS 3092 - : EXIT_FAILURE); 3091 + syscall(__NR_exit, _metadata->exit_code); 3093 3092 } 3094 3093 EXPECT_EQ(0, close(pipefd[0])); 3095 3094 ··· 3173 3174 3174 3175 ASSERT_EQ(child_pid, waitpid(child_pid, &status, 0)); 3175 3176 if (WIFSIGNALED(status) || WEXITSTATUS(status)) 3176 - _metadata->passed = 0; 3177 + _metadata->exit_code = KSFT_FAIL; 3177 3178 } 3178 3179 3179 3180 TEST_SIGNAL(filter_flag_log, SIGSYS)