]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: fix repeated runs of test-oomd-util by clearing test cgroup
authorLuca Boccassi <luca.boccassi@gmail.com>
Wed, 6 Aug 2025 13:07:26 +0000 (14:07 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 3 Sep 2025 10:10:48 +0000 (12:10 +0200)
If the test is ran multiple times in a row, without an ephemeral
scope (eg: non-booted nspawn), then subsequent runs will fail as
the test cgroup is not cleared so the previous xattrs are still
present. Trim the test cgroup before and after the test.

Follow-up for 61ff7397d08375ce0950fb7b546c08e4a657f273

(cherry picked from commit 0d333ed8e302e48efdfc26cb4c8e467a4863f460)

src/oom/test-oomd-util.c

index 53109c160d301589333c98b18ec9d992867cbaaa..a85c234ca68939983dd6037294e716f07fa092ee 100644 (file)
@@ -55,6 +55,8 @@ static void test_oomd_cgroup_kill(void) {
          * by the test so that pid1 doesn't delete it before we can read the xattrs. */
         cgroup = path_join(cgroup_root, "oomdkilltest");
         assert_se(cgroup);
+        /* Always start clean, in case of repeated runs and failures */
+        assert_se(cg_trim(SYSTEMD_CGROUP_CONTROLLER, cgroup, /* delete_root */ true) >= 0);
         assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, cgroup) >= 0);
 
         /* If we don't have permissions to set xattrs we're likely in a userns or missing capabilities */
@@ -88,6 +90,8 @@ static void test_oomd_cgroup_kill(void) {
                 assert_se(cg_get_xattr_malloc(cgroup, "user.oomd_kill", &v) >= 0);
                 assert_se(streq(v, i == 0 ? "2" : "4"));
         }
+
+        assert_se(cg_trim(SYSTEMD_CGROUP_CONTROLLER, cgroup, /* delete_root */ true) >= 0);
 }
 
 static void test_oomd_cgroup_context_acquire_and_insert(void) {