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

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
...

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