]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/test/test-unit-name.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / test / test-unit-name.c
index 2fd83f321cec6d0a23a031b4a44cd3caf802e622..013e87e73b4e3787d76769d836797507a22e80af 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
 /***
   This file is part of systemd.
 
 #include "macro.h"
 #include "manager.h"
 #include "path-util.h"
+#include "rm-rf.h"
 #include "specifier.h"
 #include "string-util.h"
 #include "test-helper.h"
+#include "tests.h"
 #include "unit-name.h"
 #include "unit-printf.h"
 #include "unit.h"
@@ -209,9 +212,9 @@ static int test_unit_printf(void) {
         assert_se(get_home_dir(&home) >= 0);
         assert_se(get_shell(&shell) >= 0);
 
-        r = manager_new(UNIT_FILE_USER, true, &m);
-        if (r == -EPERM || r == -EACCES || r == -EADDRINUSE) {
-                puts("manager_new: Permission denied. Skipping test.");
+        r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_MINIMAL, &m);
+        if (MANAGER_SKIP_TEST(r)) {
+                log_notice_errno(r, "Skipping test: manager_new: %m");
                 return EXIT_TEST_SKIP;
         }
         assert_se(r == 0);
@@ -228,8 +231,6 @@ static int test_unit_printf(void) {
                         assert_se(streq(t, expected));                     \
         }
 
-        assert_se(setenv("XDG_RUNTIME_DIR", "/run/user/1/", 1) == 0);
-
         assert_se(u = unit_new(m, sizeof(Service)));
         assert_se(unit_add_name(u, "blah.service") == 0);
         assert_se(unit_add_name(u, "blah.service") == 0);
@@ -237,7 +238,8 @@ static int test_unit_printf(void) {
         /* general tests */
         expect(u, "%%", "%");
         expect(u, "%%s", "%s");
-        expect(u, "%", "");    // REALLY?
+        expect(u, "%,", "%,");
+        expect(u, "%", "%");
 
         /* normal unit */
         expect(u, "%n", "blah.service");
@@ -463,7 +465,20 @@ static void test_unit_name_path_unescape(void) {
 }
 
 int main(int argc, char* argv[]) {
-        int rc = 0;
+        _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
+        int r, rc = 0;
+
+        log_parse_environment();
+        log_open();
+
+        r = enter_cgroup_subroot();
+        if (r == -ENOMEDIUM) {
+                log_notice_errno(r, "Skipping test: cgroupfs not available");
+                return EXIT_TEST_SKIP;
+        }
+
+        assert_se(runtime_dir = setup_fake_runtime_dir());
+
         test_unit_name_is_valid();
         test_unit_name_replace_instance();
         test_unit_name_from_path();