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 wakeup signaling with WINESYNC_IOC_WAIT_ALL.

Test contended "wait-for-all" waits, to make sure that scheduling and wakeup
logic works correctly, and that the wait only exits once objects are all
simultaneously signaled.

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

authored by

Elizabeth Figura and committed by
Greg Kroah-Hartman
72a651c1 f2327985

+91
+91
tools/testing/selftests/drivers/ntsync/ntsync.c
··· 675 675 close(fd); 676 676 } 677 677 678 + TEST(wake_all) 679 + { 680 + struct ntsync_mutex_args mutex_args = {0}; 681 + struct ntsync_wait_args wait_args = {0}; 682 + struct ntsync_sem_args sem_args = {0}; 683 + struct wait_args thread_args; 684 + int objs[2], fd, ret; 685 + __u32 count, index; 686 + pthread_t thread; 687 + 688 + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); 689 + ASSERT_LE(0, fd); 690 + 691 + sem_args.count = 0; 692 + sem_args.max = 3; 693 + objs[0] = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); 694 + EXPECT_LE(0, objs[0]); 695 + 696 + mutex_args.owner = 123; 697 + mutex_args.count = 1; 698 + objs[1] = ioctl(fd, NTSYNC_IOC_CREATE_MUTEX, &mutex_args); 699 + EXPECT_LE(0, objs[1]); 700 + 701 + wait_args.timeout = get_abs_timeout(1000); 702 + wait_args.objs = (uintptr_t)objs; 703 + wait_args.count = 2; 704 + wait_args.owner = 456; 705 + thread_args.fd = fd; 706 + thread_args.args = &wait_args; 707 + thread_args.request = NTSYNC_IOC_WAIT_ALL; 708 + ret = pthread_create(&thread, NULL, wait_thread, &thread_args); 709 + EXPECT_EQ(0, ret); 710 + 711 + ret = wait_for_thread(thread, 100); 712 + EXPECT_EQ(ETIMEDOUT, ret); 713 + 714 + count = 1; 715 + ret = release_sem(objs[0], &count); 716 + EXPECT_EQ(0, ret); 717 + EXPECT_EQ(0, count); 718 + 719 + ret = pthread_tryjoin_np(thread, NULL); 720 + EXPECT_EQ(EBUSY, ret); 721 + 722 + check_sem_state(objs[0], 1, 3); 723 + 724 + ret = wait_any(fd, 1, &objs[0], 123, &index); 725 + EXPECT_EQ(0, ret); 726 + EXPECT_EQ(0, index); 727 + 728 + ret = unlock_mutex(objs[1], 123, &count); 729 + EXPECT_EQ(0, ret); 730 + EXPECT_EQ(1, count); 731 + 732 + ret = pthread_tryjoin_np(thread, NULL); 733 + EXPECT_EQ(EBUSY, ret); 734 + 735 + check_mutex_state(objs[1], 0, 0); 736 + 737 + count = 2; 738 + ret = release_sem(objs[0], &count); 739 + EXPECT_EQ(0, ret); 740 + EXPECT_EQ(0, count); 741 + check_sem_state(objs[0], 1, 3); 742 + check_mutex_state(objs[1], 1, 456); 743 + 744 + ret = wait_for_thread(thread, 100); 745 + EXPECT_EQ(0, ret); 746 + EXPECT_EQ(0, thread_args.ret); 747 + 748 + /* delete an object while it's being waited on */ 749 + 750 + wait_args.timeout = get_abs_timeout(200); 751 + wait_args.owner = 123; 752 + ret = pthread_create(&thread, NULL, wait_thread, &thread_args); 753 + EXPECT_EQ(0, ret); 754 + 755 + ret = wait_for_thread(thread, 100); 756 + EXPECT_EQ(ETIMEDOUT, ret); 757 + 758 + close(objs[0]); 759 + close(objs[1]); 760 + 761 + ret = wait_for_thread(thread, 200); 762 + EXPECT_EQ(0, ret); 763 + EXPECT_EQ(-1, thread_args.ret); 764 + EXPECT_EQ(ETIMEDOUT, thread_args.err); 765 + 766 + close(fd); 767 + } 768 + 678 769 TEST_HARNESS_MAIN