From ed2df4e9845d58f46ec4405855036f25e8f72876 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Tue, 24 Jan 2012 23:28:39 -0200 Subject: [PATCH] testsuite: move oneshot to inside the test struct --- testsuite/testsuite.c | 24 ++++++++++++++++++------ testsuite/testsuite.h | 5 +---- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index dac79ac..57949ef 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -13,7 +13,7 @@ #include "testsuite.h" static const char *progname; -int oneshot = 0; +static int oneshot = 0; static const char options_short[] = "lhn"; static const struct option options[] = { { "list", no_argument, 0, 'l' }, @@ -86,7 +86,7 @@ const struct test *test_find(const struct test *tests[], const char *name) return NULL; } -int test_spawn_test(const struct test *t) +static int test_spawn_test(const struct test *t) { const char *const args[] = { progname, "-n", t->name, NULL }; @@ -96,6 +96,14 @@ int test_spawn_test(const struct test *t) return EXIT_FAILURE; } +static int test_run_spawned(const struct test *t) +{ + int err = t->func(t); + exit(err); + + return EXIT_FAILURE; +} + int test_spawn_prog(const char *prog, const char *args[]) { execv(prog, (char *const *) args); @@ -104,10 +112,7 @@ int test_spawn_prog(const char *prog, const char *args[]) return EXIT_FAILURE; } -int test_run_spawned(const struct test *t) { - int err = t->func(t); - exit(err); } int test_run(const struct test *t) @@ -115,6 +120,9 @@ int test_run(const struct test *t) int err; pid_t pid; + if (t->need_spawn && oneshot) + test_run_spawned(t); + LOG("running %s, in forked context\n", t->name); pid = fork(); @@ -142,5 +150,9 @@ int test_run(const struct test *t) /* kill child if parent dies */ prctl(PR_SET_PDEATHSIG, SIGTERM); - test_run_spawned(t); + + if (t->need_spawn) + return test_spawn_test(t); + else + return test_run_spawned(t); } diff --git a/testsuite/testsuite.h b/testsuite/testsuite.h index d7f8120..669b9d7 100644 --- a/testsuite/testsuite.h +++ b/testsuite/testsuite.h @@ -21,18 +21,15 @@ struct test { const char *description; testfunc func; const char *config[_TC_LAST]; + bool need_spawn; }; const struct test *test_find(const struct test *tests[], const char *name); int test_init(int argc, char *const argv[], const struct test *tests[]); -int test_spawn_test(const struct test *t); int test_spawn_prog(const char *prog, const char *args[]); int test_run(const struct test *t); -__attribute__((noreturn)) int test_run_spawned(const struct test *t); - -extern int oneshot; #define TS_EXPORT __attribute__ ((visibility("default")))