From patchwork Wed Jan 31 02:13:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194435 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1625819dyb; Tue, 30 Jan 2024 18:18:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVfap1T4GUqua2RBBMOJzOCz0MWLAhvH8uWKrL8CZNUV8d2yY2IPW7EE1o51p3lw+N8+q3 X-Received: by 2002:a17:90b:3592:b0:290:8bbf:e4c0 with SMTP id mm18-20020a17090b359200b002908bbfe4c0mr454197pjb.39.1706667527610; Tue, 30 Jan 2024 18:18:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706667527; cv=pass; d=google.com; s=arc-20160816; b=m8QMk1TuoGdGPJ5/jAN8OSjbqJ/suokSF7dNUlu8fjv3rDxyiR0bUFUo0zGUHgs9Vj M1bWFGAvF/s62Cg4O7ZQeSlvj+/2p5M1mX8hCJhbFqtRwPU6hVKTOnMcTDTwSDN/P6uK TvA7aJO1x0AicOv4JN8lkweb+6pR9ddwJBvHelZ7STl7lwfGv9kJerKfd27j8ckr6RdD LOH25ZadUgGW1v83Tu0MqJHyjH1DjO1uLSOQqFpwJwgf5/hMgamiHBut+F55xAsMjSaC r0No/a3/uqzA3m2TwECq1b7sD6Lw9ke1At90dkbCK5eU7vA2NZ0hC2dUyE2TXFaNQZT6 okRQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=h/1vAQRnjB63mlOEaG3p0S99D4AXtVBKAiVYE66GsDk=; fh=RE5eoUY+nHABu41+F02SXe+o1DxneUTJCtgCxnJ4vLo=; b=h4AxHdk7GIK0SBB3B2Vew1VM5d8O23A3VPr0Y8ZWNfEUDIbikbh5oU76QAia0Ewxiz diVYC0Cqkhx79rho64WSIKO3O4vi6xMEeWfBK3QYPf2y+nKGOD+1CHAKrgAvKA7K2i20 /5Si9hIo2nLQR2WbC4TvpIZQdoG0/wRNENr5B8+yygBut4fl9roF5H9+AKt609vrDXA5 5uf5cEsEe/fx8Qax8Nm1tq9KGELH4W1/an+E/kmcKUxvBpCnf8y2XIOi4KAPXA9n8gap Xr1ZYK6Po5ahi3ukPyoj2nGD7eNpZ553BsC7JWbRIZJZM/x1Y6OuiCU4Gcw5qb6HYsy/ /m3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=Nh0D1p1x; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45635-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45635-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCWhWIIJ4rlRX8K/bHNriTepbYsNkfKF3NqQ/LOkvkDK9BRyNRjitT/fUsZyl7wJcfpUGEQGXkTfKKRDiYdPm+sxdST8yA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id r31-20020a17090a43a200b00290260542c3si143106pjg.184.2024.01.30.18.18.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:18:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45635-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=Nh0D1p1x; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-45635-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45635-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0DA74281DC3 for ; Wed, 31 Jan 2024 02:18:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 838FB38DD2; Wed, 31 Jan 2024 02:16:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="Nh0D1p1x" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 967F65692; Wed, 31 Jan 2024 02:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667366; cv=none; b=fc0faE1PpktPXd5pTrvPeNySIHr0XujVuKC2He1sZJb7y8vfXrw/xAkvoG22jhSN8RLvclrwDdxyVhgZ+vwRnN9khmDWZMsZf23EHXVDv6ViN2BU4hn4Ess5MBJKhtFW+7f7qDBGD+oux7mHMT/S13RQGGmGCxby/DE6QWWYeW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667366; c=relaxed/simple; bh=YuG2+eVgb+GAeOar9WYoIv+9X1Xk48CH588RfHzbJNU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qlahzXkjX5jPgbP+j1Uvl1iq8NkefiolIGxZPCL9J1QZ9ODa/DAc4BdhXJTX3hJK8k/dSxyhZV8e1qI0+5AVwLxWO4pKGP8RL1wYN8GQpTOYl4RGFEbACkQjE16WS+Eplt1CWYhf3jChOZSlo/xDldV0g+PU6IR0uf19QO+dc+0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=Nh0D1p1x; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=h/1vAQRnjB63mlOEaG3p0S99D4AXtVBKAiVYE66GsDk=; b=Nh0D1p1xOizeeLJ7Gb1yhfmm7x /vcGYZN01VBqonIUtCpaFC7LJ0h/nbyS/+2TATgH+AuDSZ+81gWwICo/ALAv76bm6BsJ1s9jw6Yzu 1DCsfHlToQlQVIzYGLDv8R3zm9dYOBDfYOWrfOqCWpoGIlm4Ol/OIpb4Q7cv5bf1fB19G8BcJo4D7 yEJ+eCOlafRyIrywVF6/6OtZUIcRVzJnQqjz7XXeEMbGSksmG79/zJAB8LtC9iCGOtVoWNZ9iEIjs 0R6biI85HXUJnOZkejwPszXc9Yz3M8oA4573n1fE8gOQLzVfqu3ygWGNmxhRVo3dD2DkMkfeI5X00 uJ3VsvAg==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rV08q-0038Kv-0M; Tue, 30 Jan 2024 20:15:56 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [RFC PATCH v2 22/29] selftests: ntsync: Add some tests for wakeup signaling with WINESYNC_IOC_WAIT_ALL. Date: Tue, 30 Jan 2024 20:13:49 -0600 Message-ID: <20240131021356.10322-23-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021356.10322-1-zfigura@codeweavers.com> References: <20240131021356.10322-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789570609250805774 X-GMAIL-MSGID: 1789570609250805774 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 --- .../testing/selftests/drivers/ntsync/ntsync.c | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 96a866ef235f..7776fe71b8ef 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -673,4 +673,102 @@ TEST(wake_any) close(fd); } +TEST(wake_all) +{ + struct ntsync_mutex_args mutex_args = {0}; + struct ntsync_wait_args wait_args = {0}; + struct ntsync_sem_args sem_args = {0}; + struct wait_args thread_args; + int objs[2], fd, ret; + __u32 count, index; + pthread_t thread; + + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); + ASSERT_LE(0, fd); + + sem_args.count = 0; + sem_args.max = 3; + sem_args.sem = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, sem_args.sem); + + mutex_args.owner = 123; + mutex_args.count = 1; + mutex_args.mutex = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_MUTEX, &mutex_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, mutex_args.mutex); + + objs[0] = sem_args.sem; + objs[1] = mutex_args.mutex; + + wait_args.timeout = get_abs_timeout(1000); + wait_args.objs = (uintptr_t)objs; + wait_args.count = 2; + wait_args.owner = 456; + thread_args.fd = fd; + thread_args.args = &wait_args; + thread_args.request = NTSYNC_IOC_WAIT_ALL; + ret = pthread_create(&thread, NULL, wait_thread, &thread_args); + EXPECT_EQ(0, ret); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(ETIMEDOUT, ret); + + count = 1; + ret = post_sem(sem_args.sem, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, count); + + ret = pthread_tryjoin_np(thread, NULL); + EXPECT_EQ(EBUSY, ret); + + check_sem_state(sem_args.sem, 1, 3); + + ret = wait_any(fd, 1, &sem_args.sem, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + + ret = unlock_mutex(mutex_args.mutex, 123, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, count); + + ret = pthread_tryjoin_np(thread, NULL); + EXPECT_EQ(EBUSY, ret); + + check_mutex_state(mutex_args.mutex, 0, 0); + + count = 2; + ret = post_sem(sem_args.sem, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, count); + check_sem_state(sem_args.sem, 1, 3); + check_mutex_state(mutex_args.mutex, 1, 456); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, thread_args.ret); + + /* delete an object while it's being waited on */ + + wait_args.timeout = get_abs_timeout(200); + wait_args.owner = 123; + ret = pthread_create(&thread, NULL, wait_thread, &thread_args); + EXPECT_EQ(0, ret); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(ETIMEDOUT, ret); + + close(sem_args.sem); + close(mutex_args.mutex); + + ret = wait_for_thread(thread, 200); + EXPECT_EQ(0, ret); + EXPECT_EQ(-1, thread_args.ret); + EXPECT_EQ(ETIMEDOUT, thread_args.err); + + close(fd); +} + TEST_HARNESS_MAIN