diff options
author | Martin Pitt <martin@piware.de> | 2017-02-12 23:14:43 +0100 |
---|---|---|
committer | Martin Pitt <martin@piware.de> | 2017-02-13 22:31:13 +0100 |
commit | f853c6efb509589c8e3a82caa3af2ac5a370ae97 (patch) | |
tree | 4b5e46c4dfc6a9dfd701db8c29975d546b0b9ece /src/test | |
parent | ee3c7ff7c303cdbc8fea18d3a6f3c4c6e7c450d8 (diff) | |
download | systemd-f853c6efb509589c8e3a82caa3af2ac5a370ae97.tar.gz |
test: make unit tests relocatable
It is useful to package test-* binaries and run them as root under
autopkgtest or manually on particular machines. They currently have a
built-in hardcoded absolute path to their test data, which does not work
when running the test programs from any other path than the original
build directory.
By default, make the tests look for their data in
<test_exe_directory>/testdata/ so that they can be called from any
directory (provided that the corresponding test data is installed
correctly). As we don't have a fixed static path in the build tree (as
build and source tree are independent), set $TEST_DIR with "make check"
to point to <srcdir>/test/, as we previously did with an automake
variable.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-cgroup-mask.c | 2 | ||||
-rw-r--r-- | src/test/test-engine.c | 2 | ||||
-rw-r--r-- | src/test/test-execute.c | 2 | ||||
-rw-r--r-- | src/test/test-helper.h | 5 | ||||
-rw-r--r-- | src/test/test-path.c | 2 | ||||
-rw-r--r-- | src/test/test-sched-prio.c | 2 |
6 files changed, 10 insertions, 5 deletions
diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c index a027eb0fd2..630587aaf1 100644 --- a/src/test/test-cgroup-mask.c +++ b/src/test/test-cgroup-mask.c @@ -34,7 +34,7 @@ static int test_cgroup_mask(void) { int r; /* Prepare the manager. */ - assert_se(set_unit_path(TEST_DIR) >= 0); + assert_se(set_unit_path(TEST_DATA_DIR("")) >= 0); r = manager_new(UNIT_FILE_USER, true, &m); if (r == -EPERM || r == -EACCES) { puts("manager_new: Permission denied. Skipping test."); diff --git a/src/test/test-engine.c b/src/test/test-engine.c index a651f6b683..3ec2dfe10e 100644 --- a/src/test/test-engine.c +++ b/src/test/test-engine.c @@ -40,7 +40,7 @@ int main(int argc, char *argv[]) { assert_se(runtime_dir = setup_fake_runtime_dir()); /* prepare the test */ - assert_se(set_unit_path(TEST_DIR) >= 0); + assert_se(set_unit_path(TEST_DATA_DIR("")) >= 0); r = manager_new(UNIT_FILE_USER, true, &m); if (MANAGER_SKIP_TEST(r)) { log_notice_errno(r, "Skipping test: manager_new: %m"); diff --git a/src/test/test-execute.c b/src/test/test-execute.c index 3a3ab3eb94..145aa37a66 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -516,7 +516,7 @@ int main(int argc, char *argv[]) { } assert_se(setenv("XDG_RUNTIME_DIR", "/tmp/", 1) == 0); - assert_se(set_unit_path(TEST_DIR "/test-execute/") >= 0); + assert_se(set_unit_path(TEST_DATA_DIR("/test-execute/")) >= 0); /* Unset VAR1, VAR2 and VAR3 which are used in the PassEnvironment test * cases, otherwise (and if they are present in the environment), diff --git a/src/test/test-helper.h b/src/test/test-helper.h index ddb10f88fd..4e633ae6d8 100644 --- a/src/test/test-helper.h +++ b/src/test/test-helper.h @@ -20,6 +20,8 @@ ***/ #include "sd-daemon.h" +#include "string-util.h" +#include "tests.h" #include "macro.h" @@ -39,3 +41,6 @@ -ENOENT, \ -ENOMEDIUM /* cannot determine cgroup */ \ ) + +#define TEST_DATA_DIR(subdir) \ + strjoina(getenv("TEST_DIR") ?: get_exe_relative_testdata_dir(), subdir) diff --git a/src/test/test-path.c b/src/test/test-path.c index 5e99d478ee..d09df3e8a5 100644 --- a/src/test/test-path.c +++ b/src/test/test-path.c @@ -263,7 +263,7 @@ int main(int argc, char *argv[]) { log_open(); assert_se(runtime_dir = setup_fake_runtime_dir()); - assert_se(set_unit_path(TEST_DIR "/test-path/") >= 0); + assert_se(set_unit_path(TEST_DATA_DIR("/test-path/")) >= 0); for (test = tests; test && *test; test++) { int r; diff --git a/src/test/test-sched-prio.c b/src/test/test-sched-prio.c index 7b37910c33..dab64fea57 100644 --- a/src/test/test-sched-prio.c +++ b/src/test/test-sched-prio.c @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) { assert_se(runtime_dir = setup_fake_runtime_dir()); /* prepare the test */ - assert_se(set_unit_path(TEST_DIR) >= 0); + assert_se(set_unit_path(TEST_DATA_DIR("")) >= 0); r = manager_new(UNIT_FILE_USER, true, &m); if (MANAGER_SKIP_TEST(r)) { log_notice_errno(r, "Skipping test: manager_new: %m"); |