diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-09-08 18:11:20 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-09-08 18:11:20 -0400 |
commit | 6d6218976df142ba5594371f8dbd56650151c56f (patch) | |
tree | 601d98860da969062a1c9d4aefe9e54aca228abf /tools | |
parent | 42c8e86c9c3e15ac653c31d57b2f985579c2991d (diff) | |
parent | 369130b63178e0e2f863a2da2a5ad0238ded6d9d (diff) |
Merge tag 'linux-kselftest-4.14-rc1-update' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull kselftest updates from Shuah Khan:
- TAP13 framework API and converting tests to TAP13 continues. A few
more tests are converted and kselftest common RUN_TESTS in lib.mk is
enhanced to print TAP13 to cover test shell scripts that won't be
able to use kselftest API.
- Several fixes to existing tests to not fail in unsupported cases.
This has been an ongoing work based on the feedback from stable
release kselftest users.
- A new watchdog test and much needed cleanups to the existing tests
from Eugeniu Rosca.
- Changes to kselftest common lib.mk framework to make RUN_TESTS a
function to be called from individual test make files to run stress
and destructive sub-tests.
* tag 'linux-kselftest-4.14-rc1-update' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (41 commits)
selftests: Enhance kselftest_harness.h to print which assert failed
selftests: lib.mk: change RUN_TESTS to print messages in TAP13 format
selftests: change lib.mk RUN_TESTS to take test list as an argument
selftests: lib.mk: suppress "cd" output from run_tests target
selftests: kselftest framework: change skip exit code to 0
selftests/timers: make loop consistent with array size
selftests: timers: remove rtctest_setdate from run_destructive_tests
selftests: timers: Fix run_destructive_tests target to handle skipped tests
kselftests: timers: leap-a-day: Change default arguments to help test runs
selftests: timers: drop support for !KTEST case
rtc: rtctest: Improve support detection
selftests/cpu-hotplug: Skip test when there is only one online cpu
selftests/cpu-hotplug: exit with failure when test occured unexpected behaviors
selftests: futex: convert test to use ksft TAP13 framework
selftests: capabilities: convert error output to TAP13 ksft framework
selftests: memfd: Align STACK_SIZE for ARM AArch64 system
selftests: warn if failure is due to lack of executable bit
selftests: kselftest framework: add error counter
selftests: capabilities: convert the test to use TAP13 ksft framework
selftests: capabilities: fix to run Non-root +ia, sgidroot => i test
...
Diffstat (limited to 'tools')
47 files changed, 518 insertions, 491 deletions
diff --git a/tools/testing/selftests/breakpoints/breakpoint_test.c b/tools/testing/selftests/breakpoints/breakpoint_test.c index f63356151ad4..901b85ea6a59 100644 --- a/tools/testing/selftests/breakpoints/breakpoint_test.c +++ b/tools/testing/selftests/breakpoints/breakpoint_test.c | |||
@@ -367,11 +367,11 @@ static void launch_tests(void) | |||
367 | 367 | ||
368 | /* Icebp traps */ | 368 | /* Icebp traps */ |
369 | ptrace(PTRACE_CONT, child_pid, NULL, 0); | 369 | ptrace(PTRACE_CONT, child_pid, NULL, 0); |
370 | check_success("Test icebp"); | 370 | check_success("Test icebp\n"); |
371 | 371 | ||
372 | /* Int 3 traps */ | 372 | /* Int 3 traps */ |
373 | ptrace(PTRACE_CONT, child_pid, NULL, 0); | 373 | ptrace(PTRACE_CONT, child_pid, NULL, 0); |
374 | check_success("Test int 3 trap"); | 374 | check_success("Test int 3 trap\n"); |
375 | 375 | ||
376 | ptrace(PTRACE_CONT, child_pid, NULL, 0); | 376 | ptrace(PTRACE_CONT, child_pid, NULL, 0); |
377 | } | 377 | } |
diff --git a/tools/testing/selftests/capabilities/test_execve.c b/tools/testing/selftests/capabilities/test_execve.c index 763f37fecfb8..cf6778441381 100644 --- a/tools/testing/selftests/capabilities/test_execve.c +++ b/tools/testing/selftests/capabilities/test_execve.c | |||
@@ -1,7 +1,6 @@ | |||
1 | #define _GNU_SOURCE | 1 | #define _GNU_SOURCE |
2 | 2 | ||
3 | #include <cap-ng.h> | 3 | #include <cap-ng.h> |
4 | #include <err.h> | ||
5 | #include <linux/capability.h> | 4 | #include <linux/capability.h> |
6 | #include <stdbool.h> | 5 | #include <stdbool.h> |
7 | #include <string.h> | 6 | #include <string.h> |
@@ -18,6 +17,8 @@ | |||
18 | #include <sys/prctl.h> | 17 | #include <sys/prctl.h> |
19 | #include <sys/stat.h> | 18 | #include <sys/stat.h> |
20 | 19 | ||
20 | #include "../kselftest.h" | ||
21 | |||
21 | #ifndef PR_CAP_AMBIENT | 22 | #ifndef PR_CAP_AMBIENT |
22 | #define PR_CAP_AMBIENT 47 | 23 | #define PR_CAP_AMBIENT 47 |
23 | # define PR_CAP_AMBIENT_IS_SET 1 | 24 | # define PR_CAP_AMBIENT_IS_SET 1 |
@@ -27,6 +28,7 @@ | |||
27 | #endif | 28 | #endif |
28 | 29 | ||
29 | static int nerrs; | 30 | static int nerrs; |
31 | static pid_t mpid; /* main() pid is used to avoid duplicate test counts */ | ||
30 | 32 | ||
31 | static void vmaybe_write_file(bool enoent_ok, char *filename, char *fmt, va_list ap) | 33 | static void vmaybe_write_file(bool enoent_ok, char *filename, char *fmt, va_list ap) |
32 | { | 34 | { |
@@ -36,29 +38,32 @@ static void vmaybe_write_file(bool enoent_ok, char *filename, char *fmt, va_list | |||
36 | int buf_len; | 38 | int buf_len; |
37 | 39 | ||
38 | buf_len = vsnprintf(buf, sizeof(buf), fmt, ap); | 40 | buf_len = vsnprintf(buf, sizeof(buf), fmt, ap); |
39 | if (buf_len < 0) { | 41 | if (buf_len < 0) |
40 | err(1, "vsnprintf failed"); | 42 | ksft_exit_fail_msg("vsnprintf failed - %s\n", strerror(errno)); |
41 | } | 43 | |
42 | if (buf_len >= sizeof(buf)) { | 44 | if (buf_len >= sizeof(buf)) |
43 | errx(1, "vsnprintf output truncated"); | 45 | ksft_exit_fail_msg("vsnprintf output truncated\n"); |
44 | } | 46 | |
45 | 47 | ||
46 | fd = open(filename, O_WRONLY); | 48 | fd = open(filename, O_WRONLY); |
47 | if (fd < 0) { | 49 | if (fd < 0) { |
48 | if ((errno == ENOENT) && enoent_ok) | 50 | if ((errno == ENOENT) && enoent_ok) |
49 | return; | 51 | return; |
50 | err(1, "open of %s failed", filename); | 52 | ksft_exit_fail_msg("open of %s failed - %s\n", |
53 | filename, strerror(errno)); | ||
51 | } | 54 | } |
52 | written = write(fd, buf, buf_len); | 55 | written = write(fd, buf, buf_len); |
53 | if (written != buf_len) { | 56 | if (written != buf_len) { |
54 | if (written >= 0) { | 57 | if (written >= 0) { |
55 | errx(1, "short write to %s", filename); | 58 | ksft_exit_fail_msg("short write to %s\n", filename); |
56 | } else { | 59 | } else { |
57 | err(1, "write to %s failed", filename); | 60 | ksft_exit_fail_msg("write to %s failed - %s\n", |
61 | filename, strerror(errno)); | ||
58 | } | 62 | } |
59 | } | 63 | } |
60 | if (close(fd) != 0) { | 64 | if (close(fd) != 0) { |
61 | err(1, "close of %s failed", filename); | 65 | ksft_exit_fail_msg("close of %s failed - %s\n", |
66 | filename, strerror(errno)); | ||
62 | } | 67 | } |
63 | } | 68 | } |
64 | 69 | ||
@@ -95,11 +100,12 @@ static bool create_and_enter_ns(uid_t inner_uid) | |||
95 | */ | 100 | */ |
96 | 101 | ||
97 | if (unshare(CLONE_NEWNS) == 0) { | 102 | if (unshare(CLONE_NEWNS) == 0) { |
98 | printf("[NOTE]\tUsing global UIDs for tests\n"); | 103 | ksft_print_msg("[NOTE]\tUsing global UIDs for tests\n"); |
99 | if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) != 0) | 104 | if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) != 0) |
100 | err(1, "PR_SET_KEEPCAPS"); | 105 | ksft_exit_fail_msg("PR_SET_KEEPCAPS - %s\n", |
106 | strerror(errno)); | ||
101 | if (setresuid(inner_uid, inner_uid, -1) != 0) | 107 | if (setresuid(inner_uid, inner_uid, -1) != 0) |
102 | err(1, "setresuid"); | 108 | ksft_exit_fail_msg("setresuid - %s\n", strerror(errno)); |
103 | 109 | ||
104 | // Re-enable effective caps | 110 | // Re-enable effective caps |
105 | capng_get_caps_process(); | 111 | capng_get_caps_process(); |
@@ -107,22 +113,24 @@ static bool create_and_enter_ns(uid_t inner_uid) | |||
107 | if (capng_have_capability(CAPNG_PERMITTED, i)) | 113 | if (capng_have_capability(CAPNG_PERMITTED, i)) |
108 | capng_update(CAPNG_ADD, CAPNG_EFFECTIVE, i); | 114 | capng_update(CAPNG_ADD, CAPNG_EFFECTIVE, i); |
109 | if (capng_apply(CAPNG_SELECT_CAPS) != 0) | 115 | if (capng_apply(CAPNG_SELECT_CAPS) != 0) |
110 | err(1, "capng_apply"); | 116 | ksft_exit_fail_msg( |
117 | "capng_apply - %s\n", strerror(errno)); | ||
111 | 118 | ||
112 | have_outer_privilege = true; | 119 | have_outer_privilege = true; |
113 | } else if (unshare(CLONE_NEWUSER | CLONE_NEWNS) == 0) { | 120 | } else if (unshare(CLONE_NEWUSER | CLONE_NEWNS) == 0) { |
114 | printf("[NOTE]\tUsing a user namespace for tests\n"); | 121 | ksft_print_msg("[NOTE]\tUsing a user namespace for tests\n"); |
115 | maybe_write_file("/proc/self/setgroups", "deny"); | 122 | maybe_write_file("/proc/self/setgroups", "deny"); |
116 | write_file("/proc/self/uid_map", "%d %d 1", inner_uid, outer_uid); | 123 | write_file("/proc/self/uid_map", "%d %d 1", inner_uid, outer_uid); |
117 | write_file("/proc/self/gid_map", "0 %d 1", outer_gid); | 124 | write_file("/proc/self/gid_map", "0 %d 1", outer_gid); |
118 | 125 | ||
119 | have_outer_privilege = false; | 126 | have_outer_privilege = false; |
120 | } else { | 127 | } else { |
121 | errx(1, "must be root or be able to create a userns"); | 128 | ksft_exit_skip("must be root or be able to create a userns\n"); |
122 | } | 129 | } |
123 | 130 | ||
124 | if (mount("none", "/", NULL, MS_REC | MS_PRIVATE, NULL) != 0) | 131 | if (mount("none", "/", NULL, MS_REC | MS_PRIVATE, NULL) != 0) |
125 | err(1, "remount everything private"); | 132 | ksft_exit_fail_msg("remount everything private - %s\n", |
133 | strerror(errno)); | ||
126 | 134 | ||
127 | return have_outer_privilege; | 135 | return have_outer_privilege; |
128 | } | 136 | } |
@@ -131,20 +139,22 @@ static void chdir_to_tmpfs(void) | |||
131 | { | 139 | { |
132 | char cwd[PATH_MAX]; | 140 | char cwd[PATH_MAX]; |
133 | if (getcwd(cwd, sizeof(cwd)) != cwd) | 141 | if (getcwd(cwd, sizeof(cwd)) != cwd) |
134 | err(1, "getcwd"); | 142 | ksft_exit_fail_msg("getcwd - %s\n", strerror(errno)); |
135 | 143 | ||
136 | if (mount("private_tmp", ".", "tmpfs", 0, "mode=0777") != 0) | 144 | if (mount("private_tmp", ".", "tmpfs", 0, "mode=0777") != 0) |
137 | err(1, "mount private tmpfs"); | 145 | ksft_exit_fail_msg("mount private tmpfs - %s\n", |
146 | strerror(errno)); | ||
138 | 147 | ||
139 | if (chdir(cwd) != 0) | 148 | if (chdir(cwd) != 0) |
140 | err(1, "chdir to private tmpfs"); | 149 | ksft_exit_fail_msg("chdir to private tmpfs - %s\n", |
150 | strerror(errno)); | ||
141 | } | 151 | } |
142 | 152 | ||
143 | static void copy_fromat_to(int fromfd, const char *fromname, const char *toname) | 153 | static void copy_fromat_to(int fromfd, const char *fromname, const char *toname) |
144 | { | 154 | { |
145 | int from = openat(fromfd, fromname, O_RDONLY); | 155 | int from = openat(fromfd, fromname, O_RDONLY); |
146 | if (from == -1) | 156 | if (from == -1) |
147 | err(1, "open copy source"); | 157 | ksft_exit_fail_msg("open copy source - %s\n", strerror(errno)); |
148 | 158 | ||
149 | int to = open(toname, O_CREAT | O_WRONLY | O_EXCL, 0700); | 159 | int to = open(toname, O_CREAT | O_WRONLY | O_EXCL, 0700); |
150 | 160 | ||
@@ -154,10 +164,11 @@ static void copy_fromat_to(int fromfd, const char *fromname, const char *toname) | |||
154 | if (sz == 0) | 164 | if (sz == 0) |
155 | break; | 165 | break; |
156 | if (sz < 0) | 166 | if (sz < 0) |
157 | err(1, "read"); | 167 | ksft_exit_fail_msg("read - %s\n", strerror(errno)); |
158 | 168 | ||
159 | if (write(to, buf, sz) != sz) | 169 | if (write(to, buf, sz) != sz) |
160 | err(1, "write"); /* no short writes on tmpfs */ | 170 | /* no short writes on tmpfs */ |
171 | ksft_exit_fail_msg("write - %s\n", strerror(errno)); | ||
161 | } | 172 | } |
162 | 173 | ||
163 | close(from); | 174 | close(from); |
@@ -174,18 +185,20 @@ static bool fork_wait(void) | |||
174 | int status; | 185 | int status; |
175 | if (waitpid(child, &status, 0) != child || | 186 | if (waitpid(child, &status, 0) != child || |
176 | !WIFEXITED(status)) { | 187 | !WIFEXITED(status)) { |
177 | printf("[FAIL]\tChild died\n"); | 188 | ksft_print_msg("Child died\n"); |
178 | nerrs++; | 189 | nerrs++; |
179 | } else if (WEXITSTATUS(status) != 0) { | 190 | } else if (WEXITSTATUS(status) != 0) { |
180 | printf("[FAIL]\tChild failed\n"); | 191 | ksft_print_msg("Child failed\n"); |
181 | nerrs++; | 192 | nerrs++; |
182 | } else { | 193 | } else { |
183 | printf("[OK]\tChild succeeded\n"); | 194 | /* don't print this message for mpid */ |
195 | if (getpid() != mpid) | ||
196 | ksft_test_result_pass("Passed\n"); | ||
184 | } | 197 | } |
185 | |||
186 | return false; | 198 | return false; |
187 | } else { | 199 | } else { |
188 | err(1, "fork"); | 200 | ksft_exit_fail_msg("fork - %s\n", strerror(errno)); |
201 | return false; | ||
189 | } | 202 | } |
190 | } | 203 | } |
191 | 204 | ||
@@ -195,7 +208,7 @@ static void exec_other_validate_cap(const char *name, | |||
195 | execl(name, name, (eff ? "1" : "0"), | 208 | execl(name, name, (eff ? "1" : "0"), |
196 | (perm ? "1" : "0"), (inh ? "1" : "0"), (ambient ? "1" : "0"), | 209 | (perm ? "1" : "0"), (inh ? "1" : "0"), (ambient ? "1" : "0"), |
197 | NULL); | 210 | NULL); |
198 | err(1, "execl"); | 211 | ksft_exit_fail_msg("execl - %s\n", strerror(errno)); |
199 | } | 212 | } |
200 | 213 | ||
201 | static void exec_validate_cap(bool eff, bool perm, bool inh, bool ambient) | 214 | static void exec_validate_cap(bool eff, bool perm, bool inh, bool ambient) |
@@ -209,7 +222,8 @@ static int do_tests(int uid, const char *our_path) | |||
209 | 222 | ||
210 | int ourpath_fd = open(our_path, O_RDONLY | O_DIRECTORY); | 223 | int ourpath_fd = open(our_path, O_RDONLY | O_DIRECTORY); |
211 | if (ourpath_fd == -1) | 224 | if (ourpath_fd == -1) |
212 | err(1, "open '%s'", our_path); | 225 | ksft_exit_fail_msg("open '%s' - %s\n", |
226 | our_path, strerror(errno)); | ||
213 | 227 | ||
214 | chdir_to_tmpfs(); | 228 | chdir_to_tmpfs(); |
215 | 229 | ||
@@ -221,30 +235,30 @@ static int do_tests(int uid, const char *our_path) | |||
221 | copy_fromat_to(ourpath_fd, "validate_cap", | 235 | copy_fromat_to(ourpath_fd, "validate_cap", |
222 | "validate_cap_suidroot"); | 236 | "validate_cap_suidroot"); |
223 | if (chown("validate_cap_suidroot", 0, -1) != 0) | 237 | if (chown("validate_cap_suidroot", 0, -1) != 0) |
224 | err(1, "chown"); | 238 | ksft_exit_fail_msg("chown - %s\n", strerror(errno)); |
225 | if (chmod("validate_cap_suidroot", S_ISUID | 0700) != 0) | 239 | if (chmod("validate_cap_suidroot", S_ISUID | 0700) != 0) |
226 | err(1, "chmod"); | 240 | ksft_exit_fail_msg("chmod - %s\n", strerror(errno)); |
227 | 241 | ||
228 | copy_fromat_to(ourpath_fd, "validate_cap", | 242 | copy_fromat_to(ourpath_fd, "validate_cap", |
229 | "validate_cap_suidnonroot"); | 243 | "validate_cap_suidnonroot"); |
230 | if (chown("validate_cap_suidnonroot", uid + 1, -1) != 0) | 244 | if (chown("validate_cap_suidnonroot", uid + 1, -1) != 0) |
231 | err(1, "chown"); | 245 | ksft_exit_fail_msg("chown - %s\n", strerror(errno)); |
232 | if (chmod("validate_cap_suidnonroot", S_ISUID | 0700) != 0) | 246 | if (chmod("validate_cap_suidnonroot", S_ISUID | 0700) != 0) |
233 | err(1, "chmod"); | 247 | ksft_exit_fail_msg("chmod - %s\n", strerror(errno)); |
234 | 248 | ||
235 | copy_fromat_to(ourpath_fd, "validate_cap", | 249 | copy_fromat_to(ourpath_fd, "validate_cap", |
236 | "validate_cap_sgidroot"); | 250 | "validate_cap_sgidroot"); |
237 | if (chown("validate_cap_sgidroot", -1, 0) != 0) | 251 | if (chown("validate_cap_sgidroot", -1, 0) != 0) |
238 | err(1, "chown"); | 252 | ksft_exit_fail_msg("chown - %s\n", strerror(errno)); |
239 | if (chmod("validate_cap_sgidroot", S_ISGID | 0710) != 0) | 253 | if (chmod("validate_cap_sgidroot", S_ISGID | 0710) != 0) |
240 | err(1, "chmod"); | 254 | ksft_exit_fail_msg("chmod - %s\n", strerror(errno)); |
241 | 255 | ||
242 | copy_fromat_to(ourpath_fd, "validate_cap", | 256 | copy_fromat_to(ourpath_fd, "validate_cap", |
243 | "validate_cap_sgidnonroot"); | 257 | "validate_cap_sgidnonroot"); |
244 | if (chown("validate_cap_sgidnonroot", -1, gid + 1) != 0) | 258 | if (chown("validate_cap_sgidnonroot", -1, gid + 1) != 0) |
245 | err(1, "chown"); | 259 | ksft_exit_fail_msg("chown - %s\n", strerror(errno)); |
246 | if (chmod("validate_cap_sgidnonroot", S_ISGID | 0710) != 0) | 260 | if (chmod("validate_cap_sgidnonroot", S_ISGID | 0710) != 0) |
247 | err(1, "chmod"); | 261 | ksft_exit_fail_msg("chmod - %s\n", strerror(errno)); |
248 | } | 262 | } |
249 | 263 | ||
250 | capng_get_caps_process(); | 264 | capng_get_caps_process(); |
@@ -252,147 +266,162 @@ static int do_tests(int uid, const char *our_path) | |||
252 | /* Make sure that i starts out clear */ | 266 | /* Make sure that i starts out clear */ |
253 | capng_update(CAPNG_DROP, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE); | 267 | capng_update(CAPNG_DROP, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE); |
254 | if (capng_apply(CAPNG_SELECT_CAPS) != 0) | 268 | if (capng_apply(CAPNG_SELECT_CAPS) != 0) |
255 | err(1, "capng_apply"); | 269 | ksft_exit_fail_msg("capng_apply - %s\n", strerror(errno)); |
256 | 270 | ||
257 | if (uid == 0) { | 271 | if (uid == 0) { |
258 | printf("[RUN]\tRoot => ep\n"); | 272 | ksft_print_msg("[RUN]\tRoot => ep\n"); |
259 | if (fork_wait()) | 273 | if (fork_wait()) |
260 | exec_validate_cap(true, true, false, false); | 274 | exec_validate_cap(true, true, false, false); |
261 | } else { | 275 | } else { |
262 | printf("[RUN]\tNon-root => no caps\n"); | 276 | ksft_print_msg("[RUN]\tNon-root => no caps\n"); |
263 | if (fork_wait()) | 277 | if (fork_wait()) |
264 | exec_validate_cap(false, false, false, false); | 278 | exec_validate_cap(false, false, false, false); |
265 | } | 279 | } |
266 | 280 | ||
267 | printf("[OK]\tCheck cap_ambient manipulation rules\n"); | 281 | ksft_print_msg("Check cap_ambient manipulation rules\n"); |
268 | 282 | ||
269 | /* We should not be able to add ambient caps yet. */ | 283 | /* We should not be able to add ambient caps yet. */ |
270 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_BIND_SERVICE, 0, 0, 0) != -1 || errno != EPERM) { | 284 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_BIND_SERVICE, 0, 0, 0) != -1 || errno != EPERM) { |
271 | if (errno == EINVAL) | 285 | if (errno == EINVAL) |
272 | printf("[FAIL]\tPR_CAP_AMBIENT_RAISE isn't supported\n"); | 286 | ksft_test_result_fail( |
287 | "PR_CAP_AMBIENT_RAISE isn't supported\n"); | ||
273 | else | 288 | else |
274 | printf("[FAIL]\tPR_CAP_AMBIENT_RAISE should have failed eith EPERM on a non-inheritable cap\n"); | 289 | ksft_test_result_fail( |
290 | "PR_CAP_AMBIENT_RAISE should have failed eith EPERM on a non-inheritable cap\n"); | ||
275 | return 1; | 291 | return 1; |
276 | } | 292 | } |
277 | printf("[OK]\tPR_CAP_AMBIENT_RAISE failed on non-inheritable cap\n"); | 293 | ksft_test_result_pass( |
294 | "PR_CAP_AMBIENT_RAISE failed on non-inheritable cap\n"); | ||
278 | 295 | ||
279 | capng_update(CAPNG_ADD, CAPNG_INHERITABLE, CAP_NET_RAW); | 296 | capng_update(CAPNG_ADD, CAPNG_INHERITABLE, CAP_NET_RAW); |
280 | capng_update(CAPNG_DROP, CAPNG_PERMITTED, CAP_NET_RAW); | 297 | capng_update(CAPNG_DROP, CAPNG_PERMITTED, CAP_NET_RAW); |
281 | capng_update(CAPNG_DROP, CAPNG_EFFECTIVE, CAP_NET_RAW); | 298 | capng_update(CAPNG_DROP, CAPNG_EFFECTIVE, CAP_NET_RAW); |
282 | if (capng_apply(CAPNG_SELECT_CAPS) != 0) | 299 | if (capng_apply(CAPNG_SELECT_CAPS) != 0) |
283 | err(1, "capng_apply"); | 300 | ksft_exit_fail_msg("capng_apply - %s\n", strerror(errno)); |
284 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_RAW, 0, 0, 0) != -1 || errno != EPERM) { | 301 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_RAW, 0, 0, 0) != -1 || errno != EPERM) { |
285 | printf("[FAIL]\tPR_CAP_AMBIENT_RAISE should have failed on a non-permitted cap\n"); | 302 | ksft_test_result_fail( |
303 | "PR_CAP_AMBIENT_RAISE should have failed on a non-permitted cap\n"); | ||
286 | return 1; | 304 | return 1; |
287 | } | 305 | } |
288 | printf("[OK]\tPR_CAP_AMBIENT_RAISE failed on non-permitted cap\n"); | 306 | ksft_test_result_pass( |
307 | "PR_CAP_AMBIENT_RAISE failed on non-permitted cap\n"); | ||
289 | 308 | ||
290 | capng_update(CAPNG_ADD, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE); | 309 | capng_update(CAPNG_ADD, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE); |
291 | if (capng_apply(CAPNG_SELECT_CAPS) != 0) | 310 | if (capng_apply(CAPNG_SELECT_CAPS) != 0) |
292 | err(1, "capng_apply"); | 311 | ksft_exit_fail_msg("capng_apply - %s\n", strerror(errno)); |
293 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_BIND_SERVICE, 0, 0, 0) != 0) { | 312 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_BIND_SERVICE, 0, 0, 0) != 0) { |
294 | printf("[FAIL]\tPR_CAP_AMBIENT_RAISE should have succeeded\n"); | 313 | ksft_test_result_fail( |
314 | "PR_CAP_AMBIENT_RAISE should have succeeded\n"); | ||
295 | return 1; | 315 | return 1; |
296 | } | 316 | } |
297 | printf("[OK]\tPR_CAP_AMBIENT_RAISE worked\n"); | 317 | ksft_test_result_pass("PR_CAP_AMBIENT_RAISE worked\n"); |
298 | 318 | ||
299 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_BIND_SERVICE, 0, 0, 0) != 1) { | 319 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_BIND_SERVICE, 0, 0, 0) != 1) { |
300 | printf("[FAIL]\tPR_CAP_AMBIENT_IS_SET is broken\n"); | 320 | ksft_test_result_fail("PR_CAP_AMBIENT_IS_SET is broken\n"); |
301 | return 1; | 321 | return 1; |
302 | } | 322 | } |
303 | 323 | ||
304 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL, 0, 0, 0, 0) != 0) | 324 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL, 0, 0, 0, 0) != 0) |
305 | err(1, "PR_CAP_AMBIENT_CLEAR_ALL"); | 325 | ksft_exit_fail_msg("PR_CAP_AMBIENT_CLEAR_ALL - %s\n", |
326 | strerror(errno)); | ||
306 | 327 | ||
307 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_BIND_SERVICE, 0, 0, 0) != 0) { | 328 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_BIND_SERVICE, 0, 0, 0) != 0) { |
308 | printf("[FAIL]\tPR_CAP_AMBIENT_CLEAR_ALL didn't work\n"); | 329 | ksft_test_result_fail( |
330 | "PR_CAP_AMBIENT_CLEAR_ALL didn't work\n"); | ||
309 | return 1; | 331 | return 1; |
310 | } | 332 | } |
311 | 333 | ||
312 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_BIND_SERVICE, 0, 0, 0) != 0) | 334 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_BIND_SERVICE, 0, 0, 0) != 0) |
313 | err(1, "PR_CAP_AMBIENT_RAISE"); | 335 | ksft_exit_fail_msg("PR_CAP_AMBIENT_RAISE - %s\n", |
336 | strerror(errno)); | ||
314 | 337 | ||
315 | capng_update(CAPNG_DROP, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE); | 338 | capng_update(CAPNG_DROP, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE); |
316 | if (capng_apply(CAPNG_SELECT_CAPS) != 0) | 339 | if (capng_apply(CAPNG_SELECT_CAPS) != 0) |
317 | err(1, "capng_apply"); | 340 | ksft_exit_fail_msg("capng_apply - %s\n", strerror(errno)); |
318 | 341 | ||
319 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_BIND_SERVICE, 0, 0, 0) != 0) { | 342 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_BIND_SERVICE, 0, 0, 0) != 0) { |
320 | printf("[FAIL]\tDropping I should have dropped A\n"); | 343 | ksft_test_result_fail("Dropping I should have dropped A\n"); |
321 | return 1; | 344 | return 1; |
322 | } | 345 | } |
323 | 346 | ||
324 | printf("[OK]\tBasic manipulation appears to work\n"); | 347 | ksft_test_result_pass("Basic manipulation appears to work\n"); |
325 | 348 | ||
326 | capng_update(CAPNG_ADD, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE); | 349 | capng_update(CAPNG_ADD, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE); |
327 | if (capng_apply(CAPNG_SELECT_CAPS) != 0) | 350 | if (capng_apply(CAPNG_SELECT_CAPS) != 0) |
328 | err(1, "capng_apply"); | 351 | ksft_exit_fail_msg("capng_apply - %s\n", strerror(errno)); |
329 | if (uid == 0) { | 352 | if (uid == 0) { |
330 | printf("[RUN]\tRoot +i => eip\n"); | 353 | ksft_print_msg("[RUN]\tRoot +i => eip\n"); |
331 | if (fork_wait()) | 354 | if (fork_wait()) |
332 | exec_validate_cap(true, true, true, false); | 355 | exec_validate_cap(true, true, true, false); |
333 | } else { | 356 | } else { |
334 | printf("[RUN]\tNon-root +i => i\n"); | 357 | ksft_print_msg("[RUN]\tNon-root +i => i\n"); |
335 | if (fork_wait()) | 358 | if (fork_wait()) |
336 | exec_validate_cap(false, false, true, false); | 359 | exec_validate_cap(false, false, true, false); |
337 | } | 360 | } |
338 | 361 | ||
339 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_BIND_SERVICE, 0, 0, 0) != 0) | 362 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_BIND_SERVICE, 0, 0, 0) != 0) |
340 | err(1, "PR_CAP_AMBIENT_RAISE"); | 363 | ksft_exit_fail_msg("PR_CAP_AMBIENT_RAISE - %s\n", |
364 | strerror(errno)); | ||
341 | 365 | ||
342 | printf("[RUN]\tUID %d +ia => eipa\n", uid); | 366 | ksft_print_msg("[RUN]\tUID %d +ia => eipa\n", uid); |
343 | if (fork_wait()) | 367 | if (fork_wait()) |
344 | exec_validate_cap(true, true, true, true); | 368 | exec_validate_cap(true, true, true, true); |
345 | 369 | ||
346 | /* The remaining tests need real privilege */ | 370 | /* The remaining tests need real privilege */ |
347 | 371 | ||
348 | if (!have_outer_privilege) { | 372 | if (!have_outer_privilege) { |
349 | printf("[SKIP]\tSUID/SGID tests (needs privilege)\n"); | 373 | ksft_test_result_skip("SUID/SGID tests (needs privilege)\n"); |
350 | goto done; | 374 | goto done; |
351 | } | 375 | } |
352 | 376 | ||
353 | if (uid == 0) { | 377 | if (uid == 0) { |
354 | printf("[RUN]\tRoot +ia, suidroot => eipa\n"); | 378 | ksft_print_msg("[RUN]\tRoot +ia, suidroot => eipa\n"); |
355 | if (fork_wait()) | 379 | if (fork_wait()) |
356 | exec_other_validate_cap("./validate_cap_suidroot", | 380 | exec_other_validate_cap("./validate_cap_suidroot", |
357 | true, true, true, true); | 381 | true, true, true, true); |
358 | 382 | ||
359 | printf("[RUN]\tRoot +ia, suidnonroot => ip\n"); | 383 | ksft_print_msg("[RUN]\tRoot +ia, suidnonroot => ip\n"); |
360 | if (fork_wait()) | 384 | if (fork_wait()) |
361 | exec_other_validate_cap("./validate_cap_suidnonroot", | 385 | exec_other_validate_cap("./validate_cap_suidnonroot", |
362 | false, true, true, false); | 386 | false, true, true, false); |
363 | 387 | ||
364 | printf("[RUN]\tRoot +ia, sgidroot => eipa\n"); | 388 | ksft_print_msg("[RUN]\tRoot +ia, sgidroot => eipa\n"); |
365 | if (fork_wait()) | 389 | if (fork_wait()) |
366 | exec_other_validate_cap("./validate_cap_sgidroot", | 390 | exec_other_validate_cap("./validate_cap_sgidroot", |
367 | true, true, true, true); | 391 | true, true, true, true); |
368 | 392 | ||
369 | if (fork_wait()) { | 393 | if (fork_wait()) { |
370 | printf("[RUN]\tRoot, gid != 0, +ia, sgidroot => eip\n"); | 394 | ksft_print_msg( |
395 | "[RUN]\tRoot, gid != 0, +ia, sgidroot => eip\n"); | ||
371 | if (setresgid(1, 1, 1) != 0) | 396 | if (setresgid(1, 1, 1) != 0) |
372 | err(1, "setresgid"); | 397 | ksft_exit_fail_msg("setresgid - %s\n", |
398 | strerror(errno)); | ||
373 | exec_other_validate_cap("./validate_cap_sgidroot", | 399 | exec_other_validate_cap("./validate_cap_sgidroot", |
374 | true, true, true, false); | 400 | true, true, true, false); |
375 | } | 401 | } |
376 | 402 | ||
377 | printf("[RUN]\tRoot +ia, sgidnonroot => eip\n"); | 403 | ksft_print_msg("[RUN]\tRoot +ia, sgidnonroot => eip\n"); |
378 | if (fork_wait()) | 404 | if (fork_wait()) |
379 | exec_other_validate_cap("./validate_cap_sgidnonroot", | 405 | exec_other_validate_cap("./validate_cap_sgidnonroot", |
380 | true, true, true, false); | 406 | true, true, true, false); |
381 | } else { | 407 | } else { |
382 | printf("[RUN]\tNon-root +ia, sgidnonroot => i\n"); | 408 | ksft_print_msg("[RUN]\tNon-root +ia, sgidnonroot => i\n"); |
383 | exec_other_validate_cap("./validate_cap_sgidnonroot", | 409 | if (fork_wait()) |
410 | exec_other_validate_cap("./validate_cap_sgidnonroot", | ||
384 | false, false, true, false); | 411 | false, false, true, false); |
385 | 412 | ||
386 | if (fork_wait()) { | 413 | if (fork_wait()) { |
387 | printf("[RUN]\tNon-root +ia, sgidroot => i\n"); | 414 | ksft_print_msg("[RUN]\tNon-root +ia, sgidroot => i\n"); |
388 | if (setresgid(1, 1, 1) != 0) | 415 | if (setresgid(1, 1, 1) != 0) |
389 | err(1, "setresgid"); | 416 | ksft_exit_fail_msg("setresgid - %s\n", |
417 | strerror(errno)); | ||
390 | exec_other_validate_cap("./validate_cap_sgidroot", | 418 | exec_other_validate_cap("./validate_cap_sgidroot", |
391 | false, false, true, false); | 419 | false, false, true, false); |
392 | } | 420 | } |
393 | } | 421 | } |
394 | 422 | ||
395 | done: | 423 | done: |
424 | ksft_print_cnts(); | ||
396 | return nerrs ? 1 : 0; | 425 | return nerrs ? 1 : 0; |
397 | } | 426 | } |
398 | 427 | ||
@@ -400,23 +429,29 @@ int main(int argc, char **argv) | |||
400 | { | 429 | { |
401 | char *tmp1, *tmp2, *our_path; | 430 | char *tmp1, *tmp2, *our_path; |
402 | 431 | ||
432 | ksft_print_header(); | ||
433 | |||
403 | /* Find our path */ | 434 | /* Find our path */ |
404 | tmp1 = strdup(argv[0]); | 435 | tmp1 = strdup(argv[0]); |
405 | if (!tmp1) | 436 | if (!tmp1) |
406 | err(1, "strdup"); | 437 | ksft_exit_fail_msg("strdup - %s\n", strerror(errno)); |
407 | tmp2 = dirname(tmp1); | 438 | tmp2 = dirname(tmp1); |
408 | our_path = strdup(tmp2); | 439 | our_path = strdup(tmp2); |
409 | if (!our_path) | 440 | if (!our_path) |
410 | err(1, "strdup"); | 441 | ksft_exit_fail_msg("strdup - %s\n", strerror(errno)); |
411 | free(tmp1); | 442 | free(tmp1); |
412 | 443 | ||
444 | mpid = getpid(); | ||
445 | |||
413 | if (fork_wait()) { | 446 | if (fork_wait()) { |
414 | printf("[RUN]\t+++ Tests with uid == 0 +++\n"); | 447 | ksft_print_msg("[RUN]\t+++ Tests with uid == 0 +++\n"); |
415 | return do_tests(0, our_path); | 448 | return do_tests(0, our_path); |
416 | } | 449 | } |
417 | 450 | ||
451 | ksft_print_msg("==================================================\n"); | ||
452 | |||
418 | if (fork_wait()) { | 453 | if (fork_wait()) { |
419 | printf("[RUN]\t+++ Tests with uid != 0 +++\n"); | 454 | ksft_print_msg("[RUN]\t+++ Tests with uid != 0 +++\n"); |
420 | return do_tests(1, our_path); | 455 | return do_tests(1, our_path); |
421 | } | 456 | } |
422 | 457 | ||
diff --git a/tools/testing/selftests/capabilities/validate_cap.c b/tools/testing/selftests/capabilities/validate_cap.c index dd3c45f7b23c..694cd73d4493 100644 --- a/tools/testing/selftests/capabilities/validate_cap.c +++ b/tools/testing/selftests/capabilities/validate_cap.c | |||
@@ -1,5 +1,4 @@ | |||
1 | #include <cap-ng.h> | 1 | #include <cap-ng.h> |
2 | #include <err.h> | ||
3 | #include <linux/capability.h> | 2 | #include <linux/capability.h> |
4 | #include <stdbool.h> | 3 | #include <stdbool.h> |
5 | #include <string.h> | 4 | #include <string.h> |
@@ -7,6 +6,8 @@ | |||
7 | #include <sys/prctl.h> | 6 | #include <sys/prctl.h> |
8 | #include <sys/auxv.h> | 7 | #include <sys/auxv.h> |
9 | 8 | ||
9 | #include "../kselftest.h" | ||
10 | |||
10 | #ifndef PR_CAP_AMBIENT | 11 | #ifndef PR_CAP_AMBIENT |
11 | #define PR_CAP_AMBIENT 47 | 12 | #define PR_CAP_AMBIENT 47 |
12 | # define PR_CAP_AMBIENT_IS_SET 1 | 13 | # define PR_CAP_AMBIENT_IS_SET 1 |
@@ -25,8 +26,10 @@ static bool bool_arg(char **argv, int i) | |||
25 | return false; | 26 | return false; |
26 | else if (!strcmp(argv[i], "1")) | 27 | else if (!strcmp(argv[i], "1")) |
27 | return true; | 28 | return true; |
28 | else | 29 | else { |
29 | errx(1, "wrong argv[%d]", i); | 30 | ksft_exit_fail_msg("wrong argv[%d]\n", i); |
31 | return false; | ||
32 | } | ||
30 | } | 33 | } |
31 | 34 | ||
32 | int main(int argc, char **argv) | 35 | int main(int argc, char **argv) |
@@ -39,7 +42,7 @@ int main(int argc, char **argv) | |||
39 | */ | 42 | */ |
40 | 43 | ||
41 | if (argc != 5) | 44 | if (argc != 5) |
42 | errx(1, "wrong argc"); | 45 | ksft_exit_fail_msg("wrong argc\n"); |
43 | 46 | ||
44 | #ifdef HAVE_GETAUXVAL | 47 | #ifdef HAVE_GETAUXVAL |
45 | if (getauxval(AT_SECURE)) | 48 | if (getauxval(AT_SECURE)) |
@@ -51,23 +54,26 @@ int main(int argc, char **argv) | |||
51 | capng_get_caps_process(); | 54 | capng_get_caps_process(); |
52 | 55 | ||
53 | if (capng_have_capability(CAPNG_EFFECTIVE, CAP_NET_BIND_SERVICE) != bool_arg(argv, 1)) { | 56 | if (capng_have_capability(CAPNG_EFFECTIVE, CAP_NET_BIND_SERVICE) != bool_arg(argv, 1)) { |
54 | printf("[FAIL]\tWrong effective state%s\n", atsec); | 57 | ksft_print_msg("Wrong effective state%s\n", atsec); |
55 | return 1; | 58 | return 1; |
56 | } | 59 | } |
60 | |||
57 | if (capng_have_capability(CAPNG_PERMITTED, CAP_NET_BIND_SERVICE) != bool_arg(argv, 2)) { | 61 | if (capng_have_capability(CAPNG_PERMITTED, CAP_NET_BIND_SERVICE) != bool_arg(argv, 2)) { |
58 | printf("[FAIL]\tWrong permitted state%s\n", atsec); | 62 | ksft_print_msg("Wrong permitted state%s\n", atsec); |
59 | return 1; | 63 | return 1; |
60 | } | 64 | } |
65 | |||
61 | if (capng_have_capability(CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE) != bool_arg(argv, 3)) { | 66 | if (capng_have_capability(CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE) != bool_arg(argv, 3)) { |
62 | printf("[FAIL]\tWrong inheritable state%s\n", atsec); | 67 | ksft_print_msg("Wrong inheritable state%s\n", atsec); |
63 | return 1; | 68 | return 1; |
64 | } | 69 | } |
65 | 70 | ||
66 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_BIND_SERVICE, 0, 0, 0) != bool_arg(argv, 4)) { | 71 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_BIND_SERVICE, 0, 0, 0) != bool_arg(argv, 4)) { |
67 | printf("[FAIL]\tWrong ambient state%s\n", atsec); | 72 | ksft_print_msg("Wrong ambient state%s\n", atsec); |
68 | return 1; | 73 | return 1; |
69 | } | 74 | } |
70 | 75 | ||
71 | printf("[OK]\tCapabilities after execve were correct\n"); | 76 | ksft_print_msg("%s: Capabilities after execve were correct\n", |
77 | "validate_cap:"); | ||
72 | return 0; | 78 | return 0; |
73 | } | 79 | } |
diff --git a/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh b/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh index 98b1d6565f2c..b18b253d7bfb 100755 --- a/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh +++ b/tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh | |||
@@ -28,6 +28,12 @@ prerequisite() | |||
28 | echo "CPU online/offline summary:" | 28 | echo "CPU online/offline summary:" |
29 | online_cpus=`cat $SYSFS/devices/system/cpu/online` | 29 | online_cpus=`cat $SYSFS/devices/system/cpu/online` |
30 | online_max=${online_cpus##*-} | 30 | online_max=${online_cpus##*-} |
31 | |||
32 | if [[ "$online_cpus" = "$online_max" ]]; then | ||
33 | echo "$msg: since there is only one cpu: $online_cpus" | ||
34 | exit 0 | ||
35 | fi | ||
36 | |||
31 | echo -e "\t Cpus in online state: $online_cpus" | 37 | echo -e "\t Cpus in online state: $online_cpus" |
32 | 38 | ||
33 | offline_cpus=`cat $SYSFS/devices/system/cpu/offline` | 39 | offline_cpus=`cat $SYSFS/devices/system/cpu/offline` |
@@ -89,8 +95,10 @@ online_cpu_expect_success() | |||
89 | 95 | ||
90 | if ! online_cpu $cpu; then | 96 | if ! online_cpu $cpu; then |
91 | echo $FUNCNAME $cpu: unexpected fail >&2 | 97 | echo $FUNCNAME $cpu: unexpected fail >&2 |
98 | exit 1 | ||
92 | elif ! cpu_is_online $cpu; then | 99 | elif ! cpu_is_online $cpu; then |
93 | echo $FUNCNAME $cpu: unexpected offline >&2 | 100 | echo $FUNCNAME $cpu: unexpected offline >&2 |
101 | exit 1 | ||
94 | fi | 102 | fi |
95 | } | 103 | } |
96 | 104 | ||
@@ -100,8 +108,10 @@ online_cpu_expect_fail() | |||
100 | 108 | ||
101 | if online_cpu $cpu 2> /dev/null; then | 109 | if online_cpu $cpu 2> /dev/null; then |
102 | echo $FUNCNAME $cpu: unexpected success >&2 | 110 | echo $FUNCNAME $cpu: unexpected success >&2 |
111 | exit 1 | ||
103 | elif ! cpu_is_offline $cpu; then | 112 | elif ! cpu_is_offline $cpu; then |
104 | echo $FUNCNAME $cpu: unexpected online >&2 | 113 | echo $FUNCNAME $cpu: unexpected online >&2 |
114 | exit 1 | ||
105 | fi | 115 | fi |
106 | } | 116 | } |
107 | 117 | ||
@@ -111,8 +121,10 @@ offline_cpu_expect_success() | |||
111 | 121 | ||
112 | if ! offline_cpu $cpu; then | 122 | if ! offline_cpu $cpu; then |
113 | echo $FUNCNAME $cpu: unexpected fail >&2 | 123 | echo $FUNCNAME $cpu: unexpected fail >&2 |
124 | exit 1 | ||
114 | elif ! cpu_is_offline $cpu; then | 125 | elif ! cpu_is_offline $cpu; then |
115 | echo $FUNCNAME $cpu: unexpected offline >&2 | 126 | echo $FUNCNAME $cpu: unexpected offline >&2 |
127 | exit 1 | ||
116 | fi | 128 | fi |
117 | } | 129 | } |
118 | 130 | ||
@@ -122,8 +134,10 @@ offline_cpu_expect_fail() | |||
122 | 134 | ||
123 | if offline_cpu $cpu 2> /dev/null; then | 135 | if offline_cpu $cpu 2> /dev/null; then |
124 | echo $FUNCNAME $cpu: unexpected success >&2 | 136 | echo $FUNCNAME $cpu: unexpected success >&2 |
137 | exit 1 | ||
125 | elif ! cpu_is_online $cpu; then | 138 | elif ! cpu_is_online $cpu; then |
126 | echo $FUNCNAME $cpu: unexpected offline >&2 | 139 | echo $FUNCNAME $cpu: unexpected offline >&2 |
140 | exit 1 | ||
127 | fi | 141 | fi |
128 | } | 142 | } |
129 | 143 | ||
diff --git a/tools/testing/selftests/ftrace/ftracetest b/tools/testing/selftests/ftrace/ftracetest index 14a03ea1e21d..abc706cf7702 100755 --- a/tools/testing/selftests/ftrace/ftracetest +++ b/tools/testing/selftests/ftrace/ftracetest | |||
@@ -8,15 +8,18 @@ | |||
8 | # Released under the terms of the GPL v2. | 8 | # Released under the terms of the GPL v2. |
9 | 9 | ||
10 | usage() { # errno [message] | 10 | usage() { # errno [message] |
11 | [ "$2" ] && echo $2 | 11 | [ ! -z "$2" ] && echo $2 |
12 | echo "Usage: ftracetest [options] [testcase(s)] [testcase-directory(s)]" | 12 | echo "Usage: ftracetest [options] [testcase(s)] [testcase-directory(s)]" |
13 | echo " Options:" | 13 | echo " Options:" |
14 | echo " -h|--help Show help message" | 14 | echo " -h|--help Show help message" |
15 | echo " -k|--keep Keep passed test logs" | 15 | echo " -k|--keep Keep passed test logs" |
16 | echo " -v|--verbose Increase verbosity of test messages" | 16 | echo " -v|--verbose Increase verbosity of test messages" |
17 | echo " -vv Alias of -v -v (Show all results in stdout)" | 17 | echo " -vv Alias of -v -v (Show all results in stdout)" |
18 | echo " -vvv Alias of -v -v -v (Show all commands immediately)" | ||
19 | echo " --fail-unsupported Treat UNSUPPORTED as a failure" | ||
18 | echo " -d|--debug Debug mode (trace all shell commands)" | 20 | echo " -d|--debug Debug mode (trace all shell commands)" |
19 | echo " -l|--logdir <dir> Save logs on the <dir>" | 21 | echo " -l|--logdir <dir> Save logs on the <dir>" |
22 | echo " If <dir> is -, all logs output in console only" | ||
20 | exit $1 | 23 | exit $1 |
21 | } | 24 | } |
22 | 25 | ||
@@ -47,7 +50,7 @@ parse_opts() { # opts | |||
47 | local OPT_TEST_CASES= | 50 | local OPT_TEST_CASES= |
48 | local OPT_TEST_DIR= | 51 | local OPT_TEST_DIR= |
49 | 52 | ||
50 | while [ "$1" ]; do | 53 | while [ ! -z "$1" ]; do |
51 | case "$1" in | 54 | case "$1" in |
52 | --help|-h) | 55 | --help|-h) |
53 | usage 0 | 56 | usage 0 |
@@ -56,15 +59,20 @@ parse_opts() { # opts | |||
56 | KEEP_LOG=1 | 59 | KEEP_LOG=1 |
57 | shift 1 | 60 | shift 1 |
58 | ;; | 61 | ;; |
59 | --verbose|-v|-vv) | 62 | --verbose|-v|-vv|-vvv) |
60 | VERBOSE=$((VERBOSE + 1)) | 63 | VERBOSE=$((VERBOSE + 1)) |
61 | [ $1 = '-vv' ] && VERBOSE=$((VERBOSE + 1)) | 64 | [ $1 = '-vv' ] && VERBOSE=$((VERBOSE + 1)) |
65 | [ $1 = '-vvv' ] && VERBOSE=$((VERBOSE + 2)) | ||
62 | shift 1 | 66 | shift 1 |
63 | ;; | 67 | ;; |
64 | --debug|-d) | 68 | --debug|-d) |
65 | DEBUG=1 | 69 | DEBUG=1 |
66 | shift 1 | 70 | shift 1 |
67 | ;; | 71 | ;; |
72 | --fail-unsupported) | ||
73 | UNSUPPORTED_RESULT=1 | ||
74 | shift 1 | ||
75 | ;; | ||
68 | --logdir|-l) | 76 | --logdir|-l) |
69 | LOG_DIR=$2 | 77 | LOG_DIR=$2 |
70 | shift 2 | 78 | shift 2 |
@@ -88,7 +96,7 @@ parse_opts() { # opts | |||
88 | ;; | 96 | ;; |
89 | esac | 97 | esac |
90 | done | 98 | done |
91 | if [ "$OPT_TEST_CASES" ]; then | 99 | if [ ! -z "$OPT_TEST_CASES" ]; then |
92 | TEST_CASES=$OPT_TEST_CASES | 100 | TEST_CASES=$OPT_TEST_CASES |
93 | fi | 101 | fi |
94 | } | 102 | } |
@@ -108,6 +116,7 @@ LOG_DIR=$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`/ | |||
108 | KEEP_LOG=0 | 116 | KEEP_LOG=0 |
109 | DEBUG=0 | 117 | DEBUG=0 |
110 | VERBOSE=0 | 118 | VERBOSE=0 |
119 | UNSUPPORTED_RESULT=0 | ||
111 | # Parse command-line options | 120 | # Parse command-line options |
112 | parse_opts $* | 121 | parse_opts $* |
113 | 122 | ||
@@ -119,14 +128,20 @@ if [ -z "$TRACING_DIR" -o ! -d "$TRACING_DIR" ]; then | |||
119 | fi | 128 | fi |
120 | 129 | ||
121 | # Preparing logs | 130 | # Preparing logs |
122 | LOG_FILE=$LOG_DIR/ftracetest.log | 131 | if [ "x$LOG_DIR" = "x-" ]; then |
123 | mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR" | 132 | LOG_FILE= |
124 | date > $LOG_FILE | 133 | date |
134 | else | ||
135 | LOG_FILE=$LOG_DIR/ftracetest.log | ||
136 | mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR" | ||
137 | date > $LOG_FILE | ||
138 | fi | ||
139 | |||
125 | prlog() { # messages | 140 | prlog() { # messages |
126 | echo "$@" | tee -a $LOG_FILE | 141 | [ -z "$LOG_FILE" ] && echo "$@" || echo "$@" | tee -a $LOG_FILE |
127 | } | 142 | } |
128 | catlog() { #file | 143 | catlog() { #file |
129 | cat $1 | tee -a $LOG_FILE | 144 | [ -z "$LOG_FILE" ] && cat $1 || cat $1 | tee -a $LOG_FILE |
130 | } | 145 | } |
131 | prlog "=== Ftrace unit tests ===" | 146 | prlog "=== Ftrace unit tests ===" |
132 | 147 | ||
@@ -187,7 +202,7 @@ eval_result() { # sigval | |||
187 | $UNSUPPORTED) | 202 | $UNSUPPORTED) |
188 | prlog " [UNSUPPORTED]" | 203 | prlog " [UNSUPPORTED]" |
189 | UNSUPPORTED_CASES="$UNSUPPORTED_CASES $CASENO" | 204 | UNSUPPORTED_CASES="$UNSUPPORTED_CASES $CASENO" |
190 | return 1 # this is not a bug, but the result should be reported. | 205 | return $UNSUPPORTED_RESULT # depends on use case |
191 | ;; | 206 | ;; |
192 | $XFAIL) | 207 | $XFAIL) |
193 | prlog " [XFAIL]" | 208 | prlog " [XFAIL]" |
@@ -247,12 +262,20 @@ __run_test() { # testfile | |||
247 | # Run one test case | 262 | # Run one test case |
248 | run_test() { # testfile | 263 | run_test() { # testfile |
249 | local testname=`basename $1` | 264 | local testname=`basename $1` |
250 | local testlog=`mktemp $LOG_DIR/${testname}-log.XXXXXX` | 265 | if [ ! -z "$LOG_FILE" ] ; then |
266 | local testlog=`mktemp $LOG_DIR/${testname}-log.XXXXXX` | ||
267 | else | ||
268 | local testlog=/proc/self/fd/1 | ||
269 | fi | ||
251 | export TMPDIR=`mktemp -d /tmp/ftracetest-dir.XXXXXX` | 270 | export TMPDIR=`mktemp -d /tmp/ftracetest-dir.XXXXXX` |
252 | testcase $1 | 271 | testcase $1 |
253 | echo "execute$INSTANCE: "$1 > $testlog | 272 | echo "execute$INSTANCE: "$1 > $testlog |
254 | SIG_RESULT=0 | 273 | SIG_RESULT=0 |
255 | if [ $VERBOSE -ge 2 ]; then | 274 | if [ -z "$LOG_FILE" ]; then |
275 | __run_test $1 2>&1 | ||
276 | elif [ $VERBOSE -ge 3 ]; then | ||
277 | __run_test $1 | tee -a $testlog 2>&1 | ||
278 | elif [ $VERBOSE -eq 2 ]; then | ||
256 | __run_test $1 2>> $testlog | tee -a $testlog | 279 | __run_test $1 2>> $testlog | tee -a $testlog |
257 | else | 280 | else |
258 | __run_test $1 >> $testlog 2>&1 | 281 | __run_test $1 >> $testlog 2>&1 |
@@ -260,9 +283,9 @@ run_test() { # testfile | |||
260 | eval_result $SIG_RESULT | 283 | eval_result $SIG_RESULT |
261 | if [ $? -eq 0 ]; then | 284 | if [ $? -eq 0 ]; then |
262 | # Remove test log if the test was done as it was expected. | 285 | # Remove test log if the test was done as it was expected. |
263 | [ $KEEP_LOG -eq 0 ] && rm $testlog | 286 | [ $KEEP_LOG -eq 0 -a ! -z "$LOG_FILE" ] && rm $testlog |
264 | else | 287 | else |
265 | [ $VERBOSE -ge 1 ] && catlog $testlog | 288 | [ $VERBOSE -eq 1 -o $VERBOSE -eq 2 ] && catlog $testlog |
266 | TOTAL_RESULT=1 | 289 | TOTAL_RESULT=1 |
267 | fi | 290 | fi |
268 | rm -rf $TMPDIR | 291 | rm -rf $TMPDIR |
diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi.c b/tools/testing/selftests/futex/functional/futex_requeue_pi.c index d24ab7421e73..54cd5c414e82 100644 --- a/tools/testing/selftests/futex/functional/futex_requeue_pi.c +++ b/tools/testing/selftests/futex/functional/futex_requeue_pi.c | |||
@@ -394,9 +394,11 @@ int main(int argc, char *argv[]) | |||
394 | } | 394 | } |
395 | } | 395 | } |
396 | 396 | ||
397 | printf("%s: Test requeue functionality\n", basename(argv[0])); | 397 | ksft_print_header(); |
398 | printf("\tArguments: broadcast=%d locked=%d owner=%d timeout=%ldns\n", | 398 | ksft_print_msg("%s: Test requeue functionality\n", basename(argv[0])); |
399 | broadcast, locked, owner, timeout_ns); | 399 | ksft_print_msg( |
400 | "\tArguments: broadcast=%d locked=%d owner=%d timeout=%ldns\n", | ||
401 | broadcast, locked, owner, timeout_ns); | ||
400 | 402 | ||
401 | /* | 403 | /* |
402 | * FIXME: unit_test is obsolete now that we parse options and the | 404 | * FIXME: unit_test is obsolete now that we parse options and the |
diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi_mismatched_ops.c b/tools/testing/selftests/futex/functional/futex_requeue_pi_mismatched_ops.c index e0a798ad0d21..08187a16507f 100644 --- a/tools/testing/selftests/futex/functional/futex_requeue_pi_mismatched_ops.c +++ b/tools/testing/selftests/futex/functional/futex_requeue_pi_mismatched_ops.c | |||
@@ -78,7 +78,8 @@ int main(int argc, char *argv[]) | |||
78 | } | 78 | } |
79 | } | 79 | } |
80 | 80 | ||
81 | printf("%s: Detect mismatched requeue_pi operations\n", | 81 | ksft_print_header(); |
82 | ksft_print_msg("%s: Detect mismatched requeue_pi operations\n", | ||
82 | basename(argv[0])); | 83 | basename(argv[0])); |
83 | 84 | ||
84 | if (pthread_create(&child, NULL, blocking_child, NULL)) { | 85 | if (pthread_create(&child, NULL, blocking_child, NULL)) { |
diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi_signal_restart.c b/tools/testing/selftests/futex/functional/futex_requeue_pi_signal_restart.c index 982f83577501..f0542a344d95 100644 --- a/tools/testing/selftests/futex/functional/futex_requeue_pi_signal_restart.c +++ b/tools/testing/selftests/futex/functional/futex_requeue_pi_signal_restart.c | |||
@@ -143,9 +143,10 @@ int main(int argc, char *argv[]) | |||
143 | } | 143 | } |
144 | } | 144 | } |
145 | 145 | ||
146 | printf("%s: Test signal handling during requeue_pi\n", | 146 | ksft_print_header(); |
147 | ksft_print_msg("%s: Test signal handling during requeue_pi\n", | ||
147 | basename(argv[0])); | 148 | basename(argv[0])); |
148 | printf("\tArguments: <none>\n"); | 149 | ksft_print_msg("\tArguments: <none>\n"); |
149 | 150 | ||
150 | sa.sa_handler = handle_signal; | 151 | sa.sa_handler = handle_signal; |
151 | sigemptyset(&sa.sa_mask); | 152 | sigemptyset(&sa.sa_mask); |
diff --git a/tools/testing/selftests/futex/functional/futex_wait_private_mapped_file.c b/tools/testing/selftests/futex/functional/futex_wait_private_mapped_file.c index bdc48dc047e5..6216de828093 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_private_mapped_file.c +++ b/tools/testing/selftests/futex/functional/futex_wait_private_mapped_file.c | |||
@@ -97,8 +97,10 @@ int main(int argc, char **argv) | |||
97 | } | 97 | } |
98 | } | 98 | } |
99 | 99 | ||
100 | printf("%s: Test the futex value of private file mappings in FUTEX_WAIT\n", | 100 | ksft_print_header(); |
101 | basename(argv[0])); | 101 | ksft_print_msg( |
102 | "%s: Test the futex value of private file mappings in FUTEX_WAIT\n", | ||
103 | basename(argv[0])); | ||
102 | 104 | ||
103 | ret = pthread_create(&thr, NULL, thr_futex_wait, NULL); | 105 | ret = pthread_create(&thr, NULL, thr_futex_wait, NULL); |
104 | if (ret < 0) { | 106 | if (ret < 0) { |
diff --git a/tools/testing/selftests/futex/functional/futex_wait_timeout.c b/tools/testing/selftests/futex/functional/futex_wait_timeout.c index 6aadd560366e..bab3dfe1787f 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_timeout.c +++ b/tools/testing/selftests/futex/functional/futex_wait_timeout.c | |||
@@ -68,9 +68,10 @@ int main(int argc, char *argv[]) | |||
68 | } | 68 | } |
69 | } | 69 | } |
70 | 70 | ||
71 | printf("%s: Block on a futex and wait for timeout\n", | 71 | ksft_print_header(); |
72 | ksft_print_msg("%s: Block on a futex and wait for timeout\n", | ||
72 | basename(argv[0])); | 73 | basename(argv[0])); |
73 | printf("\tArguments: timeout=%ldns\n", timeout_ns); | 74 | ksft_print_msg("\tArguments: timeout=%ldns\n", timeout_ns); |
74 | 75 | ||
75 | /* initialize timeout */ | 76 | /* initialize timeout */ |
76 | to.tv_sec = 0; | 77 | to.tv_sec = 0; |
diff --git a/tools/testing/selftests/futex/functional/futex_wait_uninitialized_heap.c b/tools/testing/selftests/futex/functional/futex_wait_uninitialized_heap.c index d237a8b702f0..26975322545b 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_uninitialized_heap.c +++ b/tools/testing/selftests/futex/functional/futex_wait_uninitialized_heap.c | |||
@@ -99,7 +99,8 @@ int main(int argc, char **argv) | |||
99 | exit(1); | 99 | exit(1); |
100 | } | 100 | } |
101 | 101 | ||
102 | printf("%s: Test the uninitialized futex value in FUTEX_WAIT\n", | 102 | ksft_print_header(); |
103 | ksft_print_msg("%s: Test the uninitialized futex value in FUTEX_WAIT\n", | ||
103 | basename(argv[0])); | 104 | basename(argv[0])); |
104 | 105 | ||
105 | 106 | ||
diff --git a/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c index 9a2c56fa7305..da15a63269b4 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c +++ b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c | |||
@@ -64,7 +64,8 @@ int main(int argc, char *argv[]) | |||
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
67 | printf("%s: Test the unexpected futex value in FUTEX_WAIT\n", | 67 | ksft_print_header(); |
68 | ksft_print_msg("%s: Test the unexpected futex value in FUTEX_WAIT\n", | ||
68 | basename(argv[0])); | 69 | basename(argv[0])); |
69 | 70 | ||
70 | info("Calling futex_wait on f1: %u @ %p with val=%u\n", f1, &f1, f1+1); | 71 | info("Calling futex_wait on f1: %u @ %p with val=%u\n", f1, &f1, f1+1); |
diff --git a/tools/testing/selftests/futex/include/logging.h b/tools/testing/selftests/futex/include/logging.h index 4e7944984fbb..01989644e50a 100644 --- a/tools/testing/selftests/futex/include/logging.h +++ b/tools/testing/selftests/futex/include/logging.h | |||
@@ -109,22 +109,20 @@ void log_verbosity(int level) | |||
109 | */ | 109 | */ |
110 | void print_result(const char *test_name, int ret) | 110 | void print_result(const char *test_name, int ret) |
111 | { | 111 | { |
112 | const char *result = "Unknown return code"; | ||
113 | |||
114 | switch (ret) { | 112 | switch (ret) { |
115 | case RET_PASS: | 113 | case RET_PASS: |
116 | ksft_inc_pass_cnt(); | 114 | ksft_test_result_pass("%s\n", test_name); |
117 | result = PASS; | 115 | ksft_print_cnts(); |
118 | break; | 116 | return; |
119 | case RET_ERROR: | 117 | case RET_ERROR: |
120 | result = ERROR; | 118 | ksft_test_result_error("%s\n", test_name); |
121 | break; | 119 | ksft_print_cnts(); |
120 | return; | ||
122 | case RET_FAIL: | 121 | case RET_FAIL: |
123 | ksft_inc_fail_cnt(); | 122 | ksft_test_result_fail("%s\n", test_name); |
124 | result = FAIL; | 123 | ksft_print_cnts(); |
125 | break; | 124 | return; |
126 | } | 125 | } |
127 | printf("selftests: %s [%s]\n", test_name, result); | ||
128 | } | 126 | } |
129 | 127 | ||
130 | /* log level macros */ | 128 | /* log level macros */ |
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index 08e90c2cc5cb..1ae565ed9bf0 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h | |||
@@ -19,7 +19,8 @@ | |||
19 | #define KSFT_FAIL 1 | 19 | #define KSFT_FAIL 1 |
20 | #define KSFT_XFAIL 2 | 20 | #define KSFT_XFAIL 2 |
21 | #define KSFT_XPASS 3 | 21 | #define KSFT_XPASS 3 |
22 | #define KSFT_SKIP 4 | 22 | /* Treat skip as pass */ |
23 | #define KSFT_SKIP KSFT_PASS | ||
23 | 24 | ||
24 | /* counters */ | 25 | /* counters */ |
25 | struct ksft_count { | 26 | struct ksft_count { |
@@ -28,6 +29,7 @@ struct ksft_count { | |||
28 | unsigned int ksft_xfail; | 29 | unsigned int ksft_xfail; |
29 | unsigned int ksft_xpass; | 30 | unsigned int ksft_xpass; |
30 | unsigned int ksft_xskip; | 31 | unsigned int ksft_xskip; |
32 | unsigned int ksft_error; | ||
31 | }; | 33 | }; |
32 | 34 | ||
33 | static struct ksft_count ksft_cnt; | 35 | static struct ksft_count ksft_cnt; |
@@ -36,7 +38,7 @@ static inline int ksft_test_num(void) | |||
36 | { | 38 | { |
37 | return ksft_cnt.ksft_pass + ksft_cnt.ksft_fail + | 39 | return ksft_cnt.ksft_pass + ksft_cnt.ksft_fail + |
38 | ksft_cnt.ksft_xfail + ksft_cnt.ksft_xpass + | 40 | ksft_cnt.ksft_xfail + ksft_cnt.ksft_xpass + |
39 | ksft_cnt.ksft_xskip; | 41 | ksft_cnt.ksft_xskip + ksft_cnt.ksft_error; |
40 | } | 42 | } |
41 | 43 | ||
42 | static inline void ksft_inc_pass_cnt(void) { ksft_cnt.ksft_pass++; } | 44 | static inline void ksft_inc_pass_cnt(void) { ksft_cnt.ksft_pass++; } |
@@ -44,6 +46,14 @@ static inline void ksft_inc_fail_cnt(void) { ksft_cnt.ksft_fail++; } | |||
44 | static inline void ksft_inc_xfail_cnt(void) { ksft_cnt.ksft_xfail++; } | 46 | static inline void ksft_inc_xfail_cnt(void) { ksft_cnt.ksft_xfail++; } |
45 | static inline void ksft_inc_xpass_cnt(void) { ksft_cnt.ksft_xpass++; } | 47 | static inline void ksft_inc_xpass_cnt(void) { ksft_cnt.ksft_xpass++; } |
46 | static inline void ksft_inc_xskip_cnt(void) { ksft_cnt.ksft_xskip++; } | 48 | static inline void ksft_inc_xskip_cnt(void) { ksft_cnt.ksft_xskip++; } |
49 | static inline void ksft_inc_error_cnt(void) { ksft_cnt.ksft_error++; } | ||
50 | |||
51 | static inline int ksft_get_pass_cnt(void) { return ksft_cnt.ksft_pass; } | ||
52 | static inline int ksft_get_fail_cnt(void) { return ksft_cnt.ksft_fail; } | ||
53 | static inline int ksft_get_xfail_cnt(void) { return ksft_cnt.ksft_xfail; } | ||
54 | static inline int ksft_get_xpass_cnt(void) { return ksft_cnt.ksft_xpass; } | ||
55 | static inline int ksft_get_xskip_cnt(void) { return ksft_cnt.ksft_xskip; } | ||
56 | static inline int ksft_get_error_cnt(void) { return ksft_cnt.ksft_error; } | ||
47 | 57 | ||
48 | static inline void ksft_print_header(void) | 58 | static inline void ksft_print_header(void) |
49 | { | 59 | { |
@@ -52,6 +62,10 @@ static inline void ksft_print_header(void) | |||
52 | 62 | ||
53 | static inline void ksft_print_cnts(void) | 63 | static inline void ksft_print_cnts(void) |
54 | { | 64 | { |
65 | printf("Pass %d Fail %d Xfail %d Xpass %d Skip %d Error %d\n", | ||
66 | ksft_cnt.ksft_pass, ksft_cnt.ksft_fail, | ||
67 | ksft_cnt.ksft_xfail, ksft_cnt.ksft_xpass, | ||
68 | ksft_cnt.ksft_xskip, ksft_cnt.ksft_error); | ||
55 | printf("1..%d\n", ksft_test_num()); | 69 | printf("1..%d\n", ksft_test_num()); |
56 | } | 70 | } |
57 | 71 | ||
@@ -101,6 +115,18 @@ static inline void ksft_test_result_skip(const char *msg, ...) | |||
101 | va_end(args); | 115 | va_end(args); |
102 | } | 116 | } |
103 | 117 | ||
118 | static inline void ksft_test_result_error(const char *msg, ...) | ||
119 | { | ||
120 | va_list args; | ||
121 | |||
122 | ksft_cnt.ksft_error++; | ||
123 | |||
124 | va_start(args, msg); | ||
125 | printf("not ok %d # error ", ksft_test_num()); | ||
126 | vprintf(msg, args); | ||
127 | va_end(args); | ||
128 | } | ||
129 | |||
104 | static inline int ksft_exit_pass(void) | 130 | static inline int ksft_exit_pass(void) |
105 | { | 131 | { |
106 | ksft_print_cnts(); | 132 | ksft_print_cnts(); |
diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index c56f72e07cd7..e81bd28bdd89 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h | |||
@@ -51,6 +51,9 @@ | |||
51 | #define __KSELFTEST_HARNESS_H | 51 | #define __KSELFTEST_HARNESS_H |
52 | 52 | ||
53 | #define _GNU_SOURCE | 53 | #define _GNU_SOURCE |
54 | #include <asm/types.h> | ||
55 | #include <errno.h> | ||
56 | #include <stdbool.h> | ||
54 | #include <stdint.h> | 57 | #include <stdint.h> |
55 | #include <stdio.h> | 58 | #include <stdio.h> |
56 | #include <stdlib.h> | 59 | #include <stdlib.h> |
@@ -84,6 +87,14 @@ | |||
84 | * E.g., #define TH_LOG_ENABLED 1 | 87 | * E.g., #define TH_LOG_ENABLED 1 |
85 | * | 88 | * |
86 | * If no definition is provided, logging is enabled by default. | 89 | * If no definition is provided, logging is enabled by default. |
90 | * | ||
91 | * If there is no way to print an error message for the process running the | ||
92 | * test (e.g. not allowed to write to stderr), it is still possible to get the | ||
93 | * ASSERT_* number for which the test failed. This behavior can be enabled by | ||
94 | * writing `_metadata->no_print = true;` before the check sequence that is | ||
95 | * unable to print. When an error occur, instead of printing an error message | ||
96 | * and calling `abort(3)`, the test process call `_exit(2)` with the assert | ||
97 | * number as argument, which is then printed by the parent process. | ||
87 | */ | 98 | */ |
88 | #define TH_LOG(fmt, ...) do { \ | 99 | #define TH_LOG(fmt, ...) do { \ |
89 | if (TH_LOG_ENABLED) \ | 100 | if (TH_LOG_ENABLED) \ |
@@ -555,12 +566,18 @@ | |||
555 | * return while still providing an optional block to the API consumer. | 566 | * return while still providing an optional block to the API consumer. |
556 | */ | 567 | */ |
557 | #define OPTIONAL_HANDLER(_assert) \ | 568 | #define OPTIONAL_HANDLER(_assert) \ |
558 | for (; _metadata->trigger; _metadata->trigger = __bail(_assert)) | 569 | for (; _metadata->trigger; _metadata->trigger = \ |
570 | __bail(_assert, _metadata->no_print, _metadata->step)) | ||
571 | |||
572 | #define __INC_STEP(_metadata) \ | ||
573 | if (_metadata->passed && _metadata->step < 255) \ | ||
574 | _metadata->step++; | ||
559 | 575 | ||
560 | #define __EXPECT(_expected, _seen, _t, _assert) do { \ | 576 | #define __EXPECT(_expected, _seen, _t, _assert) do { \ |
561 | /* Avoid multiple evaluation of the cases */ \ | 577 | /* Avoid multiple evaluation of the cases */ \ |
562 | __typeof__(_expected) __exp = (_expected); \ | 578 | __typeof__(_expected) __exp = (_expected); \ |
563 | __typeof__(_seen) __seen = (_seen); \ | 579 | __typeof__(_seen) __seen = (_seen); \ |
580 | if (_assert) __INC_STEP(_metadata); \ | ||
564 | if (!(__exp _t __seen)) { \ | 581 | if (!(__exp _t __seen)) { \ |
565 | unsigned long long __exp_print = (uintptr_t)__exp; \ | 582 | unsigned long long __exp_print = (uintptr_t)__exp; \ |
566 | unsigned long long __seen_print = (uintptr_t)__seen; \ | 583 | unsigned long long __seen_print = (uintptr_t)__seen; \ |
@@ -576,6 +593,7 @@ | |||
576 | #define __EXPECT_STR(_expected, _seen, _t, _assert) do { \ | 593 | #define __EXPECT_STR(_expected, _seen, _t, _assert) do { \ |
577 | const char *__exp = (_expected); \ | 594 | const char *__exp = (_expected); \ |
578 | const char *__seen = (_seen); \ | 595 | const char *__seen = (_seen); \ |
596 | if (_assert) __INC_STEP(_metadata); \ | ||
579 | if (!(strcmp(__exp, __seen) _t 0)) { \ | 597 | if (!(strcmp(__exp, __seen) _t 0)) { \ |
580 | __TH_LOG("Expected '%s' %s '%s'.", __exp, #_t, __seen); \ | 598 | __TH_LOG("Expected '%s' %s '%s'.", __exp, #_t, __seen); \ |
581 | _metadata->passed = 0; \ | 599 | _metadata->passed = 0; \ |
@@ -590,6 +608,8 @@ struct __test_metadata { | |||
590 | int termsig; | 608 | int termsig; |
591 | int passed; | 609 | int passed; |
592 | int trigger; /* extra handler after the evaluation */ | 610 | int trigger; /* extra handler after the evaluation */ |
611 | __u8 step; | ||
612 | bool no_print; /* manual trigger when TH_LOG_STREAM is not available */ | ||
593 | struct __test_metadata *prev, *next; | 613 | struct __test_metadata *prev, *next; |
594 | }; | 614 | }; |
595 | 615 | ||
@@ -634,10 +654,13 @@ static inline void __register_test(struct __test_metadata *t) | |||
634 | } | 654 | } |
635 | } | 655 | } |
636 | 656 | ||
637 | static inline int __bail(int for_realz) | 657 | static inline int __bail(int for_realz, bool no_print, __u8 step) |
638 | { | 658 | { |
639 | if (for_realz) | 659 | if (for_realz) { |
660 | if (no_print) | ||
661 | _exit(step); | ||
640 | abort(); | 662 | abort(); |
663 | } | ||
641 | return 0; | 664 | return 0; |
642 | } | 665 | } |
643 | 666 | ||
@@ -655,18 +678,24 @@ void __run_test(struct __test_metadata *t) | |||
655 | t->passed = 0; | 678 | t->passed = 0; |
656 | } else if (child_pid == 0) { | 679 | } else if (child_pid == 0) { |
657 | t->fn(t); | 680 | t->fn(t); |
658 | _exit(t->passed); | 681 | /* return the step that failed or 0 */ |
682 | _exit(t->passed ? 0 : t->step); | ||
659 | } else { | 683 | } else { |
660 | /* TODO(wad) add timeout support. */ | 684 | /* TODO(wad) add timeout support. */ |
661 | waitpid(child_pid, &status, 0); | 685 | waitpid(child_pid, &status, 0); |
662 | if (WIFEXITED(status)) { | 686 | if (WIFEXITED(status)) { |
663 | t->passed = t->termsig == -1 ? WEXITSTATUS(status) : 0; | 687 | t->passed = t->termsig == -1 ? !WEXITSTATUS(status) : 0; |
664 | if (t->termsig != -1) { | 688 | if (t->termsig != -1) { |
665 | fprintf(TH_LOG_STREAM, | 689 | fprintf(TH_LOG_STREAM, |
666 | "%s: Test exited normally " | 690 | "%s: Test exited normally " |
667 | "instead of by signal (code: %d)\n", | 691 | "instead of by signal (code: %d)\n", |
668 | t->name, | 692 | t->name, |
669 | WEXITSTATUS(status)); | 693 | WEXITSTATUS(status)); |
694 | } else if (!t->passed) { | ||
695 | fprintf(TH_LOG_STREAM, | ||
696 | "%s: Test failed at step #%d\n", | ||
697 | t->name, | ||
698 | WEXITSTATUS(status)); | ||
670 | } | 699 | } |
671 | } else if (WIFSIGNALED(status)) { | 700 | } else if (WIFSIGNALED(status)) { |
672 | t->passed = 0; | 701 | t->passed = 0; |
diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk index 959273c3a52e..693616651da5 100644 --- a/tools/testing/selftests/lib.mk +++ b/tools/testing/selftests/lib.mk | |||
@@ -11,15 +11,26 @@ TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) | |||
11 | 11 | ||
12 | all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) | 12 | all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) |
13 | 13 | ||
14 | .ONESHELL: | ||
14 | define RUN_TESTS | 15 | define RUN_TESTS |
15 | @for TEST in $(TEST_GEN_PROGS) $(TEST_PROGS); do \ | 16 | @test_num=`echo 0`; |
17 | @echo "TAP version 13"; | ||
18 | @for TEST in $(1); do \ | ||
16 | BASENAME_TEST=`basename $$TEST`; \ | 19 | BASENAME_TEST=`basename $$TEST`; \ |
17 | cd `dirname $$TEST`; (./$$BASENAME_TEST && echo "selftests: $$BASENAME_TEST [PASS]") || echo "selftests: $$BASENAME_TEST [FAIL]"; cd -;\ | 20 | test_num=`echo $$test_num+1 | bc`; \ |
21 | echo "selftests: $$BASENAME_TEST"; \ | ||
22 | echo "========================================"; \ | ||
23 | if [ ! -x $$BASENAME_TEST ]; then \ | ||
24 | echo "selftests: Warning: file $$BASENAME_TEST is not executable, correct this.";\ | ||
25 | echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; \ | ||
26 | else \ | ||
27 | cd `dirname $$TEST` > /dev/null; (./$$BASENAME_TEST && echo "ok 1..$$test_num selftests: $$BASENAME_TEST [PASS]") || echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; cd - > /dev/null;\ | ||
28 | fi; \ | ||
18 | done; | 29 | done; |
19 | endef | 30 | endef |
20 | 31 | ||
21 | run_tests: all | 32 | run_tests: all |
22 | $(RUN_TESTS) | 33 | $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_PROGS)) |
23 | 34 | ||
24 | define INSTALL_RULE | 35 | define INSTALL_RULE |
25 | @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ | 36 | @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ |
diff --git a/tools/testing/selftests/memfd/fuse_test.c b/tools/testing/selftests/memfd/fuse_test.c index 67908b18f035..7f3617274bf5 100644 --- a/tools/testing/selftests/memfd/fuse_test.c +++ b/tools/testing/selftests/memfd/fuse_test.c | |||
@@ -33,7 +33,7 @@ | |||
33 | #include <unistd.h> | 33 | #include <unistd.h> |
34 | 34 | ||
35 | #define MFD_DEF_SIZE 8192 | 35 | #define MFD_DEF_SIZE 8192 |
36 | #define STACK_SIZE 65535 | 36 | #define STACK_SIZE 65536 |
37 | 37 | ||
38 | static int sys_memfd_create(const char *name, | 38 | static int sys_memfd_create(const char *name, |
39 | unsigned int flags) | 39 | unsigned int flags) |
diff --git a/tools/testing/selftests/nsfs/config b/tools/testing/selftests/nsfs/config new file mode 100644 index 000000000000..598d0a225fc9 --- /dev/null +++ b/tools/testing/selftests/nsfs/config | |||
@@ -0,0 +1,3 @@ | |||
1 | CONFIG_USER_NS=y | ||
2 | CONFIG_UTS_NS=y | ||
3 | CONFIG_PID_NS=y | ||
diff --git a/tools/testing/selftests/pstore/.gitignore b/tools/testing/selftests/pstore/.gitignore new file mode 100644 index 000000000000..5a4a26e5464b --- /dev/null +++ b/tools/testing/selftests/pstore/.gitignore | |||
@@ -0,0 +1,2 @@ | |||
1 | logs | ||
2 | *uuid | ||
diff --git a/tools/testing/selftests/ptp/Makefile b/tools/testing/selftests/ptp/Makefile index 83dd42b2129e..d4064c742c26 100644 --- a/tools/testing/selftests/ptp/Makefile +++ b/tools/testing/selftests/ptp/Makefile | |||
@@ -1,3 +1,4 @@ | |||
1 | CFLAGS += -I../../../../usr/include/ | ||
1 | TEST_PROGS := testptp | 2 | TEST_PROGS := testptp |
2 | LDLIBS += -lrt | 3 | LDLIBS += -lrt |
3 | all: $(TEST_PROGS) | 4 | all: $(TEST_PROGS) |
diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c index 73f5ea6778ce..4d6f92a9df6b 100644 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c | |||
@@ -107,7 +107,7 @@ TEST(mode_strict_support) | |||
107 | ASSERT_EQ(0, ret) { | 107 | ASSERT_EQ(0, ret) { |
108 | TH_LOG("Kernel does not support CONFIG_SECCOMP"); | 108 | TH_LOG("Kernel does not support CONFIG_SECCOMP"); |
109 | } | 109 | } |
110 | syscall(__NR_exit, 1); | 110 | syscall(__NR_exit, 0); |
111 | } | 111 | } |
112 | 112 | ||
113 | TEST_SIGNAL(mode_strict_cannot_call_prctl, SIGKILL) | 113 | TEST_SIGNAL(mode_strict_cannot_call_prctl, SIGKILL) |
diff --git a/tools/testing/selftests/sigaltstack/sas.c b/tools/testing/selftests/sigaltstack/sas.c index ccd07343d418..7d406c3973ba 100644 --- a/tools/testing/selftests/sigaltstack/sas.c +++ b/tools/testing/selftests/sigaltstack/sas.c | |||
@@ -17,6 +17,8 @@ | |||
17 | #include <assert.h> | 17 | #include <assert.h> |
18 | #include <errno.h> | 18 | #include <errno.h> |
19 | 19 | ||
20 | #include "../kselftest.h" | ||
21 | |||
20 | #ifndef SS_AUTODISARM | 22 | #ifndef SS_AUTODISARM |
21 | #define SS_AUTODISARM (1U << 31) | 23 | #define SS_AUTODISARM (1U << 31) |
22 | #endif | 24 | #endif |
@@ -41,8 +43,7 @@ void my_usr1(int sig, siginfo_t *si, void *u) | |||
41 | 43 | ||
42 | if (sp < (unsigned long)sstack || | 44 | if (sp < (unsigned long)sstack || |
43 | sp >= (unsigned long)sstack + SIGSTKSZ) { | 45 | sp >= (unsigned long)sstack + SIGSTKSZ) { |
44 | printf("[FAIL]\tSP is not on sigaltstack\n"); | 46 | ksft_exit_fail_msg("SP is not on sigaltstack\n"); |
45 | exit(EXIT_FAILURE); | ||
46 | } | 47 | } |
47 | /* put some data on stack. other sighandler will try to overwrite it */ | 48 | /* put some data on stack. other sighandler will try to overwrite it */ |
48 | aa = alloca(1024); | 49 | aa = alloca(1024); |
@@ -50,21 +51,22 @@ void my_usr1(int sig, siginfo_t *si, void *u) | |||
50 | p = (struct stk_data *)(aa + 512); | 51 | p = (struct stk_data *)(aa + 512); |
51 | strcpy(p->msg, msg); | 52 | strcpy(p->msg, msg); |
52 | p->flag = 1; | 53 | p->flag = 1; |
53 | printf("[RUN]\tsignal USR1\n"); | 54 | ksft_print_msg("[RUN]\tsignal USR1\n"); |
54 | err = sigaltstack(NULL, &stk); | 55 | err = sigaltstack(NULL, &stk); |
55 | if (err) { | 56 | if (err) { |
56 | perror("[FAIL]\tsigaltstack()"); | 57 | ksft_exit_fail_msg("sigaltstack() - %s\n", strerror(errno)); |
57 | exit(EXIT_FAILURE); | 58 | exit(EXIT_FAILURE); |
58 | } | 59 | } |
59 | if (stk.ss_flags != SS_DISABLE) | 60 | if (stk.ss_flags != SS_DISABLE) |
60 | printf("[FAIL]\tss_flags=%x, should be SS_DISABLE\n", | 61 | ksft_test_result_fail("tss_flags=%x, should be SS_DISABLE\n", |
61 | stk.ss_flags); | 62 | stk.ss_flags); |
62 | else | 63 | else |
63 | printf("[OK]\tsigaltstack is disabled in sighandler\n"); | 64 | ksft_test_result_pass( |
65 | "sigaltstack is disabled in sighandler\n"); | ||
64 | swapcontext(&sc, &uc); | 66 | swapcontext(&sc, &uc); |
65 | printf("%s\n", p->msg); | 67 | ksft_print_msg("%s\n", p->msg); |
66 | if (!p->flag) { | 68 | if (!p->flag) { |
67 | printf("[RUN]\tAborting\n"); | 69 | ksft_exit_skip("[RUN]\tAborting\n"); |
68 | exit(EXIT_FAILURE); | 70 | exit(EXIT_FAILURE); |
69 | } | 71 | } |
70 | } | 72 | } |
@@ -74,13 +76,13 @@ void my_usr2(int sig, siginfo_t *si, void *u) | |||
74 | char *aa; | 76 | char *aa; |
75 | struct stk_data *p; | 77 | struct stk_data *p; |
76 | 78 | ||
77 | printf("[RUN]\tsignal USR2\n"); | 79 | ksft_print_msg("[RUN]\tsignal USR2\n"); |
78 | aa = alloca(1024); | 80 | aa = alloca(1024); |
79 | /* dont run valgrind on this */ | 81 | /* dont run valgrind on this */ |
80 | /* try to find the data stored by previous sighandler */ | 82 | /* try to find the data stored by previous sighandler */ |
81 | p = memmem(aa, 1024, msg, strlen(msg)); | 83 | p = memmem(aa, 1024, msg, strlen(msg)); |
82 | if (p) { | 84 | if (p) { |
83 | printf("[FAIL]\tsigaltstack re-used\n"); | 85 | ksft_test_result_fail("sigaltstack re-used\n"); |
84 | /* corrupt the data */ | 86 | /* corrupt the data */ |
85 | strcpy(p->msg, msg2); | 87 | strcpy(p->msg, msg2); |
86 | /* tell other sighandler that his data is corrupted */ | 88 | /* tell other sighandler that his data is corrupted */ |
@@ -90,7 +92,7 @@ void my_usr2(int sig, siginfo_t *si, void *u) | |||
90 | 92 | ||
91 | static void switch_fn(void) | 93 | static void switch_fn(void) |
92 | { | 94 | { |
93 | printf("[RUN]\tswitched to user ctx\n"); | 95 | ksft_print_msg("[RUN]\tswitched to user ctx\n"); |
94 | raise(SIGUSR2); | 96 | raise(SIGUSR2); |
95 | setcontext(&sc); | 97 | setcontext(&sc); |
96 | } | 98 | } |
@@ -101,6 +103,8 @@ int main(void) | |||
101 | stack_t stk; | 103 | stack_t stk; |
102 | int err; | 104 | int err; |
103 | 105 | ||
106 | ksft_print_header(); | ||
107 | |||
104 | sigemptyset(&act.sa_mask); | 108 | sigemptyset(&act.sa_mask); |
105 | act.sa_flags = SA_ONSTACK | SA_SIGINFO; | 109 | act.sa_flags = SA_ONSTACK | SA_SIGINFO; |
106 | act.sa_sigaction = my_usr1; | 110 | act.sa_sigaction = my_usr1; |
@@ -110,19 +114,20 @@ int main(void) | |||
110 | sstack = mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE, | 114 | sstack = mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE, |
111 | MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0); | 115 | MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0); |
112 | if (sstack == MAP_FAILED) { | 116 | if (sstack == MAP_FAILED) { |
113 | perror("mmap()"); | 117 | ksft_exit_fail_msg("mmap() - %s\n", strerror(errno)); |
114 | return EXIT_FAILURE; | 118 | return EXIT_FAILURE; |
115 | } | 119 | } |
116 | 120 | ||
117 | err = sigaltstack(NULL, &stk); | 121 | err = sigaltstack(NULL, &stk); |
118 | if (err) { | 122 | if (err) { |
119 | perror("[FAIL]\tsigaltstack()"); | 123 | ksft_exit_fail_msg("sigaltstack() - %s\n", strerror(errno)); |
120 | exit(EXIT_FAILURE); | 124 | exit(EXIT_FAILURE); |
121 | } | 125 | } |
122 | if (stk.ss_flags == SS_DISABLE) { | 126 | if (stk.ss_flags == SS_DISABLE) { |
123 | printf("[OK]\tInitial sigaltstack state was SS_DISABLE\n"); | 127 | ksft_test_result_pass( |
128 | "Initial sigaltstack state was SS_DISABLE\n"); | ||
124 | } else { | 129 | } else { |
125 | printf("[FAIL]\tInitial sigaltstack state was %x; " | 130 | ksft_exit_fail_msg("Initial sigaltstack state was %x; " |
126 | "should have been SS_DISABLE\n", stk.ss_flags); | 131 | "should have been SS_DISABLE\n", stk.ss_flags); |
127 | return EXIT_FAILURE; | 132 | return EXIT_FAILURE; |
128 | } | 133 | } |
@@ -133,7 +138,8 @@ int main(void) | |||
133 | err = sigaltstack(&stk, NULL); | 138 | err = sigaltstack(&stk, NULL); |
134 | if (err) { | 139 | if (err) { |
135 | if (errno == EINVAL) { | 140 | if (errno == EINVAL) { |
136 | printf("[NOTE]\tThe running kernel doesn't support SS_AUTODISARM\n"); | 141 | ksft_exit_skip( |
142 | "[NOTE]\tThe running kernel doesn't support SS_AUTODISARM\n"); | ||
137 | /* | 143 | /* |
138 | * If test cases for the !SS_AUTODISARM variant were | 144 | * If test cases for the !SS_AUTODISARM variant were |
139 | * added, we could still run them. We don't have any | 145 | * added, we could still run them. We don't have any |
@@ -142,7 +148,9 @@ int main(void) | |||
142 | */ | 148 | */ |
143 | return 0; | 149 | return 0; |
144 | } else { | 150 | } else { |
145 | perror("[FAIL]\tsigaltstack(SS_ONSTACK | SS_AUTODISARM)"); | 151 | ksft_exit_fail_msg( |
152 | "sigaltstack(SS_ONSTACK | SS_AUTODISARM) %s\n", | ||
153 | strerror(errno)); | ||
146 | return EXIT_FAILURE; | 154 | return EXIT_FAILURE; |
147 | } | 155 | } |
148 | } | 156 | } |
@@ -150,7 +158,7 @@ int main(void) | |||
150 | ustack = mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE, | 158 | ustack = mmap(NULL, SIGSTKSZ, PROT_READ | PROT_WRITE, |
151 | MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0); | 159 | MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0); |
152 | if (ustack == MAP_FAILED) { | 160 | if (ustack == MAP_FAILED) { |
153 | perror("mmap()"); | 161 | ksft_exit_fail_msg("mmap() - %s\n", strerror(errno)); |
154 | return EXIT_FAILURE; | 162 | return EXIT_FAILURE; |
155 | } | 163 | } |
156 | getcontext(&uc); | 164 | getcontext(&uc); |
@@ -162,16 +170,17 @@ int main(void) | |||
162 | 170 | ||
163 | err = sigaltstack(NULL, &stk); | 171 | err = sigaltstack(NULL, &stk); |
164 | if (err) { | 172 | if (err) { |
165 | perror("[FAIL]\tsigaltstack()"); | 173 | ksft_exit_fail_msg("sigaltstack() - %s\n", strerror(errno)); |
166 | exit(EXIT_FAILURE); | 174 | exit(EXIT_FAILURE); |
167 | } | 175 | } |
168 | if (stk.ss_flags != SS_AUTODISARM) { | 176 | if (stk.ss_flags != SS_AUTODISARM) { |
169 | printf("[FAIL]\tss_flags=%x, should be SS_AUTODISARM\n", | 177 | ksft_exit_fail_msg("ss_flags=%x, should be SS_AUTODISARM\n", |
170 | stk.ss_flags); | 178 | stk.ss_flags); |
171 | exit(EXIT_FAILURE); | 179 | exit(EXIT_FAILURE); |
172 | } | 180 | } |
173 | printf("[OK]\tsigaltstack is still SS_AUTODISARM after signal\n"); | 181 | ksft_test_result_pass( |
182 | "sigaltstack is still SS_AUTODISARM after signal\n"); | ||
174 | 183 | ||
175 | printf("[OK]\tTest passed\n"); | 184 | ksft_exit_pass(); |
176 | return 0; | 185 | return 0; |
177 | } | 186 | } |
diff --git a/tools/testing/selftests/splice/.gitignore b/tools/testing/selftests/splice/.gitignore new file mode 100644 index 000000000000..1e23fefd68e8 --- /dev/null +++ b/tools/testing/selftests/splice/.gitignore | |||
@@ -0,0 +1 @@ | |||
default_file_splice_read | |||
diff --git a/tools/testing/selftests/splice/Makefile b/tools/testing/selftests/splice/Makefile index 9fc78e5e5451..7e1187e007fa 100644 --- a/tools/testing/selftests/splice/Makefile +++ b/tools/testing/selftests/splice/Makefile | |||
@@ -1,7 +1,4 @@ | |||
1 | TEST_PROGS := default_file_splice_read.sh | 1 | TEST_PROGS := default_file_splice_read.sh |
2 | EXTRA := default_file_splice_read | 2 | TEST_GEN_PROGS_EXTENDED := default_file_splice_read |
3 | all: $(TEST_PROGS) $(EXTRA) | ||
4 | 3 | ||
5 | include ../lib.mk | 4 | include ../lib.mk |
6 | |||
7 | EXTRA_CLEAN := $(EXTRA) | ||
diff --git a/tools/testing/selftests/sync/sync_test.c b/tools/testing/selftests/sync/sync_test.c index 62fa666e501a..7f7938263c5c 100644 --- a/tools/testing/selftests/sync/sync_test.c +++ b/tools/testing/selftests/sync/sync_test.c | |||
@@ -31,62 +31,83 @@ | |||
31 | #include <sys/types.h> | 31 | #include <sys/types.h> |
32 | #include <sys/stat.h> | 32 | #include <sys/stat.h> |
33 | #include <sys/wait.h> | 33 | #include <sys/wait.h> |
34 | #include <errno.h> | ||
35 | #include <string.h> | ||
34 | 36 | ||
37 | #include "../kselftest.h" | ||
35 | #include "synctest.h" | 38 | #include "synctest.h" |
36 | 39 | ||
37 | static int run_test(int (*test)(void), char *name) | 40 | static int run_test(int (*test)(void), char *name) |
38 | { | 41 | { |
39 | int result; | 42 | int result; |
40 | pid_t childpid; | 43 | pid_t childpid; |
44 | int ret; | ||
41 | 45 | ||
42 | fflush(stdout); | 46 | fflush(stdout); |
43 | childpid = fork(); | 47 | childpid = fork(); |
44 | 48 | ||
45 | if (childpid) { | 49 | if (childpid) { |
46 | waitpid(childpid, &result, 0); | 50 | waitpid(childpid, &result, 0); |
47 | if (WIFEXITED(result)) | 51 | if (WIFEXITED(result)) { |
48 | return WEXITSTATUS(result); | 52 | ret = WEXITSTATUS(result); |
53 | if (!ret) | ||
54 | ksft_test_result_pass("[RUN]\t%s\n", name); | ||
55 | else | ||
56 | ksft_test_result_fail("[RUN]\t%s\n", name); | ||
57 | return ret; | ||
58 | } | ||
49 | return 1; | 59 | return 1; |
50 | } | 60 | } |
51 | 61 | ||
52 | printf("[RUN]\tExecuting %s\n", name); | ||
53 | exit(test()); | 62 | exit(test()); |
54 | } | 63 | } |
55 | 64 | ||
56 | static int sync_api_supported(void) | 65 | static void sync_api_supported(void) |
57 | { | 66 | { |
58 | struct stat sbuf; | 67 | struct stat sbuf; |
68 | int ret; | ||
59 | 69 | ||
60 | return 0 == stat("/sys/kernel/debug/sync/sw_sync", &sbuf); | 70 | ret = stat("/sys/kernel/debug/sync/sw_sync", &sbuf); |
71 | if (!ret) | ||
72 | return; | ||
73 | |||
74 | if (errno == ENOENT) | ||
75 | ksft_exit_skip("Sync framework not supported by kernel\n"); | ||
76 | |||
77 | if (errno == EACCES) | ||
78 | ksft_exit_skip("Run Sync test as root.\n"); | ||
79 | |||
80 | ksft_exit_fail_msg("stat failed on /sys/kernel/debug/sync/sw_sync: %s", | ||
81 | strerror(errno)); | ||
61 | } | 82 | } |
62 | 83 | ||
63 | int main(void) | 84 | int main(void) |
64 | { | 85 | { |
65 | int err = 0; | 86 | int err; |
66 | 87 | ||
67 | if (!sync_api_supported()) { | 88 | ksft_print_header(); |
68 | printf("SKIP: Sync framework not supported by kernel\n"); | 89 | |
69 | return 0; | 90 | sync_api_supported(); |
70 | } | ||
71 | 91 | ||
72 | printf("[RUN]\tTesting sync framework\n"); | 92 | ksft_print_msg("[RUN]\tTesting sync framework\n"); |
73 | 93 | ||
74 | err += RUN_TEST(test_alloc_timeline); | 94 | RUN_TEST(test_alloc_timeline); |
75 | err += RUN_TEST(test_alloc_fence); | 95 | RUN_TEST(test_alloc_fence); |
76 | err += RUN_TEST(test_alloc_fence_negative); | 96 | RUN_TEST(test_alloc_fence_negative); |
77 | 97 | ||
78 | err += RUN_TEST(test_fence_one_timeline_wait); | 98 | RUN_TEST(test_fence_one_timeline_wait); |
79 | err += RUN_TEST(test_fence_one_timeline_merge); | 99 | RUN_TEST(test_fence_one_timeline_merge); |
80 | err += RUN_TEST(test_fence_merge_same_fence); | 100 | RUN_TEST(test_fence_merge_same_fence); |
81 | err += RUN_TEST(test_fence_multi_timeline_wait); | 101 | RUN_TEST(test_fence_multi_timeline_wait); |
82 | err += RUN_TEST(test_stress_two_threads_shared_timeline); | 102 | RUN_TEST(test_stress_two_threads_shared_timeline); |
83 | err += RUN_TEST(test_consumer_stress_multi_producer_single_consumer); | 103 | RUN_TEST(test_consumer_stress_multi_producer_single_consumer); |
84 | err += RUN_TEST(test_merge_stress_random_merge); | 104 | RUN_TEST(test_merge_stress_random_merge); |
85 | 105 | ||
106 | err = ksft_get_fail_cnt(); | ||
86 | if (err) | 107 | if (err) |
87 | printf("[FAIL]\tsync errors: %d\n", err); | 108 | ksft_exit_fail_msg("%d out of %d sync tests failed\n", |
88 | else | 109 | err, ksft_test_num()); |
89 | printf("[OK]\tsync\n"); | ||
90 | 110 | ||
91 | return !!err; | 111 | /* need this return to keep gcc happy */ |
112 | return ksft_exit_pass(); | ||
92 | } | 113 | } |
diff --git a/tools/testing/selftests/sync/synctest.h b/tools/testing/selftests/sync/synctest.h index e7d1d57dba7a..90a8e5369914 100644 --- a/tools/testing/selftests/sync/synctest.h +++ b/tools/testing/selftests/sync/synctest.h | |||
@@ -29,10 +29,11 @@ | |||
29 | #define SELFTESTS_SYNCTEST_H | 29 | #define SELFTESTS_SYNCTEST_H |
30 | 30 | ||
31 | #include <stdio.h> | 31 | #include <stdio.h> |
32 | #include "../kselftest.h" | ||
32 | 33 | ||
33 | #define ASSERT(cond, msg) do { \ | 34 | #define ASSERT(cond, msg) do { \ |
34 | if (!(cond)) { \ | 35 | if (!(cond)) { \ |
35 | printf("[ERROR]\t%s", (msg)); \ | 36 | ksft_print_msg("[ERROR]\t%s", (msg)); \ |
36 | return 1; \ | 37 | return 1; \ |
37 | } \ | 38 | } \ |
38 | } while (0) | 39 | } while (0) |
diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile index a9b86133b9b3..ae4593115408 100644 --- a/tools/testing/selftests/timers/Makefile +++ b/tools/testing/selftests/timers/Makefile | |||
@@ -1,5 +1,4 @@ | |||
1 | BUILD_FLAGS = -DKTEST | 1 | CFLAGS += -O3 -Wl,-no-as-needed -Wall |
2 | CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS) | ||
3 | LDFLAGS += -lrt -lpthread -lm | 2 | LDFLAGS += -lrt -lpthread -lm |
4 | 3 | ||
5 | # these are all "safe" tests that don't modify | 4 | # these are all "safe" tests that don't modify |
@@ -7,9 +6,11 @@ LDFLAGS += -lrt -lpthread -lm | |||
7 | TEST_GEN_PROGS = posix_timers nanosleep nsleep-lat set-timer-lat mqueue-lat \ | 6 | TEST_GEN_PROGS = posix_timers nanosleep nsleep-lat set-timer-lat mqueue-lat \ |
8 | inconsistency-check raw_skew threadtest rtctest | 7 | inconsistency-check raw_skew threadtest rtctest |
9 | 8 | ||
10 | TEST_GEN_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \ | 9 | DESTRUCTIVE_TESTS = alarmtimer-suspend valid-adjtimex adjtick change_skew \ |
11 | skew_consistency clocksource-switch freq-step leap-a-day \ | 10 | skew_consistency clocksource-switch freq-step leap-a-day \ |
12 | leapcrash set-tai set-2038 set-tz rtctest_setdate | 11 | leapcrash set-tai set-2038 set-tz |
12 | |||
13 | TEST_GEN_PROGS_EXTENDED = $(DESTRUCTIVE_TESTS) rtctest_setdate | ||
13 | 14 | ||
14 | 15 | ||
15 | include ../lib.mk | 16 | include ../lib.mk |
@@ -18,16 +19,4 @@ include ../lib.mk | |||
18 | # and may modify the system time or trigger | 19 | # and may modify the system time or trigger |
19 | # other behavior like suspend | 20 | # other behavior like suspend |
20 | run_destructive_tests: run_tests | 21 | run_destructive_tests: run_tests |
21 | ./alarmtimer-suspend | 22 | $(call RUN_TESTS, $(DESTRUCTIVE_TESTS)) |
22 | ./valid-adjtimex | ||
23 | ./adjtick | ||
24 | ./change_skew | ||
25 | ./skew_consistency | ||
26 | ./clocksource-switch | ||
27 | ./freq-step | ||
28 | ./leap-a-day -s -i 10 | ||
29 | ./leapcrash | ||
30 | ./set-tz | ||
31 | ./set-tai | ||
32 | ./set-2038 | ||
33 | |||
diff --git a/tools/testing/selftests/timers/adjtick.c b/tools/testing/selftests/timers/adjtick.c index 9887fd538fec..0caca3a06bd2 100644 --- a/tools/testing/selftests/timers/adjtick.c +++ b/tools/testing/selftests/timers/adjtick.c | |||
@@ -23,18 +23,7 @@ | |||
23 | #include <sys/timex.h> | 23 | #include <sys/timex.h> |
24 | #include <time.h> | 24 | #include <time.h> |
25 | 25 | ||
26 | #ifdef KTEST | ||
27 | #include "../kselftest.h" | 26 | #include "../kselftest.h" |
28 | #else | ||
29 | static inline int ksft_exit_pass(void) | ||
30 | { | ||
31 | exit(0); | ||
32 | } | ||
33 | static inline int ksft_exit_fail(void) | ||
34 | { | ||
35 | exit(1); | ||
36 | } | ||
37 | #endif | ||
38 | 27 | ||
39 | #define CLOCK_MONOTONIC_RAW 4 | 28 | #define CLOCK_MONOTONIC_RAW 4 |
40 | 29 | ||
diff --git a/tools/testing/selftests/timers/alarmtimer-suspend.c b/tools/testing/selftests/timers/alarmtimer-suspend.c index 2b361b830395..4da09dbf83ba 100644 --- a/tools/testing/selftests/timers/alarmtimer-suspend.c +++ b/tools/testing/selftests/timers/alarmtimer-suspend.c | |||
@@ -28,18 +28,7 @@ | |||
28 | #include <signal.h> | 28 | #include <signal.h> |
29 | #include <stdlib.h> | 29 | #include <stdlib.h> |
30 | #include <pthread.h> | 30 | #include <pthread.h> |
31 | #ifdef KTEST | ||
32 | #include "../kselftest.h" | 31 | #include "../kselftest.h" |
33 | #else | ||
34 | static inline int ksft_exit_pass(void) | ||
35 | { | ||
36 | exit(0); | ||
37 | } | ||
38 | static inline int ksft_exit_fail(void) | ||
39 | { | ||
40 | exit(1); | ||
41 | } | ||
42 | #endif | ||
43 | 32 | ||
44 | #define CLOCK_REALTIME 0 | 33 | #define CLOCK_REALTIME 0 |
45 | #define CLOCK_MONOTONIC 1 | 34 | #define CLOCK_MONOTONIC 1 |
diff --git a/tools/testing/selftests/timers/change_skew.c b/tools/testing/selftests/timers/change_skew.c index cb1968977c04..c4eab7124990 100644 --- a/tools/testing/selftests/timers/change_skew.c +++ b/tools/testing/selftests/timers/change_skew.c | |||
@@ -28,18 +28,7 @@ | |||
28 | #include <sys/time.h> | 28 | #include <sys/time.h> |
29 | #include <sys/timex.h> | 29 | #include <sys/timex.h> |
30 | #include <time.h> | 30 | #include <time.h> |
31 | #ifdef KTEST | ||
32 | #include "../kselftest.h" | 31 | #include "../kselftest.h" |
33 | #else | ||
34 | static inline int ksft_exit_pass(void) | ||
35 | { | ||
36 | exit(0); | ||
37 | } | ||
38 | static inline int ksft_exit_fail(void) | ||
39 | { | ||
40 | exit(1); | ||
41 | } | ||
42 | #endif | ||
43 | 32 | ||
44 | #define NSEC_PER_SEC 1000000000LL | 33 | #define NSEC_PER_SEC 1000000000LL |
45 | 34 | ||
diff --git a/tools/testing/selftests/timers/clocksource-switch.c b/tools/testing/selftests/timers/clocksource-switch.c index 5ff165373f8b..bfc974b4572d 100644 --- a/tools/testing/selftests/timers/clocksource-switch.c +++ b/tools/testing/selftests/timers/clocksource-switch.c | |||
@@ -34,18 +34,7 @@ | |||
34 | #include <fcntl.h> | 34 | #include <fcntl.h> |
35 | #include <string.h> | 35 | #include <string.h> |
36 | #include <sys/wait.h> | 36 | #include <sys/wait.h> |
37 | #ifdef KTEST | ||
38 | #include "../kselftest.h" | 37 | #include "../kselftest.h" |
39 | #else | ||
40 | static inline int ksft_exit_pass(void) | ||
41 | { | ||
42 | exit(0); | ||
43 | } | ||
44 | static inline int ksft_exit_fail(void) | ||
45 | { | ||
46 | exit(1); | ||
47 | } | ||
48 | #endif | ||
49 | 38 | ||
50 | 39 | ||
51 | int get_clocksources(char list[][30]) | 40 | int get_clocksources(char list[][30]) |
@@ -61,7 +50,7 @@ int get_clocksources(char list[][30]) | |||
61 | 50 | ||
62 | close(fd); | 51 | close(fd); |
63 | 52 | ||
64 | for (i = 0; i < 30; i++) | 53 | for (i = 0; i < 10; i++) |
65 | list[i][0] = '\0'; | 54 | list[i][0] = '\0'; |
66 | 55 | ||
67 | head = buf; | 56 | head = buf; |
diff --git a/tools/testing/selftests/timers/inconsistency-check.c b/tools/testing/selftests/timers/inconsistency-check.c index 74c60e8759a0..022d3ffe3fbf 100644 --- a/tools/testing/selftests/timers/inconsistency-check.c +++ b/tools/testing/selftests/timers/inconsistency-check.c | |||
@@ -28,18 +28,7 @@ | |||
28 | #include <sys/timex.h> | 28 | #include <sys/timex.h> |
29 | #include <string.h> | 29 | #include <string.h> |
30 | #include <signal.h> | 30 | #include <signal.h> |
31 | #ifdef KTEST | ||
32 | #include "../kselftest.h" | 31 | #include "../kselftest.h" |
33 | #else | ||
34 | static inline int ksft_exit_pass(void) | ||
35 | { | ||
36 | exit(0); | ||
37 | } | ||
38 | static inline int ksft_exit_fail(void) | ||
39 | { | ||
40 | exit(1); | ||
41 | } | ||
42 | #endif | ||
43 | 32 | ||
44 | #define CALLS_PER_LOOP 64 | 33 | #define CALLS_PER_LOOP 64 |
45 | #define NSEC_PER_SEC 1000000000ULL | 34 | #define NSEC_PER_SEC 1000000000ULL |
diff --git a/tools/testing/selftests/timers/leap-a-day.c b/tools/testing/selftests/timers/leap-a-day.c index fb46ad6ac92c..19e46ed5dfb5 100644 --- a/tools/testing/selftests/timers/leap-a-day.c +++ b/tools/testing/selftests/timers/leap-a-day.c | |||
@@ -48,18 +48,7 @@ | |||
48 | #include <string.h> | 48 | #include <string.h> |
49 | #include <signal.h> | 49 | #include <signal.h> |
50 | #include <unistd.h> | 50 | #include <unistd.h> |
51 | #ifdef KTEST | ||
52 | #include "../kselftest.h" | 51 | #include "../kselftest.h" |
53 | #else | ||
54 | static inline int ksft_exit_pass(void) | ||
55 | { | ||
56 | exit(0); | ||
57 | } | ||
58 | static inline int ksft_exit_fail(void) | ||
59 | { | ||
60 | exit(1); | ||
61 | } | ||
62 | #endif | ||
63 | 52 | ||
64 | #define NSEC_PER_SEC 1000000000ULL | 53 | #define NSEC_PER_SEC 1000000000ULL |
65 | #define CLOCK_TAI 11 | 54 | #define CLOCK_TAI 11 |
@@ -190,18 +179,18 @@ int main(int argc, char **argv) | |||
190 | struct sigevent se; | 179 | struct sigevent se; |
191 | struct sigaction act; | 180 | struct sigaction act; |
192 | int signum = SIGRTMAX; | 181 | int signum = SIGRTMAX; |
193 | int settime = 0; | 182 | int settime = 1; |
194 | int tai_time = 0; | 183 | int tai_time = 0; |
195 | int insert = 1; | 184 | int insert = 1; |
196 | int iterations = -1; | 185 | int iterations = 10; |
197 | int opt; | 186 | int opt; |
198 | 187 | ||
199 | /* Process arguments */ | 188 | /* Process arguments */ |
200 | while ((opt = getopt(argc, argv, "sti:")) != -1) { | 189 | while ((opt = getopt(argc, argv, "sti:")) != -1) { |
201 | switch (opt) { | 190 | switch (opt) { |
202 | case 's': | 191 | case 'w': |
203 | printf("Setting time to speed up testing\n"); | 192 | printf("Only setting leap-flag, not changing time. It could take up to a day for leap to trigger.\n"); |
204 | settime = 1; | 193 | settime = 0; |
205 | break; | 194 | break; |
206 | case 'i': | 195 | case 'i': |
207 | iterations = atoi(optarg); | 196 | iterations = atoi(optarg); |
@@ -210,9 +199,10 @@ int main(int argc, char **argv) | |||
210 | tai_time = 1; | 199 | tai_time = 1; |
211 | break; | 200 | break; |
212 | default: | 201 | default: |
213 | printf("Usage: %s [-s] [-i <iterations>]\n", argv[0]); | 202 | printf("Usage: %s [-w] [-i <iterations>]\n", argv[0]); |
214 | printf(" -s: Set time to right before leap second each iteration\n"); | 203 | printf(" -w: Set flag and wait for leap second each iteration"); |
215 | printf(" -i: Number of iterations\n"); | 204 | printf(" (default sets time to right before leapsecond)\n"); |
205 | printf(" -i: Number of iterations (-1 = infinite, default is 10)\n"); | ||
216 | printf(" -t: Print TAI time\n"); | 206 | printf(" -t: Print TAI time\n"); |
217 | exit(-1); | 207 | exit(-1); |
218 | } | 208 | } |
diff --git a/tools/testing/selftests/timers/leapcrash.c b/tools/testing/selftests/timers/leapcrash.c index a1071bdbdeb7..830c462f605d 100644 --- a/tools/testing/selftests/timers/leapcrash.c +++ b/tools/testing/selftests/timers/leapcrash.c | |||
@@ -22,20 +22,7 @@ | |||
22 | #include <sys/timex.h> | 22 | #include <sys/timex.h> |
23 | #include <string.h> | 23 | #include <string.h> |
24 | #include <signal.h> | 24 | #include <signal.h> |
25 | #ifdef KTEST | ||
26 | #include "../kselftest.h" | 25 | #include "../kselftest.h" |
27 | #else | ||
28 | static inline int ksft_exit_pass(void) | ||
29 | { | ||
30 | exit(0); | ||
31 | } | ||
32 | static inline int ksft_exit_fail(void) | ||
33 | { | ||
34 | exit(1); | ||
35 | } | ||
36 | #endif | ||
37 | |||
38 | |||
39 | 26 | ||
40 | /* clear NTP time_status & time_state */ | 27 | /* clear NTP time_status & time_state */ |
41 | int clear_time_state(void) | 28 | int clear_time_state(void) |
diff --git a/tools/testing/selftests/timers/mqueue-lat.c b/tools/testing/selftests/timers/mqueue-lat.c index a2a3924d0b41..1867db5d6f5e 100644 --- a/tools/testing/selftests/timers/mqueue-lat.c +++ b/tools/testing/selftests/timers/mqueue-lat.c | |||
@@ -29,18 +29,7 @@ | |||
29 | #include <signal.h> | 29 | #include <signal.h> |
30 | #include <errno.h> | 30 | #include <errno.h> |
31 | #include <mqueue.h> | 31 | #include <mqueue.h> |
32 | #ifdef KTEST | ||
33 | #include "../kselftest.h" | 32 | #include "../kselftest.h" |
34 | #else | ||
35 | static inline int ksft_exit_pass(void) | ||
36 | { | ||
37 | exit(0); | ||
38 | } | ||
39 | static inline int ksft_exit_fail(void) | ||
40 | { | ||
41 | exit(1); | ||
42 | } | ||
43 | #endif | ||
44 | 33 | ||
45 | #define NSEC_PER_SEC 1000000000ULL | 34 | #define NSEC_PER_SEC 1000000000ULL |
46 | 35 | ||
diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c index ff942ff7c9b3..8adb0bb51d4d 100644 --- a/tools/testing/selftests/timers/nanosleep.c +++ b/tools/testing/selftests/timers/nanosleep.c | |||
@@ -27,18 +27,7 @@ | |||
27 | #include <sys/timex.h> | 27 | #include <sys/timex.h> |
28 | #include <string.h> | 28 | #include <string.h> |
29 | #include <signal.h> | 29 | #include <signal.h> |
30 | #ifdef KTEST | ||
31 | #include "../kselftest.h" | 30 | #include "../kselftest.h" |
32 | #else | ||
33 | static inline int ksft_exit_pass(void) | ||
34 | { | ||
35 | exit(0); | ||
36 | } | ||
37 | static inline int ksft_exit_fail(void) | ||
38 | { | ||
39 | exit(1); | ||
40 | } | ||
41 | #endif | ||
42 | 31 | ||
43 | #define NSEC_PER_SEC 1000000000ULL | 32 | #define NSEC_PER_SEC 1000000000ULL |
44 | 33 | ||
diff --git a/tools/testing/selftests/timers/nsleep-lat.c b/tools/testing/selftests/timers/nsleep-lat.c index 2d7898fda0f1..c3c3dc10db17 100644 --- a/tools/testing/selftests/timers/nsleep-lat.c +++ b/tools/testing/selftests/timers/nsleep-lat.c | |||
@@ -24,18 +24,7 @@ | |||
24 | #include <sys/timex.h> | 24 | #include <sys/timex.h> |
25 | #include <string.h> | 25 | #include <string.h> |
26 | #include <signal.h> | 26 | #include <signal.h> |
27 | #ifdef KTEST | ||
28 | #include "../kselftest.h" | 27 | #include "../kselftest.h" |
29 | #else | ||
30 | static inline int ksft_exit_pass(void) | ||
31 | { | ||
32 | exit(0); | ||
33 | } | ||
34 | static inline int ksft_exit_fail(void) | ||
35 | { | ||
36 | exit(1); | ||
37 | } | ||
38 | #endif | ||
39 | 28 | ||
40 | #define NSEC_PER_SEC 1000000000ULL | 29 | #define NSEC_PER_SEC 1000000000ULL |
41 | 30 | ||
diff --git a/tools/testing/selftests/timers/raw_skew.c b/tools/testing/selftests/timers/raw_skew.c index 30906bfd9c1b..ca6cd146aafe 100644 --- a/tools/testing/selftests/timers/raw_skew.c +++ b/tools/testing/selftests/timers/raw_skew.c | |||
@@ -25,19 +25,7 @@ | |||
25 | #include <sys/time.h> | 25 | #include <sys/time.h> |
26 | #include <sys/timex.h> | 26 | #include <sys/timex.h> |
27 | #include <time.h> | 27 | #include <time.h> |
28 | #ifdef KTEST | ||
29 | #include "../kselftest.h" | 28 | #include "../kselftest.h" |
30 | #else | ||
31 | static inline int ksft_exit_pass(void) | ||
32 | { | ||
33 | exit(0); | ||
34 | } | ||
35 | static inline int ksft_exit_fail(void) | ||
36 | { | ||
37 | exit(1); | ||
38 | } | ||
39 | #endif | ||
40 | |||
41 | 29 | ||
42 | #define CLOCK_MONOTONIC_RAW 4 | 30 | #define CLOCK_MONOTONIC_RAW 4 |
43 | #define NSEC_PER_SEC 1000000000LL | 31 | #define NSEC_PER_SEC 1000000000LL |
diff --git a/tools/testing/selftests/timers/rtctest.c b/tools/testing/selftests/timers/rtctest.c index f61170f7b024..411eff625e66 100644 --- a/tools/testing/selftests/timers/rtctest.c +++ b/tools/testing/selftests/timers/rtctest.c | |||
@@ -221,6 +221,11 @@ test_READ: | |||
221 | /* Read the current alarm settings */ | 221 | /* Read the current alarm settings */ |
222 | retval = ioctl(fd, RTC_ALM_READ, &rtc_tm); | 222 | retval = ioctl(fd, RTC_ALM_READ, &rtc_tm); |
223 | if (retval == -1) { | 223 | if (retval == -1) { |
224 | if (errno == EINVAL) { | ||
225 | fprintf(stderr, | ||
226 | "\n...EINVAL reading current alarm setting.\n"); | ||
227 | goto test_PIE; | ||
228 | } | ||
224 | perror("RTC_ALM_READ ioctl"); | 229 | perror("RTC_ALM_READ ioctl"); |
225 | exit(errno); | 230 | exit(errno); |
226 | } | 231 | } |
@@ -231,7 +236,7 @@ test_READ: | |||
231 | /* Enable alarm interrupts */ | 236 | /* Enable alarm interrupts */ |
232 | retval = ioctl(fd, RTC_AIE_ON, 0); | 237 | retval = ioctl(fd, RTC_AIE_ON, 0); |
233 | if (retval == -1) { | 238 | if (retval == -1) { |
234 | if (errno == EINVAL) { | 239 | if (errno == EINVAL || errno == EIO) { |
235 | fprintf(stderr, | 240 | fprintf(stderr, |
236 | "\n...Alarm IRQs not supported.\n"); | 241 | "\n...Alarm IRQs not supported.\n"); |
237 | goto test_PIE; | 242 | goto test_PIE; |
diff --git a/tools/testing/selftests/timers/set-2038.c b/tools/testing/selftests/timers/set-2038.c index c8a7e14446b1..688cfd81b531 100644 --- a/tools/testing/selftests/timers/set-2038.c +++ b/tools/testing/selftests/timers/set-2038.c | |||
@@ -27,18 +27,7 @@ | |||
27 | #include <unistd.h> | 27 | #include <unistd.h> |
28 | #include <time.h> | 28 | #include <time.h> |
29 | #include <sys/time.h> | 29 | #include <sys/time.h> |
30 | #ifdef KTEST | ||
31 | #include "../kselftest.h" | 30 | #include "../kselftest.h" |
32 | #else | ||
33 | static inline int ksft_exit_pass(void) | ||
34 | { | ||
35 | exit(0); | ||
36 | } | ||
37 | static inline int ksft_exit_fail(void) | ||
38 | { | ||
39 | exit(1); | ||
40 | } | ||
41 | #endif | ||
42 | 31 | ||
43 | #define NSEC_PER_SEC 1000000000LL | 32 | #define NSEC_PER_SEC 1000000000LL |
44 | 33 | ||
diff --git a/tools/testing/selftests/timers/set-tai.c b/tools/testing/selftests/timers/set-tai.c index dc88dbc8831f..70fed27d8fd3 100644 --- a/tools/testing/selftests/timers/set-tai.c +++ b/tools/testing/selftests/timers/set-tai.c | |||
@@ -23,18 +23,7 @@ | |||
23 | #include <string.h> | 23 | #include <string.h> |
24 | #include <signal.h> | 24 | #include <signal.h> |
25 | #include <unistd.h> | 25 | #include <unistd.h> |
26 | #ifdef KTEST | ||
27 | #include "../kselftest.h" | 26 | #include "../kselftest.h" |
28 | #else | ||
29 | static inline int ksft_exit_pass(void) | ||
30 | { | ||
31 | exit(0); | ||
32 | } | ||
33 | static inline int ksft_exit_fail(void) | ||
34 | { | ||
35 | exit(1); | ||
36 | } | ||
37 | #endif | ||
38 | 27 | ||
39 | int set_tai(int offset) | 28 | int set_tai(int offset) |
40 | { | 29 | { |
diff --git a/tools/testing/selftests/timers/set-timer-lat.c b/tools/testing/selftests/timers/set-timer-lat.c index 15434da23b04..9c92b7bd5641 100644 --- a/tools/testing/selftests/timers/set-timer-lat.c +++ b/tools/testing/selftests/timers/set-timer-lat.c | |||
@@ -28,18 +28,7 @@ | |||
28 | #include <signal.h> | 28 | #include <signal.h> |
29 | #include <stdlib.h> | 29 | #include <stdlib.h> |
30 | #include <pthread.h> | 30 | #include <pthread.h> |
31 | #ifdef KTEST | ||
32 | #include "../kselftest.h" | 31 | #include "../kselftest.h" |
33 | #else | ||
34 | static inline int ksft_exit_pass(void) | ||
35 | { | ||
36 | exit(0); | ||
37 | } | ||
38 | static inline int ksft_exit_fail(void) | ||
39 | { | ||
40 | exit(1); | ||
41 | } | ||
42 | #endif | ||
43 | 32 | ||
44 | #define CLOCK_REALTIME 0 | 33 | #define CLOCK_REALTIME 0 |
45 | #define CLOCK_MONOTONIC 1 | 34 | #define CLOCK_MONOTONIC 1 |
diff --git a/tools/testing/selftests/timers/set-tz.c b/tools/testing/selftests/timers/set-tz.c index f4184928b16b..877fd5532fee 100644 --- a/tools/testing/selftests/timers/set-tz.c +++ b/tools/testing/selftests/timers/set-tz.c | |||
@@ -23,18 +23,7 @@ | |||
23 | #include <string.h> | 23 | #include <string.h> |
24 | #include <signal.h> | 24 | #include <signal.h> |
25 | #include <unistd.h> | 25 | #include <unistd.h> |
26 | #ifdef KTEST | ||
27 | #include "../kselftest.h" | 26 | #include "../kselftest.h" |
28 | #else | ||
29 | static inline int ksft_exit_pass(void) | ||
30 | { | ||
31 | exit(0); | ||
32 | } | ||
33 | static inline int ksft_exit_fail(void) | ||
34 | { | ||
35 | exit(1); | ||
36 | } | ||
37 | #endif | ||
38 | 27 | ||
39 | int set_tz(int min, int dst) | 28 | int set_tz(int min, int dst) |
40 | { | 29 | { |
diff --git a/tools/testing/selftests/timers/skew_consistency.c b/tools/testing/selftests/timers/skew_consistency.c index 2a996e072259..022b711c78ee 100644 --- a/tools/testing/selftests/timers/skew_consistency.c +++ b/tools/testing/selftests/timers/skew_consistency.c | |||
@@ -35,18 +35,7 @@ | |||
35 | #include <stdlib.h> | 35 | #include <stdlib.h> |
36 | #include <string.h> | 36 | #include <string.h> |
37 | #include <sys/wait.h> | 37 | #include <sys/wait.h> |
38 | #ifdef KTEST | ||
39 | #include "../kselftest.h" | 38 | #include "../kselftest.h" |
40 | #else | ||
41 | static inline int ksft_exit_pass(void) | ||
42 | { | ||
43 | exit(0); | ||
44 | } | ||
45 | static inline int ksft_exit_fail(void) | ||
46 | { | ||
47 | exit(1); | ||
48 | } | ||
49 | #endif | ||
50 | 39 | ||
51 | #define NSEC_PER_SEC 1000000000LL | 40 | #define NSEC_PER_SEC 1000000000LL |
52 | 41 | ||
diff --git a/tools/testing/selftests/timers/threadtest.c b/tools/testing/selftests/timers/threadtest.c index e632e116f05e..759c9c06f1a0 100644 --- a/tools/testing/selftests/timers/threadtest.c +++ b/tools/testing/selftests/timers/threadtest.c | |||
@@ -21,19 +21,7 @@ | |||
21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | #include <sys/time.h> | 22 | #include <sys/time.h> |
23 | #include <pthread.h> | 23 | #include <pthread.h> |
24 | #ifdef KTEST | ||
25 | #include "../kselftest.h" | 24 | #include "../kselftest.h" |
26 | #else | ||
27 | static inline int ksft_exit_pass(void) | ||
28 | { | ||
29 | exit(0); | ||
30 | } | ||
31 | static inline int ksft_exit_fail(void) | ||
32 | { | ||
33 | exit(1); | ||
34 | } | ||
35 | #endif | ||
36 | |||
37 | 25 | ||
38 | /* serializes shared list access */ | 26 | /* serializes shared list access */ |
39 | pthread_mutex_t list_lock = PTHREAD_MUTEX_INITIALIZER; | 27 | pthread_mutex_t list_lock = PTHREAD_MUTEX_INITIALIZER; |
diff --git a/tools/testing/selftests/timers/valid-adjtimex.c b/tools/testing/selftests/timers/valid-adjtimex.c index 60fe3c569bd9..d9d3ab93b31a 100644 --- a/tools/testing/selftests/timers/valid-adjtimex.c +++ b/tools/testing/selftests/timers/valid-adjtimex.c | |||
@@ -32,18 +32,7 @@ | |||
32 | #include <string.h> | 32 | #include <string.h> |
33 | #include <signal.h> | 33 | #include <signal.h> |
34 | #include <unistd.h> | 34 | #include <unistd.h> |
35 | #ifdef KTEST | ||
36 | #include "../kselftest.h" | 35 | #include "../kselftest.h" |
37 | #else | ||
38 | static inline int ksft_exit_pass(void) | ||
39 | { | ||
40 | exit(0); | ||
41 | } | ||
42 | static inline int ksft_exit_fail(void) | ||
43 | { | ||
44 | exit(1); | ||
45 | } | ||
46 | #endif | ||
47 | 36 | ||
48 | #define NSEC_PER_SEC 1000000000LL | 37 | #define NSEC_PER_SEC 1000000000LL |
49 | #define USEC_PER_SEC 1000000LL | 38 | #define USEC_PER_SEC 1000000LL |
diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c index a74c9d739d07..a1391be2dc1e 100644 --- a/tools/testing/selftests/watchdog/watchdog-test.c +++ b/tools/testing/selftests/watchdog/watchdog-test.c | |||
@@ -9,12 +9,25 @@ | |||
9 | #include <unistd.h> | 9 | #include <unistd.h> |
10 | #include <fcntl.h> | 10 | #include <fcntl.h> |
11 | #include <signal.h> | 11 | #include <signal.h> |
12 | #include <getopt.h> | ||
12 | #include <sys/ioctl.h> | 13 | #include <sys/ioctl.h> |
13 | #include <linux/types.h> | 14 | #include <linux/types.h> |
14 | #include <linux/watchdog.h> | 15 | #include <linux/watchdog.h> |
15 | 16 | ||
17 | #define DEFAULT_PING_RATE 1 | ||
18 | |||
16 | int fd; | 19 | int fd; |
17 | const char v = 'V'; | 20 | const char v = 'V'; |
21 | static const char sopts[] = "bdehp:t:"; | ||
22 | static const struct option lopts[] = { | ||
23 | {"bootstatus", no_argument, NULL, 'b'}, | ||
24 | {"disable", no_argument, NULL, 'd'}, | ||
25 | {"enable", no_argument, NULL, 'e'}, | ||
26 | {"help", no_argument, NULL, 'h'}, | ||
27 | {"pingrate", required_argument, NULL, 'p'}, | ||
28 | {"timeout", required_argument, NULL, 't'}, | ||
29 | {NULL, no_argument, NULL, 0x0} | ||
30 | }; | ||
18 | 31 | ||
19 | /* | 32 | /* |
20 | * This function simply sends an IOCTL to the driver, which in turn ticks | 33 | * This function simply sends an IOCTL to the driver, which in turn ticks |
@@ -23,12 +36,12 @@ const char v = 'V'; | |||
23 | */ | 36 | */ |
24 | static void keep_alive(void) | 37 | static void keep_alive(void) |
25 | { | 38 | { |
26 | int dummy; | 39 | int dummy; |
27 | int ret; | 40 | int ret; |
28 | 41 | ||
29 | ret = ioctl(fd, WDIOC_KEEPALIVE, &dummy); | 42 | ret = ioctl(fd, WDIOC_KEEPALIVE, &dummy); |
30 | if (!ret) | 43 | if (!ret) |
31 | printf("."); | 44 | printf("."); |
32 | } | 45 | } |
33 | 46 | ||
34 | /* | 47 | /* |
@@ -38,75 +51,110 @@ static void keep_alive(void) | |||
38 | 51 | ||
39 | static void term(int sig) | 52 | static void term(int sig) |
40 | { | 53 | { |
41 | int ret = write(fd, &v, 1); | 54 | int ret = write(fd, &v, 1); |
42 | 55 | ||
43 | close(fd); | 56 | close(fd); |
44 | if (ret < 0) | 57 | if (ret < 0) |
45 | printf("\nStopping watchdog ticks failed (%d)...\n", errno); | 58 | printf("\nStopping watchdog ticks failed (%d)...\n", errno); |
46 | else | 59 | else |
47 | printf("\nStopping watchdog ticks...\n"); | 60 | printf("\nStopping watchdog ticks...\n"); |
48 | exit(0); | 61 | exit(0); |
62 | } | ||
63 | |||
64 | static void usage(char *progname) | ||
65 | { | ||
66 | printf("Usage: %s [options]\n", progname); | ||
67 | printf(" -b, --bootstatus Get last boot status (Watchdog/POR)\n"); | ||
68 | printf(" -d, --disable Turn off the watchdog timer\n"); | ||
69 | printf(" -e, --enable Turn on the watchdog timer\n"); | ||
70 | printf(" -h, --help Print the help message\n"); | ||
71 | printf(" -p, --pingrate=P Set ping rate to P seconds (default %d)\n", DEFAULT_PING_RATE); | ||
72 | printf(" -t, --timeout=T Set timeout to T seconds\n"); | ||
73 | printf("\n"); | ||
74 | printf("Parameters are parsed left-to-right in real-time.\n"); | ||
75 | printf("Example: %s -d -t 10 -p 5 -e\n", progname); | ||
49 | } | 76 | } |
50 | 77 | ||
51 | int main(int argc, char *argv[]) | 78 | int main(int argc, char *argv[]) |
52 | { | 79 | { |
53 | int flags; | 80 | int flags; |
54 | unsigned int ping_rate = 1; | 81 | unsigned int ping_rate = DEFAULT_PING_RATE; |
55 | int ret; | 82 | int ret; |
56 | int i; | 83 | int c; |
57 | 84 | int oneshot = 0; | |
58 | setbuf(stdout, NULL); | 85 | |
59 | 86 | setbuf(stdout, NULL); | |
60 | fd = open("/dev/watchdog", O_WRONLY); | 87 | |
61 | 88 | fd = open("/dev/watchdog", O_WRONLY); | |
62 | if (fd == -1) { | 89 | |
63 | printf("Watchdog device not enabled.\n"); | 90 | if (fd == -1) { |
64 | exit(-1); | 91 | printf("Watchdog device not enabled.\n"); |
65 | } | 92 | exit(-1); |
66 | 93 | } | |
67 | for (i = 1; i < argc; i++) { | 94 | |
68 | if (!strncasecmp(argv[i], "-d", 2)) { | 95 | while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) { |
69 | flags = WDIOS_DISABLECARD; | 96 | switch (c) { |
70 | ret = ioctl(fd, WDIOC_SETOPTIONS, &flags); | 97 | case 'b': |
71 | if (!ret) | 98 | flags = 0; |
72 | printf("Watchdog card disabled.\n"); | 99 | oneshot = 1; |
73 | } else if (!strncasecmp(argv[i], "-e", 2)) { | 100 | ret = ioctl(fd, WDIOC_GETBOOTSTATUS, &flags); |
74 | flags = WDIOS_ENABLECARD; | 101 | if (!ret) |
75 | ret = ioctl(fd, WDIOC_SETOPTIONS, &flags); | 102 | printf("Last boot is caused by: %s.\n", (flags != 0) ? |
76 | if (!ret) | 103 | "Watchdog" : "Power-On-Reset"); |
77 | printf("Watchdog card enabled.\n"); | 104 | else |
78 | } else if (!strncasecmp(argv[i], "-t", 2) && argv[2]) { | 105 | printf("WDIOC_GETBOOTSTATUS errno '%s'\n", strerror(errno)); |
79 | flags = atoi(argv[i + 1]); | 106 | break; |
80 | ret = ioctl(fd, WDIOC_SETTIMEOUT, &flags); | 107 | case 'd': |
81 | if (!ret) | 108 | flags = WDIOS_DISABLECARD; |
82 | printf("Watchdog timeout set to %u seconds.\n", flags); | 109 | ret = ioctl(fd, WDIOC_SETOPTIONS, &flags); |
83 | i++; | 110 | if (!ret) |
84 | } else if (!strncasecmp(argv[i], "-p", 2) && argv[2]) { | 111 | printf("Watchdog card disabled.\n"); |
85 | ping_rate = strtoul(argv[i + 1], NULL, 0); | 112 | else |
86 | printf("Watchdog ping rate set to %u seconds.\n", ping_rate); | 113 | printf("WDIOS_DISABLECARD errno '%s'\n", strerror(errno)); |
87 | i++; | 114 | break; |
88 | } else { | 115 | case 'e': |
89 | printf("-d to disable, -e to enable, -t <n> to set " | 116 | flags = WDIOS_ENABLECARD; |
90 | "the timeout,\n-p <n> to set the ping rate, and "); | 117 | ret = ioctl(fd, WDIOC_SETOPTIONS, &flags); |
91 | printf("run by itself to tick the card.\n"); | 118 | if (!ret) |
92 | printf("Parameters are parsed left-to-right in real-time.\n"); | 119 | printf("Watchdog card enabled.\n"); |
93 | printf("Example: %s -d -t 10 -p 5 -e\n", argv[0]); | 120 | else |
94 | goto end; | 121 | printf("WDIOS_ENABLECARD errno '%s'\n", strerror(errno)); |
95 | } | 122 | break; |
96 | } | 123 | case 'p': |
97 | 124 | ping_rate = strtoul(optarg, NULL, 0); | |
98 | printf("Watchdog Ticking Away!\n"); | 125 | if (!ping_rate) |
99 | 126 | ping_rate = DEFAULT_PING_RATE; | |
100 | signal(SIGINT, term); | 127 | printf("Watchdog ping rate set to %u seconds.\n", ping_rate); |
101 | 128 | break; | |
102 | while(1) { | 129 | case 't': |
103 | keep_alive(); | 130 | flags = strtoul(optarg, NULL, 0); |
104 | sleep(ping_rate); | 131 | ret = ioctl(fd, WDIOC_SETTIMEOUT, &flags); |
105 | } | 132 | if (!ret) |
133 | printf("Watchdog timeout set to %u seconds.\n", flags); | ||
134 | else | ||
135 | printf("WDIOC_SETTIMEOUT errno '%s'\n", strerror(errno)); | ||
136 | break; | ||
137 | default: | ||
138 | usage(argv[0]); | ||
139 | goto end; | ||
140 | } | ||
141 | } | ||
142 | |||
143 | if (oneshot) | ||
144 | goto end; | ||
145 | |||
146 | printf("Watchdog Ticking Away!\n"); | ||
147 | |||
148 | signal(SIGINT, term); | ||
149 | |||
150 | while (1) { | ||
151 | keep_alive(); | ||
152 | sleep(ping_rate); | ||
153 | } | ||
106 | end: | 154 | end: |
107 | ret = write(fd, &v, 1); | 155 | ret = write(fd, &v, 1); |
108 | if (ret < 0) | 156 | if (ret < 0) |
109 | printf("Stopping watchdog ticks failed (%d)...\n", errno); | 157 | printf("Stopping watchdog ticks failed (%d)...\n", errno); |
110 | close(fd); | 158 | close(fd); |
111 | return 0; | 159 | return 0; |
112 | } | 160 | } |