]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite: move oneshot to inside the test struct
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Wed, 25 Jan 2012 01:28:39 +0000 (23:28 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Thu, 26 Jan 2012 18:05:04 +0000 (16:05 -0200)
testsuite/testsuite.c
testsuite/testsuite.h

index dac79ac345413f7159c527e4ef0563d2b1f235bf..57949ef78bef6db29c22b4ca783fd24a8bf1b2d9 100644 (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);
 }
index d7f81203cf3d2389d2d0534131b1cf0a85bff544..669b9d70728c750e9b39ddc79ceb9c7a3570d9ca 100644 (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")))