]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
selftests/nolibc: use snprintf() for printf tests
authorThomas Weißschuh <thomas.weissschuh@linutronix.de>
Fri, 11 Apr 2025 09:00:52 +0000 (11:00 +0200)
committerThomas Weißschuh <linux@weissschuh.net>
Tue, 22 Apr 2025 08:59:04 +0000 (10:59 +0200)
With a proper snprintf() implementation in place, the ugly pipe usage is
not necessary anymore.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
tools/testing/selftests/nolibc/nolibc-test.c

index 64f88b49202992e5bbd6dee77c8e5389422651b6..1874199b2cf641d9f231147b338d211c27600caa 100644 (file)
@@ -1299,27 +1299,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) {
@@ -1328,17 +1315,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);