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

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

Pull Kselftest updates from Shuah Khan:

- dmabuf-heaps test fixes and cleanups from John Stultz

- seccomp test fix to accept any valid fd in user_notification_addfd

- Minor fixes to breakpoints and vDSO tests

- Minor code cleanups to ipc and x86 tests

* tag 'linux-kselftest-next-5.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
selftests/seccomp: Accept any valid fd in user_notification_addfd
selftests/timens: add futex binary to .gitignore
selftests: breakpoints: Use correct error messages in breakpoint_test_arm64.c
selftests/vDSO: fix ABI selftest on riscv
selftests/x86/ldt_gdt: remove unneeded semicolon
selftests/ipc: remove unneeded semicolon
kselftests: dmabuf-heaps: Add extra checking that allocated buffers are zeroed
kselftests: dmabuf-heaps: Cleanup test output
kselftests: dmabuf-heaps: Softly fail if don't find a vgem device
kselftests: dmabuf-heaps: Add clearer checks on DMABUF_BEGIN/END_SYNC
kselftests: dmabuf-heaps: Fix Makefile's inclusion of the kernel's usr/include dir

+132 -44
+2 -2
tools/testing/selftests/breakpoints/breakpoint_test_arm64.c
··· 145 145 146 146 if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) { 147 147 ksft_print_msg( 148 - "ptrace(PTRACE_SINGLESTEP) failed: %s\n", 148 + "ptrace(PTRACE_CONT) failed: %s\n", 149 149 strerror(errno)); 150 150 return false; 151 151 } ··· 159 159 } 160 160 alarm(0); 161 161 if (WIFEXITED(status)) { 162 - ksft_print_msg("child did not single-step\n"); 162 + ksft_print_msg("child exited prematurely\n"); 163 163 return false; 164 164 } 165 165 if (!WIFSTOPPED(status)) {
+1 -1
tools/testing/selftests/dmabuf-heaps/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - CFLAGS += -static -O3 -Wl,-no-as-needed -Wall -I../../../../usr/include 2 + CFLAGS += -static -O3 -Wl,-no-as-needed -Wall 3 3 4 4 TEST_GEN_PROGS = dmabuf-heap 5 5
+119 -30
tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c
··· 130 130 dmabuf_fd); 131 131 } 132 132 133 - static void dmabuf_sync(int fd, int start_stop) 133 + static int dmabuf_sync(int fd, int start_stop) 134 134 { 135 135 struct dma_buf_sync sync = { 136 136 .flags = start_stop | DMA_BUF_SYNC_RW, 137 137 }; 138 - int ret; 139 138 140 - ret = ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync); 141 - if (ret) 142 - printf("sync failed %d\n", errno); 139 + return ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync); 143 140 } 144 141 145 142 #define ONE_MEG (1024 * 1024) ··· 148 151 void *p = NULL; 149 152 int ret; 150 153 151 - printf("Testing heap: %s\n", heap_name); 152 - 153 154 heap_fd = dmabuf_heap_open(heap_name); 154 155 if (heap_fd < 0) 155 156 return -1; 156 157 157 - printf("Allocating 1 MEG\n"); 158 + printf(" Testing allocation and importing: "); 158 159 ret = dmabuf_heap_alloc(heap_fd, ONE_MEG, 0, &dmabuf_fd); 159 160 if (ret) { 160 - printf("Allocation Failed!\n"); 161 + printf("FAIL (Allocation Failed!)\n"); 161 162 ret = -1; 162 163 goto out; 163 164 } ··· 167 172 dmabuf_fd, 168 173 0); 169 174 if (p == MAP_FAILED) { 170 - printf("mmap() failed: %m\n"); 175 + printf("FAIL (mmap() failed)\n"); 171 176 ret = -1; 172 177 goto out; 173 178 } 174 - printf("mmap passed\n"); 175 179 176 180 dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_START); 177 181 memset(p, 1, ONE_MEG / 2); ··· 180 186 importer_fd = open_vgem(); 181 187 if (importer_fd < 0) { 182 188 ret = importer_fd; 183 - printf("Failed to open vgem\n"); 184 - goto out; 189 + printf("(Could not open vgem - skipping): "); 190 + } else { 191 + ret = import_vgem_fd(importer_fd, dmabuf_fd, &handle); 192 + if (ret < 0) { 193 + printf("FAIL (Failed to import buffer)\n"); 194 + goto out; 195 + } 185 196 } 186 197 187 - ret = import_vgem_fd(importer_fd, dmabuf_fd, &handle); 198 + ret = dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_START); 188 199 if (ret < 0) { 189 - printf("Failed to import buffer\n"); 200 + printf("FAIL (DMA_BUF_SYNC_START failed!)\n"); 190 201 goto out; 191 202 } 192 - printf("import passed\n"); 193 203 194 - dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_START); 195 204 memset(p, 0xff, ONE_MEG); 196 - dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_END); 197 - printf("syncs passed\n"); 205 + ret = dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_END); 206 + if (ret < 0) { 207 + printf("FAIL (DMA_BUF_SYNC_END failed!)\n"); 208 + goto out; 209 + } 198 210 199 211 close_handle(importer_fd, handle); 200 212 ret = 0; 201 - 213 + printf(" OK\n"); 202 214 out: 203 215 if (p) 204 216 munmap(p, ONE_MEG); ··· 215 215 if (heap_fd >= 0) 216 216 close(heap_fd); 217 217 218 + return ret; 219 + } 220 + 221 + static int test_alloc_zeroed(char *heap_name, size_t size) 222 + { 223 + int heap_fd = -1, dmabuf_fd[32]; 224 + int i, j, ret; 225 + void *p = NULL; 226 + char *c; 227 + 228 + printf(" Testing alloced %ldk buffers are zeroed: ", size / 1024); 229 + heap_fd = dmabuf_heap_open(heap_name); 230 + if (heap_fd < 0) 231 + return -1; 232 + 233 + /* Allocate and fill a bunch of buffers */ 234 + for (i = 0; i < 32; i++) { 235 + ret = dmabuf_heap_alloc(heap_fd, size, 0, &dmabuf_fd[i]); 236 + if (ret < 0) { 237 + printf("FAIL (Allocation (%i) failed)\n", i); 238 + goto out; 239 + } 240 + /* mmap and fill with simple pattern */ 241 + p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, dmabuf_fd[i], 0); 242 + if (p == MAP_FAILED) { 243 + printf("FAIL (mmap() failed!)\n"); 244 + ret = -1; 245 + goto out; 246 + } 247 + dmabuf_sync(dmabuf_fd[i], DMA_BUF_SYNC_START); 248 + memset(p, 0xff, size); 249 + dmabuf_sync(dmabuf_fd[i], DMA_BUF_SYNC_END); 250 + munmap(p, size); 251 + } 252 + /* close them all */ 253 + for (i = 0; i < 32; i++) 254 + close(dmabuf_fd[i]); 255 + 256 + /* Allocate and validate all buffers are zeroed */ 257 + for (i = 0; i < 32; i++) { 258 + ret = dmabuf_heap_alloc(heap_fd, size, 0, &dmabuf_fd[i]); 259 + if (ret < 0) { 260 + printf("FAIL (Allocation (%i) failed)\n", i); 261 + goto out; 262 + } 263 + 264 + /* mmap and validate everything is zero */ 265 + p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, dmabuf_fd[i], 0); 266 + if (p == MAP_FAILED) { 267 + printf("FAIL (mmap() failed!)\n"); 268 + ret = -1; 269 + goto out; 270 + } 271 + dmabuf_sync(dmabuf_fd[i], DMA_BUF_SYNC_START); 272 + c = (char *)p; 273 + for (j = 0; j < size; j++) { 274 + if (c[j] != 0) { 275 + printf("FAIL (Allocated buffer not zeroed @ %i)\n", j); 276 + break; 277 + } 278 + } 279 + dmabuf_sync(dmabuf_fd[i], DMA_BUF_SYNC_END); 280 + munmap(p, size); 281 + } 282 + /* close them all */ 283 + for (i = 0; i < 32; i++) 284 + close(dmabuf_fd[i]); 285 + 286 + close(heap_fd); 287 + printf("OK\n"); 288 + return 0; 289 + 290 + out: 291 + while (i > 0) { 292 + close(dmabuf_fd[i]); 293 + i--; 294 + } 295 + close(heap_fd); 218 296 return ret; 219 297 } 220 298 ··· 370 292 if (heap_fd < 0) 371 293 return -1; 372 294 373 - printf("Testing (theoretical)older alloc compat\n"); 295 + printf(" Testing (theoretical)older alloc compat: "); 374 296 ret = dmabuf_heap_alloc_older(heap_fd, ONE_MEG, 0, &dmabuf_fd); 375 297 if (ret) { 376 - printf("Older compat allocation failed!\n"); 298 + printf("FAIL (Older compat allocation failed!)\n"); 377 299 ret = -1; 378 300 goto out; 379 301 } 380 302 close(dmabuf_fd); 303 + printf("OK\n"); 381 304 382 - printf("Testing (theoretical)newer alloc compat\n"); 305 + printf(" Testing (theoretical)newer alloc compat: "); 383 306 ret = dmabuf_heap_alloc_newer(heap_fd, ONE_MEG, 0, &dmabuf_fd); 384 307 if (ret) { 385 - printf("Newer compat allocation failed!\n"); 308 + printf("FAIL (Newer compat allocation failed!)\n"); 386 309 ret = -1; 387 310 goto out; 388 311 } 389 - printf("Ioctl compatibility tests passed\n"); 312 + printf("OK\n"); 390 313 out: 391 314 if (dmabuf_fd >= 0) 392 315 close(dmabuf_fd); ··· 406 327 if (heap_fd < 0) 407 328 return -1; 408 329 409 - printf("Testing expected error cases\n"); 330 + printf(" Testing expected error cases: "); 410 331 ret = dmabuf_heap_alloc(0, ONE_MEG, 0x111111, &dmabuf_fd); 411 332 if (!ret) { 412 - printf("Did not see expected error (invalid fd)!\n"); 333 + printf("FAIL (Did not see expected error (invalid fd)!)\n"); 413 334 ret = -1; 414 335 goto out; 415 336 } 416 337 417 338 ret = dmabuf_heap_alloc(heap_fd, ONE_MEG, 0x111111, &dmabuf_fd); 418 339 if (!ret) { 419 - printf("Did not see expected error (invalid heap flags)!\n"); 340 + printf("FAIL (Did not see expected error (invalid heap flags)!)\n"); 420 341 ret = -1; 421 342 goto out; 422 343 } ··· 424 345 ret = dmabuf_heap_alloc_fdflags(heap_fd, ONE_MEG, 425 346 ~(O_RDWR | O_CLOEXEC), 0, &dmabuf_fd); 426 347 if (!ret) { 427 - printf("Did not see expected error (invalid fd flags)!\n"); 348 + printf("FAIL (Did not see expected error (invalid fd flags)!)\n"); 428 349 ret = -1; 429 350 goto out; 430 351 } 431 352 432 - printf("Expected error checking passed\n"); 353 + printf("OK\n"); 433 354 ret = 0; 434 355 out: 435 356 if (dmabuf_fd >= 0) ··· 458 379 if (!strncmp(dir->d_name, "..", 3)) 459 380 continue; 460 381 382 + printf("Testing heap: %s\n", dir->d_name); 383 + printf("=======================================\n"); 461 384 ret = test_alloc_and_import(dir->d_name); 385 + if (ret) 386 + break; 387 + 388 + ret = test_alloc_zeroed(dir->d_name, 4 * 1024); 389 + if (ret) 390 + break; 391 + 392 + ret = test_alloc_zeroed(dir->d_name, ONE_MEG); 462 393 if (ret) 463 394 break; 464 395
+3 -3
tools/testing/selftests/ipc/msgque.c
··· 69 69 printf("msgsnd failed (%m)\n"); 70 70 ret = -errno; 71 71 goto destroy; 72 - }; 72 + } 73 73 } 74 74 return 0; 75 75 ··· 180 180 IPC_NOWAIT) != 0) { 181 181 printf("First message send failed (%m)\n"); 182 182 return -errno; 183 - }; 183 + } 184 184 185 185 msgbuf.mtype = ANOTHER_MSG_TYPE; 186 186 memcpy(msgbuf.mtext, ANOTHER_TEST_STRING, sizeof(ANOTHER_TEST_STRING)); ··· 188 188 IPC_NOWAIT) != 0) { 189 189 printf("Second message send failed (%m)\n"); 190 190 return -errno; 191 - }; 191 + } 192 192 return 0; 193 193 } 194 194
+2 -6
tools/testing/selftests/seccomp/seccomp_bpf.c
··· 4019 4019 4020 4020 /* Verify we can set an arbitrary remote fd */ 4021 4021 fd = ioctl(listener, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd); 4022 - /* 4023 - * The child has fds 0(stdin), 1(stdout), 2(stderr), 3(memfd), 4024 - * 4(listener), so the newly allocated fd should be 5. 4025 - */ 4026 - EXPECT_EQ(fd, 5); 4022 + EXPECT_GE(fd, 0); 4027 4023 EXPECT_EQ(filecmp(getpid(), pid, memfd, fd), 0); 4028 4024 4029 4025 /* Verify we can set an arbitrary remote fd with large size */ 4030 4026 memset(&big, 0x0, sizeof(big)); 4031 4027 big.addfd = addfd; 4032 4028 fd = ioctl(listener, SECCOMP_IOCTL_NOTIF_ADDFD_BIG, &big); 4033 - EXPECT_EQ(fd, 6); 4029 + EXPECT_GE(fd, 0); 4034 4030 4035 4031 /* Verify we can set a specific remote fd */ 4036 4032 addfd.newfd = 42;
+1
tools/testing/selftests/timens/.gitignore
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 clock_nanosleep 3 3 exec 4 + futex 4 5 gettime_perf 5 6 gettime_perf_cold 6 7 procfs
+3 -1
tools/testing/selftests/vDSO/vdso_config.h
··· 47 47 #elif defined(__x86_64__) 48 48 #define VDSO_VERSION 0 49 49 #define VDSO_NAMES 1 50 - #elif defined(__riscv__) 50 + #elif defined(__riscv__) || defined(__riscv) 51 51 #define VDSO_VERSION 5 52 52 #define VDSO_NAMES 1 53 + #if __riscv_xlen == 32 53 54 #define VDSO_32BIT 1 55 + #endif 54 56 #else /* nds32 */ 55 57 #define VDSO_VERSION 4 56 58 #define VDSO_NAMES 1
+1 -1
tools/testing/selftests/x86/ldt_gdt.c
··· 607 607 608 608 failures++; 609 609 asm volatile ("mov %0, %%ss" : : "rm" (orig_ss)); 610 - }; 610 + } 611 611 612 612 ftx = 100; /* Kill the thread. */ 613 613 syscall(SYS_futex, &ftx, FUTEX_WAKE, 0, NULL, NULL, 0);