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

Configure Feed

Select the types of activity you want to include in your feed.

selftests: ntsync: Add some tests for NTSYNC_IOC_WAIT_ALL.

Test basic synchronous functionality of NTSYNC_IOC_WAIT_ALL, and when objects
are considered simultaneously signaled.

Signed-off-by: Elizabeth Figura <zfigura@codeweavers.com>
Link: https://lore.kernel.org/r/20241213193511.457338-20-zfigura@codeweavers.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Elizabeth Figura and committed by
Greg Kroah-Hartman
d168f689 44554569

+91 -2
+91 -2
tools/testing/selftests/drivers/ntsync/ntsync.c
··· 73 73 return ret; 74 74 } 75 75 76 - static int wait_any(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) 76 + static int wait_objs(int fd, unsigned long request, __u32 count, 77 + const int *objs, __u32 owner, __u32 *index) 77 78 { 78 79 struct ntsync_wait_args args = {0}; 79 80 struct timespec timeout; ··· 87 86 args.objs = (uintptr_t)objs; 88 87 args.owner = owner; 89 88 args.index = 0xdeadbeef; 90 - ret = ioctl(fd, NTSYNC_IOC_WAIT_ANY, &args); 89 + ret = ioctl(fd, request, &args); 91 90 *index = args.index; 92 91 return ret; 92 + } 93 + 94 + static int wait_any(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) 95 + { 96 + return wait_objs(fd, NTSYNC_IOC_WAIT_ANY, count, objs, owner, index); 97 + } 98 + 99 + static int wait_all(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) 100 + { 101 + return wait_objs(fd, NTSYNC_IOC_WAIT_ALL, count, objs, owner, index); 93 102 } 94 103 95 104 TEST(semaphore_state) ··· 446 435 EXPECT_EQ(EINVAL, errno); 447 436 448 437 ret = wait_any(fd, -1, objs, 123, &index); 438 + EXPECT_EQ(-1, ret); 439 + EXPECT_EQ(EINVAL, errno); 440 + 441 + close(objs[0]); 442 + 443 + close(fd); 444 + } 445 + 446 + TEST(test_wait_all) 447 + { 448 + struct ntsync_mutex_args mutex_args = {0}; 449 + struct ntsync_sem_args sem_args = {0}; 450 + __u32 owner, index, count; 451 + int objs[2], fd, ret; 452 + 453 + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); 454 + ASSERT_LE(0, fd); 455 + 456 + sem_args.count = 2; 457 + sem_args.max = 3; 458 + objs[0] = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); 459 + EXPECT_LE(0, objs[0]); 460 + 461 + mutex_args.owner = 0; 462 + mutex_args.count = 0; 463 + objs[1] = ioctl(fd, NTSYNC_IOC_CREATE_MUTEX, &mutex_args); 464 + EXPECT_LE(0, objs[1]); 465 + 466 + ret = wait_all(fd, 2, objs, 123, &index); 467 + EXPECT_EQ(0, ret); 468 + EXPECT_EQ(0, index); 469 + check_sem_state(objs[0], 1, 3); 470 + check_mutex_state(objs[1], 1, 123); 471 + 472 + ret = wait_all(fd, 2, objs, 456, &index); 473 + EXPECT_EQ(-1, ret); 474 + EXPECT_EQ(ETIMEDOUT, errno); 475 + check_sem_state(objs[0], 1, 3); 476 + check_mutex_state(objs[1], 1, 123); 477 + 478 + ret = wait_all(fd, 2, objs, 123, &index); 479 + EXPECT_EQ(0, ret); 480 + EXPECT_EQ(0, index); 481 + check_sem_state(objs[0], 0, 3); 482 + check_mutex_state(objs[1], 2, 123); 483 + 484 + ret = wait_all(fd, 2, objs, 123, &index); 485 + EXPECT_EQ(-1, ret); 486 + EXPECT_EQ(ETIMEDOUT, errno); 487 + check_sem_state(objs[0], 0, 3); 488 + check_mutex_state(objs[1], 2, 123); 489 + 490 + count = 3; 491 + ret = release_sem(objs[0], &count); 492 + EXPECT_EQ(0, ret); 493 + EXPECT_EQ(0, count); 494 + 495 + ret = wait_all(fd, 2, objs, 123, &index); 496 + EXPECT_EQ(0, ret); 497 + EXPECT_EQ(0, index); 498 + check_sem_state(objs[0], 2, 3); 499 + check_mutex_state(objs[1], 3, 123); 500 + 501 + owner = 123; 502 + ret = ioctl(objs[1], NTSYNC_IOC_MUTEX_KILL, &owner); 503 + EXPECT_EQ(0, ret); 504 + 505 + ret = wait_all(fd, 2, objs, 123, &index); 506 + EXPECT_EQ(-1, ret); 507 + EXPECT_EQ(EOWNERDEAD, errno); 508 + check_sem_state(objs[0], 1, 3); 509 + check_mutex_state(objs[1], 1, 123); 510 + 511 + close(objs[1]); 512 + 513 + /* test waiting on the same object twice */ 514 + objs[1] = objs[0]; 515 + ret = wait_all(fd, 2, objs, 123, &index); 449 516 EXPECT_EQ(-1, ret); 450 517 EXPECT_EQ(EINVAL, errno); 451 518