diff options
author | Shuah Khan <shuahkh@osg.samsung.com> | 2017-06-29 17:19:47 -0400 |
---|---|---|
committer | Shuah Khan <shuahkh@osg.samsung.com> | 2017-06-30 18:15:58 -0400 |
commit | 4ca562878b907e34fdb652c3a8cb631fd5efe706 (patch) | |
tree | a87e77aee2c3e7ec431bf753c2a6a6eeffd3c1f3 /tools | |
parent | ab52a484455007b3c9c11e18f6d0eed6d8f2de4e (diff) |
selftests: breakpoint_test: use ksft_* var arg msg api
Use ksft_* var arg msg to include strerror() info. in test output. Change
output from child process to use ksft_print_msg() instead of ksft_exit_*
to avoid double counting tests and ensure parent does the incrementing
test counters. Also includes unused variable cleanup.
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/testing/selftests/breakpoints/breakpoint_test.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/tools/testing/selftests/breakpoints/breakpoint_test.c b/tools/testing/selftests/breakpoints/breakpoint_test.c index c02fc9a0e228..f63356151ad4 100644 --- a/tools/testing/selftests/breakpoints/breakpoint_test.c +++ b/tools/testing/selftests/breakpoints/breakpoint_test.c | |||
@@ -16,6 +16,8 @@ | |||
16 | #include <signal.h> | 16 | #include <signal.h> |
17 | #include <sys/types.h> | 17 | #include <sys/types.h> |
18 | #include <sys/wait.h> | 18 | #include <sys/wait.h> |
19 | #include <errno.h> | ||
20 | #include <string.h> | ||
19 | 21 | ||
20 | #include "../kselftest.h" | 22 | #include "../kselftest.h" |
21 | 23 | ||
@@ -43,7 +45,8 @@ static void set_breakpoint_addr(void *addr, int n) | |||
43 | ret = ptrace(PTRACE_POKEUSER, child_pid, | 45 | ret = ptrace(PTRACE_POKEUSER, child_pid, |
44 | offsetof(struct user, u_debugreg[n]), addr); | 46 | offsetof(struct user, u_debugreg[n]), addr); |
45 | if (ret) | 47 | if (ret) |
46 | ksft_exit_fail_msg("Can't set breakpoint addr"); | 48 | ksft_exit_fail_msg("Can't set breakpoint addr: %s\n", |
49 | strerror(errno)); | ||
47 | } | 50 | } |
48 | 51 | ||
49 | static void toggle_breakpoint(int n, int type, int len, | 52 | static void toggle_breakpoint(int n, int type, int len, |
@@ -103,8 +106,10 @@ static void toggle_breakpoint(int n, int type, int len, | |||
103 | 106 | ||
104 | ret = ptrace(PTRACE_POKEUSER, child_pid, | 107 | ret = ptrace(PTRACE_POKEUSER, child_pid, |
105 | offsetof(struct user, u_debugreg[7]), dr7); | 108 | offsetof(struct user, u_debugreg[7]), dr7); |
106 | if (ret) | 109 | if (ret) { |
107 | ksft_exit_fail_msg("Can't set dr7"); | 110 | ksft_print_msg("Can't set dr7: %s\n", strerror(errno)); |
111 | exit(-1); | ||
112 | } | ||
108 | } | 113 | } |
109 | 114 | ||
110 | /* Dummy variables to test read/write accesses */ | 115 | /* Dummy variables to test read/write accesses */ |
@@ -202,7 +207,7 @@ static void trigger_tests(void) | |||
202 | 207 | ||
203 | ret = ptrace(PTRACE_TRACEME, 0, NULL, 0); | 208 | ret = ptrace(PTRACE_TRACEME, 0, NULL, 0); |
204 | if (ret) { | 209 | if (ret) { |
205 | perror("Can't be traced?\n"); | 210 | ksft_print_msg("Can't be traced? %s\n", strerror(errno)); |
206 | return; | 211 | return; |
207 | } | 212 | } |
208 | 213 | ||
@@ -257,7 +262,6 @@ static void trigger_tests(void) | |||
257 | 262 | ||
258 | static void check_success(const char *msg) | 263 | static void check_success(const char *msg) |
259 | { | 264 | { |
260 | const char *msg2; | ||
261 | int child_nr_tests; | 265 | int child_nr_tests; |
262 | int status; | 266 | int status; |
263 | int ret; | 267 | int ret; |
@@ -265,7 +269,6 @@ static void check_success(const char *msg) | |||
265 | /* Wait for the child to SIGTRAP */ | 269 | /* Wait for the child to SIGTRAP */ |
266 | wait(&status); | 270 | wait(&status); |
267 | 271 | ||
268 | msg2 = "Failed"; | ||
269 | ret = 0; | 272 | ret = 0; |
270 | 273 | ||
271 | if (WSTOPSIG(status) == SIGTRAP) { | 274 | if (WSTOPSIG(status) == SIGTRAP) { |
@@ -274,7 +277,7 @@ static void check_success(const char *msg) | |||
274 | if (child_nr_tests == nr_tests) | 277 | if (child_nr_tests == nr_tests) |
275 | ret = 1; | 278 | ret = 1; |
276 | if (ptrace(PTRACE_POKEDATA, child_pid, &trapped, 1)) | 279 | if (ptrace(PTRACE_POKEDATA, child_pid, &trapped, 1)) |
277 | ksft_exit_fail_msg("Can't poke"); | 280 | ksft_exit_fail_msg("Can't poke: %s\n", strerror(errno)); |
278 | } | 281 | } |
279 | 282 | ||
280 | nr_tests++; | 283 | nr_tests++; |
@@ -293,7 +296,7 @@ static void launch_instruction_breakpoints(char *buf, int local, int global) | |||
293 | set_breakpoint_addr(dummy_funcs[i], i); | 296 | set_breakpoint_addr(dummy_funcs[i], i); |
294 | toggle_breakpoint(i, BP_X, 1, local, global, 1); | 297 | toggle_breakpoint(i, BP_X, 1, local, global, 1); |
295 | ptrace(PTRACE_CONT, child_pid, NULL, 0); | 298 | ptrace(PTRACE_CONT, child_pid, NULL, 0); |
296 | sprintf(buf, "Test breakpoint %d with local: %d global: %d", | 299 | sprintf(buf, "Test breakpoint %d with local: %d global: %d\n", |
297 | i, local, global); | 300 | i, local, global); |
298 | check_success(buf); | 301 | check_success(buf); |
299 | toggle_breakpoint(i, BP_X, 1, local, global, 0); | 302 | toggle_breakpoint(i, BP_X, 1, local, global, 0); |
@@ -315,8 +318,9 @@ static void launch_watchpoints(char *buf, int mode, int len, | |||
315 | set_breakpoint_addr(&dummy_var[i], i); | 318 | set_breakpoint_addr(&dummy_var[i], i); |
316 | toggle_breakpoint(i, mode, len, local, global, 1); | 319 | toggle_breakpoint(i, mode, len, local, global, 1); |
317 | ptrace(PTRACE_CONT, child_pid, NULL, 0); | 320 | ptrace(PTRACE_CONT, child_pid, NULL, 0); |
318 | sprintf(buf, "Test %s watchpoint %d with len: %d local: " | 321 | sprintf(buf, |
319 | "%d global: %d", mode_str, i, len, local, global); | 322 | "Test %s watchpoint %d with len: %d local: %d global: %d\n", |
323 | mode_str, i, len, local, global); | ||
320 | check_success(buf); | 324 | check_success(buf); |
321 | toggle_breakpoint(i, mode, len, local, global, 0); | 325 | toggle_breakpoint(i, mode, len, local, global, 0); |
322 | } | 326 | } |
@@ -382,7 +386,7 @@ int main(int argc, char **argv) | |||
382 | pid = fork(); | 386 | pid = fork(); |
383 | if (!pid) { | 387 | if (!pid) { |
384 | trigger_tests(); | 388 | trigger_tests(); |
385 | return 0; | 389 | exit(0); |
386 | } | 390 | } |
387 | 391 | ||
388 | child_pid = pid; | 392 | child_pid = pid; |
@@ -393,5 +397,5 @@ int main(int argc, char **argv) | |||
393 | 397 | ||
394 | wait(NULL); | 398 | wait(NULL); |
395 | 399 | ||
396 | return ksft_exit_pass(); | 400 | ksft_exit_pass(); |
397 | } | 401 | } |