37static int _rw_child = 0;
38static int _rw_timeout = 5;
40static char arg1[] =
"--child=1";
41static char arg2[] =
"--no-stdout";
43static char* args [] = { 0, arg1, arg2, 0 };
44static const int nargs =
sizeof (args) /
sizeof (*args) - 1;
48static int join_test (
rw_pid_t pid,
bool should_hang)
54 "rw_waitpid() failed, errno = %{#m}");
73 rw_assert (should_hang, __FILE__, __LINE__,
74 "The child process unexpectedly deadlocked");
76 return should_hang ? 0 : 1;
79 rw_assert (!should_hang, __FILE__, __LINE__,
80 "Expected the deadlocked process, but process exited "
86 "Process exit code: expected 0, got %d",
result);
91static int test_process_create1 ()
94 "Exercising the rw_process_create "
95 "(const char*, char* const []) overload");
100 "rw_process_create() failed, errno = %{#m}");
109 return join_test (pid,
false);
112static int test_process_create2 ()
115 "Exercising the rw_process_create (const char*, ...) overload");
118 args[0], args[1], args[2]);
120 rw_assert (-1 != pid, __FILE__, __LINE__,
121 "rw_process_create() failed, errno = %{#m}");
130 return join_test (pid,
false);
133static int test_process_deadlocked ()
136 "Exercising the rw_waitpid() with timeout and deadlocked process");
141 rw_assert (-1 != pid, __FILE__, __LINE__,
142 "rw_process_create() failed, errno = %{#m}");
144 return -1 == pid ? 1 : join_test (pid,
true);
147static int test_process_create_fail ()
150 "Exercising the rw_process_create() behavior "
151 "when invalid path specified");
161 rw_assert (-1 == pid, __FILE__, __LINE__,
162 "rw_process_create returns %ld, expected -1",
171 "errno: expected ENOENT, got %{#m}");
173 return ENOENT == errno ? 0 : 1;
176static int test_waitpid_fail ()
180 "The test, exercising the rw_waitpid() behavior "
181 "when invalid pid specified is disabled");
187 "Exercising the rw_waitpid() behavior "
188 "when invalid pid specified");
198 rw_assert (-1 == pid, __FILE__, __LINE__,
199 "rw_waitpid returns %ld, expected -1",
206 "errno: expected ECHILD, got %{#m}");
208 return ECHILD == errno ? 0 : 1;
211static int test_process_kill_fail ()
215 "The test, exercising the rw_process_kill() behavior "
216 "when invalid pid specified is disabled");
222 "Exercising the rw_process_kill() behavior "
223 "when invalid pid specified");
234 "rw_process_kill returns %ld, expected -1",
241 "errno: expected ESRCH, got %{#m}");
243 return ESRCH == errno ? 0 : 1;
252 "The child process: _rw_child = %i", _rw_child);
254 if (2 == _rw_child) {
264 for (
int i = 1;
i < argc; ++
i) {
265 if (0 != strcmp (argv [
i], args [
i]))
276 if (test_process_create1 ())
279 if (test_process_create2 ())
282 if (test_process_deadlocked ())
285 if (test_process_create_fail ())
288 if (test_waitpid_fail ())
291 if (test_process_kill_fail ())
297int main (
int argc,
char *argv[])
299 return rw_test (argc, argv, __FILE__,
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT bool rw_enable(int(*fun)(int, const char *, int, const char *,...), bool enable=true)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_error(int, const char *, int, const char *,...)
_TEST_EXPORT rw_pid_t rw_process_create(const char *,...)
_TEST_EXPORT rw_pid_t rw_waitpid(rw_pid_t, int *, int=-1)
_TEST_EXPORT int rw_process_kill(rw_pid_t, int=-1)