From nobody Mon Jun 8 23:56:07 2026 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA1DD3D6478 for ; Mon, 25 May 2026 07:57:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779695878; cv=none; b=rJ2eDN7bc/l9xaVkyT4KhqtvhS2+OPW6b0Qo09PCQziDNMe2wMAyLlU87v6pnjBIguy6JvOVKebsPrQ6XmTqVtzdjEdIlFx1kLuQIZP95lLqckpQpD4tKb4zBH2tREqmsoDEv6Rcg8Xwu9cEmqJl5dR8FNY+EAsAnvNPwOz0tkk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779695878; c=relaxed/simple; bh=Fm0Q5rNLUWf70hf1lVlbcS4AwYsaTNnXQCuOTXjviFs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jjy3DUU5afhQFt1MLPMRhc9qGtZ23SKETdPhjej3vp8TBV5kwBazk602KaEW84Y5dd7KlyKFVg3pnT0IdFmfjMQ14kJKdwZT26yWlJxHa7HxuarKFNMMVyuo68HXFYb0XMVoVVnUlnrHJnUvFPu4iQccJb9AgXfIi+5cY0Ttek0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--wakel.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=E4/Gx04b; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--wakel.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="E4/Gx04b" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-82fd55bf6cdso5729754b3a.3 for ; Mon, 25 May 2026 00:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779695876; x=1780300676; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=88My9DadzWJkWbkzxXj+e+x5l1Xi5DIoGj+mqLUxaRc=; b=E4/Gx04b1M1zoYtQvmlGpT1P67R0nHnbD40TNiQJndZplCPhuQ7vPABs+i8HwYw2Iz v09NygLHD4QGf7JecAxB4gjiaOVYkyxJziVFBSq4VcokklBXPE9tSXe+9VSansQvSwlm NMAHgjIskZZalntFwAoHH4gGRe6uTVd35oWAjQLly+zmqWqPXYuUFa20M5IgIPZqHXY8 dU6TCTHXbuCIZJdKZqNl/u91esXDDgxGftbOxKwmwraNZy0br4nbZU5v7EzW3Yb/qzaQ C555nKDJxrwhIJCAU3+rrMdcyfRoVukr9AuT2b0jKTV260HgY/asm2LadtxfWQ2TZ4ef rROQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779695876; x=1780300676; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=88My9DadzWJkWbkzxXj+e+x5l1Xi5DIoGj+mqLUxaRc=; b=Z/C57Qn4XauOpLNqA+JhUOrL9ZDbE0QuLt/6LNPIUSctV1cb1oh+GBxstEIOrErib+ i1csTkNIZwxmZ4HStvMoASkvHr6L76WXj+KokpB1pFgkOkA/1HYR0XO2RYNzt7pysz0r SS7Xr+U+jLj8rTMXwHS2jlKw8A+//Dv5uYO2pjbGtFGZH8pZq/Ewz0lgYuAoqOw9oftG TTYrFi971ULwAATU+b9VvgMQ38eqn6opeynNSanQu85TdhZZeg+PtVdUWyt7vF+LpTAd zYURSvs1s4xyvFNZKtdYpgh9VOpGkGZo0Tcvjlrtyb0hVVj8y384UzS0GxOcN9O87TG+ 1FOg== X-Forwarded-Encrypted: i=1; AFNElJ8G9IP7th7SbnAuVbdjTHYrQmbBeV4SzhNXjHa5YImKUgPGoCsUzmSKxiJRJo3QP2XZb9apVcnzi1GZ05A=@vger.kernel.org X-Gm-Message-State: AOJu0YxlaBDgFyltrQtcvro5O6DFQbKl98mh/8wWFCCYO2/m/bJuFOF1 HwFZr5oMO9iuZ3k2hsbvLczC02dHgXP6y2bHB8En1Oo3BbzS/yWSzSdNRhdn33t/PuZNyjnYqWZ ySg== X-Received: from pfnc20.prod.google.com ([2002:aa7:81d4:0:b0:829:7f86:623]) (user=wakel job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:240b:b0:835:3f51:72f8 with SMTP id d2e1a72fcca58-8415f5db6c5mr12314294b3a.18.1779695875849; Mon, 25 May 2026 00:57:55 -0700 (PDT) Date: Mon, 25 May 2026 07:57:47 +0000 In-Reply-To: <20260525075748.3720995-1-wakel@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260525075748.3720995-1-wakel@google.com> X-Mailer: git-send-email 2.54.0.746.g67dd491aae-goog Message-ID: <20260525075748.3720995-2-wakel@google.com> Subject: [PATCH 1/2] selftests/futex: Migrate functional tests to harness From: Wake Liu To: Thomas Gleixner , Ingo Molnar , Shuah Khan , linux-kselftest@vger.kernel.org Cc: Peter Zijlstra , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Carlos Llamas , Edward Liaw , linux-kernel@vger.kernel.org, wakel@google.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Wake Liu --- .../futex/functional/futex_wait_timeout.c | 101 +++++++---------- .../futex/functional/futex_wait_wouldblock.c | 40 ++++--- .../selftests/futex/functional/futex_waitv.c | 107 +++++++++--------- 3 files changed, 118 insertions(+), 130 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_wait_timeout.c = b/tools/testing/selftests/futex/functional/futex_wait_timeout.c index 674dd13af421..89d6a7daeda4 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_timeout.c +++ b/tools/testing/selftests/futex/functional/futex_wait_timeout.c @@ -31,53 +31,43 @@ 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 fail= ed"); \ + (_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 +80,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 +100,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_REALTI= ME); - 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 +118,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 +135,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) @@ -172,16 +157,14 @@ TEST(waitv) int res; =20 /* 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 9ff936ecf164..4fd517404f1f 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c +++ b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c @@ -28,21 +28,26 @@ =20 #define timeout_ns 100000 =20 +static 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); +} + 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", f= 1, &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", re= s); + if (res =3D=3D -1) + EXPECT_EQ(errno, EWOULDBLOCK) + TH_LOG("futex_wait returned unexpected errno: %d", errno); } =20 TEST(futex_waitv_wouldblock) @@ -57,8 +62,10 @@ 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 f= ailed"); =20 to.tv_nsec +=3D timeout_ns; =20 @@ -67,15 +74,12 @@ 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", r= es); + if (res =3D=3D -1) + EXPECT_EQ(errno, EWOULDBLOCK) + TH_LOG("futex_waitv returned unexpected errno: %d", errno); } =20 TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/futex/functional/futex_waitv.c b/tools= /testing/selftests/futex/functional/futex_waitv.c index b5ada9fdb26f..7bed76a1caed 100644 --- a/tools/testing/selftests/futex/functional/futex_waitv.c +++ b/tools/testing/selftests/futex/functional/futex_waitv.c @@ -25,24 +25,31 @@ static struct futex_waitv waitv[NR_FUTEXES]; u_int32_t futexes[NR_FUTEXES] =3D {0}; =20 +static 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); +} + 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 faile= d"); =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 +60,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 +71,15 @@ 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_PRIV= ATE_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 +87,17 @@ 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 +109,15 @@ 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 +128,21 @@ 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 faile= d"); =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", + EXPECT_TRUE(0) TH_LOG("futex_waitv private returned: %d %s", res ? errno : res, res ? strerror(errno) : ""); - } else { - ksft_test_result_pass("futex_waitv without FUTEX_32\n"); } } =20 @@ -147,22 +151,22 @@ 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 faile= d"); =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", + EXPECT_TRUE(0) TH_LOG("futex_wake private returned: %d %s", res ? errno : res, res ? strerror(errno) : ""); - } else { - ksft_test_result_pass("futex_waitv with an unaligned address\n"); } } =20 @@ -171,36 +175,33 @@ 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 faile= d"); =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", + EXPECT_TRUE(0) TH_LOG("futex_waitv private returned: %d %s", res ? errno : res, res ? strerror(errno) : ""); - } else { - ksft_test_result_pass("futex_waitv NULL address in waitv.uaddr\n"); } =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 faile= d"); =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", + EXPECT_TRUE(0) TH_LOG("futex_waitv private returned: %d %s", res ? errno : res, res ? strerror(errno) : ""); - } else { - ksft_test_result_pass("futex_waitv NULL address in *waiters\n"); } } =20 @@ -209,19 +210,19 @@ 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 faile= d"); =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", + EXPECT_TRUE(0) TH_LOG("futex_waitv private returned: %d %s", res ? errno : res, res ? strerror(errno) : ""); - } else { - ksft_test_result_pass("futex_waitv invalid clockid\n"); } } =20 --=20 2.54.0.746.g67dd491aae-goog From nobody Mon Jun 8 23:56:07 2026 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64EF73D5661 for ; Mon, 25 May 2026 07:57:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779695881; cv=none; b=hfxWPRpysuCm96zwB5845C/3uhogAzED4hfupZP3aczrJRwVlyeLYu2y7UxxDM8ZdJp+e1FFr7Tg2xVkPOG8Cjm0GXbDuiuE8VJRuS6bXppYEp3pkM3htNfknPsb5u2lil+o/YU20Bt94+u5qd6/wXDKxUPJNpoRT5KlggiRCMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779695881; c=relaxed/simple; bh=fbvLfcz5OT2LfqTOnVqPrV1GxfwNPFKnYVcQ4s0lcrY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pKbUfmLkInypnMIAVpu4aQSBEoldfqTxe5enTrBsxSQG5l5nGgQeuiKHsZVGQnACUH8+jPVmfN0jb7InKCnncm844VdbZkA93ONecAx9rLgUaXorwiWEreZgAskbkuyGZzYfGvcTONN2yux24eVr8KYw0m0xDO6i4aGb6qyutyM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--wakel.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=d57cTJPQ; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--wakel.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="d57cTJPQ" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-c827adbf00cso4059864a12.2 for ; Mon, 25 May 2026 00:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779695879; x=1780300679; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ffj7eFdWHqWW/R+dY3OxqwXEtgbaXV+LozfSiunZvv8=; b=d57cTJPQDwUwQsKl6DVUvJcwPme/xC2D+/vn4ALKkv7BoRU18EsM7xI5M8nwwBOVQQ uEk1xX88S5nGJYKyHxpy5EEeMzMPA83Q2UiXwCfszgT2Y/u5a1ihWmtDyJ8BR21IzaVO FDZdLUrtR6CUh5M6aGfHyBp9hA+O14OewTSZVV7lVWPqI5/qfiMIN2opHLWxSdc/lW3l OLBPXrp/RiuOK+J544Xt62Rx6Enl+Kz4KE49IO5kUfvrT0rwjXC8cUKDv3LjVgZAwcZP /uron7g9AFRD49PLXU3fqNmNxzKZbKJ5ksL3Q3YRWtsR0XjUYU1Jp4NVw0gv/GciuLk1 TiqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779695879; x=1780300679; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ffj7eFdWHqWW/R+dY3OxqwXEtgbaXV+LozfSiunZvv8=; b=jQ1S8p9uTgVVPyp7uAgik+l+z49PWjx491bgGc+UoDS7pm8TdlBlx/sxM5HlzVlRsy vjxnbvpwyBgff8MBbbUa3qh/85VGSuP7n1ujp5aNYYTd4bWc64BtBXEcQPimurYBOIxo NR0HbIQkSlR775LfD5yxf6ewf3BiP2p5Gs4pHEPQm0F/UrfQTwRpFBhmGV6Tj+Wgdw05 KeafqLght31+7MxIcXJSGYzLShLBjyNrmUFmUNCje8zTbfeTZXMox0qCaz6K2B3Y+ZGA 4AlutzjOB+EmNMVup6AAdsc/1u8m8+XBZyuvqSQ6HZL8yws4LuOk2nIK5rNSbQhlpDWY CO2w== X-Forwarded-Encrypted: i=1; AFNElJ/j5tHy2Gj+mXdksLGYvbhMLahyuqE57Kb5NYV2iVUA1tP94oidpCwEBuANV+g9UtKFpNsyOTOEVN0IOSU=@vger.kernel.org X-Gm-Message-State: AOJu0Ywn9Lz5zgJSqp0ykLoEF3Euq2siLQ7Tm/5qNUBhxOAbULiKqOtm iIT0MGYOIclqkQdtxrEfwWLU9Sjm8F85jqgac7ll3+EcEMFymjpl8GvMWoJIha+IgmOaP0nu/Po XUA== X-Received: from pfbgg15.prod.google.com ([2002:a05:6a00:630f:b0:837:c7f5:5c27]) (user=wakel job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3d0d:b0:83f:250d:5ab with SMTP id d2e1a72fcca58-8415f3a79f7mr12477853b3a.7.1779695878171; Mon, 25 May 2026 00:57:58 -0700 (PDT) Date: Mon, 25 May 2026 07:57:48 +0000 In-Reply-To: <20260525075748.3720995-1-wakel@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260525075748.3720995-1-wakel@google.com> X-Mailer: git-send-email 2.54.0.746.g67dd491aae-goog Message-ID: <20260525075748.3720995-3-wakel@google.com> Subject: [PATCH 2/2] selftests/futex: Correct validation logic in waitv From: Wake Liu To: Thomas Gleixner , Ingo Molnar , Shuah Khan , linux-kselftest@vger.kernel.org Cc: Peter Zijlstra , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" , Carlos Llamas , Edward Liaw , linux-kernel@vger.kernel.org, wakel@google.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In futex_waitv negative tests (invalid_flag, unaligned_address, etc.), test results were previously evaluated as: if (res =3D=3D EINVAL) Since sys_futex_waitv returns -1 on error and sets errno, direct positive comparisons against res are always false, causing tests to silently pass regardless of real errors. Correct these validations to assert EXPECT_EQ(res, -1) and compare errno directly against expected constants. Signed-off-by: Wake Liu --- .../selftests/futex/functional/futex_waitv.c | 45 +++++++++---------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_waitv.c b/tools= /testing/selftests/futex/functional/futex_waitv.c index 7bed76a1caed..9dc0f9c1f22a 100644 --- a/tools/testing/selftests/futex/functional/futex_waitv.c +++ b/tools/testing/selftests/futex/functional/futex_waitv.c @@ -139,11 +139,10 @@ TEST(invalid_flag) to.tv_sec++; =20 res =3D futex_waitv(waitv, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC); - if (res =3D=3D EINVAL) { - EXPECT_TRUE(0) TH_LOG("futex_waitv private returned: %d %s", - res ? errno : res, - res ? strerror(errno) : ""); - } + EXPECT_EQ(res, -1) TH_LOG("futex_waitv returned unexpected result: %d", r= es); + if (res =3D=3D -1) + EXPECT_EQ(errno, EINVAL) + TH_LOG("futex_waitv returned unexpected errno: %d", errno); } =20 TEST(unaligned_address) @@ -163,11 +162,10 @@ TEST(unaligned_address) to.tv_sec++; =20 res =3D futex_waitv(waitv, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC); - if (res =3D=3D EINVAL) { - EXPECT_TRUE(0) TH_LOG("futex_wake private returned: %d %s", - res ? errno : res, - res ? strerror(errno) : ""); - } + EXPECT_EQ(res, -1) TH_LOG("futex_waitv returned unexpected result: %d", r= es); + if (res =3D=3D -1) + EXPECT_EQ(errno, EINVAL) + TH_LOG("futex_waitv returned unexpected errno: %d", errno); } =20 TEST(null_address) @@ -186,11 +184,10 @@ TEST(null_address) to.tv_sec++; =20 res =3D futex_waitv(waitv, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC); - if (res =3D=3D EINVAL) { - EXPECT_TRUE(0) TH_LOG("futex_waitv private returned: %d %s", - res ? errno : res, - res ? strerror(errno) : ""); - } + EXPECT_EQ(res, -1) TH_LOG("futex_waitv returned unexpected result: %d", r= es); + if (res =3D=3D -1) + EXPECT_EQ(errno, EINVAL) + TH_LOG("futex_waitv returned unexpected errno: %d", errno); =20 /* Testing a NULL address for *waiters */ ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &to), 0) TH_LOG("gettime64 faile= d"); @@ -198,11 +195,10 @@ TEST(null_address) to.tv_sec++; =20 res =3D futex_waitv(NULL, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC); - if (res =3D=3D EINVAL) { - EXPECT_TRUE(0) TH_LOG("futex_waitv private returned: %d %s", - res ? errno : res, - res ? strerror(errno) : ""); - } + EXPECT_EQ(res, -1) TH_LOG("futex_waitv returned unexpected result: %d", r= es); + if (res =3D=3D -1) + EXPECT_EQ(errno, EINVAL) + TH_LOG("futex_waitv returned unexpected errno: %d", errno); } =20 TEST(invalid_clockid) @@ -219,11 +215,10 @@ TEST(invalid_clockid) to.tv_sec++; =20 res =3D futex_waitv(NULL, NR_FUTEXES, 0, &to, CLOCK_TAI); - if (res =3D=3D EINVAL) { - EXPECT_TRUE(0) TH_LOG("futex_waitv private returned: %d %s", - res ? errno : res, - res ? strerror(errno) : ""); - } + EXPECT_EQ(res, -1) TH_LOG("futex_waitv returned unexpected result: %d", r= es); + if (res =3D=3D -1) + EXPECT_EQ(errno, EINVAL) + TH_LOG("futex_waitv returned unexpected errno: %d", errno); } =20 TEST_HARNESS_MAIN --=20 2.54.0.746.g67dd491aae-goog