From patchwork Mon Feb 19 22:38:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 203307 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp76579dyc; Mon, 19 Feb 2024 14:46:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXIaOoe59Q85CB/YHgksll9yuMqnAEdHKyCdkZq6J8GzdrLmfl8P4lHNeFnXTrUMXexKHFw5OQ468VTAaI577++oISYwg== X-Google-Smtp-Source: AGHT+IEo1cCdkgp/th2psKyXVE1XbNajXDHXxQMfL3e7Yi6shRM6s2M0ZNrAad3k7kTI3aLmTZ66 X-Received: by 2002:a0c:f387:0:b0:68f:2e02:cfff with SMTP id i7-20020a0cf387000000b0068f2e02cfffmr13341300qvk.28.1708382763317; Mon, 19 Feb 2024 14:46:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708382763; cv=pass; d=google.com; s=arc-20160816; b=N7Ogks7OUL3sFWLBFWVhPa1iVus+QZTicq9beuSrZEYK3Tp48eAu4KWveyq3tivqVc fAbUZqYjHStoZ6lN/62rSex88u4sPXV62un0VLndfgoXTziFmJFTO0s8UOwmyvEKqy0h 94fNDX+40kU+K6nfZn1MigMrP5pd/E1UXgx+Ne0bMYd+ttV4xSl2uBBAYGoM+fejsHxg 35BjGuscioP8NAUXwKpDoFyl2UJpjkUPbKO0jcx92CzF1hLw/39iacZYpFfgyuFnvWNB EgLxBRol0sb3wcHTnhokIRYMjt2Fz+7BVnR3iUnmLETKCidhw75thyanp/zHCowRsicC VK7A== 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=S+Bo60slTZYs+MASNA28omTt/46YdAeLaNdjfMjNW6Q=; fh=hR3Xqo6s6FufP5gEw1XgbtLHrluZu7hd5XGp+hLIfiM=; b=J2Qq/HhNG1wwLrFptsR6MMXScJQvq8G4bYA+ueTo8OJjiZYhjkJcYHEiCjhqP01Htf 7riLL1SQaLnVcpuIMzmqzi+OXc+a+Sd7WNqqJoudMIkF20q/UAAfMuAxOoM9TifUfBsk w5W94jiBjbDT/urZO9vTA6H7Tat6TG3xZ/cqt3XRYZdNyZTHvd3CE5JQm4PmDb8qg4aG 0TI6N4DiPsLHMy+zfVAKwsK3ilI+5jEK8NSYtfqonY32X1N6Iz1xtqy/kcvszrRNjAa0 Sqc7BCydlpIf2ZYiCBp/T7ts4mW1hKfSZ5FGiUohzXJgXSvZ02uey3JEU4QD90I2vipa UHAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=O3EeQI8w; 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-72091-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72091-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pt12-20020a056214048c00b0068d0503a3a8si7536200qvb.439.2024.02.19.14.46.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 14:46:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72091-ouuuleilei=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=O3EeQI8w; 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-72091-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72091-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 363441C22A87 for ; Mon, 19 Feb 2024 22:45:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A691863120; Mon, 19 Feb 2024 22:39:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="O3EeQI8w" 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 1E1AA56758; Mon, 19 Feb 2024 22:39:36 +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=1708382381; cv=none; b=hmuNGuB8IUyavKRVuCqNtx9kslYBes1V6hvkz1zmci+cRIoHddG36DMnGq5gqaZYVaLXyCuwwoiVZ37vT/oCD+QV2ADBljRuVhTURPBqLT0eTBYtREky5XVF2GCm/DRsItawL90Ek5MfdEY7/GgrqlziuIBszxyuBsNNP56GyxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708382381; c=relaxed/simple; bh=c+6U+ZbefTz0YtyUBcA/usnu8kiO48W/n5csRaPODMw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cz6aH9RT9+/bny3NEEWEt4fCxibnZk1IUZE+srG7wSHkjWKjkzRya5oNz+r2canbnKfXwatFKn0Rf+QsE7DJwL2KYcJp1hW+YEjIfYWYtXzIBvTRDcbyYOExUup+8iHBZ0qq77dbax5v4x7lF7yiZXEtG3g9VSbBZYX/mUFVPso= 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=O3EeQI8w; 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=S+Bo60slTZYs+MASNA28omTt/46YdAeLaNdjfMjNW6Q=; b=O3EeQI8wiuddhqG6Vul1NSfZp6 L7hxg2+pePmaEcdm8zwezsLQGfLPNnTBBH9Vxap8MEPnFr6Ihm4g1VARjTBWRwpfXNmx/oec3CKXM bz2DwGCWDHvPnMSBzWQV5ZvSpDtqNpXgUT1dCCH2/eSleyw0t5MI4Ej53/nTQeExqs06hde+ITYa5 hMykxyr0CEzzs+y4nLHA/mN2XMpKbY+TZX/nRspuKRn0fEBRlUjI9DW1yIqKi3dUu7/1uT2dyQFxh rCHkXOzfIN7AxT3HG8zXJg7XMsJIXohEM8jtixCfX19yT8cj3hFUvUUzuM/qUqwfw0+nQFX5xK6DW eAtchFlg==; 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 1rcCIQ-0037Oz-1M; Mon, 19 Feb 2024 16:39:34 -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 21/31] selftests: ntsync: Add some tests for NTSYNC_IOC_WAIT_ALL. Date: Mon, 19 Feb 2024 16:38:23 -0600 Message-ID: <20240219223833.95710-22-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: 1791369164506702287 X-GMAIL-MSGID: 1791369164506702287 Test basic synchronous functionality of NTSYNC_IOC_WAIT_ALL, and when objects are considered simultaneously signaled. Signed-off-by: Elizabeth Figura --- .../testing/selftests/drivers/ntsync/ntsync.c | 99 ++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 40ad8cbd3138..c0f372167557 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -73,7 +73,8 @@ static int unlock_mutex(int mutex, __u32 owner, __u32 *count) return ret; } -static int wait_any(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) +static int wait_objs(int fd, unsigned long request, __u32 count, + const int *objs, __u32 owner, __u32 *index) { struct ntsync_wait_args args = {0}; struct timespec timeout; @@ -86,11 +87,21 @@ static int wait_any(int fd, __u32 count, const int *objs, __u32 owner, __u32 *in args.objs = (uintptr_t)objs; args.owner = owner; args.index = 0xdeadbeef; - ret = ioctl(fd, NTSYNC_IOC_WAIT_ANY, &args); + ret = ioctl(fd, request, &args); *index = args.index; return ret; } +static int wait_any(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) +{ + return wait_objs(fd, NTSYNC_IOC_WAIT_ANY, count, objs, owner, index); +} + +static int wait_all(int fd, __u32 count, const int *objs, __u32 owner, __u32 *index) +{ + return wait_objs(fd, NTSYNC_IOC_WAIT_ALL, count, objs, owner, index); +} + TEST(semaphore_state) { struct ntsync_sem_args sem_args; @@ -461,4 +472,88 @@ TEST(test_wait_any) close(fd); } +TEST(test_wait_all) +{ + struct ntsync_mutex_args mutex_args = {0}; + struct ntsync_sem_args sem_args = {0}; + __u32 owner, index, count; + int objs[2], fd, ret; + + 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_all(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, 1, 123); + + ret = wait_all(fd, 2, objs, 456, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + check_sem_state(sem_args.sem, 1, 3); + check_mutex_state(mutex_args.mutex, 1, 123); + + ret = wait_all(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, 2, 123); + + ret = wait_all(fd, 2, objs, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(ETIMEDOUT, errno); + check_sem_state(sem_args.sem, 0, 3); + check_mutex_state(mutex_args.mutex, 2, 123); + + count = 3; + ret = post_sem(sem_args.sem, &count); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, count); + + ret = wait_all(fd, 2, objs, 123, &index); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, index); + check_sem_state(sem_args.sem, 2, 3); + check_mutex_state(mutex_args.mutex, 3, 123); + + owner = 123; + ret = ioctl(mutex_args.mutex, NTSYNC_IOC_MUTEX_KILL, &owner); + EXPECT_EQ(0, ret); + + ret = wait_all(fd, 2, objs, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EOWNERDEAD, errno); + check_sem_state(sem_args.sem, 1, 3); + check_mutex_state(mutex_args.mutex, 1, 123); + + /* test waiting on the same object twice */ + objs[0] = objs[1] = sem_args.sem; + ret = wait_all(fd, 2, objs, 123, &index); + EXPECT_EQ(-1, ret); + EXPECT_EQ(EINVAL, errno); + + close(sem_args.sem); + close(mutex_args.mutex); + + close(fd); +} + TEST_HARNESS_MAIN