diff options
| author | Shuah Khan <shuahkh@osg.samsung.com> | 2017-06-29 17:37:05 -0400 |
|---|---|---|
| committer | Shuah Khan <shuahkh@osg.samsung.com> | 2017-06-30 18:16:10 -0400 |
| commit | 3fa72f2c784b5c05f271ab8b34116d6a8e8d108d (patch) | |
| tree | 1fe2486993cbbf5b35f0c85ed9cf9dcec17ec1f5 /tools/testing | |
| parent | 4ca562878b907e34fdb652c3a8cb631fd5efe706 (diff) | |
selftests: breakpoints: step_after_suspend_test use ksft_* var arg msg api
Use ksft_* var arg msg to include strerror() info. in test output and
simplify test_result and exit_* using var arg msg api.
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Diffstat (limited to 'tools/testing')
| -rw-r--r-- | tools/testing/selftests/breakpoints/step_after_suspend_test.c | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/tools/testing/selftests/breakpoints/step_after_suspend_test.c b/tools/testing/selftests/breakpoints/step_after_suspend_test.c index c60c2effb6bc..3fece06e9f64 100644 --- a/tools/testing/selftests/breakpoints/step_after_suspend_test.c +++ b/tools/testing/selftests/breakpoints/step_after_suspend_test.c | |||
| @@ -37,17 +37,19 @@ void child(int cpu) | |||
| 37 | CPU_ZERO(&set); | 37 | CPU_ZERO(&set); |
| 38 | CPU_SET(cpu, &set); | 38 | CPU_SET(cpu, &set); |
| 39 | if (sched_setaffinity(0, sizeof(set), &set) != 0) { | 39 | if (sched_setaffinity(0, sizeof(set), &set) != 0) { |
| 40 | perror("sched_setaffinity() failed"); | 40 | ksft_print_msg("sched_setaffinity() failed: %s\n", |
| 41 | strerror(errno)); | ||
| 41 | _exit(1); | 42 | _exit(1); |
| 42 | } | 43 | } |
| 43 | 44 | ||
| 44 | if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) != 0) { | 45 | if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) != 0) { |
| 45 | perror("ptrace(PTRACE_TRACEME) failed"); | 46 | ksft_print_msg("ptrace(PTRACE_TRACEME) failed: %s\n", |
| 47 | strerror(errno)); | ||
| 46 | _exit(1); | 48 | _exit(1); |
| 47 | } | 49 | } |
| 48 | 50 | ||
| 49 | if (raise(SIGSTOP) != 0) { | 51 | if (raise(SIGSTOP) != 0) { |
| 50 | perror("raise(SIGSTOP) failed"); | 52 | ksft_print_msg("raise(SIGSTOP) failed: %s\n", strerror(errno)); |
| 51 | _exit(1); | 53 | _exit(1); |
| 52 | } | 54 | } |
| 53 | 55 | ||
| @@ -61,7 +63,7 @@ bool run_test(int cpu) | |||
| 61 | pid_t wpid; | 63 | pid_t wpid; |
| 62 | 64 | ||
| 63 | if (pid < 0) { | 65 | if (pid < 0) { |
| 64 | perror("fork() failed"); | 66 | ksft_print_msg("fork() failed: %s\n", strerror(errno)); |
| 65 | return false; | 67 | return false; |
| 66 | } | 68 | } |
| 67 | if (pid == 0) | 69 | if (pid == 0) |
| @@ -69,57 +71,64 @@ bool run_test(int cpu) | |||
| 69 | 71 | ||
| 70 | wpid = waitpid(pid, &status, __WALL); | 72 | wpid = waitpid(pid, &status, __WALL); |
| 71 | if (wpid != pid) { | 73 | if (wpid != pid) { |
| 72 | perror("waitpid() failed"); | 74 | ksft_print_msg("waitpid() failed: %s\n", strerror(errno)); |
| 73 | return false; | 75 | return false; |
| 74 | } | 76 | } |
| 75 | if (!WIFSTOPPED(status)) { | 77 | if (!WIFSTOPPED(status)) { |
| 76 | printf("child did not stop\n"); | 78 | ksft_print_msg("child did not stop: %s\n", strerror(errno)); |
| 77 | return false; | 79 | return false; |
| 78 | } | 80 | } |
| 79 | if (WSTOPSIG(status) != SIGSTOP) { | 81 | if (WSTOPSIG(status) != SIGSTOP) { |
| 80 | printf("child did not stop with SIGSTOP\n"); | 82 | ksft_print_msg("child did not stop with SIGSTOP: %s\n", |
| 83 | strerror(errno)); | ||
| 81 | return false; | 84 | return false; |
| 82 | } | 85 | } |
| 83 | 86 | ||
| 84 | if (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) < 0) { | 87 | if (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) < 0) { |
| 85 | if (errno == EIO) { | 88 | if (errno == EIO) { |
| 86 | ksft_exit_skip("ptrace(PTRACE_SINGLESTEP) " | 89 | ksft_exit_skip( |
| 87 | "not supported on this architecture"); | 90 | "ptrace(PTRACE_SINGLESTEP) not supported on this architecture: %s\n", |
| 91 | strerror(errno)); | ||
| 88 | } | 92 | } |
| 89 | perror("ptrace(PTRACE_SINGLESTEP) failed"); | 93 | ksft_print_msg("ptrace(PTRACE_SINGLESTEP) failed: %s\n", |
| 94 | strerror(errno)); | ||
| 90 | return false; | 95 | return false; |
| 91 | } | 96 | } |
| 92 | 97 | ||
| 93 | wpid = waitpid(pid, &status, __WALL); | 98 | wpid = waitpid(pid, &status, __WALL); |
| 94 | if (wpid != pid) { | 99 | if (wpid != pid) { |
| 95 | perror("waitpid() failed"); | 100 | ksft_print_msg("waitpid() failed: $s\n", strerror(errno)); |
| 96 | return false; | 101 | return false; |
| 97 | } | 102 | } |
| 98 | if (WIFEXITED(status)) { | 103 | if (WIFEXITED(status)) { |
| 99 | printf("child did not single-step\n"); | 104 | ksft_print_msg("child did not single-step: %s\n", |
| 105 | strerror(errno)); | ||
| 100 | return false; | 106 | return false; |
| 101 | } | 107 | } |
| 102 | if (!WIFSTOPPED(status)) { | 108 | if (!WIFSTOPPED(status)) { |
| 103 | printf("child did not stop\n"); | 109 | ksft_print_msg("child did not stop: %s\n", strerror(errno)); |
| 104 | return false; | 110 | return false; |
| 105 | } | 111 | } |
| 106 | if (WSTOPSIG(status) != SIGTRAP) { | 112 | if (WSTOPSIG(status) != SIGTRAP) { |
| 107 | printf("child did not stop with SIGTRAP\n"); | 113 | ksft_print_msg("child did not stop with SIGTRAP: %s\n", |
| 114 | strerror(errno)); | ||
| 108 | return false; | 115 | return false; |
| 109 | } | 116 | } |
| 110 | 117 | ||
| 111 | if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) { | 118 | if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) { |
| 112 | perror("ptrace(PTRACE_CONT) failed"); | 119 | ksft_print_msg("ptrace(PTRACE_CONT) failed: %s\n", |
| 120 | strerror(errno)); | ||
| 113 | return false; | 121 | return false; |
| 114 | } | 122 | } |
| 115 | 123 | ||
| 116 | wpid = waitpid(pid, &status, __WALL); | 124 | wpid = waitpid(pid, &status, __WALL); |
| 117 | if (wpid != pid) { | 125 | if (wpid != pid) { |
| 118 | perror("waitpid() failed"); | 126 | ksft_print_msg("waitpid() failed: %s\n", strerror(errno)); |
| 119 | return false; | 127 | return false; |
| 120 | } | 128 | } |
| 121 | if (!WIFEXITED(status)) { | 129 | if (!WIFEXITED(status)) { |
| 122 | printf("child did not exit after PTRACE_CONT\n"); | 130 | ksft_print_msg("child did not exit after PTRACE_CONT: %s\n", |
| 131 | strerror(errno)); | ||
| 123 | return false; | 132 | return false; |
| 124 | } | 133 | } |
| 125 | 134 | ||
| @@ -137,19 +146,19 @@ void suspend(void) | |||
| 137 | power_state_fd = open("/sys/power/state", O_RDWR); | 146 | power_state_fd = open("/sys/power/state", O_RDWR); |
| 138 | if (power_state_fd < 0) | 147 | if (power_state_fd < 0) |
| 139 | ksft_exit_fail_msg( | 148 | ksft_exit_fail_msg( |
| 140 | "open(\"/sys/power/state\") failed (is this test running as root?)"); | 149 | "open(\"/sys/power/state\") failed (is this test running as root?)\n"); |
| 141 | 150 | ||
| 142 | timerfd = timerfd_create(CLOCK_BOOTTIME_ALARM, 0); | 151 | timerfd = timerfd_create(CLOCK_BOOTTIME_ALARM, 0); |
| 143 | if (timerfd < 0) | 152 | if (timerfd < 0) |
| 144 | ksft_exit_fail_msg("timerfd_create() failed"); | 153 | ksft_exit_fail_msg("timerfd_create() failed\n"); |
| 145 | 154 | ||
| 146 | spec.it_value.tv_sec = 5; | 155 | spec.it_value.tv_sec = 5; |
| 147 | err = timerfd_settime(timerfd, 0, &spec, NULL); | 156 | err = timerfd_settime(timerfd, 0, &spec, NULL); |
| 148 | if (err < 0) | 157 | if (err < 0) |
| 149 | ksft_exit_fail_msg("timerfd_settime() failed"); | 158 | ksft_exit_fail_msg("timerfd_settime() failed\n"); |
| 150 | 159 | ||
| 151 | if (write(power_state_fd, "mem", strlen("mem")) != strlen("mem")) | 160 | if (write(power_state_fd, "mem", strlen("mem")) != strlen("mem")) |
| 152 | ksft_exit_fail_msg("entering suspend failed"); | 161 | ksft_exit_fail_msg("Failed to enter Suspend state\n"); |
| 153 | 162 | ||
| 154 | close(timerfd); | 163 | close(timerfd); |
| 155 | close(power_state_fd); | 164 | close(power_state_fd); |
| @@ -163,7 +172,6 @@ int main(int argc, char **argv) | |||
| 163 | cpu_set_t available_cpus; | 172 | cpu_set_t available_cpus; |
| 164 | int err; | 173 | int err; |
| 165 | int cpu; | 174 | int cpu; |
| 166 | char buf[10]; | ||
| 167 | 175 | ||
| 168 | ksft_print_header(); | 176 | ksft_print_header(); |
| 169 | 177 | ||
| @@ -184,7 +192,7 @@ int main(int argc, char **argv) | |||
| 184 | 192 | ||
| 185 | err = sched_getaffinity(0, sizeof(available_cpus), &available_cpus); | 193 | err = sched_getaffinity(0, sizeof(available_cpus), &available_cpus); |
| 186 | if (err < 0) | 194 | if (err < 0) |
| 187 | ksft_exit_fail_msg("sched_getaffinity() failed"); | 195 | ksft_exit_fail_msg("sched_getaffinity() failed\n"); |
| 188 | 196 | ||
| 189 | for (cpu = 0; cpu < CPU_SETSIZE; cpu++) { | 197 | for (cpu = 0; cpu < CPU_SETSIZE; cpu++) { |
| 190 | bool test_success; | 198 | bool test_success; |
| @@ -193,11 +201,10 @@ int main(int argc, char **argv) | |||
| 193 | continue; | 201 | continue; |
| 194 | 202 | ||
| 195 | test_success = run_test(cpu); | 203 | test_success = run_test(cpu); |
| 196 | sprintf(buf, "CPU %d", cpu); | ||
| 197 | if (test_success) { | 204 | if (test_success) { |
| 198 | ksft_test_result_pass(buf); | 205 | ksft_test_result_pass("CPU %d\n", cpu); |
| 199 | } else { | 206 | } else { |
| 200 | ksft_test_result_fail(buf); | 207 | ksft_test_result_fail("CPU %d\n", cpu); |
| 201 | succeeded = false; | 208 | succeeded = false; |
| 202 | } | 209 | } |
| 203 | } | 210 | } |
