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@xxxxxxxxxxxxxxx> --- .../selftests/breakpoints/breakpoint_test.c | 28 ++++++++++++---------- 1 file 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 @@ #include <signal.h> #include <sys/types.h> #include <sys/wait.h> +#include <errno.h> +#include <string.h> #include "../kselftest.h" @@ -43,7 +45,8 @@ static void set_breakpoint_addr(void *addr, int n) ret = ptrace(PTRACE_POKEUSER, child_pid, offsetof(struct user, u_debugreg[n]), addr); if (ret) - ksft_exit_fail_msg("Can't set breakpoint addr"); + ksft_exit_fail_msg("Can't set breakpoint addr: %s\n", + strerror(errno)); } static void toggle_breakpoint(int n, int type, int len, @@ -103,8 +106,10 @@ static void toggle_breakpoint(int n, int type, int len, ret = ptrace(PTRACE_POKEUSER, child_pid, offsetof(struct user, u_debugreg[7]), dr7); - if (ret) - ksft_exit_fail_msg("Can't set dr7"); + if (ret) { + ksft_print_msg("Can't set dr7: %s\n", strerror(errno)); + exit(-1); + } } /* Dummy variables to test read/write accesses */ @@ -202,7 +207,7 @@ static void trigger_tests(void) ret = ptrace(PTRACE_TRACEME, 0, NULL, 0); if (ret) { - perror("Can't be traced?\n"); + ksft_print_msg("Can't be traced? %s\n", strerror(errno)); return; } @@ -257,7 +262,6 @@ static void trigger_tests(void) static void check_success(const char *msg) { - const char *msg2; int child_nr_tests; int status; int ret; @@ -265,7 +269,6 @@ static void check_success(const char *msg) /* Wait for the child to SIGTRAP */ wait(&status); - msg2 = "Failed"; ret = 0; if (WSTOPSIG(status) == SIGTRAP) { @@ -274,7 +277,7 @@ static void check_success(const char *msg) if (child_nr_tests == nr_tests) ret = 1; if (ptrace(PTRACE_POKEDATA, child_pid, &trapped, 1)) - ksft_exit_fail_msg("Can't poke"); + ksft_exit_fail_msg("Can't poke: %s\n", strerror(errno)); } nr_tests++; @@ -293,7 +296,7 @@ static void launch_instruction_breakpoints(char *buf, int local, int global) set_breakpoint_addr(dummy_funcs[i], i); toggle_breakpoint(i, BP_X, 1, local, global, 1); ptrace(PTRACE_CONT, child_pid, NULL, 0); - sprintf(buf, "Test breakpoint %d with local: %d global: %d", + sprintf(buf, "Test breakpoint %d with local: %d global: %d\n", i, local, global); check_success(buf); toggle_breakpoint(i, BP_X, 1, local, global, 0); @@ -315,8 +318,9 @@ static void launch_watchpoints(char *buf, int mode, int len, set_breakpoint_addr(&dummy_var[i], i); toggle_breakpoint(i, mode, len, local, global, 1); ptrace(PTRACE_CONT, child_pid, NULL, 0); - sprintf(buf, "Test %s watchpoint %d with len: %d local: " - "%d global: %d", mode_str, i, len, local, global); + sprintf(buf, + "Test %s watchpoint %d with len: %d local: %d global: %d\n", + mode_str, i, len, local, global); check_success(buf); toggle_breakpoint(i, mode, len, local, global, 0); } @@ -382,7 +386,7 @@ int main(int argc, char **argv) pid = fork(); if (!pid) { trigger_tests(); - return 0; + exit(0); } child_pid = pid; @@ -393,5 +397,5 @@ int main(int argc, char **argv) wait(NULL); - return ksft_exit_pass(); + ksft_exit_pass(); } -- 2.11.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html