aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorShuah Khan <shuahkh@osg.samsung.com>2017-06-29 17:52:42 -0400
committerShuah Khan <shuahkh@osg.samsung.com>2017-06-30 18:16:17 -0400
commit0732d06ee563bbcdf34ec889918baa62451b580d (patch)
treec4b9938d7953b63f42e0ac64b6a2e7e96d72e292 /tools
parent3fa72f2c784b5c05f271ab8b34116d6a8e8d108d (diff)
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: Shuah Khan <shuahkh@osg.samsung.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/breakpoints/breakpoint_test_arm64.c94
1 files changed, 58 insertions, 36 deletions
diff --git a/tools/testing/selftests/breakpoints/breakpoint_test_arm64.c b/tools/testing/selftests/breakpoints/breakpoint_test_arm64.c
index fa6d57af5217..960d02100c26 100644
--- a/tools/testing/selftests/breakpoints/breakpoint_test_arm64.c
+++ b/tools/testing/selftests/breakpoints/breakpoint_test_arm64.c
@@ -43,19 +43,25 @@ static void child(int size, int wr)
43 volatile uint8_t *addr = &var[32 + wr]; 43 volatile uint8_t *addr = &var[32 + wr];
44 44
45 if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) != 0) { 45 if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) != 0) {
46 perror("ptrace(PTRACE_TRACEME) failed"); 46 ksft_print_msg(
47 "ptrace(PTRACE_TRACEME) failed: %s\n",
48 strerror(errno));
47 _exit(1); 49 _exit(1);
48 } 50 }
49 51
50 if (raise(SIGSTOP) != 0) { 52 if (raise(SIGSTOP) != 0) {
51 perror("raise(SIGSTOP) failed"); 53 ksft_print_msg(
54 "raise(SIGSTOP) failed: %s\n", strerror(errno));
52 _exit(1); 55 _exit(1);
53 } 56 }
54 57
55 if ((uintptr_t) addr % size) { 58 if ((uintptr_t) addr % size) {
56 perror("Wrong address write for the given size\n"); 59 ksft_print_msg(
60 "Wrong address write for the given size: %s\n",
61 strerror(errno));
57 _exit(1); 62 _exit(1);
58 } 63 }
64
59 switch (size) { 65 switch (size) {
60 case 1: 66 case 1:
61 *addr = 47; 67 *addr = 47;
@@ -100,11 +106,14 @@ static bool set_watchpoint(pid_t pid, int size, int wp)
100 if (ptrace(PTRACE_SETREGSET, pid, NT_ARM_HW_WATCH, &iov) == 0) 106 if (ptrace(PTRACE_SETREGSET, pid, NT_ARM_HW_WATCH, &iov) == 0)
101 return true; 107 return true;
102 108
103 if (errno == EIO) { 109 if (errno == EIO)
104 ksft_exit_skip("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) " 110 ksft_print_msg(
105 "not supported on this hardware\n"); 111 "ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) not supported on this hardware: %s\n",
106 } 112 strerror(errno));
107 perror("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) failed"); 113
114 ksft_print_msg(
115 "ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) failed: %s\n",
116 strerror(errno));
108 return false; 117 return false;
109} 118}
110 119
@@ -116,7 +125,8 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp)
116 pid_t wpid; 125 pid_t wpid;
117 126
118 if (pid < 0) { 127 if (pid < 0) {
119 perror("fork() failed"); 128 ksft_test_result_fail(
129 "fork() failed: %s\n", strerror(errno));
120 return false; 130 return false;
121 } 131 }
122 if (pid == 0) 132 if (pid == 0)
@@ -124,15 +134,17 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp)
124 134
125 wpid = waitpid(pid, &status, __WALL); 135 wpid = waitpid(pid, &status, __WALL);
126 if (wpid != pid) { 136 if (wpid != pid) {
127 perror("waitpid() failed"); 137 ksft_print_msg(
138 "waitpid() failed: %s\n", strerror(errno));
128 return false; 139 return false;
129 } 140 }
130 if (!WIFSTOPPED(status)) { 141 if (!WIFSTOPPED(status)) {
131 printf("child did not stop\n"); 142 ksft_print_msg(
143 "child did not stop: %s\n", strerror(errno));
132 return false; 144 return false;
133 } 145 }
134 if (WSTOPSIG(status) != SIGSTOP) { 146 if (WSTOPSIG(status) != SIGSTOP) {
135 printf("child did not stop with SIGSTOP\n"); 147 ksft_print_msg("child did not stop with SIGSTOP\n");
136 return false; 148 return false;
137 } 149 }
138 150
@@ -140,42 +152,49 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp)
140 return false; 152 return false;
141 153
142 if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) { 154 if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) {
143 perror("ptrace(PTRACE_SINGLESTEP) failed"); 155 ksft_print_msg(
156 "ptrace(PTRACE_SINGLESTEP) failed: %s\n",
157 strerror(errno));
144 return false; 158 return false;
145 } 159 }
146 160
147 alarm(3); 161 alarm(3);
148 wpid = waitpid(pid, &status, __WALL); 162 wpid = waitpid(pid, &status, __WALL);
149 if (wpid != pid) { 163 if (wpid != pid) {
150 perror("waitpid() failed"); 164 ksft_print_msg(
165 "waitpid() failed: %s\n", strerror(errno));
151 return false; 166 return false;
152 } 167 }
153 alarm(0); 168 alarm(0);
154 if (WIFEXITED(status)) { 169 if (WIFEXITED(status)) {
155 printf("child did not single-step\t"); 170 ksft_print_msg("child did not single-step\n");
156 return false; 171 return false;
157 } 172 }
158 if (!WIFSTOPPED(status)) { 173 if (!WIFSTOPPED(status)) {
159 printf("child did not stop\n"); 174 ksft_print_msg("child did not stop\n");
160 return false; 175 return false;
161 } 176 }
162 if (WSTOPSIG(status) != SIGTRAP) { 177 if (WSTOPSIG(status) != SIGTRAP) {
163 printf("child did not stop with SIGTRAP\n"); 178 ksft_print_msg("child did not stop with SIGTRAP\n");
164 return false; 179 return false;
165 } 180 }
166 if (ptrace(PTRACE_GETSIGINFO, pid, NULL, &siginfo) != 0) { 181 if (ptrace(PTRACE_GETSIGINFO, pid, NULL, &siginfo) != 0) {
167 perror("ptrace(PTRACE_GETSIGINFO)"); 182 ksft_print_msg(
183 "ptrace(PTRACE_GETSIGINFO): %s\n",
184 strerror(errno));
168 return false; 185 return false;
169 } 186 }
170 if (siginfo.si_code != TRAP_HWBKPT) { 187 if (siginfo.si_code != TRAP_HWBKPT) {
171 printf("Unexpected si_code %d\n", siginfo.si_code); 188 ksft_print_msg(
189 "Unexpected si_code %d\n", siginfo.si_code);
172 return false; 190 return false;
173 } 191 }
174 192
175 kill(pid, SIGKILL); 193 kill(pid, SIGKILL);
176 wpid = waitpid(pid, &status, 0); 194 wpid = waitpid(pid, &status, 0);
177 if (wpid != pid) { 195 if (wpid != pid) {
178 perror("waitpid() failed"); 196 ksft_print_msg(
197 "waitpid() failed: %s\n", strerror(errno));
179 return false; 198 return false;
180 } 199 }
181 return true; 200 return true;
@@ -193,6 +212,8 @@ int main(int argc, char **argv)
193 int wr, wp, size; 212 int wr, wp, size;
194 bool result; 213 bool result;
195 214
215 ksft_print_header();
216
196 act.sa_handler = sigalrm; 217 act.sa_handler = sigalrm;
197 sigemptyset(&act.sa_mask); 218 sigemptyset(&act.sa_mask);
198 act.sa_flags = 0; 219 act.sa_flags = 0;
@@ -200,14 +221,16 @@ int main(int argc, char **argv)
200 for (size = 1; size <= 32; size = size*2) { 221 for (size = 1; size <= 32; size = size*2) {
201 for (wr = 0; wr <= 32; wr = wr + size) { 222 for (wr = 0; wr <= 32; wr = wr + size) {
202 for (wp = wr - size; wp <= wr + size; wp = wp + size) { 223 for (wp = wr - size; wp <= wr + size; wp = wp + size) {
203 printf("Test size = %d write offset = %d watchpoint offset = %d\t", size, wr, wp);
204 result = run_test(size, MIN(size, 8), wr, wp); 224 result = run_test(size, MIN(size, 8), wr, wp);
205 if ((result && wr == wp) || (!result && wr != wp)) { 225 if ((result && wr == wp) ||
206 printf("[OK]\n"); 226 (!result && wr != wp))
207 ksft_inc_pass_cnt(); 227 ksft_test_result_pass(
208 } else { 228 "Test size = %d write offset = %d watchpoint offset = %d\n",
209 printf("[FAILED]\n"); 229 size, wr, wp);
210 ksft_inc_fail_cnt(); 230 else {
231 ksft_test_result_fail(
232 "Test size = %d write offset = %d watchpoint offset = %d\n",
233 size, wr, wp);
211 succeeded = false; 234 succeeded = false;
212 } 235 }
213 } 236 }
@@ -215,19 +238,18 @@ int main(int argc, char **argv)
215 } 238 }
216 239
217 for (size = 1; size <= 32; size = size*2) { 240 for (size = 1; size <= 32; size = size*2) {
218 printf("Test size = %d write offset = %d watchpoint offset = -8\t", size, -size); 241 if (run_test(size, 8, -size, -8))
219 242 ksft_test_result_pass(
220 if (run_test(size, 8, -size, -8)) { 243 "Test size = %d write offset = %d watchpoint offset = -8\n",
221 printf("[OK]\n"); 244 size, -size);
222 ksft_inc_pass_cnt(); 245 else {
223 } else { 246 ksft_test_result_fail(
224 printf("[FAILED]\n"); 247 "Test size = %d write offset = %d watchpoint offset = -8\n",
225 ksft_inc_fail_cnt(); 248 size, -size);
226 succeeded = false; 249 succeeded = false;
227 } 250 }
228 } 251 }
229 252
230 ksft_print_cnts();
231 if (succeeded) 253 if (succeeded)
232 ksft_exit_pass(); 254 ksft_exit_pass();
233 else 255 else