selftests/nolibc: reduce syscalls during space padding
authorThomas Weißschuh <linux@weissschuh.net>
Mon, 17 Apr 2023 16:01:31 +0000 (18:01 +0200)
committerPaul E. McKenney <paulmck@kernel.org>
Fri, 9 Jun 2023 18:46:08 +0000 (11:46 -0700)
Previously each space character used for alignment during test execution
was written in a single write() call.
This would make the output from strace fairly unreadable.
Coalesce all spaces into a single call to write().

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
tools/testing/selftests/nolibc/nolibc-test.c

index 0e2ee513b273bf6fecb82b60ce1279600b269463..d5d4dea63cd6fb2d3ac07f9a0464d919ffb13c25 100644 (file)
@@ -111,19 +111,26 @@ const char *errorname(int err)
        }
 }
 
+static void putcharn(char c, size_t n)
+{
+       char buf[64];
+
+       memset(buf, c, n);
+       buf[n] = '\0';
+       fputs(buf, stdout);
+}
+
 static int pad_spc(int llen, int cnt, const char *fmt, ...)
 {
        va_list args;
-       int len;
        int ret;
 
-       for (len = 0; len < cnt - llen; len++)
-               putchar(' ');
+       putcharn(' ', cnt - llen);
 
        va_start(args, fmt);
        ret = vfprintf(stdout, fmt, args);
        va_end(args);
-       return ret < 0 ? ret : ret + len;
+       return ret < 0 ? ret : ret + cnt - llen;
 }
 
 /* The tests below are intended to be used by the macroes, which evaluate