From nobody Thu Oct 2 12:06:27 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 2565430F7E7; Wed, 17 Sep 2025 21:23:20 +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=1758144202; cv=none; b=oKWTmWUs7ly/2QuZ2smSg3ZeWlr2ifvZ0Usb6u3BOwZ/mkC8HnfiC3G1adPuu818hbQHdgmCzeg3MRNy9w5wMGnISTqScqxFwYkoebutCZ3iJI2PsqIQ5aJBHhH7Wx2SvjZyxmq+nPjsx+ZGC2q8Izr++PNM85YGXirBt5hrX3w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758144202; c=relaxed/simple; bh=pD/wnpgJ0vOz2bRWWKZ770X5NGXnCp+Sw/RRp9/TymE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C+y1xuXxhVRNqNGxPXreyU0XGMe93q9igVDrIVNi1uutqLjTcJ6NeRWH2TXHV9xGG76RkXLCpCJK19NU1YYHSUHW3pMzbm2IZQBY/FMUuGlR+WGdkv63ANw7OTZlKfKJ4MrJBiSG/lC9gltBxQvHgU789DtdKJ3izMDebcMdrEU= 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=TsG32kAF; 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="TsG32kAF" 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=sZhKyABKEJfdKZ4cH+LrqvpD2zu4zXy/O7TNVgVgI1o=; b=TsG32kAFgtpax/jInpLvONYDaR qvy1xaMzmLPOmFTTUeHzfFN8ahWoavAUJiiE3pPSFMybeGSfFY3Q9vl8hecwl51xnRFbpS+IogdEX wlzGoGrBWj2ieCrH8GSLmPQt+AGDQtSCdgiZe5O+sXyI6fMgEhf8Lxug6fezUqeA8xH/H+oI2NUjw Nxof/b66DlZeeq+2SqZ0CFTXbJurvTY/ml1IdnPrBNCPx4hV9AgkGlpNWMXIWiIEOoSVkW+S2G394 zsDf7uH8dCiBny/pa7ToEIu1Bu1/U3+huzfMqXJmOav2X+nat0BusSOJiOgPeL0hTgWv0ygNZxv44 WUouNIIg==; Received: from [191.204.197.103] (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 1uyzcU-00CsMq-62; Wed, 17 Sep 2025 23:23:18 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Wed, 17 Sep 2025 18:21:48 -0300 Subject: [PATCH v3 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: <20250917-tonyk-robust_test_cleanup-v3-9-306b373c244d@igalia.com> References: <20250917-tonyk-robust_test_cleanup-v3-0-306b373c244d@igalia.com> In-Reply-To: <20250917-tonyk-robust_test_cleanup-v3-0-306b373c244d@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 87666f21fa3bf99e7db03da0aea14a5af3e49e0d..1ce0f20cadfcc33e2d58f53e14c= 36bb8cf30b870 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.51.0