Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2102163lqo; Sun, 19 May 2024 13:37:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV6hWPzTx05NGS/ZWkBNzi1OJ5vi9mKC5iEA7d0TOyzyepZovCBzIa2tCj8RyytZnHLRuPktViPpEsTAbtiMr4PcoWSSMwRPPfzWlxLcQ== X-Google-Smtp-Source: AGHT+IGeCnDfzkpXk/WO8e98hfTDViKVC06uAEFRj/t1qBfl5RcG6CQpWYfNp4eSr/iiMtC9EhkT X-Received: by 2002:a05:6808:6290:b0:3c9:91e8:53a8 with SMTP id 5614622812f47-3c9970d1de5mr28675621b6e.54.1716151067373; Sun, 19 May 2024 13:37:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716151067; cv=pass; d=google.com; s=arc-20160816; b=kiNUHftsuKUAn5PqolF53HdJzh9owBqKMpoRN8j6YALkGMYEv2rYnI7jINjI1Jz77w M35JO1yDn7N7uE35n+fZTELsQb08OJ0Qd6RckxeZTukYEIXOxGZF7OGdKGCuxzOkfpcD Z3HuzrNd+OSaxzfgmHcHlqyICntNCkgQaeD46fj+xQh7tc0nAllKC0ZWAc3FnHqe0fww ajFEnQQZ7RfQxKXd0p+gvLFDp7kVVxV8655MixJ7z2u23doSH28J34mofh5qDsGPNNwN Icv0zyuGvTk/TK8iArkY3t3/1N6Y4qVc3CSCWl4URT2RWRsIt4vlHDwhJEJeEmSbVrvp qAng== 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=1lbo0bNxrPdMIVRoJ6+tExY5TotubsDpMSLovzCGBGc=; fh=eVY06L/C5FDTmF2RNqfudsnjwkB3tbhT/y33cGhZc0I=; b=XvIdX1pnoVzov7v0GoKarcyXWd8USha/yRkLJnc7+oiKr+aqbC+QhRInNsTSv8yB72 YTXzqDdDpSot+1+WNI40TOurUXaNI25wcO4cDXChPCmaxZe5K6NxmWEMB4upO/g/UUey Wk1XtLFq945TWaouNnFPTAxGJ/yKIzuZ+WApbPHBOK0LpX/AA7BOOcQYz+i5+K20lL1m cZZrcVbRkju2NdRo2bZUK2hpR50HJdjTdHANwSUN+O1+2elSDwbqUFkcVtx6RXK+WRhx gLX25Hc398gn7zAKIQuMHqRQ3pCPzRVwIeixfRVAuGuGSDfMKA/lHDG6hpExeIx9QMbS qJ7w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=UNJOwmxP; 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-183260-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183260-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-792bf2777d7si2341902985a.100.2024.05.19.13.37.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 May 2024 13:37:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183260-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=UNJOwmxP; 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-183260-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183260-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1BE571C2191D for ; Sun, 19 May 2024 20:31:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 698F982872; Sun, 19 May 2024 20:25:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="UNJOwmxP" 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 BD9C36E60E; Sun, 19 May 2024 20:25:15 +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=1716150322; cv=none; b=BlZ/gw9Dttk5FJ1vSRv6clyW+bYzgh09qTix3+2SGhw33gTy9QQSgnSCF+W5ZMhCHnyVMfxim5xW5rFS608yQs1l2HrQq8jL3/Rxb81Qsd434BwTpGno9osgEW7SvpRGiEKqG0wMW8WwD6CSlXf3CMZiDb2QSyYzz0Nd0g6K5aE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716150322; c=relaxed/simple; bh=8mBpNrep45/WQcWJkfana5grpHviuBbZ8c3NZYi9TZk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QxJHQsVoqIuXetfXWgopqUnry9ajqavaR2xxeIvERdDYACxbsLRwDJJ7xlaWy3iUXiBcN/cWzwKzIafnMG+SHclyXWn7Gd0WWtZ6gWCid9p9dM9Kl4sdD0UjkWA/n68UF7dRYzn9A3Fyl6m1n+52jVqek3WJGLtwZ1s42X+vuao= 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=UNJOwmxP; 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=1lbo0bNxrPdMIVRoJ6+tExY5TotubsDpMSLovzCGBGc=; b=UNJOwmxP6SKaJHQteJMQXUg+aR cCHpnKJDZ0yrSHVtUimpaLVKz1b1YkOf1HEf3glrA4uAfilvXM/bDry0FLbt+uyzInqPU/+ESPYUo DW8A3zwdFhz2gsYKxYimBFHlx63q0Wx2FbSyHpr17HYUwBEAW4NbynDcRe1UO1Yn6PdxD1sSd8TWK du7v2kV55sc3Ql8W5zO76xJVk4QpkGfJH4A2rFxaOLt1tcUiPcuhQDaPph2MatY/1HpSn3HReY0aX eezoUcJVjB6Oii1HxHPK0d8uWt63hTU7U6LSgLaskDI80j69xb5k/3gamglF01pMiorcH1gPRh53Z UFsFN0/w==; 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 1s8n5e-008wIn-03; Sun, 19 May 2024 15:25:06 -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 v5 16/28] selftests: ntsync: Add some tests for NTSYNC_IOC_WAIT_ANY. Date: Sun, 19 May 2024 15:24:42 -0500 Message-ID: <20240519202454.1192826-17-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240519202454.1192826-1-zfigura@codeweavers.com> References: <20240519202454.1192826-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_ANY, when objects are considered signaled or not signaled, and how they are affected by a successful wait. Signed-off-by: Elizabeth Figura --- .../testing/selftests/drivers/ntsync/ntsync.c | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 7cd0f40594fd..40ad8cbd3138 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -342,4 +342,123 @@ TEST(mutex_state) close(fd); } +TEST(test_wait_any) +{ + int objs[NTSYNC_MAX_WAIT_COUNT + 1], fd, ret; + struct ntsync_mutex_args mutex_args = {0}; + struct ntsync_sem_args sem_args = {0}; + __u32 owner, index, count, i; + struct timespec timeout; + + clock_gettime(CLOCK_MONOTONIC, &timeout); + + 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_any(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, 0, 0); + + ret = wait_any(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, 0, 0); + + ret = wait_any(fd, 2, objs, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, index); + check_sem_state(sem_args.sem, 0, 3); + check_mutex_state(mutex_args.mutex, 1, 123); + + count = 1; + ret = post_sem(sem_args.sem, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, count); + + ret = wait_any(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, 1, 123); + + ret = wait_any(fd, 2, objs, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, index); + check_sem_state(sem_args.sem, 0, 3); + check_mutex_state(mutex_args.mutex, 2, 123); + + ret = wait_any(fd, 2, objs, 456, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + + owner = 123; + ret = ioctl(mutex_args.mutex, NTSYNC_IOC_MUTEX_KILL, &owner); + EXPECT_EQ(0, ret); + + ret = wait_any(fd, 2, objs, 456, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EOWNERDEAD, errno); + EXPECT_EQ(1, index); + + ret = wait_any(fd, 2, objs, 456, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, index); + + /* test waiting on the same object twice */ + count = 2; + ret = post_sem(sem_args.sem, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, count); + + objs[0] = objs[1] = sem_args.sem; + ret = wait_any(fd, 2, objs, 456, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_sem_state(sem_args.sem, 1, 3); + + ret = wait_any(fd, 0, NULL, 456, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + + for (i = 0; i < NTSYNC_MAX_WAIT_COUNT + 1; ++i) + objs[i] = sem_args.sem; + + ret = wait_any(fd, NTSYNC_MAX_WAIT_COUNT, objs, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + + ret = wait_any(fd, NTSYNC_MAX_WAIT_COUNT + 1, objs, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EINVAL, errno); + + ret = wait_any(fd, -1, 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