From 14cb1fba9130ccb6b8ed315211fe46e5e3f9cc88 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Wed, 6 Aug 2025 12:48:34 +0100 Subject: [PATCH] test: fix assert when running test-cgroup in container 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 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/test/test-cgroup.c b/src/test/test-cgroup.c index d32b119d26c..e67887a004d 100644 --- a/src/test/test-cgroup.c +++ b/src/test/test-cgroup.c @@ -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); -- 2.47.3