]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: fix assert when running test-cgroup in container
authorLuca Boccassi <luca.boccassi@gmail.com>
Wed, 6 Aug 2025 11:48:34 +0000 (12:48 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 6 Aug 2025 13:09:33 +0000 (14:09 +0100)
When running in nspawn and thus from the namespaced root cgroup:

Paths for test:
//test-a
//test-b
src/test/test-cgroup.c:77: Assertion failed: Expected "path == test_b", got "/test-b != //test-b"

Use path_simplify() in the test like the code does, so that the results
always match

src/test/test-cgroup.c

index d32b119d26cbdf3c0a9176274fb37ee725ab86b3..e67887a004d604c31bc73aae467fb298792d337e 100644 (file)
@@ -51,10 +51,12 @@ TEST(cg_create) {
         _cleanup_free_ char *here = NULL;
         ASSERT_OK(cg_pid_get_path_shifted(0, NULL, &here));
 
-        _cleanup_free_ char *test_a = ASSERT_NOT_NULL(path_join(here, "/test-a")),
-                            *test_b = ASSERT_NOT_NULL(path_join(here, "/test-b")),
-                            *test_c = ASSERT_NOT_NULL(path_join(here, "/test-b/test-c")),
-                            *test_d = ASSERT_NOT_NULL(path_join(here, "/test-b/test-d"));
+        /* cg_* will use path_simplify(), so use it here too otherwise when running in a container at the
+         * root it asserts with "/test-b != //test-b" */
+        _cleanup_free_ char *test_a = ASSERT_NOT_NULL(path_simplify(path_join(here, "/test-a"))),
+                            *test_b = ASSERT_NOT_NULL(path_simplify(path_join(here, "/test-b"))),
+                            *test_c = ASSERT_NOT_NULL(path_simplify(path_join(here, "/test-b/test-c"))),
+                            *test_d = ASSERT_NOT_NULL(path_simplify(path_join(here, "/test-b/test-d")));
         char *path;
 
         log_info("Paths for test:\n%s\n%s", test_a, test_b);