Signed-off-by: Yuan Sun <[email protected]>
---
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));
+ }
+}
+
pid_t tst_vfork(void)
{
tst_flush();
diff --git a/testcases/kernel/containers/userns/userns01.c
b/testcases/kernel/containers/userns/userns01.c
index ad5c52d..74cc522 100644
--- a/testcases/kernel/containers/userns/userns01.c
+++ b/testcases/kernel/containers/userns/userns01.c
@@ -99,7 +99,6 @@ static void setup(void)
int main(int argc, char *argv[])
{
- int status;
int lc;
tst_parse_opts(argc, argv, NULL, NULL);
@@ -111,16 +110,8 @@ int main(int argc, char *argv[])
if (TEST_RETURN == -1)
tst_brkm(TFAIL | TTERRNO, NULL, "clone failed");
- else if ((wait(&status)) == -1)
- tst_brkm(TWARN | TERRNO, NULL, "wait failed");
-
- if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
- tst_resm(TFAIL, "child exited abnormally");
- else if (WIFSIGNALED(status)) {
- tst_resm(TFAIL, "child was killed with signal = %d",
- WTERMSIG(status));
- } else
- tst_resm(TPASS, "uid and gid are right");
+
+ tst_wait_record_childstatus(NULL);
}
tst_exit();
}
--
1.9.1
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list