From patchwork Wed Jan 31 02:13:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194434 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1625802dyb; Tue, 30 Jan 2024 18:18:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEe/A+RAN4S2eTbPoN2eYevk3TV8JEYq26SfM/Pd964ztGtfOTpY9T0LAyTaQhsa4wFdrUJ X-Received: by 2002:a17:903:2444:b0:1d9:1e9d:475b with SMTP id l4-20020a170903244400b001d91e9d475bmr403255pls.29.1706667526406; Tue, 30 Jan 2024 18:18:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706667526; cv=pass; d=google.com; s=arc-20160816; b=B9mmZA7HKNzTLMpB4o6QVZfC+5qlu2zUccRr9iX+/f3EyTtvvmsdtXg4kiRajA0d+u HG2L/xXsiK9StvQoiIn7K60rGdZIJGV68nv4pJAoBoeUHmxQ/4oW+5ysS2uW+JWhHCP9 eWf3v7nnGeiYUJnwr190gnEazc41IfvXoI2sPTeX41BdHnCSoK9/BS3xwgoQ0pRAubMm yGfnFbT/cJEVd+oADSNdaOsMNEpwyMktrnjP1WIPjN/mJzvBHURdiqGdtgO07T1wqeE8 /EJEBesFdoCB5Gy87wC9TbBxOGl8iy/MCafOzLQXlIGwQ3TzsYxZSFzf3d5t4tZlAF7R nJjg== 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=sQXEg3DfXuCk/ElwByxgMxoggv1uEylDwgBCMnuymGs=; fh=chKNPeTEniZEV3beQsdttoKWsVa1vulqorznAtyiiEs=; b=cU1g1TMGhkM4eabdoHI5revcvC2bWNL8zwBSAdBl7LHhWti2IXMX+JMW2ihCCHCaAa EU2BR/EPxez1yIBzNdLL3zfCjPAgtsLjtaEQdqm7nrpgjin25YE6vPSVGP0QTjzeS0TM /VO8O+Ph9plcRP+lHpIjIQ5AmB2SpDFSJqKsTUx3iQa8FfXp97fNDHE8oB0h2E9Gdacm /3aDpXadPPI3paomPoWsfTs/9XyQQRNDASnzV5NlqtumS/TD4iJ2yV8GgY3LyWu9TJjQ gbNbkCCrhZanGyGWkVRC2to/jeZS17ajlf69YvcWGcZZDgauu9ZIEaDywbWCN5xIrvqu vIPQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=QjUiZI3G; 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-45632-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45632-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCXQiXMslaWkmMsLJkVmxVqYerp/EBuRCIGRHTCPrOvWlRToK568real6YzYiJX1jEMA7eM4WekJrJsV55Qlo9+HW5zzIg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q11-20020a170902c74b00b001d903a572edsi2409645plq.606.2024.01.30.18.18.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:18:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45632-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=QjUiZI3G; 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-45632-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45632-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 11C1F28A996 for ; Wed, 31 Jan 2024 02:18:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A793383BC; 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="QjUiZI3G" 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 96166525E; 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=i4ADqNv9Bc8Aa9rAh6Ewj5V1fMeRCEBxU+qpqjburWSmOkssfs0U4odFuyZd9isqjRZuHv7oLj7y0y8nRIaBp8oflgxPA0dX+ZeT379BsD+e3vy2KQbnEdJJGagRwKPXLpi8ZF8DiYB85tYKocuEyukxNyKgkpHRBooQK8yvkGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667366; c=relaxed/simple; bh=VwCLdmCiIAKcgrkmlaOeFhsqBt6LmACQWA252aGh+/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cj1EUyEu1yeJnoFMW6E1jmdzPBc4NO52aRiDLBUeSJ4FJ8fdAQMv+YOAigS9JiUHNWfXcbKGvNWoWt69gZ7m1ZoE7dfHqsAdgDlzDYJdb0qsecjbnVIbzJugArn62rJ7vI5ywdJxJD4cgbQsOylBZSv2cNu1cXi2Q/vdjz3Ycdo= 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=QjUiZI3G; 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=sQXEg3DfXuCk/ElwByxgMxoggv1uEylDwgBCMnuymGs=; b=QjUiZI3GGisZZs3nkZEFrWfAqV td1GHtwvnZjumHcecpgEfcIFsGYHm7+5QekNC30z3mOOuNrSAijZSknQD9MRopFXl+L7sBaSggcRH KqT4odVJSTQnWRhQYIFdNpPdVED6kuI6IdQDCpE2YTwjHlNz4BKJYSutfHhvrXr31yNrPhfhRDN4K kwBmdB4ltjlUiXpipGtT/MosREgg1Vf8uSvzAjseUD2bT3gBp58ph7f/67FWrQCfbUPgOlzDmEALF D960gJBQcpvVyyBvnmri4gwdQzb/dmbT44k1kQYaG6TkH7QLTsNZR5IHucN3qc6miyKiR3ByuyS0N b37jVAJQ==; 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-2E; 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 19/29] selftests: ntsync: Add some tests for NTSYNC_IOC_WAIT_ANY. Date: Tue, 30 Jan 2024 20:13:46 -0600 Message-ID: <20240131021356.10322-20-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: 1789570607956593192 X-GMAIL-MSGID: 1789570607956593192 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 | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 80c8bd409d68..13e7c9d7441e 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -321,4 +321,109 @@ TEST(mutex_state) close(fd); } +TEST(test_wait_any) +{ + struct ntsync_mutex_args mutex_args = {0}; + struct ntsync_wait_args wait_args = {0}; + struct ntsync_sem_args sem_args = {0}; + __u32 owner, index, count; + struct timespec timeout; + int objs[2], fd, ret; + + 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, wait_args.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); + + close(sem_args.sem); + close(mutex_args.mutex); + + close(fd); +} + TEST_HARNESS_MAIN