Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1787179lqp; Mon, 15 Apr 2024 18:37:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWOCDlFoBsj0980lRN8E+x+rcNTQ+FmLOsSVW5zDvAGxnUe4CPZkP1LdkVHxpa7CdNe6B7kZkejyoASZ/udHboGLYeY2zpHlPduMwHidA== X-Google-Smtp-Source: AGHT+IHQu668Wu0Daz3YFbkoSB8Ds+53f2EZImc6e4/OqypiayD5upV+tOtQS06g/Pt/g0DzgfIe X-Received: by 2002:a17:90b:803:b0:2a6:43c:44c6 with SMTP id bk3-20020a17090b080300b002a6043c44c6mr9551739pjb.29.1713231419978; Mon, 15 Apr 2024 18:36:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713231419; cv=pass; d=google.com; s=arc-20160816; b=ICYfX76ytNobMOzHMRH0kzWkL+YdQyFZ0Z5QYQ3n/BEuHJGx0YPIsyHZXfwjFhYA2B vsf4jeMAtAGyR8tPT/PMGR2CUd1VpqZUmYrRoYsuBfcDMSmi6521v846YaF8FFCWcudQ rQ95zm6i4/lQstK5PCeYiWGAPP9rcUMg6mXXO4LuKvt4nJ6/LcSM1fzLhcxp+PUJfeb6 s4jElqYHdu23AgiSO7GO/roVSYbh3jko1FMnpEBAfM+Qp9vgoIpzrZsG0ahVEDWgQ0bI PaknXrYf5w2C77KY/roxiesvLpIxyiRQH1NpA0NuzlU7knMDXGl3lQGYd1S5N/gmY7WI GxHQ== 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=S+Bo60slTZYs+MASNA28omTt/46YdAeLaNdjfMjNW6Q=; fh=eVY06L/C5FDTmF2RNqfudsnjwkB3tbhT/y33cGhZc0I=; b=fhXRMINP6ZJrcOVXwMMTfYpR11jcknwQRrIO18kEZNVWPrTMGByIDzhraMpKbvQEwX 6+Sas2zq2tVK0Qb+Qc4MEHM9U71L4Ai94UgXGjgQ4NFFGts1t6xKv4UA7n3uOHFzss8P yj4eQpMZyTKOfb4vdNyjYyJRyNQviUoNCN5pzh7mvqyRWV+eH2Mx9jm/sQ1iEfuYqTsg gsT+MT+UuTkFwGNI/Ljc28b7EtkLj151L5cFfIGpJHFL3k5CTJ8tdR36Zax2Riwy03EH zno4Z6880MhniEdNTSwZwa1+k6/WxhHvHzmcXl3jFdcL1ghPrhuJIVbwWzAeq8tvPSIB 40lQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=RGSh9xf7; 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-146060-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146060-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a7-20020a17090acb8700b002a293bc1823si11011469pju.167.2024.04.15.18.36.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 18:36:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-146060-linux.lists.archive=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=RGSh9xf7; 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-146060-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146060-linux.lists.archive=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 0E7E0285849 for ; Tue, 16 Apr 2024 01:13:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5262244C6C; Tue, 16 Apr 2024 01:10:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="RGSh9xf7" 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 ADD063D76; Tue, 16 Apr 2024 01:10:28 +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=1713229831; cv=none; b=gt+Q9nVW9FTZPfYtPGFMCMWakB6hEDdi9TwZpBOIm51KCNfVQBrCO6HMKEUxqeR6U39+ont45z8JWrBYQ4I5/I7ex2KtBJn+ZuHMETtn0VQ2V09YimU6FebulfPfa6NPylGx7DlFhdFDMrQW7k4sL7Di4ZtJiJMZ8J2aX4rk/ik= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713229831; c=relaxed/simple; bh=c+6U+ZbefTz0YtyUBcA/usnu8kiO48W/n5csRaPODMw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HMni/83Z8n3av8Jf2nefMst+2mYgq6fcqP56dCzIa8rJMDApYzRSnkHHecLciM9YwMjKEg6R6SamjqNrusisF/3IxS18IshPEsljIxXov2E4ikmYbw2kBKG1ifHf8+llNC6nrZbh5puh79iVORcfrYFTaddpo+F9GH9HyFSNk74= 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=RGSh9xf7; 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=S+Bo60slTZYs+MASNA28omTt/46YdAeLaNdjfMjNW6Q=; b=RGSh9xf7EUkebVhFYG4izsW7VJ MnpAJE13y9RMesdl8ygYiFBzBreNubNs6bgBP1Iu/MYVOLuEeW7wyujqzVB2YXCWxRGuKU4zAH7MD W8qISkwGea23gEe+Y18yFXAZnlvBxR96PPkKkt6lUg6i62jWSpppBqKmRvxi1dditXzRtBSSMXq1/ YpX5s4zKpFoCljP0afsLZnXQKdte7ctygm6BTg0L9AZMgy9u+eNpH38slitWPL257u2YuCuevdkO4 4tUcMNgrp7lQmSgMuCGfdZjLd8LK0J3eGZwV3W9EdYk3d/3PPN+RD6sI99kHaziOSVsY44Rq2+kPD T5mK0JJw==; 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 1rwXL1-00FbQv-2Y; Mon, 15 Apr 2024 20:10:19 -0500 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=20Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Randy Dunlap , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , Elizabeth Figura Subject: [PATCH v4 17/27] selftests: ntsync: Add some tests for NTSYNC_IOC_WAIT_ALL. Date: Mon, 15 Apr 2024 20:08:27 -0500 Message-ID: <20240416010837.333694-18-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240416010837.333694-1-zfigura@codeweavers.com> References: <20240416010837.333694-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 40ad8cbd3138..c0f372167557 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 -- 2.43.0