]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: setup test data dir before fake runtime dir
authorMartin Pitt <martin@piware.de>
Tue, 14 Feb 2017 21:33:52 +0000 (22:33 +0100)
committerMartin Pitt <martin@piware.de>
Thu, 16 Feb 2017 20:36:30 +0000 (21:36 +0100)
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).

src/test/test-cgroup-mask.c
src/test/test-engine.c
src/test/test-path.c
src/test/test-sched-prio.c

index 630587aaf18391c0da5a881618bf90103c660fdb..adcff56bffe0051bb3169e86ca6c652dadd3c216 100644 (file)
@@ -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;
index 3ec2dfe10ef8234f50e80ad887b2613533ad253c..3c0c18b188d973c2b73ea36d539dfaddb8a137fe 100644 (file)
@@ -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");
index d09df3e8a5fe6af87270c8274608b4701201a453..7f108440b1df85979b9c745e263da28ea27fb128 100644 (file)
@@ -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;
index dab64fea575fb0b658b6ae2519dc12ebe1dda05e..9a918cde20bd9452248e2954b362f5b9aaac9808 100644 (file)
@@ -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");