X Tutup
Skip to content

Commit 080ca0d

Browse files
committed
test-oomd-util: fix running in mkosi
When this test is run in mkosi, the previously tested cgroup that we write xattrs into and the root cgroup are the same. Since the root cgroup is a live cgroup anyways (vs. the test cgroups which are remade each time) let's generate the expected preference values from reading the xattrs instead of assuming it will be NONE.
1 parent ea460d7 commit 080ca0d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/oom/test-oomd-util.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ static void test_oomd_cgroup_context_acquire_and_insert(void) {
8888
_cleanup_hashmap_free_ Hashmap *h1 = NULL, *h2 = NULL;
8989
_cleanup_(oomd_cgroup_context_freep) OomdCGroupContext *ctx = NULL;
9090
_cleanup_free_ char *cgroup = NULL;
91+
ManagedOOMPreference root_pref;
9192
OomdCGroupContext *c1, *c2;
9293
bool test_xattrs;
93-
int r;
94+
int root_xattrs, r;
9495

9596
if (geteuid() != 0)
9697
return (void) log_tests_skipped("not root");
@@ -140,10 +141,16 @@ static void test_oomd_cgroup_context_acquire_and_insert(void) {
140141
ctx = oomd_cgroup_context_free(ctx);
141142

142143
/* Test the root cgroup */
144+
/* Root cgroup is live and not made on demand like the cgroup the test runs in. It can have varying
145+
* xattrs set already so let's read in the booleans first to get the final preference value. */
146+
root_xattrs = cg_get_xattr_bool(SYSTEMD_CGROUP_CONTROLLER, "", "user.oomd_omit");
147+
root_pref = root_xattrs > 0 ? MANAGED_OOM_PREFERENCE_OMIT : MANAGED_OOM_PREFERENCE_NONE;
148+
root_xattrs = cg_get_xattr_bool(SYSTEMD_CGROUP_CONTROLLER, "", "user.oomd_avoid");
149+
root_pref = root_xattrs > 0 ? MANAGED_OOM_PREFERENCE_AVOID : MANAGED_OOM_PREFERENCE_NONE;
143150
assert_se(oomd_cgroup_context_acquire("", &ctx) == 0);
144151
assert_se(streq(ctx->path, "/"));
145152
assert_se(ctx->current_memory_usage > 0);
146-
assert_se(ctx->preference == MANAGED_OOM_PREFERENCE_NONE);
153+
assert_se(ctx->preference == root_pref);
147154

148155
/* Test hashmap inserts */
149156
assert_se(h1 = hashmap_new(&oomd_cgroup_ctx_hash_ops));

0 commit comments

Comments
 (0)
X Tutup