From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 C6C283A7829; Sun, 5 Jul 2026 19:54:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783281292; cv=none; b=Bhs28jbCLq9gunaDwKGt5dfZE0kMhc9zl9/h/1tVRkRlFUEKdLNFP+ymPxNEekmklKM3QCw6FOUe5t+waQLP6optSWSMHtj+CLENuWb7YXyk3LIToKOQB00rXD/y/VgTrFvX4TG/UDAS5d1Ys4i80VvkNo6OACVu8cgBCkPsZ8A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783281292; c=relaxed/simple; bh=V5vPjM9+wWx9wg7SAs3OvFyrTmNBgmH3f0843hX7A9Q=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=H+8IzaeTzj0tpPolgyS2EoaPt58tZIax1e0n/wxZIP+8mzQfDriaJVaX6YZTQd/SNr8p3OeUSGiGv5tE0V4/TH9GFNwz9znareG9itA/o3qkWrjTaB8i0svfgR1ZfZdwoX+4VPGE4swbmyUHHWnlP+pPPoJXSx6d+GxTYBgDn8Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=x6Xsdpz6; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=H1RxcyDw; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="x6Xsdpz6"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="H1RxcyDw" Date: Sun, 05 Jul 2026 19:54:41 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1783281282; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Mp4nL2ZFzoWjj5zxWRtrtBL8Y66NQGXiPHHl87NOatA=; b=x6Xsdpz6fgMbvrlvT8blBBgSj8eYn2MerbYb/YL/hpLKZj15vfc/7cBGWmcBe6THSfI6Yf 7K7PqYsLFoOq9eMMdpwZIk+m5zkWQcMxGRwftvHQay5zK/op8iCU+1gsm1x8DVakJbuPhQ O7qg9pNf0lKl1glprtL4cZUb7yCdhjeSUA1O8wFGiGJHDiqwxR1zA84Qx+Sqr27q3gcaq5 ilkB8EQ46ZuWsDIxnusCIb7ILXLbB4LZD7ClAXIyygc5o9i3ik5Re7WDL1Ta1QgUmXIavw unbqiMBD6lUDip+yZ4K8eUGOF0uENXeyKZ/I5mHs1NLQ94xGv0xXH+0EghNnvg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1783281282; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Mp4nL2ZFzoWjj5zxWRtrtBL8Y66NQGXiPHHl87NOatA=; b=H1RxcyDwpyvXoZsmPBpucp8q5AbPtgLcjdQ0mEi62FxDMQ4zC/nlNSvW+3Gj1qJeVz1e13 EzCR2+fc1hdy4SAw== From: "tip-bot2 for Wake Liu" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/futex] selftests/futex: Migrate functional tests to harness Cc: Wake Liu , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260526010635.23980-2-wakel@google.com> References: <20260526010635.23980-2-wakel@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178328128106.744054.11902856720161004393.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the locking/futex branch of tip: Commit-ID: e531301dd8fa23f1edeee9c8af62310a4e1424c5 Gitweb: https://git.kernel.org/tip/e531301dd8fa23f1edeee9c8af62310a4e1= 424c5 Author: Wake Liu AuthorDate: Tue, 26 May 2026 01:06:34=20 Committer: Thomas Gleixner CommitterDate: Sun, 05 Jul 2026 21:49:17 +02:00 selftests/futex: Migrate functional tests to harness Currently, multiple futex functional tests (wait_timeout, waitv, wait_wouldblock) mix low-level ksft_* logging and result APIs with the kselftest_harness.h framework. On older kernels where system calls like futex_waitv are missing (returning -ENOSYS), this mixed usage triggers framework inconsistencies, causing the test to fail with: "Illegal usage of low-level ksft APIs in harness test". Address this by completely refactoring these tests to exclusively use the high-level kselftest_harness.h framework (gtest-like API), mapping all low-level calls to native harness macros: - Non-fatal assertions: Replace ksft_test_result_fail() with EXPECT_EQ() and EXPECT_NE(). - Fatal assertions: Replace ksft_exit_fail_msg() with ASSERT_EQ() and ASSERT_TRUE() to immediately terminate execution upon setup failure. - Test skipping: Replace ksft_exit_skip() with the graceful SKIP() macro combined with early runtime availability checks for sys_futex_waitv. - Debug logging: Replace ksft_print_dbg_msg() with TH_LOG() to inherit automatic file/line context. - Success reporting: Remove explicit ksft_test_result_pass() calls, deferring to automated harness completion reporting. Additionally: - Fix a critical SIGSEGV crash in early syscall probing logic caused by passing a NULL pointer to inline user-space timespec conversions. - Introduce TEST_TIMEOUT() and GET_ABS_TIMEOUT() macros in wait_timeout to encapsulate assertions while preserving source line attribution. - Pass test metadata (_metadata) into secondary threads to allow native harness assertions during concurrent execution. [ tglx: Fixup coding style ] Signed-off-by: Wake Liu Signed-off-by: Thomas Gleixner Link: https://patch.msgid.link/20260526010635.23980-2-wakel@google.com --- tools/testing/selftests/futex/functional/futex_wait_timeout.c | 108 +++++= +++++++++++++++++++++-------------------------------- tools/testing/selftests/futex/functional/futex_wait_wouldblock.c | 34 +++++= ++++--------- tools/testing/selftests/futex/functional/futex_waitv.c | 131 +++++= +++++++++++++++++++++++++++++++---------------------------------- tools/testing/selftests/futex/include/futex2test.h | 10 +++++- 4 files changed, 145 insertions(+), 138 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_wait_timeout.c b/= tools/testing/selftests/futex/functional/futex_wait_timeout.c index 674dd13..6e6e770 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_timeout.c +++ b/tools/testing/selftests/futex/functional/futex_wait_timeout.c @@ -31,53 +31,47 @@ static pthread_barrier_t barrier; */ void *get_pi_lock(void *arg) { + struct __test_metadata *_metadata =3D (struct __test_metadata *)arg; int ret; volatile futex_t lock =3D 0; =20 ret =3D futex_lock_pi(&futex_pi, NULL, 0, 0); - if (ret !=3D 0) - ksft_exit_fail_msg("futex_lock_pi failed\n"); + ASSERT_EQ(ret, 0) + TH_LOG("futex_lock_pi failed"); =20 pthread_barrier_wait(&barrier); =20 /* Blocks forever */ ret =3D futex_wait(&lock, 0, NULL, 0); - ksft_exit_fail_msg("futex_wait failed\n"); + ASSERT_TRUE(0) + TH_LOG("futex_wait returned unexpectedly: %d", ret); =20 return NULL; } =20 -/* - * Check if the function returned the expected error - */ -static void test_timeout(int res, char *test_name, int err) -{ - if (!res || errno !=3D err) { - ksft_test_result_fail("%s returned %d\n", test_name, - res < 0 ? errno : res); - } else { - ksft_test_result_pass("%s succeeds\n", test_name); - } -} - -/* - * Calculate absolute timeout and correct overflow - */ -static int futex_get_abs_timeout(clockid_t clockid, struct timespec *to, - long timeout_ns) -{ - if (clock_gettime(clockid, to)) - ksft_exit_fail_msg("clock_gettime failed\n"); - - to->tv_nsec +=3D timeout_ns; - - if (to->tv_nsec >=3D 1000000000) { - to->tv_sec++; - to->tv_nsec -=3D 1000000000; - } - - return 0; -} +#define TEST_TIMEOUT(_res, _test_name, _err) do { \ + if ((_res) < 0 && errno =3D=3D ENOSYS && (_err) !=3D ENOSYS) { \ + SKIP(return, "%s is not supported (ENOSYS)", _test_name); \ + } \ + EXPECT_EQ((_res), -1) \ + TH_LOG("%s returned unexpected result: %d", _test_name, (_res));\ + if ((_res) =3D=3D -1) { \ + EXPECT_EQ(errno, (_err)) { \ + TH_LOG("%s returned unexpected errno: %d (expected %d)",\ + _test_name, errno, (_err)); \ + } \ + } \ +} while (0) + +#define GET_ABS_TIMEOUT(_clockid, _to, _timeout_ns) do { \ + ASSERT_EQ(clock_gettime((_clockid), (_to)), 0) \ + TH_LOG("clock_gettime failed"); \ + (_to)->tv_nsec +=3D (_timeout_ns); \ + if ((_to)->tv_nsec >=3D 1000000000) { \ + (_to)->tv_sec++; \ + (_to)->tv_nsec -=3D 1000000000; \ + } \ +} while (0) =20 TEST(wait_bitset) { @@ -90,19 +84,17 @@ TEST(wait_bitset) to.tv_nsec =3D timeout_ns; =20 res =3D futex_wait(&f1, f1, &to, 0); - test_timeout(res, "futex_wait relative", ETIMEDOUT); + TEST_TIMEOUT(res, "futex_wait relative", ETIMEDOUT); =20 /* FUTEX_WAIT_BITSET with CLOCK_REALTIME */ - if (futex_get_abs_timeout(CLOCK_REALTIME, &to, timeout_ns)) - ksft_test_result_error("get_time error"); + GET_ABS_TIMEOUT(CLOCK_REALTIME, &to, timeout_ns); res =3D futex_wait_bitset(&f1, f1, &to, 1, FUTEX_CLOCK_REALTIME); - test_timeout(res, "futex_wait_bitset realtime", ETIMEDOUT); + TEST_TIMEOUT(res, "futex_wait_bitset realtime", ETIMEDOUT); =20 /* FUTEX_WAIT_BITSET with CLOCK_MONOTONIC */ - if (futex_get_abs_timeout(CLOCK_MONOTONIC, &to, timeout_ns)) - ksft_test_result_error("get_time error"); + GET_ABS_TIMEOUT(CLOCK_MONOTONIC, &to, timeout_ns); res =3D futex_wait_bitset(&f1, f1, &to, 1, 0); - test_timeout(res, "futex_wait_bitset monotonic", ETIMEDOUT); + TEST_TIMEOUT(res, "futex_wait_bitset monotonic", ETIMEDOUT); } =20 TEST(requeue_pi) @@ -112,17 +104,14 @@ TEST(requeue_pi) int res; =20 /* FUTEX_WAIT_REQUEUE_PI with CLOCK_REALTIME */ - if (futex_get_abs_timeout(CLOCK_REALTIME, &to, timeout_ns)) - ksft_test_result_error("get_time error"); + GET_ABS_TIMEOUT(CLOCK_REALTIME, &to, timeout_ns); res =3D futex_wait_requeue_pi(&f1, f1, &futex_pi, &to, FUTEX_CLOCK_REALTIME= ); - test_timeout(res, "futex_wait_requeue_pi realtime", ETIMEDOUT); + TEST_TIMEOUT(res, "futex_wait_requeue_pi realtime", ETIMEDOUT); =20 /* FUTEX_WAIT_REQUEUE_PI with CLOCK_MONOTONIC */ - if (futex_get_abs_timeout(CLOCK_MONOTONIC, &to, timeout_ns)) - ksft_test_result_error("get_time error"); + GET_ABS_TIMEOUT(CLOCK_MONOTONIC, &to, timeout_ns); res =3D futex_wait_requeue_pi(&f1, f1, &futex_pi, &to, 0); - test_timeout(res, "futex_wait_requeue_pi monotonic", ETIMEDOUT); - + TEST_TIMEOUT(res, "futex_wait_requeue_pi monotonic", ETIMEDOUT); } =20 TEST(lock_pi) @@ -133,7 +122,8 @@ TEST(lock_pi) =20 /* Create a thread that will lock forever so any waiter will timeout */ pthread_barrier_init(&barrier, NULL, 2); - pthread_create(&thread, NULL, get_pi_lock, NULL); + ASSERT_EQ(pthread_create(&thread, NULL, get_pi_lock, _metadata), 0) + TH_LOG("pthread_create failed"); =20 /* Wait until the other thread calls futex_lock_pi() */ pthread_barrier_wait(&barrier); @@ -149,14 +139,13 @@ TEST(lock_pi) * time or your time machine) the monotonic clock value is always * smaller than realtime and the syscall will timeout immediately. */ - if (futex_get_abs_timeout(CLOCK_REALTIME, &to, timeout_ns)) - ksft_test_result_error("get_time error"); + GET_ABS_TIMEOUT(CLOCK_REALTIME, &to, timeout_ns); res =3D futex_lock_pi(&futex_pi, &to, 0, 0); - test_timeout(res, "futex_lock_pi realtime", ETIMEDOUT); + TEST_TIMEOUT(res, "futex_lock_pi realtime", ETIMEDOUT); =20 /* Test operations that don't support FUTEX_CLOCK_REALTIME */ res =3D futex_lock_pi(&futex_pi, NULL, 0, FUTEX_CLOCK_REALTIME); - test_timeout(res, "futex_lock_pi invalid timeout flag", ENOSYS); + TEST_TIMEOUT(res, "futex_lock_pi invalid timeout flag", ENOSYS); } =20 TEST(waitv) @@ -171,17 +160,18 @@ TEST(waitv) struct timespec to; int res; =20 + if (!is_futex_waitv_supported()) + SKIP(return, "futex_waitv syscall not supported"); + /* futex_waitv with CLOCK_MONOTONIC */ - if (futex_get_abs_timeout(CLOCK_MONOTONIC, &to, timeout_ns)) - ksft_test_result_error("get_time error"); + GET_ABS_TIMEOUT(CLOCK_MONOTONIC, &to, timeout_ns); res =3D futex_waitv(&waitv, 1, 0, &to, CLOCK_MONOTONIC); - test_timeout(res, "futex_waitv monotonic", ETIMEDOUT); + TEST_TIMEOUT(res, "futex_waitv monotonic", ETIMEDOUT); =20 /* futex_waitv with CLOCK_REALTIME */ - if (futex_get_abs_timeout(CLOCK_REALTIME, &to, timeout_ns)) - ksft_test_result_error("get_time error"); + GET_ABS_TIMEOUT(CLOCK_REALTIME, &to, timeout_ns); res =3D futex_waitv(&waitv, 1, 0, &to, CLOCK_REALTIME); - test_timeout(res, "futex_waitv realtime", ETIMEDOUT); + TEST_TIMEOUT(res, "futex_waitv realtime", ETIMEDOUT); } =20 TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c= b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c index 9ff936e..ab039dd 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c +++ b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c @@ -28,20 +28,20 @@ =20 #define timeout_ns 100000 =20 + TEST(futex_wait_wouldblock) { struct timespec to =3D {.tv_sec =3D 0, .tv_nsec =3D timeout_ns}; futex_t f1 =3D FUTEX_INITIALIZER; int res; =20 - ksft_print_dbg_msg("Calling futex_wait on f1: %u @ %p with val=3D%u\n", f1,= &f1, f1+1); + TH_LOG("Calling futex_wait on f1: %u @ %p with val=3D%u", f1, &f1, f1+1); res =3D futex_wait(&f1, f1+1, &to, FUTEX_PRIVATE_FLAG); - if (!res || errno !=3D EWOULDBLOCK) { - ksft_test_result_fail("futex_wait returned: %d %s\n", - res ? errno : res, - res ? strerror(errno) : ""); - } else { - ksft_test_result_pass("futex_wait\n"); + EXPECT_EQ(res, -1) + TH_LOG("futex_wait returned unexpected result: %d", res); + if (res =3D=3D -1) { + EXPECT_EQ(errno, EWOULDBLOCK) + TH_LOG("futex_wait returned unexpected errno: %d", errno); } } =20 @@ -57,8 +57,11 @@ TEST(futex_waitv_wouldblock) }; int res; =20 - if (clock_gettime(CLOCK_MONOTONIC, &to)) - ksft_exit_fail_msg("clock_gettime failed %d\n", errno); + if (!is_futex_waitv_supported()) + SKIP(return, "futex_waitv syscall not supported"); + + ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &to), 0) + TH_LOG("clock_gettime failed"); =20 to.tv_nsec +=3D timeout_ns; =20 @@ -67,14 +70,13 @@ TEST(futex_waitv_wouldblock) to.tv_nsec -=3D 1000000000; } =20 - ksft_print_dbg_msg("Calling futex_waitv on f1: %u @ %p with val=3D%u\n", f1= , &f1, f1+1); + TH_LOG("Calling futex_waitv on f1: %u @ %p with val=3D%u", f1, &f1, f1+1); res =3D futex_waitv(&waitv, 1, 0, &to, CLOCK_MONOTONIC); - if (!res || errno !=3D EWOULDBLOCK) { - ksft_test_result_fail("futex_waitv returned: %d %s\n", - res ? errno : res, - res ? strerror(errno) : ""); - } else { - ksft_test_result_pass("futex_waitv\n"); + EXPECT_EQ(res, -1) + TH_LOG("futex_waitv returned unexpected result: %d", res); + if (res =3D=3D -1) { + EXPECT_EQ(errno, EWOULDBLOCK) + TH_LOG("futex_waitv returned unexpected errno: %d", errno); } } =20 diff --git a/tools/testing/selftests/futex/functional/futex_waitv.c b/tools/t= esting/selftests/futex/functional/futex_waitv.c index b5ada9f..87645b6 100644 --- a/tools/testing/selftests/futex/functional/futex_waitv.c +++ b/tools/testing/selftests/futex/functional/futex_waitv.c @@ -25,24 +25,26 @@ static struct futex_waitv waitv[NR_FUTEXES]; u_int32_t futexes[NR_FUTEXES] =3D {0}; =20 + void *waiterfn(void *arg) { + struct __test_metadata *_metadata =3D (struct __test_metadata *)arg; struct timespec to; int res; =20 /* setting absolute timeout for futex2 */ - if (clock_gettime(CLOCK_MONOTONIC, &to)) - ksft_exit_fail_msg("gettime64 failed\n"); + ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &to), 0) + TH_LOG("gettime64 failed"); =20 to.tv_sec++; =20 res =3D futex_waitv(waitv, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC); if (res < 0) { - ksft_test_result_fail("futex_waitv returned: %d %s\n", - errno, strerror(errno)); - } else if (res !=3D NR_FUTEXES - 1) { - ksft_test_result_fail("futex_waitv returned: %d, expecting %d\n", - res, NR_FUTEXES - 1); + EXPECT_EQ(res, NR_FUTEXES - 1) + TH_LOG("futex_waitv failed: %s", strerror(errno)); + } else { + EXPECT_EQ(res, NR_FUTEXES - 1) + TH_LOG("futex_waitv returned %d, expected %d", res, NR_FUTEXES - 1); } =20 return NULL; @@ -53,6 +55,9 @@ TEST(private_waitv) pthread_t waiter; int res, i; =20 + if (!is_futex_waitv_supported()) + SKIP(return, "futex_waitv syscall not supported"); + for (i =3D 0; i < NR_FUTEXES; i++) { waitv[i].uaddr =3D (uintptr_t)&futexes[i]; waitv[i].flags =3D FUTEX_32 | FUTEX_PRIVATE_FLAG; @@ -61,19 +66,14 @@ TEST(private_waitv) } =20 /* Private waitv */ - if (pthread_create(&waiter, NULL, waiterfn, NULL)) - ksft_exit_fail_msg("pthread_create failed\n"); + ASSERT_EQ(pthread_create(&waiter, NULL, waiterfn, _metadata), 0) + TH_LOG("pthread_create failed"); =20 usleep(WAKE_WAIT_US); =20 res =3D futex_wake(u64_to_ptr(waitv[NR_FUTEXES - 1].uaddr), 1, FUTEX_PRIVAT= E_FLAG); - if (res !=3D 1) { - ksft_test_result_fail("futex_wake private returned: %d %s\n", - res ? errno : res, - res ? strerror(errno) : ""); - } else { - ksft_test_result_pass("futex_waitv private\n"); - } + EXPECT_EQ(res, 1) + TH_LOG("futex_wake private returned: %d %s", res, res < 0 ? strerror(errno= ) : ""); } =20 TEST(shared_waitv) @@ -81,15 +81,18 @@ TEST(shared_waitv) pthread_t waiter; int res, i; =20 + if (!is_futex_waitv_supported()) + SKIP(return, "futex_waitv syscall not supported"); + /* Shared waitv */ for (i =3D 0; i < NR_FUTEXES; i++) { int shm_id =3D shmget(IPC_PRIVATE, 4096, IPC_CREAT | 0666); =20 if (shm_id < 0) { if (errno =3D=3D ENOSYS) - ksft_exit_skip("shmget syscall not supported\n"); - perror("shmget"); - exit(1); + SKIP(return, "shmget syscall not supported"); + ASSERT_GE(shm_id, 0) + TH_LOG("shmget failed"); } =20 unsigned int *shared_data =3D shmat(shm_id, NULL, 0); @@ -101,19 +104,14 @@ TEST(shared_waitv) waitv[i].__reserved =3D 0; } =20 - if (pthread_create(&waiter, NULL, waiterfn, NULL)) - ksft_exit_fail_msg("pthread_create failed\n"); + ASSERT_EQ(pthread_create(&waiter, NULL, waiterfn, _metadata), 0) + TH_LOG("pthread_create failed"); =20 usleep(WAKE_WAIT_US); =20 res =3D futex_wake(u64_to_ptr(waitv[NR_FUTEXES - 1].uaddr), 1, 0); - if (res !=3D 1) { - ksft_test_result_fail("futex_wake shared returned: %d %s\n", - res ? errno : res, - res ? strerror(errno) : ""); - } else { - ksft_test_result_pass("futex_waitv shared\n"); - } + EXPECT_EQ(res, 1) + TH_LOG("futex_wake shared returned: %d %s", res, res < 0 ? strerror(errno)= : ""); =20 for (i =3D 0; i < NR_FUTEXES; i++) shmdt(u64_to_ptr(waitv[i].uaddr)); @@ -124,21 +122,23 @@ TEST(invalid_flag) struct timespec to; int res; =20 + if (!is_futex_waitv_supported()) + SKIP(return, "futex_waitv syscall not supported"); + /* Testing a waiter without FUTEX_32 flag */ waitv[0].flags =3D FUTEX_PRIVATE_FLAG; =20 - if (clock_gettime(CLOCK_MONOTONIC, &to)) - ksft_exit_fail_msg("gettime64 failed\n"); + ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &to), 0) + TH_LOG("gettime64 failed"); =20 to.tv_sec++; =20 res =3D futex_waitv(waitv, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC); if (res =3D=3D EINVAL) { - ksft_test_result_fail("futex_waitv private returned: %d %s\n", - res ? errno : res, - res ? strerror(errno) : ""); - } else { - ksft_test_result_pass("futex_waitv without FUTEX_32\n"); + EXPECT_TRUE(0) { + TH_LOG("futex_waitv private returned: %d %s", + res ? errno : res, res ? strerror(errno) : ""); + } } } =20 @@ -147,22 +147,24 @@ TEST(unaligned_address) struct timespec to; int res; =20 + if (!is_futex_waitv_supported()) + SKIP(return, "futex_waitv syscall not supported"); + /* Testing a waiter with an unaligned address */ waitv[0].flags =3D FUTEX_PRIVATE_FLAG | FUTEX_32; waitv[0].uaddr =3D 1; =20 - if (clock_gettime(CLOCK_MONOTONIC, &to)) - ksft_exit_fail_msg("gettime64 failed\n"); + ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &to), 0) + TH_LOG("gettime64 failed"); =20 to.tv_sec++; =20 res =3D futex_waitv(waitv, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC); if (res =3D=3D EINVAL) { - ksft_test_result_fail("futex_wake private returned: %d %s\n", - res ? errno : res, - res ? strerror(errno) : ""); - } else { - ksft_test_result_pass("futex_waitv with an unaligned address\n"); + EXPECT_TRUE(0) { + TH_LOG("futex_wake private returned: %d %s", + res ? errno : res, res ? strerror(errno) : ""); + } } } =20 @@ -171,36 +173,37 @@ TEST(null_address) struct timespec to; int res; =20 + if (!is_futex_waitv_supported()) + SKIP(return, "futex_waitv syscall not supported"); + /* Testing a NULL address for waiters.uaddr */ waitv[0].uaddr =3D 0x00000000; =20 - if (clock_gettime(CLOCK_MONOTONIC, &to)) - ksft_exit_fail_msg("gettime64 failed\n"); + ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &to), 0) + TH_LOG("gettime64 failed"); =20 to.tv_sec++; =20 res =3D futex_waitv(waitv, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC); if (res =3D=3D EINVAL) { - ksft_test_result_fail("futex_waitv private returned: %d %s\n", - res ? errno : res, - res ? strerror(errno) : ""); - } else { - ksft_test_result_pass("futex_waitv NULL address in waitv.uaddr\n"); + EXPECT_TRUE(0) { + TH_LOG("futex_waitv private returned: %d %s", + res ? errno : res, res ? strerror(errno) : ""); + } } =20 /* Testing a NULL address for *waiters */ - if (clock_gettime(CLOCK_MONOTONIC, &to)) - ksft_exit_fail_msg("gettime64 failed\n"); + ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &to), 0) + TH_LOG("gettime64 failed"); =20 to.tv_sec++; =20 res =3D futex_waitv(NULL, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC); if (res =3D=3D EINVAL) { - ksft_test_result_fail("futex_waitv private returned: %d %s\n", - res ? errno : res, - res ? strerror(errno) : ""); - } else { - ksft_test_result_pass("futex_waitv NULL address in *waiters\n"); + EXPECT_TRUE(0) { + TH_LOG("futex_waitv private returned: %d %s", + res ? errno : res, res ? strerror(errno) : ""); + } } } =20 @@ -209,19 +212,21 @@ TEST(invalid_clockid) struct timespec to; int res; =20 + if (!is_futex_waitv_supported()) + SKIP(return, "futex_waitv syscall not supported"); + /* Testing an invalid clockid */ - if (clock_gettime(CLOCK_MONOTONIC, &to)) - ksft_exit_fail_msg("gettime64 failed\n"); + ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &to), 0) + TH_LOG("gettime64 failed"); =20 to.tv_sec++; =20 res =3D futex_waitv(NULL, NR_FUTEXES, 0, &to, CLOCK_TAI); if (res =3D=3D EINVAL) { - ksft_test_result_fail("futex_waitv private returned: %d %s\n", - res ? errno : res, - res ? strerror(errno) : ""); - } else { - ksft_test_result_pass("futex_waitv invalid clockid\n"); + EXPECT_TRUE(0) { + TH_LOG("futex_waitv private returned: %d %s", + res ? errno : res, res ? strerror(errno) : ""); + } } } =20 diff --git a/tools/testing/selftests/futex/include/futex2test.h b/tools/testi= ng/selftests/futex/include/futex2test.h index 1f625b3..53e88b6 100644 --- a/tools/testing/selftests/futex/include/futex2test.h +++ b/tools/testing/selftests/futex/include/futex2test.h @@ -5,7 +5,9 @@ * Copyright 2021 Collabora Ltd. */ #include +#include #include +#include =20 #define u64_to_ptr(x) ((void *)(uintptr_t)(x)) =20 @@ -96,3 +98,11 @@ static inline int futex2_wake(void *uaddr, int nr, unsigne= d int flags) { return syscall(__NR_futex_wake, uaddr, ~0U, nr, flags); } + +static inline bool is_futex_waitv_supported(void) +{ + struct timespec ts =3D {0, 0}; + int res =3D futex_waitv(NULL, 0, 0, &ts, CLOCK_MONOTONIC); + + return !(res < 0 && errno =3D=3D ENOSYS); +}