From patchwork Wed Feb 14 23:52:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 201194 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp62357dyb; Wed, 14 Feb 2024 15:58:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXXUhF5GrxNBD0wH18GWuYke2PDaH6pZUEG468p9mG3V+h9Zzos/gPED2X3XjI5u0T/iH0Bv6L6UO41C40iK7y5t7oO7Q== X-Google-Smtp-Source: AGHT+IFGTeji62VJF0lRVINUfKD7YJeW+Eqbq2IgZ3dTXZsxRFnquiDKhtZk/DwQi/ljmhohqyUq X-Received: by 2002:a2e:bb85:0:b0:2d1:1e3c:5739 with SMTP id y5-20020a2ebb85000000b002d11e3c5739mr150412lje.31.1707955138700; Wed, 14 Feb 2024 15:58:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707955138; cv=pass; d=google.com; s=arc-20160816; b=Nv5oFevj4e3capQsAqr9RmV1kYUh5YurlJpLfimMc0JrnX4qS4z8m9kcWNWGxEDOKc gUdgs7OASzQYVlKZ6UznWlinWyXhmcz6C2bnKSZ17xcnrQRDAb7U9z5aLopbvpDDqrwB pruAxxcT2hBJQWd5YuL/XwN9yOtRauFV8iXxtnNiWJgFM7Ugsa/igKqoCpWm0TsKNd1T h5nOv6g8izI+YO3qDsMO3NCXc0Y8ONml2RWJpNa9v/NJGXDedoi7/DAi44acwTcHcZ+w 0PLE0YWaX/MXsuY4ghvWXheIWa33XT10RniaGRl6E6oBsnInYNvXWxFkyNBxMM8Dk93y 7NNw== 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=fPM9rJ6H5CJlPqJO/3ILx/GOK2m21LbhltJ/pbLrjBs=; fh=sOAzP1IXJnllEbSCBRlwdfT0MN3UiaRLwzx1Tpw7GJA=; b=a6nvfqA+g6aCM6+3Ys+9Ya1gx7sWKzFi7ToZtuM60el5yu6Max5bHtPi2KcrVlIRyJ WwVMgkEmIbGQCAFX5CzAZeYXN79TMJbmhBoq+pCzAV2uVqiEv/EXXQgIqS2X7LpAIOku wvCYiEMcgGR5OUi1FlkXGxcklNrimO1LBUKXCO/pV5QjKlwDOaqjiM7Jy5h9LGBPxfXo rO9KIKrasni5LA9EXb/8fhZNZgaxTA1Ud1ei3NG5zGpoxhd81rmPhG2kFuoysjJhQodE eKJMhhHr6BuJEXXB9n57lEPb50ldDkXWddLe5agH18jEN7mn8yn3ZngQPm22Hc2OJA9P 6h6w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=eHkbK53b; 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-66155-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66155-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id r16-20020a056402035000b00560c8889cfcsi37766edw.280.2024.02.14.15.58.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 15:58:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66155-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=eHkbK53b; 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-66155-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66155-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4C9431F21F8C for ; Wed, 14 Feb 2024 23:58:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC1AF14C599; Wed, 14 Feb 2024 23:53:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="eHkbK53b" 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 7228214A4E6; Wed, 14 Feb 2024 23:53:43 +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=1707954825; cv=none; b=T18iONN/bCxeEpWcWsRm7BmuKpGdrK+57PYCbCkOCKVmu9/mxHEvFGEyaWwl054oe045ZM9/A6w5ueK8pr7+Y22VrECYxw4/mszdwxzKvx9l5KAN8+6P6vGGgb7NgJW367gh+hYGkEGUhwHOfiOigQ1us/NsB88BgG8C/7U3ydc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707954825; c=relaxed/simple; bh=ANwJeKeLnEe9JkXTHDo3w8k+yOqr+FnkS/Fgv9klwnE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tWTm0yjryOoATQdLI35q6OMky7QLM9HZBm4vDerIWqTupC5AdF21Tt8yp9G8PEffVH3AFM9WFzRJO1w2l6Vjnrv0+VIvCtV4ix++mQNLVGBJHE8E6p4vYy81BnpMjmiFeS/7elm0E+fz6hLg/WXeQiid9VpKkrLQ/2tuLXlSJec= 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=eHkbK53b; 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=fPM9rJ6H5CJlPqJO/3ILx/GOK2m21LbhltJ/pbLrjBs=; b=eHkbK53bvkzj69i1qZF8nMGNzb 9IsboKjr+2FZ9wiCyXFaggHIpTHgLO3slKzLhdQnMRPJeEVMn/KuhqHP/aWArcRYIekMK3C7aCoRb dpcEqWTB28dLJHS69qdgGwoyexSGEQGtDBNBqAG7+v7yUIoxRgjsrM81WfxzNTtUF/6WhqQzKOara Lh05FfMPf7Huplzh5Pd6TLYXqfppnoht5kNm7Pf2yQAtLlcNA+T78BWHqA0FyjjWQOJE/il/4w+BD 4oSlkZ7MBPLSAkZk6RaGNRS2HR5uZuFHr9bBieOI/Bg37SHBYN9NREBshyPHf7A8kAiKSyLe0QVMC od0VvggA==; 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 1raP4L-00GcSK-1T; Wed, 14 Feb 2024 17:53:37 -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 20/31] selftests: ntsync: Add some tests for NTSYNC_IOC_WAIT_ANY. Date: Wed, 14 Feb 2024 17:52:55 -0600 Message-ID: <20240214235307.10494-11-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: 1790920767841278263 X-GMAIL-MSGID: 1790920767841278263 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 | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index d2c0c97839ba..ca61fb17439b 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -342,4 +342,123 @@ TEST(mutex_state) close(fd); } +TEST(test_wait_any) +{ + int objs[NTSYNC_MAX_WAIT_COUNT + 1], fd, ret; + struct ntsync_mutex_args mutex_args = {0}; + struct ntsync_sem_args sem_args = {0}; + __u32 owner, index, count, i; + struct timespec timeout; + + 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, 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); + + for (i = 0; i < NTSYNC_MAX_WAIT_COUNT + 1; ++i) + objs[i] = sem_args.sem; + + ret = wait_any(fd, NTSYNC_MAX_WAIT_COUNT, objs, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + + ret = wait_any(fd, NTSYNC_MAX_WAIT_COUNT + 1, objs, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EINVAL, errno); + + ret = wait_any(fd, -1, objs, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EINVAL, errno); + + close(sem_args.sem); + close(mutex_args.mutex); + + close(fd); +} + TEST_HARNESS_MAIN