summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-02-14 21:49:26 -0500
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2012-02-16 16:52:38 -0200
commitf31d49c8b3a8ef863a6d6401b98b9e59a29ea53d (patch)
treecd46396c765f2a2cb49a1683bf27544c517423ce /testsuite
parentf6301b65bd585a614fc72ecb130b99adc9eb2fe3 (diff)
downloadkmod-f31d49c8b3a8ef863a6d6401b98b9e59a29ea53d.tar.gz
kmod-f31d49c8b3a8ef863a6d6401b98b9e59a29ea53d.tar.bz2
kmod-f31d49c8b3a8ef863a6d6401b98b9e59a29ea53d.zip
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.
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/testsuite.c28
-rw-r--r--testsuite/testsuite.h1
2 files changed, 29 insertions, 0 deletions
diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c
index 56e73ee..f22914f 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 6093683..be3bfb8 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;
};