From patchwork Wed Feb 14 23:52:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 201198 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp63347dyb; Wed, 14 Feb 2024 16:00:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWcVLsWLv8zcrp0624dy4WppOuuBAa8kJl5VWuIQU46M7a7TOYAQbZL9N4wr3X1EUfixNWFJqizq7fgpgivlDjFyhmKGQ== X-Google-Smtp-Source: AGHT+IEIgEVdZ6sWI5AtsY4ReM1i/t1Se9f7In69UyZM0sT1Lbv2+CtSD0GWEzrsES+75jPvt6TT X-Received: by 2002:a05:6102:161f:b0:46d:3a99:7f0 with SMTP id cu31-20020a056102161f00b0046d3a9907f0mr536009vsb.2.1707955259295; Wed, 14 Feb 2024 16:00:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707955259; cv=pass; d=google.com; s=arc-20160816; b=lQGnz0kgEZUe41mRZ44hTQw7KZEkf/uCgPMCH6DLd/ye3jvHPb51bnKjhbeHV7KeOV bGQX8cVdM5kny4tiH83Nfne4xFyRrhUKbn3vpVJCN6xOQ59QfA7v09EO9HTMtlbZjdPg H/U/Y/is1IbRJBFNBPTbyxUURje9YljgMxScr3z4SVAByZh4KQpcGPiZaVa1CTYFEk49 120/ydxs591QKl+La9WZYTvgjv6RAeu3/jngwwJmxHIUFrH53N6bf7Xh0LMawIk0nx2N LPJQGGngoei1p5w2W9RnzSaNIId1B3JFVFYR+sEWtU7k5zpKnpyN1xyzjzlXbh1ShIgC Ae6w== 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=4TsUlLJY8QFZnk/5/kjEI+hyqZYDUecMdBE08/85OkY=; fh=sOAzP1IXJnllEbSCBRlwdfT0MN3UiaRLwzx1Tpw7GJA=; b=u7gjwRswYIjQnJcvf5/mMIFEyt0SUq17M9aDXfE+ooxXYAJEhxDrdAASQ+Vk6H/tGo VMQzbSaXVAtlDWSJ4/dcc2H3C0eXvrrZTGnFxlllSpHqY1hAW2B+jP0YwQxE91Ya28Cr dItTAjZwcfgrs4rWU1diR8vIrNwGI4qmWx0XPvqrmstsUEEjXaQz5YfWWpS2zRK4GpSX JKIydM/M62d8VW3+vVwAAc/XvnBX9w/RfF4O7E3oX3pH9qNSvj/RYa2Rpsos6vnA+/oh ptE/yWFO2oOZNaXWykcGEWL4GqhSX2zfji7Q5HRbqqGnHLExovHxbaD4iStrTR5WAX3Y 7XxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=P5U48B93; 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-66159-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66159-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b7-20020ac85bc7000000b0042c7659583dsi115970qtb.690.2024.02.14.16.00.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 16:00:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66159-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=P5U48B93; 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-66159-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66159-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 C6C0D1C20EDC for ; Thu, 15 Feb 2024 00:00:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E238F14E2F2; Wed, 14 Feb 2024 23:53:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="P5U48B93" 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 4D29214C58C; Wed, 14 Feb 2024 23:53:47 +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=1707954828; cv=none; b=PVuOmevxPTM3Oad+PO61YQeTm0ijNLQ8YN/JOavC/km6sNie8AOJX6l87TUIDvHQ6YVNTSYisY2s/eB7c0OAP+lF4QNuVzL3/f77e/ytCGVaIA9nz9pQdEKUafzkSv9qBwEwaWN05OxEa05N4TajO7Im92lhMQluHOlJ8lRJG1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707954828; c=relaxed/simple; bh=pFMFdKbGwK6565Qe46cPQeiQtHcHamkOetCQ7CUhyKg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ULQkQsIXtTvO6XgzBrP1ZhOOveYfDKDnjXCAQSwylGaKNTxeo2m0AEiZvj7NdmaBtjm7ufXyChk3GpuUjapS/OEoC+h68YXQ+vBJPIFfB11g4FHkramBUS/AVvOBPAJkzCDYCve4WQaQDjilqyYrnqJc7Br03Ra+OfI6j/7KhQ8= 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=P5U48B93; 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=4TsUlLJY8QFZnk/5/kjEI+hyqZYDUecMdBE08/85OkY=; b=P5U48B93FL9CbE1r1FdXS2+BYP rGlwcDMnLD8pKk7/kCUPI+y7pHPpL7+/TkcynSZB15cB3dOkTbaxwMIRn0nZul3xVBSZZYjGIKATr gR2TbMuH/7aaIjIPphNiBkoxN3JvvV/Yat1nkQuPzyKyrzKun0uqp9yZimmeabdaD/VZcgzleHvzf hngr9RrJPHk+XiX6Kv1CxDBItDQiP8O84RXkfRcxFaktwozyOuIIeSoHSs9A5VqSX9YCZ0a7Hlmmc 9prq6H1ywm32xOgnxTqd9FVH5+Aa6yQxdU9Steh0G53mmGAa5YN81eba3Er/0A2b90244jL7EzHC6 KHT8iQ6g==; 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 1raP4R-00GcSK-21; Wed, 14 Feb 2024 17:53:43 -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: [PATCH 24/31] selftests: ntsync: Add some tests for manual-reset event state. Date: Wed, 14 Feb 2024 17:52:59 -0600 Message-ID: <20240214235307.10494-15-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214235307.10494-1-zfigura@codeweavers.com> References: <20240214233645.9273-1-zfigura@codeweavers.com> <20240214235307.10494-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: 1790920893945174440 X-GMAIL-MSGID: 1790920893945174440 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 063c0ecb3bff..7cc6fdf10abd 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;