From nobody Tue Oct 7 22:39:43 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 2F9D119D8AC; Fri, 4 Jul 2025 15:05:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641533; cv=none; b=O520HZMo+usRkteu9Mu8KDl70HhzFHfA8QbUHXFpNoV+soxSx9vLWyKvzkYsm1DrPALOo+bl9i93JPrEFgezeGFNLbbYi2eym9tzYbh+Cv4GyoUoZhgc/e82VR2ntvDCjl2OFUAYQHGM791ia0xoqN9By4ltoP8LIIIK9+8JP4Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641533; c=relaxed/simple; bh=j+RakyHfBrc5c31QGIaVZaaPgN5WHp7gFZxGVt0DHLM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ycio9IsIrqZGBhuz6WRpA+ROye2scqKYDwsk/t0yQqetzGgVPq6llATEMr9K7kbUjdhWmQOLo5BKBw3taRjT8VIyuY6H+bdp6BFwtTiHoWL09YSsQAJSqRld6pJS6MM2rdE1R+Z/ks1u5OzqFH8k4SMCYnqJr3WaCefAOCTeddo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=YQsUH1Zm; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="YQsUH1Zm" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Y6+NkMRepGY1gqY9rbInC2ai3AVkY+ZEWltP4xkiMBU=; b=YQsUH1Zmxt1ovqzpCYxCKIAX4L VbCpggpnzXSOwmF+tZmOWCLSyi3yt9NVyn2x77+FbaXwJDt9u0EH1n1cYyTTvvoD6iE/09j3nQ7Kf zCBFUPxOyeOx8tRm2BtUD8RgKQliL1exB9nvWkgqOdJkmEQjsEixuEvoUEXZdSGFoSdorV7SJkFsO Xmnp/8JpJq2QYIYvzR/C22msiu/4Xj5uHxb+/2gbFQlkQoRaSYwSqwdQ9V34c93qXUaMrzH7+IGbo jvocn/FB1tSTFh5b/97uKS7oKqzfQ9r2mGeRk8lKOlDP/PcZVUPzABdi74uRYNC4FQteFMxapuCUI xIGdpsDw==; Received: from [179.100.5.63] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uXhyh-00CTWt-T9; Fri, 04 Jul 2025 17:05:28 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 04 Jul 2025 12:05:05 -0300 Subject: [PATCH 01/15] selftests: kselftest: Create ksft_print_dbg_msg() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-tonyk-robust_test_cleanup-v1-1-c0ff4f24c4e1@igalia.com> References: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> In-Reply-To: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Sebastian Andrzej Siewior Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 Create ksft_print_dbg_msg() so testers can enable extra debug messages when running a test with the flag -d. Signed-off-by: Andr=C3=A9 Almeida --- tools/testing/selftests/kselftest.h | 13 +++++++++++++ tools/testing/selftests/kselftest_harness.h | 13 +++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/= kselftest.h index c3b6d2604b1e486af5a224a11386f75fe0a83495..c1851125de9cfdcdf3b11249572= ebfb0751727f6 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -104,6 +104,7 @@ struct ksft_count { =20 static struct ksft_count ksft_cnt; static unsigned int ksft_plan; +static bool ksft_debug_enabled; =20 static inline unsigned int ksft_test_num(void) { @@ -175,6 +176,18 @@ static inline __printf(1, 2) void ksft_print_msg(const= char *msg, ...) va_end(args); } =20 +static inline void ksft_print_dbg_msg(const char *msg, ...) +{ + va_list args; + + if (!ksft_debug_enabled) + return; + + va_start(args, msg); + ksft_print_msg(msg, args); + va_end(args); +} + static inline void ksft_perror(const char *msg) { ksft_print_msg("%s: %s (%d)\n", msg, strerror(errno), errno); diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/se= lftests/kselftest_harness.h index 2925e47db995d7197ed1f55bd9cc657669df9bd3..ffefd2704ca8f60f329b5d85870= 253fe26c61b52 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -1091,7 +1091,7 @@ static int test_harness_argv_check(int argc, char **a= rgv) { int opt; =20 - while ((opt =3D getopt(argc, argv, "hlF:f:V:v:t:T:r:")) !=3D -1) { + while ((opt =3D getopt(argc, argv, "dhlF:f:V:v:t:T:r:")) !=3D -1) { switch (opt) { case 'f': case 'F': @@ -1104,12 +1104,16 @@ static int test_harness_argv_check(int argc, char *= *argv) case 'l': test_harness_list_tests(); return KSFT_SKIP; + case 'd': + ksft_debug_enabled =3D true; + break; case 'h': default: fprintf(stderr, - "Usage: %s [-h|-l] [-t|-T|-v|-V|-f|-F|-r name]\n" + "Usage: %s [-h|-l|-d] [-t|-T|-v|-V|-f|-F|-r name]\n" "\t-h print help\n" "\t-l list all tests\n" + "\t-d enable debug prints\n" "\n" "\t-t name include test\n" "\t-T name exclude test\n" @@ -1142,8 +1146,9 @@ static bool test_enabled(int argc, char **argv, int opt; =20 optind =3D 1; - while ((opt =3D getopt(argc, argv, "F:f:V:v:t:T:r:")) !=3D -1) { - has_positive |=3D islower(opt); + while ((opt =3D getopt(argc, argv, "dF:f:V:v:t:T:r:")) !=3D -1) { + if (opt !=3D 'd') + has_positive |=3D islower(opt); =20 switch (tolower(opt)) { case 't': --=20 2.49.0 From nobody Tue Oct 7 22:39:43 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 119981DED70; Fri, 4 Jul 2025 15:05:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641536; cv=none; b=I2h+4v+7iQNvXKlSgc+b4bQuL5kJPjLUtsFdI0UT+SgvWjKcvrE3Pz3zmuWSpRKG+NT6Q/5scPP/+w+/3YmLw8bcSD34IANUj1WBEGan5n1O8y3cAqhefv1AGGWRoYglX8U6S+ifqURZba3VtoGb9vM1q9VR+/QPKLQZj7fJz1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641536; c=relaxed/simple; bh=HaMlRYLGZJyUcjXuBh9S6PjkE2KAFYjDapvdOX8MFvA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CUhaojKYCRzHupVm7FIY5ivqqQ0NTUIrMBGLXfpq50oFSCZnKYnB+fdu8+BbRdMXBnTb6llLIsgQGEYl9ynfHJbIsJQMEZLks6MpsgupRn4JLdqtEfx7UYIk09M+UP99lvFbm8McxG6rHOkVVLjOZ9cvQ4NL5hDB4T1gbVC5RJY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=PqJKicOI; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="PqJKicOI" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=nIBIygsG7+Nfm0jcmAIQgjYPqNEyw7bqaTOP/Q0WnOo=; b=PqJKicOIcI5hXKpxrqphIbJJWo I0486vvb2ktK0uZjsi7PvFSmICXW8o43K5kmpXjLrX6F8fe6IFa2CADYshmsHP6LlWGWRCc16ND+f EcxK2VSea8z4Nk4QATM6yecZ7034rVReasDEHCwgDk4WbMdlaWsEbQDFXomfy0VheO+1JdheY/6pr 2Tjp4I9WrNp01lN1IKQzasa+3cuCSWcC8cZh3gEcc/C39wgDbMr0AIPnKpQqEHTgC2+dk6KkFGgxq W3IH42QGXe76eNVddZ6F1loNsiSsHYt5bE1JH2LcA4GNwcw9pArE/xlkjbShOtfAHaLfCWM5SfXKp tA+GDynA==; Received: from [179.100.5.63] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uXhyk-00CTWt-Ia; Fri, 04 Jul 2025 17:05:30 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 04 Jul 2025 12:05:06 -0300 Subject: [PATCH 02/15] selftests/futex: Refactor futex_requeue_pi with kselftest_harness.h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-tonyk-robust_test_cleanup-v1-2-c0ff4f24c4e1@igalia.com> References: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> In-Reply-To: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Sebastian Andrzej Siewior Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 To reduce the boilerplate code, refactor futex_requeue_pi test to use kselftest_harness header instead of futex's logging header. Use kselftest fixture feature to make it easy to repeat the same test with different parameters. With that, drop all repetitive test calls from run.sh. Signed-off-by: Andr=C3=A9 Almeida --- .../selftests/futex/functional/futex_requeue_pi.c | 261 ++++++++++-------= ---- tools/testing/selftests/futex/functional/run.sh | 26 +- 2 files changed, 122 insertions(+), 165 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi.c b/= tools/testing/selftests/futex/functional/futex_requeue_pi.c index 215c6cb539b4abc7a48fb00b545ae26e52fd118a..699642f08a5d1324984ca94082c= b040c04a97496 100644 --- a/tools/testing/selftests/futex/functional/futex_requeue_pi.c +++ b/tools/testing/selftests/futex/functional/futex_requeue_pi.c @@ -26,11 +26,11 @@ #include #include #include + #include "atomic.h" #include "futextest.h" -#include "logging.h" +#include "../../kselftest_harness.h" =20 -#define TEST_NAME "futex-requeue-pi" #define MAX_WAKE_ITERS 1000 #define THREAD_MAX 10 #define SIGNAL_PERIOD_US 100 @@ -42,12 +42,6 @@ futex_t f1 =3D FUTEX_INITIALIZER; futex_t f2 =3D FUTEX_INITIALIZER; futex_t wake_complete =3D FUTEX_INITIALIZER; =20 -/* Test option defaults */ -static long timeout_ns; -static int broadcast; -static int owner; -static int locked; - struct thread_arg { long id; struct timespec *timeout; @@ -56,18 +50,73 @@ struct thread_arg { }; #define THREAD_ARG_INITIALIZER { 0, NULL, 0, 0 } =20 -void usage(char *prog) +FIXTURE(args) { - printf("Usage: %s\n", prog); - printf(" -b Broadcast wakeup (all waiters)\n"); - printf(" -c Use color\n"); - printf(" -h Display this help message\n"); - printf(" -l Lock the pi futex across requeue\n"); - printf(" -o Use a third party pi futex owner during requeue (cancels -l)= \n"); - printf(" -t N Timeout in nanoseconds (default: 0)\n"); - printf(" -v L Verbosity level: %d=3DQUIET %d=3DCRITICAL %d=3DINFO\n", - VQUIET, VCRITICAL, VINFO); -} +}; + +FIXTURE_SETUP(args) +{ +}; + +FIXTURE_TEARDOWN(args) +{ +}; + +FIXTURE_VARIANT(args) +{ + long timeout_ns; + bool broadcast; + bool owner; + bool locked; +}; + +/* + * For a given timeout value, this macro creates a test input with all the + * possible combinations of valid arguments + */ +#define FIXTURE_VARIANT_ADD_TIMEOUT(timeout) \ + \ +FIXTURE_VARIANT_ADD(args, t_##timeout) \ +{ \ + .timeout_ns =3D timeout, \ +}; \ + \ +FIXTURE_VARIANT_ADD(args, t_##timeout##_broadcast) \ +{ \ + .timeout_ns =3D timeout, \ + .broadcast =3D true, \ +}; \ + \ +FIXTURE_VARIANT_ADD(args, t_##timeout##_broadcast_locked) \ +{ \ + .timeout_ns =3D timeout, \ + .broadcast =3D true, \ + .locked =3D true, \ +}; \ + \ +FIXTURE_VARIANT_ADD(args, t_##timeout##_broadcast_owner) \ +{ \ + .timeout_ns =3D timeout, \ + .broadcast =3D true, \ + .owner =3D true, \ +}; \ + \ +FIXTURE_VARIANT_ADD(args, t_##timeout##_locked) \ +{ \ + .timeout_ns =3D timeout, \ + .locked =3D true, \ +}; \ + \ +FIXTURE_VARIANT_ADD(args, t_##timeout##_owner) \ +{ \ + .timeout_ns =3D timeout, \ + .owner =3D true, \ +}; \ + +FIXTURE_VARIANT_ADD_TIMEOUT(0); +FIXTURE_VARIANT_ADD_TIMEOUT(5000); +FIXTURE_VARIANT_ADD_TIMEOUT(500000); +FIXTURE_VARIANT_ADD_TIMEOUT(2000000000); =20 int create_rt_thread(pthread_t *pth, void*(*func)(void *), void *arg, int policy, int prio) @@ -81,26 +130,26 @@ int create_rt_thread(pthread_t *pth, void*(*func)(void= *), void *arg, =20 ret =3D pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); if (ret) { - error("pthread_attr_setinheritsched\n", ret); + ksft_exit_fail_msg("pthread_attr_setinheritsched\n"); return -1; } =20 ret =3D pthread_attr_setschedpolicy(&attr, policy); if (ret) { - error("pthread_attr_setschedpolicy\n", ret); + ksft_exit_fail_msg("pthread_attr_setschedpolicy\n"); return -1; } =20 schedp.sched_priority =3D prio; ret =3D pthread_attr_setschedparam(&attr, &schedp); if (ret) { - error("pthread_attr_setschedparam\n", ret); + ksft_exit_fail_msg("pthread_attr_setschedparam\n"); return -1; } =20 ret =3D pthread_create(pth, &attr, func, arg); if (ret) { - error("pthread_create\n", ret); + ksft_exit_fail_msg("pthread_create\n"); return -1; } return 0; @@ -112,7 +161,7 @@ void *waiterfn(void *arg) struct thread_arg *args =3D (struct thread_arg *)arg; futex_t old_val; =20 - info("Waiter %ld: running\n", args->id); + ksft_print_dbg_msg("Waiter %ld: running\n", args->id); /* Each thread sleeps for a different amount of time * This is to avoid races, because we don't lock the * external mutex here */ @@ -120,26 +169,25 @@ void *waiterfn(void *arg) =20 old_val =3D f1; atomic_inc(&waiters_blocked); - info("Calling futex_wait_requeue_pi: %p (%u) -> %p\n", + ksft_print_dbg_msg("Calling futex_wait_requeue_pi: %p (%u) -> %p\n", &f1, f1, &f2); args->ret =3D futex_wait_requeue_pi(&f1, old_val, &f2, args->timeout, FUTEX_PRIVATE_FLAG); =20 - info("waiter %ld woke with %d %s\n", args->id, args->ret, + ksft_print_dbg_msg("waiter %ld woke with %d %s\n", args->id, args->ret, args->ret < 0 ? strerror(errno) : ""); atomic_inc(&waiters_woken); if (args->ret < 0) { if (args->timeout && errno =3D=3D ETIMEDOUT) args->ret =3D 0; else { - args->ret =3D RET_ERROR; - error("futex_wait_requeue_pi\n", errno); + ksft_exit_fail_msg("futex_wait_requeue_pi\n"); } futex_lock_pi(&f2, NULL, 0, FUTEX_PRIVATE_FLAG); } futex_unlock_pi(&f2, FUTEX_PRIVATE_FLAG); =20 - info("Waiter %ld: exiting with %d\n", args->id, args->ret); + ksft_print_dbg_msg("Waiter %ld: exiting with %d\n", args->id, args->ret); pthread_exit((void *)&args->ret); } =20 @@ -152,14 +200,14 @@ void *broadcast_wakerfn(void *arg) int nr_wake =3D 1; int i =3D 0; =20 - info("Waker: waiting for waiters to block\n"); + ksft_print_dbg_msg("Waker: waiting for waiters to block\n"); while (waiters_blocked.val < THREAD_MAX) usleep(1000); usleep(1000); =20 - info("Waker: Calling broadcast\n"); + ksft_print_dbg_msg("Waker: Calling broadcast\n"); if (args->lock) { - info("Calling FUTEX_LOCK_PI on mutex=3D%x @ %p\n", f2, &f2); + ksft_print_dbg_msg("Calling FUTEX_LOCK_PI on mutex=3D%x @ %p\n", f2, &f2= ); futex_lock_pi(&f2, NULL, 0, FUTEX_PRIVATE_FLAG); } continue_requeue: @@ -167,16 +215,14 @@ void *broadcast_wakerfn(void *arg) args->ret =3D futex_cmp_requeue_pi(&f1, old_val, &f2, nr_wake, nr_requeue, FUTEX_PRIVATE_FLAG); if (args->ret < 0) { - args->ret =3D RET_ERROR; - error("FUTEX_CMP_REQUEUE_PI failed\n", errno); + ksft_exit_fail_msg("FUTEX_CMP_REQUEUE_PI failed\n"); } else if (++i < MAX_WAKE_ITERS) { task_count +=3D args->ret; if (task_count < THREAD_MAX - waiters_woken.val) goto continue_requeue; } else { - error("max broadcast iterations (%d) reached with %d/%d tasks woken or r= equeued\n", - 0, MAX_WAKE_ITERS, task_count, THREAD_MAX); - args->ret =3D RET_ERROR; + ksft_exit_fail_msg("max broadcast iterations (%d) reached with %d/%d tas= ks woken or requeued\n", + MAX_WAKE_ITERS, task_count, THREAD_MAX); } =20 futex_wake(&wake_complete, 1, FUTEX_PRIVATE_FLAG); @@ -187,7 +233,7 @@ void *broadcast_wakerfn(void *arg) if (args->ret > 0) args->ret =3D task_count; =20 - info("Waker: exiting with %d\n", args->ret); + ksft_print_dbg_msg("Waker: exiting with %d\n", args->ret); pthread_exit((void *)&args->ret); } =20 @@ -200,20 +246,20 @@ void *signal_wakerfn(void *arg) int nr_wake =3D 1; int i =3D 0; =20 - info("Waker: waiting for waiters to block\n"); + ksft_print_dbg_msg("Waker: waiting for waiters to block\n"); while (waiters_blocked.val < THREAD_MAX) usleep(1000); usleep(1000); =20 while (task_count < THREAD_MAX && waiters_woken.val < THREAD_MAX) { - info("task_count: %d, waiters_woken: %d\n", + ksft_print_dbg_msg("task_count: %d, waiters_woken: %d\n", task_count, waiters_woken.val); if (args->lock) { - info("Calling FUTEX_LOCK_PI on mutex=3D%x @ %p\n", - f2, &f2); + ksft_print_dbg_msg("Calling FUTEX_LOCK_PI on mutex=3D%x @ %p\n", + f2, &f2); futex_lock_pi(&f2, NULL, 0, FUTEX_PRIVATE_FLAG); } - info("Waker: Calling signal\n"); + ksft_print_dbg_msg("Waker: Calling signal\n"); /* cond_signal */ old_val =3D f1; args->ret =3D futex_cmp_requeue_pi(&f1, old_val, &f2, @@ -221,28 +267,23 @@ void *signal_wakerfn(void *arg) FUTEX_PRIVATE_FLAG); if (args->ret < 0) args->ret =3D -errno; - info("futex: %x\n", f2); + ksft_print_dbg_msg("futex: %x\n", f2); if (args->lock) { - info("Calling FUTEX_UNLOCK_PI on mutex=3D%x @ %p\n", - f2, &f2); + ksft_print_dbg_msg("Calling FUTEX_UNLOCK_PI on mutex=3D%x @ %p\n", + f2, &f2); futex_unlock_pi(&f2, FUTEX_PRIVATE_FLAG); } - info("futex: %x\n", f2); - if (args->ret < 0) { - error("FUTEX_CMP_REQUEUE_PI failed\n", errno); - args->ret =3D RET_ERROR; - break; - } + ksft_print_dbg_msg("futex: %x\n", f2); + if (args->ret < 0) + ksft_exit_fail_msg("FUTEX_CMP_REQUEUE_PI failed\n"); =20 task_count +=3D args->ret; usleep(SIGNAL_PERIOD_US); i++; /* we have to loop at least THREAD_MAX times */ if (i > MAX_WAKE_ITERS + THREAD_MAX) { - error("max signaling iterations (%d) reached, giving up on pending wait= ers.\n", - 0, MAX_WAKE_ITERS + THREAD_MAX); - args->ret =3D RET_ERROR; - break; + ksft_exit_fail_msg("max signaling iterations (%d) reached, giving up on= pending waiters.\n", + MAX_WAKE_ITERS + THREAD_MAX); } } =20 @@ -251,8 +292,8 @@ void *signal_wakerfn(void *arg) if (args->ret >=3D 0) args->ret =3D task_count; =20 - info("Waker: exiting with %d\n", args->ret); - info("Waker: waiters_woken: %d\n", waiters_woken.val); + ksft_print_dbg_msg("Waker: exiting with %d\n", args->ret); + ksft_print_dbg_msg("Waker: waiters_woken: %d\n", waiters_woken.val); pthread_exit((void *)&args->ret); } =20 @@ -269,15 +310,13 @@ void *third_party_blocker(void *arg) ret2 =3D futex_unlock_pi(&f2, FUTEX_PRIVATE_FLAG); =20 out: - if (args->ret || ret2) { - error("third_party_blocker() futex error", 0); - args->ret =3D RET_ERROR; - } + if (args->ret || ret2) + ksft_exit_fail_msg("third_party_blocker() futex error"); =20 pthread_exit((void *)&args->ret); } =20 -int unit_test(int broadcast, long lock, int third_party_owner, long timeou= t_ns) +TEST_F(args, futex_requeue_pi) { void *(*wakerfn)(void *) =3D signal_wakerfn; struct thread_arg blocker_arg =3D THREAD_ARG_INITIALIZER; @@ -286,18 +325,26 @@ int unit_test(int broadcast, long lock, int third_par= ty_owner, long timeout_ns) struct timespec ts, *tsp =3D NULL; struct thread_arg args[THREAD_MAX]; int *waiter_ret; - int i, ret =3D RET_PASS; + int i, ret =3D 0; + bool lock =3D variant->locked; + bool third_party_owner =3D variant->owner; + bool broadcast =3D variant->broadcast; + long timeout_ns =3D variant->timeout_ns; + + ksft_print_msg( + "\tArguments: broadcast=3D%d locked=3D%d owner=3D%d timeout=3D%ldns\n", + broadcast, lock, third_party_owner, timeout_ns); =20 if (timeout_ns) { time_t secs; =20 - info("timeout_ns =3D %ld\n", timeout_ns); + ksft_print_dbg_msg("timeout_ns =3D %ld\n", timeout_ns); ret =3D clock_gettime(CLOCK_MONOTONIC, &ts); secs =3D (ts.tv_nsec + timeout_ns) / 1000000000; ts.tv_nsec =3D ((int64_t)ts.tv_nsec + timeout_ns) % 1000000000; ts.tv_sec +=3D secs; - info("ts.tv_sec =3D %ld\n", ts.tv_sec); - info("ts.tv_nsec =3D %ld\n", ts.tv_nsec); + ksft_print_dbg_msg("ts.tv_sec =3D %ld\n", ts.tv_sec); + ksft_print_dbg_msg("ts.tv_nsec =3D %ld\n", ts.tv_nsec); tsp =3D &ts; } =20 @@ -307,10 +354,7 @@ int unit_test(int broadcast, long lock, int third_part= y_owner, long timeout_ns) if (third_party_owner) { if (create_rt_thread(&blocker, third_party_blocker, (void *)&blocker_arg, SCHED_FIFO, 1)) { - error("Creating third party blocker thread failed\n", - errno); - ret =3D RET_ERROR; - goto out; + ksft_exit_fail_msg("Creating third party blocker thread failed\n"); } } =20 @@ -318,20 +362,16 @@ int unit_test(int broadcast, long lock, int third_par= ty_owner, long timeout_ns) for (i =3D 0; i < THREAD_MAX; i++) { args[i].id =3D i; args[i].timeout =3D tsp; - info("Starting thread %d\n", i); + ksft_print_dbg_msg("Starting thread %d\n", i); if (create_rt_thread(&waiter[i], waiterfn, (void *)&args[i], SCHED_FIFO, 1)) { - error("Creating waiting thread failed\n", errno); - ret =3D RET_ERROR; - goto out; + ksft_exit_fail_msg("Creating waiting thread failed\n"); } } waker_arg.lock =3D lock; if (create_rt_thread(&waker, wakerfn, (void *)&waker_arg, SCHED_FIFO, 1)) { - error("Creating waker thread failed\n", errno); - ret =3D RET_ERROR; - goto out; + ksft_exit_fail_msg("Creating waker thread failed\n"); } =20 /* Wait for threads to finish */ @@ -345,7 +385,6 @@ int unit_test(int broadcast, long lock, int third_party= _owner, long timeout_ns) pthread_join(blocker, NULL); pthread_join(waker, NULL); =20 -out: if (!ret) { if (*waiter_ret) ret =3D *waiter_ret; @@ -355,66 +394,8 @@ int unit_test(int broadcast, long lock, int third_part= y_owner, long timeout_ns) ret =3D blocker_arg.ret; } =20 - return ret; + if (ret) + ksft_test_result_fail("fail"); } =20 -int main(int argc, char *argv[]) -{ - char *test_name; - int c, ret; - - while ((c =3D getopt(argc, argv, "bchlot:v:")) !=3D -1) { - switch (c) { - case 'b': - broadcast =3D 1; - break; - case 'c': - log_color(1); - break; - case 'h': - usage(basename(argv[0])); - exit(0); - case 'l': - locked =3D 1; - break; - case 'o': - owner =3D 1; - locked =3D 0; - break; - case 't': - timeout_ns =3D atoi(optarg); - break; - case 'v': - log_verbosity(atoi(optarg)); - break; - default: - usage(basename(argv[0])); - exit(1); - } - } - - ksft_print_header(); - ksft_set_plan(1); - ksft_print_msg("%s: Test requeue functionality\n", basename(argv[0])); - ksft_print_msg( - "\tArguments: broadcast=3D%d locked=3D%d owner=3D%d timeout=3D%ldns\n", - broadcast, locked, owner, timeout_ns); - - ret =3D asprintf(&test_name, - "%s broadcast=3D%d locked=3D%d owner=3D%d timeout=3D%ldns", - TEST_NAME, broadcast, locked, owner, timeout_ns); - if (ret < 0) { - ksft_print_msg("Failed to generate test name\n"); - test_name =3D TEST_NAME; - } - - /* - * FIXME: unit_test is obsolete now that we parse options and the - * various style of runs are done by run.sh - simplify the code and move - * unit_test into main() - */ - ret =3D unit_test(broadcast, locked, owner, timeout_ns); - - print_result(test_name, ret); - return ret; -} +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/futex/functional/run.sh b/tools/testin= g/selftests/futex/functional/run.sh index 81739849f2994d52c336df00f1072db71b35573a..49edfad884869c7dffce2f482c4= 34003b9cc49d1 100755 --- a/tools/testing/selftests/futex/functional/run.sh +++ b/tools/testing/selftests/futex/functional/run.sh @@ -32,31 +32,7 @@ fi =20 =20 echo -# requeue pi testing -# without timeouts -./futex_requeue_pi $COLOR -./futex_requeue_pi $COLOR -b -./futex_requeue_pi $COLOR -b -l -./futex_requeue_pi $COLOR -b -o -./futex_requeue_pi $COLOR -l -./futex_requeue_pi $COLOR -o -# with timeouts -./futex_requeue_pi $COLOR -b -l -t 5000 -./futex_requeue_pi $COLOR -l -t 5000 -./futex_requeue_pi $COLOR -b -l -t 500000 -./futex_requeue_pi $COLOR -l -t 500000 -./futex_requeue_pi $COLOR -b -t 5000 -./futex_requeue_pi $COLOR -t 5000 -./futex_requeue_pi $COLOR -b -t 500000 -./futex_requeue_pi $COLOR -t 500000 -./futex_requeue_pi $COLOR -b -o -t 5000 -./futex_requeue_pi $COLOR -l -t 5000 -./futex_requeue_pi $COLOR -b -o -t 500000 -./futex_requeue_pi $COLOR -l -t 500000 -# with long timeout -./futex_requeue_pi $COLOR -b -l -t 2000000000 -./futex_requeue_pi $COLOR -l -t 2000000000 - +./futex_requeue_pi =20 echo ./futex_requeue_pi_mismatched_ops $COLOR --=20 2.49.0 From nobody Tue Oct 7 22:39:43 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 C73772D77E6; Fri, 4 Jul 2025 15:05:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641540; cv=none; b=sFlwS1QZ+/VVvXUlahbC7vsX7+vq1wZiC9dqFmM+7+RKVoYDKp2Sq4QVoxWl7nKYcFcfQ3tdc2ljh9Ln9LZz1TE+Erp30vAG5XllO7Ev/94BFLW7i6/n6hJjVEoudI2twHbwl1w5PPNYwDg/ZZ44EkU6pDR0RfPZcxyMC3e+eQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641540; c=relaxed/simple; bh=hbKqNRayFt4LIIrZhEVvzb9r70LNdGzAbESZORhU2/I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UVL5xRR3o4hxSLREnAjmPFBGaLfxXPW4tskKR819SO0sRMFqiZzbv7r2xtyLK9Dt7G2lE2b/ENDcVSYsHgHVXVFHv2gDK5Orec95A7oVdKN4a2+7q7Dz1tnWnj3DUzYP+0JVNdhtcrxj3Oeh8Jqi504nFW2zI1d8ZvGYSRp4keQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=RUs38z5f; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="RUs38z5f" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=VREAvdW2dJm/U4tSDAEKh5HsiNV3L70v/2/QV6VXkT8=; b=RUs38z5fE2kts+6doWwTtJ4/XF oOtlsGhF3Gk/HVX/8yBte6G7+SgG3M8hnpFHhz8amyawrZ9gwrq/sLl+m3kp+hJK8SRUBTrWnms8h ye3h+X0w0yGOzyi7LZAjhwZB41vEPO6HYAW2Y8eQ5PY64bkQLheziZAZIjtLxex+N/HVpRCqf3Oz+ hFKCk214bjpLhFmALZ2Di2Le6DrkYJRtC91WBHl11EhGLgrZWjonkkZxRVfexpANj4AsDvicJOUuI i6Odi7L8QLvqKCAzQ6eRnZbaoJtFQTw8bKonjJ05ndn2DhYX9hbUFtd+vAK6Yh8J6gVLn7055AqeO YNU6YOYA==; Received: from [179.100.5.63] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uXhyn-00CTWt-EV; Fri, 04 Jul 2025 17:05:33 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 04 Jul 2025 12:05:07 -0300 Subject: [PATCH 03/15] selftests/futex: Refactor futex_requeue_pi_mismatched_ops with kselftest_harness.h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-tonyk-robust_test_cleanup-v1-3-c0ff4f24c4e1@igalia.com> References: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> In-Reply-To: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Sebastian Andrzej Siewior Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 To reduce the boilerplate code, refactor futex_requeue_pi_mismatched_ops test to use kselftest_harness header instead of futex's logging header. Signed-off-by: Andr=C3=A9 Almeida --- .../functional/futex_requeue_pi_mismatched_ops.c | 80 +++++-------------= ---- tools/testing/selftests/futex/functional/run.sh | 2 +- 2 files changed, 19 insertions(+), 63 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi_mism= atched_ops.c b/tools/testing/selftests/futex/functional/futex_requeue_pi_mi= smatched_ops.c index d0a4d332ea44131d5e78a4c7d0cd36d36ae468d2..a956fdf931b3b50b25ed71d9034= a5f1a5001f77e 100644 --- a/tools/testing/selftests/futex/functional/futex_requeue_pi_mismatched_= ops.c +++ b/tools/testing/selftests/futex/functional/futex_requeue_pi_mismatched_= ops.c @@ -23,67 +23,32 @@ #include #include #include -#include "futextest.h" -#include "logging.h" =20 -#define TEST_NAME "futex-requeue-pi-mismatched-ops" +#include "futextest.h" +#include "../../kselftest_harness.h" =20 futex_t f1 =3D FUTEX_INITIALIZER; futex_t f2 =3D FUTEX_INITIALIZER; int child_ret =3D 0; =20 -void usage(char *prog) -{ - printf("Usage: %s\n", prog); - printf(" -c Use color\n"); - printf(" -h Display this help message\n"); - printf(" -v L Verbosity level: %d=3DQUIET %d=3DCRITICAL %d=3DINFO\n", - VQUIET, VCRITICAL, VINFO); -} - void *blocking_child(void *arg) { child_ret =3D futex_wait(&f1, f1, NULL, FUTEX_PRIVATE_FLAG); if (child_ret < 0) { child_ret =3D -errno; - error("futex_wait\n", errno); + ksft_exit_fail_msg("futex_wait\n"); } return (void *)&child_ret; } =20 -int main(int argc, char *argv[]) +TEST(requeue_pi_mismatched_ops) { - int ret =3D RET_PASS; pthread_t child; - int c; + int ret; =20 - while ((c =3D getopt(argc, argv, "chv:")) !=3D -1) { - switch (c) { - case 'c': - log_color(1); - break; - case 'h': - usage(basename(argv[0])); - exit(0); - case 'v': - log_verbosity(atoi(optarg)); - break; - default: - usage(basename(argv[0])); - exit(1); - } - } - - ksft_print_header(); - ksft_set_plan(1); - ksft_print_msg("%s: Detect mismatched requeue_pi operations\n", - basename(argv[0])); + if (pthread_create(&child, NULL, blocking_child, NULL)) + ksft_exit_fail_msg("pthread_create\n"); =20 - if (pthread_create(&child, NULL, blocking_child, NULL)) { - error("pthread_create\n", errno); - ret =3D RET_ERROR; - goto out; - } /* Allow the child to block in the kernel. */ sleep(1); =20 @@ -102,34 +67,25 @@ int main(int argc, char *argv[]) * FUTEX_WAKE. */ ret =3D futex_wake(&f1, 1, FUTEX_PRIVATE_FLAG); - if (ret =3D=3D 1) { - ret =3D RET_PASS; - } else if (ret < 0) { - error("futex_wake\n", errno); - ret =3D RET_ERROR; - } else { - error("futex_wake did not wake the child\n", 0); - ret =3D RET_ERROR; - } + if (ret =3D=3D 1) + ksft_test_result_pass("pass"); + else if (ret < 0) + ksft_exit_fail_msg("futex_wake\n"); + else + ksft_exit_fail_msg("futex_wake did not wake the child\n"); } else { - error("futex_cmp_requeue_pi\n", errno); - ret =3D RET_ERROR; + ksft_exit_fail_msg("futex_cmp_requeue_pi\n"); } } else if (ret > 0) { - fail("futex_cmp_requeue_pi failed to detect the mismatch\n"); - ret =3D RET_FAIL; + ksft_test_result_fail("futex_cmp_requeue_pi failed to detect the mismatc= h\n"); } else { - error("futex_cmp_requeue_pi found no waiters\n", 0); - ret =3D RET_ERROR; + ksft_exit_fail_msg("futex_cmp_requeue_pi found no waiters\n"); } =20 pthread_join(child, NULL); =20 if (!ret) ret =3D child_ret; - - out: - /* If the kernel crashes, we shouldn't return at all. */ - print_result(TEST_NAME, ret); - return ret; } + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/futex/functional/run.sh b/tools/testin= g/selftests/futex/functional/run.sh index 49edfad884869c7dffce2f482c434003b9cc49d1..f9d598ef43ec3fb7580ab59bf6f= c70b6ecd8a82d 100755 --- a/tools/testing/selftests/futex/functional/run.sh +++ b/tools/testing/selftests/futex/functional/run.sh @@ -35,7 +35,7 @@ echo ./futex_requeue_pi =20 echo -./futex_requeue_pi_mismatched_ops $COLOR +./futex_requeue_pi_mismatched_ops =20 echo ./futex_requeue_pi_signal_restart $COLOR --=20 2.49.0 From nobody Tue Oct 7 22:39:43 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 6DF522D7812; Fri, 4 Jul 2025 15:05:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641541; cv=none; b=TaX1crRNHiJ/22MMXEVSEFCgJ4qJ+UVY33nDUx3BUm7+y8qsmU0/2XSQv6H9p9BAR2wxRLv4/90tDXtRn5+tgEa42+2LtGzfcXjjVCvBc277diddFBaXMl/mkrb+xIJXBnkE9cHLXZHKTj9CCCcC6kUbpGZS6bViSLXijH3O7oc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641541; c=relaxed/simple; bh=V3tMoIJp/NTXTgwMUmtavU/XTfr+PVu/hBgU2sjou64=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mvQfmOtfcbNdVbGWkZ8thvfKBjDnaDsAyqKqZ98AT0yUhk6UvRJNRkXrrcjbh9fu3ZpKGL36QJENLQJTIaxbsS94WFfXn8BEyceN3tGMrA0JtUik6iqBRfzJIhK5Y8cXIo8mlT9nLdn7/Ma3HzsVfZpAFy/2yWhZ4j4UBYEtIlg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=V+A9LfeI; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="V+A9LfeI" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=lity6QYpYzE34cdd1wQik8MA/JHn0N3eCxfewvB4jD4=; b=V+A9LfeI4/55mA2qK8Y15yce7t ixsBCF7s1Hb6FS8QQtg5BMhNw2lYTreIJFdclmeOEOMixTOq7n2w5IPsXqA4ncVx7FvYDWmNpJ2Lo nRlQHwX9v8NZAdURre6sopaTSAnoY+qMpSxLY3/feLv67ZIFboNLzjJgocew6XVhMJ400Ir9iIQdb kiEHO80ARE5qRlB0jjK4RUBz1/7wmFNsr+RBXV1t1XH8wwyvKovMEUMJGru6+xm+Xv2pHxIuDU5xu SYCpVg6eXTNXSSEw9Uya0etBMYAVpXVBTWqmAwGyuO2lj7eYqre0TSVB3NFtCNy+096W5uFUeARW3 cQESitmg==; Received: from [179.100.5.63] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uXhyq-00CTWt-4G; Fri, 04 Jul 2025 17:05:36 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 04 Jul 2025 12:05:08 -0300 Subject: [PATCH 04/15] selftests/futex: Refactor futex_requeue_pi_signal_restart with kselftest_harness.h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-tonyk-robust_test_cleanup-v1-4-c0ff4f24c4e1@igalia.com> References: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> In-Reply-To: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Sebastian Andrzej Siewior Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 To reduce the boilerplate code, refactor futex_requeue_pi_signal_restart test to use kselftest_harness header instead of futex's logging header. Signed-off-by: Andr=C3=A9 Almeida --- .../functional/futex_requeue_pi_signal_restart.c | 129 ++++++-----------= ---- tools/testing/selftests/futex/functional/run.sh | 2 +- 2 files changed, 38 insertions(+), 93 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_requeue_pi_sign= al_restart.c b/tools/testing/selftests/futex/functional/futex_requeue_pi_si= gnal_restart.c index c6b8f32990c87587551b14577b200e62c56af223..e34ee0f9ebccdb2cd2984e48acf= 157245b12848f 100644 --- a/tools/testing/selftests/futex/functional/futex_requeue_pi_signal_rest= art.c +++ b/tools/testing/selftests/futex/functional/futex_requeue_pi_signal_rest= art.c @@ -24,11 +24,11 @@ #include #include #include + #include "atomic.h" #include "futextest.h" -#include "logging.h" +#include "../../kselftest_harness.h" =20 -#define TEST_NAME "futex-requeue-pi-signal-restart" #define DELAY_US 100 =20 futex_t f1 =3D FUTEX_INITIALIZER; @@ -37,15 +37,6 @@ atomic_t requeued =3D ATOMIC_INITIALIZER; =20 int waiter_ret =3D 0; =20 -void usage(char *prog) -{ - printf("Usage: %s\n", prog); - printf(" -c Use color\n"); - printf(" -h Display this help message\n"); - printf(" -v L Verbosity level: %d=3DQUIET %d=3DCRITICAL %d=3DINFO\n", - VQUIET, VCRITICAL, VINFO); -} - int create_rt_thread(pthread_t *pth, void*(*func)(void *), void *arg, int policy, int prio) { @@ -57,35 +48,28 @@ int create_rt_thread(pthread_t *pth, void*(*func)(void = *), void *arg, memset(&schedp, 0, sizeof(schedp)); =20 ret =3D pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); - if (ret) { - error("pthread_attr_setinheritsched\n", ret); - return -1; - } + if (ret) + ksft_exit_fail_msg("pthread_attr_setinheritsched\n"); =20 ret =3D pthread_attr_setschedpolicy(&attr, policy); - if (ret) { - error("pthread_attr_setschedpolicy\n", ret); - return -1; - } + if (ret) + ksft_exit_fail_msg("pthread_attr_setschedpolicy\n"); =20 schedp.sched_priority =3D prio; ret =3D pthread_attr_setschedparam(&attr, &schedp); - if (ret) { - error("pthread_attr_setschedparam\n", ret); - return -1; - } + if (ret) + ksft_exit_fail_msg("pthread_attr_setschedparam\n"); =20 ret =3D pthread_create(pth, &attr, func, arg); - if (ret) { - error("pthread_create\n", ret); - return -1; - } + if (ret) + ksft_exit_fail_msg("pthread_create\n"); + return 0; } =20 void handle_signal(int signo) { - info("signal received %s requeue\n", + ksft_print_dbg_msg("signal received %s requeue\n", requeued.val ? "after" : "prior to"); } =20 @@ -94,78 +78,46 @@ void *waiterfn(void *arg) unsigned int old_val; int res; =20 - waiter_ret =3D RET_PASS; - - info("Waiter running\n"); - info("Calling FUTEX_LOCK_PI on f2=3D%x @ %p\n", f2, &f2); + ksft_print_dbg_msg("Waiter running\n"); + ksft_print_dbg_msg("Calling FUTEX_LOCK_PI on f2=3D%x @ %p\n", f2, &f2); old_val =3D f1; res =3D futex_wait_requeue_pi(&f1, old_val, &(f2), NULL, FUTEX_PRIVATE_FLAG); if (!requeued.val || errno !=3D EWOULDBLOCK) { - fail("unexpected return from futex_wait_requeue_pi: %d (%s)\n", + ksft_test_result_fail("unexpected return from futex_wait_requeue_pi: %d = (%s)\n", res, strerror(errno)); - info("w2:futex: %x\n", f2); + ksft_print_dbg_msg("w2:futex: %x\n", f2); if (!res) futex_unlock_pi(&f2, FUTEX_PRIVATE_FLAG); - waiter_ret =3D RET_FAIL; } =20 - info("Waiter exiting with %d\n", waiter_ret); pthread_exit(NULL); } =20 =20 -int main(int argc, char *argv[]) +TEST(futex_requeue_pi_signal_restart) { unsigned int old_val; struct sigaction sa; pthread_t waiter; - int c, res, ret =3D RET_PASS; - - while ((c =3D getopt(argc, argv, "chv:")) !=3D -1) { - switch (c) { - case 'c': - log_color(1); - break; - case 'h': - usage(basename(argv[0])); - exit(0); - case 'v': - log_verbosity(atoi(optarg)); - break; - default: - usage(basename(argv[0])); - exit(1); - } - } - - ksft_print_header(); - ksft_set_plan(1); - ksft_print_msg("%s: Test signal handling during requeue_pi\n", - basename(argv[0])); - ksft_print_msg("\tArguments: \n"); + int res; =20 sa.sa_handler =3D handle_signal; sigemptyset(&sa.sa_mask); sa.sa_flags =3D 0; - if (sigaction(SIGUSR1, &sa, NULL)) { - error("sigaction\n", errno); - exit(1); - } + if (sigaction(SIGUSR1, &sa, NULL)) + ksft_exit_fail_msg("sigaction\n"); =20 - info("m1:f2: %x\n", f2); - info("Creating waiter\n"); + ksft_print_dbg_msg("m1:f2: %x\n", f2); + ksft_print_dbg_msg("Creating waiter\n"); res =3D create_rt_thread(&waiter, waiterfn, NULL, SCHED_FIFO, 1); - if (res) { - error("Creating waiting thread failed", res); - ret =3D RET_ERROR; - goto out; - } + if (res) + ksft_exit_fail_msg("Creating waiting thread failed"); =20 - info("Calling FUTEX_LOCK_PI on f2=3D%x @ %p\n", f2, &f2); - info("m2:f2: %x\n", f2); + ksft_print_dbg_msg("Calling FUTEX_LOCK_PI on f2=3D%x @ %p\n", f2, &f2); + ksft_print_dbg_msg("m2:f2: %x\n", f2); futex_lock_pi(&f2, 0, 0, FUTEX_PRIVATE_FLAG); - info("m3:f2: %x\n", f2); + ksft_print_dbg_msg("m3:f2: %x\n", f2); =20 while (1) { /* @@ -173,11 +125,11 @@ int main(int argc, char *argv[]) * restart futex_wait_requeue_pi() in the kernel. Wait for the * waiter to block on f1 again. */ - info("Issuing SIGUSR1 to waiter\n"); + ksft_print_dbg_msg("Issuing SIGUSR1 to waiter\n"); pthread_kill(waiter, SIGUSR1); usleep(DELAY_US); =20 - info("Requeueing waiter via FUTEX_CMP_REQUEUE_PI\n"); + ksft_print_dbg_msg("Requeueing waiter via FUTEX_CMP_REQUEUE_PI\n"); old_val =3D f1; res =3D futex_cmp_requeue_pi(&f1, old_val, &(f2), 1, 0, FUTEX_PRIVATE_FLAG); @@ -191,12 +143,10 @@ int main(int argc, char *argv[]) atomic_set(&requeued, 1); break; } else if (res < 0) { - error("FUTEX_CMP_REQUEUE_PI failed\n", errno); - ret =3D RET_ERROR; - break; + ksft_exit_fail_msg("FUTEX_CMP_REQUEUE_PI failed\n"); } } - info("m4:f2: %x\n", f2); + ksft_print_dbg_msg("m4:f2: %x\n", f2); =20 /* * Signal the waiter after requeue, waiter should return from @@ -204,19 +154,14 @@ int main(int argc, char *argv[]) * futex_unlock_pi() can't happen before the signal wakeup is detected * in the kernel. */ - info("Issuing SIGUSR1 to waiter\n"); + ksft_print_dbg_msg("Issuing SIGUSR1 to waiter\n"); pthread_kill(waiter, SIGUSR1); - info("Waiting for waiter to return\n"); + ksft_print_dbg_msg("Waiting for waiter to return\n"); pthread_join(waiter, NULL); =20 - info("Calling FUTEX_UNLOCK_PI on mutex=3D%x @ %p\n", f2, &f2); + ksft_print_dbg_msg("Calling FUTEX_UNLOCK_PI on mutex=3D%x @ %p\n", f2, &f= 2); futex_unlock_pi(&f2, FUTEX_PRIVATE_FLAG); - info("m5:f2: %x\n", f2); - - out: - if (ret =3D=3D RET_PASS && waiter_ret) - ret =3D waiter_ret; - - print_result(TEST_NAME, ret); - return ret; + ksft_print_dbg_msg("m5:f2: %x\n", f2); } + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/futex/functional/run.sh b/tools/testin= g/selftests/futex/functional/run.sh index f9d598ef43ec3fb7580ab59bf6fc70b6ecd8a82d..37f614e7d7fd3ce9741861e23df= 40f87139f572a 100755 --- a/tools/testing/selftests/futex/functional/run.sh +++ b/tools/testing/selftests/futex/functional/run.sh @@ -38,7 +38,7 @@ echo ./futex_requeue_pi_mismatched_ops =20 echo -./futex_requeue_pi_signal_restart $COLOR +./futex_requeue_pi_signal_restart =20 echo ./futex_wait_timeout $COLOR --=20 2.49.0 From nobody Tue Oct 7 22:39:43 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 171452DE710; Fri, 4 Jul 2025 15:05:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641543; cv=none; b=ZFE7yzGozu4rX4FTxl66Q7X2bCV3hbtCUKoZ7du3aRYgJ3vLIHsrJqaALX4TmMdo5Ad/2ugiB+0YvluxZMnhYbtxo/BvVEhTNL7Cmnk1DTv1YbUhPkdXlK19Cc7sh4frLKSRSYwHAOmg3eTrKF/VNfKjCXBqPYBHT1v4+KkeGq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641543; c=relaxed/simple; bh=Wg4yy5y9MyYHmyF5L8tl3PEUJZrQ24Vqqu7zaLgmnEg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L21n49gPOBRTOOAb1S0r6KhLS0fbyOQaeyCC3fZnRnCI9tAZkdqTxfPxzjqtNWvpC5V7la2ofaVbA9VaXTWTEs0xQ1q9WF7I38ZL3iqg90cSc5proMRsbVvtszjWulDdzO+Oj9lZpbc5OVZMtjtfiDZtwSzGtXRemFVyKEKC+XM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=NCXjXNK6; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="NCXjXNK6" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=c6WEnVGf8U+FfRf9MBqFGKJNZ0FWJUy70Io4K0h5Lg4=; b=NCXjXNK6uk49/iOiHRCq+eUG/Y gdxllzfTrLeI9J3ob1CYg0IaLVFCotmc5mYZMI+JbyFRq89lllXc7kX5JjcVwUtCIOBZGFjyQU3PY RqtIkyID7XgW0+YZoxWe34kMnv1QhlRewv8X2yz62jahUoZxh/12Q6AWHGu+vph4OWt8hl/y3WVKC vHbZPx/G7dKgQ5XCdV2LJ3yMCoYRqp3ZopL0Qz5B2h3JVR1TVrtruHyi1RU/0C0/toZVoKqIXQZvj 6whp3eO9mchEXdN/7liRlT1mrbeOBjhsRkVfS9Uwm2SL1CVrOic/tmgZPPdq+kzEmo6ReIXXsgavB eM4Txy5g==; Received: from [179.100.5.63] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uXhys-00CTWt-Pv; Fri, 04 Jul 2025 17:05:38 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 04 Jul 2025 12:05:09 -0300 Subject: [PATCH 05/15] selftests/futex: Refactor futex_wait_timeout with kselftest_harness.h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-tonyk-robust_test_cleanup-v1-5-c0ff4f24c4e1@igalia.com> References: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> In-Reply-To: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Sebastian Andrzej Siewior Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 To reduce the boilerplate code, refactor futex_wait_timeout test to use kselftest_harness header instead of futex's logging header. Signed-off-by: Andr=C3=A9 Almeida --- .../futex/functional/futex_wait_timeout.c | 139 +++++++++--------= ---- tools/testing/selftests/futex/functional/run.sh | 2 +- 2 files changed, 61 insertions(+), 80 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_wait_timeout.c = b/tools/testing/selftests/futex/functional/futex_wait_timeout.c index d183f878360bcd04c72565510c116808b3e82347..ee01e49b1b3fa62dbad87f80b69= 37816fcb110ac 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_timeout.c +++ b/tools/testing/selftests/futex/functional/futex_wait_timeout.c @@ -16,26 +16,15 @@ *************************************************************************= ****/ =20 #include + #include "futextest.h" #include "futex2test.h" -#include "logging.h" - -#define TEST_NAME "futex-wait-timeout" +#include "../../kselftest_harness.h" =20 static long timeout_ns =3D 100000; /* 100us default timeout */ static futex_t futex_pi; static pthread_barrier_t barrier; =20 -void usage(char *prog) -{ - printf("Usage: %s\n", prog); - printf(" -c Use color\n"); - printf(" -h Display this help message\n"); - printf(" -t N Timeout in nanoseconds (default: 100,000)\n"); - printf(" -v L Verbosity level: %d=3DQUIET %d=3DCRITICAL %d=3DINFO\n", - VQUIET, VCRITICAL, VINFO); -} - /* * Get a PI lock and hold it forever, so the main thread lock_pi will block * and we can test the timeout @@ -47,13 +36,13 @@ void *get_pi_lock(void *arg) =20 ret =3D futex_lock_pi(&futex_pi, NULL, 0, 0); if (ret !=3D 0) - error("futex_lock_pi failed\n", ret); + ksft_exit_fail_msg("futex_lock_pi failed\n"); =20 pthread_barrier_wait(&barrier); =20 /* Blocks forever */ ret =3D futex_wait(&lock, 0, NULL, 0); - error("futex_wait failed\n", ret); + ksft_exit_fail_msg("futex_wait failed\n"); =20 return NULL; } @@ -61,12 +50,11 @@ void *get_pi_lock(void *arg) /* * Check if the function returned the expected error */ -static void test_timeout(int res, int *ret, char *test_name, int err) +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); - *ret =3D RET_FAIL; } else { ksft_test_result_pass("%s succeeds\n", test_name); } @@ -78,10 +66,8 @@ static void test_timeout(int res, int *ret, char *test_n= ame, int err) static int futex_get_abs_timeout(clockid_t clockid, struct timespec *to, long timeout_ns) { - if (clock_gettime(clockid, to)) { - error("clock_gettime failed\n", errno); - return errno; - } + if (clock_gettime(clockid, to)) + ksft_exit_fail_msg("clock_gettime failed\n"); =20 to->tv_nsec +=3D timeout_ns; =20 @@ -93,83 +79,66 @@ static int futex_get_abs_timeout(clockid_t clockid, str= uct timespec *to, return 0; } =20 -int main(int argc, char *argv[]) +TEST(wait_bitset) { futex_t f1 =3D FUTEX_INITIALIZER; - int res, ret =3D RET_PASS; struct timespec to; - pthread_t thread; - int c; - struct futex_waitv waitv =3D { - .uaddr =3D (uintptr_t)&f1, - .val =3D f1, - .flags =3D FUTEX_32, - .__reserved =3D 0 - }; - - while ((c =3D getopt(argc, argv, "cht:v:")) !=3D -1) { - switch (c) { - case 'c': - log_color(1); - break; - case 'h': - usage(basename(argv[0])); - exit(0); - case 't': - timeout_ns =3D atoi(optarg); - break; - case 'v': - log_verbosity(atoi(optarg)); - break; - default: - usage(basename(argv[0])); - exit(1); - } - } - - ksft_print_header(); - ksft_set_plan(9); - ksft_print_msg("%s: Block on a futex and wait for timeout\n", - basename(argv[0])); - ksft_print_msg("\tArguments: timeout=3D%ldns\n", timeout_ns); - - pthread_barrier_init(&barrier, NULL, 2); - pthread_create(&thread, NULL, get_pi_lock, NULL); + int res; =20 /* initialize relative timeout */ to.tv_sec =3D 0; to.tv_nsec =3D timeout_ns; =20 res =3D futex_wait(&f1, f1, &to, 0); - test_timeout(res, &ret, "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)) - return RET_FAIL; + ksft_test_result_error("get_time error"); res =3D futex_wait_bitset(&f1, f1, &to, 1, FUTEX_CLOCK_REALTIME); - test_timeout(res, &ret, "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)) - return RET_FAIL; + ksft_test_result_error("get_time error"); res =3D futex_wait_bitset(&f1, f1, &to, 1, 0); - test_timeout(res, &ret, "futex_wait_bitset monotonic", ETIMEDOUT); + test_timeout(res, "futex_wait_bitset monotonic", ETIMEDOUT); +} + +TEST(requeue_pi) +{ + futex_t f1 =3D FUTEX_INITIALIZER; + struct timespec to; + int res; =20 /* FUTEX_WAIT_REQUEUE_PI with CLOCK_REALTIME */ if (futex_get_abs_timeout(CLOCK_REALTIME, &to, timeout_ns)) - return RET_FAIL; + ksft_test_result_error("get_time error"); res =3D futex_wait_requeue_pi(&f1, f1, &futex_pi, &to, FUTEX_CLOCK_REALTI= ME); - test_timeout(res, &ret, "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)) - return RET_FAIL; + ksft_test_result_error("get_time error"); res =3D futex_wait_requeue_pi(&f1, f1, &futex_pi, &to, 0); - test_timeout(res, &ret, "futex_wait_requeue_pi monotonic", ETIMEDOUT); + test_timeout(res, "futex_wait_requeue_pi monotonic", ETIMEDOUT); + +} + +TEST(lock_pi) +{ + struct timespec to; + pthread_t thread; + int res; + + /* 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); =20 /* Wait until the other thread calls futex_lock_pi() */ pthread_barrier_wait(&barrier); pthread_barrier_destroy(&barrier); + /* * FUTEX_LOCK_PI with CLOCK_REALTIME * Due to historical reasons, FUTEX_LOCK_PI supports only realtime @@ -181,26 +150,38 @@ int main(int argc, char *argv[]) * smaller than realtime and the syscall will timeout immediately. */ if (futex_get_abs_timeout(CLOCK_REALTIME, &to, timeout_ns)) - return RET_FAIL; + ksft_test_result_error("get_time error"); res =3D futex_lock_pi(&futex_pi, &to, 0, 0); - test_timeout(res, &ret, "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, &ret, "futex_lock_pi invalid timeout flag", ENOSYS); + test_timeout(res, "futex_lock_pi invalid timeout flag", ENOSYS); +} + +TEST(waitv) +{ + futex_t f1 =3D FUTEX_INITIALIZER; + struct timespec to; + int res; + struct futex_waitv waitv =3D { + .uaddr =3D (uintptr_t)&f1, + .val =3D f1, + .flags =3D FUTEX_32, + .__reserved =3D 0 + }; =20 /* futex_waitv with CLOCK_MONOTONIC */ if (futex_get_abs_timeout(CLOCK_MONOTONIC, &to, timeout_ns)) - return RET_FAIL; + ksft_test_result_error("get_time error"); res =3D futex_waitv(&waitv, 1, 0, &to, CLOCK_MONOTONIC); - test_timeout(res, &ret, "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)) - return RET_FAIL; + ksft_test_result_error("get_time error"); res =3D futex_waitv(&waitv, 1, 0, &to, CLOCK_REALTIME); - test_timeout(res, &ret, "futex_waitv realtime", ETIMEDOUT); - - ksft_print_cnts(); - return ret; + test_timeout(res, "futex_waitv realtime", ETIMEDOUT); } + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/futex/functional/run.sh b/tools/testin= g/selftests/futex/functional/run.sh index 37f614e7d7fd3ce9741861e23df40f87139f572a..d42a8f4cf0a3d4361fd9d1196cb= 385a3ae38a04a 100755 --- a/tools/testing/selftests/futex/functional/run.sh +++ b/tools/testing/selftests/futex/functional/run.sh @@ -41,7 +41,7 @@ echo ./futex_requeue_pi_signal_restart =20 echo -./futex_wait_timeout $COLOR +./futex_wait_timeout =20 echo ./futex_wait_wouldblock $COLOR --=20 2.49.0 From nobody Tue Oct 7 22:39:43 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 B22A128B518; Fri, 4 Jul 2025 15:05:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641546; cv=none; b=A3vD2xM+s5nILjnTjZbLbinhD1pUJV3eDEPRrRrhuYCZBvBWRXcfPaloINMNSos0db0si035MSWO6J42RHVwbwWkjWtfsGCsLV+ePcnFuukAIAvrw37U/MNupoJaA/IPxl8nvmiInFrlsR4lxX0AlH0b6LNa2PATZoPyGnTzDek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641546; c=relaxed/simple; bh=odnkQvkojvnteSaHtbFSOTRRo8C2vgZLNLqrTgVa+Gw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X/HXG1LJ9mLeBJTKSiRE5l3AK9dqadg1fh1Oun3pfFsdiA96v7zdAYS96u3aAnkNf2CRMbOBvcu7aZ/PSUY014ib4YFMwU55VJm8Uh1hjoaDkT+cAxUdoy5fcOWuS+zapmpOL+GKzFS4boy6pqQpwT0QV8B6BaxOh9mOZNqXS7U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=OeD7H49y; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="OeD7H49y" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=t9TXouFtixw7kd2vb5hlpDTW7gPiyDOyqgfXJ7aDhq0=; b=OeD7H49ywdUGuxO3/Uus4wmIuX nfrDmvNRi3aPtpSI0XY7s8PgyfClWgFdpxsr5+jIgCN0kK/r0s5iNdGCmE1mHBlXXTc8KN7bJZUgf ryvMmU5LLhPeXapNBMCxTt0/fOVJATgmMxMUyMnYK5nhV2puhP0C+O7WqAH09YA0oCqgDqDobIblt scKqSy5igSIkkD7BSrKeWp62JGA1w/tE93wvlaD4KjQZSIoHGAf8E35jpsPLH6TiBNJU/NdvYmiPN m9tsS5OLX5fQifCvJZ+vJMvPaKXr9n/GLAvBER/jIhIivY9E4wga+WlBIygoJ+tyAU//YvLU9z+IT Jg4iAf5w==; Received: from [179.100.5.63] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uXhyv-00CTWt-Fb; Fri, 04 Jul 2025 17:05:41 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 04 Jul 2025 12:05:10 -0300 Subject: [PATCH 06/15] selftests/futex: Refactor futex_wait_wouldblock with kselftest_harness.h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-tonyk-robust_test_cleanup-v1-6-c0ff4f24c4e1@igalia.com> References: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> In-Reply-To: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Sebastian Andrzej Siewior Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 To reduce the boilerplate code, refactor futex_wait_wouldblock test to use kselftest_harness header instead of futex's logging header. Signed-off-by: Andr=C3=A9 Almeida --- .../futex/functional/futex_wait_wouldblock.c | 75 +++++++-----------= ---- tools/testing/selftests/futex/functional/run.sh | 2 +- 2 files changed, 23 insertions(+), 54 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_wait_wouldblock= .c b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c index 2d8230da906429cd9f1f9021e8df23e12398429e..7bb4ff4dcd9d5fef289b1012975= 558f19e1490e0 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c +++ b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c @@ -21,72 +21,43 @@ #include #include #include + #include "futextest.h" #include "futex2test.h" -#include "logging.h" +#include "../../kselftest_harness.h" =20 -#define TEST_NAME "futex-wait-wouldblock" #define timeout_ns 100000 =20 -void usage(char *prog) -{ - printf("Usage: %s\n", prog); - printf(" -c Use color\n"); - printf(" -h Display this help message\n"); - printf(" -v L Verbosity level: %d=3DQUIET %d=3DCRITICAL %d=3DINFO\n", - VQUIET, VCRITICAL, VINFO); -} - -int main(int argc, char *argv[]) +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, ret =3D RET_PASS; - int c; - struct futex_waitv waitv =3D { - .uaddr =3D (uintptr_t)&f1, - .val =3D f1+1, - .flags =3D FUTEX_32, - .__reserved =3D 0 - }; - - while ((c =3D getopt(argc, argv, "cht:v:")) !=3D -1) { - switch (c) { - case 'c': - log_color(1); - break; - case 'h': - usage(basename(argv[0])); - exit(0); - case 'v': - log_verbosity(atoi(optarg)); - break; - default: - usage(basename(argv[0])); - exit(1); - } - } - - ksft_print_header(); - ksft_set_plan(2); - ksft_print_msg("%s: Test the unexpected futex value in FUTEX_WAIT\n", - basename(argv[0])); + int res; =20 - info("Calling futex_wait on f1: %u @ %p with val=3D%u\n", f1, &f1, f1+1); + ksft_print_dbg_msg("Calling futex_wait on f1: %u @ %p with val=3D%u\n", f= 1, &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) : ""); - ret =3D RET_FAIL; } else { ksft_test_result_pass("futex_wait\n"); } +} =20 - if (clock_gettime(CLOCK_MONOTONIC, &to)) { - error("clock_gettime failed\n", errno); - return errno; - } +TEST(futex_waitv_wouldblock) +{ + struct timespec to =3D {.tv_sec =3D 0, .tv_nsec =3D timeout_ns}; + futex_t f1 =3D FUTEX_INITIALIZER; + int res; + struct futex_waitv waitv =3D { + .uaddr =3D (uintptr_t)&f1, + .val =3D f1+1, + .flags =3D FUTEX_32, + .__reserved =3D 0 + }; + if (clock_gettime(CLOCK_MONOTONIC, &to)) + ksft_exit_fail_msg("clock_gettime failed %d\n", errno); =20 to.tv_nsec +=3D timeout_ns; =20 @@ -95,17 +66,15 @@ int main(int argc, char *argv[]) to.tv_nsec -=3D 1000000000; } =20 - info("Calling futex_waitv on f1: %u @ %p with val=3D%u\n", f1, &f1, f1+1); + ksft_print_dbg_msg("Calling futex_waitv on f1: %u @ %p with val=3D%u\n", = 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) : ""); - ret =3D RET_FAIL; } else { ksft_test_result_pass("futex_waitv\n"); } - - ksft_print_cnts(); - return ret; } + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/futex/functional/run.sh b/tools/testin= g/selftests/futex/functional/run.sh index d42a8f4cf0a3d4361fd9d1196cb385a3ae38a04a..4a4fe9891f1ef8d69bb968a3a2b= e6c7dccd3575f 100755 --- a/tools/testing/selftests/futex/functional/run.sh +++ b/tools/testing/selftests/futex/functional/run.sh @@ -44,7 +44,7 @@ echo ./futex_wait_timeout =20 echo -./futex_wait_wouldblock $COLOR +./futex_wait_wouldblock =20 echo ./futex_wait_uninitialized_heap $COLOR --=20 2.49.0 From nobody Tue Oct 7 22:39:43 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 3A380307AF3; Fri, 4 Jul 2025 15:05:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641548; cv=none; b=Etkxsa8fzRmi+H9CCrp9CCr82bWP00qwwmq8gCIhlHkBLuj9e2sO2obtHj2lZk6RFeb8bILUDctsLn8wRiPGXQXsxBWJ22rUwrzmb1j8cnva7NbICn50xStxPSUOliDZZvWOBe0JStH7AT4onnl2asQM3rx6rHs/LGmPISy4oTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641548; c=relaxed/simple; bh=5Pvjh50WQyx5/gMeQSfj7awWgdJbbPO6FFu59gX9q1w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B4Tk5uZmmggu6myaesRlt5L54FkBkNMWBxs3Fppvda5KnCz8qbELCVbajjljEjbZ+qOjo1nhSK1L+neval+GxVzLPJKHtAJAEaX35ix4eZ2v0vAwGVeXyu1fudH+0dke5zY6kk+kCsGPoE3SmpjClYQcFsbFR/3/fr7DebqL1l4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=O+qKuisz; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="O+qKuisz" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=u6gK7oLhQiOEvzO1qG23okxcLQZxtVgiVb9V1xWsQnY=; b=O+qKuiszMuacHmOYryQ4hrzebk tBRIDM0DH606/KO4SY9y0PsQTYvePZH6M0EW+QeovH/sRv0G8s/UzfmE/UTnETPkbrjTup9s9OMg1 /ge8H3Htd+5xVRCrjL8uYv8/tCmJh5SqGldExBF1H017uNMFZaefBbz57+X/Wxtk3XZd1ran1inZJ Bynwrvas0kGcC76beiU5+ixnuu+nAgb69NdZo7HVO0K68VR3YqhmizGUp6yGc5EN1UzDcuBnylnqs 18+/YzzY7qKp5IA7rNUTxdjeru8RVRxEBeySqhFf2PCbDA0DjnEp2IlgoGUfMbgRxD2EvvypfbHQ9 td7Mj78Q==; Received: from [179.100.5.63] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uXhyy-00CTWt-5A; Fri, 04 Jul 2025 17:05:44 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 04 Jul 2025 12:05:11 -0300 Subject: [PATCH 07/15] selftests/futex: Refactor futex_wait_unitialized_heap with kselftest_harness.h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-tonyk-robust_test_cleanup-v1-7-c0ff4f24c4e1@igalia.com> References: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> In-Reply-To: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Sebastian Andrzej Siewior Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 To reduce the boilerplate code, refactor futex_wait_unitialized_heap test to use kselftest_harness header instead of futex's logging header. Signed-off-by: Andr=C3=A9 Almeida --- .../functional/futex_wait_uninitialized_heap.c | 76 +++++-------------= ---- tools/testing/selftests/futex/functional/run.sh | 2 +- 2 files changed, 19 insertions(+), 59 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_wait_uninitiali= zed_heap.c b/tools/testing/selftests/futex/functional/futex_wait_uninitiali= zed_heap.c index ed9cd07e31c1a980bb505bb97617282411b6085a..ce2301500d839ca7b2d527ab4e0= 72b9f00d1146a 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_uninitialized_hea= p.c +++ b/tools/testing/selftests/futex/functional/futex_wait_uninitialized_hea= p.c @@ -29,95 +29,55 @@ #include #include =20 -#include "logging.h" #include "futextest.h" +#include "../../kselftest_harness.h" =20 -#define TEST_NAME "futex-wait-uninitialized-heap" #define WAIT_US 5000000 =20 static int child_blocked =3D 1; -static int child_ret; +static bool child_ret; void *buf; =20 -void usage(char *prog) -{ - printf("Usage: %s\n", prog); - printf(" -c Use color\n"); - printf(" -h Display this help message\n"); - printf(" -v L Verbosity level: %d=3DQUIET %d=3DCRITICAL %d=3DINFO\n", - VQUIET, VCRITICAL, VINFO); -} - void *wait_thread(void *arg) { int res; =20 - child_ret =3D RET_PASS; + child_ret =3D true; res =3D futex_wait(buf, 1, NULL, 0); child_blocked =3D 0; =20 if (res !=3D 0 && errno !=3D EWOULDBLOCK) { - error("futex failure\n", errno); - child_ret =3D RET_ERROR; + ksft_exit_fail_msg("futex failure\n"); + child_ret =3D false; } pthread_exit(NULL); } =20 -int main(int argc, char **argv) +TEST(futex_wait_uninitialized_heap) { - int c, ret =3D RET_PASS; long page_size; pthread_t thr; - - while ((c =3D getopt(argc, argv, "chv:")) !=3D -1) { - switch (c) { - case 'c': - log_color(1); - break; - case 'h': - usage(basename(argv[0])); - exit(0); - case 'v': - log_verbosity(atoi(optarg)); - break; - default: - usage(basename(argv[0])); - exit(1); - } - } + int ret; =20 page_size =3D sysconf(_SC_PAGESIZE); =20 buf =3D mmap(NULL, page_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); - if (buf =3D=3D (void *)-1) { - error("mmap\n", errno); - exit(1); - } - - ksft_print_header(); - ksft_set_plan(1); - ksft_print_msg("%s: Test the uninitialized futex value in FUTEX_WAIT\n", - basename(argv[0])); - + if (buf =3D=3D (void *)-1) + ksft_exit_fail_msg("mmap\n"); =20 ret =3D pthread_create(&thr, NULL, wait_thread, NULL); - if (ret) { - error("pthread_create\n", errno); - ret =3D RET_ERROR; - goto out; - } + if (ret) + ksft_exit_fail_msg("pthread_create\n"); =20 - info("waiting %dus for child to return\n", WAIT_US); + ksft_print_dbg_msg("waiting %dus for child to return\n", WAIT_US); usleep(WAIT_US); =20 - ret =3D child_ret; - if (child_blocked) { - fail("child blocked in kernel\n"); - ret =3D RET_FAIL; - } + if (child_blocked) + ksft_test_result_fail("child blocked in kernel\n"); =20 - out: - print_result(TEST_NAME, ret); - return ret; + if (!child_ret) + ksft_test_result_fail("child error\n"); } + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/futex/functional/run.sh b/tools/testin= g/selftests/futex/functional/run.sh index 4a4fe9891f1ef8d69bb968a3a2be6c7dccd3575f..a93eb2a21d4aa23f874bf11ccc8= 52838a4c3866f 100755 --- a/tools/testing/selftests/futex/functional/run.sh +++ b/tools/testing/selftests/futex/functional/run.sh @@ -47,7 +47,7 @@ echo ./futex_wait_wouldblock =20 echo -./futex_wait_uninitialized_heap $COLOR +./futex_wait_uninitialized_heap ./futex_wait_private_mapped_file $COLOR =20 echo --=20 2.49.0 From nobody Tue Oct 7 22:39:43 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 C6EE4309A41; Fri, 4 Jul 2025 15:05:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641550; cv=none; b=fVv3ktFdhZrgDl8GKabcpDvi+2x1a3gOb3rEt7kVrX3ARdN19BMZ5pKeSLbwFHKYRmLbB7r0W7ZlSa8dP4ud/JyoK1SeKOBA6XUAj0mKCof+g+JI22E6al5iBAcCUufO3bJmh9PQ1J4fTbd7KlwAOwyqV3uux/rJKiL/8BHshPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641550; c=relaxed/simple; bh=/FLp9Qe+fb+AJI4kLii+i9V8yYUqq8zGZ//5px20r/A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Wa/AhRMjVJeaz5pO/fh4lToKToCjBVvi7lGot24uJeshs/doWiQfYGJdq13RSSl3U0B6tDy8ZcmqiYPze0/vlfoYO1fnfj4GZF2/FkvtqUuKVvf8tD/JUps2EBCnSGGogfq9Ge1kHPz5XakqXCo/k3oLqFlPMTv04Lvs50tEnaI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=g+GBOnHa; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="g+GBOnHa" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=MZTI4WF4Tz8d+DEIyJQ4A8TYNIg+KdLeZ7NA6TNm+pk=; b=g+GBOnHacOATMT439lS7qmuZXA 6DCC7OD1h60aCkWvosevi041yn53eFRkIj0xOlXPCc0R1BbAaLYRn/pnq0WHLmG2MdvlOShaoEOL/ Y5PjxTf7DNv7UOsXolnBYPvfIhIp/sIzWvR+XFFo7LUNc1Bffl7pAek9YPATrNx3uhY2DvkpYrBK5 Yvf4EezFp3LQAkzWm+5uQdqMrUsLIQcabsimjqgyWc6ZWmrAtupmsVlXzgsFJU5RXykIcCdNZZJxE iWQO6U0D2os+ug+XbAzeffrjQjumFFkUiDCKzcN8B9NVMqxRkn9TtCjP1Q5kl32Gq2FZrVib4Rq+0 kg3ryBXw==; Received: from [179.100.5.63] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uXhz0-00CTWt-Ql; Fri, 04 Jul 2025 17:05:47 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 04 Jul 2025 12:05:12 -0300 Subject: [PATCH 08/15] selftests/futex: Refactor futex_wait_private_mapped_file with kselftest_harness.h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-tonyk-robust_test_cleanup-v1-8-c0ff4f24c4e1@igalia.com> References: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> In-Reply-To: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Sebastian Andrzej Siewior Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 To reduce the boilerplate code, refactor futex_wait_private_mapped_file test to use kselftest_harness header instead of futex's logging header. Signed-off-by: Andr=C3=A9 Almeida --- .../functional/futex_wait_private_mapped_file.c | 83 ++++++------------= ---- tools/testing/selftests/futex/functional/run.sh | 2 +- 2 files changed, 21 insertions(+), 64 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_wait_private_ma= pped_file.c b/tools/testing/selftests/futex/functional/futex_wait_private_m= apped_file.c index fb4148f23fa3722cb9c464e188b2747516534dbb..8952ebda14ab8a54d67be4cf36d= d2913dbf3c403 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_private_mapped_fi= le.c +++ b/tools/testing/selftests/futex/functional/futex_wait_private_mapped_fi= le.c @@ -27,10 +27,9 @@ #include #include =20 -#include "logging.h" #include "futextest.h" +#include "../../kselftest_harness.h" =20 -#define TEST_NAME "futex-wait-private-mapped-file" #define PAGE_SZ 4096 =20 char pad[PAGE_SZ] =3D {1}; @@ -40,86 +39,44 @@ char pad2[PAGE_SZ] =3D {1}; #define WAKE_WAIT_US 3000000 struct timespec wait_timeout =3D { .tv_sec =3D 5, .tv_nsec =3D 0}; =20 -void usage(char *prog) -{ - printf("Usage: %s\n", prog); - printf(" -c Use color\n"); - printf(" -h Display this help message\n"); - printf(" -v L Verbosity level: %d=3DQUIET %d=3DCRITICAL %d=3DINFO\n", - VQUIET, VCRITICAL, VINFO); -} - void *thr_futex_wait(void *arg) { int ret; =20 - info("futex wait\n"); + ksft_print_dbg_msg("futex wait\n"); ret =3D futex_wait(&val, 1, &wait_timeout, 0); - if (ret && errno !=3D EWOULDBLOCK && errno !=3D ETIMEDOUT) { - error("futex error.\n", errno); - print_result(TEST_NAME, RET_ERROR); - exit(RET_ERROR); - } + if (ret && errno !=3D EWOULDBLOCK && errno !=3D ETIMEDOUT) + ksft_exit_fail_msg("futex error.\n"); =20 if (ret && errno =3D=3D ETIMEDOUT) - fail("waiter timedout\n"); + ksft_exit_fail_msg("waiter timedout\n"); =20 - info("futex_wait: ret =3D %d, errno =3D %d\n", ret, errno); + ksft_print_dbg_msg("futex_wait: ret =3D %d, errno =3D %d\n", ret, errno); =20 return NULL; } =20 -int main(int argc, char **argv) +TEST(wait_private_mapped_file) { pthread_t thr; - int ret =3D RET_PASS; int res; - int c; - - while ((c =3D getopt(argc, argv, "chv:")) !=3D -1) { - switch (c) { - case 'c': - log_color(1); - break; - case 'h': - usage(basename(argv[0])); - exit(0); - case 'v': - log_verbosity(atoi(optarg)); - break; - default: - usage(basename(argv[0])); - exit(1); - } - } - - ksft_print_header(); - ksft_set_plan(1); - ksft_print_msg( - "%s: Test the futex value of private file mappings in FUTEX_WAIT\n", - basename(argv[0])); - - ret =3D pthread_create(&thr, NULL, thr_futex_wait, NULL); - if (ret < 0) { - fprintf(stderr, "pthread_create error\n"); - ret =3D RET_ERROR; - goto out; - } - - info("wait a while\n"); + + res =3D pthread_create(&thr, NULL, thr_futex_wait, NULL); + if (res < 0) + ksft_exit_fail_msg("pthread_create error\n"); + + ksft_print_dbg_msg("wait a while\n"); usleep(WAKE_WAIT_US); val =3D 2; res =3D futex_wake(&val, 1, 0); - info("futex_wake %d\n", res); - if (res !=3D 1) { - fail("FUTEX_WAKE didn't find the waiting thread.\n"); - ret =3D RET_FAIL; - } + ksft_print_dbg_msg("futex_wake %d\n", res); + if (res !=3D 1) + ksft_exit_fail_msg("FUTEX_WAKE didn't find the waiting thread.\n"); =20 - info("join\n"); + ksft_print_dbg_msg("join\n"); pthread_join(thr, NULL); =20 - out: - print_result(TEST_NAME, ret); - return ret; + ksft_test_result_pass("wait_private_mapped_file"); } + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/futex/functional/run.sh b/tools/testin= g/selftests/futex/functional/run.sh index a93eb2a21d4aa23f874bf11ccc852838a4c3866f..2b3409d2513ea6b2c29efbcbded= fedd525f64151 100755 --- a/tools/testing/selftests/futex/functional/run.sh +++ b/tools/testing/selftests/futex/functional/run.sh @@ -48,7 +48,7 @@ echo =20 echo ./futex_wait_uninitialized_heap -./futex_wait_private_mapped_file $COLOR +./futex_wait_private_mapped_file =20 echo ./futex_wait $COLOR --=20 2.49.0 From nobody Tue Oct 7 22:39:43 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 D0E9C309DB9; Fri, 4 Jul 2025 15:05:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641553; cv=none; b=WBej1wBKArbTIfL/ho+CFDEUaGukZypHpGXjZutAHyE9PY8FfP9C93q+HmQTu3ykIsIYpH0lI1+IK4UsqSWqbKycWitOJaW6/hW48WpEzcSkmA8DcauH04T/uPQY7XpKmHAOggrnOoHBEgcPh6uenDx2NOLdSMZI/bBd/gVKnCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641553; c=relaxed/simple; bh=8RzRZSLDMjobrezoZPjBrKTp5EQRctaBkvLREMCWMVo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=O7LN5GkpS8GtXgu/8v10c8q9Zu1wXVizHmWYO/ljIo5EuiEdFCHQYVcNUa72bpSQtkv2V5+BmSQgq2Tp+6Rc/D2FE0HSr1Kc0jwsExkoM+Zn1FTZvOMf9pHbH0BdwAK0EXA0xm7OFTnpyoauneNz8vy/OjG3YWNA/Ci1cgW2pmY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=JJUifL6C; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="JJUifL6C" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=byWJufBHF2TZ6Av5c14+Z5l9xUJ+8KykWZvC68i3/FY=; b=JJUifL6CXzSUOEnDvCAqHwzyCf rWRQipugqAN1DT+omUjGJ1KhXVF17oiLYgupArwyYU89Eo6ttfxAGvqV6M/9EF+3xuySQGIBFtGdR iHyZGwctLjoJNnQq5KtAkGPi7mYhmHvGFai6eGk15jFLlnGfHhbNtmKZjNJmSXgPTYixohO7Z+K18 SqS3Yo2V6/Wgz7lh1mLBhgbulIUcnq6sAf//Kih+AC7/E3R7/kjo78FNmMcGFSeSEgyRSwCMBtgY8 OYYp1byX1XsgSDR2KBvoQ6SIN4L/c9lylUgnY1RpvNGq86xeYvp5bqO3v3pr3G1avbMBp3nxgUzsp +JU0T31g==; Received: from [179.100.5.63] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uXhz3-00CTWt-GJ; Fri, 04 Jul 2025 17:05:49 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 04 Jul 2025 12:05:13 -0300 Subject: [PATCH 09/15] selftests/futex: Refactor futex_wait with kselftest_harness.h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-tonyk-robust_test_cleanup-v1-9-c0ff4f24c4e1@igalia.com> References: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> In-Reply-To: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Sebastian Andrzej Siewior Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 To reduce the boilerplate code, refactor futex_wait test to use kselftest_harness header instead of futex's logging header. Signed-off-by: Andr=C3=A9 Almeida --- .../selftests/futex/functional/futex_wait.c | 103 ++++++++---------= ---- tools/testing/selftests/futex/functional/run.sh | 2 +- 2 files changed, 39 insertions(+), 66 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_wait.c b/tools/= testing/selftests/futex/functional/futex_wait.c index 685140d9b93d2f71f7f1d9f07c29bfd38adfd059..5a772a7e6831b13c3d63084c775= 9560825b93628 100644 --- a/tools/testing/selftests/futex/functional/futex_wait.c +++ b/tools/testing/selftests/futex/functional/futex_wait.c @@ -9,25 +9,16 @@ #include #include #include -#include "logging.h" + #include "futextest.h" +#include "../../kselftest_harness.h" =20 -#define TEST_NAME "futex-wait" #define timeout_ns 30000000 #define WAKE_WAIT_US 10000 #define SHM_PATH "futex_shm_file" =20 void *futex; =20 -void usage(char *prog) -{ - printf("Usage: %s\n", prog); - printf(" -c Use color\n"); - printf(" -h Display this help message\n"); - printf(" -v L Verbosity level: %d=3DQUIET %d=3DCRITICAL %d=3DINFO\n", - VQUIET, VCRITICAL, VINFO); -} - static void *waiterfn(void *arg) { struct timespec to; @@ -45,53 +36,37 @@ static void *waiterfn(void *arg) return NULL; } =20 -int main(int argc, char *argv[]) +TEST(private_futex) { - int res, ret =3D RET_PASS, fd, c, shm_id; - u_int32_t f_private =3D 0, *shared_data; + int res; + u_int32_t f_private =3D 0; unsigned int flags =3D FUTEX_PRIVATE_FLAG; pthread_t waiter; - void *shm; =20 futex =3D &f_private; =20 - while ((c =3D getopt(argc, argv, "cht:v:")) !=3D -1) { - switch (c) { - case 'c': - log_color(1); - break; - case 'h': - usage(basename(argv[0])); - exit(0); - case 'v': - log_verbosity(atoi(optarg)); - break; - default: - usage(basename(argv[0])); - exit(1); - } - } - - ksft_print_header(); - ksft_set_plan(3); - ksft_print_msg("%s: Test futex_wait\n", basename(argv[0])); - /* Testing a private futex */ - info("Calling private futex_wait on futex: %p\n", futex); + ksft_print_dbg_msg("Calling private futex_wait on futex: %p\n", futex); if (pthread_create(&waiter, NULL, waiterfn, (void *) &flags)) - error("pthread_create failed\n", errno); + ksft_exit_fail_msg("pthread_create failed\n"); =20 usleep(WAKE_WAIT_US); =20 - info("Calling private futex_wake on futex: %p\n", futex); + ksft_print_dbg_msg("Calling private futex_wake on futex: %p\n", futex); res =3D futex_wake(futex, 1, FUTEX_PRIVATE_FLAG); if (res !=3D 1) { ksft_test_result_fail("futex_wake private returned: %d %s\n", errno, strerror(errno)); - ret =3D RET_FAIL; } else { ksft_test_result_pass("futex_wake private succeeds\n"); } +} + +TEST(anon_page) +{ + u_int32_t *shared_data; + pthread_t waiter; + int res, shm_id; =20 /* Testing an anon page shared memory */ shm_id =3D shmget(IPC_PRIVATE, 4096, IPC_CREAT | 0666); @@ -105,67 +80,65 @@ int main(int argc, char *argv[]) *shared_data =3D 0; futex =3D shared_data; =20 - info("Calling shared (page anon) futex_wait on futex: %p\n", futex); + ksft_print_dbg_msg("Calling shared (page anon) futex_wait on futex: %p\n"= , futex); if (pthread_create(&waiter, NULL, waiterfn, NULL)) - error("pthread_create failed\n", errno); + ksft_exit_fail_msg("pthread_create failed\n"); =20 usleep(WAKE_WAIT_US); =20 - info("Calling shared (page anon) futex_wake on futex: %p\n", futex); + ksft_print_dbg_msg("Calling shared (page anon) futex_wake on futex: %p\n"= , futex); res =3D futex_wake(futex, 1, 0); if (res !=3D 1) { ksft_test_result_fail("futex_wake shared (page anon) returned: %d %s\n", errno, strerror(errno)); - ret =3D RET_FAIL; } else { ksft_test_result_pass("futex_wake shared (page anon) succeeds\n"); } =20 + shmdt(shared_data); +} + +TEST(file_backed) +{ + u_int32_t f_private =3D 0; + pthread_t waiter; + int res, fd; + void *shm; =20 /* Testing a file backed shared memory */ fd =3D open(SHM_PATH, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); - if (fd < 0) { - perror("open"); - exit(1); - } + if (fd < 0) + ksft_exit_fail_msg("open"); =20 - if (ftruncate(fd, sizeof(f_private))) { - perror("ftruncate"); - exit(1); - } + if (ftruncate(fd, sizeof(f_private))) + ksft_exit_fail_msg("ftruncate"); =20 shm =3D mmap(NULL, sizeof(f_private), PROT_READ | PROT_WRITE, MAP_SHARED,= fd, 0); - if (shm =3D=3D MAP_FAILED) { - perror("mmap"); - exit(1); - } + if (shm =3D=3D MAP_FAILED) + ksft_exit_fail_msg("mmap"); =20 memcpy(shm, &f_private, sizeof(f_private)); =20 futex =3D shm; =20 - info("Calling shared (file backed) futex_wait on futex: %p\n", futex); + ksft_print_dbg_msg("Calling shared (file backed) futex_wait on futex: %p\= n", futex); if (pthread_create(&waiter, NULL, waiterfn, NULL)) - error("pthread_create failed\n", errno); + ksft_exit_fail_msg("pthread_create failed\n"); =20 usleep(WAKE_WAIT_US); =20 - info("Calling shared (file backed) futex_wake on futex: %p\n", futex); + ksft_print_dbg_msg("Calling shared (file backed) futex_wake on futex: %p\= n", futex); res =3D futex_wake(shm, 1, 0); if (res !=3D 1) { ksft_test_result_fail("futex_wake shared (file backed) returned: %d %s\n= ", errno, strerror(errno)); - ret =3D RET_FAIL; } else { ksft_test_result_pass("futex_wake shared (file backed) succeeds\n"); } =20 - /* Freeing resources */ - shmdt(shared_data); munmap(shm, sizeof(f_private)); remove(SHM_PATH); close(fd); - - ksft_print_cnts(); - return ret; } + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/futex/functional/run.sh b/tools/testin= g/selftests/futex/functional/run.sh index 2b3409d2513ea6b2c29efbcbdedfedd525f64151..b461a0a075a2ae526d37a1fcd09= e196e48c2d4ff 100755 --- a/tools/testing/selftests/futex/functional/run.sh +++ b/tools/testing/selftests/futex/functional/run.sh @@ -51,7 +51,7 @@ echo ./futex_wait_private_mapped_file =20 echo -./futex_wait $COLOR +./futex_wait =20 echo ./futex_requeue $COLOR --=20 2.49.0 From nobody Tue Oct 7 22:39:43 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 56154309DD9; Fri, 4 Jul 2025 15:05:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641556; cv=none; b=qjl0+aHgeetVqoVlGVUCuthQHvbPVmokCN3NRZzibBZKcwFfyBX5n+ctQiTPtA8jrP7ITViPTWhlFNO9LO9OxTuvkmlm3Acf/q7r+j2i9Ya4ti1jKrzx6iGWaqJ5RxS7Q4zkI0vebetkp8dP/HU6D+SBi1QHDRYnGHWRhtdR2lY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641556; c=relaxed/simple; bh=a2WsffCtMjrOr3eN7sgJUtVLrxo/37LsvsGcPypTyJY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=K355KAPXcrSPh/m2YCGsPuneQHeSo6T1fp7l9dwQJAwND2zYnr8rVz0t7m1Sk69iDSkwuVBKlz7FnI5kTqfcQMlh8idlSnvw3SElct61R07C7l2Gc2XapLF/UD1gDtbq145ZntoLhe3f0OY5Q0vUS88XCaXs3I4Cov71KEfQVtU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=gueOyhD+; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="gueOyhD+" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=hDJnfoXLRCbu8K4cHIiQu4FkSAttrXT2oWxF07oKpXs=; b=gueOyhD+SHa5wkoBFMtEdsemeu 8R91OqMFuCfvHQKgLa70U4CupTiFKFVKP32+GooC2SS/FOGgCeBvRVOz0XbWSb65rK3vp1D6SeP/m bsG4u3aqZuoMgH8liTfHQwICreI8g8CTSWhjXffv1+FBu4iwsa2zvYo9LozCdbtlh83meXsBnxIm2 aRVuZU66w+/fkUYQEIYzqkFqStzCeBS0d6kFyQQtcb8ZmlNz+SIoYnc9h5Ldrob8D5fmoHC2M/H7Z LkLL01jVHrTehU9ZaJ8R1D9xELUed5iEKVupNkKsgdh7NzgDjLvegfisStPuO/TqQJmc7gk+wyl+7 +z06dPfA==; Received: from [179.100.5.63] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uXhz6-00CTWt-5n; Fri, 04 Jul 2025 17:05:52 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 04 Jul 2025 12:05:14 -0300 Subject: [PATCH 10/15] selftests/futex: Refactor futex_requeue with kselftest_harness.h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-tonyk-robust_test_cleanup-v1-10-c0ff4f24c4e1@igalia.com> References: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> In-Reply-To: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Sebastian Andrzej Siewior Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 To reduce the boilerplate code, refactor futex_requeue test to use kselftest_harness header instead of futex's logging header. Signed-off-by: Andr=C3=A9 Almeida --- .../selftests/futex/functional/futex_requeue.c | 76 +++++++-----------= ---- tools/testing/selftests/futex/functional/run.sh | 2 +- 2 files changed, 24 insertions(+), 54 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_requeue.c b/too= ls/testing/selftests/futex/functional/futex_requeue.c index 51485be6eb2f1be6d0e30bc26c116515a0e5e7cc..69e2555b60399174a16ee1316b0= b7d2e10419989 100644 --- a/tools/testing/selftests/futex/functional/futex_requeue.c +++ b/tools/testing/selftests/futex/functional/futex_requeue.c @@ -7,24 +7,15 @@ =20 #include #include -#include "logging.h" + #include "futextest.h" +#include "../../kselftest_harness.h" =20 -#define TEST_NAME "futex-requeue" #define timeout_ns 30000000 #define WAKE_WAIT_US 10000 =20 volatile futex_t *f1; =20 -void usage(char *prog) -{ - printf("Usage: %s\n", prog); - printf(" -c Use color\n"); - printf(" -h Display this help message\n"); - printf(" -v L Verbosity level: %d=3DQUIET %d=3DCRITICAL %d=3DINFO\n", - VQUIET, VCRITICAL, VINFO); -} - void *waiterfn(void *arg) { struct timespec to; @@ -38,67 +29,49 @@ void *waiterfn(void *arg) return NULL; } =20 -int main(int argc, char *argv[]) +TEST(requeue_single) { - pthread_t waiter[10]; - int res, ret =3D RET_PASS; - int c, i; volatile futex_t _f1 =3D 0; volatile futex_t f2 =3D 0; + pthread_t waiter[10]; + int res; =20 f1 =3D &_f1; =20 - while ((c =3D getopt(argc, argv, "cht:v:")) !=3D -1) { - switch (c) { - case 'c': - log_color(1); - break; - case 'h': - usage(basename(argv[0])); - exit(0); - case 'v': - log_verbosity(atoi(optarg)); - break; - default: - usage(basename(argv[0])); - exit(1); - } - } - - ksft_print_header(); - ksft_set_plan(2); - ksft_print_msg("%s: Test futex_requeue\n", - basename(argv[0])); - /* * Requeue a waiter from f1 to f2, and wake f2. */ if (pthread_create(&waiter[0], NULL, waiterfn, NULL)) - error("pthread_create failed\n", errno); + ksft_exit_fail_msg("pthread_create failed\n"); =20 usleep(WAKE_WAIT_US); =20 - info("Requeuing 1 futex from f1 to f2\n"); + ksft_print_dbg_msg("Requeuing 1 futex from f1 to f2\n"); res =3D futex_cmp_requeue(f1, 0, &f2, 0, 1, 0); - if (res !=3D 1) { + if (res !=3D 1) ksft_test_result_fail("futex_requeue simple returned: %d %s\n", res ? errno : res, res ? strerror(errno) : ""); - ret =3D RET_FAIL; - } =20 - - info("Waking 1 futex at f2\n"); + ksft_print_dbg_msg("Waking 1 futex at f2\n"); res =3D futex_wake(&f2, 1, 0); if (res !=3D 1) { ksft_test_result_fail("futex_requeue simple returned: %d %s\n", res ? errno : res, res ? strerror(errno) : ""); - ret =3D RET_FAIL; } else { ksft_test_result_pass("futex_requeue simple succeeds\n"); } +} + +TEST(requeue_multiple) +{ + volatile futex_t _f1 =3D 0; + volatile futex_t f2 =3D 0; + pthread_t waiter[10]; + int res, i; =20 + f1 =3D &_f1; =20 /* * Create 10 waiters at f1. At futex_requeue, wake 3 and requeue 7. @@ -106,31 +79,28 @@ int main(int argc, char *argv[]) */ for (i =3D 0; i < 10; i++) { if (pthread_create(&waiter[i], NULL, waiterfn, NULL)) - error("pthread_create failed\n", errno); + ksft_exit_fail_msg("pthread_create failed\n"); } =20 usleep(WAKE_WAIT_US); =20 - info("Waking 3 futexes at f1 and requeuing 7 futexes from f1 to f2\n"); + ksft_print_dbg_msg("Waking 3 futexes at f1 and requeuing 7 futexes from f= 1 to f2\n"); res =3D futex_cmp_requeue(f1, 0, &f2, 3, 7, 0); if (res !=3D 10) { ksft_test_result_fail("futex_requeue many returned: %d %s\n", res ? errno : res, res ? strerror(errno) : ""); - ret =3D RET_FAIL; } =20 - info("Waking INT_MAX futexes at f2\n"); + ksft_print_dbg_msg("Waking INT_MAX futexes at f2\n"); res =3D futex_wake(&f2, INT_MAX, 0); if (res !=3D 7) { ksft_test_result_fail("futex_requeue many returned: %d %s\n", res ? errno : res, res ? strerror(errno) : ""); - ret =3D RET_FAIL; } else { ksft_test_result_pass("futex_requeue many succeeds\n"); } - - ksft_print_cnts(); - return ret; } + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/futex/functional/run.sh b/tools/testin= g/selftests/futex/functional/run.sh index b461a0a075a2ae526d37a1fcd09e196e48c2d4ff..af32695cfaded4f834c7c07c249= 08b8a3e32fe28 100755 --- a/tools/testing/selftests/futex/functional/run.sh +++ b/tools/testing/selftests/futex/functional/run.sh @@ -54,7 +54,7 @@ echo ./futex_wait =20 echo -./futex_requeue $COLOR +./futex_requeue =20 echo ./futex_waitv $COLOR --=20 2.49.0 From nobody Tue Oct 7 22:39:43 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 11A6E30B989; Fri, 4 Jul 2025 15:05:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641559; cv=none; b=j6nMpNCg0Lj1hGWHFmm3SiloMR5eJ9J9Ih24Y5WuwM2mFAEqC5yeVDYX3Eo3EoWMbHihL+ymBWzeL8UaC9xUQGk/9PBovigINY0jO/gYKwYFJ/9nEvoZkMO/WnW9nzUJ6EAWWV+GOrrn8hYK53/z3fVr2O86lIunGmbasWk7PzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641559; c=relaxed/simple; bh=qYXwK2YGQZqip896SrJHiyTGRpexJhyk0g/culYDl1g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VJPsQFxyfjx1BvAgPpvN7ykA0MgFkXoblQbvOqJX2v4SIMYGsWKUDJorT5wThf2z2JMQrr8cBjKIh1KJLf292hq+GPvbuk72BPuNs0+nVcyU1w4hhhAw2nlL+7qoHmcWxIQorOupazMGt85GdoVvRLiwnyvvcXvPvEtvK4fFTF4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=VIqSpHEW; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="VIqSpHEW" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=OYN5jYCYnRMuaZ05Z/No4kCfDRRyEiAgDtvFVDOFf9k=; b=VIqSpHEWX1yZQWJhVyTAUqia/7 Xpwf0FuM1Ub4TIDvJb+57LQTOATSHd4bC1Pq2W/fFEvcAjHIusaVTB6JzbcDnSoXdPjo1P8zHgRnP zi//4h68yGEaECSUi2Imjak+LUNaeMURtkAQmpIrYPk+z+dX4v9C5/9h1fwrfVomjNidpXIePD8xD wzoIRm5wOWc2l688meNBjDQTZP+mBBhpFysjJBoK8RAKIi4ulsAAz9R3cX8Az59K8BqX/v3tBhXSR FQivzCRPXYuzKU+4kSQk3NYnYFvVlJ2JNaR+QiEuGWJLW/lgwxiatFH5V/c7hVG5vB+W9rsX8/18k EF1C4nyw==; Received: from [179.100.5.63] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uXhz8-00CTWt-Rs; Fri, 04 Jul 2025 17:05:55 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 04 Jul 2025 12:05:15 -0300 Subject: [PATCH 11/15] selftests/futex: Refactor futex_waitv with kselftest_harness.h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-tonyk-robust_test_cleanup-v1-11-c0ff4f24c4e1@igalia.com> References: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> In-Reply-To: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Sebastian Andrzej Siewior Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 To reduce the boilerplate code, refactor futex_waitv test to use kselftest_harness header instead of futex's logging header. Signed-off-by: Andr=C3=A9 Almeida --- .../selftests/futex/functional/futex_waitv.c | 98 ++++++++++--------= ---- tools/testing/selftests/futex/functional/run.sh | 2 +- 2 files changed, 44 insertions(+), 56 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_waitv.c b/tools= /testing/selftests/futex/functional/futex_waitv.c index a94337f677e181544992efd53891ccca02787adb..8ceaa372b2524fe243400c50382= a142a30e61159 100644 --- a/tools/testing/selftests/futex/functional/futex_waitv.c +++ b/tools/testing/selftests/futex/functional/futex_waitv.c @@ -15,25 +15,16 @@ #include #include #include + #include "futextest.h" #include "futex2test.h" -#include "logging.h" +#include "../../kselftest_harness.h" =20 -#define TEST_NAME "futex-wait" #define WAKE_WAIT_US 10000 #define NR_FUTEXES 30 static struct futex_waitv waitv[NR_FUTEXES]; u_int32_t futexes[NR_FUTEXES] =3D {0}; =20 -void usage(char *prog) -{ - printf("Usage: %s\n", prog); - printf(" -c Use color\n"); - printf(" -h Display this help message\n"); - printf(" -v L Verbosity level: %d=3DQUIET %d=3DCRITICAL %d=3DINFO\n", - VQUIET, VCRITICAL, VINFO); -} - void *waiterfn(void *arg) { struct timespec to; @@ -41,7 +32,7 @@ void *waiterfn(void *arg) =20 /* setting absolute timeout for futex2 */ if (clock_gettime(CLOCK_MONOTONIC, &to)) - error("gettime64 failed\n", errno); + ksft_exit_fail_msg("gettime64 failed\n"); =20 to.tv_sec++; =20 @@ -57,34 +48,10 @@ void *waiterfn(void *arg) return NULL; } =20 -int main(int argc, char *argv[]) +TEST(private_waitv) { pthread_t waiter; - int res, ret =3D RET_PASS; - struct timespec to; - int c, i; - - while ((c =3D getopt(argc, argv, "cht:v:")) !=3D -1) { - switch (c) { - case 'c': - log_color(1); - break; - case 'h': - usage(basename(argv[0])); - exit(0); - case 'v': - log_verbosity(atoi(optarg)); - break; - default: - usage(basename(argv[0])); - exit(1); - } - } - - ksft_print_header(); - ksft_set_plan(7); - ksft_print_msg("%s: Test FUTEX_WAITV\n", - basename(argv[0])); + int res, i; =20 for (i =3D 0; i < NR_FUTEXES; i++) { waitv[i].uaddr =3D (uintptr_t)&futexes[i]; @@ -95,7 +62,7 @@ int main(int argc, char *argv[]) =20 /* Private waitv */ if (pthread_create(&waiter, NULL, waiterfn, NULL)) - error("pthread_create failed\n", errno); + ksft_exit_fail_msg("pthread_create failed\n"); =20 usleep(WAKE_WAIT_US); =20 @@ -104,10 +71,15 @@ int main(int argc, char *argv[]) ksft_test_result_fail("futex_wake private returned: %d %s\n", res ? errno : res, res ? strerror(errno) : ""); - ret =3D RET_FAIL; } else { ksft_test_result_pass("futex_waitv private\n"); } +} + +TEST(shared_waitv) +{ + pthread_t waiter; + int res, i; =20 /* Shared waitv */ for (i =3D 0; i < NR_FUTEXES; i++) { @@ -128,7 +100,7 @@ int main(int argc, char *argv[]) } =20 if (pthread_create(&waiter, NULL, waiterfn, NULL)) - error("pthread_create failed\n", errno); + ksft_exit_fail_msg("pthread_create failed\n"); =20 usleep(WAKE_WAIT_US); =20 @@ -137,19 +109,24 @@ int main(int argc, char *argv[]) ksft_test_result_fail("futex_wake shared returned: %d %s\n", res ? errno : res, res ? strerror(errno) : ""); - ret =3D RET_FAIL; } else { ksft_test_result_pass("futex_waitv shared\n"); } =20 for (i =3D 0; i < NR_FUTEXES; i++) shmdt(u64_to_ptr(waitv[i].uaddr)); +} + +TEST(invalid_flag) +{ + struct timespec to; + int res; =20 /* Testing a waiter without FUTEX_32 flag */ waitv[0].flags =3D FUTEX_PRIVATE_FLAG; =20 if (clock_gettime(CLOCK_MONOTONIC, &to)) - error("gettime64 failed\n", errno); + ksft_exit_fail_msg("gettime64 failed\n"); =20 to.tv_sec++; =20 @@ -158,17 +135,21 @@ int main(int argc, char *argv[]) ksft_test_result_fail("futex_waitv private returned: %d %s\n", res ? errno : res, res ? strerror(errno) : ""); - ret =3D RET_FAIL; } else { ksft_test_result_pass("futex_waitv without FUTEX_32\n"); } +} =20 +TEST(unaligned_address) +{ + struct timespec to; + int res; /* 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)) - error("gettime64 failed\n", errno); + ksft_exit_fail_msg("gettime64 failed\n"); =20 to.tv_sec++; =20 @@ -177,16 +158,21 @@ int main(int argc, char *argv[]) ksft_test_result_fail("futex_wake private returned: %d %s\n", res ? errno : res, res ? strerror(errno) : ""); - ret =3D RET_FAIL; } else { ksft_test_result_pass("futex_waitv with an unaligned address\n"); } +} + +TEST(null_address) +{ + struct timespec to; + int res; =20 /* Testing a NULL address for waiters.uaddr */ waitv[0].uaddr =3D 0x00000000; =20 if (clock_gettime(CLOCK_MONOTONIC, &to)) - error("gettime64 failed\n", errno); + ksft_exit_fail_msg("gettime64 failed\n"); =20 to.tv_sec++; =20 @@ -195,14 +181,13 @@ int main(int argc, char *argv[]) ksft_test_result_fail("futex_waitv private returned: %d %s\n", res ? errno : res, res ? strerror(errno) : ""); - ret =3D RET_FAIL; } 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)) - error("gettime64 failed\n", errno); + ksft_exit_fail_msg("gettime64 failed\n"); =20 to.tv_sec++; =20 @@ -211,14 +196,19 @@ int main(int argc, char *argv[]) ksft_test_result_fail("futex_waitv private returned: %d %s\n", res ? errno : res, res ? strerror(errno) : ""); - ret =3D RET_FAIL; } else { ksft_test_result_pass("futex_waitv NULL address in *waiters\n"); } +} + +TEST(invalid_clockid) +{ + struct timespec to; + int res; =20 /* Testing an invalid clockid */ if (clock_gettime(CLOCK_MONOTONIC, &to)) - error("gettime64 failed\n", errno); + ksft_exit_fail_msg("gettime64 failed\n"); =20 to.tv_sec++; =20 @@ -227,11 +217,9 @@ int main(int argc, char *argv[]) ksft_test_result_fail("futex_waitv private returned: %d %s\n", res ? errno : res, res ? strerror(errno) : ""); - ret =3D RET_FAIL; } else { ksft_test_result_pass("futex_waitv invalid clockid\n"); } - - ksft_print_cnts(); - return ret; } + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/futex/functional/run.sh b/tools/testin= g/selftests/futex/functional/run.sh index af32695cfaded4f834c7c07c24908b8a3e32fe28..6086b5652687af3cd2d4e4bd561= 59149d5bb5fea 100755 --- a/tools/testing/selftests/futex/functional/run.sh +++ b/tools/testing/selftests/futex/functional/run.sh @@ -57,7 +57,7 @@ echo ./futex_requeue =20 echo -./futex_waitv $COLOR +./futex_waitv =20 echo ./futex_priv_hash $COLOR --=20 2.49.0 From nobody Tue Oct 7 22:39:43 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 98C3830B9AA; Fri, 4 Jul 2025 15:05:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641561; cv=none; b=I8AGEy7NyPs92lwX059cxqCEg2EIrkq1yixNsgHvnlbbZa2Emk6Anuqff6/cj84U8BIqc9oh/Vb7u8TY/jwnOlcJLFt9re990SL7J9vaqMZSHBUucqj9KE38zLYbwZNFwP22Ss241Br+B2M1U0WtWMd5ZevxF5UE5PnSJQ+7ZZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641561; c=relaxed/simple; bh=kAi9i9IfyttvVKnUHDkuA9SHG5Amwz3TQLac87kM/c4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=J9RK+RVQo6SuXooe8GhjH91fA4rVzOyMUTAuXyf7O+H3o6nngQ2VxNx1am5Glu81vRshCjISlbmZ0ujTlm1Dwo726cm37Ds3ojPOgXF+1leeXwfvGPnQAnQsvRCxQRzICSwpA++06vlG3d+nFwitZ9AKhnpMqR6AlKfk0/Vu/eg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=C2+InXdP; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="C2+InXdP" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=XxdhNpyBlGxsIIdE0FBlYLv5Nk70hHWxt9uMVX8H2OM=; b=C2+InXdP77V9nIzDoUT0OGvb8Q DoIWX3XwpacKNLtlz4B/8G4IN344LI8/fRmJqgcXqjSwQ2ketxPaCrRFPs6jt3Tg/F2QvEuU5lNzY UWSIgX0sFvJhx3hHI4+GSwjpk18iZlgjAG5Nvn4cqE7wyVRuQ5zvq2kgS3UiYPaeK6tGiqUVLGqBr E2Ga3IMFFbbWI6hRZyUzOALh0a90xhbgeTTW2tuikgqYH4MMWErhuA90Rsvln1nDKiXTy80CTaK5e 1U8KhYj8naYE7Oz1jhKKSwN5Nun+ty1+5hYN58eYw0FcW7QOwjjBl5TaCyK89vtcPtGie+HCD7UWY /WDjnk/A==; Received: from [179.100.5.63] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uXhzB-00CTWt-Gx; Fri, 04 Jul 2025 17:05:57 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 04 Jul 2025 12:05:16 -0300 Subject: [PATCH 12/15] selftests/futex: Refactor futex_priv_hash with kselftest_harness.h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-tonyk-robust_test_cleanup-v1-12-c0ff4f24c4e1@igalia.com> References: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> In-Reply-To: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Sebastian Andrzej Siewior Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 To reduce the boilerplate code, refactor futex_priv_hash test to use kselftest_harness header instead of futex's logging header. Use the fixture feature to run the same test with different parameters (with global hash enabled and disabled). Signed-off-by: Andr=C3=A9 Almeida --- .../selftests/futex/functional/futex_priv_hash.c | 79 ++++++++++--------= ---- tools/testing/selftests/futex/functional/run.sh | 3 +- 2 files changed, 35 insertions(+), 47 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_priv_hash.c b/t= ools/testing/selftests/futex/functional/futex_priv_hash.c index 24a92dc94eb86cc0e03ded5d6a4a0a96b0dc8a36..8ad7135cb59adc16bd2ff9ea577= 96a3a5c282ae5 100644 --- a/tools/testing/selftests/futex/functional/futex_priv_hash.c +++ b/tools/testing/selftests/futex/functional/futex_priv_hash.c @@ -14,7 +14,7 @@ #include #include =20 -#include "logging.h" +#include "../../kselftest_harness.h" =20 #define MAX_THREADS 64 =20 @@ -111,50 +111,42 @@ static void join_max_threads(void) } } =20 -static void usage(char *prog) +static const char *test_msg_auto_create =3D "Automatic hash bucket init on= thread creation.\n"; +static const char *test_msg_auto_inc =3D "Automatic increase with more tha= n 16 CPUs\n"; + +FIXTURE(global_hash) +{ +}; + +FIXTURE_VARIANT(global_hash) +{ + bool use_global_hash; +}; + +FIXTURE_VARIANT_ADD(global_hash, enabled) +{ + .use_global_hash =3D true, +}; + +FIXTURE_VARIANT_ADD(global_hash, disabled) +{ + .use_global_hash =3D false, +}; + +FIXTURE_SETUP(global_hash) { - printf("Usage: %s\n", prog); - printf(" -c Use color\n"); - printf(" -g Test global hash instead intead local immutable \n"); - printf(" -h Display this help message\n"); - printf(" -v L Verbosity level: %d=3DQUIET %d=3DCRITICAL %d=3DINFO\n", - VQUIET, VCRITICAL, VINFO); } =20 -static const char *test_msg_auto_create =3D "Automatic hash bucket init on= thread creation.\n"; -static const char *test_msg_auto_inc =3D "Automatic increase with more tha= n 16 CPUs\n"; +FIXTURE_TEARDOWN(global_hash) +{ +} =20 -int main(int argc, char *argv[]) +TEST_F(global_hash, priv_hash) { int futex_slots1, futex_slotsn, online_cpus; pthread_mutexattr_t mutex_attr_pi; - int use_global_hash =3D 0; + int use_global_hash =3D variant->use_global_hash; int ret; - int c; - - while ((c =3D getopt(argc, argv, "cghv:")) !=3D -1) { - switch (c) { - case 'c': - log_color(1); - break; - case 'g': - use_global_hash =3D 1; - break; - case 'h': - usage(basename(argv[0])); - exit(0); - break; - case 'v': - log_verbosity(atoi(optarg)); - break; - default: - usage(basename(argv[0])); - exit(1); - } - } - - ksft_print_header(); - ksft_set_plan(22); =20 ret =3D pthread_mutexattr_init(&mutex_attr_pi); ret |=3D pthread_mutexattr_setprotocol(&mutex_attr_pi, PTHREAD_PRIO_INHER= IT); @@ -259,7 +251,7 @@ int main(int argc, char *argv[]) ksft_test_result(ret =3D=3D 0, "Immutable resize to 4\n"); } if (ret !=3D 0) - goto out; + return; =20 futex_hash_slots_set_must_fail(4, 0); futex_hash_slots_set_must_fail(4, FH_FLAG_IMMUTABLE); @@ -269,10 +261,9 @@ int main(int argc, char *argv[]) futex_hash_slots_set_must_fail(6, FH_FLAG_IMMUTABLE); =20 ret =3D pthread_barrier_init(&barrier_main, NULL, MAX_THREADS); - if (ret !=3D 0) { + if (ret !=3D 0) ksft_exit_fail_msg("pthread_barrier_init failed: %m\n"); - return 1; - } + create_max_threads(thread_lock_fn); join_max_threads(); =20 @@ -285,8 +276,6 @@ int main(int argc, char *argv[]) =20 ret =3D futex_hash_immutable_get(); ksft_test_result(ret =3D=3D 1, "Hash reports to be immutable\n"); - -out: - ksft_finished(); - return 0; } + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/futex/functional/run.sh b/tools/testin= g/selftests/futex/functional/run.sh index 6086b5652687af3cd2d4e4bd56159149d5bb5fea..f725531f06c4a88e6d3ebbabb62= 8a5d5009eaa3b 100755 --- a/tools/testing/selftests/futex/functional/run.sh +++ b/tools/testing/selftests/futex/functional/run.sh @@ -60,8 +60,7 @@ echo ./futex_waitv =20 echo -./futex_priv_hash $COLOR -./futex_priv_hash -g $COLOR +./futex_priv_hash =20 echo ./futex_numa_mpol $COLOR --=20 2.49.0 From nobody Tue Oct 7 22:39:43 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 31CCA2D239F; Fri, 4 Jul 2025 15:06:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641563; cv=none; b=FcD7rJdyQIifHZnrtmkpZvyyThWNMpur6Z/qtqjUNTLJJm5ptiM1iJUFqk8/auXsWg2ZAxEVG8EpnevT8hCJaIFUo7tiN8F0Rd+dN5P5RmEFCsEF+2T469xW50UkjVz8KvDeAOawoZN4F4/xwe9YwfXfG9Q6BQ5rbU/ZY1iQs30= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641563; c=relaxed/simple; bh=17FfIMnlwwp+CoU5dF8jfiI05bINnG0s1RoAWdgmX/g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DPNFpDj8snlaT88CLZH6UjHamuLg2ykilmNjTUyMUjT+HaT/COIkOfPjZUg26bU5+jIQ/EfBJJOsmB0bVItiE7rHEpnV3ug103MepxCZodVhQeRme4gfLTP86e6G2fNSWyp9O7SitArFVBdaSd/DoZJBjp/Ciyl//EJIgtOT2eQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=LnXApKQX; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="LnXApKQX" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=lTueqYYX+5lziQBuPtjlMwnK94+sxOr/xm3TqVdfy9U=; b=LnXApKQXtXkhNbt8NPS+1B58Kn nmdL6ANFFxIoEARwZE9wR+k7CgIV3CNfD3olvUwioh/gc9UQy5qyS5wzyDwQnb1eAD35z2wLA8zPe isgS/AvZ5fJNZy/cbCy5Gxx6BEZo+7vVM5z8izZqlBjGCb4iW0FcSQ+l7oZtsL17xqEY+27p5evx2 eClRbo6jJAOvs+jlMXi3Of5rI35sGRIfpXuu/x1bCzdPQneoNHPzgEagzDmxJfQtcGVRJSRp9IPZl ieIMsJbkHHI/G7vwCwCB0RKRqCvNcvZDHjir2+/PVsFuqpaBMiI1nA8sV959N7v1gaZKr5DvxUN31 XLc1cgxg==; Received: from [179.100.5.63] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uXhzE-00CTWt-6h; Fri, 04 Jul 2025 17:06:00 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 04 Jul 2025 12:05:17 -0300 Subject: [PATCH 13/15] selftests/futex: Refactor futex_numa_mpol with kselftest_harness.h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-tonyk-robust_test_cleanup-v1-13-c0ff4f24c4e1@igalia.com> References: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> In-Reply-To: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Sebastian Andrzej Siewior Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 To reduce the boilerplate code, refactor futex_numa_mpol test to use kselftest_harness header instead of futex's logging header. Using kselftest_harness produces a side effect of having two adjacents buffers, because test_harness_run() calls mmap() before this test calling mmap(). This makes the "Memory out of range" subtest fail, because the test address falls inside the first mmap() region, thus being a valid address. Create a "buffer zone" with mmap(PROT_NONE) to make sure there's invalid memory between the two mmaps and munmap() them by the end of the test. Signed-off-by: Andr=C3=A9 Almeida --- .../selftests/futex/functional/futex_numa_mpol.c | 57 ++++++++----------= ---- tools/testing/selftests/futex/functional/run.sh | 15 +----- 2 files changed, 21 insertions(+), 51 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_numa_mpol.c b/t= ools/testing/selftests/futex/functional/futex_numa_mpol.c index a9ecfb2d3932add7e560d885dc2088313fbb63bb..8d8d117b095f267af08fddcf133= 37f4674c44863 100644 --- a/tools/testing/selftests/futex/functional/futex_numa_mpol.c +++ b/tools/testing/selftests/futex/functional/futex_numa_mpol.c @@ -16,9 +16,9 @@ #include #include =20 -#include "logging.h" #include "futextest.h" #include "futex2test.h" +#include "../../kselftest_harness.h" =20 #define MAX_THREADS 64 =20 @@ -130,44 +130,25 @@ static void test_futex_mpol(void *futex_ptr, int must= _fail) __test_futex(futex_ptr, must_fail, FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG |= FUTEX2_NUMA | FUTEX2_MPOL); } =20 -static void usage(char *prog) -{ - printf("Usage: %s\n", prog); - printf(" -c Use color\n"); - printf(" -h Display this help message\n"); - printf(" -v L Verbosity level: %d=3DQUIET %d=3DCRITICAL %d=3DINFO\n", - VQUIET, VCRITICAL, VINFO); -} - -int main(int argc, char *argv[]) +TEST(futex_numa_mpol) { struct futex32_numa *futex_numa; int mem_size, i; - void *futex_ptr; - int c; - - while ((c =3D getopt(argc, argv, "chv:")) !=3D -1) { - switch (c) { - case 'c': - log_color(1); - break; - case 'h': - usage(basename(argv[0])); - exit(0); - break; - case 'v': - log_verbosity(atoi(optarg)); - break; - default: - usage(basename(argv[0])); - exit(1); - } - } - - ksft_print_header(); - ksft_set_plan(1); + void *futex_ptr, *buffer_zone; =20 mem_size =3D sysconf(_SC_PAGE_SIZE); + + /* + * test_harness_run() calls mmap(..., MAP_SHARED, ...), which can create + * a valid access memory region just bellow the mmap() issue here. Then, + * the test for "Memory out of range" will fail because it will succeed + * accessing the memory address after the range. To avoid this we create + * a "Buffer zone" with PROT_NONE between the two mmap's. + */ + buffer_zone =3D mmap(NULL, mem_size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMO= US, 0, 0); + if (buffer_zone =3D=3D MAP_FAILED) + ksft_exit_fail_msg("mmap() for %d bytes failed\n", mem_size); + futex_ptr =3D mmap(NULL, mem_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | = MAP_ANONYMOUS, 0, 0); if (futex_ptr =3D=3D MAP_FAILED) ksft_exit_fail_msg("mmap() for %d bytes failed\n", mem_size); @@ -229,7 +210,9 @@ int main(int argc, char *argv[]) } } } - ksft_test_result_pass("NUMA MPOL tests passed\n"); - ksft_finished(); - return 0; + + munmap(buffer_zone, mem_size); + munmap(futex_ptr, mem_size); } + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/futex/functional/run.sh b/tools/testin= g/selftests/futex/functional/run.sh index f725531f06c4a88e6d3ebbabb628a5d5009eaa3b..e88545c06d57a7b202e9a65a66d= 129996b4ebd27 100755 --- a/tools/testing/selftests/futex/functional/run.sh +++ b/tools/testing/selftests/futex/functional/run.sh @@ -18,19 +18,6 @@ # ##########################################################################= ##### =20 -# Test for a color capable console -if [ -z "$USE_COLOR" ]; then - tput setf 7 || tput setaf 7 - if [ $? -eq 0 ]; then - USE_COLOR=3D1 - tput sgr0 - fi -fi -if [ "$USE_COLOR" -eq 1 ]; then - COLOR=3D"-c" -fi - - echo ./futex_requeue_pi =20 @@ -63,4 +50,4 @@ echo ./futex_priv_hash =20 echo -./futex_numa_mpol $COLOR +./futex_numa_mpol --=20 2.49.0 From nobody Tue Oct 7 22:39:43 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 E621330E83B; Fri, 4 Jul 2025 15:06:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641566; cv=none; b=tpFYE6K3R4JtSAMoiTUZWzcj6jh7JRXdfjiCKwdqzBha///RItu/pZG8PbdsxxW60H9baDSO5XXkna14VneNAv2t+BamxoOF5AMAM7R8cEyCTYsFEW8F+2TRlVgwCn9iS543bxOireJVCJrSeBGqAdbWV0vZGPJJaNDjoVoPvGE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641566; c=relaxed/simple; bh=IGx6RA/qSGDnUuqoITgyVlrWelS8o+WS5T5N7bVta6A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HmfZfmQMLFyMP7Qj3jrVujxSXZlaBozlDMIxgAgG63iX8IwOobF3eyfzGG1i698KxWyI+NSVIhOaX4jhWDwi+cwP0f4WxGG7OGJxN9qVSDkJ+NL6lNRV+YPJFuG5p7JVsk3TWTPllMMfG9ee+GV30WaG6cjjAD1SpeOnAmKhccc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=r8n9cDJM; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="r8n9cDJM" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=IQAthR6ECHpnnSjG9/Db3T6k6+4p4GhEJ3Vk90bWF+U=; b=r8n9cDJMo1iEUmoC21xIVVzBAq ePztTWWuKQQkYW0nvwJ0k+BZTn1cgcDiZfdF0DICvvS09AFe+8ANLG61PdziISf1IIvZ7eXa2/fMu jHaMemkVNsrA3IZBe2MJVXSeAp8KzhbWMQp7MgCLXPwoNTRgHEc9HbdP09ealo0TP1KsHMKNOTf4Q P+CqoyjK1T986EDy3x2vOEXtF4aaygOOKPqo8RswDs24UMEPQ73A6tQSrBvic8Asn+JV6CpBhJCDz DltFtpNwqan7mgJ+GXTlW2ITr4zlf3Wov6Q1OdhcMXWBnOQkYXdTV+O1detB+/epRqBN8NRD+8gMI f1DTB6SA==; Received: from [179.100.5.63] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uXhzG-00CTWt-SX; Fri, 04 Jul 2025 17:06:03 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 04 Jul 2025 12:05:18 -0300 Subject: [PATCH 14/15] selftests/futex: Drop logging.h include from futex_numa Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-tonyk-robust_test_cleanup-v1-14-c0ff4f24c4e1@igalia.com> References: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> In-Reply-To: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Sebastian Andrzej Siewior Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 futex_numa doesn't really use logging.h helpers, it's only need two includes from this file. So drop it and include the two missing includes. Signed-off-by: Andr=C3=A9 Almeida --- tools/testing/selftests/futex/functional/futex_numa.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/futex/functional/futex_numa.c b/tools/= testing/selftests/futex/functional/futex_numa.c index f29e4d627e7942bd0bc8f031f9c0ad59c157c536..e0a33510ccb60c799275cdc8b41= 254c8161f8090 100644 --- a/tools/testing/selftests/futex/functional/futex_numa.c +++ b/tools/testing/selftests/futex/functional/futex_numa.c @@ -5,9 +5,10 @@ #include #include #include +#include +#include #include #include -#include "logging.h" #include "futextest.h" #include "futex2test.h" =20 --=20 2.49.0 From nobody Tue Oct 7 22:39:43 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 B905C30E851; Fri, 4 Jul 2025 15:06:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641569; cv=none; b=sK6/VOQgTgtxREDci16ZngLrun3dnQ/G9FjFz140qDv4B7ZWxPSv6Bb4ON4w1Z/5WbDiX3HMZHeyzDV/3Jl5k7xDX63ztdOQyEn3Ex5B83K08A6Bs4aDwv1UADnfEcXQRisRUBauRNk/BQPa4QcotyGYX+dn3+a2CIvsSZ4r7VE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751641569; c=relaxed/simple; bh=QHgoEqFwVgwRujgbNG51hT0DEPu1DsyZr+w69/+j7Tw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AaCkbDdIGFcBQYcuo6YgGiF7tdStXnJD3rwLBchi46MVvBTJsLdb2+bg1lLV/uhzVxxka5rMo9ffN+KqLr6gdtrwNRem56DdSkXliVOXDPmDTqiUOom3p0Sq/uSMt+j5PN/JwyXiQrHZY0zu3aLXcNxflsNRnWk5mAxfZ02PI+g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=HRSlyqjk; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="HRSlyqjk" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Qs8/o1Qf6X+HvOHYatMnj6kc67Bj/BywR1JMPfbw63w=; b=HRSlyqjkt+0jD7J7YEqzxoMzb0 XZ3NhddqiXdkhLcAyqH70Jr7ClQUj9cfE6zXhpStKJfIufsRlFo1sR28wJEJnaFA/UreB+HfHWsdF 31OSPZHt3Ob9g9yTLL6Nq7OWgOVuyfIAZHZCWPXXL4pnOMg2BKa9ybgDZth6jJrTLsQdkloCtArYu hq+3G+Qk3ZvXJr5Q9wgBTco2QP5hZk6cCz1oH+ErDRrWqJmpoZwH327m9m5VoLLiJ2idUuY7pfK2J 3kA9jy2U/cmq/5pXsZJXKjDS3sfeVA85EHfzXvnZR8qyk46CfO3XDnk0qiCKnP1w05XxLaq8x6w/j iYCU2wVA==; Received: from [179.100.5.63] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uXhzJ-00CTWt-II; Fri, 04 Jul 2025 17:06:05 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Fri, 04 Jul 2025 12:05:19 -0300 Subject: [PATCH 15/15] selftests/futex: Remove logging.h file Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-tonyk-robust_test_cleanup-v1-15-c0ff4f24c4e1@igalia.com> References: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> In-Reply-To: <20250704-tonyk-robust_test_cleanup-v1-0-c0ff4f24c4e1@igalia.com> To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Sebastian Andrzej Siewior Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 Every futex selftest uses the kselftest_harness.h helper and don't need the logging.h file. Delete it. Signed-off-by: Andr=C3=A9 Almeida --- tools/testing/selftests/futex/functional/Makefile | 3 +- tools/testing/selftests/futex/include/logging.h | 148 ------------------= ---- 2 files changed, 1 insertion(+), 150 deletions(-) diff --git a/tools/testing/selftests/futex/functional/Makefile b/tools/test= ing/selftests/futex/functional/Makefile index 8cfb87f7f7c5059c82f1e6290c076d3f13f5ea41..6bd6f9b972f1bf113b84f72386c= 21e2fb43436d5 100644 --- a/tools/testing/selftests/futex/functional/Makefile +++ b/tools/testing/selftests/futex/functional/Makefile @@ -5,8 +5,7 @@ LDLIBS :=3D -lpthread -lrt -lnuma =20 LOCAL_HDRS :=3D \ ../include/futextest.h \ - ../include/atomic.h \ - ../include/logging.h + ../include/atomic.h TEST_GEN_PROGS :=3D \ futex_wait_timeout \ futex_wait_wouldblock \ diff --git a/tools/testing/selftests/futex/include/logging.h b/tools/testin= g/selftests/futex/include/logging.h deleted file mode 100644 index 874c69ce5cce9efa3a9d6de246f5972a75437dbf..000000000000000000000000000= 0000000000000 --- a/tools/testing/selftests/futex/include/logging.h +++ /dev/null @@ -1,148 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/*************************************************************************= ***** - * - * Copyright =C2=A9 International Business Machines Corp., 2009 - * - * DESCRIPTION - * Glibc independent futex library for testing kernel functionality. - * - * AUTHOR - * Darren Hart - * - * HISTORY - * 2009-Nov-6: Initial version by Darren Hart - * - *************************************************************************= ****/ - -#ifndef _LOGGING_H -#define _LOGGING_H - -#include -#include -#include -#include -#include "kselftest.h" - -/* - * Define PASS, ERROR, and FAIL strings with and without color escape - * sequences, default to no color. - */ -#define ESC 0x1B, '[' -#define BRIGHT '1' -#define GREEN '3', '2' -#define YELLOW '3', '3' -#define RED '3', '1' -#define ESCEND 'm' -#define BRIGHT_GREEN ESC, BRIGHT, ';', GREEN, ESCEND -#define BRIGHT_YELLOW ESC, BRIGHT, ';', YELLOW, ESCEND -#define BRIGHT_RED ESC, BRIGHT, ';', RED, ESCEND -#define RESET_COLOR ESC, '0', 'm' -static const char PASS_COLOR[] =3D {BRIGHT_GREEN, ' ', 'P', 'A', 'S', 'S', - RESET_COLOR, 0}; -static const char ERROR_COLOR[] =3D {BRIGHT_YELLOW, 'E', 'R', 'R', 'O', 'R= ', - RESET_COLOR, 0}; -static const char FAIL_COLOR[] =3D {BRIGHT_RED, ' ', 'F', 'A', 'I', 'L', - RESET_COLOR, 0}; -static const char INFO_NORMAL[] =3D " INFO"; -static const char PASS_NORMAL[] =3D " PASS"; -static const char ERROR_NORMAL[] =3D "ERROR"; -static const char FAIL_NORMAL[] =3D " FAIL"; -const char *INFO =3D INFO_NORMAL; -const char *PASS =3D PASS_NORMAL; -const char *ERROR =3D ERROR_NORMAL; -const char *FAIL =3D FAIL_NORMAL; - -/* Verbosity setting for INFO messages */ -#define VQUIET 0 -#define VCRITICAL 1 -#define VINFO 2 -#define VMAX VINFO -int _verbose =3D VCRITICAL; - -/* Functional test return codes */ -#define RET_PASS 0 -#define RET_ERROR -1 -#define RET_FAIL -2 - -/** - * log_color() - Use colored output for PASS, ERROR, and FAIL strings - * @use_color: use color (1) or not (0) - */ -void log_color(int use_color) -{ - if (use_color) { - PASS =3D PASS_COLOR; - ERROR =3D ERROR_COLOR; - FAIL =3D FAIL_COLOR; - } else { - PASS =3D PASS_NORMAL; - ERROR =3D ERROR_NORMAL; - FAIL =3D FAIL_NORMAL; - } -} - -/** - * log_verbosity() - Set verbosity of test output - * @verbose: Enable (1) verbose output or not (0) - * - * Currently setting verbose=3D1 will enable INFO messages and 0 will disa= ble - * them. FAIL and ERROR messages are always displayed. - */ -void log_verbosity(int level) -{ - if (level > VMAX) - level =3D VMAX; - else if (level < 0) - level =3D 0; - _verbose =3D level; -} - -/** - * print_result() - Print standard PASS | ERROR | FAIL results - * @ret: the return value to be considered: 0 | RET_ERROR | RET_FAIL - * - * print_result() is primarily intended for functional tests. - */ -void print_result(const char *test_name, int ret) -{ - switch (ret) { - case RET_PASS: - ksft_test_result_pass("%s\n", test_name); - ksft_print_cnts(); - return; - case RET_ERROR: - ksft_test_result_error("%s\n", test_name); - ksft_print_cnts(); - return; - case RET_FAIL: - ksft_test_result_fail("%s\n", test_name); - ksft_print_cnts(); - return; - } -} - -/* log level macros */ -#define info(message, vargs...) \ -do { \ - if (_verbose >=3D VINFO) \ - fprintf(stderr, "\t%s: "message, INFO, ##vargs); \ -} while (0) - -#define error(message, err, args...) \ -do { \ - if (_verbose >=3D VCRITICAL) {\ - if (err) \ - fprintf(stderr, "\t%s: %s: "message, \ - ERROR, strerror(err), ##args); \ - else \ - fprintf(stderr, "\t%s: "message, ERROR, ##args); \ - } \ -} while (0) - -#define fail(message, args...) \ -do { \ - if (_verbose >=3D VCRITICAL) \ - fprintf(stderr, "\t%s: "message, FAIL, ##args); \ -} while (0) - -#endif --=20 2.49.0