summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pitt <martin@piware.de>2017-02-14 22:33:52 +0100
committerMartin Pitt <martin@piware.de>2017-02-16 21:36:30 +0100
commit3e29e810ae48c96c17fdaca7ce9da9378eb4056d (patch)
treef173b2beaa5f6b821a6ffd56b09ca23fb3e8791e
parent31f8b331c77160019bb282c8b722ace5c9c290d4 (diff)
test: setup test data dir before fake runtime dir
That way, if the test directory does not exist we don't leave behind temporary files (as in that case or on test failure the cleanup actions don't run).
-rw-r--r--src/test/test-cgroup-mask.c4
-rw-r--r--src/test/test-engine.c3
-rw-r--r--src/test/test-path.c2
-rw-r--r--src/test/test-sched-prio.c3
4 files changed, 5 insertions, 7 deletions
diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c
index 630587aaf1..adcff56bff 100644
--- a/src/test/test-cgroup-mask.c
+++ b/src/test/test-cgroup-mask.c
@@ -27,6 +27,7 @@
#include "unit.h"
static int test_cgroup_mask(void) {
+ _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
Manager *m = NULL;
Unit *son, *daughter, *parent, *root, *grandchild, *parent_deep;
FILE *serial = NULL;
@@ -35,6 +36,7 @@ static int test_cgroup_mask(void) {
/* Prepare the manager. */
assert_se(set_unit_path(TEST_DATA_DIR("")) >= 0);
+ assert_se(runtime_dir = setup_fake_runtime_dir());
r = manager_new(UNIT_FILE_USER, true, &m);
if (r == -EPERM || r == -EACCES) {
puts("manager_new: Permission denied. Skipping test.");
@@ -110,10 +112,8 @@ static int test_cgroup_mask(void) {
}
int main(int argc, char* argv[]) {
- _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
int rc = 0;
- assert_se(runtime_dir = setup_fake_runtime_dir());
TEST_REQ_RUNNING_SYSTEMD(rc = test_cgroup_mask());
return rc;
diff --git a/src/test/test-engine.c b/src/test/test-engine.c
index 3ec2dfe10e..3c0c18b188 100644
--- a/src/test/test-engine.c
+++ b/src/test/test-engine.c
@@ -37,10 +37,9 @@ int main(int argc, char *argv[]) {
Job *j;
int r;
- assert_se(runtime_dir = setup_fake_runtime_dir());
-
/* prepare the test */
assert_se(set_unit_path(TEST_DATA_DIR("")) >= 0);
+ assert_se(runtime_dir = setup_fake_runtime_dir());
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-path.c b/src/test/test-path.c
index d09df3e8a5..7f108440b1 100644
--- a/src/test/test-path.c
+++ b/src/test/test-path.c
@@ -262,8 +262,8 @@ int main(int argc, char *argv[]) {
log_parse_environment();
log_open();
- assert_se(runtime_dir = setup_fake_runtime_dir());
assert_se(set_unit_path(TEST_DATA_DIR("/test-path/")) >= 0);
+ assert_se(runtime_dir = setup_fake_runtime_dir());
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 dab64fea57..9a918cde20 100644
--- a/src/test/test-sched-prio.c
+++ b/src/test/test-sched-prio.c
@@ -34,10 +34,9 @@ int main(int argc, char *argv[]) {
FDSet *fdset = NULL;
int r;
- assert_se(runtime_dir = setup_fake_runtime_dir());
-
/* prepare the test */
assert_se(set_unit_path(TEST_DATA_DIR("")) >= 0);
+ assert_se(runtime_dir = setup_fake_runtime_dir());
r = manager_new(UNIT_FILE_USER, true, &m);
if (MANAGER_SKIP_TEST(r)) {
log_notice_errno(r, "Skipping test: manager_new: %m");