public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 1/2] lib/tst_res.c: introduce tst_record_childstatus()
@ 2014-07-13  5:49 Xiaoguang Wang
  2014-07-13  5:49 ` [LTP] [PATCH v2 2/2] syscalls: fix testcases which take TCONF as TFAIL Xiaoguang Wang
  2014-07-15 14:24 ` [LTP] [PATCH v2 1/2] lib/tst_res.c: introduce tst_record_childstatus() chrubis
  0 siblings, 2 replies; 10+ messages in thread
From: Xiaoguang Wang @ 2014-07-13  5:49 UTC (permalink / raw)
  To: ltp-list

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 <wangxg.fnst@cn.fujitsu.com>
---
 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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2014-07-29 10:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-13  5:49 [LTP] [PATCH v2 1/2] lib/tst_res.c: introduce tst_record_childstatus() Xiaoguang Wang
2014-07-13  5:49 ` [LTP] [PATCH v2 2/2] syscalls: fix testcases which take TCONF as TFAIL Xiaoguang Wang
2014-07-15 14:24 ` [LTP] [PATCH v2 1/2] lib/tst_res.c: introduce tst_record_childstatus() chrubis
     [not found]   ` <53CCA4B9.2070005@cn.fujitsu.com>
2014-07-22 14:30     ` chrubis
2014-07-28 11:51       ` [LTP] [PATCH v3 1/3] " Xiaoguang Wang
2014-07-28 11:51         ` [LTP] [PATCH v3 2/3] doc: add paragraph to describe using test interface in child process Xiaoguang Wang
2014-07-29  9:58           ` chrubis
2014-07-28 11:51         ` [LTP] [PATCH v3 3/3] syscalls: fix testcases which take TCONF as TFAIL Xiaoguang Wang
2014-07-29 10:09           ` chrubis
2014-07-29  9:56         ` [LTP] [PATCH v3 1/3] lib/tst_res.c: introduce tst_record_childstatus() chrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox