From: Lucas De Marchi Date: Wed, 25 Jan 2012 18:01:17 +0000 (-0200) Subject: testsuite: separate child from parent X-Git-Tag: v5~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45481ee28c44c66a25015b7682f355d093c3b94a;p=thirdparty%2Fkmod.git testsuite: separate child from parent --- diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index 0f9a361e..1f483d60 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -160,9 +160,41 @@ static void test_export_environ(const struct test *t) free(preload); } -int test_run(const struct test *t) +static inline int test_run_child(const struct test *t) { + /* kill child if parent dies */ + prctl(PR_SET_PDEATHSIG, SIGTERM); + + test_export_environ(t); + + if (t->need_spawn) + return test_spawn_test(t); + else + return test_run_spawned(t); +} + +static inline int test_run_parent(const struct test *t) +{ + pid_t pid; int err; + + do { + pid = wait(&err); + if (pid == -1) { + ERR("error waitpid(): %m\n"); + return EXIT_FAILURE; + } + } while (!WIFEXITED(err) && !WIFSIGNALED(err)); + + if (err != 0) + ERR("error while running %s\n", t->name); + + LOG("%s: %s\n", err == 0 ? "PASSED" : "FAILED", t->name); + return err; +} + +int test_run(const struct test *t) +{ pid_t pid; if (t->need_spawn && oneshot) @@ -177,29 +209,8 @@ int test_run(const struct test *t) return EXIT_FAILURE; } - if (pid > 0) { - do { - pid = wait(&err); - if (pid == -1) { - ERR("error waitpid(): %m\n"); - return EXIT_FAILURE; - } - } while (!WIFEXITED(err) && !WIFSIGNALED(err)); - - if (err != 0) - ERR("error while running %s\n", t->name); - - LOG("%s: %s\n", err == 0 ? "PASSED" : "FAILED", t->name); - return err; - } + if (pid > 0) + return test_run_parent(t); - /* kill child if parent dies */ - prctl(PR_SET_PDEATHSIG, SIGTERM); - - test_export_environ(t); - - if (t->need_spawn) - return test_spawn_test(t); - else - return test_run_spawned(t); + return test_run_child(t); }