Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2098746lqo; Sun, 19 May 2024 13:26:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX6P+N9sg62Y1XBgN8fCHbV31w1GF8S4TOuNQj9rvtNJ6PBCdxoILjf7wZYHHWhDOWuig7/tvr05P9mQavPPOCR46Cv4BJ973kl/1rUNg== X-Google-Smtp-Source: AGHT+IEdw+a3GXO61nXobfOF/mB+rJGpYcZZBqngFvwuX4GkSQD/F6k0vs37dvrr7g4PQASdTmPZ X-Received: by 2002:a05:620a:7f7:b0:792:970a:86a6 with SMTP id af79cd13be357-792c760e8f2mr2527192785a.65.1716150370942; Sun, 19 May 2024 13:26:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716150370; cv=pass; d=google.com; s=arc-20160816; b=K2I4sYR2M0zMwjCVRt+dKEvkZNAPm03PxgFjjtp2h/uYbUkGoUd3trapWbMwUlCOYq XAGxR9e/d2S97Q3cjRK0L803+BTvO9lueG7jyRMsGegJ3PF7ocejnGYs0VUgPN9BDzus yiVInRcg4QUNJGB50PaUbsE9O3Kd/lyNR73CYJq7xLbdyQPc+kQ6lUmKAI0dw0tEbEPD 8tojWncH31ZsfEHc/ZWQK44h3mCIej6rK5bPJF+xYkoMOPjgWUgJI5sWzRopSUkc7rF3 saslAxKHqYu1kFtr/4ng/o4E1DgCQeHQBJVmYHXjmFRv+DelJX8JvWcaaZC/t8f5gw5G Ddkg== 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=sRVvK3PXYm0eOCy4h040E2JuAl2v9xoXVKyVT6JY+Rw=; fh=eVY06L/C5FDTmF2RNqfudsnjwkB3tbhT/y33cGhZc0I=; b=O5PH/xcG5Dcxzh7llkkebg9fWWhjaBI1a2isYlXr91FZHUwvAWtNZBEZt5cas/hKMW RdGg0/KrhrCerAGvnKCWX8Ue0HCFu2Oo46DhgXwTnA6kgfi8P+cqU5liW2URJn/cZaEH BDFIaum5SijJXOY37UbdequOBIZE5sf4eYMBRvwIdGVv0VP9AOkvtUvG+voPTq9eBl/T UJjpc8cWiXzmFh2mQaN+IWW+JC3B4N4czxlrav5rqRmmfrNpwsR8kvUJCOZcneuTMgn5 y35n3XEPeHT/zuRPOvTgHPIaRg2haXb1WNlgHwpV+04hUyVB8e6Cl24II4J7qtH2OvUs R0qg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=eaoBbPtn; 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-183236-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183236-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-79302f9f486si941163585a.655.2024.05.19.13.26.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 May 2024 13:26:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183236-linux.lists.archive=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=eaoBbPtn; 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-183236-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183236-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A80FB1C2085D for ; Sun, 19 May 2024 20:26:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC6E8757E5; Sun, 19 May 2024 20:25:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="eaoBbPtn" 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 ADE356A33C; Sun, 19 May 2024 20:25:14 +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=1716150316; cv=none; b=WSgwFU41s6MrPMQ7FJhLjYKx2vV9dZ17O5/uypW/a8PMY29l14146d1URYkNZDs2An7WQfHg9ytG+8e/v7k7n4oWQeNaohfPSkStY4Edaez5znPoCHDleYK+FjFaNPV8+m3ZzDX5iIl8njPnuOarFRQ9kA2VpXtAk/hEAsERT0A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716150316; c=relaxed/simple; bh=BZw7zShBTT5PfD4hawcGoNVQjDPKfhLnloDinunlfUc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h5Hf4pQmwjlyj5ETF4UpsCFjhMdMhn89DniY/lnc9NL5exgwvxvB6izWgL+HAozVri4QvXMtAwQO0ZdApjyhMYe/vGbLLfDeuYqkll38KSqtWLE9zcGMLNx+CJwhSEC4IXxbsjLaMX0SBpDnSBnPNajF75mjrPwxvVT4vGcX0Sc= 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=eaoBbPtn; 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=sRVvK3PXYm0eOCy4h040E2JuAl2v9xoXVKyVT6JY+Rw=; b=eaoBbPtn4GhFc3UMuK2hwpo5j2 LN/8G80Mcs1OyFrVq98EcrM2aVpb7RdlwrXQiEoLorGIFnK21/Mxonzswxo/N06FoSDQQ17ti5tNn JTgRgdKUMdreM7V4flEmIVmLn//18K89OLRfz7DAmS99ECOZdlJ0i353hO2/ZluDs9C8JqLvUPjKQ drw5QjdXgQ51h00hXYeun+D/qvPx+yGa12W+PZqGPpodAPzXVJgZctTicwAdohJva8F8etW1+1Adr gk0CNEfBOmKhi9fTywrth7npYZNKXMuPcH9SwrcadK92MgYEHMeuYDj9QL4rXAySefDjuGxyzSyjF P0U2EZOg==; 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 1s8n5e-008wIn-1k; Sun, 19 May 2024 15:25:06 -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 v5 19/28] selftests: ntsync: Add some tests for wakeup signaling with WINESYNC_IOC_WAIT_ALL. Date: Sun, 19 May 2024 15:24:45 -0500 Message-ID: <20240519202454.1192826-20-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240519202454.1192826-1-zfigura@codeweavers.com> References: <20240519202454.1192826-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 contended "wait-for-all" waits, to make sure that scheduling and wakeup logic works correctly, and that the wait only exits once objects are all simultaneously signaled. Signed-off-by: Elizabeth Figura --- .../testing/selftests/drivers/ntsync/ntsync.c | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 993f5db23768..b77fb0b2c4b1 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -706,4 +706,102 @@ TEST(wake_any) close(fd); } +TEST(wake_all) +{ + struct ntsync_mutex_args mutex_args = {0}; + struct ntsync_wait_args wait_args = {0}; + struct ntsync_sem_args sem_args = {0}; + struct wait_args thread_args; + int objs[2], fd, ret; + __u32 count, index; + pthread_t thread; + + fd = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); + ASSERT_LE(0, fd); + + sem_args.count = 0; + 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 = 123; + mutex_args.count = 1; + 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; + + wait_args.timeout = get_abs_timeout(1000); + wait_args.objs = (uintptr_t)objs; + wait_args.count = 2; + wait_args.owner = 456; + thread_args.fd = fd; + thread_args.args = &wait_args; + thread_args.request = NTSYNC_IOC_WAIT_ALL; + ret = pthread_create(&thread, NULL, wait_thread, &thread_args); + EXPECT_EQ(0, ret); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(ETIMEDOUT, ret); + + count = 1; + ret = post_sem(sem_args.sem, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, count); + + ret = pthread_tryjoin_np(thread, NULL); + EXPECT_EQ(EBUSY, ret); + + check_sem_state(sem_args.sem, 1, 3); + + ret = wait_any(fd, 1, &sem_args.sem, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + + ret = unlock_mutex(mutex_args.mutex, 123, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, count); + + ret = pthread_tryjoin_np(thread, NULL); + EXPECT_EQ(EBUSY, ret); + + check_mutex_state(mutex_args.mutex, 0, 0); + + count = 2; + ret = post_sem(sem_args.sem, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, count); + check_sem_state(sem_args.sem, 1, 3); + check_mutex_state(mutex_args.mutex, 1, 456); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, thread_args.ret); + + /* delete an object while it's being waited on */ + + wait_args.timeout = get_abs_timeout(200); + wait_args.owner = 123; + ret = pthread_create(&thread, NULL, wait_thread, &thread_args); + EXPECT_EQ(0, ret); + + ret = wait_for_thread(thread, 100); + EXPECT_EQ(ETIMEDOUT, ret); + + close(sem_args.sem); + close(mutex_args.mutex); + + ret = wait_for_thread(thread, 200); + EXPECT_EQ(0, ret); + EXPECT_EQ(-1, thread_args.ret); + EXPECT_EQ(ETIMEDOUT, thread_args.err); + + close(fd); +} + TEST_HARNESS_MAIN -- 2.43.0