hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/tools/testing/selftests/breakpoints/step_after_suspend_test.c
....@@ -1,15 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2016 Google, Inc.
3
- *
4
- * This software is licensed under the terms of the GNU General Public
5
- * License version 2, as published by the Free Software Foundation, and
6
- * may be copied, distributed, and modified under those terms.
7
- *
8
- * This program is distributed in the hope that it will be useful,
9
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- * GNU General Public License for more details.
12
- *
134 */
145
156 #define _GNU_SOURCE
....@@ -56,7 +47,7 @@
5647 _exit(0);
5748 }
5849
59
-bool run_test(int cpu)
50
+int run_test(int cpu)
6051 {
6152 int status;
6253 pid_t pid = fork();
....@@ -64,7 +55,7 @@
6455
6556 if (pid < 0) {
6657 ksft_print_msg("fork() failed: %s\n", strerror(errno));
67
- return false;
58
+ return KSFT_FAIL;
6859 }
6960 if (pid == 0)
7061 child(cpu);
....@@ -72,67 +63,68 @@
7263 wpid = waitpid(pid, &status, __WALL);
7364 if (wpid != pid) {
7465 ksft_print_msg("waitpid() failed: %s\n", strerror(errno));
75
- return false;
66
+ return KSFT_FAIL;
7667 }
7768 if (!WIFSTOPPED(status)) {
7869 ksft_print_msg("child did not stop: %s\n", strerror(errno));
79
- return false;
70
+ return KSFT_FAIL;
8071 }
8172 if (WSTOPSIG(status) != SIGSTOP) {
8273 ksft_print_msg("child did not stop with SIGSTOP: %s\n",
8374 strerror(errno));
84
- return false;
75
+ return KSFT_FAIL;
8576 }
8677
8778 if (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) < 0) {
8879 if (errno == EIO) {
89
- ksft_exit_skip(
80
+ ksft_print_msg(
9081 "ptrace(PTRACE_SINGLESTEP) not supported on this architecture: %s\n",
9182 strerror(errno));
83
+ return KSFT_SKIP;
9284 }
9385 ksft_print_msg("ptrace(PTRACE_SINGLESTEP) failed: %s\n",
9486 strerror(errno));
95
- return false;
87
+ return KSFT_FAIL;
9688 }
9789
9890 wpid = waitpid(pid, &status, __WALL);
9991 if (wpid != pid) {
10092 ksft_print_msg("waitpid() failed: $s\n", strerror(errno));
101
- return false;
93
+ return KSFT_FAIL;
10294 }
10395 if (WIFEXITED(status)) {
10496 ksft_print_msg("child did not single-step: %s\n",
10597 strerror(errno));
106
- return false;
98
+ return KSFT_FAIL;
10799 }
108100 if (!WIFSTOPPED(status)) {
109101 ksft_print_msg("child did not stop: %s\n", strerror(errno));
110
- return false;
102
+ return KSFT_FAIL;
111103 }
112104 if (WSTOPSIG(status) != SIGTRAP) {
113105 ksft_print_msg("child did not stop with SIGTRAP: %s\n",
114106 strerror(errno));
115
- return false;
107
+ return KSFT_FAIL;
116108 }
117109
118110 if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) {
119111 ksft_print_msg("ptrace(PTRACE_CONT) failed: %s\n",
120112 strerror(errno));
121
- return false;
113
+ return KSFT_FAIL;
122114 }
123115
124116 wpid = waitpid(pid, &status, __WALL);
125117 if (wpid != pid) {
126118 ksft_print_msg("waitpid() failed: %s\n", strerror(errno));
127
- return false;
119
+ return KSFT_FAIL;
128120 }
129121 if (!WIFEXITED(status)) {
130122 ksft_print_msg("child did not exit after PTRACE_CONT: %s\n",
131123 strerror(errno));
132
- return false;
124
+ return KSFT_FAIL;
133125 }
134126
135
- return true;
127
+ return KSFT_PASS;
136128 }
137129
138130 void suspend(void)
....@@ -173,6 +165,7 @@
173165 int opt;
174166 bool do_suspend = true;
175167 bool succeeded = true;
168
+ unsigned int tests = 0;
176169 cpu_set_t available_cpus;
177170 int err;
178171 int cpu;
....@@ -191,25 +184,38 @@
191184 }
192185 }
193186
194
- if (do_suspend)
195
- suspend();
196
-
197187 err = sched_getaffinity(0, sizeof(available_cpus), &available_cpus);
198188 if (err < 0)
199189 ksft_exit_fail_msg("sched_getaffinity() failed\n");
200190
201191 for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
202
- bool test_success;
192
+ if (!CPU_ISSET(cpu, &available_cpus))
193
+ continue;
194
+ tests++;
195
+ }
196
+
197
+ if (do_suspend)
198
+ suspend();
199
+
200
+ ksft_set_plan(tests);
201
+ for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
202
+ int test_success;
203203
204204 if (!CPU_ISSET(cpu, &available_cpus))
205205 continue;
206206
207207 test_success = run_test(cpu);
208
- if (test_success) {
208
+ switch (test_success) {
209
+ case KSFT_PASS:
209210 ksft_test_result_pass("CPU %d\n", cpu);
210
- } else {
211
+ break;
212
+ case KSFT_SKIP:
213
+ ksft_test_result_skip("CPU %d\n", cpu);
214
+ break;
215
+ case KSFT_FAIL:
211216 ksft_test_result_fail("CPU %d\n", cpu);
212217 succeeded = false;
218
+ break;
213219 }
214220 }
215221