From dbb122d157af41515c03bb5da227832930730719 Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Wed, 6 Jul 2011 10:21:33 -0700 Subject: [PATCH] systest_runnable: implement processes Implement process-based tests as an alternative to threads. Signed-off-by: Colin McCabe --- src/test/system/systest_runnable.cc | 54 +++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/src/test/system/systest_runnable.cc b/src/test/system/systest_runnable.cc index 000022d772eb7..ea89ea8850f67 100644 --- a/src/test/system/systest_runnable.cc +++ b/src/test/system/systest_runnable.cc @@ -12,6 +12,7 @@ * */ +#include "common/errno.h" #include "include/atomic.h" #include "systest_runnable.h" #include "systest_settings.h" @@ -26,6 +27,7 @@ #include #include #include +#include #include using std::ostringstream; @@ -75,9 +77,22 @@ start() return 0; } else { - // TODO: implement - // m_pid = ??? - return -ENOTSUP; + pid_t pid = fork(); + if (pid == -1) { + int err = errno; + return -err; + } + else if (pid == 0) { + m_started = true; + m_pid = getpid(); + void *retptr = systest_runnable_pthread_helper(static_cast(this)); + exit((int)(uintptr_t)retptr); + } + else { + m_started = true; + m_pid = pid; + return 0; + } } } @@ -105,9 +120,34 @@ join() return ""; } else { - // TODO: implement - // m_pid = ??? - return "processes not supported yet"; + int status; + printf("waitpid(%d)\n", m_pid); + pid_t pid = waitpid(m_pid, &status, 0); + if (pid == -1) { + int err = errno; + ostringstream oss; + oss << get_id_str() << " waitpid error: " << cpp_strerror(err); + return oss.str(); + } + else if (WIFSIGNALED(status)) { + ostringstream oss; + oss << get_id_str() << " exited with a signal"; + return oss.str(); + } + else if (!WIFEXITED(status)) { + ostringstream oss; + oss << get_id_str() << " did not exit normally"; + return oss.str(); + } + else { + int exit_status = WEXITSTATUS(status); + if (exit_status != 0) { + ostringstream oss; + oss << get_id_str() << " returned exit_status " << exit_status; + return oss.str(); + } + return ""; + } } } @@ -152,7 +192,7 @@ run_until_finished(std::vector < SysTestRunnable * > &runnables) if (!rstr.empty()) { ostringstream oss; oss << "run_until_finished: runnable " << (*r)->get_id_str() - << ": got error " << rstr; + << ": got error: " << rstr; return oss.str(); } } -- 2.39.5