From: Dave Reisner Date: Wed, 15 Feb 2012 02:49:26 +0000 (-0500) Subject: testsuite: add .path member to test struct X-Git-Tag: v6~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f31d49c8b3a8ef863a6d6401b98b9e59a29ea53d;p=thirdparty%2Fkmod.git testsuite: add .path member to test struct 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. --- diff --git a/TODO b/TODO index 4f5e7c80..315878ea 100644 --- 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 diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index 56e73ee8..f22914fb 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -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(); diff --git a/testsuite/testsuite.h b/testsuite/testsuite.h index 60936836..be3bfb85 100644 --- a/testsuite/testsuite.h +++ b/testsuite/testsuite.h @@ -82,6 +82,7 @@ struct test { } output; testfunc func; const char *config[_TC_LAST]; + const char *path; bool need_spawn; bool expected_fail; };