Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+33 -26
+33 -26
tools/testing/selftests/breakpoints/step_after_suspend_test.c
··· 37 37 CPU_ZERO(&set); 38 38 CPU_SET(cpu, &set); 39 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 42 _exit(1); 42 43 } 43 44 44 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 48 _exit(1); 47 49 } 48 50 49 51 if (raise(SIGSTOP) != 0) { 50 - perror("raise(SIGSTOP) failed"); 52 + ksft_print_msg("raise(SIGSTOP) failed: %s\n", strerror(errno)); 51 53 _exit(1); 52 54 } 53 55 ··· 63 61 pid_t wpid; 64 62 65 63 if (pid < 0) { 66 - perror("fork() failed"); 64 + ksft_print_msg("fork() failed: %s\n", strerror(errno)); 67 65 return false; 68 66 } 69 67 if (pid == 0) ··· 71 69 72 70 wpid = waitpid(pid, &status, __WALL); 73 71 if (wpid != pid) { 74 - perror("waitpid() failed"); 72 + ksft_print_msg("waitpid() failed: %s\n", strerror(errno)); 75 73 return false; 76 74 } 77 75 if (!WIFSTOPPED(status)) { 78 - printf("child did not stop\n"); 76 + ksft_print_msg("child did not stop: %s\n", strerror(errno)); 79 77 return false; 80 78 } 81 79 if (WSTOPSIG(status) != SIGSTOP) { 82 - printf("child did not stop with SIGSTOP\n"); 80 + ksft_print_msg("child did not stop with SIGSTOP: %s\n", 81 + strerror(errno)); 83 82 return false; 84 83 } 85 84 86 85 if (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) < 0) { 87 86 if (errno == EIO) { 88 - ksft_exit_skip("ptrace(PTRACE_SINGLESTEP) " 89 - "not supported on this architecture"); 87 + ksft_exit_skip( 88 + "ptrace(PTRACE_SINGLESTEP) not supported on this architecture: %s\n", 89 + strerror(errno)); 90 90 } 91 - perror("ptrace(PTRACE_SINGLESTEP) failed"); 91 + ksft_print_msg("ptrace(PTRACE_SINGLESTEP) failed: %s\n", 92 + strerror(errno)); 92 93 return false; 93 94 } 94 95 95 96 wpid = waitpid(pid, &status, __WALL); 96 97 if (wpid != pid) { 97 - perror("waitpid() failed"); 98 + ksft_print_msg("waitpid() failed: $s\n", strerror(errno)); 98 99 return false; 99 100 } 100 101 if (WIFEXITED(status)) { 101 - printf("child did not single-step\n"); 102 + ksft_print_msg("child did not single-step: %s\n", 103 + strerror(errno)); 102 104 return false; 103 105 } 104 106 if (!WIFSTOPPED(status)) { 105 - printf("child did not stop\n"); 107 + ksft_print_msg("child did not stop: %s\n", strerror(errno)); 106 108 return false; 107 109 } 108 110 if (WSTOPSIG(status) != SIGTRAP) { 109 - printf("child did not stop with SIGTRAP\n"); 111 + ksft_print_msg("child did not stop with SIGTRAP: %s\n", 112 + strerror(errno)); 110 113 return false; 111 114 } 112 115 113 116 if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) { 114 - perror("ptrace(PTRACE_CONT) failed"); 117 + ksft_print_msg("ptrace(PTRACE_CONT) failed: %s\n", 118 + strerror(errno)); 115 119 return false; 116 120 } 117 121 118 122 wpid = waitpid(pid, &status, __WALL); 119 123 if (wpid != pid) { 120 - perror("waitpid() failed"); 124 + ksft_print_msg("waitpid() failed: %s\n", strerror(errno)); 121 125 return false; 122 126 } 123 127 if (!WIFEXITED(status)) { 124 - printf("child did not exit after PTRACE_CONT\n"); 128 + ksft_print_msg("child did not exit after PTRACE_CONT: %s\n", 129 + strerror(errno)); 125 130 return false; 126 131 } 127 132 ··· 146 137 power_state_fd = open("/sys/power/state", O_RDWR); 147 138 if (power_state_fd < 0) 148 139 ksft_exit_fail_msg( 149 - "open(\"/sys/power/state\") failed (is this test running as root?)"); 140 + "open(\"/sys/power/state\") failed (is this test running as root?)\n"); 150 141 151 142 timerfd = timerfd_create(CLOCK_BOOTTIME_ALARM, 0); 152 143 if (timerfd < 0) 153 - ksft_exit_fail_msg("timerfd_create() failed"); 144 + ksft_exit_fail_msg("timerfd_create() failed\n"); 154 145 155 146 spec.it_value.tv_sec = 5; 156 147 err = timerfd_settime(timerfd, 0, &spec, NULL); 157 148 if (err < 0) 158 - ksft_exit_fail_msg("timerfd_settime() failed"); 149 + ksft_exit_fail_msg("timerfd_settime() failed\n"); 159 150 160 151 if (write(power_state_fd, "mem", strlen("mem")) != strlen("mem")) 161 - ksft_exit_fail_msg("entering suspend failed"); 152 + ksft_exit_fail_msg("Failed to enter Suspend state\n"); 162 153 163 154 close(timerfd); 164 155 close(power_state_fd); ··· 172 163 cpu_set_t available_cpus; 173 164 int err; 174 165 int cpu; 175 - char buf[10]; 176 166 177 167 ksft_print_header(); 178 168 ··· 192 184 193 185 err = sched_getaffinity(0, sizeof(available_cpus), &available_cpus); 194 186 if (err < 0) 195 - ksft_exit_fail_msg("sched_getaffinity() failed"); 187 + ksft_exit_fail_msg("sched_getaffinity() failed\n"); 196 188 197 189 for (cpu = 0; cpu < CPU_SETSIZE; cpu++) { 198 190 bool test_success; ··· 201 193 continue; 202 194 203 195 test_success = run_test(cpu); 204 - sprintf(buf, "CPU %d", cpu); 205 196 if (test_success) { 206 - ksft_test_result_pass(buf); 197 + ksft_test_result_pass("CPU %d\n", cpu); 207 198 } else { 208 - ksft_test_result_fail(buf); 199 + ksft_test_result_fail("CPU %d\n", cpu); 209 200 succeeded = false; 210 201 } 211 202 }