Commit 0732d06e authored by Shuah Khan's avatar Shuah Khan

selftests: breakpoints: breakpoint_test_arm64: convert test to use TAP13

Convert breakpoint_test_arm64 output to TAP13 format. Use ksft_* var arg
msg api to include strerror() info. in the output. Change output from
child process to use ksft_print_msg() instead of ksft_exit_* to avoid
double counting tests and ensure parent process does the test counter
incrementing.
Signed-off-by: default avatarShuah Khan <shuahkh@osg.samsung.com>
parent 3fa72f2c
...@@ -43,19 +43,25 @@ static void child(int size, int wr) ...@@ -43,19 +43,25 @@ static void child(int size, int wr)
volatile uint8_t *addr = &var[32 + wr]; volatile uint8_t *addr = &var[32 + wr];
if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) != 0) { if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) != 0) {
perror("ptrace(PTRACE_TRACEME) failed"); ksft_print_msg(
"ptrace(PTRACE_TRACEME) failed: %s\n",
strerror(errno));
_exit(1); _exit(1);
} }
if (raise(SIGSTOP) != 0) { if (raise(SIGSTOP) != 0) {
perror("raise(SIGSTOP) failed"); ksft_print_msg(
"raise(SIGSTOP) failed: %s\n", strerror(errno));
_exit(1); _exit(1);
} }
if ((uintptr_t) addr % size) { if ((uintptr_t) addr % size) {
perror("Wrong address write for the given size\n"); ksft_print_msg(
"Wrong address write for the given size: %s\n",
strerror(errno));
_exit(1); _exit(1);
} }
switch (size) { switch (size) {
case 1: case 1:
*addr = 47; *addr = 47;
...@@ -100,11 +106,14 @@ static bool set_watchpoint(pid_t pid, int size, int wp) ...@@ -100,11 +106,14 @@ static bool set_watchpoint(pid_t pid, int size, int wp)
if (ptrace(PTRACE_SETREGSET, pid, NT_ARM_HW_WATCH, &iov) == 0) if (ptrace(PTRACE_SETREGSET, pid, NT_ARM_HW_WATCH, &iov) == 0)
return true; return true;
if (errno == EIO) { if (errno == EIO)
ksft_exit_skip("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) " ksft_print_msg(
"not supported on this hardware\n"); "ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) not supported on this hardware: %s\n",
} strerror(errno));
perror("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) failed");
ksft_print_msg(
"ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) failed: %s\n",
strerror(errno));
return false; return false;
} }
...@@ -116,7 +125,8 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp) ...@@ -116,7 +125,8 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp)
pid_t wpid; pid_t wpid;
if (pid < 0) { if (pid < 0) {
perror("fork() failed"); ksft_test_result_fail(
"fork() failed: %s\n", strerror(errno));
return false; return false;
} }
if (pid == 0) if (pid == 0)
...@@ -124,15 +134,17 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp) ...@@ -124,15 +134,17 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp)
wpid = waitpid(pid, &status, __WALL); wpid = waitpid(pid, &status, __WALL);
if (wpid != pid) { if (wpid != pid) {
perror("waitpid() failed"); ksft_print_msg(
"waitpid() failed: %s\n", strerror(errno));
return false; return false;
} }
if (!WIFSTOPPED(status)) { if (!WIFSTOPPED(status)) {
printf("child did not stop\n"); ksft_print_msg(
"child did not stop: %s\n", strerror(errno));
return false; return false;
} }
if (WSTOPSIG(status) != SIGSTOP) { if (WSTOPSIG(status) != SIGSTOP) {
printf("child did not stop with SIGSTOP\n"); ksft_print_msg("child did not stop with SIGSTOP\n");
return false; return false;
} }
...@@ -140,42 +152,49 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp) ...@@ -140,42 +152,49 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp)
return false; return false;
if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) { if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) {
perror("ptrace(PTRACE_SINGLESTEP) failed"); ksft_print_msg(
"ptrace(PTRACE_SINGLESTEP) failed: %s\n",
strerror(errno));
return false; return false;
} }
alarm(3); alarm(3);
wpid = waitpid(pid, &status, __WALL); wpid = waitpid(pid, &status, __WALL);
if (wpid != pid) { if (wpid != pid) {
perror("waitpid() failed"); ksft_print_msg(
"waitpid() failed: %s\n", strerror(errno));
return false; return false;
} }
alarm(0); alarm(0);
if (WIFEXITED(status)) { if (WIFEXITED(status)) {
printf("child did not single-step\t"); ksft_print_msg("child did not single-step\n");
return false; return false;
} }
if (!WIFSTOPPED(status)) { if (!WIFSTOPPED(status)) {
printf("child did not stop\n"); ksft_print_msg("child did not stop\n");
return false; return false;
} }
if (WSTOPSIG(status) != SIGTRAP) { if (WSTOPSIG(status) != SIGTRAP) {
printf("child did not stop with SIGTRAP\n"); ksft_print_msg("child did not stop with SIGTRAP\n");
return false; return false;
} }
if (ptrace(PTRACE_GETSIGINFO, pid, NULL, &siginfo) != 0) { if (ptrace(PTRACE_GETSIGINFO, pid, NULL, &siginfo) != 0) {
perror("ptrace(PTRACE_GETSIGINFO)"); ksft_print_msg(
"ptrace(PTRACE_GETSIGINFO): %s\n",
strerror(errno));
return false; return false;
} }
if (siginfo.si_code != TRAP_HWBKPT) { if (siginfo.si_code != TRAP_HWBKPT) {
printf("Unexpected si_code %d\n", siginfo.si_code); ksft_print_msg(
"Unexpected si_code %d\n", siginfo.si_code);
return false; return false;
} }
kill(pid, SIGKILL); kill(pid, SIGKILL);
wpid = waitpid(pid, &status, 0); wpid = waitpid(pid, &status, 0);
if (wpid != pid) { if (wpid != pid) {
perror("waitpid() failed"); ksft_print_msg(
"waitpid() failed: %s\n", strerror(errno));
return false; return false;
} }
return true; return true;
...@@ -193,6 +212,8 @@ int main(int argc, char **argv) ...@@ -193,6 +212,8 @@ int main(int argc, char **argv)
int wr, wp, size; int wr, wp, size;
bool result; bool result;
ksft_print_header();
act.sa_handler = sigalrm; act.sa_handler = sigalrm;
sigemptyset(&act.sa_mask); sigemptyset(&act.sa_mask);
act.sa_flags = 0; act.sa_flags = 0;
...@@ -200,14 +221,16 @@ int main(int argc, char **argv) ...@@ -200,14 +221,16 @@ int main(int argc, char **argv)
for (size = 1; size <= 32; size = size*2) { for (size = 1; size <= 32; size = size*2) {
for (wr = 0; wr <= 32; wr = wr + size) { for (wr = 0; wr <= 32; wr = wr + size) {
for (wp = wr - size; wp <= wr + size; wp = wp + size) { for (wp = wr - size; wp <= wr + size; wp = wp + size) {
printf("Test size = %d write offset = %d watchpoint offset = %d\t", size, wr, wp);
result = run_test(size, MIN(size, 8), wr, wp); result = run_test(size, MIN(size, 8), wr, wp);
if ((result && wr == wp) || (!result && wr != wp)) { if ((result && wr == wp) ||
printf("[OK]\n"); (!result && wr != wp))
ksft_inc_pass_cnt(); ksft_test_result_pass(
} else { "Test size = %d write offset = %d watchpoint offset = %d\n",
printf("[FAILED]\n"); size, wr, wp);
ksft_inc_fail_cnt(); else {
ksft_test_result_fail(
"Test size = %d write offset = %d watchpoint offset = %d\n",
size, wr, wp);
succeeded = false; succeeded = false;
} }
} }
...@@ -215,19 +238,18 @@ int main(int argc, char **argv) ...@@ -215,19 +238,18 @@ int main(int argc, char **argv)
} }
for (size = 1; size <= 32; size = size*2) { for (size = 1; size <= 32; size = size*2) {
printf("Test size = %d write offset = %d watchpoint offset = -8\t", size, -size); if (run_test(size, 8, -size, -8))
ksft_test_result_pass(
if (run_test(size, 8, -size, -8)) { "Test size = %d write offset = %d watchpoint offset = -8\n",
printf("[OK]\n"); size, -size);
ksft_inc_pass_cnt(); else {
} else { ksft_test_result_fail(
printf("[FAILED]\n"); "Test size = %d write offset = %d watchpoint offset = -8\n",
ksft_inc_fail_cnt(); size, -size);
succeeded = false; succeeded = false;
} }
} }
ksft_print_cnts();
if (succeeded) if (succeeded)
ksft_exit_pass(); ksft_exit_pass();
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment