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

selftests: Add test plan API to kselftest.h and adjust callers

The test plan for TAP needs to be declared immediately after the header.
This adds the test plan API to kselftest.h and updates all callers to
declare their expected test counts.

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Kees Cook and committed by
Shuah Khan
5821ba96 f41c322f

+48 -8
+12 -3
tools/testing/selftests/breakpoints/breakpoint_test.c
··· 21 21 22 22 #include "../kselftest.h" 23 23 24 + #define COUNT_ISN_BPS 4 25 + #define COUNT_WPS 4 24 26 25 27 /* Breakpoint access modes */ 26 28 enum { ··· 222 220 if (!local && !global) 223 221 continue; 224 222 225 - for (i = 0; i < 4; i++) { 223 + for (i = 0; i < COUNT_ISN_BPS; i++) { 226 224 dummy_funcs[i](); 227 225 check_trapped(); 228 226 } ··· 294 292 { 295 293 int i; 296 294 297 - for (i = 0; i < 4; i++) { 295 + for (i = 0; i < COUNT_ISN_BPS; i++) { 298 296 set_breakpoint_addr(dummy_funcs[i], i); 299 297 toggle_breakpoint(i, BP_X, 1, local, global, 1); 300 298 ptrace(PTRACE_CONT, child_pid, NULL, 0); ··· 316 314 else 317 315 mode_str = "read"; 318 316 319 - for (i = 0; i < 4; i++) { 317 + for (i = 0; i < COUNT_WPS; i++) { 320 318 set_breakpoint_addr(&dummy_var[i], i); 321 319 toggle_breakpoint(i, mode, len, local, global, 1); 322 320 ptrace(PTRACE_CONT, child_pid, NULL, 0); ··· 332 330 static void launch_tests(void) 333 331 { 334 332 char buf[1024]; 333 + unsigned int tests = 0; 335 334 int len, local, global, i; 335 + 336 + tests += 3 * COUNT_ISN_BPS; 337 + tests += sizeof(long) / 2 * 3 * COUNT_WPS; 338 + tests += sizeof(long) / 2 * 3 * COUNT_WPS; 339 + tests += 2; 340 + ksft_set_plan(tests); 336 341 337 342 /* Instruction breakpoints */ 338 343 for (local = 0; local < 2; local++) {
+2 -1
tools/testing/selftests/breakpoints/breakpoint_test_arm64.c
··· 118 118 return false; 119 119 } 120 120 121 - static bool run_test(int wr_size, int wp_size, int wr, int wp) 121 + static bool arun_test(int wr_size, int wp_size, int wr, int wp) 122 122 { 123 123 int status; 124 124 siginfo_t siginfo; ··· 214 214 bool result; 215 215 216 216 ksft_print_header(); 217 + ksft_set_plan(213); 217 218 218 219 act.sa_handler = sigalrm; 219 220 sigemptyset(&act.sa_mask);
+8
tools/testing/selftests/breakpoints/step_after_suspend_test.c
··· 173 173 int opt; 174 174 bool do_suspend = true; 175 175 bool succeeded = true; 176 + unsigned int tests = 0; 176 177 cpu_set_t available_cpus; 177 178 int err; 178 179 int cpu; ··· 191 190 return -1; 192 191 } 193 192 } 193 + 194 + for (cpu = 0; cpu < CPU_SETSIZE; cpu++) { 195 + if (!CPU_ISSET(cpu, &available_cpus)) 196 + continue; 197 + tests++; 198 + } 199 + ksft_set_plan(tests); 194 200 195 201 if (do_suspend) 196 202 suspend();
+4 -2
tools/testing/selftests/capabilities/test_execve.c
··· 430 430 { 431 431 char *tmp1, *tmp2, *our_path; 432 432 433 - ksft_print_header(); 434 - 435 433 /* Find our path */ 436 434 tmp1 = strdup(argv[0]); 437 435 if (!tmp1) ··· 443 445 mpid = getpid(); 444 446 445 447 if (fork_wait()) { 448 + ksft_print_header(); 449 + ksft_set_plan(12); 446 450 ksft_print_msg("[RUN]\t+++ Tests with uid == 0 +++\n"); 447 451 return do_tests(0, our_path); 448 452 } ··· 452 452 ksft_print_msg("==================================================\n"); 453 453 454 454 if (fork_wait()) { 455 + ksft_print_header(); 456 + ksft_set_plan(9); 455 457 ksft_print_msg("[RUN]\t+++ Tests with uid != 0 +++\n"); 456 458 return do_tests(1, our_path); 457 459 }
+1
tools/testing/selftests/futex/functional/futex_requeue_pi.c
··· 395 395 } 396 396 397 397 ksft_print_header(); 398 + ksft_set_plan(1); 398 399 ksft_print_msg("%s: Test requeue functionality\n", basename(argv[0])); 399 400 ksft_print_msg( 400 401 "\tArguments: broadcast=%d locked=%d owner=%d timeout=%ldns\n",
+1
tools/testing/selftests/futex/functional/futex_requeue_pi_mismatched_ops.c
··· 79 79 } 80 80 81 81 ksft_print_header(); 82 + ksft_set_plan(1); 82 83 ksft_print_msg("%s: Detect mismatched requeue_pi operations\n", 83 84 basename(argv[0])); 84 85
+1
tools/testing/selftests/futex/functional/futex_requeue_pi_signal_restart.c
··· 144 144 } 145 145 146 146 ksft_print_header(); 147 + ksft_set_plan(1); 147 148 ksft_print_msg("%s: Test signal handling during requeue_pi\n", 148 149 basename(argv[0])); 149 150 ksft_print_msg("\tArguments: <none>\n");
+1
tools/testing/selftests/futex/functional/futex_wait_private_mapped_file.c
··· 98 98 } 99 99 100 100 ksft_print_header(); 101 + ksft_set_plan(1); 101 102 ksft_print_msg( 102 103 "%s: Test the futex value of private file mappings in FUTEX_WAIT\n", 103 104 basename(argv[0]));
+1
tools/testing/selftests/futex/functional/futex_wait_timeout.c
··· 69 69 } 70 70 71 71 ksft_print_header(); 72 + ksft_set_plan(1); 72 73 ksft_print_msg("%s: Block on a futex and wait for timeout\n", 73 74 basename(argv[0])); 74 75 ksft_print_msg("\tArguments: timeout=%ldns\n", timeout_ns);
+1
tools/testing/selftests/futex/functional/futex_wait_uninitialized_heap.c
··· 100 100 } 101 101 102 102 ksft_print_header(); 103 + ksft_set_plan(1); 103 104 ksft_print_msg("%s: Test the uninitialized futex value in FUTEX_WAIT\n", 104 105 basename(argv[0])); 105 106
+1
tools/testing/selftests/futex/functional/futex_wait_wouldblock.c
··· 65 65 } 66 66 67 67 ksft_print_header(); 68 + ksft_set_plan(1); 68 69 ksft_print_msg("%s: Test the unexpected futex value in FUTEX_WAIT\n", 69 70 basename(argv[0])); 70 71
+11 -2
tools/testing/selftests/kselftest.h
··· 33 33 }; 34 34 35 35 static struct ksft_count ksft_cnt; 36 + static unsigned int ksft_plan; 36 37 37 38 static inline int ksft_test_num(void) 38 39 { ··· 62 61 printf("TAP version 13\n"); 63 62 } 64 63 64 + static inline void ksft_set_plan(unsigned int plan) 65 + { 66 + ksft_plan = plan; 67 + printf("1..%d\n", ksft_plan); 68 + } 69 + 65 70 static inline void ksft_print_cnts(void) 66 71 { 72 + if (ksft_plan != ksft_test_num()) 73 + printf("# Planned tests != run tests (%u != %u)\n", 74 + ksft_plan, ksft_test_num()); 67 75 printf("# Pass %d Fail %d Xfail %d Xpass %d Skip %d Error %d\n", 68 76 ksft_cnt.ksft_pass, ksft_cnt.ksft_fail, 69 77 ksft_cnt.ksft_xfail, ksft_cnt.ksft_xpass, 70 78 ksft_cnt.ksft_xskip, ksft_cnt.ksft_error); 71 - printf("1..%d\n", ksft_test_num()); 72 79 } 73 80 74 81 static inline void ksft_print_msg(const char *msg, ...) ··· 181 172 va_list args; 182 173 183 174 va_start(args, msg); 184 - printf("not ok %d # SKIP ", ksft_test_num()); 175 + printf("not ok %d # SKIP ", 1 + ksft_test_num()); 185 176 vprintf(msg, args); 186 177 va_end(args); 187 178 } else {
+1
tools/testing/selftests/membarrier/membarrier_test.c
··· 304 304 int main(int argc, char **argv) 305 305 { 306 306 ksft_print_header(); 307 + ksft_set_plan(13); 307 308 308 309 test_membarrier_query(); 309 310 test_membarrier();
+1
tools/testing/selftests/pidfd/pidfd_test.c
··· 371 371 int main(int argc, char **argv) 372 372 { 373 373 ksft_print_header(); 374 + ksft_set_plan(4); 374 375 375 376 test_pidfd_send_signal_syscall_support(); 376 377 test_pidfd_send_signal_simple_success();
+1
tools/testing/selftests/sigaltstack/sas.c
··· 109 109 int err; 110 110 111 111 ksft_print_header(); 112 + ksft_set_plan(3); 112 113 113 114 sigemptyset(&act.sa_mask); 114 115 act.sa_flags = SA_ONSTACK | SA_SIGINFO;
+1
tools/testing/selftests/sync/sync_test.c
··· 86 86 int err; 87 87 88 88 ksft_print_header(); 89 + ksft_set_plan(3 + 7); 89 90 90 91 sync_api_supported(); 91 92