In case we need do real test work in child porcess, it is OK for child process
to use tst_resm(), tst_brkm() or tst_exit(). Parent process can use
tst_record_childstatus() to make child process's test results propagated to 
parent
process correctly.

Meanwhile we reset T_exitval to 0 for child process in tst_fork(), which will
make child process can record test results with tst_resm() or tst_brkm() 
correctly.

Signed-off-by: Xiaoguang Wang <[email protected]>
---
 include/test.h | 10 ++++++++++
 lib/tst_res.c  | 29 ++++++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/include/test.h b/include/test.h
index 011866d..3672a8c 100644
--- a/include/test.h
+++ b/include/test.h
@@ -135,9 +135,19 @@ void tst_flush(void);
 
 /*
  * tst_flush() + fork
+ * NOTE: tst_fork() will reset T_exitval to 0 for child process.
  */
 pid_t tst_fork(void);
 
+/* lib/tst_res.c */
+/*
+ * In case we need do real test work in child porcess, it is OK for
+ * child process to use tst_resm(), tst_brkm() or tst_exit(). Parent
+ * process can use tst_record_childstatus() to make child process's
+ * test results propagated to parent process correctly.
+ */
+void tst_record_childstatus(void (*cleanup)(void), pid_t child);
+
 extern int tst_count;
 
 /* lib/tst_sig.c */
diff --git a/lib/tst_res.c b/lib/tst_res.c
index 31186e0..35eefa3 100644
--- a/lib/tst_res.c
+++ b/lib/tst_res.c
@@ -101,6 +101,9 @@
 #include <stdarg.h>
 #include <string.h>
 #include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
 #include "test.h"
 #include "usctest.h"
 #include "ltp_priv.h"
@@ -568,8 +571,32 @@ void tst_exit(void)
 
 pid_t tst_fork(void)
 {
+       pid_t child;
+
        tst_flush();
-       return fork();
+
+       child = fork();
+       if (child == 0)
+               T_exitval = 0;
+
+       return child;
+}
+
+void tst_record_childstatus(void (*cleanup)(void), pid_t child)
+{
+       int status, ttype_result;
+
+       if (waitpid(child, &status, 0) < 0)
+               tst_brkm(TBROK | TERRNO, cleanup, "waitpid(%d) failed", child);
+
+       if (WIFEXITED(status)) {
+               ttype_result = WEXITSTATUS(status);
+               ttype_result = TTYPE_RESULT(ttype_result);
+               T_exitval |= ttype_result;
+       } else {
+               tst_brkm(TBROK, cleanup, "child process(%d) killed by "
+                        "unexpected signal", child);
+       }
 }
 
 pid_t tst_vfork(void)
-- 
1.8.2.1


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to