Skip to content

Commit 5821ba9

Browse files
keesshuahkh
authored andcommitted
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 <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent f41c322 commit 5821ba9

16 files changed

+48
-8
lines changed

tools/testing/selftests/breakpoints/breakpoint_test.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
#include "../kselftest.h"
2323

24+
#define COUNT_ISN_BPS 4
25+
#define COUNT_WPS 4
2426

2527
/* Breakpoint access modes */
2628
enum {
@@ -220,7 +222,7 @@ static void trigger_tests(void)
220222
if (!local && !global)
221223
continue;
222224

223-
for (i = 0; i < 4; i++) {
225+
for (i = 0; i < COUNT_ISN_BPS; i++) {
224226
dummy_funcs[i]();
225227
check_trapped();
226228
}
@@ -292,7 +294,7 @@ static void launch_instruction_breakpoints(char *buf, int local, int global)
292294
{
293295
int i;
294296

295-
for (i = 0; i < 4; i++) {
297+
for (i = 0; i < COUNT_ISN_BPS; i++) {
296298
set_breakpoint_addr(dummy_funcs[i], i);
297299
toggle_breakpoint(i, BP_X, 1, local, global, 1);
298300
ptrace(PTRACE_CONT, child_pid, NULL, 0);
@@ -314,7 +316,7 @@ static void launch_watchpoints(char *buf, int mode, int len,
314316
else
315317
mode_str = "read";
316318

317-
for (i = 0; i < 4; i++) {
319+
for (i = 0; i < COUNT_WPS; i++) {
318320
set_breakpoint_addr(&dummy_var[i], i);
319321
toggle_breakpoint(i, mode, len, local, global, 1);
320322
ptrace(PTRACE_CONT, child_pid, NULL, 0);
@@ -330,8 +332,15 @@ static void launch_watchpoints(char *buf, int mode, int len,
330332
static void launch_tests(void)
331333
{
332334
char buf[1024];
335+
unsigned int tests = 0;
333336
int len, local, global, i;
334337

338+
tests += 3 * COUNT_ISN_BPS;
339+
tests += sizeof(long) / 2 * 3 * COUNT_WPS;
340+
tests += sizeof(long) / 2 * 3 * COUNT_WPS;
341+
tests += 2;
342+
ksft_set_plan(tests);
343+
335344
/* Instruction breakpoints */
336345
for (local = 0; local < 2; local++) {
337346
for (global = 0; global < 2; global++) {

tools/testing/selftests/breakpoints/breakpoint_test_arm64.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static bool set_watchpoint(pid_t pid, int size, int wp)
118118
return false;
119119
}
120120

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)
122122
{
123123
int status;
124124
siginfo_t siginfo;
@@ -214,6 +214,7 @@ int main(int argc, char **argv)
214214
bool result;
215215

216216
ksft_print_header();
217+
ksft_set_plan(213);
217218

218219
act.sa_handler = sigalrm;
219220
sigemptyset(&act.sa_mask);

tools/testing/selftests/breakpoints/step_after_suspend_test.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ int main(int argc, char **argv)
173173
int opt;
174174
bool do_suspend = true;
175175
bool succeeded = true;
176+
unsigned int tests = 0;
176177
cpu_set_t available_cpus;
177178
int err;
178179
int cpu;
@@ -191,6 +192,13 @@ int main(int argc, char **argv)
191192
}
192193
}
193194

195+
for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
196+
if (!CPU_ISSET(cpu, &available_cpus))
197+
continue;
198+
tests++;
199+
}
200+
ksft_set_plan(tests);
201+
194202
if (do_suspend)
195203
suspend();
196204

tools/testing/selftests/capabilities/test_execve.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,6 @@ int main(int argc, char **argv)
430430
{
431431
char *tmp1, *tmp2, *our_path;
432432

433-
ksft_print_header();
434-
435433
/* Find our path */
436434
tmp1 = strdup(argv[0]);
437435
if (!tmp1)
@@ -445,13 +443,17 @@ int main(int argc, char **argv)
445443
mpid = getpid();
446444

447445
if (fork_wait()) {
446+
ksft_print_header();
447+
ksft_set_plan(12);
448448
ksft_print_msg("[RUN]\t+++ Tests with uid == 0 +++\n");
449449
return do_tests(0, our_path);
450450
}
451451

452452
ksft_print_msg("==================================================\n");
453453

454454
if (fork_wait()) {
455+
ksft_print_header();
456+
ksft_set_plan(9);
455457
ksft_print_msg("[RUN]\t+++ Tests with uid != 0 +++\n");
456458
return do_tests(1, our_path);
457459
}

tools/testing/selftests/futex/functional/futex_requeue_pi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ int main(int argc, char *argv[])
395395
}
396396

397397
ksft_print_header();
398+
ksft_set_plan(1);
398399
ksft_print_msg("%s: Test requeue functionality\n", basename(argv[0]));
399400
ksft_print_msg(
400401
"\tArguments: broadcast=%d locked=%d owner=%d timeout=%ldns\n",

tools/testing/selftests/futex/functional/futex_requeue_pi_mismatched_ops.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ int main(int argc, char *argv[])
7979
}
8080

8181
ksft_print_header();
82+
ksft_set_plan(1);
8283
ksft_print_msg("%s: Detect mismatched requeue_pi operations\n",
8384
basename(argv[0]));
8485

tools/testing/selftests/futex/functional/futex_requeue_pi_signal_restart.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ int main(int argc, char *argv[])
144144
}
145145

146146
ksft_print_header();
147+
ksft_set_plan(1);
147148
ksft_print_msg("%s: Test signal handling during requeue_pi\n",
148149
basename(argv[0]));
149150
ksft_print_msg("\tArguments: <none>\n");

tools/testing/selftests/futex/functional/futex_wait_private_mapped_file.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ int main(int argc, char **argv)
9898
}
9999

100100
ksft_print_header();
101+
ksft_set_plan(1);
101102
ksft_print_msg(
102103
"%s: Test the futex value of private file mappings in FUTEX_WAIT\n",
103104
basename(argv[0]));

tools/testing/selftests/futex/functional/futex_wait_timeout.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ int main(int argc, char *argv[])
6969
}
7070

7171
ksft_print_header();
72+
ksft_set_plan(1);
7273
ksft_print_msg("%s: Block on a futex and wait for timeout\n",
7374
basename(argv[0]));
7475
ksft_print_msg("\tArguments: timeout=%ldns\n", timeout_ns);

tools/testing/selftests/futex/functional/futex_wait_uninitialized_heap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ int main(int argc, char **argv)
100100
}
101101

102102
ksft_print_header();
103+
ksft_set_plan(1);
103104
ksft_print_msg("%s: Test the uninitialized futex value in FUTEX_WAIT\n",
104105
basename(argv[0]));
105106

0 commit comments

Comments
 (0)