From patchwork Wed Feb 14 23:52:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 201197 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp62804dyb; Wed, 14 Feb 2024 16:00:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX2NdPQgzcLoEyJjNld7IThG3MhnlRvwI7rvg2RQXTjGCFymNdbrR9j9Cg9hWl4m2/fNZ2btcAUfx6MST2YGqgg1FvHuA== X-Google-Smtp-Source: AGHT+IGkCncYwLGnMwLiUZRVMVbpF683g36jkr7BVkE3tpjy2PEVJOkAa89HggE21q8M/+bwD2+1 X-Received: by 2002:a17:902:7001:b0:1da:1e83:b961 with SMTP id y1-20020a170902700100b001da1e83b961mr152497plk.63.1707955210037; Wed, 14 Feb 2024 16:00:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707955210; cv=pass; d=google.com; s=arc-20160816; b=p5bAP+gL3aJaX5k6GqklCX3T90BnYV7dcWNLwLuepfw8cg0vw5AJ21hzD921CzyLGu oME5RYVgmP4AGm5Ptu8PvvPw3BFTpQJSmmF/6oD+lVggLivk3srvy51NmUiljjFIpnAd lfSc5auHTxyxqY1x9JEHjgSl93M0vsLGWW5d8f14hZlXVdNEodiV6dk9a+phctz8mGPV NiuV6ejSmzrfTjdEd9+0nN7lf1P6fWwvcAEZzNiF+bDItjlAEGNv2WkPyAKyZV0/gBXb hCGCJbC5kSB3QmvpOHdA9UK+2cq16IlmJdMCtsKFjk7XK53p+GlB01uVC7GDaGUe8rJH 4dKQ== 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=1JYvPoY/ppOEUjmlJpt8VqHXNCiWzb7HrdTFPiD3zs0=; fh=sOAzP1IXJnllEbSCBRlwdfT0MN3UiaRLwzx1Tpw7GJA=; b=il+c09nK68HeccSQGTgxKn010YwyMollWVk1Bo6WKdcmt4SfJbCM9R4W01ZS5XeK1H iR6IggIO4MtM3+q6tl94m8/r2VSDCI0E4FNEiQ6gZHOOvAFvit+5L22V4XZYIIp+ZRuI rIa0mK5HR8WDoTXSOEeTSvgE//bBxc5+BO40yY+ZW7beKX/qlGCkpcOCfH8ItLb/gvOt hpbDfWWdKj8M74y28rTtbx2rMALbY5SOmaoh7xu2ilH/uvOz2wmv1FhqNf9Xe6olonTA zS9Xyan/tAuYuFIKb/R/lPyPr2roSXPpbnADeYhH3x8uG1hV0wIRgtvJWjoSuXzmRMiB BcMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b="CA/L99Iu"; 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-66156-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66156-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p6-20020a170902780600b001db29e3ba29si44115pll.77.2024.02.14.16.00.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 16:00:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66156-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b="CA/L99Iu"; 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-66156-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66156-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 40A71282EE9 for ; Wed, 14 Feb 2024 23:59:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 454CE14D430; Wed, 14 Feb 2024 23:53:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="CA/L99Iu" 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 6D4ED14A4FB; Wed, 14 Feb 2024 23:53:44 +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=1707954825; cv=none; b=AAEtQNq//YSOfiAaPB/R4XOtUoGHyX/T+i8kJuEGCdLGnciLyGu17Wf6f8eHL5Aqqu5S1uJtSY8dKR58RIchgy90KKKxkZ2/yL25KKNdrY0JPxvD+/3K3umJ59nqHE3P6qpC4HSa0ff5bpRtSt7s3QHa/NkndtJW+QpXP/8f1ik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707954825; c=relaxed/simple; bh=UA9Bt50olybqISzQXiEAoLdmwT0I1oA3lCfN4NtbGKU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oS582QTCsb80Jqe69DVyoWtxPbjMelPE4QtlLHVUlm+Zsz3vYaoKRGJvSw0Tknu7usNvmZRQCnj/aYNBD0Rxmnoqc1rC+5E1AJn6DhLwX9J1GPai9Q6ofX/efHLJvJILgNrLpvxRUL9xRZGaXyndvvCcHNcR9673RhGBkM/YDKk= 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=CA/L99Iu; 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=1JYvPoY/ppOEUjmlJpt8VqHXNCiWzb7HrdTFPiD3zs0=; b=CA/L99Iu7+foxDZuRDdZL0SDQz z48iryMa1yPz3CntPRVq21mKsmbl2Eq1O++kSx1Ux7UZjLhz74H5DthGMedo4crh1+LGU6BIvL6Np Nkdt0rv3QNDQshtC3LvK2/SnYuR4zMyiyPcaEUoeXnv7OyFuqHzGrqrQoWELv1PwpoCpQ36UxlusW nez0S6HhdPAoepk0J+oytn1zL7bHvBbduBO/pvC+dj+FRxJIu8hl44L3UV1df2VvqEh6T6SBBv7f5 qPBE8g8qWRdsGz0RkRGRfuujGXTv7GKG0l3ncRPVdv3Oh+0FHrB/I8GcMQRlf38+Ha91I1SFvHcoz 8mWqVIqw==; 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 1raP4M-00GcSK-29; Wed, 14 Feb 2024 17:53:39 -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: [PATCH 21/31] selftests: ntsync: Add some tests for NTSYNC_IOC_WAIT_ALL. Date: Wed, 14 Feb 2024 17:52:56 -0600 Message-ID: <20240214235307.10494-12-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214235307.10494-1-zfigura@codeweavers.com> References: <20240214233645.9273-1-zfigura@codeweavers.com> <20240214235307.10494-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: 1790920842357417244 X-GMAIL-MSGID: 1790920842357417244 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 ca61fb17439b..6bb3bdc2ef3c 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; @@ -461,4 +472,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