#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <errno.h>
+#include <string.h>
#include "../kselftest.h"
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,
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 */
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;
}
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) {
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++;
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);
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);
}
pid = fork();
if (!pid) {
trigger_tests();
- return 0;
+ exit(0);
}
child_pid = pid;
wait(NULL);
- return ksft_exit_pass();
+ ksft_exit_pass();
}