Skip to content

Commit f000a39

Browse files
bonzinishuahkh
authored andcommitted
selftests: breakpoints: do not use ksft_exit_skip after ksft_set_plan
Calling ksft_exit_skip after ksft_set_plan results in executing fewer tests than planned. Use ksft_test_result_skip for the individual tests. The call in suspend() is fine, but ksft_set_plan should be after it. Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent ce32659 commit f000a39

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

tools/testing/selftests/breakpoints/step_after_suspend_test.c

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,83 +47,84 @@ void child(int cpu)
4747
_exit(0);
4848
}
4949

50-
bool run_test(int cpu)
50+
int run_test(int cpu)
5151
{
5252
int status;
5353
pid_t pid = fork();
5454
pid_t wpid;
5555

5656
if (pid < 0) {
5757
ksft_print_msg("fork() failed: %s\n", strerror(errno));
58-
return false;
58+
return KSFT_FAIL;
5959
}
6060
if (pid == 0)
6161
child(cpu);
6262

6363
wpid = waitpid(pid, &status, __WALL);
6464
if (wpid != pid) {
6565
ksft_print_msg("waitpid() failed: %s\n", strerror(errno));
66-
return false;
66+
return KSFT_FAIL;
6767
}
6868
if (!WIFSTOPPED(status)) {
6969
ksft_print_msg("child did not stop: %s\n", strerror(errno));
70-
return false;
70+
return KSFT_FAIL;
7171
}
7272
if (WSTOPSIG(status) != SIGSTOP) {
7373
ksft_print_msg("child did not stop with SIGSTOP: %s\n",
7474
strerror(errno));
75-
return false;
75+
return KSFT_FAIL;
7676
}
7777

7878
if (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) < 0) {
7979
if (errno == EIO) {
80-
ksft_exit_skip(
80+
ksft_print_msg(
8181
"ptrace(PTRACE_SINGLESTEP) not supported on this architecture: %s\n",
8282
strerror(errno));
83+
return KSFT_SKIP;
8384
}
8485
ksft_print_msg("ptrace(PTRACE_SINGLESTEP) failed: %s\n",
8586
strerror(errno));
86-
return false;
87+
return KSFT_FAIL;
8788
}
8889

8990
wpid = waitpid(pid, &status, __WALL);
9091
if (wpid != pid) {
9192
ksft_print_msg("waitpid() failed: $s\n", strerror(errno));
92-
return false;
93+
return KSFT_FAIL;
9394
}
9495
if (WIFEXITED(status)) {
9596
ksft_print_msg("child did not single-step: %s\n",
9697
strerror(errno));
97-
return false;
98+
return KSFT_FAIL;
9899
}
99100
if (!WIFSTOPPED(status)) {
100101
ksft_print_msg("child did not stop: %s\n", strerror(errno));
101-
return false;
102+
return KSFT_FAIL;
102103
}
103104
if (WSTOPSIG(status) != SIGTRAP) {
104105
ksft_print_msg("child did not stop with SIGTRAP: %s\n",
105106
strerror(errno));
106-
return false;
107+
return KSFT_FAIL;
107108
}
108109

109110
if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) {
110111
ksft_print_msg("ptrace(PTRACE_CONT) failed: %s\n",
111112
strerror(errno));
112-
return false;
113+
return KSFT_FAIL;
113114
}
114115

115116
wpid = waitpid(pid, &status, __WALL);
116117
if (wpid != pid) {
117118
ksft_print_msg("waitpid() failed: %s\n", strerror(errno));
118-
return false;
119+
return KSFT_FAIL;
119120
}
120121
if (!WIFEXITED(status)) {
121122
ksft_print_msg("child did not exit after PTRACE_CONT: %s\n",
122123
strerror(errno));
123-
return false;
124+
return KSFT_FAIL;
124125
}
125126

126-
return true;
127+
return KSFT_PASS;
127128
}
128129

129130
void suspend(void)
@@ -192,23 +193,29 @@ int main(int argc, char **argv)
192193
continue;
193194
tests++;
194195
}
195-
ksft_set_plan(tests);
196196

197197
if (do_suspend)
198198
suspend();
199199

200+
ksft_set_plan(tests);
200201
for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
201-
bool test_success;
202+
int test_success;
202203

203204
if (!CPU_ISSET(cpu, &available_cpus))
204205
continue;
205206

206207
test_success = run_test(cpu);
207-
if (test_success) {
208+
switch (test_success) {
209+
case KSFT_PASS:
208210
ksft_test_result_pass("CPU %d\n", cpu);
209-
} else {
211+
break;
212+
case KSFT_SKIP:
213+
ksft_test_result_skip("CPU %d\n", cpu);
214+
break;
215+
case KSFT_FAIL:
210216
ksft_test_result_fail("CPU %d\n", cpu);
211217
succeeded = false;
218+
break;
212219
}
213220
}
214221

0 commit comments

Comments
 (0)