From patchwork Mon Feb 19 22:38:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 203311 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp77111dyc; Mon, 19 Feb 2024 14:47:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVhH0afzpITXkkQGJwR+ydZ+2li1Q98aw4sJxJr9DIoP7Xq9q5GFZGc9kYs8m0Hl7F7poP4T35TdLQ+XxUh5HkcIpNnvA== X-Google-Smtp-Source: AGHT+IGJIjbvfscNONtC30aFjqUKIVWyiZT5Y3Io0TGOfo3fmSg/LpYRJIvNJGeRalZj59sgkPHG X-Received: by 2002:a17:90b:305:b0:299:1802:4c54 with SMTP id ay5-20020a17090b030500b0029918024c54mr16538951pjb.16.1708382851140; Mon, 19 Feb 2024 14:47:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708382851; cv=pass; d=google.com; s=arc-20160816; b=GjpL14bVVSaD52d9gq4wQ4kkkqtjSLAmPGRa8CT9UOfjTSG2R1uAvknuWzmAOpCtgW VucLT26bZTTEP3CouXcRszRQm/psRdwUIp2pc2R1l2zFhg/xdYqXmm815phxf0td8Cb8 H6iGgK6cE/JvIbhqiRrMPpVwpk70OMjEiFMm20c1ikQ26WcZwMMrakwu8gXJPILzPd3W fWVTdBCbc8Baisd32DWUFYlLxNQCzL5Wf9R9K2vS2u81wP/wMy9wu1HT5Bil4oUMfr+3 s++uAFrUsHDsXYdeb9RjGjc9ZJy02U+rs3ivu5LRb+HW8oiY0ODHgOQinDbF9hNPUUvp uKDg== 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=Y95uioGAPMdZZ0cAwPbXEkD4hHbWG+8pblZmeRY+GjA=; fh=hR3Xqo6s6FufP5gEw1XgbtLHrluZu7hd5XGp+hLIfiM=; b=KJaq9vWkTfXlkrI6La0YA1X3n9ps1uI8mDHmtU2z5oWShJ6CuVYMl15+DPm611Ogv1 wELb/m9CNNMdDOdR+j9DIo+M466srMhtMVST3HWzrnWsoAyzm89iAGmNc4JWpSnVO7Yc Mn2xopKzNNAvP1/2q/JLRd1Igg+uezCARmzeo0ThEgSJllg9Cd9ghvsFCuLk4z8mEjNM vxRFAHvakvD07Iz+NEAiSxgsna6xs46nZ1mHqWqstKw0bsfoUbxFohU1BznhU6StJ0HN ipzXosUlr9BjNYXNUS2QU0SyUzXs41tvBljy2WINbnQBUlrJtZVYlvEPXGlmMLx1U4x6 1rWA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=PFjbysXD; 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-72096-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72096-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 z15-20020a17090abd8f00b0029897526522si5165561pjr.103.2024.02.19.14.47.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 14:47:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72096-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=PFjbysXD; 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-72096-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72096-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 F253128A44B for ; Mon, 19 Feb 2024 22:47:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8E62679E5; Mon, 19 Feb 2024 22:39:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="PFjbysXD" 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 3A42B56774; Mon, 19 Feb 2024 22:39:38 +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=1708382381; cv=none; b=c52F/c3Q0M/IGcxoF/sumZ1SjDOZ9s9zefq9QLpNzu4o+47VkStUJR2INA9sIw+o278PYyfkGjdVvaBdiXedXgh57AXB27mniKCA4ZXaN2/3f6faznNaNH86HD9RE5de/XEVdPHhKw6e6m7OAeeveSeDvsEmEg4NyW4n/H5nX6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708382381; c=relaxed/simple; bh=L8d9LKUtIlHbbP7cxUNXa7f8ALBrZ7EKpjsLi7r052M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nJidxJYSQag4ZXU1JFaGdeS7j4GiSffGxGfgYID14YVDDUCbT590cn05B82jG2sAHVmgNeEeUP/scd8eQGIXf5laHJ9APBFYtT9zhx4oVz2gWthWcXGcxNCmonUEIgEfK4pB/o0Yh9AyL21fuDZ+7UTMFV1M7XSOoCbfcXc1+9E= 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=PFjbysXD; 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=Y95uioGAPMdZZ0cAwPbXEkD4hHbWG+8pblZmeRY+GjA=; b=PFjbysXDP3Sh5p/o7yi0bgUjsT 1RPZfHZV7+Qqg/X4YPek7i5/IcapvYKOMHsE3fU6ddZ938DmiVnOCd6hKCeQTdeQjveqJoEwncnRH gTv5pdDrCI18aXO+nRlUYBDJZoivDYWAo3gQ3TM3RPZv4/4uot76bIOuqWecdL5C0e1zsb9wWynwS G8J/pHmHMcs5pTP+67Wm06KND/Cv9f3ZOM67NGV1ZKfOtiLuaK+0z7jClIhhD4Dj7D3sIjbNGmy+L ocN7CVCTxzowEy2QNvccR3QiyHjfMcIBhOy06Qbb4uZmFSe1n3ZkK2UGgz3lhHG6CeisPoEaEJ1ZC 4IHCZehg==; 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 1rcCIR-0037Oz-3B; Mon, 19 Feb 2024 16:39:36 -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, Randy Dunlap , Elizabeth Figura Subject: [PATCH v2 24/31] selftests: ntsync: Add some tests for manual-reset event state. Date: Mon, 19 Feb 2024 16:38:26 -0600 Message-ID: <20240219223833.95710-25-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240219223833.95710-1-zfigura@codeweavers.com> References: <20240219223833.95710-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: 1791369256737602150 X-GMAIL-MSGID: 1791369256737602150 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 b77fb0b2c4b1..b6481c2b85cc 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) { @@ -353,6 +374,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) { int objs[NTSYNC_MAX_WAIT_COUNT + 1], fd, ret;