From patchwork Wed Jan 31 02:13:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194459 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1629638dyb; Tue, 30 Jan 2024 18:31:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IH3hYz24xqYYesZrRkxWHjDZ3RFlqTNGY9h0SIHJFYk4+4YEmV8nupTVTNJG1e4qOC88jfs X-Received: by 2002:a05:6214:c44:b0:685:67e0:1e13 with SMTP id r4-20020a0562140c4400b0068567e01e13mr365708qvj.18.1706668265376; Tue, 30 Jan 2024 18:31:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706668265; cv=pass; d=google.com; s=arc-20160816; b=i8VcwVGVlpd7LyNbJJRxA6y7Tvrk11wMULKlIhXx/Xd4hDfuDiEGeqyDra48UtIK8G 2k/Ha/+sNAHv28Ubb0+8nBnoplVDnOtegjeS458PjQ9C/gw2H0NVt3xMRXCH0nVMR2Z4 1A7epWuHxdivVobAqMguF2KQxAUkyplIb1IlzKQM5A139hZYR5ot71w88HOq9qSXuHWl 7vrxznLbjj/OLXaJa1rn9X9jIYtPIq5d6lo80uyd0eu+WNy2b88e4iLYlSYY+yHjWUMW FMWop8D48x9nGNUc2r/5sgUsAsGJ+nzkT++MtR7+7DBdcn7nQ4cV3jbs19hxiIe3zvXb sE1w== 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=zBFsoSMdTXq6ZUjgrCY1qmpBczS13zgM2yQLxywo0xI=; fh=9c0jTnVtO/cRfgOIw4vanxTUv5R46FyCwZ7yxmvt5Mk=; b=iIWgyd3j3ul8sTMJkHWJcRj0eUyyCkKHXEx3sKa7Me+WQiSk3NDmDzfRLo6hd4VB5N PAbboOvXz73o+4GPNWsG/YmiJ7sjSLiTEoFhqdzDsIS7nJ4FBKrZ55fN/p8RVDT+VFRX d9ddG8sLs1riGhBq3TY8Xe3OzE829LznZYnxwYCMcu8E0oZCg1EffrWeb/jmMfM7tGwY nBLCSLSxsqA4BUc4PySwuLMd4hXYhuNUYz0dTqA5dgxTIQjchSfOVkoSrJn/X6TqCFpR PScKX8rzCnoUgePBUf1bAND3e8O7rTYoESczRwExEVP2EZcrLUiKqWebYPNaU0mswEOL G8jg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=CISuoKe3; 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-45641-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45641-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCXSgwC7mbV2AQGMpaLej8VM9oYzIkDavEcTs9la2JVpthkcB0WOwjwXSWZ+4mBWXTLW7fnWk95bM5FP1voWxIzbq6zkHQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u12-20020a05620a454c00b0078534dc432bsi1881130qkp.369.2024.01.30.18.31.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:31:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45641-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=CISuoKe3; 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-45641-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45641-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id DE1A91C20FAE for ; Wed, 31 Jan 2024 02:20:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A2C03A267; 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="CISuoKe3" 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 968D75697; 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=RdYjpE7eTsthSVnnfwrZIUemPO1+uYrXed461UID2EaAvrMBQA544ABn2h3xsidaylX92XvfhZczYVm12Yxb2kRpOyLEQJKBbZnjBGDgYSDvEOx+UqgP0+kftcpTeipKgXgPSk20owTtcTJmOIqvYYDc01Q/QkME0t0/Yw0hz0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667367; c=relaxed/simple; bh=VlAa0x53Zal9SGTSmO7FlNYompGdzB0uV0PrcJepaC4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uGRTK3BRH/XQ6/q6nWE7gc2fDyCIrJ6CLNIt4zTc+2I5QAqjW6Cj06H7cF7oMX+HpK92l+3dp9uIpXMCPDvFDq3tci9Hy22kHrnTNu66sSr4rj0YDEg17Eos5ssE/NLnEq3ZZi+KhogSBhpHLBqhxEJ7s8Y1dbcH4iAL8Famktg= 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=CISuoKe3; 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=zBFsoSMdTXq6ZUjgrCY1qmpBczS13zgM2yQLxywo0xI=; b=CISuoKe3oAl92A2fJOaI8g2P9W AsSdfvikPC8ln2q0is0/4rWRnmbXDFiNmxXAfCfIJaxqE4B+uWla1BTuKi4xwCmIl3CP3Fir3EQg4 1D1i2lQbJNH+2fqqNyKaVJ3aVpHnXxBLyCaaJXfriRMUEJFbxgClGb4lWSlvbIzZS/lh1PZPsZ3uR c7XM9c9brHJG4OOdxaR7F4LBLiFaMBFpWdzvea7yVLp9LiDjvT0P0A69jwvJeLN64v4zO4g/Zd/NX rqMqUlDfkaHGUuX1QA3QqXDW7vVIQ0lMRFZiCESbFpqujktHBEox3dMd1UvY4qJSLSda4c8oWwmJ5 JmYYNuTQ==; 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 1rV08q-0038Kv-0s; Tue, 30 Jan 2024 20:15:56 -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 23/29] selftests: ntsync: Add some tests for manual-reset event state. Date: Tue, 30 Jan 2024 20:13:50 -0600 Message-ID: <20240131021356.10322-24-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: 1789571382685103290 X-GMAIL-MSGID: 1789571382685103290 Test event-specific ioctls NTSYNC_IOC_EVENT_SET, NTSYNC_IOC_EVENT_RESET, NTSYNC_IOC_EVENT_PULSE, NTSYNC_IOC_EVENT_READ for manual-reset events, and waiting on manual-reset events. Signed-off-by: Elizabeth Figura --- .../testing/selftests/drivers/ntsync/ntsync.c | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 7776fe71b8ef..98fc70a9a58b 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -73,6 +73,27 @@ static int unlock_mutex(int mutex, __u32 owner, __u32 *count) return ret; } +static int read_event_state(int event, __u32 *signaled, __u32 *manual) +{ + struct ntsync_event_args args; + int ret; + + memset(&args, 0xcc, sizeof(args)); + ret = ioctl(event, NTSYNC_IOC_EVENT_READ, &args); + *signaled = args.signaled; + *manual = args.manual; + return ret; +} + +#define check_event_state(event, signaled, manual) \ + ({ \ + __u32 __signaled, __manual; \ + int ret = read_event_state((event), &__signaled, &__manual); \ + EXPECT_EQ(0, ret); \ + EXPECT_EQ((signaled), __signaled); \ + EXPECT_EQ((manual), __manual); \ + }) + static int wait_objs(int fd, unsigned long request, __u32 count, const int *objs, __u32 owner, __u32 *index) { @@ -332,6 +353,74 @@ TEST(mutex_state) close(fd); } +TEST(manual_event_state) +{ + struct ntsync_event_args event_args; + __u32 index, signaled; + int fd, event, ret; + + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); + ASSERT_LE(0, fd); + + event_args.manual = 1; + event_args.signaled = 0; + event_args.event = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_EVENT, &event_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, event_args.event); + event = event_args.event; + check_event_state(event, 0, 1); + + signaled = 0xdeadbeef; + ret = ioctl(event, NTSYNC_IOC_EVENT_SET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, signaled); + check_event_state(event, 1, 1); + + ret = ioctl(event, NTSYNC_IOC_EVENT_SET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, signaled); + check_event_state(event, 1, 1); + + ret = wait_any(fd, 1, &event, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_event_state(event, 1, 1); + + signaled = 0xdeadbeef; + ret = ioctl(event, NTSYNC_IOC_EVENT_RESET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, signaled); + check_event_state(event, 0, 1); + + ret = ioctl(event, NTSYNC_IOC_EVENT_RESET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, signaled); + check_event_state(event, 0, 1); + + ret = wait_any(fd, 1, &event, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + + ret = ioctl(event, NTSYNC_IOC_EVENT_SET, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, signaled); + + ret = ioctl(event, NTSYNC_IOC_EVENT_PULSE, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, signaled); + check_event_state(event, 0, 1); + + ret = ioctl(event, NTSYNC_IOC_EVENT_PULSE, &signaled); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, signaled); + check_event_state(event, 0, 1); + + close(event); + + close(fd); +} + TEST(test_wait_any) { struct ntsync_mutex_args mutex_args = {0};