From patchwork Fri Apr 26 11:08:56 2024 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: 13644656 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (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 EC91414037C; Fri, 26 Apr 2024 11:09:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714129765; cv=none; b=hS8BcLFVC5oPc8D78FCBHMXaAWJymcv37pmNSZGFI8DDOfuXihVF/LnrjWChC4bjNsAP4i8w+l4dSwl4Um0BmfXykM7Q1Cc2xE/pYEOpztr7dNxPo8frk46UBuWbQG5b2foI4vrf4iIhGDmkow0ROpiNmE2ldW9hlkkQahOIA3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714129765; c=relaxed/simple; bh=POPoBWA0zb+CZxTZKQlvH0jHEDfJwJeLYQ/q42Q4tds=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WEbDIRwkr5rP0HWZ0piRGFG7TEABSSxa55ssuWj+45EVlfn32slVfWq7NvL2rj1LFf2RG82/kij2EjeDwL0lQJGFSKLC3hSac1Fp2W/DTi7r3+G2XrVHccBI9Bt66/NEZDurBx8w7nzmkxXkDwvA8r6t5Gp0hLOGhDxKsKKenIo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=WUOSdkjH; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="WUOSdkjH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1714129754; bh=POPoBWA0zb+CZxTZKQlvH0jHEDfJwJeLYQ/q42Q4tds=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WUOSdkjHWxDPd0U/iFslTgTmwnqkN7oHeNmu3TUfmmD2kXPvfdpXSBJxbnG0gUhO5 4Iy959TvW/Ut+XzIsvyj9xn4C0jNCTNcXVkDLA/9xHmYAnbbAST+VLxuIKfyYEGzlU zyQkCmbE3vy1cTKMa+IRIzPYbPDasA2Q18AN+Y8w= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Fri, 26 Apr 2024 13:08:56 +0200 Subject: [PATCH 1/3] selftests/nolibc: introduce condition to run tests only on nolibc Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240426-nolibc-strerror-v1-1-76a4c9c5271d@weissschuh.net> References: <20240426-nolibc-strerror-v1-0-76a4c9c5271d@weissschuh.net> In-Reply-To: <20240426-nolibc-strerror-v1-0-76a4c9c5271d@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1714129753; l=3870; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=POPoBWA0zb+CZxTZKQlvH0jHEDfJwJeLYQ/q42Q4tds=; b=HuIlN6rPjhA6VH5rmE3ZlIQZCJFQgnuMWRUt+OWRMPAohYcsyfBBDb6hKa5IVXqkaXqRkW+Wz vsK3AM1Q48vCWVLkDrINm3uQTA7rjI5jkheKN/tqvgEKhiWxoHlDZ6C X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Some tests only make sense on nolibc. To avoid gaps in the test numbers do to inline "#ifdef NOLIBC", add a condition to formally skip these tests. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/nolibc/nolibc-test.c | 32 +++++++++++++++++----------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 6161bd57a0c9..dadc9b8f2727 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -64,6 +64,14 @@ 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 */ @@ -1125,19 +1133,17 @@ int run_stdlib(int min, int max) 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; -#ifdef NOLIBC - CASE_TEST(strlcat_0); EXPECT_STRBUFEQ(1, strlcat(buf, "bar", 0), buf, 3, "test"); break; - CASE_TEST(strlcat_1); EXPECT_STRBUFEQ(1, strlcat(buf, "bar", 1), buf, 4, "test"); break; - CASE_TEST(strlcat_5); EXPECT_STRBUFEQ(1, strlcat(buf, "bar", 5), buf, 7, "test"); break; - CASE_TEST(strlcat_6); EXPECT_STRBUFEQ(1, strlcat(buf, "bar", 6), buf, 7, "testb"); break; - CASE_TEST(strlcat_7); EXPECT_STRBUFEQ(1, strlcat(buf, "bar", 7), buf, 7, "testba"); break; - CASE_TEST(strlcat_8); EXPECT_STRBUFEQ(1, strlcat(buf, "bar", 8), buf, 7, "testbar"); break; - CASE_TEST(strlcpy_0); EXPECT_STRBUFEQ(1, strlcpy(buf, "bar", 0), buf, 3, "test"); break; - CASE_TEST(strlcpy_1); EXPECT_STRBUFEQ(1, strlcpy(buf, "bar", 1), buf, 3, ""); break; - CASE_TEST(strlcpy_2); EXPECT_STRBUFEQ(1, strlcpy(buf, "bar", 2), buf, 3, "b"); break; - CASE_TEST(strlcpy_3); EXPECT_STRBUFEQ(1, strlcpy(buf, "bar", 3), buf, 3, "ba"); break; - CASE_TEST(strlcpy_4); EXPECT_STRBUFEQ(1, strlcpy(buf, "bar", 4), buf, 3, "bar"); break; -#endif + 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; From patchwork Fri Apr 26 11:08:57 2024 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: 13644658 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (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 A2D12144D0E; Fri, 26 Apr 2024 11:09:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714129765; cv=none; b=clj1Hd5DPFrc8PiVAefDNfHkGHz3cPbSoqDG22Exz4/d5IkFLT4ST6pvvnFjTV7WtA296D+jApFPhwxsLRT/Rr3ydoezVCt2VQ9bj8fphl7MktfUazmkqK0UzCFG20SJYOYabbdrf4pk4eAGipz7HIXCM7zPT7CVDF82R74BEp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714129765; c=relaxed/simple; bh=NBg8CCRMBOJmgxZRwKaQbukZLLVfWaE0h/O78pLsQbU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=S0yJQGfgBMP149iRJPlarVPOVxAvynuE9NBHpiB5YK2u9zb7Wvvg6WXrDNqJvtX3wn6XscXuJM4N9LFFx52bxJhUvWkYocgM7Lq9NdHbXNaAE7AngBysiddp41PTXTRfeJPIwoUJgTkTqXl93OMtbZmqE/xBQepJCRKu/WARzk0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=PUYvuhGV; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="PUYvuhGV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1714129754; bh=NBg8CCRMBOJmgxZRwKaQbukZLLVfWaE0h/O78pLsQbU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PUYvuhGV+o4EGVe/HmRpG/breHRO5ePgxGc5iPgXfaIDqpYB1BBratm/0XeNHaxvX 3QbytrVb/0s8Fvq9UT7iyQbCbJEt+YAgN2Ms+JlEjJZ/3pSKYEC/GE1om50aainndt wNZZqLK+WsAbzvo2iuwZAnE4pQWJ7rjtwi7pmO0M= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Fri, 26 Apr 2024 13:08:57 +0200 Subject: [PATCH 2/3] tools/nolibc: implement strerror() Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240426-nolibc-strerror-v1-2-76a4c9c5271d@weissschuh.net> References: <20240426-nolibc-strerror-v1-0-76a4c9c5271d@weissschuh.net> In-Reply-To: <20240426-nolibc-strerror-v1-0-76a4c9c5271d@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1714129753; l=2098; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=NBg8CCRMBOJmgxZRwKaQbukZLLVfWaE0h/O78pLsQbU=; b=2+5cf3DWm5+radMrTu3w4PvCDKr2JJPmJ8wDAZsbZbd6gEOODQIPfQ5J3G65Uj1iiNDRQTWvK MdMaa2zXQTACrye0T+HKaznHdkpV7xrMWzFOq+VGV1HKvHvOizPI0/Y X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= strerror() is commonly used. For example in kselftest which currently needs to do an #ifdef NOLIBC to handle the lack of strerror(). Keep it simple and reuse the output format of perror() for strerror(). Signed-off-by: Thomas Weißschuh --- tools/include/nolibc/stdio.h | 10 ++++++++++ tools/testing/selftests/nolibc/nolibc-test.c | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index 16cd4d807251..c968dbbc4ef8 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -376,6 +376,16 @@ int setvbuf(FILE *stream __attribute__((unused)), return 0; } +static __attribute__((unused)) +const char *strerror(int errno) +{ + static char buf[18] = "errno="; + + i64toa_r(errno, &buf[6]); + + return buf; +} + /* 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 dadc9b8f2727..1c23776713f5 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1208,6 +1208,10 @@ int run_stdlib(int min, int max) 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 __LINE__: return ret; /* must be last */ From patchwork Fri Apr 26 11:08:58 2024 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: 13644655 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (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 A2CC31448DF; Fri, 26 Apr 2024 11:09:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714129764; cv=none; b=Ndb8shDvZesjGqpgfuC8XNVjZd7nZGM73Z0juijzVxe4og15idJA/KRXhxVA2kWXCo7xjfZH7/oIchHWaa7j/IOYr7lt6Aj1qyVXukckC5t2oNFJzy35e409K37pHNLJhWube5jyuKax8JtaFGazUC2OGt9HdInlCotrTgbSrVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714129764; c=relaxed/simple; bh=9YJTYL0hFAFIxLg99RWUafnC/eaz4B750rx1oj19Es8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KR+aF59e+xsqoRggk8hR6E5e+fBpAIuV7yaEajkrazW/fQjXHtP3CIiqQm4fD6hbrqKo1faWsdiw409frhuZdkSJo6z/YwFHNUbzSYT5cJkBLEnErq5YJBvPPQOvSB0JyjegfGP3IDbtUqNdeIZ07bMVgLspiPlhx359JWqA6IM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=fC6mqdDL; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="fC6mqdDL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1714129754; bh=9YJTYL0hFAFIxLg99RWUafnC/eaz4B750rx1oj19Es8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fC6mqdDL2aBKq7NvmWLnbLc1mAOzfFYqokstdr+KfkofTDsdLwYD5UQJQBIpJ9KLm UBKCkjKPP5tSVGzC5MKVNktFyT838ShWW9UMtBdHQdiTy8AntZ38NTXluPBQrOHySa mrvOXlecYNwLgKqgz+3nV7oomSIre4hsVs8+XKMQ= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Fri, 26 Apr 2024 13:08:58 +0200 Subject: [PATCH 3/3] selftests: kselftest: also use strerror() on nolibc Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240426-nolibc-strerror-v1-3-76a4c9c5271d@weissschuh.net> References: <20240426-nolibc-strerror-v1-0-76a4c9c5271d@weissschuh.net> In-Reply-To: <20240426-nolibc-strerror-v1-0-76a4c9c5271d@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1714129753; l=969; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=9YJTYL0hFAFIxLg99RWUafnC/eaz4B750rx1oj19Es8=; b=QHYxmeweV/vq0rJcOPRdfSZaB7V3GTzNrKTqnNthBNo2TPTt/tGEUh9Fj8PYuGyOf7K6Ks8m3 ZH4O1EaBLqeCH8BaZn45Xge6ZmnJswb8t/fp+vdBWvqjWq8Fk9v6ji9 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= nolibc gained an implementation of strerror() recently. Use it and drop the ifdeffery. Signed-off-by: Thomas Weißschuh Acked-by: Shuah Khan Acked-by: Shuah Khan --- tools/testing/selftests/kselftest.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index 541bf192e30e..f4bfe98c31e4 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -161,15 +161,7 @@ static inline __printf(1, 2) void ksft_print_msg(const char *msg, ...) static inline void ksft_perror(const char *msg) { -#ifndef NOLIBC ksft_print_msg("%s: %s (%d)\n", msg, strerror(errno), errno); -#else - /* - * nolibc doesn't provide strerror() and it seems - * inappropriate to add one, just print the errno. - */ - ksft_print_msg("%s: %d)\n", msg, errno); -#endif } static inline __printf(1, 2) void ksft_test_result_pass(const char *msg, ...)