All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests/nolibc: test_fork: fix up duplicated print
@ 2023-05-30  6:03 Zhangjin Wu
  2023-06-02  2:41 ` Zhangjin Wu
  0 siblings, 1 reply; 4+ messages in thread
From: Zhangjin Wu @ 2023-05-30  6:03 UTC (permalink / raw)
  To: w; +Cc: thomas, falcon, linux-kernel, linux-kselftest

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>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 7de46305f419..88323a60aa4a 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:
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] selftests/nolibc: test_fork: fix up duplicated print
  2023-05-30  6:03 [PATCH] selftests/nolibc: test_fork: fix up duplicated print Zhangjin Wu
@ 2023-06-02  2:41 ` Zhangjin Wu
  2023-06-02 10:20   ` Thomas Weißschuh
  0 siblings, 1 reply; 4+ messages in thread
From: Zhangjin Wu @ 2023-06-02  2:41 UTC (permalink / raw)
  To: falcon, thomas, w; +Cc: linux-kernel, linux-kselftest

Hi, Willy

What about this one for 2023xxxx-nolibc-rv32+stkp6?

@Thomas, welcome your Reviewed-by If it is ok for you ;-)

Best regards,
Zhangjin

> 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>
> ---
>  tools/testing/selftests/nolibc/nolibc-test.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> index 7de46305f419..88323a60aa4a 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:
> -- 
> 2.25.1
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] selftests/nolibc: test_fork: fix up duplicated print
  2023-06-02  2:41 ` Zhangjin Wu
@ 2023-06-02 10:20   ` Thomas Weißschuh
  2023-06-04 10:47     ` Willy Tarreau
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Weißschuh @ 2023-06-02 10:20 UTC (permalink / raw)
  To: Zhangjin Wu; +Cc: w, linux-kernel, linux-kselftest

On 2023-06-02 10:41:57+0800, Zhangjin Wu wrote:
> Hi, Willy
> 
> What about this one for 2023xxxx-nolibc-rv32+stkp6?
> 
> @Thomas, welcome your Reviewed-by If it is ok for you ;-)

Indeed, good catch!

Reviewed-by: Thomas Weißschuh <linux@weissschuh.net>

> Best regards,
> Zhangjin
> 
> > 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>
> > ---
> >  tools/testing/selftests/nolibc/nolibc-test.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> > index 7de46305f419..88323a60aa4a 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:
> > -- 
> > 2.25.1
> > 
> > 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] selftests/nolibc: test_fork: fix up duplicated print
  2023-06-02 10:20   ` Thomas Weißschuh
@ 2023-06-04 10:47     ` Willy Tarreau
  0 siblings, 0 replies; 4+ messages in thread
From: Willy Tarreau @ 2023-06-04 10:47 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: Zhangjin Wu, linux-kernel, linux-kselftest

On Fri, Jun 02, 2023 at 12:20:34PM +0200, Thomas Weißschuh wrote:
> On 2023-06-02 10:41:57+0800, Zhangjin Wu wrote:
> > Hi, Willy
> > 
> > What about this one for 2023xxxx-nolibc-rv32+stkp6?
> > 
> > @Thomas, welcome your Reviewed-by If it is ok for you ;-)
> 
> Indeed, good catch!
> 
> Reviewed-by: Thomas Weißschuh <linux@weissschuh.net>

And queued, thanks to you both!
Willy

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-04 10:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-30  6:03 [PATCH] selftests/nolibc: test_fork: fix up duplicated print Zhangjin Wu
2023-06-02  2:41 ` Zhangjin Wu
2023-06-02 10:20   ` Thomas Weißschuh
2023-06-04 10:47     ` Willy Tarreau

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.