From patchwork Wed Jan 31 02:13:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194441 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1626189dyb; Tue, 30 Jan 2024 18:20:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4WzHygVcZ0IefSXpwBMiJld+VRRW/LNPwT9qRfupgED+rCo0UqLzNiPkDcCiNS6bZ1xQx X-Received: by 2002:a17:906:5053:b0:a35:32ae:e0c0 with SMTP id e19-20020a170906505300b00a3532aee0c0mr132002ejk.3.1706667603709; Tue, 30 Jan 2024 18:20:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706667603; cv=pass; d=google.com; s=arc-20160816; b=xSYK1v8x7+rViNPaXUldjq8XegdF9W0eqBbh5TAfn6ZkRD04txE6gvkh33Rw88NDJ1 WLsXLBHABa1XUp4SRQ+XXBO/jYcHqfPQhfPbeAeixDShCiVgfN7NX1d0Wo55zoDItHLb uIi1MR9oFxNvbTFISZR3Oq6+6wAkBrMygsGUnx4LzogSoTqOuhSUJ6dc5ffbbrpN9v/N gXfhJuua+oUiRprXvCQuK41Fe1SpwiofseN55fesC3x5phDxAfczqxRunxYVoHpIdkI/ jXzSXLyFFeElgiof2agSVdftd48LLixKlcUV9jE6Ua7plhxyh9bzqsfpF7PXZ/Ap8W8H B+9g== 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=sOzqgnLGIgtRKny4Ao2xmWC9bt9j+bFRdf4xOt6jSBg=; fh=gYdumsO9MQReQQWUn7obxuaqjrvRnE+NeXEH/iEc55Y=; b=UQ6Lhj469TniGMuxKQaUGs0kDpzejPVrt4+gnpHuRh1HX+xcoXZk8diCYz5XobeHLj t/wDJjb2p0hRT3Af9Nu3tChs1wWt99ZUYI12XGO8iq29wUdM0pdh6i4w1Qfy7upXCjFc PR5yvZyQpsBB+JBUukz4Aql3/bBaV8+aK1FRA0OWZ6pMzQOwBitSn7msu/ZzWPYK+gHM WmO4ZpBL+kGtOctTFV7lNWvqbMONAcyikqm0658OqDowb/LmdV/usnK/RrxykJ8eWr4H EfSAK7nSg3xW5MPysQZMo6NfQc7FQVwysSeATueC38iy11lJfcyROSkj6mBwp6qWRZqR gWug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=RBVsFPvj; 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-45638-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45638-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCU2OGifF7UKKc3N3NAZ3spSBtETzMRhNt7Jg3b/Zucllvqg4obNIDbNj0b/fyNGTk6yH8qAd91DUAV9rbC9lEegq+tPUw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f6-20020a1709067f8600b00a3588053674si3199002ejr.815.2024.01.30.18.20.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:20:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45638-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=RBVsFPvj; 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-45638-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45638-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2525C1F27DF0 for ; Wed, 31 Jan 2024 02:20:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 607F03A1DC; Wed, 31 Jan 2024 02:16:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="RBVsFPvj" 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 969415C89; 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=1706667367; cv=none; b=KjcYQH/ORyjEf4N1NGzA4nWd75oydARYyi98Cw66k81h6JrKJZHJu68XPfwb8B8jJlAU1pirenkvcm+rmZs3JzcArGDFe9XIQgmB0iucU05++1y1d8lvQNq7mtQaRBW66upVruzN88HMUiKuT90dd8s8xuSaDA5uDtd4t16JmOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; c=relaxed/simple; bh=Kxq4U91L+cNlWSbgSblxx75X7Ad/unW7tV8FCOgmvDE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tLpDhv/AEzszk0ESzQRWfXmUBynmRZKKXd26ITLT6Oeao39GyWpjrhiOXJ4VFy4FQsjlXQd6k1fwlQVWiKUW527Sw7zHc35mmXmgZ+S7Q7ImK7tfYS6GqG4CN/LQNZb1T2pEcHe4xOC6V0QRGbSTqKZscmPiVSuC5PtPkjeKJ2c= 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=RBVsFPvj; 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=sOzqgnLGIgtRKny4Ao2xmWC9bt9j+bFRdf4xOt6jSBg=; b=RBVsFPvjaFUGQWiZ5fE3H2QHuK QNMwZ+In0cCqZ8//4V7v/9dSRYePTgH2Cdy/H2H4f7rdQiCnUjqSkdXYfUX1cRpWcY2oIcP1tXGHh e8liJK0QCXtXjDYL0oTWWnt4ldy5y6XPFfCyAky9RfEU8ms/TK924zqAMzZVAW2tw4d3qeKGl5UwH j4eRKwNgHKipTPLusD9c8ME4WpxMjjecaJzSnoKvcSYzkPBdnlASvN5WwDIZxwPRWnGObqbUr1+rj M0lIYOiWAFGWh3tQlrGtFTH0FIFQlAtY3KDUFbZA31Lgby0AosPS0Xr30a0thzUnlgl4RdvxAOWLB E4tdhVVg==; 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 1rV08p-0038Kv-2k; Tue, 30 Jan 2024 20:15:55 -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 20/29] selftests: ntsync: Add some tests for NTSYNC_IOC_WAIT_ALL. Date: Tue, 30 Jan 2024 20:13:47 -0600 Message-ID: <20240131021356.10322-21-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: 1789570689046815479 X-GMAIL-MSGID: 1789570689046815479 Test basic synchronous functionality of NTSYNC_IOC_WAIT_ALL, and when objects are considered simultaneously signaled. Signed-off-by: Elizabeth Figura --- .../testing/selftests/drivers/ntsync/ntsync.c | 99 ++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 13e7c9d7441e..77f1b7e42d76 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -73,7 +73,8 @@ static int unlock_mutex(int mutex, __u32 owner, __u32 *count) return ret; } -static int wait_any(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) +static int wait_objs(int fd, unsigned long request, __u32 count, + const int *objs, __u32 owner, __u32 *index) { struct ntsync_wait_args args = {0}; struct timespec timeout; @@ -86,11 +87,21 @@ static int wait_any(int fd, __u32 count, const int *objs, __u32 owner, __u32 *in args.objs = (uintptr_t)objs; args.owner = owner; args.index = 0xdeadbeef; - ret = ioctl(fd, NTSYNC_IOC_WAIT_ANY, &args); + ret = ioctl(fd, request, &args); *index = args.index; return ret; } +static int wait_any(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) +{ + return wait_objs(fd, NTSYNC_IOC_WAIT_ANY, count, objs, owner, index); +} + +static int wait_all(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) +{ + return wait_objs(fd, NTSYNC_IOC_WAIT_ALL, count, objs, owner, index); +} + TEST(semaphore_state) { struct ntsync_sem_args sem_args; @@ -426,4 +437,88 @@ TEST(test_wait_any) close(fd); } +TEST(test_wait_all) +{ + struct ntsync_mutex_args mutex_args = {0}; + struct ntsync_sem_args sem_args = {0}; + __u32 owner, index, count; + int objs[2], fd, ret; + + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); + ASSERT_LE(0, fd); + + sem_args.count = 2; + 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 = 0; + mutex_args.count = 0; + 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; + + ret = wait_all(fd, 2, objs, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_sem_state(sem_args.sem, 1, 3); + check_mutex_state(mutex_args.mutex, 1, 123); + + ret = wait_all(fd, 2, objs, 456, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + check_sem_state(sem_args.sem, 1, 3); + check_mutex_state(mutex_args.mutex, 1, 123); + + ret = wait_all(fd, 2, objs, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_sem_state(sem_args.sem, 0, 3); + check_mutex_state(mutex_args.mutex, 2, 123); + + ret = wait_all(fd, 2, objs, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + check_sem_state(sem_args.sem, 0, 3); + check_mutex_state(mutex_args.mutex, 2, 123); + + count = 3; + ret = post_sem(sem_args.sem, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, count); + + ret = wait_all(fd, 2, objs, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_sem_state(sem_args.sem, 2, 3); + check_mutex_state(mutex_args.mutex, 3, 123); + + owner = 123; + ret = ioctl(mutex_args.mutex, NTSYNC_IOC_MUTEX_KILL, &owner); + EXPECT_EQ(0, ret); + + ret = wait_all(fd, 2, objs, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EOWNERDEAD, errno); + check_sem_state(sem_args.sem, 1, 3); + check_mutex_state(mutex_args.mutex, 1, 123); + + /* test waiting on the same object twice */ + objs[0] = objs[1] = sem_args.sem; + ret = wait_all(fd, 2, objs, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EINVAL, errno); + + close(sem_args.sem); + close(mutex_args.mutex); + + close(fd); +} + TEST_HARNESS_MAIN