From patchwork Wed Jan 31 02:13:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 194454 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1628752dyb; Tue, 30 Jan 2024 18:28:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IG1OBgbWZEaVIxlX7F6+I4A1JqRsLhWU0nRlvCzSuMi4hkTpdDS119r4AiU2D3p9dpJq/jP X-Received: by 2002:a54:4092:0:b0:3be:ab0e:733 with SMTP id i18-20020a544092000000b003beab0e0733mr465483oii.13.1706668103656; Tue, 30 Jan 2024 18:28:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706668103; cv=pass; d=google.com; s=arc-20160816; b=imHYQtq6oR+2s9sXFv2fWqINU8dpaZBs+17pG26jwNUcxz7sSv4QlVXEJ0wfOgPsSn YkGKqV/a9+Ihwzfy1Cuzoc4eeeCHdmxV6rHLY3k17RFgYtNI2qBNk5BPUdNlGsxQ86WX 7HHxBZxO1ExGA4PXLSdsm9EdCE4juIrHgiMZiPObpCfHA0hkJnRMcBa8DaTxHyyENuJF 7+1LYeWPIN08dox99OYUjROGkv8WerWbiF2htlN+Nz7q8vNlresE8dwpUKpp9AYFWw1q Pix1GJ05uJ161ZYDbHr6Bc3rh2VDOr77SvxKZHMKF3VEpNDJmQ54P6cZy0OlviUMsD42 5lDg== 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=9a/wMnBLv1xoxspXfxOrW3hEE0JYusn2W8rgrXnFegU=; fh=wqgAhUDHbOcaB+z3edFPpGq8PIk2UfjBVfTdTocLxW0=; b=EB0tkuLA8awbx805/vQgrFh6fp3BSAkFVrlH7PyPpNlZH2IqOB48nIsgmtkStFqZce Cljv69XLhHXbOUZcuG1zAzP4npLMfWqDWtZxFfNtXUzR27gVU1eTQnhz6GjtSMiIm2fu kTz8S2pktqGA2YCFhlcMGx93c3vhO3XmJtPrtKOnaL0c5/NbH0vg9VVKA2FzhcICVo20 PESes0+nooKeSaS1T/C2AdpE3apyUCL2I/MAszmm16u/NgsV8tCiMGaa/HaNUHui+LTf ezJagYizp/ijKvTHuK9ZWNAMonYcxpXxQrXu/hLxEzfgr08OJxO+tizzDMfa9J9jEkAD jPtQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=gAx8v05d; 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-45649-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45649-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com X-Forwarded-Encrypted: i=1; AJvYcCUQUq++KNCjETTrFJAjYFyZ52fvjIwKU79CMzeV3QuZ8i8cFnIs4d71WXK9QMIIK/T9mSuNmbCO00f/vvLUqMxRB0e/ew== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id cm8-20020a056a020a0800b005cdfbd1d0e1si8689950pgb.129.2024.01.30.18.28.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:28:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45649-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=gAx8v05d; 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-45649-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45649-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 521BAB26DBB for ; Wed, 31 Jan 2024 02:23:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BFBC3D96D; Wed, 31 Jan 2024 02:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="gAx8v05d" 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 59F2063C7; Wed, 31 Jan 2024 02:16:06 +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=1706667368; cv=none; b=tzdUlIZd6k02zwRo1aryb21tLzGNqGgsoyD5RvZ7wn1FLbp3DTpWhhXXzl9J9GVaWgpMAyrL9vq9Mlq4EVVcLUKikOMUBlRRS4oLw//r74xXG+G9oU020uFFTwWaYeZKq0FxvUrOKFKOOgBHnXl2wR0JiI9eSNQ484s+OCFzZsA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667368; c=relaxed/simple; bh=31Rr5cIrKWA5Jh3ekx9HXSxmqlSxR8yZglxBVPVOJoI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V42ObxV9Cr8kIsV4A7Y8zth0WqxIvs8UGzA8IIrOgNL8JOBW7SJZAY1M6kLjpG9E3Jx0Cp5bmQqToQeeICnltwM8MSO5Fy3lin7BAj2ZIU/yQSKIMtZUBmYfMqp5Q7Vohph2e0Ah3uY5nsImZKu9KN4uFU0uLtWdpcZWMVfXnVM= 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=gAx8v05d; 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=9a/wMnBLv1xoxspXfxOrW3hEE0JYusn2W8rgrXnFegU=; b=gAx8v05dK5R5gEbKhG0F9I9T1o xfnYmZ4w1atOmAQdpD9Rc8pwxpgVFZ9r4KpsKRZD8j7RqjlqGKQ+EmwDxV+0/stfgWITBsjVfMpl6 GTC0f22zZhPch9VELfqE8hKJ6ypkRSSBkAdhBsDmKZnlkxSr0bNVjlvwT2Eq0/l2RTWO8YBHvlNAA nnhmVIZ4l1m62Y6Voeh7HJXlw+K5+WpQeNweQ6eQPjR2YCsGRF13EgV+PKssduXKyRJlmvKAYKIwb h350mEFbPZD9U/zfUoX7W+QTv04/v7Z0pUafk1oOfDYsAJerbD8G2SPaP9ljLfbV+8FpWxeef0rbq LOHInviw==; 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 1rV08r-0038Kv-1n; Tue, 30 Jan 2024 20:15:57 -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 26/29] selftests: ntsync: Add tests for alertable waits. Date: Tue, 30 Jan 2024 20:13:53 -0600 Message-ID: <20240131021356.10322-27-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: 1789571213320592742 X-GMAIL-MSGID: 1789571213320592742 Test the "alert" functionality of NTSYNC_IOC_WAIT_ALL and NTSYNC_IOC_WAIT_ANY, when a wait is woken with an alert and when it is woken by an object. Signed-off-by: Elizabeth Figura --- .../testing/selftests/drivers/ntsync/ntsync.c | 179 +++++++++++++++++- 1 file changed, 176 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 598333df3e6d..6c00a55909aa 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -95,7 +95,7 @@ static int read_event_state(int event, __u32 *signaled, __u32 *manual) }) static int wait_objs(int fd, unsigned long request, __u32 count, - const int *objs, __u32 owner, __u32 *index) + const int *objs, __u32 owner, int alert, __u32 *index) { struct ntsync_wait_args args = {0}; struct timespec timeout; @@ -108,6 +108,7 @@ static int wait_objs(int fd, unsigned long request, __u32 count, args.objs = (uintptr_t)objs; args.owner = owner; args.index = 0xdeadbeef; + args.alert = alert; ret = ioctl(fd, request, &args); *index = args.index; return ret; @@ -115,12 +116,26 @@ static int wait_objs(int fd, unsigned long request, __u32 count, static int wait_any(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) { - return wait_objs(fd, NTSYNC_IOC_WAIT_ANY, count, objs, owner, index); + return wait_objs(fd, NTSYNC_IOC_WAIT_ANY, count, objs, owner, 0, index); } static int wait_all(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) { - return wait_objs(fd, NTSYNC_IOC_WAIT_ALL, count, objs, owner, index); + return wait_objs(fd, NTSYNC_IOC_WAIT_ALL, count, objs, owner, 0, index); +} + +static int wait_any_alert(int fd, __u32 count, const int *objs, + __u32 owner, int alert, __u32 *index) +{ + return wait_objs(fd, NTSYNC_IOC_WAIT_ANY, + count, objs, owner, alert, index); +} + +static int wait_all_alert(int fd, __u32 count, const int *objs, + __u32 owner, int alert, __u32 *index) +{ + return wait_objs(fd, NTSYNC_IOC_WAIT_ALL, + count, objs, owner, alert, index); } TEST(semaphore_state) @@ -1062,4 +1077,162 @@ TEST(wake_all) close(fd); } +TEST(alert_any) +{ + struct ntsync_event_args event_args = {0}; + struct ntsync_sem_args sem_args = {0}; + __u32 index, count, signaled; + int objs[2], fd, ret; + + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); + ASSERT_LE(0, fd); + + sem_args.count = 0; + sem_args.max = 2; + sem_args.sem = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, sem_args.sem); + objs[0] = sem_args.sem; + + sem_args.count = 1; + sem_args.max = 2; + sem_args.sem = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, sem_args.sem); + objs[1] = sem_args.sem; + + event_args.manual = true; + event_args.signaled = true; + ret = ioctl(fd, NTSYNC_IOC_CREATE_EVENT, &event_args); + EXPECT_EQ(0, ret); + + ret = wait_any_alert(fd, 0, NULL, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + + ret = ioctl(event_args.event, NTSYNC_IOC_EVENT_RESET, &signaled); + EXPECT_EQ(0, ret); + + ret = wait_any_alert(fd, 0, NULL, 123, event_args.event, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + + ret = ioctl(event_args.event, NTSYNC_IOC_EVENT_SET, &signaled); + EXPECT_EQ(0, ret); + + ret = wait_any_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, index); + + ret = wait_any_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(2, index); + + close(event_args.event); + + /* test with an auto-reset event */ + + event_args.manual = false; + event_args.signaled = true; + ret = ioctl(fd, NTSYNC_IOC_CREATE_EVENT, &event_args); + EXPECT_EQ(0, ret); + + count = 1; + ret = post_sem(objs[0], &count); + EXPECT_EQ(0, ret); + + ret = wait_any_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + + ret = wait_any_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(2, index); + + ret = wait_any_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + + close(event_args.event); + + close(objs[0]); + close(objs[1]); + + close(fd); +} + +TEST(alert_all) +{ + struct ntsync_event_args event_args = {0}; + struct ntsync_sem_args sem_args = {0}; + __u32 index, count, signaled; + int objs[2], fd, ret; + + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); + ASSERT_LE(0, fd); + + sem_args.count = 2; + sem_args.max = 2; + sem_args.sem = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, sem_args.sem); + objs[0] = sem_args.sem; + + sem_args.count = 1; + sem_args.max = 2; + sem_args.sem = 0xdeadbeef; + ret = ioctl(fd, NTSYNC_IOC_CREATE_SEM, &sem_args); + EXPECT_EQ(0, ret); + EXPECT_NE(0xdeadbeef, sem_args.sem); + objs[1] = sem_args.sem; + + event_args.manual = true; + event_args.signaled = true; + ret = ioctl(fd, NTSYNC_IOC_CREATE_EVENT, &event_args); + EXPECT_EQ(0, ret); + + ret = wait_all_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + + ret = wait_all_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(2, index); + + close(event_args.event); + + /* test with an auto-reset event */ + + event_args.manual = false; + event_args.signaled = true; + ret = ioctl(fd, NTSYNC_IOC_CREATE_EVENT, &event_args); + EXPECT_EQ(0, ret); + + count = 2; + ret = post_sem(objs[1], &count); + EXPECT_EQ(0, ret); + + ret = wait_all_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + + ret = wait_all_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(2, index); + + ret = wait_all_alert(fd, 2, objs, 123, event_args.event, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + + close(event_args.event); + + close(objs[0]); + close(objs[1]); + + close(fd); +} + TEST_HARNESS_MAIN