From nobody Wed Oct 8 00:29:50 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