]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite: add .path member to test struct
authorDave Reisner <dreisner@archlinux.org>
Wed, 15 Feb 2012 02:49:26 +0000 (21:49 -0500)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Thu, 16 Feb 2012 18:52:38 +0000 (16:52 -0200)
This allows us to prepend an arbitrary item to the PATH environment
variable, meaning we can favor the binaries we just built, rather than
relying on those in the filesystem.

TODO
testsuite/testsuite.c
testsuite/testsuite.h

diff --git a/TODO b/TODO
index 4f5e7c80c9d8fdbfe7dfd67e43d148a76b711e5c..315878ea0dcecdc491540054a62ecc9bfadd9ffb 100644 (file)
--- a/TODO
+++ b/TODO
@@ -39,7 +39,6 @@ Features:
 * Stop using system() inside the library and use fork + exec instead
 
 * testsuite:
-   - allow to set PATH, so install commands can contain tools in them
    - when fake init_module() succeeds, create an entry in /sys/module
    - when fake delete_module() succeeds, remove its entry from /sys/module
    - add test for dependency loop _with install commands_ relying on module
index 56e73ee8f1e357e3ac59b796d23b5ff280112def..f22914fbefac48ae11e81beaeed0cc5afcdb2c50 100644 (file)
@@ -445,6 +445,29 @@ static inline int test_run_parent(const struct test *t, int fdout[2],
        return err;
 }
 
+static int prepend_path(const char *extra)
+{
+       char *oldpath, *newpath;
+       int r;
+
+       if (extra == NULL)
+               return 0;
+
+       oldpath = getenv("PATH");
+       if (oldpath == NULL)
+               return setenv("PATH", extra, 1);
+
+       if (asprintf(&newpath, "%s:%s", extra, oldpath) < 0) {
+               ERR("failed to allocate memory to new PATH");
+               return -1;
+       }
+
+       r = setenv("PATH", newpath, 1);
+       free(newpath);
+
+       return r;
+}
+
 int test_run(const struct test *t)
 {
        pid_t pid;
@@ -468,6 +491,11 @@ int test_run(const struct test *t)
                }
        }
 
+       if (prepend_path(t->path) < 0) {
+               ERR("failed to prepend '%s' to PATH\n", t->path);
+               return EXIT_FAILURE;
+       }
+
        LOG("running %s, in forked context\n", t->name);
 
        pid = fork();
index 609368364218ed532787d6923e8553065d37e169..be3bfb85c893a490c1fe621ee870b82803f146a7 100644 (file)
@@ -82,6 +82,7 @@ struct test {
        } output;
        testfunc func;
        const char *config[_TC_LAST];
+       const char *path;
        bool need_spawn;
        bool expected_fail;
 };