testsuite: move oneshot to inside the test struct

This commit is contained in:
Lucas De Marchi 2012-01-24 23:28:39 -02:00
parent 68cc449376
commit ed2df4e984
2 changed files with 19 additions and 10 deletions

View File

@ -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);
}

View File

@ -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")))