Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1783176lqp; Mon, 15 Apr 2024 18:23:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVel81ygke/4eT+oL4mnkp/KWARSqndhaElxUAMbeUPFIRo/J94zviXhFyhLn2L9DJZRbU1Vh3W04u/Kx/TQ6V6Qx13nn09/Vu4eyv3qw== X-Google-Smtp-Source: AGHT+IHnOGMHMhUYZRq7VBobD1gUPj5YDTn0zlf97uyNZVsCdtWiARbNyT7auh/h10Yc1naWyVcj X-Received: by 2002:a05:6a21:78a2:b0:1a7:186:f976 with SMTP id bf34-20020a056a2178a200b001a70186f976mr10598249pzc.40.1713230638584; Mon, 15 Apr 2024 18:23:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713230638; cv=pass; d=google.com; s=arc-20160816; b=IIrCktg7qeAxFVtYOA/T0H26deC8enUlP+R1mT2Sn1TxuyGsFemOXaVdJhFNVIFTZM fsPQdzVlwEUUlQM97Ds1I3xQrmENbjIt+ZyG/YbSj1J1RpKjH3kxGhPmeOiOSvL0yvkU A7NJuon7kpQoWE/zNFY55FcBcaFOKkGOnGZl91S5Dj6F/pYRuNZLgO7PMSSCF0Searoa O/FBTY/09OWaIYhzp6W4F5hGzqDj2dYco6a7ZW8zaJwK3njhgeExsz2o90H83pGaHaEn 6KgzLpPhXwLUSLVgWaQAPH2x/MOLTihHfAiBDXYHXUi7rBG/UVhQVCYijUyoHsVqR21B 5oqA== 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=1lbo0bNxrPdMIVRoJ6+tExY5TotubsDpMSLovzCGBGc=; fh=eVY06L/C5FDTmF2RNqfudsnjwkB3tbhT/y33cGhZc0I=; b=bcj3EmAyh0BlP0wVar5mObokNPfre0HUWiGGulsPf6wq6aLX0EJx82ln1Powkcy8IH MDT2iHY+tvyBqu+POHLUluo1m93P7Iw7zqlXZ3LixUdr6OfPy3AULN3EpJVjG4paTSrT YfKhYIEr4b8v4vdue4U1SF3MkuaW+06VCfHnA2xFR2gyaSmCWJVDopuOe44zVquwo/7z MSCC33YWfho0RCW2nRSd2JJXG7t9NpNMCEdpKIJOh80w2dzxZgn+41F49kJAFUTIf1NU rMwgp/z39ddalru1XZzHvnHRyfSK76i6NMsT3OzH4NTBkEgIaJUcQEPPlPhSjiq0SOYb bu9Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=Uqv0o8xf; 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-146063-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146063-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bc8-20020a170902930800b001e0b2870953si8622815plb.595.2024.04.15.18.23.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 18:23:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-146063-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=Uqv0o8xf; 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-146063-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146063-linux.lists.archive=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 4DEB0285A7C for ; Tue, 16 Apr 2024 01:13:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D0894AEE9; Tue, 16 Apr 2024 01:10:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="Uqv0o8xf" 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 B2CA15223; Tue, 16 Apr 2024 01:10:28 +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=1713229831; cv=none; b=r02BAF6bCyjTX8JLQvkl5Og4cb7ky4U419LgEjyaMd1CmkQTyq8vq+yg7CVl6ivDc6N4O1kUgamvGWorbYW/S/GlR32HfRRiISJTrSu81W+G0HPbu4SMnBRjGQLYz6hHv0pvAOFDfiM56EPchAy/YjAA3JpMm3PcdxBWy4Jf9KE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713229831; c=relaxed/simple; bh=8mBpNrep45/WQcWJkfana5grpHviuBbZ8c3NZYi9TZk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XhskgV6wO92BuYeDiImaXru3WoNzNEGd4kncqnoL3thHCYHjvgz9WYjnNSO/xYsbTAHQUAUBbf/QHsYFPStWcJaW8W83rWLD5e97dGv88TwJT+ea9jcfujw0CU82c2YO5jKNPMG96ua14GiA/x2SqhQgZJ54dzdLrTE1zF/LpzM= 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=Uqv0o8xf; 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=1lbo0bNxrPdMIVRoJ6+tExY5TotubsDpMSLovzCGBGc=; b=Uqv0o8xfie2sRquqOJ0k7RXBhy i/kSPxpDGJrngafdgLn8/M2rJRGwhArYGOlNc8CVFo+ujP1MSlRx+mTfnnPo5ZZJhlkpRVawK/3Rr 0CXf5TEgl6OPNpsrUdUVoA2OYlJOIF2kGcAM/Sbfp5FdRxzibI5bCTdww1tri3Qo1JnmvhAZapRg0 +meum92bHNUL05YmJOcU/qgfRzl0GHDbZWUtZOxGhuQh9fBsIF4GHs/ix+dAFi8MOyoY13Z2eEaz1 OfLga9fu84/YMQLIIbKvUDqkjC4PvXWjUEWomcx76E+ZBIoh+rvR/fS9HOA/XbDs1WjaJo3EnLdFe jcCyERlA==; 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 1rwXL1-00FbQv-1y; Mon, 15 Apr 2024 20:10:19 -0500 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=20Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Randy Dunlap , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , Elizabeth Figura Subject: [PATCH v4 16/27] selftests: ntsync: Add some tests for NTSYNC_IOC_WAIT_ANY. Date: Mon, 15 Apr 2024 20:08:26 -0500 Message-ID: <20240416010837.333694-17-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240416010837.333694-1-zfigura@codeweavers.com> References: <20240416010837.333694-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 7cd0f40594fd..40ad8cbd3138 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 -- 2.43.0