From patchwork Wed Feb 14 23:52:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 201196 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp62663dyb; Wed, 14 Feb 2024 15:59:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCULDs2ePMpmUGiNz8+H8wq225IyNUZ0wssUmlmhEHyZb5oVCE3x5cbAmqcHylnscArQ0lgblogKjU0ycUwXQ3rPE+pTFw== X-Google-Smtp-Source: AGHT+IFPm49HiNBhSSkTFxXfi8c2PXTN7/iEvu0W6cnPVF9fhkNqxZjMLMDaHWUd6OYqYFVaHdIK X-Received: by 2002:a50:ed93:0:b0:563:7f35:6a26 with SMTP id h19-20020a50ed93000000b005637f356a26mr96990edr.8.1707955193413; Wed, 14 Feb 2024 15:59:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707955193; cv=pass; d=google.com; s=arc-20160816; b=dfLn5t0I+d3y3kfUduoq1ukFZGftkCnNPxBtsgUaJ4/dfV7Qz8QTZ38MQp8sNGc/6M NIpt8NLEqZyU+nANp1N/NTk5eRsRV2d8KPgFeBqfsT1bOB40cgsjjUEllGNdPuu0/ENj tT8sMZMiINvqOr8c3mJEYcXI2+3JcvTKDHa+Xk9Iprk7QgTdPVgIb98tkMPux7Uy5Oc2 ZXKckekDGEXalsuTfFrx5tfJ3pm7IoNcN3WYHy4uVlKACcvIKK1syn2yISJ/B8ePVDDz sBayP3+hwiiLDkgh2VIWFK/WXiW7tRerU6+tMFBcbuzOu/VGuJkY8MuY0Nk/b7SHEUFd uKpg== 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=KwS1FfUvDDDY/WvGCa7UVhhPBJO8eSHPusvHbywdvFk=; fh=sOAzP1IXJnllEbSCBRlwdfT0MN3UiaRLwzx1Tpw7GJA=; b=Ghez2W6VgFqJMJVU8Jq5ClGZRSBq0y7NcRm/j2hhS53DeQZSshBe3khMN2+6b/aSsD JyL4PwAcpXrUzn74DeG4vJkBdAS/Qfnggx5CTU4jzu2tYfIKz5+eAbFHrT0um+V3fdVW JOK6DHdQqkJWTKkjqn7ML2Grxtuc5bwAJ/sObTR6EsmrqkURycmkGILMvddcb+SFRigs +7r3ByP1m+tTDnZDQHCiq/BH+gSvlN+glifdPUrm1ybd4lYOPWBzDyIQB+aKhxXHxPUr gH8CCkpZnt9pyewst9Y/yZKbwo5PkhNaYt3jkIaDySZ6PLVb+nczdctYT9jhDSY9GTHG UJWg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=jaumXm3F; 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-66158-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66158-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 o16-20020aa7c510000000b00563a2e8884dsi30995edq.675.2024.02.14.15.59.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 15:59:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66158-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=jaumXm3F; 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-66158-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66158-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 ABF621F21FE7 for ; Wed, 14 Feb 2024 23:59:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0797514E2CC; Wed, 14 Feb 2024 23:53:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="jaumXm3F" 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 3A62014AD28; Wed, 14 Feb 2024 23:53:46 +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=1707954827; cv=none; b=OEZVLuOdLaMjzfDAVohgGu+n2ou86WvN68gVDd1tFklPmyZtEylTGjxh/VpFmB8TNdZyhHCbZJ7Ym4Ch8jsm6Qr+dchASH3N5pNuTEDHO11qbNO0LWJnWoYjwIet6q4Jtjmrmv1biDWbRwpWXiiJIgHRa3pVjhbKaa3WuWw/+IQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707954827; c=relaxed/simple; bh=ULCw8wBkAv3LJc8jc62DPGxWhXuGWE5SyY5bMA8HPwE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q8m40yYoZC5ValrHegpMv2NFXZ3yp249lrQN9+/3WzKrG4Nj56oEzwmx7ELBvx3K6O2hFlPFJnFenU+F1rrpmlrC7sTgY0DTIb0Yq40Yt/rXnSlgLRCJLMfoVkhFeFhsFlZRgR4QH6FAcAK0qjtaIulpBPUYbBFEsDYp/SHlARo= 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=jaumXm3F; 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=KwS1FfUvDDDY/WvGCa7UVhhPBJO8eSHPusvHbywdvFk=; b=jaumXm3F2nQpGRXUuWC+Cv9rdg KlqKvmoEUtXGrIO+M6m2w5QZz18rRTH5ium83E3dDgECCgyt25BjDOU87iKK8wST1Z5ddvjl5E5Hb igF3KTXjg949iRb+rixzL/AcNFVYiVhkvJZ5vLTXnph6klyIUG6mQzZRQb0iVTFzcRFNXMfWPOPDd vE0/Ub1Jw4yrfocl+Wd9SBwnp0s56SAZqC2aQxS5ZoioJl5BGL+ghr/r4Z5DNOoY3F6PgvQviJDjx xG+tlvOjJOANCuIw+n6eiNAWx6MxoYfEdRBTHQm42cLEM1wBx/lVwJk/3hNDMNywpYIOnWJqizY8k yzUosXwA==; 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 1raP4Q-00GcSK-1M; Wed, 14 Feb 2024 17:53:42 -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 23/31] selftests: ntsync: Add some tests for wakeup signaling with WINESYNC_IOC_WAIT_ALL. Date: Wed, 14 Feb 2024 17:52:58 -0600 Message-ID: <20240214235307.10494-14-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: 1790920824971400321 X-GMAIL-MSGID: 1790920824971400321 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 e825e115f11f..063c0ecb3bff 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