From patchwork Mon Feb 19 22:38:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 203338 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp80002dyc; Mon, 19 Feb 2024 14:57:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWyDlKHgrlx0hOX+gbq2B2aP1f/z8O73l+xc3E4Q1p6ISuShTec2xr1SgXddkUZguzZFyGiafl1qA3SnCYNDoyiALizdw== X-Google-Smtp-Source: AGHT+IEsBGd6gnYgGKO6yfDhgksaLmcaiy7Nw1q+W+P9VH6KPX5jS9DpZnYHN+Uw33zLkN+GD2Hx X-Received: by 2002:a05:6870:5692:b0:21e:e5db:7964 with SMTP id p18-20020a056870569200b0021ee5db7964mr3740409oao.23.1708383427153; Mon, 19 Feb 2024 14:57:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708383427; cv=pass; d=google.com; s=arc-20160816; b=yhUqPMVi27yPliis+vF6+osh802+rRwGhZ/b1pqlLMRheXoNVSrqlglIqoHTvwomHY kvzFhf5wvK2pA/gng5qOazWAB9uIOGSKE7Al1SrRUAd5liWkHRM6FSLN/sSXgluMK9Ae pi35GIr1vClAW1b0m5a+JCw3HKVGaAoaZ1DcWh5NM2dKLepfoEaSEWlNkQVI4gIwE6iI WjHjJByK+KvU/C+mRNYaSpV4UXut5+aUaNYZNkDs8T2yMAPCAUd5LwK1XJQr3TVy8Vq6 66OMY0za1gE8ek+uocPhugCBDN2AeykpZYIj1zFDrtiIqeQFT+lEY2FQUIBUTtHa0rTh 1iAQ== 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=hR3Xqo6s6FufP5gEw1XgbtLHrluZu7hd5XGp+hLIfiM=; b=lR6O8Jjj7FaGBvBHe3RXHr2KsMIXwC/yXtcWOlbYIm3ff3sQ2dVsZ1CTF4eLp4eRBH WOaz4bwlX/lW0GtptLKxsbzjC4oF54S6KZdd8+LnkRGyobdMJj7Dlhjbq9vDEUP+m4kJ XfkpD4ob7ObIdKGPyJxaleQ6OGUEiSvOv5jm6OwAZW4i2iI7+nMI0B1FGiU4Xgfkqd9a VQB9RbWhLsX0PvxWmdn4bjIx1npGX90Lj4zj8ttRF/hSyswtwudLz3GEXLMt/Wg3ZX7e 09+Mm1a0iNVaREkgzACh9lkOqtbFI/gAte4DTCa66W4RiL8/wVrmc2L5bma2XvUEprSn 6NbQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=lsLBJ0mf; 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-72106-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72106-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e22-20020a656896000000b005cf0309e41bsi5022288pgt.823.2024.02.19.14.57.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 14:57:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72106-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=lsLBJ0mf; 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-72106-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72106-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 AF9D8B24C7A for ; Mon, 19 Feb 2024 22:47:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3EA3267A17; Mon, 19 Feb 2024 22:39:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="lsLBJ0mf" 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 EDFD056760; Mon, 19 Feb 2024 22:39:38 +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=1708382383; cv=none; b=jsl3YSxFfOJWwjHoIGShd0d7UTcoOyVWK22/NrYasgEVvKkmUINFFNJgXQdQdPYdER2NvxrWR7rD/uZFCICYVmksikQuliQQ5Y2VRlgPCjQtTvCFcrQVBAHI5mAwIzm2Y7vGietSNanVTBiCVwQwOoM8xo/Rl67PA/xBmGKhn5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708382383; c=relaxed/simple; bh=BZw7zShBTT5PfD4hawcGoNVQjDPKfhLnloDinunlfUc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ep086e6wWeorTPcVnMTPV68Y/7YmxVbtCI0INfQI8YdiP3mCYcga0Qql060pxEt5gkq0cDJzV98f1xMd4SnTVGf4svPITli/Zp1jtyaGROSl+OeP9DiVKm05e9IaXHHQRqrU/modkuIEy/a1x7J1zRKIn+URUBi5e2g0sZru/Iw= 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=lsLBJ0mf; 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=lsLBJ0mfYfA07EzwEPdhS32PEg /GHDs3wzD3576ItezKBFTAef5mlNlfJdaDyj03K77DMkkrVYm94pb017mtWXrAYdnzDndUloaMOea Y7yBKoC4nRkr43znD8qxvOT9+95/WOIYAOEoYNz4u4i6z0RfKPTzWJ5PbpLZ7CSPfoBtUNm9BJPxX iJ6QwNizdmLugD7FTeBDz2U17VayvBmXZLBg5D0thV1nz5HFDuTDFeHipLQhOe3K8szedKKdAHsvr B165J9rLRsZg1+o1sRhzcdLEqGoJrNiHvDsZAfUjoFxkRFgIGQ3V4xbSPh5KVIhdDmAGMaqG+qyOE S4SFEPgg==; 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 1rcCIR-0037Oz-1h; Mon, 19 Feb 2024 16:39:35 -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, Randy Dunlap , Elizabeth Figura Subject: [PATCH v2 23/31] selftests: ntsync: Add some tests for wakeup signaling with WINESYNC_IOC_WAIT_ALL. Date: Mon, 19 Feb 2024 16:38:25 -0600 Message-ID: <20240219223833.95710-24-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240219223833.95710-1-zfigura@codeweavers.com> References: <20240219223833.95710-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: 1791369860473822348 X-GMAIL-MSGID: 1791369860473822348 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