summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/breakpoints/breakpoint_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/testing/selftests/breakpoints/breakpoint_test.c')
-rw-r--r--tools/testing/selftests/breakpoints/breakpoint_test.c45
1 files changed, 25 insertions, 20 deletions
diff --git a/tools/testing/selftests/breakpoints/breakpoint_test.c b/tools/testing/selftests/breakpoints/breakpoint_test.c
index 120895ab5505..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"
@@ -42,10 +44,9 @@ static void set_breakpoint_addr(void *addr, int n)
ret = ptrace(PTRACE_POKEUSER, child_pid,
offsetof(struct user, u_debugreg[n]), addr);
- if (ret) {
- perror("Can't set breakpoint addr\n");
- ksft_exit_fail();
- }
+ if (ret)
+ ksft_exit_fail_msg("Can't set breakpoint addr: %s\n",
+ strerror(errno));
}
static void toggle_breakpoint(int n, int type, int len,
@@ -106,8 +107,8 @@ 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) {
- perror("Can't set dr7");
- ksft_exit_fail();
+ ksft_print_msg("Can't set dr7: %s\n", strerror(errno));
+ exit(-1);
}
}
@@ -206,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;
}
@@ -261,29 +262,30 @@ static void trigger_tests(void)
static void check_success(const char *msg)
{
- const char *msg2;
int child_nr_tests;
int status;
+ int ret;
/* Wait for the child to SIGTRAP */
wait(&status);
- msg2 = "Failed";
+ ret = 0;
if (WSTOPSIG(status) == SIGTRAP) {
child_nr_tests = ptrace(PTRACE_PEEKDATA, child_pid,
&nr_tests, 0);
if (child_nr_tests == nr_tests)
- msg2 = "Ok";
- if (ptrace(PTRACE_POKEDATA, child_pid, &trapped, 1)) {
- perror("Can't poke\n");
- ksft_exit_fail();
- }
+ ret = 1;
+ if (ptrace(PTRACE_POKEDATA, child_pid, &trapped, 1))
+ ksft_exit_fail_msg("Can't poke: %s\n", strerror(errno));
}
nr_tests++;
- printf("%s [%s]\n", msg, msg2);
+ if (ret)
+ ksft_test_result_pass(msg);
+ else
+ ksft_test_result_fail(msg);
}
static void launch_instruction_breakpoints(char *buf, int local, int global)
@@ -294,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);
@@ -316,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);
}
@@ -378,10 +381,12 @@ int main(int argc, char **argv)
pid_t pid;
int ret;
+ ksft_print_header();
+
pid = fork();
if (!pid) {
trigger_tests();
- return 0;
+ exit(0);
}
child_pid = pid;
@@ -392,5 +397,5 @@ int main(int argc, char **argv)
wait(NULL);
- return ksft_exit_pass();
+ ksft_exit_pass();
}