summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorZhangjin Wu <falcon@tinylab.org>2023-05-30 09:03:33 +0300
committerPaul E. McKenney <paulmck@kernel.org>2023-06-09 21:46:09 +0300
commited495f0945e732c55bb8c21e660c2c86f5e57812 (patch)
tree19a72d8a116000f77800e7b45b443ef04a6dc615 /tools
parent0dd2fdbfa59373a77b4d6ba82027b60700b6a0a0 (diff)
downloadlinux-ed495f0945e732c55bb8c21e660c2c86f5e57812.tar.xz
selftests/nolibc: test_fork: fix up duplicated print
running nolibc-test with glibc on x86_64 got such print issue: 29 execve_root = -1 EACCES [OK] 30 fork30 fork = 0 [OK] 31 getdents64_root = 712 [OK] The fork test case has three printf calls: (1) llen += printf("%d %s", test, #name); (2) llen += printf(" = %d %s ", expr, errorname(errno)); (3) llen += pad_spc(llen, 64, "[FAIL]\n"); --> vfprintf() In the following scene, the above issue happens: (a) The parent calls (1) (b) The parent calls fork() (c) The child runs and shares the print buffer of (1) (d) The child exits, flushs the print buffer and closes its own stdout/stderr * "30 fork" is printed at the first time. (e) The parent calls (2) and (3), with "\n" in (3), it flushs the whole buffer * "30 fork = 0 ..." is printed Therefore, there are two "30 fork" in the stdout. Between (a) and (b), if flush the stdout (and the sterr), the child in stage (c) will not be able to 'see' the print buffer. Signed-off-by: Zhangjin Wu <falcon@tinylab.org> Reviewed-by: Thomas Weißschuh <linux@weissschuh.net> Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/nolibc/nolibc-test.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index d417ca5d976f..fa18e7dc35c8 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -486,7 +486,13 @@ static int test_getpagesize(void)
static int test_fork(void)
{
int status;
- pid_t pid = fork();
+ pid_t pid;
+
+ /* flush the printf buffer to avoid child flush it */
+ fflush(stdout);
+ fflush(stderr);
+
+ pid = fork();
switch (pid) {
case -1: