[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250407-nolibc-kselftest-harness-v2-28-f8812f76e930@linutronix.de>
Date: Mon, 07 Apr 2025 08:52:51 +0200
From: Thomas Weißschuh <thomas.weissschuh@...utronix.de>
To: Shuah Khan <shuah@...nel.org>, Shuah Khan <skhan@...uxfoundation.org>,
Willy Tarreau <w@....eu>,
Thomas Weißschuh <linux@...ssschuh.net>
Cc: linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org,
Thomas Weißschuh <thomas.weissschuh@...utronix.de>
Subject: [PATCH v2 28/32] selftests/nolibc: use snprintf() for printf tests
With a proper snprintf() implementation in place, the ugly pipe usage is
not necessary anymore.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@...utronix.de>
Acked-by: Willy Tarreau <w@....eu>
---
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);
--
2.49.0
Powered by blists - more mailing lists