Hi!
> Signed-off-by: Yuan Sun <sunyu...@huawei.com>
> ---
>  doc/test-writing-guidelines.txt               |  7 +++---
>  include/test.h                                |  2 ++
>  lib/tst_res.c                                 | 31 
> +++++++++++++++++++++++++++
>  testcases/kernel/containers/userns/userns01.c | 13 ++---------
>  4 files changed, 39 insertions(+), 14 deletions(-)
> 
> diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
> index 69b8cb7..8b46a19 100644
> --- a/doc/test-writing-guidelines.txt
> +++ b/doc/test-writing-guidelines.txt
> @@ -631,15 +631,16 @@ If you have to do the test in a child process you have 
> two possibilities:
>  * Or you can stick to plain old 'exit()' with 'TPASS', 'TBROK', 'TFAIL' and
>    'TCONF' constants.
>  
> -Then you call 'tst_record_childstatus()' to records the result of the test
> -(done in child process) which propagates the child result (child exit status)
> -to the parent process correctly.
> +Then you call 'tst_record_childstatus()' or 'tst_wait_record_childstatus' to
> +records the result of the test (done in child process) which propagates the
> +child result (child exit status) to the parent process correctly.
>  
>  [source,c]
>  
> -------------------------------------------------------------------------------
>  #include "test.h"
>  
>  void tst_record_childstatus(void (*cleanup)(void), pid_t child);
> +void tst_wait_record_childstatus(void (*cleanup)(void));
>  
> -------------------------------------------------------------------------------
>  
>  This function does a 'waitpid()' on child process and record child process's
> diff --git a/include/test.h b/include/test.h
> index ac00590..15b2139 100644
> --- a/include/test.h
> +++ b/include/test.h
> @@ -194,6 +194,8 @@ pid_t tst_fork(void);
>   */
>  void tst_record_childstatus(void (*cleanup)(void), pid_t child);
>  
> +void tst_wait_record_childstatus(void (*cleanup)(void));
> +
>  extern int tst_count;
>  
>  /* lib/tst_sig.c */
> diff --git a/lib/tst_res.c b/lib/tst_res.c
> index 7a64a50..f21c1d2 100644
> --- a/lib/tst_res.c
> +++ b/lib/tst_res.c
> @@ -572,6 +572,37 @@ void tst_record_childstatus(void (*cleanup)(void), pid_t 
> child)
>       }
>  }
>  
> +void tst_wait_record_childstatus(void (*cleanup)(void))
> +{
> +     int status, ttype_result;
> +
> +     if (wait(&status) < 0)
> +             tst_brkm(TWARN | TERRNO, NULL, "wait failed");
> +
> +     if (WIFEXITED(status)) {
> +             ttype_result = WEXITSTATUS(status);
> +             ttype_result = TTYPE_RESULT(ttype_result);
> +             T_exitval |= ttype_result;
> +
> +             if (ttype_result == TPASS)
> +                     tst_resm(TINFO, "Child process returned TPASS");
> +
> +             if (ttype_result & TFAIL)
> +                     tst_resm(TINFO, "Child process returned TFAIL");
> +
> +             if (ttype_result & TBROK)
> +                     tst_resm(TINFO, "Child process returned TBROK");
> +
> +             if (ttype_result & TCONF)
> +                     tst_resm(TINFO, "Child process returned TCONF");
> +
> +     } else {
> +             tst_brkm(TBROK, cleanup, "child process killed by "
> +                      "unexpected signal %s(%d)",
> +                      tst_strsig(WTERMSIG(status)), WTERMSIG(status));
> +     }
> +}

There is no need for this. If you pass -1 as pid to waitpid() it's the
same as calling wait().

-- 
Cyril Hrubis
chru...@suse.cz

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to