From nobody Mon Oct 6 15:18:16 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 29068238D49; Sun, 20 Jul 2025 22:29:27 +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=1753050569; cv=none; b=uJt689DozicYAkj2xULD0zgwVo0l9lgP4a5nasgClp43F04s3Oc5Oydonn5q3xbYvHdIdecrj2UELrnf9017G+jWQub1NOsjeSXjCcSxq0uw9wtvEnMmiFuQuPeHUfpzU3+aZ/iOS+JJVrPmWAOBgCASHSdUFAXUYXfSAgaBxSI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753050569; c=relaxed/simple; bh=H4iYYSR1EPw1jXLUZmghYgvFBscXdY9RcVjwSwSzzp0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OhxxmzcoiCAJpgm5LV3nwZhwAEdt4gVcOJHgY6QNeTLG1FvR+o7gee6oJOObAtHVucDOFMusdWaQ11+BNw0lKgcEjDBz8YHNvlIWy9JRZOFZfRkPu+LJYvDn6t7auPpN/Hn5glS21dEfOe7cSXTFMKVzjtYMpNhUF8wUU3mcofo= 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=KR9O36ZD; 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="KR9O36ZD" 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=fXIsA7YZCbRiiS349P0/OiXuHW47QjimRmCZkkvInyA=; b=KR9O36ZDOvUAB7birLKVZ0pTQn gmwt+UHTXuChgelqRp+V6vY9i2MuUpBQqSreiA/ILZNtDJPEEqo93QtlZ+x14fTTc9Fd6geRR6dzo maVd9mBAwybXtKMVG1kfXSzwV8ikEIpya7tXBU27puy7dTkrCSQms6sWayGMpl+n8EeZGLk66qUW8 TpnI54BBbeeledbQ2LYE9L+FRKLHC2mQuGKous/KLRVqRAlAcsFznZOTFmLLKsrB7d3vEFE0sCOHf lMuDUouQaiZp1u2Exjd3qOyl0dRDHTh6bO2hBHjspdTPND7I4WKyWJQCmuzrRM1eHwrcwdQfJK6y4 fIWNXlZg==; Received: from [187.57.76.50] (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 1udcX7-001Sqt-3T; Mon, 21 Jul 2025 00:29:25 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Sun, 20 Jul 2025 19:29:05 -0300 Subject: [PATCH v2 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: <20250720-tonyk-robust_test_cleanup-v2-7-1f9bcb5b7294@igalia.com> References: <20250720-tonyk-robust_test_cleanup-v2-0-1f9bcb5b7294@igalia.com> In-Reply-To: <20250720-tonyk-robust_test_cleanup-v2-0-1f9bcb5b7294@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.50.1