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

Merge tag 'linux-kselftest-5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull kselftest updates form Shuah Khan:

- TAP output reporting related fixes from Paolo Bonzini and Kees Cook.

These fixes make it skip reporting consistent with TAP format.

- Cleanup fixes to framework run_tests from Yauheni Kaliuta

* tag 'linux-kselftest-5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (23 commits)
selftests/harness: Limit step counter reporting
selftests/seccomp: Check ENOSYS under tracing
selftests/seccomp: Refactor to use fixture variants
selftests/harness: Clean up kern-doc for fixtures
selftests: kmod: Add module address visibility test
Replace HTTP links with HTTPS ones: KMOD KERNEL MODULE LOADER - USERMODE HELPER
selftests: fix condition in run_tests
selftests: do not use .ONESHELL
selftests: pidfd: skip test if unshare fails with EPERM
selftests: pidfd: do not use ksft_exit_skip after ksft_set_plan
selftests/harness: Report skip reason
selftests/harness: Display signed values correctly
selftests/harness: Refactor XFAIL into SKIP
selftests/harness: Switch to TAP output
selftests: Add header documentation and helpers
selftests/binderfs: Fix harness API usage
selftests: Remove unneeded selftest API headers
selftests/clone3: Reorder reporting output
selftests: sync_test: do not use ksft_exit_skip after ksft_set_plan
selftests: sigaltstack: do not use ksft_exit_skip after ksft_set_plan
...

+465 -254
+35 -28
tools/testing/selftests/breakpoints/step_after_suspend_test.c
··· 47 47 _exit(0); 48 48 } 49 49 50 - bool run_test(int cpu) 50 + int run_test(int cpu) 51 51 { 52 52 int status; 53 53 pid_t pid = fork(); ··· 55 55 56 56 if (pid < 0) { 57 57 ksft_print_msg("fork() failed: %s\n", strerror(errno)); 58 - return false; 58 + return KSFT_FAIL; 59 59 } 60 60 if (pid == 0) 61 61 child(cpu); ··· 63 63 wpid = waitpid(pid, &status, __WALL); 64 64 if (wpid != pid) { 65 65 ksft_print_msg("waitpid() failed: %s\n", strerror(errno)); 66 - return false; 66 + return KSFT_FAIL; 67 67 } 68 68 if (!WIFSTOPPED(status)) { 69 69 ksft_print_msg("child did not stop: %s\n", strerror(errno)); 70 - return false; 70 + return KSFT_FAIL; 71 71 } 72 72 if (WSTOPSIG(status) != SIGSTOP) { 73 73 ksft_print_msg("child did not stop with SIGSTOP: %s\n", 74 74 strerror(errno)); 75 - return false; 75 + return KSFT_FAIL; 76 76 } 77 77 78 78 if (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) < 0) { 79 79 if (errno == EIO) { 80 - ksft_exit_skip( 80 + ksft_print_msg( 81 81 "ptrace(PTRACE_SINGLESTEP) not supported on this architecture: %s\n", 82 82 strerror(errno)); 83 + return KSFT_SKIP; 83 84 } 84 85 ksft_print_msg("ptrace(PTRACE_SINGLESTEP) failed: %s\n", 85 86 strerror(errno)); 86 - return false; 87 + return KSFT_FAIL; 87 88 } 88 89 89 90 wpid = waitpid(pid, &status, __WALL); 90 91 if (wpid != pid) { 91 92 ksft_print_msg("waitpid() failed: $s\n", strerror(errno)); 92 - return false; 93 + return KSFT_FAIL; 93 94 } 94 95 if (WIFEXITED(status)) { 95 96 ksft_print_msg("child did not single-step: %s\n", 96 97 strerror(errno)); 97 - return false; 98 + return KSFT_FAIL; 98 99 } 99 100 if (!WIFSTOPPED(status)) { 100 101 ksft_print_msg("child did not stop: %s\n", strerror(errno)); 101 - return false; 102 + return KSFT_FAIL; 102 103 } 103 104 if (WSTOPSIG(status) != SIGTRAP) { 104 105 ksft_print_msg("child did not stop with SIGTRAP: %s\n", 105 106 strerror(errno)); 106 - return false; 107 + return KSFT_FAIL; 107 108 } 108 109 109 110 if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) { 110 111 ksft_print_msg("ptrace(PTRACE_CONT) failed: %s\n", 111 112 strerror(errno)); 112 - return false; 113 + return KSFT_FAIL; 113 114 } 114 115 115 116 wpid = waitpid(pid, &status, __WALL); 116 117 if (wpid != pid) { 117 118 ksft_print_msg("waitpid() failed: %s\n", strerror(errno)); 118 - return false; 119 + return KSFT_FAIL; 119 120 } 120 121 if (!WIFEXITED(status)) { 121 122 ksft_print_msg("child did not exit after PTRACE_CONT: %s\n", 122 123 strerror(errno)); 123 - return false; 124 + return KSFT_FAIL; 124 125 } 125 126 126 - return true; 127 + return KSFT_PASS; 127 128 } 128 129 129 130 void suspend(void) ··· 184 183 } 185 184 } 186 185 187 - for (cpu = 0; cpu < CPU_SETSIZE; cpu++) { 188 - if (!CPU_ISSET(cpu, &available_cpus)) 189 - continue; 190 - tests++; 191 - } 192 - ksft_set_plan(tests); 193 - 194 - if (do_suspend) 195 - suspend(); 196 - 197 186 err = sched_getaffinity(0, sizeof(available_cpus), &available_cpus); 198 187 if (err < 0) 199 188 ksft_exit_fail_msg("sched_getaffinity() failed\n"); 200 189 201 190 for (cpu = 0; cpu < CPU_SETSIZE; cpu++) { 202 - bool test_success; 191 + if (!CPU_ISSET(cpu, &available_cpus)) 192 + continue; 193 + tests++; 194 + } 195 + 196 + if (do_suspend) 197 + suspend(); 198 + 199 + ksft_set_plan(tests); 200 + for (cpu = 0; cpu < CPU_SETSIZE; cpu++) { 201 + int test_success; 203 202 204 203 if (!CPU_ISSET(cpu, &available_cpus)) 205 204 continue; 206 205 207 206 test_success = run_test(cpu); 208 - if (test_success) { 207 + switch (test_success) { 208 + case KSFT_PASS: 209 209 ksft_test_result_pass("CPU %d\n", cpu); 210 - } else { 210 + break; 211 + case KSFT_SKIP: 212 + ksft_test_result_skip("CPU %d\n", cpu); 213 + break; 214 + case KSFT_FAIL: 211 215 ksft_test_result_fail("CPU %d\n", cpu); 212 216 succeeded = false; 217 + break; 213 218 } 214 219 } 215 220
+1 -1
tools/testing/selftests/clone3/clone3.c
··· 131 131 132 132 uid_t uid = getuid(); 133 133 134 - test_clone3_supported(); 135 134 ksft_print_header(); 136 135 ksft_set_plan(17); 136 + test_clone3_supported(); 137 137 138 138 /* Just a simple clone3() should return 0.*/ 139 139 test_clone3(0, 0, 0, CLONE3_ARGS_NO_TEST);
+1 -2
tools/testing/selftests/clone3/clone3_clear_sighand.c
··· 119 119 int main(int argc, char **argv) 120 120 { 121 121 ksft_print_header(); 122 - test_clone3_supported(); 123 - 124 122 ksft_set_plan(1); 123 + test_clone3_supported(); 125 124 126 125 test_clone3_clear_sighand(); 127 126
+1 -1
tools/testing/selftests/clone3/clone3_set_tid.c
··· 157 157 pid_t set_tid[MAX_PID_NS_LEVEL * 2]; 158 158 159 159 ksft_print_header(); 160 - test_clone3_supported(); 161 160 ksft_set_plan(29); 161 + test_clone3_supported(); 162 162 163 163 if (pipe(pipe_1) < 0 || pipe(pipe_2) < 0) 164 164 ksft_exit_fail_msg("pipe() failed\n");
+148 -140
tools/testing/selftests/filesystems/binderfs/binderfs_test.c
··· 21 21 #include <linux/android/binder.h> 22 22 #include <linux/android/binderfs.h> 23 23 24 - #include "../../kselftest.h" 25 24 #include "../../kselftest_harness.h" 26 25 27 26 #define DEFAULT_THREADS 4 ··· 36 37 fd = -EBADF; \ 37 38 } 38 39 39 - #define log_exit(format, ...) \ 40 - ({ \ 41 - fprintf(stderr, format "\n", ##__VA_ARGS__); \ 42 - exit(EXIT_FAILURE); \ 43 - }) 44 - 45 - static void change_mountns(void) 40 + static void change_mountns(struct __test_metadata *_metadata) 46 41 { 47 42 int ret; 48 43 49 44 ret = unshare(CLONE_NEWNS); 50 - if (ret < 0) 51 - ksft_exit_fail_msg("%s - Failed to unshare mount namespace\n", 52 - strerror(errno)); 45 + ASSERT_EQ(ret, 0) { 46 + TH_LOG("%s - Failed to unshare mount namespace", 47 + strerror(errno)); 48 + } 53 49 54 50 ret = mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0); 55 - if (ret < 0) 56 - ksft_exit_fail_msg("%s - Failed to mount / as private\n", 57 - strerror(errno)); 51 + ASSERT_EQ(ret, 0) { 52 + TH_LOG("%s - Failed to mount / as private", 53 + strerror(errno)); 54 + } 58 55 } 59 56 60 - static void rmdir_protect_errno(const char *dir) 57 + static int __do_binderfs_test(struct __test_metadata *_metadata) 61 58 { 62 - int saved_errno = errno; 63 - (void)rmdir(dir); 64 - errno = saved_errno; 65 - } 66 - 67 - static int __do_binderfs_test(void) 68 - { 69 - int fd, ret, saved_errno; 59 + int fd, ret, saved_errno, result = 1; 70 60 size_t len; 71 61 ssize_t wret; 72 62 struct binderfs_device device = { 0 }; ··· 63 75 char binderfs_mntpt[] = P_tmpdir "/binderfs_XXXXXX", 64 76 device_path[sizeof(P_tmpdir "/binderfs_XXXXXX/") + BINDERFS_MAX_NAME]; 65 77 66 - change_mountns(); 78 + change_mountns(_metadata); 67 79 68 - if (!mkdtemp(binderfs_mntpt)) 69 - ksft_exit_fail_msg( 70 - "%s - Failed to create binderfs mountpoint\n", 80 + EXPECT_NE(mkdtemp(binderfs_mntpt), NULL) { 81 + TH_LOG("%s - Failed to create binderfs mountpoint", 71 82 strerror(errno)); 72 - 73 - ret = mount(NULL, binderfs_mntpt, "binder", 0, 0); 74 - if (ret < 0) { 75 - if (errno != ENODEV) 76 - ksft_exit_fail_msg("%s - Failed to mount binderfs\n", 77 - strerror(errno)); 78 - 79 - rmdir_protect_errno(binderfs_mntpt); 80 - return 1; 83 + goto out; 81 84 } 82 85 83 - /* binderfs mount test passed */ 84 - ksft_inc_pass_cnt(); 86 + ret = mount(NULL, binderfs_mntpt, "binder", 0, 0); 87 + EXPECT_EQ(ret, 0) { 88 + if (errno == ENODEV) 89 + XFAIL(goto out, "binderfs missing"); 90 + TH_LOG("%s - Failed to mount binderfs", strerror(errno)); 91 + goto rmdir; 92 + } 93 + 94 + /* success: binderfs mounted */ 85 95 86 96 memcpy(device.name, "my-binder", strlen("my-binder")); 87 97 88 98 snprintf(device_path, sizeof(device_path), "%s/binder-control", binderfs_mntpt); 89 99 fd = open(device_path, O_RDONLY | O_CLOEXEC); 90 - if (fd < 0) 91 - ksft_exit_fail_msg( 92 - "%s - Failed to open binder-control device\n", 100 + EXPECT_GE(fd, 0) { 101 + TH_LOG("%s - Failed to open binder-control device", 93 102 strerror(errno)); 103 + goto umount; 104 + } 94 105 95 106 ret = ioctl(fd, BINDER_CTL_ADD, &device); 96 107 saved_errno = errno; 97 108 close(fd); 98 109 errno = saved_errno; 99 - if (ret < 0) { 100 - rmdir_protect_errno(binderfs_mntpt); 101 - ksft_exit_fail_msg( 102 - "%s - Failed to allocate new binder device\n", 110 + EXPECT_GE(ret, 0) { 111 + TH_LOG("%s - Failed to allocate new binder device", 103 112 strerror(errno)); 113 + goto umount; 104 114 } 105 115 106 - ksft_print_msg( 107 - "Allocated new binder device with major %d, minor %d, and name %s\n", 116 + TH_LOG("Allocated new binder device with major %d, minor %d, and name %s", 108 117 device.major, device.minor, device.name); 109 118 110 - /* binder device allocation test passed */ 111 - ksft_inc_pass_cnt(); 119 + /* success: binder device allocation */ 112 120 113 121 snprintf(device_path, sizeof(device_path), "%s/my-binder", binderfs_mntpt); 114 122 fd = open(device_path, O_CLOEXEC | O_RDONLY); 115 - if (fd < 0) { 116 - rmdir_protect_errno(binderfs_mntpt); 117 - ksft_exit_fail_msg("%s - Failed to open my-binder device\n", 118 - strerror(errno)); 123 + EXPECT_GE(fd, 0) { 124 + TH_LOG("%s - Failed to open my-binder device", 125 + strerror(errno)); 126 + goto umount; 119 127 } 120 128 121 129 ret = ioctl(fd, BINDER_VERSION, &version); 122 130 saved_errno = errno; 123 131 close(fd); 124 132 errno = saved_errno; 125 - if (ret < 0) { 126 - rmdir_protect_errno(binderfs_mntpt); 127 - ksft_exit_fail_msg( 128 - "%s - Failed to open perform BINDER_VERSION request\n", 133 + EXPECT_GE(ret, 0) { 134 + TH_LOG("%s - Failed to open perform BINDER_VERSION request", 129 135 strerror(errno)); 136 + goto umount; 130 137 } 131 138 132 - ksft_print_msg("Detected binder version: %d\n", 133 - version.protocol_version); 139 + TH_LOG("Detected binder version: %d", version.protocol_version); 134 140 135 - /* binder transaction with binderfs binder device passed */ 136 - ksft_inc_pass_cnt(); 141 + /* success: binder transaction with binderfs binder device */ 137 142 138 143 ret = unlink(device_path); 139 - if (ret < 0) { 140 - rmdir_protect_errno(binderfs_mntpt); 141 - ksft_exit_fail_msg("%s - Failed to delete binder device\n", 142 - strerror(errno)); 144 + EXPECT_EQ(ret, 0) { 145 + TH_LOG("%s - Failed to delete binder device", 146 + strerror(errno)); 147 + goto umount; 143 148 } 144 149 145 - /* binder device removal passed */ 146 - ksft_inc_pass_cnt(); 150 + /* success: binder device removal */ 147 151 148 152 snprintf(device_path, sizeof(device_path), "%s/binder-control", binderfs_mntpt); 149 153 ret = unlink(device_path); 150 - if (!ret) { 151 - rmdir_protect_errno(binderfs_mntpt); 152 - ksft_exit_fail_msg("Managed to delete binder-control device\n"); 153 - } else if (errno != EPERM) { 154 - rmdir_protect_errno(binderfs_mntpt); 155 - ksft_exit_fail_msg( 156 - "%s - Failed to delete binder-control device but exited with unexpected error code\n", 154 + EXPECT_NE(ret, 0) { 155 + TH_LOG("Managed to delete binder-control device"); 156 + goto umount; 157 + } 158 + EXPECT_EQ(errno, EPERM) { 159 + TH_LOG("%s - Failed to delete binder-control device but exited with unexpected error code", 157 160 strerror(errno)); 161 + goto umount; 158 162 } 159 163 160 - /* binder-control device removal failed as expected */ 161 - ksft_inc_xfail_cnt(); 164 + /* success: binder-control device removal failed as expected */ 165 + result = 0; 162 166 163 - on_error: 167 + umount: 164 168 ret = umount2(binderfs_mntpt, MNT_DETACH); 165 - rmdir_protect_errno(binderfs_mntpt); 166 - if (ret < 0) 167 - ksft_exit_fail_msg("%s - Failed to unmount binderfs\n", 168 - strerror(errno)); 169 - 170 - /* binderfs unmount test passed */ 171 - ksft_inc_pass_cnt(); 172 - return 0; 169 + EXPECT_EQ(ret, 0) { 170 + TH_LOG("%s - Failed to unmount binderfs", strerror(errno)); 171 + } 172 + rmdir: 173 + ret = rmdir(binderfs_mntpt); 174 + EXPECT_EQ(ret, 0) { 175 + TH_LOG("%s - Failed to rmdir binderfs mount", strerror(errno)); 176 + } 177 + out: 178 + return result; 173 179 } 174 180 175 181 static int wait_for_pid(pid_t pid) ··· 273 291 return 0; 274 292 } 275 293 276 - static void change_userns(int syncfds[2]) 294 + static void change_userns(struct __test_metadata *_metadata, int syncfds[2]) 277 295 { 278 296 int ret; 279 297 char buf; ··· 281 299 close_prot_errno_disarm(syncfds[1]); 282 300 283 301 ret = unshare(CLONE_NEWUSER); 284 - if (ret < 0) 285 - ksft_exit_fail_msg("%s - Failed to unshare user namespace\n", 286 - strerror(errno)); 302 + ASSERT_EQ(ret, 0) { 303 + TH_LOG("%s - Failed to unshare user namespace", 304 + strerror(errno)); 305 + } 287 306 288 307 ret = write_nointr(syncfds[0], "1", 1); 289 - if (ret != 1) 290 - ksft_exit_fail_msg("write_nointr() failed\n"); 308 + ASSERT_EQ(ret, 1) { 309 + TH_LOG("write_nointr() failed"); 310 + } 291 311 292 312 ret = read_nointr(syncfds[0], &buf, 1); 293 - if (ret != 1) 294 - ksft_exit_fail_msg("read_nointr() failed\n"); 313 + ASSERT_EQ(ret, 1) { 314 + TH_LOG("read_nointr() failed"); 315 + } 295 316 296 317 close_prot_errno_disarm(syncfds[0]); 297 318 298 - if (setid_userns_root()) 299 - ksft_exit_fail_msg("setid_userns_root() failed"); 319 + ASSERT_EQ(setid_userns_root(), 0) { 320 + TH_LOG("setid_userns_root() failed"); 321 + } 300 322 } 301 323 302 - static void change_idmaps(int syncfds[2], pid_t pid) 324 + static void change_idmaps(struct __test_metadata *_metadata, int syncfds[2], pid_t pid) 303 325 { 304 326 int ret; 305 327 char buf; ··· 312 326 close_prot_errno_disarm(syncfds[0]); 313 327 314 328 ret = read_nointr(syncfds[1], &buf, 1); 315 - if (ret != 1) 316 - ksft_exit_fail_msg("read_nointr() failed\n"); 329 + ASSERT_EQ(ret, 1) { 330 + TH_LOG("read_nointr() failed"); 331 + } 317 332 318 333 snprintf(id_map, sizeof(id_map), "0 %d 1\n", getuid()); 319 334 ret = write_id_mapping(UID_MAP, pid, id_map, strlen(id_map)); 320 - if (ret) 321 - ksft_exit_fail_msg("write_id_mapping(UID_MAP) failed"); 335 + ASSERT_EQ(ret, 0) { 336 + TH_LOG("write_id_mapping(UID_MAP) failed"); 337 + } 322 338 323 339 snprintf(id_map, sizeof(id_map), "0 %d 1\n", getgid()); 324 340 ret = write_id_mapping(GID_MAP, pid, id_map, strlen(id_map)); 325 - if (ret) 326 - ksft_exit_fail_msg("write_id_mapping(GID_MAP) failed"); 341 + ASSERT_EQ(ret, 0) { 342 + TH_LOG("write_id_mapping(GID_MAP) failed"); 343 + } 327 344 328 345 ret = write_nointr(syncfds[1], "1", 1); 329 - if (ret != 1) 330 - ksft_exit_fail_msg("write_nointr() failed"); 346 + ASSERT_EQ(ret, 1) { 347 + TH_LOG("write_nointr() failed"); 348 + } 331 349 332 350 close_prot_errno_disarm(syncfds[1]); 333 351 } 334 352 353 + struct __test_metadata *_thread_metadata; 335 354 static void *binder_version_thread(void *data) 336 355 { 356 + struct __test_metadata *_metadata = _thread_metadata; 337 357 int fd = PTR_TO_INT(data); 338 358 struct binder_version version = { 0 }; 339 359 int ret; 340 360 341 361 ret = ioctl(fd, BINDER_VERSION, &version); 342 362 if (ret < 0) 343 - ksft_print_msg("%s - Failed to open perform BINDER_VERSION request\n", strerror(errno)); 363 + TH_LOG("%s - Failed to open perform BINDER_VERSION request\n", 364 + strerror(errno)); 344 365 345 366 pthread_exit(data); 346 367 } ··· 370 377 device_path[sizeof(P_tmpdir "/binderfs_XXXXXX/") + BINDERFS_MAX_NAME]; 371 378 372 379 ret = socketpair(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0, syncfds); 373 - if (ret < 0) 374 - ksft_exit_fail_msg("%s - Failed to create socket pair", strerror(errno)); 380 + ASSERT_EQ(ret, 0) { 381 + TH_LOG("%s - Failed to create socket pair", strerror(errno)); 382 + } 375 383 376 384 pid = fork(); 377 - if (pid < 0) { 385 + ASSERT_GE(pid, 0) { 386 + TH_LOG("%s - Failed to fork", strerror(errno)); 378 387 close_prot_errno_disarm(syncfds[0]); 379 388 close_prot_errno_disarm(syncfds[1]); 380 - ksft_exit_fail_msg("%s - Failed to fork", strerror(errno)); 381 389 } 382 390 383 391 if (pid == 0) { 384 392 int i, j, k, nthreads; 385 393 pthread_attr_t attr; 386 394 pthread_t threads[DEFAULT_THREADS]; 387 - change_userns(syncfds); 388 - change_mountns(); 395 + change_userns(_metadata, syncfds); 396 + change_mountns(_metadata); 389 397 390 - if (!mkdtemp(binderfs_mntpt)) 391 - log_exit("%s - Failed to create binderfs mountpoint\n", 392 - strerror(errno)); 398 + ASSERT_NE(mkdtemp(binderfs_mntpt), NULL) { 399 + TH_LOG("%s - Failed to create binderfs mountpoint", 400 + strerror(errno)); 401 + } 393 402 394 403 ret = mount(NULL, binderfs_mntpt, "binder", 0, 0); 395 - if (ret < 0) 396 - log_exit("%s - Failed to mount binderfs\n", strerror(errno)); 404 + ASSERT_EQ(ret, 0) { 405 + TH_LOG("%s - Failed to mount binderfs", strerror(errno)); 406 + } 397 407 398 408 for (int i = 0; i < ARRAY_SIZE(fds); i++) { 399 409 400 410 snprintf(device_path, sizeof(device_path), 401 411 "%s/binder-control", binderfs_mntpt); 402 412 fd = open(device_path, O_RDONLY | O_CLOEXEC); 403 - if (fd < 0) 404 - log_exit("%s - Failed to open binder-control device\n", strerror(errno)); 413 + ASSERT_GE(fd, 0) { 414 + TH_LOG("%s - Failed to open binder-control device", 415 + strerror(errno)); 416 + } 405 417 406 418 memset(&device, 0, sizeof(device)); 407 419 snprintf(device.name, sizeof(device.name), "%d", i); 408 420 ret = ioctl(fd, BINDER_CTL_ADD, &device); 409 421 close_prot_errno_disarm(fd); 410 - if (ret < 0) 411 - log_exit("%s - Failed to allocate new binder device\n", strerror(errno)); 422 + ASSERT_EQ(ret, 0) { 423 + TH_LOG("%s - Failed to allocate new binder device", 424 + strerror(errno)); 425 + } 412 426 413 427 snprintf(device_path, sizeof(device_path), "%s/%d", 414 428 binderfs_mntpt, i); 415 429 fds[i] = open(device_path, O_RDONLY | O_CLOEXEC); 416 - if (fds[i] < 0) 417 - log_exit("%s - Failed to open binder device\n", strerror(errno)); 430 + ASSERT_GE(fds[i], 0) { 431 + TH_LOG("%s - Failed to open binder device", strerror(errno)); 432 + } 418 433 } 419 434 420 435 ret = umount2(binderfs_mntpt, MNT_DETACH); 421 - rmdir_protect_errno(binderfs_mntpt); 422 - if (ret < 0) 423 - log_exit("%s - Failed to unmount binderfs\n", strerror(errno)); 436 + ASSERT_EQ(ret, 0) { 437 + TH_LOG("%s - Failed to unmount binderfs", strerror(errno)); 438 + rmdir(binderfs_mntpt); 439 + } 424 440 425 441 nthreads = get_nprocs_conf(); 426 442 if (nthreads > DEFAULT_THREADS) 427 443 nthreads = DEFAULT_THREADS; 428 444 445 + _thread_metadata = _metadata; 429 446 pthread_attr_init(&attr); 430 447 for (k = 0; k < ARRAY_SIZE(fds); k++) { 431 448 for (i = 0; i < nthreads; i++) { 432 449 ret = pthread_create(&threads[i], &attr, binder_version_thread, INT_TO_PTR(fds[k])); 433 450 if (ret) { 434 - ksft_print_msg("%s - Failed to create thread %d\n", strerror(errno), i); 451 + TH_LOG("%s - Failed to create thread %d", 452 + strerror(errno), i); 435 453 break; 436 454 } 437 455 } ··· 452 448 453 449 ret = pthread_join(threads[j], &fdptr); 454 450 if (ret) 455 - ksft_print_msg("%s - Failed to join thread %d for fd %d\n", strerror(errno), j, PTR_TO_INT(fdptr)); 451 + TH_LOG("%s - Failed to join thread %d for fd %d", 452 + strerror(errno), j, PTR_TO_INT(fdptr)); 456 453 } 457 454 } 458 455 pthread_attr_destroy(&attr); ··· 464 459 exit(EXIT_SUCCESS); 465 460 } 466 461 467 - change_idmaps(syncfds, pid); 462 + change_idmaps(_metadata, syncfds, pid); 468 463 469 464 ret = wait_for_pid(pid); 470 - if (ret) 471 - ksft_exit_fail_msg("wait_for_pid() failed"); 465 + ASSERT_EQ(ret, 0) { 466 + TH_LOG("wait_for_pid() failed"); 467 + } 472 468 } 473 469 474 470 TEST(binderfs_test_privileged) ··· 477 471 if (geteuid() != 0) 478 472 XFAIL(return, "Tests are not run as root. Skipping privileged tests"); 479 473 480 - if (__do_binderfs_test() == 1) 474 + if (__do_binderfs_test(_metadata)) 481 475 XFAIL(return, "The Android binderfs filesystem is not available"); 482 476 } 483 477 ··· 488 482 pid_t pid; 489 483 490 484 ret = socketpair(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0, syncfds); 491 - if (ret < 0) 492 - ksft_exit_fail_msg("%s - Failed to create socket pair", strerror(errno)); 485 + ASSERT_EQ(ret, 0) { 486 + TH_LOG("%s - Failed to create socket pair", strerror(errno)); 487 + } 493 488 494 489 pid = fork(); 495 - if (pid < 0) { 490 + ASSERT_GE(pid, 0) { 496 491 close_prot_errno_disarm(syncfds[0]); 497 492 close_prot_errno_disarm(syncfds[1]); 498 - ksft_exit_fail_msg("%s - Failed to fork", strerror(errno)); 493 + TH_LOG("%s - Failed to fork", strerror(errno)); 499 494 } 500 495 501 496 if (pid == 0) { 502 - change_userns(syncfds); 503 - if (__do_binderfs_test() == 1) 497 + change_userns(_metadata, syncfds); 498 + if (__do_binderfs_test(_metadata)) 504 499 exit(2); 505 500 exit(EXIT_SUCCESS); 506 501 } 507 502 508 - change_idmaps(syncfds, pid); 503 + change_idmaps(_metadata, syncfds, pid); 509 504 510 505 ret = wait_for_pid(pid); 511 506 if (ret) { 512 507 if (ret == 2) 513 508 XFAIL(return, "The Android binderfs filesystem is not available"); 514 - else 515 - ksft_exit_fail_msg("wait_for_pid() failed"); 509 + ASSERT_EQ(ret, 0) { 510 + TH_LOG("wait_for_pid() failed"); 511 + } 516 512 } 517 513 } 518 514
+1 -1
tools/testing/selftests/kmod/kmod.sh
··· 130 130 if [[ $KMOD_VERSION -le 19 ]]; then 131 131 echo "$0: You need at least kmod 20" >&2 132 132 echo "kmod <= 19 is buggy, for details see:" >&2 133 - echo "http://git.kernel.org/cgit/utils/kernel/kmod/kmod.git/commit/libkmod/libkmod-module.c?id=fd44a98ae2eb5eb32161088954ab21e58e19dfc4" >&2 133 + echo "https://git.kernel.org/cgit/utils/kernel/kmod/kmod.git/commit/libkmod/libkmod-module.c?id=fd44a98ae2eb5eb32161088954ab21e58e19dfc4" >&2 134 134 exit $ksft_skip 135 135 fi 136 136
+94 -12
tools/testing/selftests/kselftest.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 2 /* 3 - * kselftest.h: kselftest framework return codes to include from 4 - * selftests. 3 + * kselftest.h: low-level kselftest framework to include from 4 + * selftest programs. When possible, please use 5 + * kselftest_harness.h instead. 5 6 * 6 7 * Copyright (c) 2014 Shuah Khan <shuahkh@osg.samsung.com> 7 8 * Copyright (c) 2014 Samsung Electronics Co., Ltd. 9 + * 10 + * Using this API consists of first counting how many tests your code 11 + * has to run, and then starting up the reporting: 12 + * 13 + * ksft_print_header(); 14 + * ksft_set_plan(total_number_of_tests); 15 + * 16 + * For each test, report any progress, debugging, etc with: 17 + * 18 + * ksft_print_msg(fmt, ...); 19 + * 20 + * and finally report the pass/fail/skip/xfail state of the test with one of: 21 + * 22 + * ksft_test_result(condition, fmt, ...); 23 + * ksft_test_result_pass(fmt, ...); 24 + * ksft_test_result_fail(fmt, ...); 25 + * ksft_test_result_skip(fmt, ...); 26 + * ksft_test_result_xfail(fmt, ...); 27 + * ksft_test_result_error(fmt, ...); 28 + * 29 + * When all tests are finished, clean up and exit the program with one of: 30 + * 31 + * ksft_exit(condition); 32 + * ksft_exit_pass(); 33 + * ksft_exit_fail(); 34 + * 35 + * If the program wants to report details on why the entire program has 36 + * failed, it can instead exit with a message (this is usually done when 37 + * the program is aborting before finishing all tests): 38 + * 39 + * ksft_exit_fail_msg(fmt, ...); 8 40 * 9 41 */ 10 42 #ifndef __KSELFTEST_H ··· 106 74 if (ksft_plan != ksft_test_num()) 107 75 printf("# Planned tests != run tests (%u != %u)\n", 108 76 ksft_plan, ksft_test_num()); 109 - printf("# Pass %d Fail %d Xfail %d Xpass %d Skip %d Error %d\n", 77 + printf("# Totals: pass:%d fail:%d xfail:%d xpass:%d skip:%d error:%d\n", 110 78 ksft_cnt.ksft_pass, ksft_cnt.ksft_fail, 111 79 ksft_cnt.ksft_xfail, ksft_cnt.ksft_xpass, 112 80 ksft_cnt.ksft_xskip, ksft_cnt.ksft_error); ··· 152 120 va_end(args); 153 121 } 154 122 123 + /** 124 + * ksft_test_result() - Report test success based on truth of condition 125 + * 126 + * @condition: if true, report test success, otherwise failure. 127 + */ 128 + #define ksft_test_result(condition, fmt, ...) do { \ 129 + if (!!(condition)) \ 130 + ksft_test_result_pass(fmt, ##__VA_ARGS__);\ 131 + else \ 132 + ksft_test_result_fail(fmt, ##__VA_ARGS__);\ 133 + } while (0) 134 + 135 + static inline void ksft_test_result_xfail(const char *msg, ...) 136 + { 137 + int saved_errno = errno; 138 + va_list args; 139 + 140 + ksft_cnt.ksft_xfail++; 141 + 142 + va_start(args, msg); 143 + printf("ok %d # XFAIL ", ksft_test_num()); 144 + errno = saved_errno; 145 + vprintf(msg, args); 146 + va_end(args); 147 + } 148 + 155 149 static inline void ksft_test_result_skip(const char *msg, ...) 156 150 { 157 151 int saved_errno = errno; ··· 186 128 ksft_cnt.ksft_xskip++; 187 129 188 130 va_start(args, msg); 189 - printf("not ok %d # SKIP ", ksft_test_num()); 131 + printf("ok %d # SKIP ", ksft_test_num()); 190 132 errno = saved_errno; 191 133 vprintf(msg, args); 192 134 va_end(args); 193 135 } 194 136 137 + /* TODO: how does "error" differ from "fail" or "skip"? */ 195 138 static inline void ksft_test_result_error(const char *msg, ...) 196 139 { 197 140 int saved_errno = errno; ··· 215 156 216 157 static inline int ksft_exit_fail(void) 217 158 { 218 - printf("Bail out!\n"); 219 159 ksft_print_cnts(); 220 160 exit(KSFT_FAIL); 221 161 } 162 + 163 + /** 164 + * ksft_exit() - Exit selftest based on truth of condition 165 + * 166 + * @condition: if true, exit self test with success, otherwise fail. 167 + */ 168 + #define ksft_exit(condition) do { \ 169 + if (!!(condition)) \ 170 + ksft_exit_pass(); \ 171 + else \ 172 + ksft_exit_fail(); \ 173 + } while (0) 222 174 223 175 static inline int ksft_exit_fail_msg(const char *msg, ...) 224 176 { ··· 260 190 261 191 static inline int ksft_exit_skip(const char *msg, ...) 262 192 { 263 - if (msg) { 264 - int saved_errno = errno; 265 - va_list args; 193 + int saved_errno = errno; 194 + va_list args; 266 195 267 - va_start(args, msg); 268 - printf("not ok %d # SKIP ", 1 + ksft_test_num()); 196 + va_start(args, msg); 197 + 198 + /* 199 + * FIXME: several tests misuse ksft_exit_skip so produce 200 + * something sensible if some tests have already been run 201 + * or a plan has been printed. Those tests should use 202 + * ksft_test_result_skip or ksft_exit_fail_msg instead. 203 + */ 204 + if (ksft_plan || ksft_test_num()) { 205 + ksft_cnt.ksft_xskip++; 206 + printf("ok %d # SKIP ", 1 + ksft_test_num()); 207 + } else { 208 + printf("1..0 # SKIP "); 209 + } 210 + if (msg) { 269 211 errno = saved_errno; 270 212 vprintf(msg, args); 271 213 va_end(args); 272 - } else { 273 - ksft_print_cnts(); 274 214 } 215 + if (ksft_test_num()) 216 + ksft_print_cnts(); 275 217 exit(KSFT_SKIP); 276 218 } 277 219
+1 -1
tools/testing/selftests/kselftest/runner.sh
··· 77 77 echo "ok $test_num $TEST_HDR_MSG") || 78 78 (rc=$?; \ 79 79 if [ $rc -eq $skip_rc ]; then \ 80 - echo "not ok $test_num $TEST_HDR_MSG # SKIP" 80 + echo "ok $test_num $TEST_HDR_MSG # SKIP" 81 81 elif [ $rc -eq $timeout_rc ]; then \ 82 82 echo "#" 83 83 echo "not ok $test_num $TEST_HDR_MSG # TIMEOUT"
+125 -41
tools/testing/selftests/kselftest_harness.h
··· 50 50 #ifndef __KSELFTEST_HARNESS_H 51 51 #define __KSELFTEST_HARNESS_H 52 52 53 + #ifndef _GNU_SOURCE 53 54 #define _GNU_SOURCE 55 + #endif 54 56 #include <asm/types.h> 55 57 #include <errno.h> 56 58 #include <stdbool.h> ··· 60 58 #include <stdio.h> 61 59 #include <stdlib.h> 62 60 #include <string.h> 61 + #include <sys/mman.h> 63 62 #include <sys/types.h> 64 63 #include <sys/wait.h> 65 64 #include <unistd.h> 65 + 66 + #include "kselftest.h" 66 67 67 68 #define TEST_TIMEOUT_DEFAULT 30 68 69 ··· 109 104 110 105 /* Unconditional logger for internal use. */ 111 106 #define __TH_LOG(fmt, ...) \ 112 - fprintf(TH_LOG_STREAM, "%s:%d:%s:" fmt "\n", \ 107 + fprintf(TH_LOG_STREAM, "# %s:%d:%s:" fmt "\n", \ 113 108 __FILE__, __LINE__, _metadata->name, ##__VA_ARGS__) 114 109 115 110 /** 116 - * XFAIL(statement, fmt, ...) 111 + * SKIP(statement, fmt, ...) 117 112 * 118 - * @statement: statement to run after reporting XFAIL 113 + * @statement: statement to run after reporting SKIP 119 114 * @fmt: format string 120 115 * @...: optional arguments 121 116 * 122 - * This forces a "pass" after reporting a failure with an XFAIL prefix, 117 + * This forces a "pass" after reporting why something is being skipped 123 118 * and runs "statement", which is usually "return" or "goto skip". 124 119 */ 125 - #define XFAIL(statement, fmt, ...) do { \ 120 + #define SKIP(statement, fmt, ...) do { \ 121 + snprintf(_metadata->results->reason, \ 122 + sizeof(_metadata->results->reason), fmt, ##__VA_ARGS__); \ 126 123 if (TH_LOG_ENABLED) { \ 127 - fprintf(TH_LOG_STREAM, "[ XFAIL! ] " fmt "\n", \ 128 - ##__VA_ARGS__); \ 124 + fprintf(TH_LOG_STREAM, "# SKIP %s\n", \ 125 + _metadata->results->reason); \ 129 126 } \ 130 - /* TODO: find a way to pass xfail to test runner process. */ \ 131 127 _metadata->passed = 1; \ 128 + _metadata->skip = 1; \ 132 129 _metadata->trigger = 0; \ 133 130 statement; \ 134 131 } while (0) ··· 680 673 __bail(_assert, _metadata->no_print, _metadata->step)) 681 674 682 675 #define __INC_STEP(_metadata) \ 683 - if (_metadata->passed && _metadata->step < 255) \ 676 + /* Keep "step" below 255 (which is used for "SKIP" reporting). */ \ 677 + if (_metadata->passed && _metadata->step < 253) \ 684 678 _metadata->step++; 679 + 680 + #define is_signed_type(var) (!!(((__typeof__(var))(-1)) < (__typeof__(var))1)) 685 681 686 682 #define __EXPECT(_expected, _expected_str, _seen, _seen_str, _t, _assert) do { \ 687 683 /* Avoid multiple evaluation of the cases */ \ ··· 692 682 __typeof__(_seen) __seen = (_seen); \ 693 683 if (_assert) __INC_STEP(_metadata); \ 694 684 if (!(__exp _t __seen)) { \ 695 - unsigned long long __exp_print = (uintptr_t)__exp; \ 696 - unsigned long long __seen_print = (uintptr_t)__seen; \ 697 - __TH_LOG("Expected %s (%llu) %s %s (%llu)", \ 698 - _expected_str, __exp_print, #_t, \ 699 - _seen_str, __seen_print); \ 685 + /* Report with actual signedness to avoid weird output. */ \ 686 + switch (is_signed_type(__exp) * 2 + is_signed_type(__seen)) { \ 687 + case 0: { \ 688 + unsigned long long __exp_print = (uintptr_t)__exp; \ 689 + unsigned long long __seen_print = (uintptr_t)__seen; \ 690 + __TH_LOG("Expected %s (%llu) %s %s (%llu)", \ 691 + _expected_str, __exp_print, #_t, \ 692 + _seen_str, __seen_print); \ 693 + break; \ 694 + } \ 695 + case 1: { \ 696 + unsigned long long __exp_print = (uintptr_t)__exp; \ 697 + long long __seen_print = (intptr_t)__seen; \ 698 + __TH_LOG("Expected %s (%llu) %s %s (%lld)", \ 699 + _expected_str, __exp_print, #_t, \ 700 + _seen_str, __seen_print); \ 701 + break; \ 702 + } \ 703 + case 2: { \ 704 + long long __exp_print = (intptr_t)__exp; \ 705 + unsigned long long __seen_print = (uintptr_t)__seen; \ 706 + __TH_LOG("Expected %s (%lld) %s %s (%llu)", \ 707 + _expected_str, __exp_print, #_t, \ 708 + _seen_str, __seen_print); \ 709 + break; \ 710 + } \ 711 + case 3: { \ 712 + long long __exp_print = (intptr_t)__exp; \ 713 + long long __seen_print = (intptr_t)__seen; \ 714 + __TH_LOG("Expected %s (%lld) %s %s (%lld)", \ 715 + _expected_str, __exp_print, #_t, \ 716 + _seen_str, __seen_print); \ 717 + break; \ 718 + } \ 719 + } \ 700 720 _metadata->passed = 0; \ 701 721 /* Ensure the optional handler is triggered */ \ 702 722 _metadata->trigger = 1; \ ··· 766 726 head = item; \ 767 727 } \ 768 728 } 729 + 730 + struct __test_results { 731 + char reason[1024]; /* Reason for test result */ 732 + }; 769 733 770 734 struct __test_metadata; 771 735 struct __fixture_variant_metadata; ··· 818 774 struct __fixture_metadata *fixture; 819 775 int termsig; 820 776 int passed; 777 + int skip; /* did SKIP get used? */ 821 778 int trigger; /* extra handler after the evaluation */ 822 779 int timeout; /* seconds to wait for test timeout */ 823 780 bool timed_out; /* did this test timeout instead of exiting? */ 824 781 __u8 step; 825 782 bool no_print; /* manual trigger when TH_LOG_STREAM is not available */ 783 + struct __test_results *results; 826 784 struct __test_metadata *prev, *next; 827 785 }; 828 786 ··· 860 814 /* Sanity check handler execution environment. */ 861 815 if (!t) { 862 816 fprintf(TH_LOG_STREAM, 863 - "no active test in SIGALRM handler!?\n"); 817 + "# no active test in SIGALRM handler!?\n"); 864 818 abort(); 865 819 } 866 820 if (sig != SIGALRM || sig != info->si_signo) { 867 821 fprintf(TH_LOG_STREAM, 868 - "%s: SIGALRM handler caught signal %d!?\n", 822 + "# %s: SIGALRM handler caught signal %d!?\n", 869 823 t->name, sig != SIGALRM ? sig : info->si_signo); 870 824 abort(); 871 825 } ··· 886 840 if (sigaction(SIGALRM, &action, &saved_action)) { 887 841 t->passed = 0; 888 842 fprintf(TH_LOG_STREAM, 889 - "%s: unable to install SIGALRM handler\n", 843 + "# %s: unable to install SIGALRM handler\n", 890 844 t->name); 891 845 return; 892 846 } ··· 898 852 if (sigaction(SIGALRM, &saved_action, NULL)) { 899 853 t->passed = 0; 900 854 fprintf(TH_LOG_STREAM, 901 - "%s: unable to uninstall SIGALRM handler\n", 855 + "# %s: unable to uninstall SIGALRM handler\n", 902 856 t->name); 903 857 return; 904 858 } ··· 907 861 if (t->timed_out) { 908 862 t->passed = 0; 909 863 fprintf(TH_LOG_STREAM, 910 - "%s: Test terminated by timeout\n", t->name); 864 + "# %s: Test terminated by timeout\n", t->name); 911 865 } else if (WIFEXITED(status)) { 912 - t->passed = t->termsig == -1 ? !WEXITSTATUS(status) : 0; 913 866 if (t->termsig != -1) { 867 + t->passed = 0; 914 868 fprintf(TH_LOG_STREAM, 915 - "%s: Test exited normally " 916 - "instead of by signal (code: %d)\n", 869 + "# %s: Test exited normally instead of by signal (code: %d)\n", 917 870 t->name, 918 871 WEXITSTATUS(status)); 919 - } else if (!t->passed) { 920 - fprintf(TH_LOG_STREAM, 921 - "%s: Test failed at step #%d\n", 922 - t->name, 923 - WEXITSTATUS(status)); 872 + } else { 873 + switch (WEXITSTATUS(status)) { 874 + /* Success */ 875 + case 0: 876 + t->passed = 1; 877 + break; 878 + /* SKIP */ 879 + case 255: 880 + t->passed = 1; 881 + t->skip = 1; 882 + break; 883 + /* Other failure, assume step report. */ 884 + default: 885 + t->passed = 0; 886 + fprintf(TH_LOG_STREAM, 887 + "# %s: Test failed at step #%d\n", 888 + t->name, 889 + WEXITSTATUS(status)); 890 + } 924 891 } 925 892 } else if (WIFSIGNALED(status)) { 926 893 t->passed = 0; 927 894 if (WTERMSIG(status) == SIGABRT) { 928 895 fprintf(TH_LOG_STREAM, 929 - "%s: Test terminated by assertion\n", 896 + "# %s: Test terminated by assertion\n", 930 897 t->name); 931 898 } else if (WTERMSIG(status) == t->termsig) { 932 899 t->passed = 1; 933 900 } else { 934 901 fprintf(TH_LOG_STREAM, 935 - "%s: Test terminated unexpectedly " 936 - "by signal %d\n", 902 + "# %s: Test terminated unexpectedly by signal %d\n", 937 903 t->name, 938 904 WTERMSIG(status)); 939 905 } 940 906 } else { 941 907 fprintf(TH_LOG_STREAM, 942 - "%s: Test ended in some other way [%u]\n", 908 + "# %s: Test ended in some other way [%u]\n", 943 909 t->name, 944 910 status); 945 911 } ··· 963 905 { 964 906 /* reset test struct */ 965 907 t->passed = 1; 908 + t->skip = 0; 966 909 t->trigger = 0; 967 910 t->step = 0; 968 911 t->no_print = 0; 912 + memset(t->results->reason, 0, sizeof(t->results->reason)); 969 913 970 - printf("[ RUN ] %s%s%s.%s\n", 914 + ksft_print_msg(" RUN %s%s%s.%s ...\n", 971 915 f->name, variant->name[0] ? "." : "", variant->name, t->name); 972 916 t->pid = fork(); 973 917 if (t->pid < 0) { 974 - printf("ERROR SPAWNING TEST CHILD\n"); 918 + ksft_print_msg("ERROR SPAWNING TEST CHILD\n"); 975 919 t->passed = 0; 976 920 } else if (t->pid == 0) { 977 921 t->fn(t, variant); 978 - /* return the step that failed or 0 */ 979 - _exit(t->passed ? 0 : t->step); 922 + if (t->skip) 923 + _exit(255); 924 + /* Pass is exit 0 */ 925 + if (t->passed) 926 + _exit(0); 927 + /* Something else happened, report the step. */ 928 + _exit(t->step); 980 929 } else { 981 930 __wait_for_test(t); 982 931 } 983 - printf("[ %4s ] %s%s%s.%s\n", (t->passed ? "OK" : "FAIL"), 932 + ksft_print_msg(" %4s %s%s%s.%s\n", t->passed ? "OK" : "FAIL", 984 933 f->name, variant->name[0] ? "." : "", variant->name, t->name); 934 + 935 + if (t->skip) 936 + ksft_test_result_skip("%s\n", t->results->reason[0] ? 937 + t->results->reason : "unknown"); 938 + else 939 + ksft_test_result(t->passed, "%s%s%s.%s\n", 940 + f->name, variant->name[0] ? "." : "", variant->name, t->name); 985 941 } 986 942 987 943 static int test_harness_run(int __attribute__((unused)) argc, ··· 1004 932 struct __fixture_variant_metadata no_variant = { .name = "", }; 1005 933 struct __fixture_variant_metadata *v; 1006 934 struct __fixture_metadata *f; 935 + struct __test_results *results; 1007 936 struct __test_metadata *t; 1008 937 int ret = 0; 1009 938 unsigned int case_count = 0, test_count = 0; ··· 1019 946 } 1020 947 } 1021 948 1022 - /* TODO(wad) add optional arguments similar to gtest. */ 1023 - printf("[==========] Running %u tests from %u test cases.\n", 949 + results = mmap(NULL, sizeof(*results), PROT_READ | PROT_WRITE, 950 + MAP_SHARED | MAP_ANONYMOUS, -1, 0); 951 + 952 + ksft_print_header(); 953 + ksft_set_plan(test_count); 954 + ksft_print_msg("Starting %u tests from %u test cases.\n", 1024 955 test_count, case_count); 1025 956 for (f = __fixture_list; f; f = f->next) { 1026 957 for (v = f->variant ?: &no_variant; v; v = v->next) { 1027 958 for (t = f->tests; t; t = t->next) { 1028 959 count++; 960 + t->results = results; 1029 961 __run_test(f, v, t); 962 + t->results = NULL; 1030 963 if (t->passed) 1031 964 pass_count++; 1032 965 else ··· 1040 961 } 1041 962 } 1042 963 } 1043 - printf("[==========] %u / %u tests passed.\n", pass_count, count); 1044 - printf("[ %s ]\n", (ret ? "FAILED" : "PASSED")); 1045 - return ret; 964 + munmap(results, sizeof(*results)); 965 + 966 + ksft_print_msg("%s: %u / %u tests passed.\n", ret ? "FAILED" : "PASSED", 967 + pass_count, count); 968 + ksft_exit(ret == 0); 969 + 970 + /* unreachable */ 971 + return KSFT_FAIL; 1046 972 } 1047 973 1048 974 static void __attribute__((constructor)) __constructor_order_first(void)
+9 -11
tools/testing/selftests/lib.mk
··· 59 59 all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) 60 60 endif 61 61 62 - .ONESHELL: 63 62 define RUN_TESTS 64 - @BASE_DIR="$(selfdir)"; \ 63 + BASE_DIR="$(selfdir)"; \ 65 64 . $(selfdir)/kselftest/runner.sh; \ 66 65 if [ "X$(summary)" != "X" ]; then \ 67 66 per_test_logging=1; \ ··· 70 71 71 72 run_tests: all 72 73 ifdef building_out_of_srctree 73 - @if [ "X$(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)" != "X" ]; then 74 - @rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT) 74 + @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ 75 + rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \ 75 76 fi 76 - @if [ "X$(TEST_PROGS)" != "X" ]; then 77 - $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS)) 78 - else 79 - $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS)) 77 + @if [ "X$(TEST_PROGS)" != "X" ]; then \ 78 + $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS)) ; \ 79 + else \ 80 + $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS)); \ 80 81 fi 81 82 else 82 - $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS)) 83 + @$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS)) 83 84 endif 84 85 85 86 define INSTALL_SINGLE_RULE 86 87 $(if $(INSTALL_LIST),@mkdir -p $(INSTALL_PATH)) 87 - $(if $(INSTALL_LIST),@echo rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/) 88 - $(if $(INSTALL_LIST),@rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/) 88 + $(if $(INSTALL_LIST),rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/) 89 89 endef 90 90 91 91 define INSTALL_RULE
-1
tools/testing/selftests/pid_namespace/regression_enomem.c
··· 11 11 #include <syscall.h> 12 12 #include <sys/wait.h> 13 13 14 - #include "../kselftest.h" 15 14 #include "../kselftest_harness.h" 16 15 #include "../pidfd/pidfd.h" 17 16
-1
tools/testing/selftests/pidfd/pidfd_getfd_test.c
··· 18 18 #include <linux/kcmp.h> 19 19 20 20 #include "pidfd.h" 21 - #include "../kselftest.h" 22 21 #include "../kselftest_harness.h" 23 22 24 23 /*
-1
tools/testing/selftests/pidfd/pidfd_setns_test.c
··· 20 20 21 21 #include "pidfd.h" 22 22 #include "../clone3/clone3_selftests.h" 23 - #include "../kselftest.h" 24 23 #include "../kselftest_harness.h" 25 24 26 25 enum {
+46 -9
tools/testing/selftests/pidfd/pidfd_test.c
··· 8 8 #include <sched.h> 9 9 #include <signal.h> 10 10 #include <stdio.h> 11 + #include <stdbool.h> 11 12 #include <stdlib.h> 12 13 #include <string.h> 13 14 #include <syscall.h> ··· 27 26 #define CHILD_THREAD_MIN_WAIT 3 /* seconds */ 28 27 29 28 #define MAX_EVENTS 5 29 + 30 + static bool have_pidfd_send_signal; 30 31 31 32 static pid_t pidfd_clone(int flags, int *pidfd, int (*fn)(void *)) 32 33 { ··· 59 56 int pidfd, ret; 60 57 const char *test_name = "pidfd_send_signal send SIGUSR1"; 61 58 59 + if (!have_pidfd_send_signal) { 60 + ksft_test_result_skip( 61 + "%s test: pidfd_send_signal() syscall not supported\n", 62 + test_name); 63 + return 0; 64 + } 65 + 62 66 pidfd = open("/proc/self", O_DIRECTORY | O_CLOEXEC); 63 67 if (pidfd < 0) 64 68 ksft_exit_fail_msg( ··· 95 85 char buf[256]; 96 86 pid_t pid; 97 87 const char *test_name = "pidfd_send_signal signal exited process"; 88 + 89 + if (!have_pidfd_send_signal) { 90 + ksft_test_result_skip( 91 + "%s test: pidfd_send_signal() syscall not supported\n", 92 + test_name); 93 + return 0; 94 + } 98 95 99 96 pid = fork(); 100 97 if (pid < 0) ··· 154 137 pid_t pid1; 155 138 const char *test_name = "pidfd_send_signal signal recycled pid"; 156 139 140 + if (!have_pidfd_send_signal) { 141 + ksft_test_result_skip( 142 + "%s test: pidfd_send_signal() syscall not supported\n", 143 + test_name); 144 + return 0; 145 + } 146 + 157 147 ret = unshare(CLONE_NEWPID); 158 - if (ret < 0) 148 + if (ret < 0) { 149 + if (errno == EPERM) { 150 + ksft_test_result_skip("%s test: Unsharing pid namespace not permitted\n", 151 + test_name); 152 + return 0; 153 + } 159 154 ksft_exit_fail_msg("%s test: Failed to unshare pid namespace\n", 160 155 test_name); 156 + } 161 157 162 158 ret = unshare(CLONE_NEWNS); 163 - if (ret < 0) 164 - ksft_exit_fail_msg( 165 - "%s test: Failed to unshare mount namespace\n", 166 - test_name); 159 + if (ret < 0) { 160 + if (errno == EPERM) { 161 + ksft_test_result_skip("%s test: Unsharing mount namespace not permitted\n", 162 + test_name); 163 + return 0; 164 + } 165 + ksft_exit_fail_msg("%s test: Failed to unshare mount namespace\n", 166 + test_name); 167 + } 167 168 168 169 ret = mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0); 169 170 if (ret < 0) ··· 360 325 361 326 ret = sys_pidfd_send_signal(pidfd, 0, NULL, 0); 362 327 if (ret < 0) { 363 - if (errno == ENOSYS) 364 - ksft_exit_skip( 328 + if (errno == ENOSYS) { 329 + ksft_test_result_skip( 365 330 "%s test: pidfd_send_signal() syscall not supported\n", 366 331 test_name); 367 - 332 + return 0; 333 + } 368 334 ksft_exit_fail_msg("%s test: Failed to send signal\n", 369 335 test_name); 370 336 } 371 337 338 + have_pidfd_send_signal = true; 372 339 close(pidfd); 373 340 ksft_test_result_pass( 374 341 "%s test: pidfd_send_signal() syscall is supported. Tests can be executed\n", ··· 558 521 int main(int argc, char **argv) 559 522 { 560 523 ksft_print_header(); 561 - ksft_set_plan(4); 524 + ksft_set_plan(8); 562 525 563 526 test_pidfd_poll_exec(0); 564 527 test_pidfd_poll_exec(1);
+2 -2
tools/testing/selftests/sigaltstack/sas.c
··· 71 71 swapcontext(&sc, &uc); 72 72 ksft_print_msg("%s\n", p->msg); 73 73 if (!p->flag) { 74 - ksft_exit_skip("[RUN]\tAborting\n"); 74 + ksft_exit_fail_msg("[RUN]\tAborting\n"); 75 75 exit(EXIT_FAILURE); 76 76 } 77 77 } ··· 144 144 err = sigaltstack(&stk, NULL); 145 145 if (err) { 146 146 if (errno == EINVAL) { 147 - ksft_exit_skip( 147 + ksft_test_result_skip( 148 148 "[NOTE]\tThe running kernel doesn't support SS_AUTODISARM\n"); 149 149 /* 150 150 * If test cases for the !SS_AUTODISARM variant were
+1 -1
tools/testing/selftests/sync/sync_test.c
··· 86 86 int err; 87 87 88 88 ksft_print_header(); 89 - ksft_set_plan(3 + 7); 90 89 91 90 sync_api_supported(); 91 + ksft_set_plan(3 + 7); 92 92 93 93 ksft_print_msg("[RUN]\tTesting sync framework\n"); 94 94
-1
tools/testing/selftests/uevent/uevent_filtering.c
··· 19 19 #include <sys/wait.h> 20 20 #include <unistd.h> 21 21 22 - #include "../kselftest.h" 23 22 #include "../kselftest_harness.h" 24 23 25 24 #define __DEV_FULL "/sys/devices/virtual/mem/full/uevent"