From patchwork Mon Apr 7 06:52:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 878920 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 087FC211A39; Mon, 7 Apr 2025 06:53:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008783; cv=none; b=auLnCVDb9QBuS3y/0tu1WjOyeCNRVQa5SkQSA/ocbGE6gjhF8vf1sMctTuCdQnV5AAEJqyiPr4iZ8eKRY1l6DTaFarU7rEiDOm1eyuV79XQumgsR16SYo2NVIAcG3IG9ziEmI7Y2jjAHD8lIP/OJQqR/STy8mU/NRYiqj3cFMRY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008783; c=relaxed/simple; bh=IbF3dpnbmDMqynvxHeCn++RKSL483IkiGlufXOYi80g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=khjRjMmR6dTCu4nPrKRY5hmk/CpfvywCSKPW8O8DFqyxcTuJbz223cz7nS6Pc3M3RdB6sV7HoAEmIUaeQKUqSI7royOT0O9kOesk6vlMqrnPNdOayize7Gcw/FcPESNfJ6a6pnUDLQVzUjcwsCSNt9j/gO9anGYEji0jIKd6YUU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Jt4tp3Gd; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=npUPD208; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Jt4tp3Gd"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="npUPD208" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D/CF9Pf6s9VZiCzyI0O7TZZkfoFNszIhPXCLoc65GcE=; b=Jt4tp3GdDcN9ha6tI+qm0VijAzPG7lwxdW5//SjYJE7yZMZCoVxkw/x9aqZPxyPcNjPwdc gNVC69CkL24iP9QzSn00F3HB6oWH/kIz8sU4W4mP/TA/Nea9onCQ/KP3akpiLpAgwDS6ot 8fFOV2jc/u4fa4Nw/kcxTbk/KufqBJwRHS08RGCtLXNwwCrUkbpINI1jaHe2XMi5Ewdc8k BJbm3hY+firmisF7Cawzz2iTkqQGu1aZzVVRQEP8rQbG5kSx+ouEP8qL3xp5lv5L22ToN5 kc1KIYPRemnvjD/KTxqm0bXZj10mwb2ZH4+MGnW9QRSNEDYk61M/5VEpYunEFA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D/CF9Pf6s9VZiCzyI0O7TZZkfoFNszIhPXCLoc65GcE=; b=npUPD208aRLvMjW5QCqty4uLxh4FLzgqgzurOU30fsAVRi1nyl1sd5VI6RfD2L0Qhhuhte KeIqoh5iNXrmMAAQ== Date: Mon, 07 Apr 2025 08:52:24 +0200 Subject: [PATCH v2 01/32] selftests: harness: Add harness selftest Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-1-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=8071; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=IbF3dpnbmDMqynvxHeCn++RKSL483IkiGlufXOYi80g=; b=SBsBbKZurUN3do7JpyLZaXjULL+AKmFtwrlo6Q6lwCeqgRZkDsLu+WTysEfeB3zXkQOGVGFrO WAuxHvgWN91AhQKCtG0yPU2CRI06CPFh52X3V5IIAOlC+Xehir9Ixv1 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Add a selftest for the harness itself so any changes can be validated. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/kselftest/.gitignore | 1 + tools/testing/selftests/kselftest/Makefile | 6 + .../testing/selftests/kselftest/harness-selftest.c | 129 +++++++++++++++++++++ .../selftests/kselftest/harness-selftest.expected | 62 ++++++++++ .../selftests/kselftest/harness-selftest.sh | 14 +++ 6 files changed, 213 insertions(+) diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index c77c8c8e3d9bdd8047c9cb7722c3830447e504e5..3ce071eefa86af59aadd1df7972fdf3bf6e01d52 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -48,6 +48,7 @@ TARGETS += ipc TARGETS += ir TARGETS += kcmp TARGETS += kexec +TARGETS += kselftest TARGETS += kvm TARGETS += landlock TARGETS += lib diff --git a/tools/testing/selftests/kselftest/.gitignore b/tools/testing/selftests/kselftest/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..9aab194e8ea25a2c5ccc116f9f728b8afd0c51c4 --- /dev/null +++ b/tools/testing/selftests/kselftest/.gitignore @@ -0,0 +1 @@ +/harness-selftest diff --git a/tools/testing/selftests/kselftest/Makefile b/tools/testing/selftests/kselftest/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..2f2933553dbc47014d9dfe0b4bd8ad3bc36e38c2 --- /dev/null +++ b/tools/testing/selftests/kselftest/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 + +TEST_GEN_PROGS_EXTENDED := harness-selftest +TEST_PROGS := harness-selftest.sh + +include ../lib.mk diff --git a/tools/testing/selftests/kselftest/harness-selftest.c b/tools/testing/selftests/kselftest/harness-selftest.c new file mode 100644 index 0000000000000000000000000000000000000000..8d39e7a0b99c41a5d33edfe2dbf875cac04c098d --- /dev/null +++ b/tools/testing/selftests/kselftest/harness-selftest.c @@ -0,0 +1,129 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +#ifndef NOLIBC +#include +#include +#endif + +/* Avoid any inconsistencies */ +#define TH_LOG_STREAM stdout + +#include "../kselftest_harness.h" + +TEST(standalone_pass) { + TH_LOG("before"); + ASSERT_EQ(0, 0); + EXPECT_EQ(0, 0); + TH_LOG("after"); +} + +TEST(standalone_fail) { + TH_LOG("before"); + EXPECT_EQ(0, 0); + EXPECT_EQ(0, 1); + ASSERT_EQ(0, 1); + TH_LOG("after"); +} + +TEST_SIGNAL(signal_pass, SIGUSR1) { + TH_LOG("before"); + ASSERT_EQ(0, 0); + TH_LOG("after"); + kill(getpid(), SIGUSR1); +} + +TEST_SIGNAL(signal_fail, SIGUSR1) { + TH_LOG("before"); + ASSERT_EQ(0, 1); + TH_LOG("after"); + kill(getpid(), SIGUSR1); +} + +FIXTURE(fixture) { + pid_t testpid; +}; + +FIXTURE_SETUP(fixture) { + TH_LOG("setup"); + self->testpid = getpid(); +} + +FIXTURE_TEARDOWN(fixture) { + TH_LOG("teardown same-process=%d", self->testpid == getpid()); +} + +TEST_F(fixture, pass) { + TH_LOG("before"); + ASSERT_EQ(0, 0); + TH_LOG("after"); +} + +TEST_F(fixture, fail) { + TH_LOG("before"); + ASSERT_EQ(0, 1); + TH_LOG("after"); +} + +TEST_F_TIMEOUT(fixture, timeout, 1) { + TH_LOG("before"); + sleep(2); + TH_LOG("after"); +} + +FIXTURE(fixture_parent) { + pid_t testpid; +}; + +FIXTURE_SETUP(fixture_parent) { + TH_LOG("setup"); + self->testpid = getpid(); +} + +FIXTURE_TEARDOWN_PARENT(fixture_parent) { + TH_LOG("teardown same-process=%d", self->testpid == getpid()); +} + +TEST_F(fixture_parent, pass) { + TH_LOG("before"); + ASSERT_EQ(0, 0); + TH_LOG("after"); +} + +FIXTURE(fixture_setup_failure) { + pid_t testpid; +}; + +FIXTURE_SETUP(fixture_setup_failure) { + TH_LOG("setup"); + self->testpid = getpid(); + ASSERT_EQ(0, 1); +} + +FIXTURE_TEARDOWN(fixture_setup_failure) { + TH_LOG("teardown same-process=%d", self->testpid == getpid()); +} + +TEST_F(fixture_setup_failure, pass) { + TH_LOG("before"); + ASSERT_EQ(0, 0); + TH_LOG("after"); +} + +int main(int argc, char **argv) +{ + /* + * The harness uses abort() to signal assertion failures, which triggers coredumps. + * This may be useful to debug real failures but not for this selftest, disable them. + */ + struct rlimit rlimit = { + .rlim_cur = 0, + .rlim_max = 0, + }; + + prctl(PR_SET_DUMPABLE, 0, 0, 0, 0); + setrlimit(RLIMIT_CORE, &rlimit); + + return test_harness_run(argc, argv); +} diff --git a/tools/testing/selftests/kselftest/harness-selftest.expected b/tools/testing/selftests/kselftest/harness-selftest.expected new file mode 100644 index 0000000000000000000000000000000000000000..1aa6461db90d4e7cc0679f19b69aadf4032875ec --- /dev/null +++ b/tools/testing/selftests/kselftest/harness-selftest.expected @@ -0,0 +1,62 @@ +TAP version 13 +1..9 +# Starting 9 tests from 4 test cases. +# RUN global.standalone_pass ... +# harness-selftest.c:16:standalone_pass:before +# harness-selftest.c:19:standalone_pass:after +# OK global.standalone_pass +ok 1 global.standalone_pass +# RUN global.standalone_fail ... +# harness-selftest.c:23:standalone_fail:before +# harness-selftest.c:25:standalone_fail:Expected 0 (0) == 1 (1) +# harness-selftest.c:26:standalone_fail:Expected 0 (0) == 1 (1) +# standalone_fail: Test terminated by assertion +# FAIL global.standalone_fail +not ok 2 global.standalone_fail +# RUN global.signal_pass ... +# harness-selftest.c:31:signal_pass:before +# harness-selftest.c:33:signal_pass:after +# OK global.signal_pass +ok 3 global.signal_pass +# RUN global.signal_fail ... +# harness-selftest.c:38:signal_fail:before +# harness-selftest.c:39:signal_fail:Expected 0 (0) == 1 (1) +# signal_fail: Test terminated by assertion +# FAIL global.signal_fail +not ok 4 global.signal_fail +# RUN fixture.pass ... +# harness-selftest.c:49:pass:setup +# harness-selftest.c:58:pass:before +# harness-selftest.c:60:pass:after +# harness-selftest.c:54:pass:teardown same-process=1 +# OK fixture.pass +ok 5 fixture.pass +# RUN fixture.fail ... +# harness-selftest.c:49:fail:setup +# harness-selftest.c:64:fail:before +# harness-selftest.c:65:fail:Expected 0 (0) == 1 (1) +# harness-selftest.c:54:fail:teardown same-process=1 +# fail: Test terminated by assertion +# FAIL fixture.fail +not ok 6 fixture.fail +# RUN fixture.timeout ... +# harness-selftest.c:49:timeout:setup +# harness-selftest.c:70:timeout:before +# timeout: Test terminated by timeout +# FAIL fixture.timeout +not ok 7 fixture.timeout +# RUN fixture_parent.pass ... +# harness-selftest.c:80:pass:setup +# harness-selftest.c:89:pass:before +# harness-selftest.c:91:pass:after +# harness-selftest.c:85:pass:teardown same-process=0 +# OK fixture_parent.pass +ok 8 fixture_parent.pass +# RUN fixture_setup_failure.pass ... +# harness-selftest.c:99:pass:setup +# harness-selftest.c:101:pass:Expected 0 (0) == 1 (1) +# pass: Test terminated by assertion +# FAIL fixture_setup_failure.pass +not ok 9 fixture_setup_failure.pass +# FAILED: 4 / 9 tests passed. +# Totals: pass:4 fail:5 xfail:0 xpass:0 skip:0 error:0 diff --git a/tools/testing/selftests/kselftest/harness-selftest.sh b/tools/testing/selftests/kselftest/harness-selftest.sh new file mode 100755 index 0000000000000000000000000000000000000000..bf691adf0b41aaedb2fbc5f06add9fd1d5689044 --- /dev/null +++ b/tools/testing/selftests/kselftest/harness-selftest.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# Selftest for kselftest_harness.h +# + +DIR="$(dirname $(readlink -f "$0"))" + +TMPFILE="$(mktemp)" +trap 'rm "$TMPFILE"' EXIT + +$DIR/harness-selftest > "$TMPFILE" + +diff -u "$DIR"/harness-selftest.expected "$TMPFILE" From patchwork Mon Apr 7 06:52:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 879554 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 C5A14218AC1; Mon, 7 Apr 2025 06:53:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008783; cv=none; b=eYwOl+h/vjQXtYwe5+BC/xdQfCf9NPaQ7MSQmEaHdCPVa9XZlO4tSdzUFMumDU6Q2rSULQLePauBVuhkqPWBf0dExZIOsGbdyEA4W5cOvrP5IQ8l9TsEM5WNnyQEdRtbxdCQKGeHMg+bQt0mrycD3MRLxDfagn4mIZnPjHJ0w0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008783; c=relaxed/simple; bh=jGKlKoofOPJIAZx1RxcX4p7LfMYOyHoN+Nx2/9d9seQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tJvmNYkqpppfAd3vzn80zUFZ0S8B4yhCfbfgHzGDLe1iAGVbrbjEqyKtslibgok059T5a1zOrfSZYnpkP3J2M263rMABWbr2waQ4V+0ZPVoPCbyYNM+rDu73SAD4YiQBKTBCSg9jl9j9CZi7DZp1d+WYR22qAXpbbMm9ktJaYZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=CWpeqjD9; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=iVY0muvJ; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="CWpeqjD9"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iVY0muvJ" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wLj0ETsEs/I2mut8MoZZYVz5W4X+4bN5Q7Nlryt1VEQ=; b=CWpeqjD9Bp/CjmVDcAfS9JVG/V0nAppFVTKu5W3L+a4Kaa0jybvIpkSqqmIQ/iqeYwuqHq aE314RwRal/v22PFAoYHdTfEIW8UhC+BSxZCsVjyEKcIsoPQOMjqE6h1jHSzT8Gk1XYAAQ dg4fDKVfg3/khB884XTUQC8qfPbfkgxIe3tpgutQmPGtLUEbpQHiZcbB4lDLmwSNrQvpzn 7dvp5/j1Pu2I4HVXoDYr947mdbip5TSD6xM+cmUSwZ0buocz0v7K404aaOjtvnnN3/DG/O 8RWhnNffLYqO+Jvx5Mma8fNZo/PG2IiFYUx7mZkHrG1dIWTgBA8SburKVqLO+A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wLj0ETsEs/I2mut8MoZZYVz5W4X+4bN5Q7Nlryt1VEQ=; b=iVY0muvJWrhR1sS89voVwio+aL527Uo9ygv0b0F+Y1UUCLwOt1061DFp6+Ibbx2ODoeRa0 WeKclcuRBdPfsjBg== Date: Mon, 07 Apr 2025 08:52:25 +0200 Subject: [PATCH v2 02/32] selftests: harness: Use C89 comment style Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-2-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=842; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=jGKlKoofOPJIAZx1RxcX4p7LfMYOyHoN+Nx2/9d9seQ=; b=UWCBg0T/rsIh7DRZAFxDpi3u/2xYdHQwh9pXhNssosgTrvVklijQ3t07uXdUCm2wScdA6Y+Y0 mjHm8TgQyZJA++zAqkxP0fcuYmhTBobhHKZOLXGAbf7OmMi5tgK7NL4 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= All comments in this file use C89 comment style. Except for this one. Change it to get one step closer to C89 compatibility. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/kselftest_harness.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 666c9fde76da9d25fe6e248a7f2143c113473fe1..bac4327775ea65dbe977e9b22ee548bedcbd33ff 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -983,7 +983,7 @@ static void __timeout_handler(int sig, siginfo_t *info, void *ucontext) } t->timed_out = true; - // signal process group + /* signal process group */ kill(-(t->pid), SIGKILL); } From patchwork Mon Apr 7 06:52:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 878919 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 EBBCC2206B5; Mon, 7 Apr 2025 06:53:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008783; cv=none; b=NXPzSsKnptP7mRu1KSpxTj1hYNqluK8HMh7GONjQgxppU+A1RY30XqpW3PTWfRUv6iCAI9DnC6P1uJVO5gcL64NYFFd7Z54Ad0CHfDfM/rKZjCOT0xbBJJfjKkkzWBXhwVt4L5KP7CjY5QyxemZsLTChPt2+HSTz2LscdxkMpb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008783; c=relaxed/simple; bh=uLWlLJaq4ECFs7tKmzm/BB013m1Cb/4uGDVEx9NPT8E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SKqH1ueB7tjE6w73yEcfNrAViysyCdzv3vpKXOH1kHPMNAI4EXTbEv8sSrGz7D2fP4HQ9KbW9NtHyC3qtdMG4zqLoscWzmwZktZd3mHbvHY55Ls0fnW1G5tu9zUcTqFpbVrJiPGJUV8PqwMdhtP1+FGPyLdaaLEN51I3VceBudA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=m0poAOFu; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=4wQVa/Rj; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="m0poAOFu"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="4wQVa/Rj" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008780; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dSfz9/AFbJD22rKh2X5yGK08myEeYljLwAyhzu3/huo=; b=m0poAOFuYPvzYUkXl+tcPpuwqDtVvcbx4ONTtc4DqDH193GzdYy6qrZ2hpLvLMy4eb5ygW SlQLPJjj+mtYFQsVEuEMsM5/6yi7uw5hoeiKoXYx80ov8IdTYfz9RqJOU+TYF8s2Di9/Ka i4HngqSwkSKPxz3u5AZY0nrUz1vpK4ApFtk46krv6FyL9VD4uFYPcbuIYEhCWgRZ1Cp88Y aBIgor0tgu9gc+HPn2iWZ7rE21Bwa6qtvgVcVdLpf9xuzyEZK9NdbG5kzYOcD3J6jdCtMG FQQ0SMkN3IhePpyB61bNpxco2uWf4l9wX7J+IX7J1nt34a6GKc/Pzm4FjmSESQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008780; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dSfz9/AFbJD22rKh2X5yGK08myEeYljLwAyhzu3/huo=; b=4wQVa/Rjvg6+oV8NnM/bcR0ONBFZmV4uYBs8VrYx5VdJtfJfOSuhefwZEQ6jcd7tVQS0iH Y8m0isAg+raf1QDA== Date: Mon, 07 Apr 2025 08:52:26 +0200 Subject: [PATCH v2 03/32] selftests: harness: Ignore unused variant argument warning Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-3-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=997; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=uLWlLJaq4ECFs7tKmzm/BB013m1Cb/4uGDVEx9NPT8E=; b=05BQFZlE1fk/l6kWCQ5q8cPJlu8MFAHbLVz28C18IJz6yB9GTYmL1GhQ7P9fDqyvHfvP8Sx+U tkmktZACMlUB9P9QCSRyr9Qui6NUkj6eQyRv5vlVoZ2iWr9+s+JWCbN X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= For tests without fixtures the variant argument is unused. This is intentional, prevent to compiler from complaining. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/kselftest_harness.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index bac4327775ea65dbe977e9b22ee548bedcbd33ff..2b350ed60b2bf1cbede8e3a9b4ac5fe716900144 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -174,7 +174,7 @@ static void test_name(struct __test_metadata *_metadata); \ static inline void wrapper_##test_name( \ struct __test_metadata *_metadata, \ - struct __fixture_variant_metadata *variant) \ + struct __fixture_variant_metadata __attribute__((unused)) *variant) \ { \ _metadata->setup_completed = true; \ if (setjmp(_metadata->env) == 0) \ From patchwork Mon Apr 7 06:52:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 879553 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 864A32248A4; Mon, 7 Apr 2025 06:53:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008784; cv=none; b=Cd6GFHyhYylY2uCCzoMk7w8UQbcFFhE7AZX3bLPKrxc4uy6yKuufFoiZ7Re7MGSz+/HaOOoS5dP9kXYguVri5L5dx4w+eXdPOS4xkhnH/ftTVuUXNiJ5EfXMDnd+ASvqGxptitpLrxXw7G/PXnkpdMyOYiOQj8gtYefacao38ws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008784; c=relaxed/simple; bh=7893zOP3ErdGxPwks26zDP9HHy3HGwCgpTrK5rmbvbc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ML2CkBbtnqDzMVdBF2XQm6egvFeF4tzqbPRxSgI9tUySxjTMAFl4pubdbths+syBmf8VcWsb7zCg6qlgWpVAYl1jAciCU4fLAkQXfJEoJIuHhherdKHcjTYTN0MGIQWcO9KZ1dish3WNzkvIHeHVUAzulTEowZlEevbUKAuOzBw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=UBIcstF8; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=MJlkKgrP; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UBIcstF8"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="MJlkKgrP" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008780; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Nz0u8GJ5dhijczEOeytq6qafYlrK5qIQk1St+S1OOGs=; b=UBIcstF84RxUF/8Oj2Zjthj5aIUzaoeRDX8ies+KzDDJQvAMK3W4q1mQJNdw/j9R8tytNw W7Ra1CWJhfRchqmKvuqctyonlg8/ibhqPJHF6TehZcL3oNiVT9fVSyfIHGG2DGmKXw5+wq 0DAQVSLSujwIYhwPFqH12ojFAKYVe5xV4eanlOHnoM2usotLuj6CjmLj9hmXU867qGVc6/ +AC0MrqL7l+r8tkP/uY9rp/mxHQVxHJdX0Rp2oRwDzaVSFeG8ye4V7kgd6sQHo8gIfSCzp 3xt2htemjfUoVHleOteDr8/mXtwokFAnFyBA5LmrKnL5MgG5mViXoby/1N/kYg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008780; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Nz0u8GJ5dhijczEOeytq6qafYlrK5qIQk1St+S1OOGs=; b=MJlkKgrPigPUHnGOTupfCnd4xiQG1UQ3T7ubz7cwP6yMYulLj1LnYP5/zS1aJPad6/Q6+F /lookqiBrT14O3Dw== Date: Mon, 07 Apr 2025 08:52:27 +0200 Subject: [PATCH v2 04/32] selftests: harness: Mark functions without prototypes static Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-4-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=2245; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=7893zOP3ErdGxPwks26zDP9HHy3HGwCgpTrK5rmbvbc=; b=NMWEA3A5sGkwwVwSAad8ApervGWtmoiPgGq7uRH5Rwr1BHlX1sqvdiwl78HgCxNr4asichvrM ucLugT+SYlICO7jAtRfYC8zg3W19uTBVMSLA5U2em5AnxzPLAeP2McC X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= With -Wmissing-prototypes the compiler will warn about non-static functions which don't have a prototype defined. As they are not used from a different compilation unit they don't need to be defined globally. Avoid the issue by marking the functions static. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/kselftest_harness.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 2b350ed60b2bf1cbede8e3a9b4ac5fe716900144..5822bc0b86a3c623fd34830fb8b541b27672a00b 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -258,7 +258,7 @@ * A bare "return;" statement may be used to return early. */ #define FIXTURE_SETUP(fixture_name) \ - void fixture_name##_setup( \ + static void fixture_name##_setup( \ struct __test_metadata __attribute__((unused)) *_metadata, \ FIXTURE_DATA(fixture_name) __attribute__((unused)) *self, \ const FIXTURE_VARIANT(fixture_name) \ @@ -307,7 +307,7 @@ __FIXTURE_TEARDOWN(fixture_name) #define __FIXTURE_TEARDOWN(fixture_name) \ - void fixture_name##_teardown( \ + static void fixture_name##_teardown( \ struct __test_metadata __attribute__((unused)) *_metadata, \ FIXTURE_DATA(fixture_name) __attribute__((unused)) *self, \ const FIXTURE_VARIANT(fixture_name) \ @@ -987,7 +987,7 @@ static void __timeout_handler(int sig, siginfo_t *info, void *ucontext) kill(-(t->pid), SIGKILL); } -void __wait_for_test(struct __test_metadata *t) +static void __wait_for_test(struct __test_metadata *t) { struct sigaction action = { .sa_sigaction = __timeout_handler, @@ -1205,9 +1205,9 @@ static bool test_enabled(int argc, char **argv, return !has_positive; } -void __run_test(struct __fixture_metadata *f, - struct __fixture_variant_metadata *variant, - struct __test_metadata *t) +static void __run_test(struct __fixture_metadata *f, + struct __fixture_variant_metadata *variant, + struct __test_metadata *t) { struct __test_xfail *xfail; char test_name[1024]; From patchwork Mon Apr 7 06:52:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 879552 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 2110D225798; Mon, 7 Apr 2025 06:53:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008785; cv=none; b=ZXG4EObV4qgwd4kdOiAIevLDWbeSD0tJ1+MjFsUAzLqOjrGAu+KDNsvdBjnuzCB2Gofv6F42V4BqZ8aiKehDMXK6CNAxaTWIsvGR4L6GH6NF3YYUVxf3MPwMfmCFo2SdeD1wtRoaWjFnYBcMSlMeFPt3fITZ8VdBx4r+uLLJTfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008785; c=relaxed/simple; bh=iTc/RNQUri37IjlCMpegyjj2hPVvSJ8rCK9az0iWMW4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dKOy7lxMXAmeEUKCcj3RK2Ky0+kelCUAuWW4mUSGJ0+bbeslvZv+tGnc42I1vC1R5gkBnCk/HenDgoECSRqWVLgixgEHs1y9ElsfOGX+rqlWx1MAixTXNFvuaNmwDVHfBh3NnlsQFeUIr/SQzlshO2Ubd2L9TQw/T1hv1qw6dyw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=G3Jpdo1N; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=mnbNiMQG; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="G3Jpdo1N"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mnbNiMQG" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tMe0g3jwXR/976+VePxD04JYud2yUWQle7bIApeWz3U=; b=G3Jpdo1N6yh/w2DbbHuAPbzLVQoPOD0N2DCjiggJTZV/xmIizw+4j4bcWf3xtBIUM9fP+0 nGMlIc1Uwwfuicuw1whh2QG3pmc6gFtKT4XSsYYNf/P2P418aXrJM5UhFF/ztTLtOMCPqe tw0iPFvc9KjP4U5HsVeOhbl/llGGpXP0Ql63q9e+oP9d6OpC4vz9nCP/0KcEIu6qugvr+e 4BUoYpD2QxxTZG5TheI4IkgtjdS6SIQUaoYhAuXrXT1cglWY2cobY2Uow+etBT30oPE638 Dzhni6XVNfkZG18QtDQwl9dyku3MBPUPPsA/l5PHzz8d9O+wOASTixRVfLFk+g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tMe0g3jwXR/976+VePxD04JYud2yUWQle7bIApeWz3U=; b=mnbNiMQGcxWqmK8+eswVy3fFEqOh4khlUjvif2kdqmM8XglIMwznTGdAuv8S6wuJglCeLd 0Xdo5GTW14vzNRCA== Date: Mon, 07 Apr 2025 08:52:28 +0200 Subject: [PATCH v2 05/32] selftests: harness: Remove inline qualifier for wrappers Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-5-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=1419; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=iTc/RNQUri37IjlCMpegyjj2hPVvSJ8rCK9az0iWMW4=; b=fPuqO+THwyekty5QwWrGCk90B0dBCnHpCOameY4Pv6uN4eoOtDVUBuZDOSMx4Aj0fCPwhx8R2 fU0Q67Ai9eVBztjXmjrEcdaJnHwkVT12iukuaHLgLDjne1RzX7RgvYK X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= The pointers to the wrappers are stored in function pointers, preventing them from actually being inlined. Remove the inline qualifier, aligning these wrappers with the other functions defined through macros. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/kselftest_harness.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 5822bc0b86a3c623fd34830fb8b541b27672a00b..222a4f51a8d704c41597e09a241ad887ef787139 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -172,7 +172,7 @@ #define __TEST_IMPL(test_name, _signal) \ static void test_name(struct __test_metadata *_metadata); \ - static inline void wrapper_##test_name( \ + static void wrapper_##test_name( \ struct __test_metadata *_metadata, \ struct __fixture_variant_metadata __attribute__((unused)) *variant) \ { \ @@ -401,7 +401,7 @@ struct __test_metadata *_metadata, \ FIXTURE_DATA(fixture_name) *self, \ const FIXTURE_VARIANT(fixture_name) *variant); \ - static inline void wrapper_##fixture_name##_##test_name( \ + static void wrapper_##fixture_name##_##test_name( \ struct __test_metadata *_metadata, \ struct __fixture_variant_metadata *variant) \ { \ From patchwork Mon Apr 7 06:52:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 878918 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 210B3225797; Mon, 7 Apr 2025 06:53:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008785; cv=none; b=VmLCYHNgsr25Wn3hJBU4ztAF4GZ0/SAbAb5mfVf7Uh4sBpQUa1g7cqR3ibtKJocRVhzXT6SO1x6DYQyxmKSQ/MUZan8NRb8Xn/7vtKn3w0vC/Djw/GdXF6ihonAooftYWYzZ6ibwJRQxVzcQ6XoweHUwnmUOZsLp009M0k3gci4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008785; c=relaxed/simple; bh=X+BMimOr27k+/lCB8IAFuJEQitOZeP8NtZG5I0zUYoE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IDfJ+2xtdVNKxQY61myhXtuBKQmRwJD9ryzSpky1iBZGKPwe5ffCtyA8otk/zmQftetYWHQApL3mV1VySRzBaQ/7dJcmKxmaiINbKRucrL9UE0DF5EjWjU6Bhzicm/iw5qO5pfhMEzmrqQHWc/Qmg68dczBPvGaoBbLMcYxBDyE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=QC/CgySL; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jsIPwuO0; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QC/CgySL"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jsIPwuO0" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wtICgEwn39BNK2RVwM0gACpiOULlMkuI9K6OeLRKX6w=; b=QC/CgySLPb8G0uPvTHftXR63Js/yqF8ZwbcOXYN4by83lAtfR7GOMG1/FJMdzsu+q6j4X2 HpJ8oulmT5f3HuRXhlwjEvcuPr8a+mxHYNVfmJlhiWbGrS0CcmhXx0jv+xxpbKtBaFz8TL csMM7Rdw3B7ZhP+73FP9AjLRKw7FNmHbOMgJHYOBwqZ0YU+nehK4Gqwzy5jLVsN4ZCLPhs dkjHY2Emvcy1v25aSunqTjV8JkLnHUd7ecTdF6LbTURGZfex3zHsdQarvu/1oGKQ6CdOyN lQwj7aNSCpjclWAn6Ua0vUq+wjQc0aoYBLAHfn32FLtB4fH4E4DnZ2uLBpaWGQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wtICgEwn39BNK2RVwM0gACpiOULlMkuI9K6OeLRKX6w=; b=jsIPwuO06RW3ZllBgG2wUUQt1igUNC7Sf9FXXabJm7I83Elv1Xbg4IkAc3EeKBZ/PJDQa7 XieX5GHxKs0WeBDQ== Date: Mon, 07 Apr 2025 08:52:29 +0200 Subject: [PATCH v2 06/32] selftests: harness: Remove dependency on libatomic Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-6-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=1409; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=X+BMimOr27k+/lCB8IAFuJEQitOZeP8NtZG5I0zUYoE=; b=mpooDyXjTAA/0FPKJ3eg/h9ao9poICLHIrFGQxe/S2CvGJJdFmljNPx04hlh4b71+4eDX4RNT E792W+2GTa5AiiV6fnEp0nkC9twKOHrm6z4O35YZVn/BYBBXUwDhc++ X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= __sync_bool_compare_and_swap() is deprecated and requires libatomic on GCC. Compiler toolchains don't necessarily have libatomic available, so avoid this requirement by using atomics that don't need libatomic. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/kselftest_harness.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 222a4f51a8d704c41597e09a241ad887ef787139..7ec4f66d0e3d7f129f6c2a45ff58310dabe5d03f 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -439,12 +439,12 @@ } \ if (child == 0) { \ if (_metadata->setup_completed && !fixture_name##_teardown_parent && \ - __sync_bool_compare_and_swap(teardown, false, true)) \ + !__atomic_test_and_set(teardown, __ATOMIC_RELAXED)) \ fixture_name##_teardown(_metadata, self, variant->data); \ _exit(0); \ } \ if (_metadata->setup_completed && fixture_name##_teardown_parent && \ - __sync_bool_compare_and_swap(teardown, false, true)) \ + !__atomic_test_and_set(teardown, __ATOMIC_RELAXED)) \ fixture_name##_teardown(_metadata, self, variant->data); \ munmap(teardown, sizeof(*teardown)); \ if (self && fixture_name##_teardown_parent) \ From patchwork Mon Apr 7 06:52:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 878917 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 C9A5B226183; Mon, 7 Apr 2025 06:53:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008786; cv=none; b=H8lFamxJJVStWRU4qzE0Kj+AzkV+CmKlHdHRxAkg+fNHRgQm/J76MGh7NiUnhsl9EQN1hf7zTgdeKcxlg6EzDrkh0lq7layKZxFF3QJUuMZ5i7xFyWH7bM3f3kAPGcztvYCjohD9eKyP50kVRZBbA2OF0Cgu7/2mFfVEuA+JJXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008786; c=relaxed/simple; bh=+dslTYWYeJwxZbZ+0Wm4R7ANchBW/ILHYihcJOyZL/s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Bi7vm5ydAP5Kw/qJTGLaZtNxy2//jVM7CmoZeoRWO4xBlx7aWc+POGeZ7aWUkO/5b2tV6LT+mf5p5vv3aAJbOTgYSuscpgrG9qW4iFVkLUfURgnz5k2DvxRpQYnidDqOfxdGCYImaRt6tlY5q8BRzlD+VXoh6T/XCPs+fMhrW4g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=V38+wXGL; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=31mmJ2cW; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="V38+wXGL"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="31mmJ2cW" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008783; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TmiOiBbSMjseKwrhLLCFNenUe0eZoM7FizEqWVEk5UQ=; b=V38+wXGLOtUhDQla3uWydkWVzU/I/vE0Sv+vxPQegruk6c7uKp7NRe3BWl+PTFMJfCu3T+ 6cruUq7VApZ9h/L4pQQXTzgmZeo+Zp+UCqnfYbCHi3EZs76FIVgy0RYX89HrDpb7AQzQNv 95uNnqI4zt91mh1ltjsP0QzcBvbkoYTeXls46HyT79XdePDFrR6yYwPWS+EOQRnjE/hRAe CPp916RfgPAheXshQ0ytH1n8GEukDeKDVfmhL5MZUDMbHG9nOfLZZpKO1wIwHxehKH2Zy/ UnVXSIf01O1NOswqfVAGd4kc70UKbSvyeeqbRnR3vRf+rBIovSYSXYlzGlpGcg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008783; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TmiOiBbSMjseKwrhLLCFNenUe0eZoM7FizEqWVEk5UQ=; b=31mmJ2cWW9pklYy1+PczYNiK+fXn4qANvpSDmYczbse4/CNHgwZaTxNbo25/HvBC5Odk0X KwJLfFRkPbnfqbCQ== Date: Mon, 07 Apr 2025 08:52:30 +0200 Subject: [PATCH v2 07/32] selftests: harness: Implement test timeouts through pidfd Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-7-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=4071; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=+dslTYWYeJwxZbZ+0Wm4R7ANchBW/ILHYihcJOyZL/s=; b=cu7SgK/T4ZELMNP3Tmj+zwV3v0cZxgO3eB92D9yGauWiobLp6z+dEfdCfAzNyvyo7rysI63LH J+5wjIygrtEAu955RJN0C6shUs0RlpQpKIpG+eKQTmuqyaHdMy5DgZQ X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Make the harness compatible with nolibc which does not implement signals by replacing the signal logic with pidfds. The code also becomes simpler. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/kselftest_harness.h | 72 ++++++++++------------------- 1 file changed, 25 insertions(+), 47 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 7ec4f66d0e3d7f129f6c2a45ff58310dabe5d03f..1e459619fe8657d7d213a7b16d7bcbc58e76e892 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -56,6 +56,8 @@ #include #include #include +#include +#include #include #include #include @@ -914,7 +916,6 @@ struct __test_metadata { int exit_code; int trigger; /* extra handler after the evaluation */ int timeout; /* seconds to wait for test timeout */ - bool timed_out; /* did this test timeout instead of exiting? */ bool aborted; /* stopped test due to failed ASSERT */ bool setup_completed; /* did setup finish? */ jmp_buf env; /* for exiting out of test early */ @@ -964,75 +965,52 @@ static inline void __test_check_assert(struct __test_metadata *t) abort(); } -struct __test_metadata *__active_test; -static void __timeout_handler(int sig, siginfo_t *info, void *ucontext) -{ - struct __test_metadata *t = __active_test; - - /* Sanity check handler execution environment. */ - if (!t) { - fprintf(TH_LOG_STREAM, - "# no active test in SIGALRM handler!?\n"); - abort(); - } - if (sig != SIGALRM || sig != info->si_signo) { - fprintf(TH_LOG_STREAM, - "# %s: SIGALRM handler caught signal %d!?\n", - t->name, sig != SIGALRM ? sig : info->si_signo); - abort(); - } - - t->timed_out = true; - /* signal process group */ - kill(-(t->pid), SIGKILL); -} - static void __wait_for_test(struct __test_metadata *t) { - struct sigaction action = { - .sa_sigaction = __timeout_handler, - .sa_flags = SA_SIGINFO, - }; - struct sigaction saved_action; /* * Sets status so that WIFEXITED(status) returns true and * WEXITSTATUS(status) returns KSFT_FAIL. This safe default value * should never be evaluated because of the waitpid(2) check and - * SIGALRM handling. + * timeout handling. */ int status = KSFT_FAIL << 8; - int child; + struct pollfd poll_child; + int ret, child, childfd; + bool timed_out = false; - if (sigaction(SIGALRM, &action, &saved_action)) { + childfd = syscall(__NR_pidfd_open, t->pid, 0); + if (childfd == -1) { t->exit_code = KSFT_FAIL; fprintf(TH_LOG_STREAM, - "# %s: unable to install SIGALRM handler\n", + "# %s: unable to open pidfd\n", t->name); return; } - __active_test = t; - t->timed_out = false; - alarm(t->timeout); - child = waitpid(t->pid, &status, 0); - if (child == -1 && errno != EINTR) { + + poll_child.fd = childfd; + poll_child.events = POLLIN; + ret = poll(&poll_child, 1, t->timeout * 1000); + if (ret == -1) { t->exit_code = KSFT_FAIL; fprintf(TH_LOG_STREAM, - "# %s: Failed to wait for PID %d (errno: %d)\n", - t->name, t->pid, errno); + "# %s: unable to wait on child pidfd\n", + t->name); return; + } else if (ret == 0) { + timed_out = true; + /* signal process group */ + kill(-(t->pid), SIGKILL); } - - alarm(0); - if (sigaction(SIGALRM, &saved_action, NULL)) { + child = waitpid(t->pid, &status, WNOHANG); + if (child == -1 && errno != EINTR) { t->exit_code = KSFT_FAIL; fprintf(TH_LOG_STREAM, - "# %s: unable to uninstall SIGALRM handler\n", - t->name); + "# %s: Failed to wait for PID %d (errno: %d)\n", + t->name, t->pid, errno); return; } - __active_test = NULL; - if (t->timed_out) { + if (timed_out) { t->exit_code = KSFT_FAIL; fprintf(TH_LOG_STREAM, "# %s: Test terminated by timeout\n", t->name); From patchwork Mon Apr 7 06:52:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 879551 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 5F08E22687C; Mon, 7 Apr 2025 06:53:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008786; cv=none; b=W8Xg7BWohyfNq9WP0A8A1ZdASDAOrkn9OpyuVigU9W95Z3mbM8/+gvrp+2Lc1Lhm+Yc16MMQU11jhezmBoM9rKjU6smhaPMM0a1qbqmDOwJ7Gy5YtewVMjlSaQW7xlzWSq96OPYQKe6JWRQ+vrIPF+RghrxzAxH7RwqCtG5S5S8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008786; c=relaxed/simple; bh=DYq0rbz3jmlhEduwTAuGV0UE7Ds8U5rzr+9vob1udYk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MT0U279lI+BAwvKMVP5UELWRq5TNjXbmYnWGisClkY9nzehOuRpx4elcxxzt2VZtcKwgRAXUdcKuUcGh9utVA86lkaJwt62sQMBieQ5GO/4KZTDDtG4fsV6nPj+dNsfh1leGBzZsp/+iiQCwkPVXOTA7hXvpyv40BFrHaJaEO0c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=oQnGpQne; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=6zgwhJ+r; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="oQnGpQne"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="6zgwhJ+r" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008783; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qg3M61XE6rp6LYbeiMFWtQMLhXgLKx330vGb2tHj74s=; b=oQnGpQnevP0CeDcXmzxn0LiqroYU/FJBBv/Gg/8fGf0XF0065l2Q2KrpgXTJQM6uQYNnN1 6YnembfuHsCppMu5bfkOzwL/JXiZByZ+iqoOPdhTujtAWmiAPCXW6Dm4pT1chdIrHNPauh c3OCwGjN+Xln79D5EZpv9L0smh1Hl5P2a/dv7TnSGFX3sex4ezpjziEl6plxhGb8E5Ez8Q qmNw47pr4YdNY52t6FQZMQEhXnSbkAiF20MApSp+hck9GN7YPnJ+hFzVdxaZw1iyVHV/ba IR29HAwI1qlQ8C83sfLD0C6+YVy+SFD1huA+hJc0qZbUpz3RV+4DCyajM70Ghw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008783; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qg3M61XE6rp6LYbeiMFWtQMLhXgLKx330vGb2tHj74s=; b=6zgwhJ+r/XFeFsxlXpiRtUJ2VcOl8iIG1pCS8XxVklEFJPwTLjOTtN5X2/2oQG562wYum0 UwMcEvxIyOWYJYDQ== Date: Mon, 07 Apr 2025 08:52:31 +0200 Subject: [PATCH v2 08/32] selftests: harness: Don't set setup_completed for fixtureless tests Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-8-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=862; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=DYq0rbz3jmlhEduwTAuGV0UE7Ds8U5rzr+9vob1udYk=; b=ieV2FmPcrKiLSRtiKwGOGYCIJxRKefKMzCPXw+6O8FU0DIsGdMK23K3CwnKCPn2Lo5aoi5UBX SWiq5I1qcZ1CX2RwRje5Nej8g1S+8RLnbTNSI8KKIf+APm0czSeANAq X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= This field is unused and has no meaning for tests without fixtures. Don't set it for them. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/kselftest_harness.h | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 1e459619fe8657d7d213a7b16d7bcbc58e76e892..905986debbfb0ce8c9659dbd52b6c67c6759cae7 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -178,7 +178,6 @@ struct __test_metadata *_metadata, \ struct __fixture_variant_metadata __attribute__((unused)) *variant) \ { \ - _metadata->setup_completed = true; \ if (setjmp(_metadata->env) == 0) \ test_name(_metadata); \ __test_check_assert(_metadata); \ From patchwork Mon Apr 7 06:52:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 878916 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 9BF89226CEF; Mon, 7 Apr 2025 06:53:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008787; cv=none; b=FvKGU/+dVYuFHemSLYgheN4RFQVgderNv4CMtl1sa7vIwcodXm0wNzkW/xUcmJWAqC4XvspA7UZn0zzqAOyrpeM/ffnNMGJ09GUunkoZodqQ0/vokZpf3L+7w748ly08Id2PohKkOMnn1PPEul1eFVmRzI+Ee2wkwB60VVawAPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008787; c=relaxed/simple; bh=BVT171KPOVJVjfzTPXmBhG+I/rvwg4GYgQn0y8XhdF0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LqO53ILp4Vjv4q1Pm0g3cQOBuYVOgcMgG1JFKw58Htx1MwJ2/mOlU1CrsiM6pVho3QAu3qrv7+smXtkDNQ6dqEpvJTML7HHeQtawTJ7ZVLFbGhA41LOYa/HT/RhUAEAsp1A25XxC+JS8xoaad0H3/IxGT0ldyHqhAmZdqV2HIHo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=119EFkKa; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=brpD5Vq0; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="119EFkKa"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="brpD5Vq0" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008784; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PfHP6lDLf5mEBPgKe6QaxYDp7DWXdQcn3ptsh2iol5E=; b=119EFkKaDIyTry59mhF6Nj6Q8i7IqCcSaEij1XCc1mx/ic9n0pXXKk6e7oNKqnLWaHGkJf ldRmSURSE8UsakW5GFO/dt74mmrVATJcVUp6Xx4bEvNuiTrL24/OCoiaOynD11XmV2NlIJ wMsAGRg5D9wFMkxWBrTGWHt1os6cYBFwrWBi07IZ4IMVMmM1W2yr9TdPk4qRaMyKQ/Ec6B bTUTeY9DDqM6Uk3S5HHxbITusezgF/D5OnDwpKgffDp0tEZzp/nek0l6KpOs1V14t7HOol 71T+6/kvczJYNY+3vbIgYwZCCTqnpW0HmwnZt/udOO/zYCYfuFVCE1aF3CxmVw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008784; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PfHP6lDLf5mEBPgKe6QaxYDp7DWXdQcn3ptsh2iol5E=; b=brpD5Vq0BTZ60J3GCjNOOZ9F9JyPzhxGSaA5sCouL/MGLReltn+Hy0hP45hxlAXZzER1nR OMgBH6tFovjADcBQ== Date: Mon, 07 Apr 2025 08:52:32 +0200 Subject: [PATCH v2 09/32] selftests: harness: Always provide "self" and "variant" Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-9-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=1726; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=BVT171KPOVJVjfzTPXmBhG+I/rvwg4GYgQn0y8XhdF0=; b=EVaqUXTX8S9p1Cg05h5IAzL1hFWtZWPygOsiGMSM2xZxIZYd0RG4EAh48/iKnVjIo+l+BSYgT xW1vK0VlblZCEl37Zi1EzwYnJZkbex40hwjlCfLlnknujFbK/sA0/cQ X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Some upcoming changes to the assertion macros need those two symbols also to be available for tests without fixtures. Provide them with a NULL value. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/kselftest_harness.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 905986debbfb0ce8c9659dbd52b6c67c6759cae7..4038ceeb42a870a2b77c6888df8a7bb4c4a258ba 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -173,13 +173,13 @@ #define TEST_SIGNAL(test_name, signal) __TEST_IMPL(test_name, signal) #define __TEST_IMPL(test_name, _signal) \ - static void test_name(struct __test_metadata *_metadata); \ + static void test_name(struct __test_metadata *_metadata, void *self, const void *variant); \ static void wrapper_##test_name( \ struct __test_metadata *_metadata, \ struct __fixture_variant_metadata __attribute__((unused)) *variant) \ { \ if (setjmp(_metadata->env) == 0) \ - test_name(_metadata); \ + test_name(_metadata, NULL, NULL); \ __test_check_assert(_metadata); \ } \ static struct __test_metadata _##test_name##_object = \ @@ -193,7 +193,9 @@ __register_test(&_##test_name##_object); \ } \ static void test_name( \ - struct __test_metadata __attribute__((unused)) *_metadata) + struct __test_metadata __attribute__((unused)) *_metadata, \ + void __attribute__((unused)) *self, \ + const void __attribute__((unused)) *variant) /** * FIXTURE_DATA() - Wraps the struct name so we have one less From patchwork Mon Apr 7 06:52:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 879549 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 94308225A31; Mon, 7 Apr 2025 06:53:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008789; cv=none; b=NVrr6nPTKexDoJhbLHsWyr+1JS4LqAQx0YLaWhUy7h5vZQyBHog2PkM/Lhaeea/eJEhR9UMJBIT42ZDZ0py2bXWDPC6hZtOGkzKq/GEfq6XSKwLcAqaCSttIGxFqV2695tl3Po0ZSZTvOdGWKaTRnsDUaRcqXoR4HImmlYM/DJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008789; c=relaxed/simple; bh=xsOgqpVF3xELBsCaLrwDdUg/BIkBndVgq3S6YVEJtrg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hkhqrAe1CF1Y7x65NShVXBqK8xpRFlvAuSdVZyz+1YwhGkdcWKT/emzkLLneNHxc9kDPl7WCiQ1WgVYfER4tZY/Lg7jkiqa9ma2bfzYf0hDFDmsuAofhYFsqVhRE/M1dvLauDTLMWNPbEVMtKPs1e1EC65jAfEHM5prc83opsaM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=IXeZxYkv; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=KJViICUw; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IXeZxYkv"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="KJViICUw" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008784; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s2m1ytKmJLv4W19Ree/8QxaUIOzVWzU9VNFHgbO9ms8=; b=IXeZxYkv1OYam7J/e0atSnptO2qbkkrLtOaK/c/gw73RJr6/YhVbIkLGwK0+6zI8KqIxCV 0K/kVNkuQ5JrsE5Cge+pn7w/48yqKYinmw5BOfMcoZgKmtKIun1CqFgEgd/26OFQzDuaR0 GzNk4LkMv84/b77g+qfVVyZeTOR+63zaK8kURTcjqcczS4wUtDK5WQ29Sa+CLslZPyVpU2 PPYaO+43/qso9n2riBwzbkc1jXiitU7Vn++f7BvhMHZtvTD85qu7Jmoet+T74EkNtzyEGs Zexo8VgyjyPBM1evFZ/0uXTXmC11sm5HgtNcO8QpMDXclMtyGJjt8zNacZuwPg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008784; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s2m1ytKmJLv4W19Ree/8QxaUIOzVWzU9VNFHgbO9ms8=; b=KJViICUwFWy9pHzmhp6jnV1zB4MaHL9JfdvZhCtipA33x9pSmsMU6Gn7bBwHhf7KI8tKWb PXFjsHiNaZtQECDA== Date: Mon, 07 Apr 2025 08:52:33 +0200 Subject: [PATCH v2 10/32] selftests: harness: Move teardown conditional into test metadata Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-10-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=3443; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=xsOgqpVF3xELBsCaLrwDdUg/BIkBndVgq3S6YVEJtrg=; b=wyJ1aTkDeVvu4HQE4t5UT7rxpGoIYKdi4n7ZZ+rPHeiFeibNPA85n82HuWlcxVcTBsHoh9k9J ysEX4balNVsA2xFN4Y/698QK/vtqcTEanYJa5piH0xOXKhyBt1Im9fX X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= To get rid of setjmp()/longjmp(), the teardown logic needs to be usable from __bail(). To access the atomic teardown conditional from there, move it into the test metadata. This also allows the removal of "setup_completed". Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/kselftest_harness.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 4038ceeb42a870a2b77c6888df8a7bb4c4a258ba..790445c541aa3875d8d42822ab979295cc869d39 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -413,9 +413,9 @@ pid_t child = 1; \ int status = 0; \ /* Makes sure there is only one teardown, even when child forks again. */ \ - bool *teardown = mmap(NULL, sizeof(*teardown), \ + _metadata->no_teardown = mmap(NULL, sizeof(*_metadata->no_teardown), \ PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); \ - *teardown = false; \ + *_metadata->no_teardown = true; \ if (sizeof(*self) > 0) { \ if (fixture_name##_teardown_parent) { \ self = mmap(NULL, sizeof(*self), PROT_READ | PROT_WRITE, \ @@ -433,7 +433,7 @@ /* Let setup failure terminate early. */ \ if (_metadata->exit_code) \ _exit(0); \ - _metadata->setup_completed = true; \ + *_metadata->no_teardown = false; \ fixture_name##_##test_name(_metadata, self, variant->data); \ } else if (child < 0 || child != waitpid(child, &status, 0)) { \ ksft_print_msg("ERROR SPAWNING TEST GRANDCHILD\n"); \ @@ -441,15 +441,16 @@ } \ } \ if (child == 0) { \ - if (_metadata->setup_completed && !fixture_name##_teardown_parent && \ - !__atomic_test_and_set(teardown, __ATOMIC_RELAXED)) \ + if (!fixture_name##_teardown_parent && \ + !__atomic_test_and_set(_metadata->no_teardown, __ATOMIC_RELAXED)) \ fixture_name##_teardown(_metadata, self, variant->data); \ _exit(0); \ } \ - if (_metadata->setup_completed && fixture_name##_teardown_parent && \ - !__atomic_test_and_set(teardown, __ATOMIC_RELAXED)) \ + if (fixture_name##_teardown_parent && \ + !__atomic_test_and_set(_metadata->no_teardown, __ATOMIC_RELAXED)) \ fixture_name##_teardown(_metadata, self, variant->data); \ - munmap(teardown, sizeof(*teardown)); \ + munmap(_metadata->no_teardown, sizeof(*_metadata->no_teardown)); \ + _metadata->no_teardown = NULL; \ if (self && fixture_name##_teardown_parent) \ munmap(self, sizeof(*self)); \ if (WIFEXITED(status)) { \ @@ -918,7 +919,7 @@ struct __test_metadata { int trigger; /* extra handler after the evaluation */ int timeout; /* seconds to wait for test timeout */ bool aborted; /* stopped test due to failed ASSERT */ - bool setup_completed; /* did setup finish? */ + bool *no_teardown; /* fixture needs teardown */ jmp_buf env; /* for exiting out of test early */ struct __test_results *results; struct __test_metadata *prev, *next; @@ -1197,7 +1198,7 @@ static void __run_test(struct __fixture_metadata *f, t->exit_code = KSFT_PASS; t->trigger = 0; t->aborted = false; - t->setup_completed = false; + t->no_teardown = NULL; memset(t->env, 0, sizeof(t->env)); memset(t->results->reason, 0, sizeof(t->results->reason)); From patchwork Mon Apr 7 06:52:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 879550 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 D35C2227B94; Mon, 7 Apr 2025 06:53:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008788; cv=none; b=QdFMDd1Ns4LRpO+nEenfQCZlq7rF4LDyoa2+c6rH15RD2TgVImdzyLdndyW5n82t7SlLssWczQQNXzxDN3QldSGpGhdIcUq6IfTrNbcXSsWRbwklC7Xkt5x8t8boesV2tYTCOOycPmDT9Y5hnDra4wpN8753wD6UcxiKyDPIHZg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008788; c=relaxed/simple; bh=LGVMuklXgCkpJyincccVHRHsRYbHKB8kTUjlwhV0ovw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rt9JSsuDaYguscXpdUXB43mCnA2jwvyrV7I3ZnJjbPSntVfFSZBS36xkIV2P+SCB/z0OiooCVLo3aN4KXONfsY4lqFhEmhUtNkJ0sudroopksFH2/fVufsAr0p+5fHPnsod72/AiYVa1ET7YTT8QFHdjPwBKKemPbN67o3zxlCE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=WdyOPdFu; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dUuS3g/n; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WdyOPdFu"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dUuS3g/n" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008785; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z7VvCGnYllIwWlmCyX7MyWOjcCjHF74d/AC9380lrt0=; b=WdyOPdFu3mOYACexSwGyIMhbG3Ql1IiPr/0+tW0iGj56hbhItBLhdC0sWVK17KN77/H/9V OyvCzatOfbdct3YnSBRWCJ/f7mV6HXxBURT9KSZ2nmOpFuf+y32jXix8UZzDc2TW6woQMW 9Oc/6wxf4sgBnt6WE/gEqTaokT4mtvLNgCzkfZKl6qQypfF5n51GZlL04R/8OVc2O9+oh4 HsDo0t/E7+GwS0dl7blzbgU0o0ck3hYWp7wUaT1s9nNDkWjqqDTk/zjkA5opS/WYY61aJl k/IQQOZ+zmytx+KeAMq4aRZPZyqNWPSbEOH0CxLImBQPU+CVooaIMfmu9NX0Ng== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008785; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z7VvCGnYllIwWlmCyX7MyWOjcCjHF74d/AC9380lrt0=; b=dUuS3g/nIJPohoaV7YioHFC+czIeyDLogcqrOFjgOfLrwoHv7jV70kdzbrYTu6aVX+ZRVs fiZdNZjGb4RJcsBA== Date: Mon, 07 Apr 2025 08:52:34 +0200 Subject: [PATCH v2 11/32] selftests: harness: Add teardown callback to test metadata Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-11-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=2758; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=LGVMuklXgCkpJyincccVHRHsRYbHKB8kTUjlwhV0ovw=; b=mDCKvXHrs+8EhNHov9yHAtB/weKXm8CTu3PLsSAatKJgPJRPOu2EE7M/4hurod/yrSF0CixIQ 8t7BNCZl6liC/cf90d52vtZpI90PYi6BiqnE/VlaO0MhHXPwfse7mJH X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= To get rid of setjmp()/longjmp(), the teardown logic needs to be usable from __bail(). Introduce a new callback for it. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/kselftest_harness.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 790445c541aa3875d8d42822ab979295cc869d39..5373b8da8886aef5df3368aeff95080636ae2343 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -441,14 +441,10 @@ } \ } \ if (child == 0) { \ - if (!fixture_name##_teardown_parent && \ - !__atomic_test_and_set(_metadata->no_teardown, __ATOMIC_RELAXED)) \ - fixture_name##_teardown(_metadata, self, variant->data); \ + _metadata->teardown_fn(false, _metadata, self, variant->data); \ _exit(0); \ } \ - if (fixture_name##_teardown_parent && \ - !__atomic_test_and_set(_metadata->no_teardown, __ATOMIC_RELAXED)) \ - fixture_name##_teardown(_metadata, self, variant->data); \ + _metadata->teardown_fn(true, _metadata, self, variant->data); \ munmap(_metadata->no_teardown, sizeof(*_metadata->no_teardown)); \ _metadata->no_teardown = NULL; \ if (self && fixture_name##_teardown_parent) \ @@ -462,6 +458,14 @@ } \ __test_check_assert(_metadata); \ } \ + static void wrapper_##fixture_name##_##test_name##_teardown( \ + bool in_parent, struct __test_metadata *_metadata, \ + void *self, const void *variant) \ + { \ + if (fixture_name##_teardown_parent == in_parent && \ + !__atomic_test_and_set(_metadata->no_teardown, __ATOMIC_RELAXED)) \ + fixture_name##_teardown(_metadata, self, variant); \ + } \ static struct __test_metadata *_##fixture_name##_##test_name##_object; \ static void __attribute__((constructor)) \ _register_##fixture_name##_##test_name(void) \ @@ -471,6 +475,7 @@ object->name = #test_name; \ object->fn = &wrapper_##fixture_name##_##test_name; \ object->fixture = &_##fixture_name##_fixture_object; \ + object->teardown_fn = &wrapper_##fixture_name##_##test_name##_teardown; \ object->termsig = signal; \ object->timeout = tmout; \ _##fixture_name##_##test_name##_object = object; \ @@ -914,6 +919,8 @@ struct __test_metadata { struct __fixture_variant_metadata *); pid_t pid; /* pid of test when being run */ struct __fixture_metadata *fixture; + void (*teardown_fn)(bool in_parent, struct __test_metadata *_metadata, + void *self, const void *variant); int termsig; int exit_code; int trigger; /* extra handler after the evaluation */ From patchwork Mon Apr 7 06:52:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 878915 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 5FD49227E95; Mon, 7 Apr 2025 06:53:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008789; cv=none; b=AVbzKXN5YRm7pZ8QKc+5HJQOMsi4fmEiGWuAiV6rw0dE5PWkWcjs1yNMIyvPhO8FwtGq+a382G8U3NaYYhNeQn2cpLLsj/VKpmhpOyzsLyxV5rKk3tLD7rxsybB9q/RnHkxXhm7wR0+P/RaVVtkksVC8XbSWXm+EbLtWGPtKNPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008789; c=relaxed/simple; bh=ROPqzxq1eeM/Z2SLe3nArtedAx5wJL7q5hTnAUzBZ+0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a5hG5m9C4Q1KwUfeL2xTysjSN5/0dwctjLoTC9YihQG99alNfj7AKAgRCqqDd/LiEZfcb0iLjym18A5Id0L8HWwD/012yy/6nBTUfM46GhOfZWm+VcWfa9kKhEW5iNHN4iTcCSBdhQNxSOoCIA0agM/+D/N1/zO6js4oLVwhxIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=K6hc7nj2; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ApfBqGjH; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="K6hc7nj2"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ApfBqGjH" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008786; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Nw4rcpI3oL6Bs10R/XzcuUCLJVM3NVoV8YHTZBkuT2U=; b=K6hc7nj2afGxdw776RAnsZMGAEjfPJyGkEhwGn+Tst0N8sWmyuIMpg81dOR8Kdpqv+Eo3d p+gDCqJ5jfVkzp1zZK8zE/WcK9cNrAB1OcO1lLkBKnFNwXt7nHCIERj37D8Klmx2ihaPT6 xOROqpE1HH4GOTCxvPfF020LevTc4QtJ9fDFqtakji8YlGmBbt1WTJiOqwVeu6bRqHbsVz Kibg0COaWK91c6cmHdV1NmM4im210YLebj/ZkT0QMTCG79TmgdhWejSKjqpjRfrkw3N7eT c2FI1W7Fsf9gKvQLfVtOTegXdB8lMVlIfZOongQYKPYz+fAMYjSpaoG6wcYKzg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008786; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Nw4rcpI3oL6Bs10R/XzcuUCLJVM3NVoV8YHTZBkuT2U=; b=ApfBqGjH9Fl9PDHr8BBbu4fLy/lg42A+0sZeyK1Ld6JXv7luXsDW63HdBNrqeEhWAOTMZ2 b88MPWJQPXRU2aCQ== Date: Mon, 07 Apr 2025 08:52:35 +0200 Subject: [PATCH v2 12/32] selftests: harness: Stop using setjmp()/longjmp() Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-12-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=5100; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=ROPqzxq1eeM/Z2SLe3nArtedAx5wJL7q5hTnAUzBZ+0=; b=PeBac82BLrexwbS8lMclgonDU1WIe5nKjGu5Ozpu3cRrJ7ueTcZTlRUpcxrnbSDY3gEil2gzh iY9VwYgwSQUDJ/epuvKAx8phB0eMMwrvt0tzg4DnDbI1n88TwhKI13w X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Usage of longjmp() was added to ensure that teardown is always run in commit 63e6b2a42342 ("selftests/harness: Run TEARDOWN for ASSERT failures") However instead of calling longjmp() to the teardown handler it is easier to just call the teardown handler directly from __bail(). Any potential duplicate teardown invocations are harmless as the actual handler will only ever be executed once since commit fff37bd32c76 ("selftests/harness: Fix fixture teardown"). Additionally this removes a incompatibility with nolibc, which does not support setjmp()/longjmp(). Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/kselftest_harness.h | 49 ++++++++++------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 5373b8da8886aef5df3368aeff95080636ae2343..1e584f39a42023c400988dea96f0274d4dc3645b 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -67,7 +67,6 @@ #include #include #include -#include #include "kselftest.h" @@ -178,9 +177,7 @@ struct __test_metadata *_metadata, \ struct __fixture_variant_metadata __attribute__((unused)) *variant) \ { \ - if (setjmp(_metadata->env) == 0) \ - test_name(_metadata, NULL, NULL); \ - __test_check_assert(_metadata); \ + test_name(_metadata, NULL, NULL); \ } \ static struct __test_metadata _##test_name##_object = \ { .name = #test_name, \ @@ -425,24 +422,20 @@ self = &self_private; \ } \ } \ - if (setjmp(_metadata->env) == 0) { \ - /* _metadata and potentially self are shared with all forks. */ \ - child = fork(); \ - if (child == 0) { \ - fixture_name##_setup(_metadata, self, variant->data); \ - /* Let setup failure terminate early. */ \ - if (_metadata->exit_code) \ - _exit(0); \ - *_metadata->no_teardown = false; \ - fixture_name##_##test_name(_metadata, self, variant->data); \ - } else if (child < 0 || child != waitpid(child, &status, 0)) { \ - ksft_print_msg("ERROR SPAWNING TEST GRANDCHILD\n"); \ - _metadata->exit_code = KSFT_FAIL; \ - } \ - } \ + /* _metadata and potentially self are shared with all forks. */ \ + child = fork(); \ if (child == 0) { \ + fixture_name##_setup(_metadata, self, variant->data); \ + /* Let setup failure terminate early. */ \ + if (_metadata->exit_code) \ + _exit(0); \ + *_metadata->no_teardown = false; \ + fixture_name##_##test_name(_metadata, self, variant->data); \ _metadata->teardown_fn(false, _metadata, self, variant->data); \ _exit(0); \ + } else if (child < 0 || child != waitpid(child, &status, 0)) { \ + ksft_print_msg("ERROR SPAWNING TEST GRANDCHILD\n"); \ + _metadata->exit_code = KSFT_FAIL; \ } \ _metadata->teardown_fn(true, _metadata, self, variant->data); \ munmap(_metadata->no_teardown, sizeof(*_metadata->no_teardown)); \ @@ -456,7 +449,6 @@ /* Forward signal to __wait_for_test(). */ \ kill(getpid(), WTERMSIG(status)); \ } \ - __test_check_assert(_metadata); \ } \ static void wrapper_##fixture_name##_##test_name##_teardown( \ bool in_parent, struct __test_metadata *_metadata, \ @@ -757,7 +749,7 @@ */ #define OPTIONAL_HANDLER(_assert) \ for (; _metadata->trigger; _metadata->trigger = \ - __bail(_assert, _metadata)) + __bail(_assert, _metadata, self, variant)) #define is_signed_type(var) (!!(((__typeof__(var))(-1)) < (__typeof__(var))1)) @@ -927,7 +919,6 @@ struct __test_metadata { int timeout; /* seconds to wait for test timeout */ bool aborted; /* stopped test due to failed ASSERT */ bool *no_teardown; /* fixture needs teardown */ - jmp_buf env; /* for exiting out of test early */ struct __test_results *results; struct __test_metadata *prev, *next; }; @@ -957,23 +948,18 @@ static inline void __register_xfail(struct __test_xfail *xf) __LIST_APPEND(xf->variant->xfails, xf); } -static inline int __bail(int for_realz, struct __test_metadata *t) +static inline int __bail(int for_realz, struct __test_metadata *t, void *self, const void *variant) { /* if this is ASSERT, return immediately. */ if (for_realz) { - t->aborted = true; - longjmp(t->env, 1); + if (t->teardown_fn) + t->teardown_fn(false, t, self, variant); + abort(); } /* otherwise, end the for loop and continue. */ return 0; } -static inline void __test_check_assert(struct __test_metadata *t) -{ - if (t->aborted) - abort(); -} - static void __wait_for_test(struct __test_metadata *t) { /* @@ -1206,7 +1192,6 @@ static void __run_test(struct __fixture_metadata *f, t->trigger = 0; t->aborted = false; t->no_teardown = NULL; - memset(t->env, 0, sizeof(t->env)); memset(t->results->reason, 0, sizeof(t->results->reason)); snprintf(test_name, sizeof(test_name), "%s%s%s.%s", From patchwork Mon Apr 7 06:52:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 878914 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 6EEEF2288F7; Mon, 7 Apr 2025 06:53:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008790; cv=none; b=MKFm6B8Umk435IH+1SKi3O+7d6sV7g4C1zIcMGNLTaZhuw+6lkMwhkXWguPYz1tCeqFxrwGfJPzP1k8+c3nT9LmE6/yGY3R7ZYbawY341O8zesRpv/bAFCs4Yj/4tvjgbxz0fbBZb8omlLJSWlzzujZGGC4Fnt7haPkWhDT81RQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008790; c=relaxed/simple; bh=6pkon7Kh5/SE7q0KZvHsGJsIG9RSM3sGqKstS7SVzkM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DlKrXq4cPTkfNpLEZINJiq6/EwmPaLPO9w0lf7fykKhILCuzG6p4vTBGXU0qMpwezWV7hbBcEAkdCalK31W3Yi1daBscb7ChrVJoQzoKYa+7gqRt8O92hCOCfdOtUILRJMPLmTFwWnlLatc0Ffk2naC8CmJpjV+ZIYJi67lfiEM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=s4Q40ZmC; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=z7/AcDJ7; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="s4Q40ZmC"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="z7/AcDJ7" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008786; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pv+09698FZpTal/X+RrmmE1s8VEJjIksZePhFfpyAqw=; b=s4Q40ZmCDmMS99Bvi3ruXx74WDA9/OcvqlbJMORgCLvxpkgBOHxpNGHEG6zV9cCifkeeQY 4Bx6ngKLvG5JcaFeIx5PK8cLy3OO6kZV7ZY8BUuWwCsmfZVHltDihrj/EKNXOV3eq/V3Rp M//GDbtJ8rgSmiK5f2Ph6itPZNXg901DfFwT8IfJQoIAwpVweavvtOzZv0zZ40SPYRnjm5 k6u78Mp5zPa/hYERU7bAc15pBbTU4DgMbeSA8jrMTs0J6Qm5/8ToLqQhiowHyg7dGos15M pvuseuo2pePWPkq+8XOcexD2Jx6kEonQhxF0logXmYn2p7LlKpILjq1H6Lc2HA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008786; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pv+09698FZpTal/X+RrmmE1s8VEJjIksZePhFfpyAqw=; b=z7/AcDJ79d+veISA8eq1r4KuA1t5O8e6Gg/a2cb8i55V/lwfDNAyBW2bRWzOxKIkpf9T3E dz9qlLLSAcerIuDQ== Date: Mon, 07 Apr 2025 08:52:36 +0200 Subject: [PATCH v2 13/32] selftests: harness: Guard includes on nolibc Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-13-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=1082; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=6pkon7Kh5/SE7q0KZvHsGJsIG9RSM3sGqKstS7SVzkM=; b=VUPqGH/CqJ9c693gGeDTP7kUCmYVU8ZWXB22zgFfEiIKJzrfQMonkwuEUySAtx2zUB1pX+O8e 98fvlOy6u52Dd+j64ddlPZ8Z6lJC6E/xL7Pa2dK+clfPIHycwDwHpuo X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Nolibc doesn't provide all normal header files. Don't try to include these non-existent header files, as the symbols are available unconditionally anyways. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/kselftest_harness.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 1e584f39a42023c400988dea96f0274d4dc3645b..4247c67b3060fbe9d224c1171f3ec998ae6b1080 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -57,16 +57,19 @@ #include #include #include -#include #include #include #include #include #include +#include + +#ifndef NOLIBC +#include #include #include #include -#include +#endif #include "kselftest.h" From patchwork Mon Apr 7 06:52:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 879548 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 04EB7229B03; Mon, 7 Apr 2025 06:53:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008790; cv=none; b=sBRiqCWbfvEan2jGm/yyawleApTk35b0qrOiCyBhpNhVf6FPw/aohTPzMKP1+vduEo3iaiLvglfQsHRhY8dY22EDBz/Zoywda8UNZKlIN4uujVS0M8rhi0B5XvsBFslXZx8la9kc+La4ukySJgJqLeP5nFlWiOwzSpe0ytEzcms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008790; c=relaxed/simple; bh=vziCUdNp26ABjp35XwXDT3/Jp4kbGW8VzXFVpyrSY4M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NtmUvTNIzQhJGWKnV0oUKz6F6uxV83cd2f0E1ufSW+EkkCEE1TKhlxjvyTWGlrGZ0mM9DeYTmroAdtlxdaM9YK3dsJ6RfGseYLAGRoxLWcaCKBPgLW043xbpnMsf5cWPCYoJUYLoU2/hlnBkn7UiC2dRvLrXuDk7obdPYYrd3sA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=R80EhLog; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rGBLEOBd; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="R80EhLog"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rGBLEOBd" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008787; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pGXtZX2jgI41oXqZ0O6HteDy6lpCTkO9gddogCmzDs8=; b=R80EhLoga4nnOSjJoCclYk/M5Axw/4T9Fkbx5TMLkp9scZfRAf9Od+vETHN3fAIuLCa6M6 l7B3xH+kF+iSvTrPXBhGtNUMYk2pac5z1BqKY4gM9CYWn1YMx79rxi0Zo6UaC+fUkYUMqP 3h+rEgGRLGm3ibS/6d5hCdF8T/o9silV9Dvn1RirrwtS7xrBceFYecKMclqMyoNIjpZq7c LTdEts8xQNd8SdnjjunQVMqMaNdUvmZeK15l/ch7VaKjOJ8xjQAkriKw23xD+3+wsYkdSY +LCo5ekf9P+kDAaLbJf84zXhWkjBfY0PdF9dyAXZox4bcxyLzSuHbR2Ul/OYCQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008787; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pGXtZX2jgI41oXqZ0O6HteDy6lpCTkO9gddogCmzDs8=; b=rGBLEOBduT9FbyBAuaJixgE3SAC/1AUTDSG4IbsadcPHr+K793nwRhAinCcdiMQ9eGpe3e YyrT+jm79uTnb8Ag== Date: Mon, 07 Apr 2025 08:52:37 +0200 Subject: [PATCH v2 14/32] tools/nolibc: handle intmax_t/uintmax_t in printf Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-14-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=1971; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=vziCUdNp26ABjp35XwXDT3/Jp4kbGW8VzXFVpyrSY4M=; b=vw6ZSUoX6zR+yKJ0gQorpmCbUzLlJv0goLlWMzKUTFWF3anga1U/fdsdUOJel6acgqW7GRDwY 9TW2cLeHRISBSLyCbHJ1J4yAqmuov20P+TC0iBw1fYHN615VyaPj+m1 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= In nolibc intmax_t and uintmax_t are always the same as (unsigned) long long/uint64_t as 128bit numbers are not supported. Even libcs that do support 128bit numbers often fix intmax_t to 64bit as it is used in ABIs and any change would break those. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/include/nolibc/stdio.h | 2 ++ tools/testing/selftests/nolibc/nolibc-test.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index a403351dbf6098ac8292b9589ed8a054b4c5669f..b32b8b794015276ab6242c2be18f860c095f90a3 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -286,6 +286,8 @@ int vfprintf(FILE *stream, const char *fmt, va_list args) if (c == 'l') { /* long format prefix, maintain the escape */ lpref++; + } else if (c == 'j') { + lpref = 2; } escape = 1; goto do_escape; diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 5884a891c491544050fc35b07322c73a1a9dbaf3..ccf865e80eb715488f4ee5d623b7a02d9dd8abec 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1430,6 +1430,8 @@ static int run_vfprintf(int min, int max) CASE_TEST(char); EXPECT_VFPRINTF(1, "c", "%c", 'c'); break; CASE_TEST(hex); EXPECT_VFPRINTF(1, "f", "%x", 0xf); break; CASE_TEST(pointer); EXPECT_VFPRINTF(3, "0x1", "%p", (void *) 0x1); break; + CASE_TEST(uintmax_t); EXPECT_VFPRINTF(20, "18446744073709551615", "%ju", 0xffffffffffffffffULL); break; + CASE_TEST(intmax_t); EXPECT_VFPRINTF(20, "-9223372036854775807", "%jd", 0x8000000000000001LL); break; CASE_TEST(scanf); EXPECT_ZR(1, test_scanf()); break; case __LINE__: return ret; /* must be last */ From patchwork Mon Apr 7 06:52:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 878913 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 44935229B18; Mon, 7 Apr 2025 06:53:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008790; cv=none; b=Pzemy+yQZzogL68PEqhTPladzlU4sdvirQKtU+1j0TwcXLxbCK9n4HtXCymgFrh1gqo6EPLOYpJancYiglie5iBZPn5Y3JeZFuQaic6qUriBcraZ2gTrcAVK4fhZ6do5E7NmTVrXJs2kZ15dOEMuQMGmy+T45lYRf2pf5MlchbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008790; c=relaxed/simple; bh=yiN7932Hjz9o4Z41OyO0HMGRnPv3dGLSS2woL8P+hvA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NdYM8VtO6c7LgQaYcsLdq1iddtYHFK0kPX7PbGYPzlrs4bOCjPVg6R5iq2rxRvYgPRYJK01c5wh5Hmjel1q3la48iMePdmi/zZSies6yR21l3vAKzMrW57kX6KQcnSSwSwNRLc5T6/LlwP0OqV+Ncy9+0p1gzOKH+WDHggXkPAA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Gf/C9680; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=qUhP7tUO; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Gf/C9680"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qUhP7tUO" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008787; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=icAotOumz5oayfyIPCgSJr46gLVPYeiQGTGFCJGRKFI=; b=Gf/C9680+OH6UUbiuug16VtZiq6GQp+SjWCxR+Eo2N3/+4VptCPTJYHLoLk6+jf6EKP5WG thRF1TeuqygXwK5PwN1tuCvAI6lr5Ta7RigYTMFqlQZ+5APVXXL/0jxZ9izlC2YS2gmD/C IEHtPTthEJHCStZ/fK+7CBwFLoC9euaUy6UDvcWqvj5X+NEf6WEM6dK36p6h+kjv1+o7KT 5VpGn9YizJ97a5C5XdefRzMaspDqhh8wYhpqEvZh81qEb4clKX6yVnAlaeEdHMbRD2ykeS 9ySEe7hYHA++LG3jPPWHu8q95BkSCL1oQPH5Volr3e1RKJYO0GfaaRLWn03WVg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008787; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=icAotOumz5oayfyIPCgSJr46gLVPYeiQGTGFCJGRKFI=; b=qUhP7tUOiQ/khFF6BIuKaGoliXb2X79spYpjZ0sBTiQaDKxyfLfD8OjQfaskN8nQtBBCEr JZpWHqFp4BRmpRBg== Date: Mon, 07 Apr 2025 08:52:38 +0200 Subject: [PATCH v2 15/32] tools/nolibc: use intmax definitions from compiler Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-15-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=1199; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=yiN7932Hjz9o4Z41OyO0HMGRnPv3dGLSS2woL8P+hvA=; b=rpojShlHV8Dp4sPfS0nEziqyHJYVCwc431dd4fc38z7bQoVqiY8T7FrHXslSuYvslrFStPIeK fD9kWXIiY1YDMCM3oIBX+IPIpHO/1v+fFLzMUE5LEbZ2D75AyER5sbz X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= The printf format checking in the compiler uses the intmax types from the compiler, not libc. This can lead to compiler errors. Instead use the types already provided by the compiler. Example issue with clang 19 for arm64: nolibc-test.c:30:2: error: format specifies type 'uintmax_t' (aka 'unsigned long') but the argument has type 'uintmax_t' (aka 'unsigned long long') [-Werror,-Wformat] Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/include/nolibc/stdint.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/include/nolibc/stdint.h b/tools/include/nolibc/stdint.h index cd79ddd6170e05b19945e66151bcbcf840028d32..b052ad6303c38f09685b645268dad1fa8848370d 100644 --- a/tools/include/nolibc/stdint.h +++ b/tools/include/nolibc/stdint.h @@ -39,8 +39,8 @@ typedef size_t uint_fast32_t; typedef int64_t int_fast64_t; typedef uint64_t uint_fast64_t; -typedef int64_t intmax_t; -typedef uint64_t uintmax_t; +typedef __INTMAX_TYPE__ intmax_t; +typedef __UINTMAX_TYPE__ uintmax_t; /* limits of integral types */ From patchwork Mon Apr 7 06:52:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 879547 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 BDDA722A1CF; Mon, 7 Apr 2025 06:53:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008791; cv=none; b=cICR82jFNqdUMqs8zEJP6Ii0dDGlQzhhg3iFc4dSPM04TFd2hTyKlr6MoMakUjPmEfOB8xV5QfSkNec0cHbYPmlohZMgVIPLqcdiSemw1oKW2FZ/YxC+hXEkt1COZt2qWh9Afb7/nviaMKc/ENxIMZ413e2VZgh/llAEzp4ppQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008791; c=relaxed/simple; bh=dNb0DycZOXECXF1uglDgQ5OZ5A0IF51QyPd7mDkmpqQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cNvWWd8v3NOZ/gtQJuRKSEWEb5VxuM0A9RkAwGJvJgR3IvYjr1pf4Vi6iNGXuWEX148DyRbk8oT6TXPSzTIlju4lz18HJWhOr9xeJgMtZ599xw+8rJipJlcOCi4gQ2ZUt+qqAv7Oif3BN96KHpzul1euMEXB02JZJIxfNysPauY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=AuV7VeIK; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=/Rmtk9ol; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="AuV7VeIK"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="/Rmtk9ol" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008788; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OqWg6AnaVdBpGZDz7vvxu+fK6BxS8YBbe1FDLG4qoKs=; b=AuV7VeIKFvSThJ7EWy87hBfCFAkZovM2BHm4BmW4NksqewRssXoFsOyalOZ+bvtLQwzfSb 8xnII1bk82ItJsF1x1ZJkvOrnBaPeGZ1iDbl/9gCbPfTx5iKTtNcMGABUbf23Ydgkd54iO wPkgT7R9gTP0XNojLI7KzFmzfjngwZktPJI0FDMcpLkPVX8gPIzC+Gl9wN9geH7FZHZAMb WVZuGkgItSbB8hfl2bX8xZQfxBYplpSswqmekVasv1/J0lvtRspHOjXwtA/gDYXd72qa6m /GBzr+gnAtFmQ3ZaBM0uxMP4ivAQ3iQy1DwTUclYlTwh/LhgffG/5mDgypzlOg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008788; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OqWg6AnaVdBpGZDz7vvxu+fK6BxS8YBbe1FDLG4qoKs=; b=/Rmtk9olDLwqysVfhC0010MzBRqZihjOB1K/49cFiFxgHE3kXC6PhQ7BBU9YQIBKNA4SAv sMG6hIkgIcn0qQAQ== Date: Mon, 07 Apr 2025 08:52:39 +0200 Subject: [PATCH v2 16/32] tools/nolibc: use pselect6_time64 if available Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-16-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=1164; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=dNb0DycZOXECXF1uglDgQ5OZ5A0IF51QyPd7mDkmpqQ=; b=siPCZeEZrV81W2zDYwybgE5DfL0UzV+ZLqYHz0S1WQYvHegTpeuCeaS8TysTwlFbkU12VoSuz Gp/8JSEJdpVDMgj+B24dodjAsdXzD3K7nMhwZwJ9XgK70mp8ajZWdhA X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= riscv32 does not have any of the older select systemcalls. Use pselect6_time64 instead. poll() is also used to implement sleep(). Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/include/nolibc/sys.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 08c1c074bec89a27e53e5d461a3ebbf71ec323d1..a5decdba402236fa0935207f9207c771ac2700bf 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -1023,6 +1023,14 @@ int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeva t.tv_nsec = timeout->tv_usec * 1000; } return my_syscall6(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); +#elif defined(__NR_pselect6_time64) + struct __kernel_timespec t; + + if (timeout) { + t.tv_sec = timeout->tv_sec; + t.tv_nsec = timeout->tv_usec * 1000; + } + return my_syscall6(__NR_pselect6_time64, nfds, rfds, wfds, efds, timeout ? &t : NULL, NULL); #else return __nolibc_enosys(__func__, nfds, rfds, wfds, efds, timeout); #endif From patchwork Mon Apr 7 06:52:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 878912 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 CCB8622A4F6; Mon, 7 Apr 2025 06:53:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008792; cv=none; b=MC16oYQ/jWoyq0d1RPt01HILyvArhaUs4fZGPADEdwXwP4qT/d+fQJxikAR8aoMSDQuH/cfLnFnEbcJXHkw/N8dxIVoOzSCUpP6ThT7Ojj1KBwVW/eWpA/wAqvBWqQ1bGJGSV0VU9JA9L9gHMqIGZtmiJuYKvkl6126eK4THUhY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008792; c=relaxed/simple; bh=UfwFCU91ffZuTdxNtj6J2SdT3JrHuwqMEWx4TRmx2p4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eRuZdRhSDzM1Y62m+ae5fYjb/22VYEb2HTlSHMlDJAGDi2l1qSprfKKtHceNNYr+7qFuVDo/Fw3Aq6JMWb/crnA3VRuQph38+mIb1vhqzrYc8m0gLGIk6JcJMKWmJu5he6kEvCElv58FZDxtkiO4ToR5te0OJg9QRROXziPj0y0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=UdJ4lWw7; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ucDHXGDZ; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UdJ4lWw7"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ucDHXGDZ" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P+8VoWEW0XZjMSQDsaz/4MYv5EAvq9VHzk9t+oyNa0Y=; b=UdJ4lWw7v2I7h8rlVSgBO1H7lbgE2CQJVtg1tQNzEPUZQugncjO8v42VBprWMFn7qdoz98 XI01RIJupRljigtUN1c20CBHKzXqsaxTi/0iF4pS8ga4+pHvXMH8TFaMkfdKCsGAuXb+fw 4D+YgZxNmJ/XEaBItqYb3bV9FBpqB3jBze19yiwLNmpKS3Nj7XEWQeep84r6s0Td4D2Z0L QXeqzMiednwyFMlbKzbBwV8GSVKyhw81VxSW8s7Fo9wwOYcGObsnxO6XM/TC1nco5171FT BTdtQZkeDG1M+uJMPfsY4AQ9W3NPz3xHEGF88VWy33ophkr3vbItHW/V2a2fzA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P+8VoWEW0XZjMSQDsaz/4MYv5EAvq9VHzk9t+oyNa0Y=; b=ucDHXGDZVX/+tmsR+WrdoJgiJe0nJP1nQC+1q19tObd47efqragCDBtRC78EgoWnQYq/l2 JiYSfpVDsOeUjPCA== Date: Mon, 07 Apr 2025 08:52:40 +0200 Subject: [PATCH v2 17/32] tools/nolibc: use ppoll_time64 if available Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-17-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=1086; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=UfwFCU91ffZuTdxNtj6J2SdT3JrHuwqMEWx4TRmx2p4=; b=L4+CAQe6TXN1O2+ZX8Sh0H2rY8xWrw0WRDzHukKtWkWcJ43BOj9HldYG57DfeE3sRU0JpiYaQ Dl2/lF0SgizBCpz9DQ3AlNOxo8ltJfqoecYYA8DsJo/buPQjm4HTIRO X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= riscv32 does not have any of the older poll systemcalls. Use ppoll_time64 instead. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/include/nolibc/sys.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index a5decdba402236fa0935207f9207c771ac2700bf..b04d83a7ec50cad7beb32198d9d47bd9d5873f69 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -893,6 +893,14 @@ int sys_poll(struct pollfd *fds, int nfds, int timeout) t.tv_nsec = (timeout % 1000) * 1000000; } return my_syscall5(__NR_ppoll, fds, nfds, (timeout >= 0) ? &t : NULL, NULL, 0); +#elif defined(__NR_ppoll_time64) + struct __kernel_timespec t; + + if (timeout >= 0) { + t.tv_sec = timeout / 1000; + t.tv_nsec = (timeout % 1000) * 1000000; + } + return my_syscall5(__NR_ppoll_time64, fds, nfds, (timeout >= 0) ? &t : NULL, NULL, 0); #elif defined(__NR_poll) return my_syscall3(__NR_poll, fds, nfds, timeout); #else From patchwork Mon Apr 7 06:52:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 879546 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 EF50422A4FE; Mon, 7 Apr 2025 06:53:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008792; cv=none; b=f4PG+a6d7WdpZunbssW1j+rUPsC/ph8U8kLDGDh9PrAbUzXvgr7YTSTa2vl0JKgZR7blgtSZeg1XCO2NjA73ELumXoNfVah6NlcnExlEgS5bUxVJttejmZNkXaY/pz3HBpb8vdW8SO/5ywEbmmHd3y2S0v8uS2rXd3svpK3VTxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008792; c=relaxed/simple; bh=k1JKwXo2zjXkowh2Iz1iHtu5+LVsdl8EjpnFP/4zQps=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BZHeerZqRsXYLmu4U8mJLbGIlf6EPCkZewiU945adQHigaf73ZxcdSy05gZU4dBxQjUUjH60XrV2mAmJV0k2nniBgXx4bhV1IrGtYACe5uX0CmxhaHymjjnhmD5N2pAOqFmwznafa3JGM/c/ETyDjkg98Oq/NQwmYD15ViGCUSI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=VkT0ydVV; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=j58ANFYe; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VkT0ydVV"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="j58ANFYe" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sSOX1xpNeJxiyfhOoTmnjm0bIp+e5sn96YzgFsrPl2s=; b=VkT0ydVVHCG0pKLyhiCMzKwTRMozffwYPXM53/e7lz/6aCqJyTSy/BUk/RqBwLBjE/NUzE uf6wwDifHKGlMReq+5L3y06cpCRnaBJ18lMJbWXVDOaTyfSukV2s1EZk7cg3gOHe8EwtcG 2zwiOboGrIeF7bM6sx8prqAwNIbGiQ0SFki6x7o3F10aM09cY5DdPewD0JYOBdibFm6A2D A3EIbGYaQ87BMl4h+WFzLfynsI4uSM8Y4DMvCXCBi/qCl19c95Ddp2NpShtiMNEOrUovv2 loR/V3TbJwYFf1yeG2k/DtP2dDb7SZHVmzigl7UDkwhenHFVdSWfvv+mNcx4iw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sSOX1xpNeJxiyfhOoTmnjm0bIp+e5sn96YzgFsrPl2s=; b=j58ANFYeAuXUGDLp1IEz5aPkd7uCGriHT3UnUpH/QBaKM4Th4K7/qyZgmmvwalyX5mEtM5 7XvBkz6W3THEd0BQ== Date: Mon, 07 Apr 2025 08:52:41 +0200 Subject: [PATCH v2 18/32] tools/nolibc: add tolower() and toupper() Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-18-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=2208; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=k1JKwXo2zjXkowh2Iz1iHtu5+LVsdl8EjpnFP/4zQps=; b=iiaXByHJ8N+nZTuC3Z0NcMB0cA7uBZDkwQun4LszzuFnFezONYgfGs1d0SpFJUgbhDHQ5Z5SE 7ys+o2HGSo7CXIy3UkC32LpTM7PIC3RC22QlDaXrJj+C5F/tvobKVQG X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= The kselftest harness uses these functions. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/include/nolibc/string.h | 17 +++++++++++++++++ tools/testing/selftests/nolibc/nolibc-test.c | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h index ba84ab700e3001a7d105e1c9e40c01bf45db9d8c..f0d335f0e467ec870066811289dfd11e46e60a92 100644 --- a/tools/include/nolibc/string.h +++ b/tools/include/nolibc/string.h @@ -289,6 +289,23 @@ char *strrchr(const char *s, int c) return (char *)ret; } +static __attribute__((unused)) +int tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + return c - 'A' + 'a'; + return c; +} + +static __attribute__((unused)) +int toupper(int c) +{ + if (c >= 'a' && c <= 'z') + return c - 'a' + 'A'; + return c; +} + + /* make sure to include all global symbols */ #include "nolibc.h" diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index ccf865e80eb715488f4ee5d623b7a02d9dd8abec..70d418b87f7731572b85d64a8128c62d01df6b2b 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -40,6 +40,7 @@ #include #include #include +#include #endif #endif @@ -1281,6 +1282,10 @@ int run_stdlib(int min, int max) CASE_TEST(strerror_EINVAL); EXPECT_STREQ(is_nolibc, strerror(EINVAL), "errno=22"); break; CASE_TEST(strerror_int_max); EXPECT_STREQ(is_nolibc, strerror(INT_MAX), "errno=2147483647"); break; CASE_TEST(strerror_int_min); EXPECT_STREQ(is_nolibc, strerror(INT_MIN), "errno=-2147483648"); break; + CASE_TEST(tolower); EXPECT_EQ(1, tolower('A'), 'a'); break; + CASE_TEST(tolower_noop); EXPECT_EQ(1, tolower('a'), 'a'); break; + CASE_TEST(toupper); EXPECT_EQ(1, toupper('a'), 'A'); break; + CASE_TEST(toupper_noop); EXPECT_EQ(1, toupper('A'), 'A'); break; case __LINE__: return ret; /* must be last */ From patchwork Mon Apr 7 06:52:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 878911 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 2B8E122ACD1; Mon, 7 Apr 2025 06:53:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008793; cv=none; b=Qf79yBgG4QRLFFqm+Ii8dWsjFdIEJCRRORLG1NYxmGR+FndLfwpfHF703Z4bzobdW8WHOM0+qImNNDvTkbsjyEhidBaYLtFJERW7qGx3HS3niAcBfb2Lt91OeKtUiknlsR0psl3EpeKKRlM+qV+EGlWRC76ar1DbdlQafHnXO30= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008793; c=relaxed/simple; bh=57F0YmhSlN4tFYcLaIwl/LaPNC82JeponEq16ncbsHI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dF4etaI5UvaorAdehGF4DSje0bq+ek61Zrkgvglyn/3CoNOP8LyaNA/tuc5mEE3LBsfImSKsOhGTVpf+D71CMXSLWO01qLwEsHMEvdMBsWp0CH+RJhkLQFGpYBfCVA3x3ToF+YV0WyYrmAt3dMJwJsyXwbjPRG7UsfToAbzku50= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=YfXWzs1Q; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=11rargUh; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YfXWzs1Q"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="11rargUh" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008790; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lCm7NpzwzHwG5QyiMDAKDL8vf/JWws+fnKfEgWpTx3s=; b=YfXWzs1QcONG6O8k+6clQ9A6IncwyFsZMfdcxiya4QaLfoWbM3pyWrB3MbcxVt8YNaTQZm mE9tDBAjN67ph+hmxTpbn3akkyuRfqmi4nsVRLkuQaqtV+fINVsxAKumjs7rw6kT1SUhhg dhR5/O8PLy81wcFhGZS0kfqQjNb/KrWC60W9yADTvflz+NdOg/0NgqV25lb+qudbj52R1n ceZ9RX7akT5SLoSSY6t9rSMLoyrNs1nzr8YBdPmUHThorxVyA781TWTZxFstN60jDQv9Tr oHf/TF41Qd9vGK3G7f8Hs6zUvoX5iHa6pMrzI0zZDz2yc+sQzTiH8/CGokjNgQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008790; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lCm7NpzwzHwG5QyiMDAKDL8vf/JWws+fnKfEgWpTx3s=; b=11rargUhMkihEH8cENiWRYqp8qNZyaWiZcZwsnyXlYnQP7nFnJmDYpSwksFb2egCb9BLQG nGdjtthHzyUUuFAA== Date: Mon, 07 Apr 2025 08:52:42 +0200 Subject: [PATCH v2 19/32] tools/nolibc: add _exit() Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-19-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=912; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=57F0YmhSlN4tFYcLaIwl/LaPNC82JeponEq16ncbsHI=; b=am9offQqMwiAHrIymp2LL0jDvA3O4PpFrCziKjwvnat14IGBWq6/qTZumMElG4appwa+LkDqN zYAjqf3bCoqA0xb9eziBrerfUvoZn6IhYRXN8chD+r/O3FsG4WSa7gz X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= _exit() is the faster variant of exit(), skipping all cleanup actions. As nolibc does not perform any cleanup anyways, the implementation is trivial. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/include/nolibc/sys.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index b04d83a7ec50cad7beb32198d9d47bd9d5873f69..f52e1953020945fb2902d47ad5f7a8e7c2c1c290 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -301,11 +301,17 @@ void sys_exit(int status) } static __attribute__((noreturn,unused)) -void exit(int status) +void _exit(int status) { sys_exit(status); } +static __attribute__((noreturn,unused)) +void exit(int status) +{ + _exit(status); +} + /* * pid_t fork(void); From patchwork Mon Apr 7 06:52:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 879545 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 E1EE922B598; Mon, 7 Apr 2025 06:53:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008794; cv=none; b=mtEbpZzopj/BOlyaXtmBis2yWVDnNNGuY8DC+bEk5xPfToIemhXsG5FFpMoA/eoSQ6YsCmS5HUu/A0xd8yKUxhr1H9KGgaWkJnjEp5AxtqgOUa7cu/MSSSKX30lgDtNj+pWDdBHiOwiOKNET1UGd1mYtmGvy8kRxhtiIYZOun5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008794; c=relaxed/simple; bh=d5MljKKNkutS36nrGWCEFbpFryRCK+Ka8uE6LBhTqxg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AEcpxbbpMhK2ukLR28CnwCRsRE9shDy8iIJk1vTPyZnSRHeEwvvZuFbpLbFV9CiYt3WqRY4MMSo1D6LXQfPRe6ZqcLYytktmJATrlih9JLqx10dq2Br5AsdSQmvfk+rUd4n7+zdCM4O1txE+PamijXL+LaEJ+Lg2b7aDyC4aHfI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=B87BattH; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rZ4OtVuI; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="B87BattH"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rZ4OtVuI" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008791; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EGIsurDNbt9wfy1oRuJrCVBPEF2XC6rkda0U4p2igXs=; b=B87BattHZE4/kqunwBMNkeoq62YUJCrR9gDnMv/GOHOJxKZJMmyqz+7ARG0OUDe0+S1ShK mFpTqWTA4zDWsPzZgfTuSI46QS3IqaYBOV2/e0xSuMDELwjPNVNpYU42LoEjuG7BpyapTk fFmLU3e/bJ5AGFmIjhsBGcRkz1PaKQQkmIbsRmIbYe3EBoaluQ5mEArGeNYP/Z62a7HOln nmqbqoX13R0vkCSgfN7+c+9YPiChnXD8z/GguiZtpIwBS6EOXyMGfOR0fs45I3r0D3ZfB1 50oDzZ/cYNR/I7ywBgZM27TdOBl8Us7OGYSAJ4LfqP2RrUxuKEWaY1TZ4ukpIw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008791; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EGIsurDNbt9wfy1oRuJrCVBPEF2XC6rkda0U4p2igXs=; b=rZ4OtVuIdd83FBiFXfs2jZAnW7XCbnanKjUV+F4sFDYKUDwmKg0XWL7rgl28CZwjolTcdz MGlidhObsWqwr1Ag== Date: Mon, 07 Apr 2025 08:52:43 +0200 Subject: [PATCH v2 20/32] tools/nolibc: add setpgrp() Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-20-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=772; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=d5MljKKNkutS36nrGWCEFbpFryRCK+Ka8uE6LBhTqxg=; b=Bc0Hb8IsKvO1wptKLJ2rsDtL2BQKr9/hIqQtXo2eJB8dz7oLQ0ozBfK2R+7YS5TpFkr/SpWAO A4u/WXG+cW5CRC/oIgta82s0tOqJyQDdYKQCJs5gzsZzEDQibho2ViP X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= setpgrp() is defined to be identical to setpgid(0, 0). Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/include/nolibc/sys.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index f52e1953020945fb2902d47ad5f7a8e7c2c1c290..5c71a2f65c7bd93f6f516a54f7e63244466fad47 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -1073,6 +1073,16 @@ int setpgid(pid_t pid, pid_t pgid) return __sysret(sys_setpgid(pid, pgid)); } +/* + * pid_t setpgrp(void) + */ + +static __attribute__((unused)) +pid_t setpgrp(void) +{ + return setpgid(0, 0); +} + /* * pid_t setsid(void); From patchwork Mon Apr 7 06:52:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 878910 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 042B922B8C8; Mon, 7 Apr 2025 06:53:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008795; cv=none; b=XAVPqsyjnHWnidVP6whIHEHeJYOOsq41MofG0hVIH/qBrhIQ8oiwtdWklOZRX5QzybIX2r9sSJDnKZ6RHin/JJ6jvAW3+34Yfhfw3UknmuZ/fIHro7QX7Wd9CBOoQv+Enby/fcB34ZNZH/QqEyB/hqwB09SqQ46Y8VKNS1Hn5wE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008795; c=relaxed/simple; bh=eueIMfuhJ+J1yj2bA5e9rnF4yzqTd/ncjRAHWOjdMl8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bjHHtjFEuzCQzOxkboahn89D88w0oHHsXw/zrQqMB+AFbJcl3md0NbOtDCBJkDNKo9eWPA5fJyCNRfUo29eYfLgOsNAvUlus1Yg4aQtUVsUWOUzrNRFdPwfdvVG8upAO+KQUO1qiIFYwYp7ENpB8K3Vft2PcXq3vD3AnRbZxCQU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=haV6Mavk; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=WYS6HE84; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="haV6Mavk"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WYS6HE84" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008792; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tz+K3JzFCxIC1WzEuZHw4kf96d8I8QM3F1CQ6V2mVsY=; b=haV6MavkJ3INLV/sb12G6p+5mwA0rJLvRRfv/Qnh5t5RCuivBOHBbzrDoD2JEAaFZk44ed WdguII8++cXG9sDM6oOpZyTB2XC0Nno2B+nm41c+45/KKw3JGYL3Tc2Q/zKNp9rnxzpjue 32iLMzORkw3c/3j0dkKdy8DgQBJpTqH/FlncfmkH5qyAjcpKsS5C5BZEHVZr3eWmZKEUF6 5AAAG3ZrnxxgkuR/8M/Mngfi2lo3BbRfDvFfPo1w/jVUs63suFA56ShgkTnBoFvpPevF4f RmNA8oFfUOL/q+KL7JJasqtQ76jP3+jLBK8EfE92vw3eBJdfpCSxNMnOGTJfYQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008792; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tz+K3JzFCxIC1WzEuZHw4kf96d8I8QM3F1CQ6V2mVsY=; b=WYS6HE84mqpV4OI//j5AWim59+SRTAsqN4WCtR+O6ecEfnuZvdkTm+z/LJiNuzMfb4PPeP K+BAwvNY+e6vrCCw== Date: Mon, 07 Apr 2025 08:52:44 +0200 Subject: [PATCH v2 21/32] tools/nolibc: implement waitpid() in terms of waitid() Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-21-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=2732; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=eueIMfuhJ+J1yj2bA5e9rnF4yzqTd/ncjRAHWOjdMl8=; b=c1Y/9C5M8EZrpldyWRKJa8tv+1Ke9Pz0esyc0zHkgHGB1PokScLvzl+UcSFQJMxUfhwY9eSeI 3XKgZkZVQkJAoW0/thfJln2R5Ipt+jThg2uv0qKRNGqleHxCNYo4hWQ X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= The old wait4() syscall used by waitpid() before is not available everywhere. Switch to the waitid() syscall which is the new replacement. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/include/nolibc/sys.h | 71 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 12 deletions(-) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 5c71a2f65c7bd93f6f516a54f7e63244466fad47..e39eefb2b82cc97eccfc030005fe0321632f12c4 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -1267,6 +1267,7 @@ int unlink(const char *path) * pid_t wait(int *status); * pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage); * pid_t waitpid(pid_t pid, int *status, int options); + * int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options); */ static __attribute__((unused)) @@ -1291,18 +1292,6 @@ pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage) return __sysret(sys_wait4(pid, status, options, rusage)); } - -static __attribute__((unused)) -pid_t waitpid(pid_t pid, int *status, int options) -{ - return __sysret(sys_wait4(pid, status, options, NULL)); -} - - -/* - * int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options); - */ - static __attribute__((unused)) int sys_waitid(int which, pid_t pid, siginfo_t *infop, int options, struct rusage *rusage) { @@ -1316,6 +1305,64 @@ int waitid(int which, pid_t pid, siginfo_t *infop, int options) } +static __attribute__((unused)) +pid_t waitpid(pid_t pid, int *status, int options) +{ + int idtype, ret; + siginfo_t info; + pid_t id; + + if (pid == INT_MIN) { + SET_ERRNO(ESRCH); + return -1; + } else if (pid < -1) { + idtype = P_PGID; + id = -pid; + } else if (pid == -1) { + idtype = P_ALL; + id = 0; + } else if (pid == 0) { + idtype = P_PGID; + id = 0; + } else { + idtype = P_PID; + id = pid; + } + + options |= WEXITED; + + ret = waitid(idtype, id, &info, options); + if (ret) + return ret; + + switch (info.si_code) { + case 0: + *status = 0; + break; + case CLD_EXITED: + *status = (info.si_status & 0xff) << 8; + break; + case CLD_KILLED: + *status = info.si_status & 0x7f; + break; + case CLD_DUMPED: + *status = (info.si_status & 0x7f) | 0x80; + break; + case CLD_STOPPED: + case CLD_TRAPPED: + *status = (info.si_status << 8) + 0x7f; + break; + case CLD_CONTINUED: + *status = 0xffff; + break; + default: + return -1; + } + + return info.si_pid; +} + + /* * ssize_t write(int fd, const void *buf, size_t count); */ From patchwork Mon Apr 7 06:52:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 879544 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 2C7FB22B8D4; Mon, 7 Apr 2025 06:53:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008795; cv=none; b=oXXmbftIe6UTgn1o5kySoNsE8lSzpmm5MWJJxzpHnyoQdLKzt28SaLnpApzFcifi81SX25Um6CShW2pHhTA3Xr28AgPb4tSj3B42Prnzecgmi9c1nNKUY2Cw349Fh5uUssjLlYeo8dcHExKwE0xraJHoridGIWjawuzVB8ZtObg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008795; c=relaxed/simple; bh=q4kd7mGGuPTJdyPDCjQYjszzTh6pp6UOGPR7zUxPBBs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HHRvXW968BTPDHUctaLHosJhJ56TLXwAzcT0FSscizMpLpQ+xGAxSMySHReZks5RFQVnd435QlQIyMvyMeUyh2THCoOW9lPvcAmw3HfvHsmOntmfSVOEf0GBAXIYLg2xeZrg1M7+og1RHCFnWHJyutbFhIhhZEEcSrgCooIqJ/4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=lGM6hPZP; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=o0wkToQ1; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="lGM6hPZP"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="o0wkToQ1" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008792; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AqLj2uDZACTDisGAnX7h0mSVa8/8RdDY0n+eZ6yxnAE=; b=lGM6hPZP5H7TtTPmf4PmBteB2HK/GYA/rQ0NUQkKz7EsXh6kR6/RDwqD8C4NwEp/WMILmD 5gpnkz+IfOm7LHK/h1XZPhV/Ld1Uxs8RCt+8QmXeuG/C5zL0m1r+JYlHgh2yViOheCFrxD vZoNkX9mHa264PuHmnmlw4ZwOTWUeaI4Vb7S7pcuOltnzXWDd6shUDX7VPYOirT7OPMZgY Okj6c+gDpT8QHX0wZ/59RWc1cdaJNpJw2nTj/5r2A6pQYqD94Cqfcr16aXak/hF8OStpuT DFw4u/PuLu9rAAaDOAYlZpp7f7hN3G13hrO3eeRir2iInPdnig0tGFu/fsCB7Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008792; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AqLj2uDZACTDisGAnX7h0mSVa8/8RdDY0n+eZ6yxnAE=; b=o0wkToQ1Qqw4XHfLLxzjGRHEnmQAgQRfiZGTc9fjkmu8U89YiAYp+1FKnsb+8M1kHSLZxJ y43l5d8+/Mtu2/BA== Date: Mon, 07 Apr 2025 08:52:45 +0200 Subject: [PATCH v2 22/32] Revert "selftests/nolibc: use waitid() over waitpid()" Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-22-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=1651; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=q4kd7mGGuPTJdyPDCjQYjszzTh6pp6UOGPR7zUxPBBs=; b=CDj6H+Bwa7JIQMAieYEjLtY7FkRGQnhzlMzywRHig/rtA8y1a+vPuSKNMRdap2rxZo9V0Pnry 8qi80tZiGH3A6TupLC5dICsbnAfv7A8m6OBAjO9fuhCLGJA+vO49pxI X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= nolibc's waitpid() now uses the waitid() syscall internally. This removes the original reasoning for the reverted commit as waitpid() is now available on all platforms and has an easier interface. Switch back to waitpid(). This reverts commit a0bc8947ac731ff95a56e0c1737e69e8c56d5b78. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/testing/selftests/nolibc/nolibc-test.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 70d418b87f7731572b85d64a8128c62d01df6b2b..b4b9a8422d76e1170ff967850429916a2190139b 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1462,8 +1462,7 @@ static int run_protection(int min __attribute__((unused)), int max __attribute__((unused))) { pid_t pid; - int llen = 0, ret; - siginfo_t siginfo = {}; + int llen = 0, status; struct rlimit rlimit = { 0, 0 }; llen += printf("0 -fstackprotector "); @@ -1501,11 +1500,10 @@ static int run_protection(int min __attribute__((unused)), return 1; default: - ret = waitid(P_PID, pid, &siginfo, WEXITED); + pid = waitpid(pid, &status, 0); - if (ret != 0 || siginfo.si_signo != SIGCHLD || - siginfo.si_code != CLD_KILLED || siginfo.si_status != SIGABRT) { - llen += printf("waitid()"); + if (pid == -1 || !WIFSIGNALED(status) || WTERMSIG(status) != SIGABRT) { + llen += printf("waitpid()"); result(llen, FAIL); return 1; } From patchwork Mon Apr 7 06:52:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 878909 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 37F6C22CBD5; Mon, 7 Apr 2025 06:53:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008796; cv=none; b=RYI15q7WJJX16ZM0YT2YT0ufhmt3Ij8fy6YPvlISEpPC1tVu8HNLbaIQSFXm0wBjKMNvmgV2hZS4dWXoMibYVT8NnHXe0eB1LgQzH/zxnOYlmssFMkawnYCMn0PUzWq7xvF/vLiyRuniur1qGvzBwykELId6KCkVXpThyefWbkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008796; c=relaxed/simple; bh=orWxm+0HgDh0luacmmPqHBYqPsziQRKvdvp7XdrcWAY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=m/IPOxa4PWlEIjEL4eJX/REYJnMOzpRjrn9UGAc1taHTn++Dns5fjl3BsyJly+CHoOD29CcCpeqhSJ4rUTeUJmqethx+U8yx/Al5LbNi3+Et8zlxhgOY1O+VxJfGPNFdiut9/tCVUJkFKyOEgWFv2OK4RLpNpwL/G4/c22tFaEA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=XINUmWGS; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=GSA1f0R4; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="XINUmWGS"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GSA1f0R4" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008793; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zxPxFvYnts74EjizYrncbr+uFIPm2JowqVuGA565ZYE=; b=XINUmWGSqm3ZLtQ/RUTAc9kRwyuBaDhz68Ht45lK8O7a+9qFsBgK0e3VJnO/ziQsr57wkg Uy5bL/db4YTcTNTj46czPVkSC1L1EDE38hFhq7ZCq25UWbXzu1QYuABFdd9DTdA5SOprMT /7mOKmstaP0qAfyGENQeRz1kYM9kX3ELqf2QIpuP/af1587JnpXZJruvyBIcyECiPZx3AH EWvxMJYyqmrM+RLlqSsi/DNQ6qyTYbOx7XGW2z82ssWYJ6iqghV5YNYnRwEq+CkKkMYMpI 3JdDHxF7/DKjoLAGC1FUEAva1nUAcYOa/YeeM/HJ88dvJns4IRDC1YEQJ1u1Dg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008793; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zxPxFvYnts74EjizYrncbr+uFIPm2JowqVuGA565ZYE=; b=GSA1f0R49mBlFEqFJenZ0hBd5VDKslLpNspKQzJfMpaa5PGc8OqVqv6RUpQ+Sg+6N4c9Pp LdqCFJDpCv60JDDw== Date: Mon, 07 Apr 2025 08:52:46 +0200 Subject: [PATCH v2 23/32] tools/nolibc: add dprintf() and vdprintf() Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-23-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=1389; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=orWxm+0HgDh0luacmmPqHBYqPsziQRKvdvp7XdrcWAY=; b=zgu6bhfIbTzLSbHAGSc9RMoJXQxadrdVuWFlyKVdA8snPXsAOEQabrhfz0KG9RSCs8p02vfER LjB7FDssy2RAfBOU65TC3kuAEhXr92h+7GnqmfqdA/Qw/QEUpaT5FhL X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= dprintf() and vdprintf() are printf() variants printing directly into a filedescriptor. As FILE in nolibc is based directly on filedescriptors, the implementation is trivial. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/include/nolibc/stdio.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index b32b8b794015276ab6242c2be18f860c095f90a3..262d0da4da9062e0c83b55661b2509f36548cf88 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -351,6 +351,30 @@ int printf(const char *fmt, ...) return ret; } +static __attribute__((unused, format(printf, 2, 0))) +int vdprintf(int fd, const char *fmt, va_list args) +{ + FILE *stream; + + stream = fdopen(fd, NULL); + if (!stream) + return -1; + /* Technically 'stream' is leaked, but as it's only a wrapper around 'fd' that is fine */ + return vfprintf(stream, fmt, args); +} + +static __attribute__((unused, format(printf, 2, 3))) +int dprintf(int fd, const char *fmt, ...) +{ + va_list args; + int ret; + + va_start(args, fmt); + ret = vdprintf(fd, fmt, args); + va_end(args); + return ret; +} + static __attribute__((unused)) int vsscanf(const char *str, const char *format, va_list args) { From patchwork Mon Apr 7 06:52:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 878908 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 C08EA22CBF9; Mon, 7 Apr 2025 06:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008797; cv=none; b=iUf7pYPVN1QNQHZf2F26z0zOxfzbOxIZqlERV8JDMNnX1aAaGDr7nrB4Mn6vnC6Mh+jF70pVWbXAx/90PcQfgbF5i/ngxoHgODxvZ1wIqez0NdqUULnQSom5pDQ4uiiukVpr9i6uvM4O43iK26yKX+RE822ldoNfXdLCqkVpF0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008797; c=relaxed/simple; bh=tt5NS4cBLTbNoJ7EV6vHy54O54vj6AeymCsD10sDXy0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AUvXGo0huyP5OA/mjXgaTNE2SmA7DjCz2heH1LNw0Cn2RnSP2L9vHtTQMnP+BsDeF1CId/Mtoz0M62S/VAHCVU35m4Ui6pYYr6Ic/afR9BAz2TNP+320X31540RrqKyqRXg4QBMRhDjteXsU6LhvludCO6/bAhtgTJkKlmy4h60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cabcOXmZ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=9BhbHd0s; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cabcOXmZ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="9BhbHd0s" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008794; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2u19rqjC1rYwxFvMglNkhCFpgxOoiJO9w3f9eDb1mvo=; b=cabcOXmZk9YOq7XN1PSQx2o9bgs7u+tx2aYHCPHeMBQpKYnF0zk68ssaXbNENl1Dt4WVGL jZDKe/difepVa0ekrPPZEkN/NY4ZY9cd5bo+81yRPYbgGHM3QPJonWLCKI5eyslGVII2kS 0a6H6VrJroNGtDvBApe+fz+QiuvVMhZJa6qZ3Pi1I5CmXBDaPBYc6cvv8YR3t9Llu6ayIJ JlgJycG7QvfSnYvVOH+iCWf50IfUrRVli3o3YhKX65dJ/xhlMebW/If1ZeUEYk1eAeljbB gG4kL84jDGynnetCaKPMmTh6jl4hEzvlBff5IjDh5Jvzb0kJeFwDvpluaSozkw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008794; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2u19rqjC1rYwxFvMglNkhCFpgxOoiJO9w3f9eDb1mvo=; b=9BhbHd0sLMuS+UtiV4owJ2ZJ1bxgy/9DLD/6vVMjy3zWNYnPawW2LRkV1eBhB3NCC6cYg0 jJssi8LutzO4qlDA== Date: Mon, 07 Apr 2025 08:52:47 +0200 Subject: [PATCH v2 24/32] tools/nolibc: add getopt() Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-24-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=3808; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=tt5NS4cBLTbNoJ7EV6vHy54O54vj6AeymCsD10sDXy0=; b=LRL2J5pb4wAWcxHeNVNEvKmL9deo7/Ny/Vj8QxpZmPcTEQobICspcxBRFrmX8yljcYemA2QOz znzzAOHX/JfCMXPLoMk1f/MnrmLqddspPwdmdXLtaKSawpqkFwZejaT X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Introduce a getopt() implementation based on the one from musl. The only deviations are adaption to the kernel coding style and nolibc infrastructure and removal of multi-byte support. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/getopt.h | 101 ++++++++++++++++++++++++++++++++++++++++++ tools/include/nolibc/nolibc.h | 1 + 3 files changed, 103 insertions(+) diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index f9702877ac21ab5ad30df1740e40e67f477f3824..e47e1607bab82f1d91effc025c9257e8a451f047 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -31,6 +31,7 @@ all_files := \ ctype.h \ dirent.h \ errno.h \ + getopt.h \ limits.h \ nolibc.h \ signal.h \ diff --git a/tools/include/nolibc/getopt.h b/tools/include/nolibc/getopt.h new file mode 100644 index 0000000000000000000000000000000000000000..5fd06c9702e96e8c58a6b242f535bca09db69343 --- /dev/null +++ b/tools/include/nolibc/getopt.h @@ -0,0 +1,101 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * getopt function definitions for NOLIBC, adapted from musl libc + * Copyright (C) 2005-2020 Rich Felker, et al. + * Copyright (C) 2025 Thomas Weißschuh + */ + +#ifndef _NOLIBC_GETOPT_H +#define _NOLIBC_GETOPT_H + +struct FILE; +static struct FILE *const stderr; +static int fprintf(struct FILE *stream, const char *fmt, ...); + +__attribute__((weak,unused,section(".data.nolibc_getopt"))) +char *optarg; + +__attribute__((weak,unused,section(".data.nolibc_getopt"))) +int optind = 1, opterr = 1, optopt; + +static __attribute__((unused)) +int getopt(int argc, char * const argv[], const char *optstring) +{ + static int __optpos; + int i; + char c, d; + char *optchar; + + if (!optind) { + __optpos = 0; + optind = 1; + } + + if (optind >= argc || !argv[optind]) + return -1; + + if (argv[optind][0] != '-') { + if (optstring[0] == '-') { + optarg = argv[optind++]; + return 1; + } + return -1; + } + + if (!argv[optind][1]) + return -1; + + if (argv[optind][1] == '-' && !argv[optind][2]) + return optind++, -1; + + if (!__optpos) + __optpos++; + c = argv[optind][__optpos]; + optchar = argv[optind] + __optpos; + __optpos++; + + if (!argv[optind][__optpos]) { + optind++; + __optpos = 0; + } + + if (optstring[0] == '-' || optstring[0] == '+') + optstring++; + + i = 0; + d = 0; + do { + d = optstring[i++]; + } while (d && d != c); + + if (d != c || c == ':') { + optopt = c; + if (optstring[0] != ':' && opterr) + fprintf(stderr, "%s: unrecognized option: %c\n", argv[0], *optchar); + return '?'; + } + if (optstring[i] == ':') { + optarg = 0; + if (optstring[i + 1] != ':' || __optpos) { + optarg = argv[optind++]; + if (__optpos) + optarg += __optpos; + __optpos = 0; + } + if (optind > argc) { + optopt = c; + if (optstring[0] == ':') + return ':'; + if (opterr) + fprintf(stderr, "%s: option requires argument: %c\n", + argv[0], *optchar); + return '?'; + } + } + return c; +} + +/* make sure to include all global symbols */ +#include "nolibc.h" + +#endif /* _NOLIBC_GETOPT_H */ diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h index 70872401aca8d5aa37b12ee585193353f692576d..187490535d1359aff371e2981118e62bcc0c6948 100644 --- a/tools/include/nolibc/nolibc.h +++ b/tools/include/nolibc/nolibc.h @@ -105,6 +105,7 @@ #include "time.h" #include "stackprotector.h" #include "dirent.h" +#include "getopt.h" /* Used by programs to avoid std includes */ #define NOLIBC From patchwork Mon Apr 7 06:52:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 879543 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 E547722D4C5; Mon, 7 Apr 2025 06:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008797; cv=none; b=CRcEevP4skrDornngnCrag+3Tq+WOpcsWoWE2caobb7cqsZtBrE3TPA7jd3LNRw46ioc688mMrRJGPOaIrpCJmhG0NpacafSuEnnCKr2ZnQKX+rsPp1uqTnXfDizmca5+fmKHaDP8E51GHkSpCGs90CjIrMFRyNYqOyt+AVEMpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008797; c=relaxed/simple; bh=P5LbQi17NAkuvW7XclFYFaQVXn+26pugbIFKqyTCxcY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=J9gHquOF8CwFJt4ecBDGEfZgn2anB/xncojdwNHCMuU800knXy5cKtIhzGWtyRBZWMSI4kv7juP59z4EkIWG3aRL8EoWSnQgQ8HwK60LEaSQgMOKHxQsQT8Lc3t1snaMrZ7l/ZQbjsho1LMZXtILvObNmGs2qmw8T1QiejqSKVA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=d2tldDAP; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=E3Bd+8Q5; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="d2tldDAP"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="E3Bd+8Q5" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008794; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2c+JQsB+d6lrmsGdRgSEPuvJuQzEcudvCh2/xlKMBJo=; b=d2tldDAPIYCnQcLVP52sjKwsLnpfmHWo1xT75iKEAPllI0mbuxw1Rd+Y1UH72TbTMSL3Fu Yw4oWz5uupDjUsMrv2/8RcpoqItgVaVW+tHTxiTIh/ccQZn63C2UDlciG+BlxfthNz3DGa XPN44y6MryF3sE3uisTgzbcUiPR7KjbgD08w0B3TNH2M3Z1eAFNgLtoKpt7DnQJgjDyK// Z+IMpjlmbUNDHqh+DE/JeXEZUXPNGepmKaqb1BIvnpeocsOqwWlB9j3expslZmRIK6gVob N48TzCgfoYWPx5dE3VuJd4IKYD1qKlYiXm/vTSaVHdGFkgAXSdxO48TKY37aDA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008794; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2c+JQsB+d6lrmsGdRgSEPuvJuQzEcudvCh2/xlKMBJo=; b=E3Bd+8Q5TLDEfKE66jrqrK4uiHx/3LbqHw0pDINFbcABRs6oILNcBljJrDq9tW7O35LKgR 4YkuQ8Ju8fZpsYBg== Date: Mon, 07 Apr 2025 08:52:48 +0200 Subject: [PATCH v2 25/32] tools/nolibc: allow different write callbacks in printf Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-25-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=2074; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=P5LbQi17NAkuvW7XclFYFaQVXn+26pugbIFKqyTCxcY=; b=Qg2kFVCMiqHSu0omQmWo/1dZsvVcHgSqeo89NnyviD/hhXSFAnBy8jInEYZPeYYoQn6FjObZ0 w64cIZLo/qAAieO4b4fOuELoX4oSCy0vsWLqqKRbLa3IOfPS9unXeS9 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Decouple the formatting logic from the writing logic to later enable writing straight to a buffer in sprintf(). Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/include/nolibc/stdio.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index 262d0da4da9062e0c83b55661b2509f36548cf88..5c893b4903a3040a366e11b600ccde30913d7db2 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -208,13 +208,15 @@ char *fgets(char *s, int size, FILE *stream) } -/* minimal vfprintf(). It supports the following formats: +/* minimal printf(). It supports the following formats: * - %[l*]{d,u,c,x,p} * - %s * - unknown modifiers are ignored. */ -static __attribute__((unused, format(printf, 2, 0))) -int vfprintf(FILE *stream, const char *fmt, va_list args) +typedef int (*__nolibc_printf_cb)(intptr_t state, const char *buf, size_t size); + +static __attribute__((unused, format(printf, 3, 0))) +int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, const char *fmt, va_list args) { char escape, lpref, c; unsigned long long v; @@ -304,7 +306,7 @@ int vfprintf(FILE *stream, const char *fmt, va_list args) outstr = fmt; len = ofs - 1; flush_str: - if (_fwrite(outstr, len, stream) != 0) + if (cb(state, outstr, len) != 0) break; written += len; @@ -321,6 +323,17 @@ int vfprintf(FILE *stream, const char *fmt, va_list args) return written; } +static int __nolibc_fprintf_cb(intptr_t state, const char *buf, size_t size) +{ + return _fwrite(buf, size, (FILE *)state); +} + +static __attribute__((unused, format(printf, 2, 0))) +int vfprintf(FILE *stream, const char *fmt, va_list args) +{ + return __nolibc_printf(__nolibc_fprintf_cb, (intptr_t)stream, fmt, args); +} + static __attribute__((unused, format(printf, 1, 0))) int vprintf(const char *fmt, va_list args) { From patchwork Mon Apr 7 06:52:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 879542 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 6FBC822D4DB; Mon, 7 Apr 2025 06:53:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008798; cv=none; b=XdP8Js+qfIR466dgD/7nBQvPFJaJgHhSUiHwswfwRI1MqBCl2M6Kv5CB/j9BF5a9hxHx+xuQkwsESaGRCq3pSKUAOgqNkvGBA8Z+FE2dtOhnosWFpeS5KTAo0/U2VIlVUcblMy0zU+JW2nAV9Ld1eSxRMkbQpNI/IIXxnSMAEL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008798; c=relaxed/simple; bh=HtVJce/zltJfmoUxHSGByH8pfwgO3OfNF4RtzIB7sOk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eIYWU2+x9gnUxUT/blrgHdr7LC+MCTodQOHjptlg98poK9rBDSSj/oZguy9+l5AUpbRiON2UEyQ/oLOiwY55esqmBSPQsS/b8CGoGt9CP4GIU5XmQsIm1rZGGZf+LZ5u3I1yz5QLRgQ0cSkpzyiTiEFUDcTGDwpJG+ybh0h4fqs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=LjKZNFeK; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=LG3JWloy; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LjKZNFeK"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LG3JWloy" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008795; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pvBGqGX78XvKEVW6i13ta4x/bQjOWTVre+e55nvMR/A=; b=LjKZNFeKaT5zlIG0HQqN+TdGrfIZkHYq+m9pS6BXEA1IZ946yhU1d9QUuiV+FKg9wcFeeA y+KrTekmnLlsHN9fDld0c1OKCK+VXLaeEVCYoDUP8Uy2NLuJRcx3xC51ycXVj1NaCzn2r7 ou5tCsXzZVZRhdNYyYDM0u6YVuHXX2RB5zCdR/bnaZa94ENPxkZxbQBFE1eSnDgMMuizZy AunHcxoAOZXzqhlIOuLVueyXihf05dq1FGAgGLFxq/SJ8Vx+IzJoju9flVpvi2Xqws4mB7 JmagNIe3R5aupFsg9RZlxaVOOqqOFDdPKgMn3S5xL8bl7tKAN2cTsXRnZI6zVA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008795; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pvBGqGX78XvKEVW6i13ta4x/bQjOWTVre+e55nvMR/A=; b=LG3JWloykDvoRMJEKshLOVrrzK6rE2Tx/36yZrKqYlpCXI0ckO72s21bTvnwcXQlScR0Db BoWibW9NDiiS7oAw== Date: Mon, 07 Apr 2025 08:52:49 +0200 Subject: [PATCH v2 26/32] tools/nolibc: allow limiting of printf destination size Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-26-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=2100; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=HtVJce/zltJfmoUxHSGByH8pfwgO3OfNF4RtzIB7sOk=; b=IqgTPpO3PWnUMN4VmPuep8LFP/X0mBYJeu1nuF5O9IQhGCEnuk4jDyCNBDcwdzqaacw/3ljjX YdrUmm3BSikDE7XGyiTwRvMH1lTnDW8LogMKafJh/1w2cEAoA7Vao4I X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= snprintf() allows limiting the output buffer, while still returning the number of all bytes that would have been written. Implement the limitation logic in preparation for snprintf(). Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/include/nolibc/stdio.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index 5c893b4903a3040a366e11b600ccde30913d7db2..b17b473bd8751a6283309178b4848e61e1683305 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -215,13 +215,13 @@ char *fgets(char *s, int size, FILE *stream) */ typedef int (*__nolibc_printf_cb)(intptr_t state, const char *buf, size_t size); -static __attribute__((unused, format(printf, 3, 0))) -int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, const char *fmt, va_list args) +static __attribute__((unused, format(printf, 4, 0))) +int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char *fmt, va_list args) { char escape, lpref, c; unsigned long long v; unsigned int written; - size_t len, ofs; + size_t len, ofs, w; char tmpbuf[21]; const char *outstr; @@ -306,8 +306,12 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, const char *fmt, va_l outstr = fmt; len = ofs - 1; flush_str: - if (cb(state, outstr, len) != 0) - break; + if (n) { + w = len < n ? len : n; + n -= w; + if (cb(state, outstr, w) != 0) + break; + } written += len; do_escape: @@ -331,7 +335,7 @@ static int __nolibc_fprintf_cb(intptr_t state, const char *buf, size_t size) static __attribute__((unused, format(printf, 2, 0))) int vfprintf(FILE *stream, const char *fmt, va_list args) { - return __nolibc_printf(__nolibc_fprintf_cb, (intptr_t)stream, fmt, args); + return __nolibc_printf(__nolibc_fprintf_cb, (intptr_t)stream, SIZE_MAX, fmt, args); } static __attribute__((unused, format(printf, 1, 0))) From patchwork Mon Apr 7 06:52:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 878906 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 4AFA122D7B1; Mon, 7 Apr 2025 06:53:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008800; cv=none; b=Ka0fy3WtFioxsPk8eUVL2zY6JUGIK1H1NTXTBYi9+Pqsqhtz9y2+MXDmnxrWh9r0Zp6akkoVgH7HgduoT1RBeMGm0WKn1Rrb4/8HCzew1tpJoXXdll2Dzf+8MSH8dFlS5UL7jbwygNuZD76LKqAiSk3BSKeRRMPtXN8z6Wq8Hnc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008800; c=relaxed/simple; bh=kr1493r0mCxh9Smwnzq2sT4EOgraIN/H6Zk+RSFwpBw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mLZEkIJgNy3fmj+qC4bM3GUGcPCNVfy46DDVy11qmXvReu0b8RtIoaiw5jBykzcl7XxQRBEnQsRQ+wvx/jo5iBu8C/RO4IJvjaky+LAGX9xw9+u7nzaq2NLhoZn8oMzQAAnrxpbJ8NDI0M25SWxgYuj7Xyhzz/+fM23yqu6YdkQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=DaPb9ygV; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=X24OgPGa; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="DaPb9ygV"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="X24OgPGa" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008795; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R9tNYn1A7xCJCEfyuN7DqxsUEM5cT1Wf6v4wfadNgQw=; b=DaPb9ygVoceu7y23NxtPhtA/1626L9zDd6Ge4IcjV3uuQ0EG9uc6Ib0x0vNreccd0JRo5N R1BDHL3FTsBfaMDdYHMffDpYiPPBFyJYnqkbF0x4ubiuaJ97VVcb6oX2VQK4kSVsVE5mul DDWCra8q8kcd2Gz/DLDJiH8/qF13mKXl96+zo2yhH583vzKPZ/NXnul1eOzzdRl29jX/aj uegW80nPYoWn7xKUUBAFiEAB0ANfh155cTrQv3jlpsRvM8DIZP8Z3AhNUTdsU/BmWHWEaM rmKvoOwIV0vJSReBsiRXElg071AtUFscW7CxxYR+xyKYZ1NLCqNqPAmIX5+e2g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008795; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R9tNYn1A7xCJCEfyuN7DqxsUEM5cT1Wf6v4wfadNgQw=; b=X24OgPGaw6uBBnj+2v9K590oczvbjqMFJvA9AKQ+CFLgExmmscTruzMxX6ZIxspAejPle8 eqf8O8YU0Xqz+6AQ== Date: Mon, 07 Apr 2025 08:52:50 +0200 Subject: [PATCH v2 27/32] tools/nolibc: add snprintf() and friends Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-27-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=1911; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=kr1493r0mCxh9Smwnzq2sT4EOgraIN/H6Zk+RSFwpBw=; b=T169iwSDEAw6NBOfISyp8FfGy70pTOpo2d0vbbH4ooZWXmB2gSDkpeRZS7m3SVrgxlcN+2R+s GKaaqWzQRNRDEC3ug+KAPNi8BwbFnGRewrekivT5jyR6DvLMlgmIcZu X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Add more of the printf() functions. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/include/nolibc/stdio.h | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index b17b473bd8751a6283309178b4848e61e1683305..46bd90f96d654fadda20292baddc98358a3afc62 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -389,6 +389,61 @@ int dprintf(int fd, const char *fmt, ...) va_start(args, fmt); ret = vdprintf(fd, fmt, args); va_end(args); + + return ret; +} + +static int __nolibc_sprintf_cb(intptr_t _state, const char *buf, size_t size) +{ + char **state = (char **)_state; + + memcpy(*state, buf, size); + *state += size; + return 0; +} + +static __attribute__((unused, format(printf, 3, 0))) +int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) +{ + char *state = buf; + int ret; + + ret = __nolibc_printf(__nolibc_sprintf_cb, (intptr_t)&state, size, fmt, args); + if (ret < 0) + return ret; + buf[(size_t)ret < size ? (size_t)ret : size - 1] = '\0'; + return ret; +} + +static __attribute__((unused, format(printf, 3, 4))) +int snprintf(char *buf, size_t size, const char *fmt, ...) +{ + va_list args; + int ret; + + va_start(args, fmt); + ret = vsnprintf(buf, size, fmt, args); + va_end(args); + + return ret; +} + +static __attribute__((unused, format(printf, 2, 0))) +int vsprintf(char *buf, const char *fmt, va_list args) +{ + return vsnprintf(buf, SIZE_MAX, fmt, args); +} + +static __attribute__((unused, format(printf, 2, 3))) +int sprintf(char *buf, const char *fmt, ...) +{ + va_list args; + int ret; + + va_start(args, fmt); + ret = vsprintf(buf, fmt, args); + va_end(args); + return ret; } From patchwork Mon Apr 7 06:52:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 878907 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 7CEAB22CBE2; Mon, 7 Apr 2025 06:53:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008799; cv=none; b=qRs/A3Q9exIgcK3Wfw4asq6wItBAm/Hjc6TRu3eWF3tV9nn4lcpLlQk7+47QoRKKQ3Xal8RsHN+zxvN/GPsvoLkzA9jGYu3KothsOOInpPP8kgL1b31+fHS2YUa4c5SwUYq5pnvjqRLzaAHnDs8EikdAG76tJ8ONjLoOBN7LJIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008799; c=relaxed/simple; bh=MN6AkwH7M04l/Z4uzha4BvhmgdSGZ7J563KtStfiHRc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rMzG+L7CDWBuNhOjcTc/p6k096hNbfxtj35CbwYEM3TGEVND8pJ/1aJ+6wPCKV0o8mQOiWbGcbhQN7QyY4koNhA2C0FYvQ9X1X8rjqrBnHWRzGgeZ2Ldlxe2z72cwvBFOAY1mK5lt5TEtBs4kbvTSm4qO2vqBrWmcSGc8TG/N+M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=BxVIMfeP; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ex6DkJvT; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BxVIMfeP"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ex6DkJvT" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008796; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=psPihsV7XI/HoMHLIosI4/jOkhz9urwrehOWAUKYKjE=; b=BxVIMfePCq7MiKSN3T6DPTfo4WJddcGat7+gp6i9WgBidRGQHaMxaturBsmv59fQveovtX LADQMEaGINpNolayCRp0wobv51NgdwppDRC4iHLAcsuor7aziQzEJPrtLOCdXefUz3F73F mOnamlUF4fVUChbWyXxKi8dxKiouRcmhEIlWC45NlwqYdZ4JeD0vBJrHVQPE0QRI6ZctLX CfvrczcOKqkncwtQexikl5MLWwv+Y2kfnVTUOb3zmb2kvrAzHc4iw2W8s90xIZS5wxnlyq O4Uuj4czy1SORsQClT7pmdGVwYvuEMGk5kiHLZ4thiLgDl3PtlmXdvvNOZSHFg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008796; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=psPihsV7XI/HoMHLIosI4/jOkhz9urwrehOWAUKYKjE=; b=ex6DkJvThdjAQweOSJel42sGdBop35w3/FeRsojnk/h+GHAoZAo0SahRt1J7DsNsRQx4sy R+fruN1EZJU5L9Cw== Date: Mon, 07 Apr 2025 08:52:51 +0200 Subject: [PATCH v2 28/32] selftests/nolibc: use snprintf() for printf tests Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-28-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=1769; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=MN6AkwH7M04l/Z4uzha4BvhmgdSGZ7J563KtStfiHRc=; b=6DuZnZsMm7M2fM8yoQAI8p76Temf70okFkuGrfK/aETEsEfNtUo2jQypz4gNTP46thjUBH7FB BkT0d5oKKmUCs13O0xXacId7ZVmP7tf0KjUmT5hRqrTJ3yo9ce5IFSc X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= With a proper snprintf() implementation in place, the ugly pipe usage is not necessary anymore. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/testing/selftests/nolibc/nolibc-test.c | 30 +++------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index b4b9a8422d76e1170ff967850429916a2190139b..8fb241af33cbba2ceb1303bf41582d51f70df68e 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1300,27 +1300,14 @@ int run_stdlib(int min, int max) static int expect_vfprintf(int llen, int c, const char *expected, const char *fmt, ...) { - int ret, pipefd[2]; - ssize_t w, r; char buf[100]; - FILE *memfile; va_list args; + ssize_t w; + int ret; - ret = pipe(pipefd); - if (ret == -1) { - llen += printf(" pipe() != %s", strerror(errno)); - result(llen, FAIL); - return 1; - } - - memfile = fdopen(pipefd[1], "w"); - if (!memfile) { - result(llen, FAIL); - return 1; - } va_start(args, fmt); - w = vfprintf(memfile, fmt, args); + w = vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); if (w != c) { @@ -1329,17 +1316,6 @@ static int expect_vfprintf(int llen, int c, const char *expected, const char *fm return 1; } - fclose(memfile); - - r = read(pipefd[0], buf, sizeof(buf) - 1); - - if (r != w) { - llen += printf(" written(%d) != read(%d)", (int)w, (int)r); - result(llen, FAIL); - return 1; - } - - buf[r] = '\0'; llen += printf(" \"%s\" = \"%s\"", expected, buf); ret = strncmp(expected, buf, c); From patchwork Mon Apr 7 06:52:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 879541 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 4B04A22D7B2; Mon, 7 Apr 2025 06:53:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008800; cv=none; b=DZwFg3q+ligmlmmstwqA7DNrTZHsg1c61RNSEEh2HFuZyDiXxUefPs/V6FWY3C3NlqQg9wYg436VCtwNRgbCqBO7ZDpSAiia/En6u+Vo2Qfx3y4mCtXwPiRKwME9YMApL5hVHz2l/0WxSdjThf1l1TWCVuK2/gH0J7ujWw046GI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008800; c=relaxed/simple; bh=1m4pGrKjarsVyBk2sHbIz0kz1QLrAgcqnYe0JpUbZkA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lH+RFSbNrOTijuHU66lRgzovl95GpHi7q6GvS8RKk1NTDlAPk9qQ9/RazNsVudG1XJcsq99lEm1oIZHds5GAp0U9xWnzHoRiwgLima7a9n8OZmqXeJadeN61BlQQz11FQmVcdOA2ClSQVj9VvZUGlUFy55SyHQfacEzwTb6J5nE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Mkb5WT+Y; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=QZWUTXSj; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Mkb5WT+Y"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QZWUTXSj" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008796; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0hGEGPrYAeGEEY4KfXy0LyZoEFXiYSsEkS/Ru5j/+Io=; b=Mkb5WT+YUXsT/8FtcHbecxTApa0LVrVumSyNF2ddzkoDb6a76Rqms1Ow/ee1RZjkkS+16K u6Yuk23PdLEWsYsj2NfrFboHJHncaAR+gLnjlvcoFSv80vLBhIHQN335zzdCvSGOOWextH p7GD1FYakO6AsMlZCWf4snM5GYaGiswMvyRZXkjR8hUiOQARfl2G4PC6gJApRyKYNf1MGh +ttf8h4OzWdHupbGYWNyCYPm6jA40U2fL18S61XNw5L9L7q2YCf/o2N1fbArEk8AmzcnU5 im4fjC1zoBCKMenCdUQzuON/w3kHkW+wiOgizJtLI8JNSj4RATcg0P2NlnGjYA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008796; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0hGEGPrYAeGEEY4KfXy0LyZoEFXiYSsEkS/Ru5j/+Io=; b=QZWUTXSj1lfBXo5lr71SoE9ResbdyhCYHc0UahaVHh3rWVoE/wSj6uBKtR/apJvLTvRjzD fz1vKkZdRc0ap2Bw== Date: Mon, 07 Apr 2025 08:52:52 +0200 Subject: [PATCH v2 29/32] selftests/nolibc: rename vfprintf test suite Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-29-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=1295; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=1m4pGrKjarsVyBk2sHbIz0kz1QLrAgcqnYe0JpUbZkA=; b=jK4ZmALcMJeh5JmuULzDop3M2vDXEc2vzdzs7aK+yBMOlg+bb4hg5LRVK6XDmm1oSLKmfhLXe GEaC/2qMZQADrB8p5eTQzPIgK1CmR2KtkNFvsYupfMWTzRfBg4nUvlK X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= With the addition of snprintf() and its usage in nolibc-test, the name of the "vfprintf" test suite is not accurate anymore. Rename the suite to be more generic. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/testing/selftests/nolibc/nolibc-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 8fb241af33cbba2ceb1303bf41582d51f70df68e..6dfa94df37547dae46ab19195a763fe22b065bab 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1390,7 +1390,7 @@ static int test_scanf(void) return 0; } -static int run_vfprintf(int min, int max) +static int run_printf(int min, int max) { int test; int ret = 0; @@ -1551,7 +1551,7 @@ static const struct test test_names[] = { { .name = "startup", .func = run_startup }, { .name = "syscall", .func = run_syscall }, { .name = "stdlib", .func = run_stdlib }, - { .name = "vfprintf", .func = run_vfprintf }, + { .name = "printf", .func = run_printf }, { .name = "protection", .func = run_protection }, { 0 } }; From patchwork Mon Apr 7 06:52:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 879540 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 69A5E22D7B9; Mon, 7 Apr 2025 06:53:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008800; cv=none; b=uoSDH2gKB3DmWc5vlAamwtUps/hhHi6X+GskngAWuQ2saCWSSH4n/lUt/pxjt41fwlxxHVFW7qLf1jhfGtveVxIiDE/kZfIiW/DHqyES7ToSHWcNrVjlymsgYwMcMKU/mTojwQAZcLR1dRSOa1N6s1XtTiOuTouPlT/kinovEb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008800; c=relaxed/simple; bh=8gx2j4OH7y+ey3+O8eHa4G2jocjuirJqpQ8j8E98oto=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MxMJgogTI+TwmhjVxTwAJej/E5RGJGXNJQjcA2V5zpkenaVvhkkFQ1ddl3GxE58DikR+7hj/PZVZTT0mWc9sRmEinvrjluauSAOGVyp9AKdaLQX7r2OGSHjn8Hhp2N3wz15w0Iy5BJwC2T/kE4OyAJOyWPrZimNUbC/xCxWJncE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=k6IaNKBM; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=/7BeNvxC; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="k6IaNKBM"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="/7BeNvxC" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tGncphnL/iwYpyKH8kWhkIbaBWNrCOh1asPqEQP8sdM=; b=k6IaNKBMjL8R82hCIbmOKz2Z54NT6rH6WZMazn/Njx/FYvUpHmVZlUXGMGFUPgNSayQ5lU 8W/HRKBgpzuU9aPWEDijEXKmRBeL+JdMyA1Zc206ZNM31w8vRyQISWaFC3uJTsFb+65g/R UoajDcyZpQG5w7u8wQmIFyfzt3EZ6T1JiipYsK4VXWS4yT4rcN1/0IGM6k78+wt825NLmh tzZLzNvy+acB75eVyTlT006seJCvYcQv5eYDB+MtGbuCoiBUn1/lv7+iQ9oCQ+b5elXL0N hNn2pLX7As9oV8zBkO6EV8odtSXqfDqVCfmFpJ0XJFX8z94RF+qDFpY0oeIocg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tGncphnL/iwYpyKH8kWhkIbaBWNrCOh1asPqEQP8sdM=; b=/7BeNvxCd+2GBts2slRFBZ+gX7MSP8fHsKeDu9dkIJ/kALR2DyEGuWJMsP9hIpxjelws50 DrpPRU5b2FwmSBCQ== Date: Mon, 07 Apr 2025 08:52:53 +0200 Subject: [PATCH v2 30/32] selftests/nolibc: add test for snprintf() truncation Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-30-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=1552; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=8gx2j4OH7y+ey3+O8eHa4G2jocjuirJqpQ8j8E98oto=; b=BhC7h+puBd4O9DmWI8gn+gRsb3fFR4Thhp6iWt+25q3//CLAwF5mxhioFtd2wZjVxnsWdje2X MPTX7bEuAYoDo/mXkYN4DgF6Wx3imMzkyHdZUs6sH+VEG6HEZ1ASbi3 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Now that we have a proper snprintf() implementation, make sure truncation is handled properly. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/testing/selftests/nolibc/nolibc-test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 6dfa94df37547dae46ab19195a763fe22b065bab..9bd0a9c68b903cbd660ff81d4b0386b0b7c13977 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1307,7 +1307,8 @@ static int expect_vfprintf(int llen, int c, const char *expected, const char *fm va_start(args, fmt); - w = vsnprintf(buf, sizeof(buf), fmt, args); + /* Only allow writing 21 bytes, to test truncation */ + w = vsnprintf(buf, 21, fmt, args); va_end(args); if (w != c) { @@ -1413,6 +1414,7 @@ static int run_printf(int min, int max) CASE_TEST(pointer); EXPECT_VFPRINTF(3, "0x1", "%p", (void *) 0x1); break; CASE_TEST(uintmax_t); EXPECT_VFPRINTF(20, "18446744073709551615", "%ju", 0xffffffffffffffffULL); break; CASE_TEST(intmax_t); EXPECT_VFPRINTF(20, "-9223372036854775807", "%jd", 0x8000000000000001LL); break; + CASE_TEST(truncation); EXPECT_VFPRINTF(25, "01234567890123456789", "%s", "0123456789012345678901234"); break; CASE_TEST(scanf); EXPECT_ZR(1, test_scanf()); break; case __LINE__: return ret; /* must be last */ From patchwork Mon Apr 7 06:52:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 878905 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 E0005225784; Mon, 7 Apr 2025 06:53:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008800; cv=none; b=It6Zq+pxb8fuol7/C+hpEU4gYIEUwI0URaNXGWVZv4U750BsbEmHkBCTRH+T+pCgOfKjPXU30jPttSMD6W0kcMjDVhea4dMW3ANAAkOChyDK99Ej4o7gvlNk2v/+m1vCzIiVFokwmPbRdjlUpdrPIxP5a5zqSCkK1+Xpgat4U0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008800; c=relaxed/simple; bh=4PWMuyjdFGi/rGm+eh3+GEBgJVFiFZN51q5MAPLIuoQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=vEWIqAndMlbyxCdOn8u8ZgCdQRioo3fGnwsFXr5JRuJPJ4RDDhn181nZ4ckXQbj0greYmV3h6DMmZpGhWe9oV1fEPBNgYjmFz3+VSy16P7WRQK3rLyWrAHFYQExr6zVrTgGTucajApmRbmsGlD3RRHV6NMMAgWWRk4YxESLWRtw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=X5dQqlsB; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Q+srFaGl; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="X5dQqlsB"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Q+srFaGl" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WupVzBzhpR9wEE1wxtcIpqdyGm1uGqU4Sj1sAih5bIM=; b=X5dQqlsB2qejMY5VwwQrIGL7uQuxqOxjboziLRreUAeXK0A+I0I/uvkc5+WjC//9a0nT2p eG5Ks1JqYx0xB8P1iLdH55RwXyTJqe6BOpj7Q8WwG0kAchkpJRONqXNbdpEyHhlJ6LDjP2 H1Q9w/JRNSGEhFkiu4zWncnlp9bZz9QzZb7X6jCnsk+dI/dov6pHYbuvuLI6DY8cF5IF+H 2zgix4LziP+vFL+KhuUr26AefZq5PJDYBDuD7YXGbH2bS/wZDHOsw+neNUaUpXymH1VgDN krogqRDE0q0V1+EovLIX8n1o743FxpVErf5WuvwXspOvdZSYELI3w3NMM9Qq5A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WupVzBzhpR9wEE1wxtcIpqdyGm1uGqU4Sj1sAih5bIM=; b=Q+srFaGlhXFsvsBtvQ0hUpNowVQiTUCA7hKkS2XhacfQbJuTxWjRD45INjwrQ7bu9NsatC MmBHclYib3kaXuBA== Date: Mon, 07 Apr 2025 08:52:54 +0200 Subject: [PATCH v2 31/32] tools/nolibc: implement width padding in printf() Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-31-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=2908; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=4PWMuyjdFGi/rGm+eh3+GEBgJVFiFZN51q5MAPLIuoQ=; b=TJ90SRsc2feIExru4VXFrumYdLrrO7jtqgIU4tDVzCdQpxyG9QTl8b1REeXRTplAa9OkknO0G DscsRnUhMgbBf/LggjenAALK0oHHfPS5EF4qqBG+HBI74drrMCDbPjj X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= printf can pad each argument to a certain width. Implement this for compatibility with the kselftest harness. Currently only padding with spaces is supported. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau --- tools/include/nolibc/stdio.h | 17 ++++++++++++++++- tools/testing/selftests/nolibc/nolibc-test.c | 3 +++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index 46bd90f96d654fadda20292baddc98358a3afc62..fb0417477759ee6c9663e84807c1d1067e735dec 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -220,7 +220,7 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char { char escape, lpref, c; unsigned long long v; - unsigned int written; + unsigned int written, width; size_t len, ofs, w; char tmpbuf[21]; const char *outstr; @@ -228,10 +228,20 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char written = ofs = escape = lpref = 0; while (1) { c = fmt[ofs++]; + width = 0; if (escape) { /* we're in an escape sequence, ofs == 1 */ escape = 0; + + /* width */ + while (c >= '0' && c <= '9') { + width *= 10; + width += c - '0'; + + c = fmt[ofs++]; + } + if (c == 'c' || c == 'd' || c == 'u' || c == 'x' || c == 'p') { char *out = tmpbuf; @@ -309,6 +319,11 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char if (n) { w = len < n ? len : n; n -= w; + while (width-- > w) { + if (cb(state, " ", 1) != 0) + break; + written += 1; + } if (cb(state, outstr, w) != 0) break; } diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 9bd0a9c68b903cbd660ff81d4b0386b0b7c13977..16ec4f658bbec43440679c5d5c35014827c377bc 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1415,6 +1415,9 @@ static int run_printf(int min, int max) CASE_TEST(uintmax_t); EXPECT_VFPRINTF(20, "18446744073709551615", "%ju", 0xffffffffffffffffULL); break; CASE_TEST(intmax_t); EXPECT_VFPRINTF(20, "-9223372036854775807", "%jd", 0x8000000000000001LL); break; CASE_TEST(truncation); EXPECT_VFPRINTF(25, "01234567890123456789", "%s", "0123456789012345678901234"); break; + CASE_TEST(string_width); EXPECT_VFPRINTF(10, " 1", "%10s", "1"); break; + CASE_TEST(number_width); EXPECT_VFPRINTF(10, " 1", "%10d", 1); break; + CASE_TEST(width_trunc); EXPECT_VFPRINTF(25, " ", "%25d", 1); break; CASE_TEST(scanf); EXPECT_ZR(1, test_scanf()); break; case __LINE__: return ret; /* must be last */ From patchwork Mon Apr 7 06:52:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 879539 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 9369422DFA7; Mon, 7 Apr 2025 06:53:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008803; cv=none; b=f4qlQBn2OHjmWwgNz6Wne9HH2qGNWalHE6WGhVzkZYlCfNeMB/bS2P4R/loDHYeTGg+CYfc/UpAwgrlzSkYxth7TsDTCUGO3++h1PkoI7UrvFW840PAm0VvW4CYLMrj4sSSOkTWSaQWJWNZfIBfJxdK/8C7ACdtLnj8TiqD0TyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744008803; c=relaxed/simple; bh=t4cdn751b8ZL/EBwPtgZ0Wccis+025xK4yp9qeVhNFk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LG+R1qN+Ein/IWto5Vq5slkvy5jnekmtG2z6RvBqzlF9NHoglmQhYA93L18uiQ3Tb+IJ0GAAUPrdzIkaDpJncwlhu1c77j1mA6nrC6vVF6L8ZaOewaoneAJWfxUJDxtL5MDaDXAbHkvmrfwc9uTqP6xbyRkWgqzw+k7XiKYhf5A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dYERS1AX; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=a6Ee2mgF; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dYERS1AX"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="a6Ee2mgF" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744008798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k8DW5l20ktp/sLUwR9pTBXowTMQFjcb1kK9a1ZiD1bs=; b=dYERS1AXZVMW4oEbZRLhwRFoFYnkcpcZz73bt7F/PgsHxPzVAf37l3TILVLAeh5Ppk+IhW T+dQSrlf3JYRMRX0moRoVFDBB1TChKIpmsrxR+F3ojV6/k/6k1dS4v1FS7FDT0x5J8XmaR Ma/H9JZnAbVjwS/zo+RJfEoPNejyjCQQpLOAdQfxAgjbm/gzPzWk0Hyrl4srLF9K5wp0Rt s00nKoszdtwy4Tjw3xiUUUeeb/cKBmGShkbbNj8J7IeJ1IjYRtWixfMz7Tz7chPBOZXHC+ ERkerkRSRQsYQ1MokTrMBEYBY6qfMbDQpXWHTmxfX/HuvNY7KJjTn+5zI1aTGg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744008798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k8DW5l20ktp/sLUwR9pTBXowTMQFjcb1kK9a1ZiD1bs=; b=a6Ee2mgFJ2TAfZ96XWs76inhn2AqV7F6iRJ5t7PVZN1sMv0NYjqEmMrQ+v0GyGP9MUZ/XC CEkrmy5ghGEDrgCg== Date: Mon, 07 Apr 2025 08:52:55 +0200 Subject: [PATCH v2 32/32] HACK: selftests/nolibc: demonstrate usage of the kselftest harness Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-nolibc-kselftest-harness-v2-32-f8812f76e930@linutronix.de> References: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> In-Reply-To: <20250407-nolibc-kselftest-harness-v2-0-f8812f76e930@linutronix.de> To: Shuah Khan , Shuah Khan , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1744008776; l=61263; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=t4cdn751b8ZL/EBwPtgZ0Wccis+025xK4yp9qeVhNFk=; b=B+7IsZleinS6gQKX6XmGskADKLZ5wvogFqhJDjikcIB8A4O4iwWAefonIeUqekBdN4gH/glGo RHOmLu+Kj7mAQ66Vb8ilk563LSlKlOn+yFrTOM7YBWWM5KftTFveS9h X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Show how to use the kselftest harness together with nolibc. This just runs the existing harness selftest by crudely replacing the regular nolibc-test.c with the harness-selftest.c to get that wired up easily. To use it: $ cd tools/testing/selftests/nolibc/ $ ./run-tests -m user In the future nolibc-test can use the harness for itself. Not-Signed-off-by: Thomas Weißschuh --- .../testing/selftests/kselftest/harness-selftest.c | 2 +- tools/testing/selftests/nolibc/Makefile | 13 +- tools/testing/selftests/nolibc/harness-selftest.c | 1 + tools/testing/selftests/nolibc/nolibc-test.c | 1715 +------------------- tools/testing/selftests/nolibc/run-tests.sh | 2 +- 5 files changed, 11 insertions(+), 1722 deletions(-) diff --git a/tools/testing/selftests/kselftest/harness-selftest.c b/tools/testing/selftests/kselftest/harness-selftest.c index 8d39e7a0b99c41a5d33edfe2dbf875cac04c098d..bbb2fda7042ca8bac608625e6f4302466b23f7b3 100644 --- a/tools/testing/selftests/kselftest/harness-selftest.c +++ b/tools/testing/selftests/kselftest/harness-selftest.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +/* SPDX-License-Identifier: GPL-2.0 */ #include diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile index 58bcbbd029bc3ad9ccac968191b703ccf5df0717..7c037fb3f3c8d8e510cf8a6e80fcd11f0ec3538c 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -165,8 +165,8 @@ Q=@ endif CFLAGS_i386 = $(call cc-option,-m32) -CFLAGS_arm = -marm -CFLAGS_armthumb = -mthumb -march=armv6t2 +CFLAGS_arm = -marm -march=armv7-a +CFLAGS_armthumb = -mthumb -march=armv7 CFLAGS_ppc = -m32 -mbig-endian -mno-vsx $(call cc-option,-mmultiple) CFLAGS_ppc64 = -m64 -mbig-endian -mno-vsx $(call cc-option,-mmultiple) CFLAGS_ppc64le = -m64 -mlittle-endian -mno-vsx $(call cc-option,-mabi=elfv2) @@ -175,8 +175,10 @@ CFLAGS_s390 = -m31 CFLAGS_mips32le = -EL -mabi=32 -fPIC CFLAGS_mips32be = -EB -mabi=32 CFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all)) -CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra \ +CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra -ggdb -ffreestanding \ + -ffile-prefix-map=./= \ $(call cc-option,-fno-stack-protector) $(call cc-option,-Wmissing-prototypes) \ + $(call cc-option,-mno-outline-atomics) \ $(CFLAGS_$(XARCH)) $(CFLAGS_STACKPROTECTOR) $(CFLAGS_EXTRA) LDFLAGS := @@ -193,10 +195,7 @@ include $(srctree)/tools/scripts/Makefile.include # GCC uses "s390", clang "systemz" CLANG_CROSS_FLAGS := $(subst --target=s390-linux,--target=systemz-linux,$(CLANG_CROSS_FLAGS)) -REPORT ?= awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{if (!f) printf("\n"); f++; print;} /\[SKIPPED\][\r]*$$/{s++} \ - END{ printf("\n%3d test(s): %3d passed, %3d skipped, %3d failed => status: ", p+s+f, p, s, f); \ - if (f || !p) printf("failure\n"); else if (s) printf("warning\n"); else printf("success\n");; \ - printf("\nSee all results in %s\n", ARGV[1]); }' +REPORT = sed -i -e '/^\[/d' -e 's/\x0d//' run.out; cmp ../kselftest/harness-selftest.expected run.out && echo ok; true help: @echo "Supported targets under selftests/nolibc:" diff --git a/tools/testing/selftests/nolibc/harness-selftest.c b/tools/testing/selftests/nolibc/harness-selftest.c new file mode 120000 index 0000000000000000000000000000000000000000..847b121e60482513cd0911422cfdb19bdf681bd6 --- /dev/null +++ b/tools/testing/selftests/nolibc/harness-selftest.c @@ -0,0 +1 @@ +../kselftest/harness-selftest.c \ No newline at end of file diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 16ec4f658bbec43440679c5d5c35014827c377bc..9a074d2b24c99d86bf27f8399f2e7dc719dbcd24 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1,1716 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0 */ -#define _GNU_SOURCE -#define _LARGEFILE64_SOURCE +#define inline __inline__ -/* libc-specific include files - * The program may be built in 3 ways: - * $(CC) -nostdlib -include /path/to/nolibc.h => NOLIBC already defined - * $(CC) -nostdlib -I/path/to/nolibc/sysroot => _NOLIBC_* guards are present - * $(CC) with default libc => NOLIBC* never defined - */ -#ifndef NOLIBC -#include -#include -#include -#ifndef _NOLIBC_STDIO_H -/* standard libcs need more includes */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#endif -#endif - -#pragma GCC diagnostic ignored "-Wmissing-prototypes" - -#include "nolibc-test-linkage.h" - -/* for the type of int_fast16_t and int_fast32_t, musl differs from glibc and nolibc */ -#define SINT_MAX_OF_TYPE(type) (((type)1 << (sizeof(type) * 8 - 2)) - (type)1 + ((type)1 << (sizeof(type) * 8 - 2))) -#define SINT_MIN_OF_TYPE(type) (-SINT_MAX_OF_TYPE(type) - 1) - -/* will be used to test initialization of environ */ -static char **test_envp; - -/* will be used to test initialization of argv */ -static char **test_argv; - -/* will be used to test initialization of argc */ -static int test_argc; - -/* will be used by some test cases as readable file, please don't write it */ -static const char *argv0; - -/* will be used by constructor tests */ -static int constructor_test_value; - -static const int is_nolibc = -#ifdef NOLIBC - 1 -#else - 0 -#endif -; - -/* definition of a series of tests */ -struct test { - const char *name; /* test name */ - int (*func)(int min, int max); /* handler */ -}; - -#ifndef _NOLIBC_STDLIB_H -char *itoa(int i) -{ - static char buf[12]; - int ret; - - ret = snprintf(buf, sizeof(buf), "%d", i); - return (ret >= 0 && ret < sizeof(buf)) ? buf : "#err"; -} -#endif - -#define CASE_ERR(err) \ - case err: return #err - -/* returns the error name (e.g. "ENOENT") for common errors, "SUCCESS" for 0, - * or the decimal value for less common ones. - */ -static const char *errorname(int err) -{ - switch (err) { - case 0: return "SUCCESS"; - CASE_ERR(EPERM); - CASE_ERR(ENOENT); - CASE_ERR(ESRCH); - CASE_ERR(EINTR); - CASE_ERR(EIO); - CASE_ERR(ENXIO); - CASE_ERR(E2BIG); - CASE_ERR(ENOEXEC); - CASE_ERR(EBADF); - CASE_ERR(ECHILD); - CASE_ERR(EAGAIN); - CASE_ERR(ENOMEM); - CASE_ERR(EACCES); - CASE_ERR(EFAULT); - CASE_ERR(ENOTBLK); - CASE_ERR(EBUSY); - CASE_ERR(EEXIST); - CASE_ERR(EXDEV); - CASE_ERR(ENODEV); - CASE_ERR(ENOTDIR); - CASE_ERR(EISDIR); - CASE_ERR(EINVAL); - CASE_ERR(ENFILE); - CASE_ERR(EMFILE); - CASE_ERR(ENOTTY); - CASE_ERR(ETXTBSY); - CASE_ERR(EFBIG); - CASE_ERR(ENOSPC); - CASE_ERR(ESPIPE); - CASE_ERR(EROFS); - CASE_ERR(EMLINK); - CASE_ERR(EPIPE); - CASE_ERR(EDOM); - CASE_ERR(ERANGE); - CASE_ERR(ENOSYS); - CASE_ERR(EOVERFLOW); - default: - return itoa(err); - } -} - -static void align_result(size_t llen) -{ - const size_t align = 64; - char buf[align]; - size_t n; - - if (llen >= align) - return; - - n = align - llen; - memset(buf, ' ', n); - buf[n] = '\0'; - fputs(buf, stdout); -} - -enum RESULT { - OK, - FAIL, - SKIPPED, -}; - -static void result(int llen, enum RESULT r) -{ - const char *msg; - - if (r == OK) - msg = " [OK]"; - else if (r == SKIPPED) - msg = "[SKIPPED]"; - else - msg = " [FAIL]"; - - align_result(llen); - puts(msg); -} - -/* The tests below are intended to be used by the macroes, which evaluate - * expression , print the status to stdout, and update the "ret" - * variable to count failures. The functions themselves return the number - * of failures, thus either 0 or 1. - */ - -#define EXPECT_ZR(cond, expr) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_zr(expr, llen); } while (0) - -static __attribute__((unused)) -int expect_zr(int expr, int llen) -{ - int ret = !(expr == 0); - - llen += printf(" = %d ", expr); - result(llen, ret ? FAIL : OK); - return ret; -} - - -#define EXPECT_NZ(cond, expr, val) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_nz(expr, llen; } while (0) - -static __attribute__((unused)) -int expect_nz(int expr, int llen) -{ - int ret = !(expr != 0); - - llen += printf(" = %d ", expr); - result(llen, ret ? FAIL : OK); - return ret; -} - - -#define EXPECT_EQ(cond, expr, val) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_eq(expr, llen, val); } while (0) - -static __attribute__((unused)) -int expect_eq(uint64_t expr, int llen, uint64_t val) -{ - int ret = !(expr == val); - - llen += printf(" = %lld ", (long long)expr); - result(llen, ret ? FAIL : OK); - return ret; -} - - -#define EXPECT_NE(cond, expr, val) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ne(expr, llen, val); } while (0) - -static __attribute__((unused)) -int expect_ne(int expr, int llen, int val) -{ - int ret = !(expr != val); - - llen += printf(" = %d ", expr); - result(llen, ret ? FAIL : OK); - return ret; -} - - -#define EXPECT_GE(cond, expr, val) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ge(expr, llen, val); } while (0) - -static __attribute__((unused)) -int expect_ge(int expr, int llen, int val) -{ - int ret = !(expr >= val); - - llen += printf(" = %d ", expr); - result(llen, ret ? FAIL : OK); - return ret; -} - - -#define EXPECT_GT(cond, expr, val) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_gt(expr, llen, val); } while (0) - -static __attribute__((unused)) -int expect_gt(int expr, int llen, int val) -{ - int ret = !(expr > val); - - llen += printf(" = %d ", expr); - result(llen, ret ? FAIL : OK); - return ret; -} - - -#define EXPECT_LE(cond, expr, val) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_le(expr, llen, val); } while (0) - -static __attribute__((unused)) -int expect_le(int expr, int llen, int val) -{ - int ret = !(expr <= val); - - llen += printf(" = %d ", expr); - result(llen, ret ? FAIL : OK); - return ret; -} - - -#define EXPECT_LT(cond, expr, val) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_lt(expr, llen, val); } while (0) - -static __attribute__((unused)) -int expect_lt(int expr, int llen, int val) -{ - int ret = !(expr < val); - - llen += printf(" = %d ", expr); - result(llen, ret ? FAIL : OK); - return ret; -} - - -#define EXPECT_SYSZR(cond, expr) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_syszr(expr, llen); } while (0) - -static __attribute__((unused)) -int expect_syszr(int expr, int llen) -{ - int ret = 0; - - if (errno == ENOSYS) { - llen += printf(" = ENOSYS"); - result(llen, SKIPPED); - } else if (expr) { - ret = 1; - llen += printf(" = %d %s ", expr, errorname(errno)); - result(llen, FAIL); - } else { - llen += printf(" = %d ", expr); - result(llen, OK); - } - return ret; -} - - -#define EXPECT_SYSEQ(cond, expr, val) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_syseq(expr, llen, val); } while (0) - -static __attribute__((unused)) -int expect_syseq(int expr, int llen, int val) -{ - int ret = 0; - - if (expr != val) { - ret = 1; - llen += printf(" = %d %s ", expr, errorname(errno)); - result(llen, FAIL); - } else { - llen += printf(" = %d ", expr); - result(llen, OK); - } - return ret; -} - - -#define EXPECT_SYSNE(cond, expr, val) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_sysne(expr, llen, val); } while (0) - -static __attribute__((unused)) -int expect_sysne(int expr, int llen, int val) -{ - int ret = 0; - - if (errno == ENOSYS) { - llen += printf(" = ENOSYS"); - result(llen, SKIPPED); - } else if (expr == val) { - ret = 1; - llen += printf(" = %d %s ", expr, errorname(errno)); - result(llen, FAIL); - } else { - llen += printf(" = %d ", expr); - result(llen, OK); - } - return ret; -} - - -#define EXPECT_SYSER2(cond, expr, expret, experr1, experr2) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_syserr2(expr, expret, experr1, experr2, llen); } while (0) - -#define EXPECT_SYSER(cond, expr, expret, experr) \ - EXPECT_SYSER2(cond, expr, expret, experr, 0) - -static __attribute__((unused)) -int expect_syserr2(int expr, int expret, int experr1, int experr2, int llen) -{ - int ret = 0; - int _errno = errno; - - llen += printf(" = %d %s ", expr, errorname(_errno)); - if (errno == ENOSYS) { - result(llen, SKIPPED); - } else if (expr != expret || (_errno != experr1 && _errno != experr2)) { - ret = 1; - if (experr2 == 0) - llen += printf(" != (%d %s) ", expret, errorname(experr1)); - else - llen += printf(" != (%d %s %s) ", expret, errorname(experr1), errorname(experr2)); - result(llen, FAIL); - } else { - result(llen, OK); - } - return ret; -} - - -#define EXPECT_PTRZR(cond, expr) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ptrzr(expr, llen); } while (0) - -static __attribute__((unused)) -int expect_ptrzr(const void *expr, int llen) -{ - int ret = 0; - - llen += printf(" = <%p> ", expr); - if (expr) { - ret = 1; - result(llen, FAIL); - } else { - result(llen, OK); - } - return ret; -} - - -#define EXPECT_PTRNZ(cond, expr) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ptrnz(expr, llen); } while (0) - -static __attribute__((unused)) -int expect_ptrnz(const void *expr, int llen) -{ - int ret = 0; - - llen += printf(" = <%p> ", expr); - if (!expr) { - ret = 1; - result(llen, FAIL); - } else { - result(llen, OK); - } - return ret; -} - -#define EXPECT_PTREQ(cond, expr, cmp) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ptreq(expr, llen, cmp); } while (0) - -static __attribute__((unused)) -int expect_ptreq(const void *expr, int llen, const void *cmp) -{ - int ret = 0; - - llen += printf(" = <%p> ", expr); - if (expr != cmp) { - ret = 1; - result(llen, FAIL); - } else { - result(llen, OK); - } - return ret; -} - -#define EXPECT_PTRNE(cond, expr, cmp) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ptrne(expr, llen, cmp); } while (0) - -static __attribute__((unused)) -int expect_ptrne(const void *expr, int llen, const void *cmp) -{ - int ret = 0; - - llen += printf(" = <%p> ", expr); - if (expr == cmp) { - ret = 1; - result(llen, FAIL); - } else { - result(llen, OK); - } - return ret; -} - -#define EXPECT_PTRGE(cond, expr, cmp) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ptrge(expr, llen, cmp); } while (0) - -static __attribute__((unused)) -int expect_ptrge(const void *expr, int llen, const void *cmp) -{ - int ret = !(expr >= cmp); - - llen += printf(" = <%p> ", expr); - result(llen, ret ? FAIL : OK); - return ret; -} - -#define EXPECT_PTRGT(cond, expr, cmp) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ptrgt(expr, llen, cmp); } while (0) - -static __attribute__((unused)) -int expect_ptrgt(const void *expr, int llen, const void *cmp) -{ - int ret = !(expr > cmp); - - llen += printf(" = <%p> ", expr); - result(llen, ret ? FAIL : OK); - return ret; -} - - -#define EXPECT_PTRLE(cond, expr, cmp) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ptrle(expr, llen, cmp); } while (0) - -static __attribute__((unused)) -int expect_ptrle(const void *expr, int llen, const void *cmp) -{ - int ret = !(expr <= cmp); - - llen += printf(" = <%p> ", expr); - result(llen, ret ? FAIL : OK); - return ret; -} - - -#define EXPECT_PTRLT(cond, expr, cmp) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ptrlt(expr, llen, cmp); } while (0) - -static __attribute__((unused)) -int expect_ptrlt(const void *expr, int llen, const void *cmp) -{ - int ret = !(expr < cmp); - - llen += printf(" = <%p> ", expr); - result(llen, ret ? FAIL : OK); - return ret; -} - -#define EXPECT_PTRER2(cond, expr, expret, experr1, experr2) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_ptrerr2(expr, expret, experr1, experr2, llen); } while (0) - -#define EXPECT_PTRER(cond, expr, expret, experr) \ - EXPECT_PTRER2(cond, expr, expret, experr, 0) - -static __attribute__((unused)) -int expect_ptrerr2(const void *expr, const void *expret, int experr1, int experr2, int llen) -{ - int ret = 0; - int _errno = errno; - - llen += printf(" = <%p> %s ", expr, errorname(_errno)); - if (expr != expret || (_errno != experr1 && _errno != experr2)) { - ret = 1; - if (experr2 == 0) - llen += printf(" != (<%p> %s) ", expret, errorname(experr1)); - else - llen += printf(" != (<%p> %s %s) ", expret, errorname(experr1), errorname(experr2)); - result(llen, FAIL); - } else { - result(llen, OK); - } - return ret; -} - -#define EXPECT_STRZR(cond, expr) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_strzr(expr, llen); } while (0) - -static __attribute__((unused)) -int expect_strzr(const char *expr, int llen) -{ - int ret = 0; - - llen += printf(" = <%s> ", expr ? expr : "(null)"); - if (expr) { - ret = 1; - result(llen, FAIL); - } else { - result(llen, OK); - } - return ret; -} - - -#define EXPECT_STRNZ(cond, expr) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_strnz(expr, llen); } while (0) - -static __attribute__((unused)) -int expect_strnz(const char *expr, int llen) -{ - int ret = 0; - - llen += printf(" = <%s> ", expr ? expr : "(null)"); - if (!expr) { - ret = 1; - result(llen, FAIL); - } else { - result(llen, OK); - } - return ret; -} - - -#define EXPECT_STREQ(cond, expr, cmp) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_streq(expr, llen, cmp); } while (0) - -static __attribute__((unused)) -int expect_streq(const char *expr, int llen, const char *cmp) -{ - int ret = 0; - - llen += printf(" = <%s> ", expr); - if (strcmp(expr, cmp) != 0) { - ret = 1; - result(llen, FAIL); - } else { - result(llen, OK); - } - return ret; -} - - -#define EXPECT_STRNE(cond, expr, cmp) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_strne(expr, llen, cmp); } while (0) - -static __attribute__((unused)) -int expect_strne(const char *expr, int llen, const char *cmp) -{ - int ret = 0; - - llen += printf(" = <%s> ", expr); - if (strcmp(expr, cmp) == 0) { - ret = 1; - result(llen, FAIL); - } else { - result(llen, OK); - } - return ret; -} - -#define EXPECT_STRBUFEQ(cond, expr, buf, val, cmp) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_str_buf_eq(expr, buf, val, llen, cmp); } while (0) - -static __attribute__((unused)) -int expect_str_buf_eq(size_t expr, const char *buf, size_t val, int llen, const char *cmp) -{ - llen += printf(" = %lu <%s> ", (unsigned long)expr, buf); - if (strcmp(buf, cmp) != 0) { - result(llen, FAIL); - return 1; - } - if (expr != val) { - result(llen, FAIL); - return 1; - } - - result(llen, OK); - return 0; -} - -#define EXPECT_STRTOX(cond, func, input, base, expected, chars, expected_errno) \ - do { if (!(cond)) result(llen, SKIPPED); else ret += expect_strtox(llen, func, input, base, expected, chars, expected_errno); } while (0) - -static __attribute__((unused)) -int expect_strtox(int llen, void *func, const char *input, int base, intmax_t expected, int expected_chars, int expected_errno) -{ - char *endptr; - int actual_errno, actual_chars; - intmax_t r; - - errno = 0; - if (func == strtol) { - r = strtol(input, &endptr, base); - } else if (func == strtoul) { - r = strtoul(input, &endptr, base); - } else { - result(llen, FAIL); - return 1; - } - actual_errno = errno; - actual_chars = endptr - input; - - llen += printf(" %lld = %lld", (long long)expected, (long long)r); - if (r != expected) { - result(llen, FAIL); - return 1; - } - if (expected_chars == -1) { - if (*endptr != '\0') { - result(llen, FAIL); - return 1; - } - } else if (expected_chars != actual_chars) { - result(llen, FAIL); - return 1; - } - if (actual_errno != expected_errno) { - result(llen, FAIL); - return 1; - } - - result(llen, OK); - return 0; -} - -/* declare tests based on line numbers. There must be exactly one test per line. */ -#define CASE_TEST(name) \ - case __LINE__: llen += printf("%d %s", test, #name); - -/* constructors validate that they are executed in definition order */ -__attribute__((constructor)) -static void constructor1(void) -{ - constructor_test_value |= 1 << 0; -} - -__attribute__((constructor)) -static void constructor2(int argc, char **argv, char **envp) -{ - if (argc && argv && envp) - constructor_test_value |= 1 << 1; -} - -int run_startup(int min, int max) -{ - int test; - int ret = 0; - /* kernel at least passes HOME and TERM, shell passes more */ - int env_total = 2; - /* checking NULL for argv/argv0, environ and _auxv is not enough, let's compare with sbrk(0) or &end */ - extern char end; - char *brk = sbrk(0) != (void *)-1 ? sbrk(0) : &end; - /* differ from nolibc, both glibc and musl have no global _auxv */ - const unsigned long *test_auxv = (void *)-1; -#ifdef NOLIBC - test_auxv = _auxv; -#endif - - for (test = min; test >= 0 && test <= max; test++) { - int llen = 0; /* line length */ - - /* avoid leaving empty lines below, this will insert holes into - * test numbers. - */ - switch (test + __LINE__ + 1) { - CASE_TEST(argc); EXPECT_GE(1, test_argc, 1); break; - CASE_TEST(argv_addr); EXPECT_PTRGT(1, test_argv, brk); break; - CASE_TEST(argv_environ); EXPECT_PTRLT(1, test_argv, environ); break; - CASE_TEST(argv_total); EXPECT_EQ(1, environ - test_argv - 1, test_argc ?: 1); break; - CASE_TEST(argv0_addr); EXPECT_PTRGT(1, argv0, brk); break; - CASE_TEST(argv0_str); EXPECT_STRNZ(1, argv0 > brk ? argv0 : NULL); break; - CASE_TEST(argv0_len); EXPECT_GE(1, argv0 > brk ? strlen(argv0) : 0, 1); break; - CASE_TEST(environ_addr); EXPECT_PTRGT(1, environ, brk); break; - CASE_TEST(environ_envp); EXPECT_PTREQ(1, environ, test_envp); break; - CASE_TEST(environ_auxv); EXPECT_PTRLT(test_auxv != (void *)-1, environ, test_auxv); break; - CASE_TEST(environ_total); EXPECT_GE(test_auxv != (void *)-1, (void *)test_auxv - (void *)environ - 1, env_total); break; - CASE_TEST(environ_HOME); EXPECT_PTRNZ(1, getenv("HOME")); break; - CASE_TEST(auxv_addr); EXPECT_PTRGT(test_auxv != (void *)-1, test_auxv, brk); break; - CASE_TEST(auxv_AT_UID); EXPECT_EQ(1, getauxval(AT_UID), getuid()); break; - CASE_TEST(constructor); EXPECT_EQ(is_nolibc, constructor_test_value, 0x3); break; - CASE_TEST(linkage_errno); EXPECT_PTREQ(1, linkage_test_errno_addr(), &errno); break; - CASE_TEST(linkage_constr); EXPECT_EQ(1, linkage_test_constructor_test_value, 0x3); break; - case __LINE__: - return ret; /* must be last */ - /* note: do not set any defaults so as to permit holes above */ - } - } - return ret; -} - - -/* used by some syscall tests below */ -int test_getdents64(const char *dir) -{ - char buffer[4096]; - int fd, ret; - int err; - - ret = fd = open(dir, O_RDONLY | O_DIRECTORY, 0); - if (ret < 0) - return ret; - - ret = getdents64(fd, (void *)buffer, sizeof(buffer)); - err = errno; - close(fd); - - errno = err; - return ret; -} - -static int test_dirent(void) -{ - int comm = 0, cmdline = 0; - struct dirent dirent, *result; - DIR *dir; - int ret; - - dir = opendir("/proc/self"); - if (!dir) - return 1; - - while (1) { - errno = 0; - ret = readdir_r(dir, &dirent, &result); - if (ret != 0) - return 1; - if (!result) - break; - - if (strcmp(dirent.d_name, "comm") == 0) - comm++; - else if (strcmp(dirent.d_name, "cmdline") == 0) - cmdline++; - } - - if (errno) - return 1; - - ret = closedir(dir); - if (ret) - return 1; - - if (comm != 1 || cmdline != 1) - return 1; - - return 0; -} - -int test_getpagesize(void) -{ - int x = getpagesize(); - int c; - - if (x < 0) - return x; - -#if defined(__x86_64__) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) - /* - * x86 family is always 4K page. - */ - c = (x == 4096); -#elif defined(__aarch64__) - /* - * Linux aarch64 supports three values of page size: 4K, 16K, and 64K - * which are selected at kernel compilation time. - */ - c = (x == 4096 || x == (16 * 1024) || x == (64 * 1024)); -#else - /* - * Assuming other architectures must have at least 4K page. - */ - c = (x >= 4096); -#endif - - return !c; -} - -int test_fork(void) -{ - int status; - pid_t pid; - - /* flush the printf buffer to avoid child flush it */ - fflush(stdout); - fflush(stderr); - - pid = fork(); - - switch (pid) { - case -1: - return 1; - - case 0: - exit(123); - - default: - pid = waitpid(pid, &status, 0); - - return pid == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 123; - } -} - -int test_stat_timestamps(void) -{ - struct stat st; - - if (sizeof(st.st_atim.tv_sec) != sizeof(st.st_atime)) - return 1; - - if (stat("/proc/self/", &st) && stat(argv0, &st) && stat("/", &st)) - return 1; - - if (st.st_atim.tv_sec != st.st_atime || st.st_atim.tv_nsec > 1000000000) - return 1; - - if (st.st_mtim.tv_sec != st.st_mtime || st.st_mtim.tv_nsec > 1000000000) - return 1; - - if (st.st_ctim.tv_sec != st.st_ctime || st.st_ctim.tv_nsec > 1000000000) - return 1; - - return 0; -} - -int test_uname(void) -{ - struct utsname buf; - char osrelease[sizeof(buf.release)]; - ssize_t r; - int fd; - - memset(&buf.domainname, 'P', sizeof(buf.domainname)); - - if (uname(&buf)) - return 1; - - if (strncmp("Linux", buf.sysname, sizeof(buf.sysname))) - return 1; - - fd = open("/proc/sys/kernel/osrelease", O_RDONLY); - if (fd == -1) - return 1; - - r = read(fd, osrelease, sizeof(osrelease)); - if (r == -1) - return 1; - - close(fd); - - if (osrelease[r - 1] == '\n') - r--; - - /* Validate one of the later fields to ensure field sizes are correct */ - if (strncmp(osrelease, buf.release, r)) - return 1; - - /* Ensure the field domainname is set, it is missing from struct old_utsname */ - if (strnlen(buf.domainname, sizeof(buf.domainname)) == sizeof(buf.domainname)) - return 1; - - return 0; -} - -int test_mmap_munmap(void) -{ - int ret, fd, i, page_size; - void *mem; - size_t file_size, length; - off_t offset, pa_offset; - struct stat stat_buf; - const char * const files[] = { - "/dev/zero", - "/proc/1/exe", "/proc/self/exe", - argv0, - NULL - }; - - page_size = getpagesize(); - if (page_size < 0) - return 1; - - /* find a right file to mmap, existed and accessible */ - for (i = 0; files[i] != NULL; i++) { - ret = fd = open(files[i], O_RDONLY); - if (ret == -1) - continue; - else - break; - } - if (ret == -1) - return 1; - - ret = stat(files[i], &stat_buf); - if (ret == -1) - goto end; - - /* file size of the special /dev/zero is 0, let's assign one manually */ - if (i == 0) - file_size = 3*page_size; - else - file_size = stat_buf.st_size; - - offset = file_size - 1; - if (offset < 0) - offset = 0; - length = file_size - offset; - pa_offset = offset & ~(page_size - 1); - - mem = mmap(NULL, length + offset - pa_offset, PROT_READ, MAP_SHARED, fd, pa_offset); - if (mem == MAP_FAILED) { - ret = 1; - goto end; - } - - ret = munmap(mem, length + offset - pa_offset); - -end: - close(fd); - return !!ret; -} - -int test_pipe(void) -{ - const char *const msg = "hello, nolibc"; - int pipefd[2]; - char buf[32]; - size_t len; - - if (pipe(pipefd) == -1) - return 1; - - write(pipefd[1], msg, strlen(msg)); - close(pipefd[1]); - len = read(pipefd[0], buf, sizeof(buf)); - close(pipefd[0]); - - if (len != strlen(msg)) - return 1; - - return !!memcmp(buf, msg, len); -} - -int test_rlimit(void) -{ - struct rlimit rlim = { - .rlim_cur = 1 << 20, - .rlim_max = 1 << 21, - }; - int ret; - - ret = setrlimit(RLIMIT_CORE, &rlim); - if (ret) - return -1; - - rlim.rlim_cur = 0; - rlim.rlim_max = 0; - - ret = getrlimit(RLIMIT_CORE, &rlim); - if (ret) - return -1; - - if (rlim.rlim_cur != 1 << 20) - return -1; - if (rlim.rlim_max != 1 << 21) - return -1; - - return 0; -} - -int test_openat(void) -{ - int dev, null; - - dev = openat(AT_FDCWD, "/dev", O_DIRECTORY); - if (dev < 0) - return -1; - - null = openat(dev, "null", O_RDONLY); - close(dev); - if (null < 0) - return -1; - - close(null); - return 0; -} - -/* Run syscall tests between IDs and . - * Return 0 on success, non-zero on failure. - */ -int run_syscall(int min, int max) -{ - struct timeval tv; - struct timezone tz; - struct stat stat_buf; - int euid0; - int proc; - int test; - int tmp; - int ret = 0; - void *p1, *p2; - int has_gettid = 1; - int has_brk; - - /* indicates whether or not /proc is mounted */ - proc = stat("/proc", &stat_buf) == 0; - - /* this will be used to skip certain tests that can't be run unprivileged */ - euid0 = geteuid() == 0; - - /* from 2.30, glibc provides gettid() */ -#if defined(__GLIBC_MINOR__) && defined(__GLIBC__) - has_gettid = __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 30); -#endif - - /* on musl setting brk()/sbrk() always fails */ - has_brk = brk(0) == 0; - - for (test = min; test >= 0 && test <= max; test++) { - int llen = 0; /* line length */ - - /* avoid leaving empty lines below, this will insert holes into - * test numbers. - */ - switch (test + __LINE__ + 1) { - CASE_TEST(getpid); EXPECT_SYSNE(1, getpid(), -1); break; - CASE_TEST(getppid); EXPECT_SYSNE(1, getppid(), -1); break; - CASE_TEST(gettid); EXPECT_SYSNE(has_gettid, gettid(), -1); break; - CASE_TEST(getpgid_self); EXPECT_SYSNE(1, getpgid(0), -1); break; - CASE_TEST(getpgid_bad); EXPECT_SYSER(1, getpgid(-1), -1, ESRCH); break; - CASE_TEST(kill_0); EXPECT_SYSZR(1, kill(getpid(), 0)); break; - CASE_TEST(kill_CONT); EXPECT_SYSZR(1, kill(getpid(), 0)); break; - CASE_TEST(kill_BADPID); EXPECT_SYSER(1, kill(INT_MAX, 0), -1, ESRCH); break; - CASE_TEST(sbrk_0); EXPECT_PTRNE(has_brk, sbrk(0), (void *)-1); break; - CASE_TEST(sbrk); if ((p1 = p2 = sbrk(4096)) != (void *)-1) p2 = sbrk(-4096); EXPECT_SYSZR(has_brk, (p2 == (void *)-1) || p2 == p1); break; - CASE_TEST(brk); EXPECT_SYSZR(has_brk, brk(sbrk(0))); break; - CASE_TEST(chdir_root); EXPECT_SYSZR(1, chdir("/")); chdir(getenv("PWD")); break; - CASE_TEST(chdir_dot); EXPECT_SYSZR(1, chdir(".")); break; - CASE_TEST(chdir_blah); EXPECT_SYSER(1, chdir("/blah"), -1, ENOENT); break; - CASE_TEST(chmod_argv0); EXPECT_SYSZR(1, chmod(argv0, 0555)); break; - CASE_TEST(chmod_self); EXPECT_SYSER(proc, chmod("/proc/self", 0555), -1, EPERM); break; - CASE_TEST(chown_self); EXPECT_SYSER(proc, chown("/proc/self", 0, 0), -1, EPERM); break; - CASE_TEST(chroot_root); EXPECT_SYSZR(euid0, chroot("/")); break; - CASE_TEST(chroot_blah); EXPECT_SYSER(1, chroot("/proc/self/blah"), -1, ENOENT); break; - CASE_TEST(chroot_exe); EXPECT_SYSER(1, chroot(argv0), -1, ENOTDIR); break; - CASE_TEST(close_m1); EXPECT_SYSER(1, close(-1), -1, EBADF); break; - CASE_TEST(close_dup); EXPECT_SYSZR(1, close(dup(0))); break; - CASE_TEST(dup_0); tmp = dup(0); EXPECT_SYSNE(1, tmp, -1); close(tmp); break; - CASE_TEST(dup_m1); tmp = dup(-1); EXPECT_SYSER(1, tmp, -1, EBADF); if (tmp != -1) close(tmp); break; - CASE_TEST(dup2_0); tmp = dup2(0, 100); EXPECT_SYSNE(1, tmp, -1); close(tmp); break; - CASE_TEST(dup2_m1); tmp = dup2(-1, 100); EXPECT_SYSER(1, tmp, -1, EBADF); if (tmp != -1) close(tmp); break; - CASE_TEST(dup3_0); tmp = dup3(0, 100, 0); EXPECT_SYSNE(1, tmp, -1); close(tmp); break; - CASE_TEST(dup3_m1); tmp = dup3(-1, 100, 0); EXPECT_SYSER(1, tmp, -1, EBADF); if (tmp != -1) close(tmp); break; - CASE_TEST(execve_root); EXPECT_SYSER(1, execve("/", (char*[]){ [0] = "/", [1] = NULL }, NULL), -1, EACCES); break; - CASE_TEST(fork); EXPECT_SYSZR(1, test_fork()); break; - CASE_TEST(getdents64_root); EXPECT_SYSNE(1, test_getdents64("/"), -1); break; - CASE_TEST(getdents64_null); EXPECT_SYSER(1, test_getdents64("/dev/null"), -1, ENOTDIR); break; - CASE_TEST(directories); EXPECT_SYSZR(proc, test_dirent()); break; - CASE_TEST(gettimeofday_tv); EXPECT_SYSZR(1, gettimeofday(&tv, NULL)); break; - CASE_TEST(gettimeofday_tv_tz);EXPECT_SYSZR(1, gettimeofday(&tv, &tz)); break; - CASE_TEST(getpagesize); EXPECT_SYSZR(1, test_getpagesize()); break; - CASE_TEST(ioctl_tiocinq); EXPECT_SYSZR(1, ioctl(0, TIOCINQ, &tmp)); break; - CASE_TEST(link_root1); EXPECT_SYSER(1, link("/", "/"), -1, EEXIST); break; - CASE_TEST(link_blah); EXPECT_SYSER(1, link("/proc/self/blah", "/blah"), -1, ENOENT); break; - CASE_TEST(link_dir); EXPECT_SYSER(euid0, link("/", "/blah"), -1, EPERM); break; - CASE_TEST(link_cross); EXPECT_SYSER(proc, link("/proc/self/cmdline", "/blah"), -1, EXDEV); break; - CASE_TEST(lseek_m1); EXPECT_SYSER(1, lseek(-1, 0, SEEK_SET), -1, EBADF); break; - CASE_TEST(lseek_0); EXPECT_SYSER(1, lseek(0, 0, SEEK_SET), -1, ESPIPE); break; - CASE_TEST(mkdir_root); EXPECT_SYSER(1, mkdir("/", 0755), -1, EEXIST); break; - CASE_TEST(mmap_bad); EXPECT_PTRER(1, mmap(NULL, 0, PROT_READ, MAP_PRIVATE, 0, 0), MAP_FAILED, EINVAL); break; - CASE_TEST(munmap_bad); EXPECT_SYSER(1, munmap(NULL, 0), -1, EINVAL); break; - CASE_TEST(mmap_munmap_good); EXPECT_SYSZR(1, test_mmap_munmap()); break; - CASE_TEST(open_tty); EXPECT_SYSNE(1, tmp = open("/dev/null", O_RDONLY), -1); if (tmp != -1) close(tmp); break; - CASE_TEST(open_blah); EXPECT_SYSER(1, tmp = open("/proc/self/blah", O_RDONLY), -1, ENOENT); if (tmp != -1) close(tmp); break; - CASE_TEST(openat_dir); EXPECT_SYSZR(1, test_openat()); break; - CASE_TEST(pipe); EXPECT_SYSZR(1, test_pipe()); break; - CASE_TEST(poll_null); EXPECT_SYSZR(1, poll(NULL, 0, 0)); break; - CASE_TEST(poll_stdout); EXPECT_SYSNE(1, ({ struct pollfd fds = { 1, POLLOUT, 0}; poll(&fds, 1, 0); }), -1); break; - CASE_TEST(poll_fault); EXPECT_SYSER(1, poll(NULL, 1, 0), -1, EFAULT); break; - CASE_TEST(prctl); EXPECT_SYSER(1, prctl(PR_SET_NAME, (unsigned long)NULL, 0, 0, 0), -1, EFAULT); break; - CASE_TEST(read_badf); EXPECT_SYSER(1, read(-1, &tmp, 1), -1, EBADF); break; - CASE_TEST(rlimit); EXPECT_SYSZR(1, test_rlimit()); break; - CASE_TEST(rmdir_blah); EXPECT_SYSER(1, rmdir("/blah"), -1, ENOENT); break; - CASE_TEST(sched_yield); EXPECT_SYSZR(1, sched_yield()); break; - CASE_TEST(select_null); EXPECT_SYSZR(1, ({ struct timeval tv = { 0 }; select(0, NULL, NULL, NULL, &tv); })); break; - CASE_TEST(select_stdout); EXPECT_SYSNE(1, ({ fd_set fds; FD_ZERO(&fds); FD_SET(1, &fds); select(2, NULL, &fds, NULL, NULL); }), -1); break; - CASE_TEST(select_fault); EXPECT_SYSER(1, select(1, (void *)1, NULL, NULL, 0), -1, EFAULT); break; - CASE_TEST(stat_blah); EXPECT_SYSER(1, stat("/proc/self/blah", &stat_buf), -1, ENOENT); break; - CASE_TEST(stat_fault); EXPECT_SYSER(1, stat(NULL, &stat_buf), -1, EFAULT); break; - CASE_TEST(stat_timestamps); EXPECT_SYSZR(1, test_stat_timestamps()); break; - CASE_TEST(symlink_root); EXPECT_SYSER(1, symlink("/", "/"), -1, EEXIST); break; - CASE_TEST(uname); EXPECT_SYSZR(proc, test_uname()); break; - CASE_TEST(uname_fault); EXPECT_SYSER(1, uname(NULL), -1, EFAULT); break; - CASE_TEST(unlink_root); EXPECT_SYSER(1, unlink("/"), -1, EISDIR); break; - CASE_TEST(unlink_blah); EXPECT_SYSER(1, unlink("/proc/self/blah"), -1, ENOENT); break; - CASE_TEST(wait_child); EXPECT_SYSER(1, wait(&tmp), -1, ECHILD); break; - CASE_TEST(waitpid_min); EXPECT_SYSER(1, waitpid(INT_MIN, &tmp, WNOHANG), -1, ESRCH); break; - CASE_TEST(waitpid_child); EXPECT_SYSER(1, waitpid(getpid(), &tmp, WNOHANG), -1, ECHILD); break; - CASE_TEST(write_badf); EXPECT_SYSER(1, write(-1, &tmp, 1), -1, EBADF); break; - CASE_TEST(write_zero); EXPECT_SYSZR(1, write(1, &tmp, 0)); break; - CASE_TEST(syscall_noargs); EXPECT_SYSEQ(1, syscall(__NR_getpid), getpid()); break; - CASE_TEST(syscall_args); EXPECT_SYSER(1, syscall(__NR_statx, 0, NULL, 0, 0, NULL), -1, EFAULT); break; - case __LINE__: - return ret; /* must be last */ - /* note: do not set any defaults so as to permit holes above */ - } - } - return ret; -} - -int run_stdlib(int min, int max) -{ - int test; - int ret = 0; - - for (test = min; test >= 0 && test <= max; test++) { - int llen = 0; /* line length */ - - /* For functions that take a long buffer, like strlcat() - * Add some more chars after the \0, to test functions that overwrite the buffer set - * the \0 at the exact right position. - */ - char buf[10] = "test123456"; - buf[4] = '\0'; - - - /* avoid leaving empty lines below, this will insert holes into - * test numbers. - */ - switch (test + __LINE__ + 1) { - CASE_TEST(getenv_TERM); EXPECT_STRNZ(1, getenv("TERM")); break; - CASE_TEST(getenv_blah); EXPECT_STRZR(1, getenv("blah")); break; - CASE_TEST(setcmp_blah_blah); EXPECT_EQ(1, strcmp("blah", "blah"), 0); break; - CASE_TEST(setcmp_blah_blah2); EXPECT_NE(1, strcmp("blah", "blah2"), 0); break; - CASE_TEST(setncmp_blah_blah); EXPECT_EQ(1, strncmp("blah", "blah", 10), 0); break; - CASE_TEST(setncmp_blah_blah4); EXPECT_EQ(1, strncmp("blah", "blah4", 4), 0); break; - CASE_TEST(setncmp_blah_blah5); EXPECT_NE(1, strncmp("blah", "blah5", 5), 0); break; - CASE_TEST(setncmp_blah_blah6); EXPECT_NE(1, strncmp("blah", "blah6", 6), 0); break; - CASE_TEST(strchr_foobar_o); EXPECT_STREQ(1, strchr("foobar", 'o'), "oobar"); break; - CASE_TEST(strchr_foobar_z); EXPECT_STRZR(1, strchr("foobar", 'z')); break; - CASE_TEST(strrchr_foobar_o); EXPECT_STREQ(1, strrchr("foobar", 'o'), "obar"); break; - CASE_TEST(strrchr_foobar_z); EXPECT_STRZR(1, strrchr("foobar", 'z')); break; - CASE_TEST(strlcat_0); EXPECT_STRBUFEQ(is_nolibc, strlcat(buf, "bar", 0), buf, 3, "test"); break; - CASE_TEST(strlcat_1); EXPECT_STRBUFEQ(is_nolibc, strlcat(buf, "bar", 1), buf, 4, "test"); break; - CASE_TEST(strlcat_5); EXPECT_STRBUFEQ(is_nolibc, strlcat(buf, "bar", 5), buf, 7, "test"); break; - CASE_TEST(strlcat_6); EXPECT_STRBUFEQ(is_nolibc, strlcat(buf, "bar", 6), buf, 7, "testb"); break; - CASE_TEST(strlcat_7); EXPECT_STRBUFEQ(is_nolibc, strlcat(buf, "bar", 7), buf, 7, "testba"); break; - CASE_TEST(strlcat_8); EXPECT_STRBUFEQ(is_nolibc, strlcat(buf, "bar", 8), buf, 7, "testbar"); break; - CASE_TEST(strlcpy_0); EXPECT_STRBUFEQ(is_nolibc, strlcpy(buf, "bar", 0), buf, 3, "test"); break; - CASE_TEST(strlcpy_1); EXPECT_STRBUFEQ(is_nolibc, strlcpy(buf, "bar", 1), buf, 3, ""); break; - CASE_TEST(strlcpy_2); EXPECT_STRBUFEQ(is_nolibc, strlcpy(buf, "bar", 2), buf, 3, "b"); break; - CASE_TEST(strlcpy_3); EXPECT_STRBUFEQ(is_nolibc, strlcpy(buf, "bar", 3), buf, 3, "ba"); break; - CASE_TEST(strlcpy_4); EXPECT_STRBUFEQ(is_nolibc, strlcpy(buf, "bar", 4), buf, 3, "bar"); break; - CASE_TEST(memcmp_20_20); EXPECT_EQ(1, memcmp("aaa\x20", "aaa\x20", 4), 0); break; - CASE_TEST(memcmp_20_60); EXPECT_LT(1, memcmp("aaa\x20", "aaa\x60", 4), 0); break; - CASE_TEST(memcmp_60_20); EXPECT_GT(1, memcmp("aaa\x60", "aaa\x20", 4), 0); break; - CASE_TEST(memcmp_20_e0); EXPECT_LT(1, memcmp("aaa\x20", "aaa\xe0", 4), 0); break; - CASE_TEST(memcmp_e0_20); EXPECT_GT(1, memcmp("aaa\xe0", "aaa\x20", 4), 0); break; - CASE_TEST(memcmp_80_e0); EXPECT_LT(1, memcmp("aaa\x80", "aaa\xe0", 4), 0); break; - CASE_TEST(memcmp_e0_80); EXPECT_GT(1, memcmp("aaa\xe0", "aaa\x80", 4), 0); break; - CASE_TEST(limit_int8_max); EXPECT_EQ(1, INT8_MAX, (int8_t) 0x7f); break; - CASE_TEST(limit_int8_min); EXPECT_EQ(1, INT8_MIN, (int8_t) 0x80); break; - CASE_TEST(limit_uint8_max); EXPECT_EQ(1, UINT8_MAX, (uint8_t) 0xff); break; - CASE_TEST(limit_int16_max); EXPECT_EQ(1, INT16_MAX, (int16_t) 0x7fff); break; - CASE_TEST(limit_int16_min); EXPECT_EQ(1, INT16_MIN, (int16_t) 0x8000); break; - CASE_TEST(limit_uint16_max); EXPECT_EQ(1, UINT16_MAX, (uint16_t) 0xffff); break; - CASE_TEST(limit_int32_max); EXPECT_EQ(1, INT32_MAX, (int32_t) 0x7fffffff); break; - CASE_TEST(limit_int32_min); EXPECT_EQ(1, INT32_MIN, (int32_t) 0x80000000); break; - CASE_TEST(limit_uint32_max); EXPECT_EQ(1, UINT32_MAX, (uint32_t) 0xffffffff); break; - CASE_TEST(limit_int64_max); EXPECT_EQ(1, INT64_MAX, (int64_t) 0x7fffffffffffffff); break; - CASE_TEST(limit_int64_min); EXPECT_EQ(1, INT64_MIN, (int64_t) 0x8000000000000000); break; - CASE_TEST(limit_uint64_max); EXPECT_EQ(1, UINT64_MAX, (uint64_t) 0xffffffffffffffff); break; - CASE_TEST(limit_int_least8_max); EXPECT_EQ(1, INT_LEAST8_MAX, (int_least8_t) 0x7f); break; - CASE_TEST(limit_int_least8_min); EXPECT_EQ(1, INT_LEAST8_MIN, (int_least8_t) 0x80); break; - CASE_TEST(limit_uint_least8_max); EXPECT_EQ(1, UINT_LEAST8_MAX, (uint_least8_t) 0xff); break; - CASE_TEST(limit_int_least16_max); EXPECT_EQ(1, INT_LEAST16_MAX, (int_least16_t) 0x7fff); break; - CASE_TEST(limit_int_least16_min); EXPECT_EQ(1, INT_LEAST16_MIN, (int_least16_t) 0x8000); break; - CASE_TEST(limit_uint_least16_max); EXPECT_EQ(1, UINT_LEAST16_MAX, (uint_least16_t) 0xffff); break; - CASE_TEST(limit_int_least32_max); EXPECT_EQ(1, INT_LEAST32_MAX, (int_least32_t) 0x7fffffff); break; - CASE_TEST(limit_int_least32_min); EXPECT_EQ(1, INT_LEAST32_MIN, (int_least32_t) 0x80000000); break; - CASE_TEST(limit_uint_least32_max); EXPECT_EQ(1, UINT_LEAST32_MAX, (uint_least32_t) 0xffffffffU); break; - CASE_TEST(limit_int_least64_min); EXPECT_EQ(1, INT_LEAST64_MIN, (int_least64_t) 0x8000000000000000LL); break; - CASE_TEST(limit_int_least64_max); EXPECT_EQ(1, INT_LEAST64_MAX, (int_least64_t) 0x7fffffffffffffffLL); break; - CASE_TEST(limit_uint_least64_max); EXPECT_EQ(1, UINT_LEAST64_MAX, (uint_least64_t) 0xffffffffffffffffULL); break; - CASE_TEST(limit_int_fast8_max); EXPECT_EQ(1, INT_FAST8_MAX, (int_fast8_t) 0x7f); break; - CASE_TEST(limit_int_fast8_min); EXPECT_EQ(1, INT_FAST8_MIN, (int_fast8_t) 0x80); break; - CASE_TEST(limit_uint_fast8_max); EXPECT_EQ(1, UINT_FAST8_MAX, (uint_fast8_t) 0xff); break; - CASE_TEST(limit_int_fast16_min); EXPECT_EQ(1, INT_FAST16_MIN, (int_fast16_t) SINT_MIN_OF_TYPE(int_fast16_t)); break; - CASE_TEST(limit_int_fast16_max); EXPECT_EQ(1, INT_FAST16_MAX, (int_fast16_t) SINT_MAX_OF_TYPE(int_fast16_t)); break; - CASE_TEST(limit_uint_fast16_max); EXPECT_EQ(1, UINT_FAST16_MAX, (uint_fast16_t) UINTPTR_MAX); break; - CASE_TEST(limit_int_fast32_min); EXPECT_EQ(1, INT_FAST32_MIN, (int_fast32_t) SINT_MIN_OF_TYPE(int_fast32_t)); break; - CASE_TEST(limit_int_fast32_max); EXPECT_EQ(1, INT_FAST32_MAX, (int_fast32_t) SINT_MAX_OF_TYPE(int_fast32_t)); break; - CASE_TEST(limit_uint_fast32_max); EXPECT_EQ(1, UINT_FAST32_MAX, (uint_fast32_t) UINTPTR_MAX); break; - CASE_TEST(limit_int_fast64_min); EXPECT_EQ(1, INT_FAST64_MIN, (int_fast64_t) INT64_MIN); break; - CASE_TEST(limit_int_fast64_max); EXPECT_EQ(1, INT_FAST64_MAX, (int_fast64_t) INT64_MAX); break; - CASE_TEST(limit_uint_fast64_max); EXPECT_EQ(1, UINT_FAST64_MAX, (uint_fast64_t) UINT64_MAX); break; - CASE_TEST(sizeof_long_sane); EXPECT_EQ(1, sizeof(long) == 8 || sizeof(long) == 4, 1); break; - CASE_TEST(limit_intptr_min); EXPECT_EQ(1, INTPTR_MIN, sizeof(long) == 8 ? (intptr_t) 0x8000000000000000LL : (intptr_t) 0x80000000); break; - CASE_TEST(limit_intptr_max); EXPECT_EQ(1, INTPTR_MAX, sizeof(long) == 8 ? (intptr_t) 0x7fffffffffffffffLL : (intptr_t) 0x7fffffff); break; - CASE_TEST(limit_uintptr_max); EXPECT_EQ(1, UINTPTR_MAX, sizeof(long) == 8 ? (uintptr_t) 0xffffffffffffffffULL : (uintptr_t) 0xffffffffU); break; - CASE_TEST(limit_ptrdiff_min); EXPECT_EQ(1, PTRDIFF_MIN, sizeof(long) == 8 ? (ptrdiff_t) 0x8000000000000000LL : (ptrdiff_t) 0x80000000); break; - CASE_TEST(limit_ptrdiff_max); EXPECT_EQ(1, PTRDIFF_MAX, sizeof(long) == 8 ? (ptrdiff_t) 0x7fffffffffffffffLL : (ptrdiff_t) 0x7fffffff); break; - CASE_TEST(limit_size_max); EXPECT_EQ(1, SIZE_MAX, sizeof(long) == 8 ? (size_t) 0xffffffffffffffffULL : (size_t) 0xffffffffU); break; - CASE_TEST(strtol_simple); EXPECT_STRTOX(1, strtol, "35", 10, 35, -1, 0); break; - CASE_TEST(strtol_positive); EXPECT_STRTOX(1, strtol, "+35", 10, 35, -1, 0); break; - CASE_TEST(strtol_negative); EXPECT_STRTOX(1, strtol, "-35", 10, -35, -1, 0); break; - CASE_TEST(strtol_hex_auto); EXPECT_STRTOX(1, strtol, "0xFF", 0, 255, -1, 0); break; - CASE_TEST(strtol_base36); EXPECT_STRTOX(1, strtol, "12yZ", 36, 50507, -1, 0); break; - CASE_TEST(strtol_cutoff); EXPECT_STRTOX(1, strtol, "1234567890", 8, 342391, 7, 0); break; - CASE_TEST(strtol_octal_auto); EXPECT_STRTOX(1, strtol, "011", 0, 9, -1, 0); break; - CASE_TEST(strtol_hex_00); EXPECT_STRTOX(1, strtol, "0x00", 16, 0, -1, 0); break; - CASE_TEST(strtol_hex_FF); EXPECT_STRTOX(1, strtol, "FF", 16, 255, -1, 0); break; - CASE_TEST(strtol_hex_ff); EXPECT_STRTOX(1, strtol, "ff", 16, 255, -1, 0); break; - CASE_TEST(strtol_hex_prefix); EXPECT_STRTOX(1, strtol, "0xFF", 16, 255, -1, 0); break; - CASE_TEST(strtol_trailer); EXPECT_STRTOX(1, strtol, "35foo", 10, 35, 2, 0); break; - CASE_TEST(strtol_overflow); EXPECT_STRTOX(1, strtol, "0x8000000000000000", 16, LONG_MAX, -1, ERANGE); break; - CASE_TEST(strtol_underflow); EXPECT_STRTOX(1, strtol, "-0x8000000000000001", 16, LONG_MIN, -1, ERANGE); break; - CASE_TEST(strtoul_negative); EXPECT_STRTOX(1, strtoul, "-0x1", 16, ULONG_MAX, 4, 0); break; - CASE_TEST(strtoul_overflow); EXPECT_STRTOX(1, strtoul, "0x10000000000000000", 16, ULONG_MAX, -1, ERANGE); break; - CASE_TEST(strerror_success); EXPECT_STREQ(is_nolibc, strerror(0), "errno=0"); break; - CASE_TEST(strerror_EINVAL); EXPECT_STREQ(is_nolibc, strerror(EINVAL), "errno=22"); break; - CASE_TEST(strerror_int_max); EXPECT_STREQ(is_nolibc, strerror(INT_MAX), "errno=2147483647"); break; - CASE_TEST(strerror_int_min); EXPECT_STREQ(is_nolibc, strerror(INT_MIN), "errno=-2147483648"); break; - CASE_TEST(tolower); EXPECT_EQ(1, tolower('A'), 'a'); break; - CASE_TEST(tolower_noop); EXPECT_EQ(1, tolower('a'), 'a'); break; - CASE_TEST(toupper); EXPECT_EQ(1, toupper('a'), 'A'); break; - CASE_TEST(toupper_noop); EXPECT_EQ(1, toupper('A'), 'A'); break; - - case __LINE__: - return ret; /* must be last */ - /* note: do not set any defaults so as to permit holes above */ - } - } - return ret; -} - -#define EXPECT_VFPRINTF(c, expected, fmt, ...) \ - ret += expect_vfprintf(llen, c, expected, fmt, ##__VA_ARGS__) - -static int expect_vfprintf(int llen, int c, const char *expected, const char *fmt, ...) -{ - char buf[100]; - va_list args; - ssize_t w; - int ret; - - - va_start(args, fmt); - /* Only allow writing 21 bytes, to test truncation */ - w = vsnprintf(buf, 21, fmt, args); - va_end(args); - - if (w != c) { - llen += printf(" written(%d) != %d", (int)w, c); - result(llen, FAIL); - return 1; - } - - llen += printf(" \"%s\" = \"%s\"", expected, buf); - ret = strncmp(expected, buf, c); - - result(llen, ret ? FAIL : OK); - return ret; -} - -static int test_scanf(void) -{ - unsigned long long ull; - unsigned long ul; - unsigned int u; - long long ll; - long l; - void *p; - int i; - - /* return __LINE__ to point to the specific failure */ - - /* test EOF */ - if (sscanf("", "foo") != EOF) - return __LINE__; - - /* test simple literal without placeholder */ - if (sscanf("foo", "foo") != 0) - return __LINE__; - - /* test single placeholder */ - if (sscanf("123", "%d", &i) != 1) - return __LINE__; - - if (i != 123) - return __LINE__; - - /* test multiple place holders and separators */ - if (sscanf("a123b456c0x90", "a%db%uc%p", &i, &u, &p) != 3) - return __LINE__; - - if (i != 123) - return __LINE__; - - if (u != 456) - return __LINE__; - - if (p != (void *)0x90) - return __LINE__; - - /* test space handling */ - if (sscanf("a b1", "a b%d", &i) != 1) - return __LINE__; - - if (i != 1) - return __LINE__; - - /* test literal percent */ - if (sscanf("a%1", "a%%%d", &i) != 1) - return __LINE__; - - if (i != 1) - return __LINE__; - - /* test stdint.h types */ - if (sscanf("1|2|3|4|5|6", - "%d|%ld|%lld|%u|%lu|%llu", - &i, &l, &ll, &u, &ul, &ull) != 6) - return __LINE__; - - if (i != 1 || l != 2 || ll != 3 || - u != 4 || ul != 5 || ull != 6) - return __LINE__; - - return 0; -} - -static int run_printf(int min, int max) -{ - int test; - int ret = 0; - - for (test = min; test >= 0 && test <= max; test++) { - int llen = 0; /* line length */ - - /* avoid leaving empty lines below, this will insert holes into - * test numbers. - */ - switch (test + __LINE__ + 1) { - CASE_TEST(empty); EXPECT_VFPRINTF(0, "", ""); break; - CASE_TEST(simple); EXPECT_VFPRINTF(3, "foo", "foo"); break; - CASE_TEST(string); EXPECT_VFPRINTF(3, "foo", "%s", "foo"); break; - CASE_TEST(number); EXPECT_VFPRINTF(4, "1234", "%d", 1234); break; - CASE_TEST(negnumber); EXPECT_VFPRINTF(5, "-1234", "%d", -1234); break; - CASE_TEST(unsigned); EXPECT_VFPRINTF(5, "12345", "%u", 12345); break; - CASE_TEST(char); EXPECT_VFPRINTF(1, "c", "%c", 'c'); break; - CASE_TEST(hex); EXPECT_VFPRINTF(1, "f", "%x", 0xf); break; - CASE_TEST(pointer); EXPECT_VFPRINTF(3, "0x1", "%p", (void *) 0x1); break; - CASE_TEST(uintmax_t); EXPECT_VFPRINTF(20, "18446744073709551615", "%ju", 0xffffffffffffffffULL); break; - CASE_TEST(intmax_t); EXPECT_VFPRINTF(20, "-9223372036854775807", "%jd", 0x8000000000000001LL); break; - CASE_TEST(truncation); EXPECT_VFPRINTF(25, "01234567890123456789", "%s", "0123456789012345678901234"); break; - CASE_TEST(string_width); EXPECT_VFPRINTF(10, " 1", "%10s", "1"); break; - CASE_TEST(number_width); EXPECT_VFPRINTF(10, " 1", "%10d", 1); break; - CASE_TEST(width_trunc); EXPECT_VFPRINTF(25, " ", "%25d", 1); break; - CASE_TEST(scanf); EXPECT_ZR(1, test_scanf()); break; - case __LINE__: - return ret; /* must be last */ - /* note: do not set any defaults so as to permit holes above */ - } - } - return ret; -} - -static int smash_stack(void) -{ - char buf[100]; - volatile char *ptr = buf; - size_t i; - - for (i = 0; i < 200; i++) - ptr[i] = 'P'; - - return 1; -} - -static int run_protection(int min __attribute__((unused)), - int max __attribute__((unused))) -{ - pid_t pid; - int llen = 0, status; - struct rlimit rlimit = { 0, 0 }; - - llen += printf("0 -fstackprotector "); - -#if !defined(_NOLIBC_STACKPROTECTOR) - llen += printf("not supported"); - result(llen, SKIPPED); - return 0; -#endif - -#if defined(_NOLIBC_STACKPROTECTOR) - if (!__stack_chk_guard) { - llen += printf("__stack_chk_guard not initialized"); - result(llen, FAIL); - return 1; - } -#endif - - pid = -1; - pid = fork(); - - switch (pid) { - case -1: - llen += printf("fork()"); - result(llen, FAIL); - return 1; - - case 0: - close(STDOUT_FILENO); - close(STDERR_FILENO); - - prctl(PR_SET_DUMPABLE, 0, 0, 0, 0); - setrlimit(RLIMIT_CORE, &rlimit); - smash_stack(); - return 1; - - default: - pid = waitpid(pid, &status, 0); - - if (pid == -1 || !WIFSIGNALED(status) || WTERMSIG(status) != SIGABRT) { - llen += printf("waitpid()"); - result(llen, FAIL); - return 1; - } - result(llen, OK); - return 0; - } -} - -/* prepare what needs to be prepared for pid 1 (stdio, /dev, /proc, etc) */ -int prepare(void) -{ - struct stat stat_buf; - - /* It's possible that /dev doesn't even exist or was not mounted, so - * we'll try to create it, mount it, or create minimal entries into it. - * We want at least /dev/null and /dev/console. - */ - if (stat("/dev/.", &stat_buf) == 0 || mkdir("/dev", 0755) == 0) { - if (stat("/dev/console", &stat_buf) != 0 || - stat("/dev/null", &stat_buf) != 0 || - stat("/dev/zero", &stat_buf) != 0) { - /* try devtmpfs first, otherwise fall back to manual creation */ - if (mount("/dev", "/dev", "devtmpfs", 0, 0) != 0) { - mknod("/dev/console", 0600 | S_IFCHR, makedev(5, 1)); - mknod("/dev/null", 0666 | S_IFCHR, makedev(1, 3)); - mknod("/dev/zero", 0666 | S_IFCHR, makedev(1, 5)); - } - } - } - - /* If no /dev/console was found before calling init, stdio is closed so - * we need to reopen it from /dev/console. If it failed above, it will - * still fail here and we cannot emit a message anyway. - */ - if (close(dup(1)) == -1) { - int fd = open("/dev/console", O_RDWR); - - if (fd >= 0) { - if (fd != 0) - dup2(fd, 0); - if (fd != 1) - dup2(fd, 1); - if (fd != 2) - dup2(fd, 2); - if (fd > 2) - close(fd); - puts("\nSuccessfully reopened /dev/console."); - } - } - - /* try to mount /proc if not mounted. Silently fail otherwise */ - if (stat("/proc/.", &stat_buf) == 0 || mkdir("/proc", 0755) == 0) { - if (stat("/proc/self", &stat_buf) != 0) { - /* If not mountable, remove /proc completely to avoid misuse */ - if (mount("none", "/proc", "proc", 0, 0) != 0) - rmdir("/proc"); - } - } - - /* some tests rely on a writable /tmp */ - mkdir("/tmp", 0755); - - return 0; -} - -/* This is the definition of known test names, with their functions */ -static const struct test test_names[] = { - /* add new tests here */ - { .name = "startup", .func = run_startup }, - { .name = "syscall", .func = run_syscall }, - { .name = "stdlib", .func = run_stdlib }, - { .name = "printf", .func = run_printf }, - { .name = "protection", .func = run_protection }, - { 0 } -}; - -static int is_setting_valid(char *test) -{ - int idx, len, test_len, valid = 0; - char delimiter; - - if (!test) - return valid; - - test_len = strlen(test); - - for (idx = 0; test_names[idx].name; idx++) { - len = strlen(test_names[idx].name); - if (test_len < len) - continue; - - if (strncmp(test, test_names[idx].name, len) != 0) - continue; - - delimiter = test[len]; - if (delimiter != ':' && delimiter != ',' && delimiter != '\0') - continue; - - valid = 1; - break; - } - - return valid; -} - -int main(int argc, char **argv, char **envp) -{ - int min = 0; - int max = INT_MAX; - int ret = 0; - int err; - int idx; - char *test; - - argv0 = argv[0]; - test_argc = argc; - test_argv = argv; - test_envp = envp; - - /* when called as init, it's possible that no console was opened, for - * example if no /dev file system was provided. We'll check that fd#1 - * was opened, and if not we'll attempt to create and open /dev/console - * and /dev/null that we'll use for later tests. - */ - if (getpid() == 1) - prepare(); - - /* the definition of a series of tests comes from either argv[1] or the - * "NOLIBC_TEST" environment variable. It's made of a comma-delimited - * series of test names and optional ranges: - * syscall:5-15[:.*],stdlib:8-10 - */ - test = argv[1]; - if (!is_setting_valid(test)) - test = getenv("NOLIBC_TEST"); - - if (is_setting_valid(test)) { - char *comma, *colon, *dash, *value; - - do { - comma = strchr(test, ','); - if (comma) - *(comma++) = '\0'; - - colon = strchr(test, ':'); - if (colon) - *(colon++) = '\0'; - - for (idx = 0; test_names[idx].name; idx++) { - if (strcmp(test, test_names[idx].name) == 0) - break; - } - - if (test_names[idx].name) { - /* The test was named, it will be called at least - * once. We may have an optional range at - * here, which defaults to the full range. - */ - do { - min = 0; max = INT_MAX; - value = colon; - if (value && *value) { - colon = strchr(value, ':'); - if (colon) - *(colon++) = '\0'; - - dash = strchr(value, '-'); - if (dash) - *(dash++) = '\0'; - - /* support :val: :min-max: :min-: :-max: */ - if (*value) - min = atoi(value); - if (!dash) - max = min; - else if (*dash) - max = atoi(dash); - - value = colon; - } - - /* now's time to call the test */ - printf("Running test '%s'\n", test_names[idx].name); - err = test_names[idx].func(min, max); - ret += err; - printf("Errors during this test: %d\n\n", err); - } while (colon && *colon); - } else - printf("Ignoring unknown test name '%s'\n", test); - - test = comma; - } while (test && *test); - } else { - /* no test mentioned, run everything */ - for (idx = 0; test_names[idx].name; idx++) { - printf("Running test '%s'\n", test_names[idx].name); - err = test_names[idx].func(min, max); - ret += err; - printf("Errors during this test: %d\n\n", err); - } - } - - printf("Total number of errors: %d\n", ret); - - if (getpid() == 1) { - /* we're running as init, there's no other process on the - * system, thus likely started from a VM for a quick check. - * Exiting will provoke a kernel panic that may be reported - * as an error by Qemu or the hypervisor, while stopping - * cleanly will often be reported as a success. This allows - * to use the output of this program for bisecting kernels. - */ - printf("Leaving init with final status: %d\n", !!ret); - if (ret == 0) - reboot(RB_POWER_OFF); -#if defined(__x86_64__) - /* QEMU started with "-device isa-debug-exit -no-reboot" will - * exit with status code 2N+1 when N is written to 0x501. We - * hard-code the syscall here as it's arch-dependent. - */ - else if (syscall(__NR_ioperm, 0x501, 1, 1) == 0) - __asm__ volatile ("outb %%al, %%dx" :: "d"(0x501), "a"(0)); - /* if it does nothing, fall back to the regular panic */ -#endif - } - - printf("Exiting with status %d\n", !!ret); - return !!ret; -} +#include "harness-selftest.c" diff --git a/tools/testing/selftests/nolibc/run-tests.sh b/tools/testing/selftests/nolibc/run-tests.sh index 0299a0912d4049dd12217f9835b81d231e1d2bfd..9344e3e8e10466dbb04a80028439599bb0cb28a2 100755 --- a/tools/testing/selftests/nolibc/run-tests.sh +++ b/tools/testing/selftests/nolibc/run-tests.sh @@ -189,7 +189,7 @@ test_arch() { swallow_output "${MAKE[@]}" defconfig swallow_output "${MAKE[@]}" CFLAGS_EXTRA="$CFLAGS_EXTRA" "$test_target" V=1 cp run.out run.out."${arch}" - "${MAKE[@]}" report | grep passed + "${MAKE[@]}" report } if [ "$perform_download" -ne 0 ]; then