]> 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)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 6 Aug 2025 13:09:33 +0000 (14:09 +0100)
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

src/oom/test-oomd-util.c

index b6f5fe25a5546f53c1f3a12d76dbba5c520e78e5..abb5c2ccd8ec6c63ed79e85319e184a92e62a21a 100644 (file)
@@ -68,6 +68,8 @@ TEST(oomd_cgroup_kill) {
         /* Create another cgroup below this one for the pids we forked off. We need this to be managed
          * by the test so that pid1 doesn't delete it before we can read the xattrs. */
         ASSERT_NOT_NULL(subcgroup = path_join(cgroup, "oomdkilltest"));
+        /* Always start clean, in case of repeated runs and failures */
+        ASSERT_OK(cg_trim(subcgroup, /* delete_root */ true));
         ASSERT_OK(cg_create(subcgroup));
 
         /* If we don't have permissions to set xattrs we're likely in a userns or missing capabilities */
@@ -106,6 +108,8 @@ TEST(oomd_cgroup_kill) {
                 ASSERT_OK(cg_get_xattr(subcgroup, "user.oomd_kill", &v, /* ret_size= */ NULL));
                 ASSERT_STREQ(v, i == 0 ? "2" : "4");
         }
+
+        ASSERT_OK(cg_trim(subcgroup, /* delete_root */ true));
 }
 
 TEST(oomd_cgroup_context_acquire_and_insert) {