2024-04-26 11:09:53

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH 0/3] tools/nolibc: implement strerror()

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 <[email protected]>
---
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 <[email protected]>



2024-04-26 11:09:57

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH 2/3] tools/nolibc: implement strerror()

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 <[email protected]>
---
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


2024-05-02 16:17:50

by Thomas Weißschuh

[permalink] [raw]
Subject: Re: [PATCH 0/3] tools/nolibc: implement strerror()

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 <[email protected]>
> ---
> 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 <[email protected]>