* [PATCH 0/3] tools/nolibc: implement strerror()
@ 2024-04-26 11:08 Thomas Weißschuh
2024-04-26 11:08 ` [PATCH 1/3] selftests/nolibc: introduce condition to run tests only on nolibc Thomas Weißschuh
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Thomas Weißschuh @ 2024-04-26 11:08 UTC (permalink / raw)
To: Willy Tarreau, Shuah Khan
Cc: linux-kselftest, linux-kernel, Thomas Weißschuh
Adds a simple implementation of strerror() and makes use of it in
kselftests.
Shuah, could you Ack patch 3?
Willy, this should work *without* your Ack.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Thomas Weißschuh (3):
selftests/nolibc: introduce condition to run tests only on nolibc
tools/nolibc: implement strerror()
selftests: kselftest: also use strerror() on nolibc
tools/include/nolibc/stdio.h | 10 ++++++++
tools/testing/selftests/kselftest.h | 8 -------
tools/testing/selftests/nolibc/nolibc-test.c | 36 ++++++++++++++++++----------
3 files changed, 33 insertions(+), 21 deletions(-)
---
base-commit: a3063ba97f31e0364379a3ffc567203e3f79e877
change-id: 20240425-nolibc-strerror-67f4bfa03035
Best regards,
--
Thomas Weißschuh <linux@weissschuh.net>
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 1/3] selftests/nolibc: introduce condition to run tests only on nolibc 2024-04-26 11:08 [PATCH 0/3] tools/nolibc: implement strerror() Thomas Weißschuh @ 2024-04-26 11:08 ` Thomas Weißschuh 2024-04-26 11:08 ` [PATCH 2/3] tools/nolibc: implement strerror() Thomas Weißschuh ` (2 subsequent siblings) 3 siblings, 0 replies; 9+ messages in thread From: Thomas Weißschuh @ 2024-04-26 11:08 UTC (permalink / raw) To: Willy Tarreau, Shuah Khan Cc: linux-kselftest, linux-kernel, Thomas Weißschuh 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 <linux@weissschuh.net> --- 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; -- 2.44.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/3] tools/nolibc: implement strerror() 2024-04-26 11:08 [PATCH 0/3] tools/nolibc: implement strerror() Thomas Weißschuh 2024-04-26 11:08 ` [PATCH 1/3] selftests/nolibc: introduce condition to run tests only on nolibc Thomas Weißschuh @ 2024-04-26 11:08 ` Thomas Weißschuh 2024-04-26 11:08 ` [PATCH 3/3] selftests: kselftest: also use strerror() on nolibc Thomas Weißschuh 2024-05-02 16:10 ` [PATCH 0/3] tools/nolibc: implement strerror() Thomas Weißschuh 3 siblings, 0 replies; 9+ messages in thread From: Thomas Weißschuh @ 2024-04-26 11:08 UTC (permalink / raw) To: Willy Tarreau, Shuah Khan Cc: linux-kselftest, linux-kernel, Thomas Weißschuh 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 <linux@weissschuh.net> --- 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 */ -- 2.44.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/3] selftests: kselftest: also use strerror() on nolibc 2024-04-26 11:08 [PATCH 0/3] tools/nolibc: implement strerror() Thomas Weißschuh 2024-04-26 11:08 ` [PATCH 1/3] selftests/nolibc: introduce condition to run tests only on nolibc Thomas Weißschuh 2024-04-26 11:08 ` [PATCH 2/3] tools/nolibc: implement strerror() Thomas Weißschuh @ 2024-04-26 11:08 ` Thomas Weißschuh 2024-05-27 16:11 ` Thomas Weißschuh 2024-06-28 21:25 ` Shuah Khan 2024-05-02 16:10 ` [PATCH 0/3] tools/nolibc: implement strerror() Thomas Weißschuh 3 siblings, 2 replies; 9+ messages in thread From: Thomas Weißschuh @ 2024-04-26 11:08 UTC (permalink / raw) To: Willy Tarreau, Shuah Khan Cc: linux-kselftest, linux-kernel, Thomas Weißschuh nolibc gained an implementation of strerror() recently. Use it and drop the ifdeffery. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- 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, ...) -- 2.44.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] selftests: kselftest: also use strerror() on nolibc 2024-04-26 11:08 ` [PATCH 3/3] selftests: kselftest: also use strerror() on nolibc Thomas Weißschuh @ 2024-05-27 16:11 ` Thomas Weißschuh 2024-06-28 20:56 ` Shuah Khan 2024-06-28 21:25 ` Shuah Khan 1 sibling, 1 reply; 9+ messages in thread From: Thomas Weißschuh @ 2024-05-27 16:11 UTC (permalink / raw) To: Shuah Khan; +Cc: Willy Tarreau, linux-kselftest, linux-kernel Hi Shuah, Could you Ack the patch below to kselftest.h? Thanks, Thomas On 2024-04-26 13:08:58+0000, Thomas Weißschuh wrote: > nolibc gained an implementation of strerror() recently. > Use it and drop the ifdeffery. > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > --- > 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, ...) > > -- > 2.44.0 > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] selftests: kselftest: also use strerror() on nolibc 2024-05-27 16:11 ` Thomas Weißschuh @ 2024-06-28 20:56 ` Shuah Khan 0 siblings, 0 replies; 9+ messages in thread From: Shuah Khan @ 2024-06-28 20:56 UTC (permalink / raw) To: Thomas Weißschuh, Shuah Khan Cc: Willy Tarreau, linux-kselftest, linux-kernel, Shuah Khan On 5/27/24 10:11, Thomas Weißschuh wrote: > Hi Shuah, > > Could you Ack the patch below to kselftest.h? > > Thanks, > Thomas > > On 2024-04-26 13:08:58+0000, Thomas Weißschuh wrote: >> nolibc gained an implementation of strerror() recently. >> Use it and drop the ifdeffery. >> >> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> >> --- >> 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, ...) >> >> -- >> 2.44.0 >> Sorry - this git lost in my Inbox. Acked-by: Shuah Khan <skhan@linuxfoundation.org> thanks, -- Shuah ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] selftests: kselftest: also use strerror() on nolibc 2024-04-26 11:08 ` [PATCH 3/3] selftests: kselftest: also use strerror() on nolibc Thomas Weißschuh 2024-05-27 16:11 ` Thomas Weißschuh @ 2024-06-28 21:25 ` Shuah Khan 1 sibling, 0 replies; 9+ messages in thread From: Shuah Khan @ 2024-06-28 21:25 UTC (permalink / raw) To: Thomas Weißschuh, Willy Tarreau, Shuah Khan Cc: linux-kselftest, linux-kernel, Shuah Khan On 4/26/24 05:08, Thomas Weißschuh wrote: > nolibc gained an implementation of strerror() recently. > Use it and drop the ifdeffery. > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > --- > 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, ...) > Sorry for the delay o this. Acked-by: Shuah Khan <skhan@linuxfoundation.org> thanks, -- Shuah ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/3] tools/nolibc: implement strerror() 2024-04-26 11:08 [PATCH 0/3] tools/nolibc: implement strerror() Thomas Weißschuh ` (2 preceding siblings ...) 2024-04-26 11:08 ` [PATCH 3/3] selftests: kselftest: also use strerror() on nolibc Thomas Weißschuh @ 2024-05-02 16:10 ` Thomas Weißschuh 2024-06-28 21:46 ` Shuah Khan 3 siblings, 1 reply; 9+ messages in thread From: Thomas Weißschuh @ 2024-05-02 16:10 UTC (permalink / raw) To: Shuah Khan; +Cc: linux-kselftest, linux-kernel, Willy Tarreau Hi Shuah, On 2024-04-26 13:08:55+0000, Thomas Weißschuh wrote: > Adds a simple implementation of strerror() and makes use of it in > kselftests. > > Shuah, could you Ack patch 3? Friendly ping for an Ack of patch 3 of this series. After that I'd like to submit an updated nolibc pull request to you for 6.10. > Willy, this should work *without* your Ack. > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > --- > Thomas Weißschuh (3): > selftests/nolibc: introduce condition to run tests only on nolibc > tools/nolibc: implement strerror() > selftests: kselftest: also use strerror() on nolibc > > tools/include/nolibc/stdio.h | 10 ++++++++ > tools/testing/selftests/kselftest.h | 8 ------- > tools/testing/selftests/nolibc/nolibc-test.c | 36 ++++++++++++++++++---------- > 3 files changed, 33 insertions(+), 21 deletions(-) > --- > base-commit: a3063ba97f31e0364379a3ffc567203e3f79e877 > change-id: 20240425-nolibc-strerror-67f4bfa03035 > > Best regards, > -- > Thomas Weißschuh <linux@weissschuh.net> ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/3] tools/nolibc: implement strerror() 2024-05-02 16:10 ` [PATCH 0/3] tools/nolibc: implement strerror() Thomas Weißschuh @ 2024-06-28 21:46 ` Shuah Khan 0 siblings, 0 replies; 9+ messages in thread From: Shuah Khan @ 2024-06-28 21:46 UTC (permalink / raw) To: Thomas Weißschuh, Shuah Khan Cc: linux-kselftest, linux-kernel, Willy Tarreau, Shuah Khan On 5/2/24 10:10, Thomas Weißschuh wrote: > Hi Shuah, > > On 2024-04-26 13:08:55+0000, Thomas Weißschuh wrote: >> Adds a simple implementation of strerror() and makes use of it in >> kselftests. >> >> Shuah, could you Ack patch 3? > > Friendly ping for an Ack of patch 3 of this series. > > After that I'd like to submit an updated nolibc pull request to you for 6.10. > >> Willy, this should work *without* your Ack. >> >> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> >> --- >> Thomas Weißschuh (3): >> selftests/nolibc: introduce condition to run tests only on nolibc >> tools/nolibc: implement strerror() >> selftests: kselftest: also use strerror() on nolibc >> >> tools/include/nolibc/stdio.h | 10 ++++++++ >> tools/testing/selftests/kselftest.h | 8 ------- >> tools/testing/selftests/nolibc/nolibc-test.c | 36 ++++++++++++++++++---------- >> 3 files changed, 33 insertions(+), 21 deletions(-) >> --- >> base-commit: a3063ba97f31e0364379a3ffc567203e3f79e877 >> change-id: 20240425-nolibc-strerror-67f4bfa03035 >> >> Best regards, >> -- >> Thomas Weißschuh <linux@weissschuh.net> Sorry for the delay o this. Acked-by: Shuah Khan <skhan@linuxfoundation.org> thanks, -- Shuah ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-06-28 21:46 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-04-26 11:08 [PATCH 0/3] tools/nolibc: implement strerror() Thomas Weißschuh 2024-04-26 11:08 ` [PATCH 1/3] selftests/nolibc: introduce condition to run tests only on nolibc Thomas Weißschuh 2024-04-26 11:08 ` [PATCH 2/3] tools/nolibc: implement strerror() Thomas Weißschuh 2024-04-26 11:08 ` [PATCH 3/3] selftests: kselftest: also use strerror() on nolibc Thomas Weißschuh 2024-05-27 16:11 ` Thomas Weißschuh 2024-06-28 20:56 ` Shuah Khan 2024-06-28 21:25 ` Shuah Khan 2024-05-02 16:10 ` [PATCH 0/3] tools/nolibc: implement strerror() Thomas Weißschuh 2024-06-28 21:46 ` Shuah Khan
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox