From ea460d79644560bcb1ed2adb4cf30413f285492a Mon Sep 17 00:00:00 2001 From: Anita Zhang Date: Thu, 1 Apr 2021 18:44:26 -0700 Subject: [PATCH 1/2] meson: link with libm for math functions Fixes this error I got building on F33: /usr/bin/ld: test-random-util.p/src_test_test-random-util.c.o: undefined reference to symbol 'sqrt@@GLIBC_2.2.5' /usr/bin/ld: /usr/lib64/libm.so.6: error adding symbols: DSO missing from command line --- src/test/meson.build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/meson.build b/src/test/meson.build index 0488baba82..45f1fd6e3f 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -158,7 +158,9 @@ tests += [ [['src/test/test-fstab-util.c']], - [['src/test/test-random-util.c']], + [['src/test/test-random-util.c'], + [], + [libm]], [['src/test/test-format-table.c']], From 080ca0d830d69dea5fb2b07aace54a4402bf7294 Mon Sep 17 00:00:00 2001 From: Anita Zhang Date: Thu, 1 Apr 2021 19:06:26 -0700 Subject: [PATCH 2/2] 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. --- src/oom/test-oomd-util.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/oom/test-oomd-util.c b/src/oom/test-oomd-util.c index bd1c574ca7..278fc305b3 100644 --- a/src/oom/test-oomd-util.c +++ b/src/oom/test-oomd-util.c @@ -88,9 +88,10 @@ static void test_oomd_cgroup_context_acquire_and_insert(void) { _cleanup_hashmap_free_ Hashmap *h1 = NULL, *h2 = NULL; _cleanup_(oomd_cgroup_context_freep) OomdCGroupContext *ctx = NULL; _cleanup_free_ char *cgroup = NULL; + ManagedOOMPreference root_pref; OomdCGroupContext *c1, *c2; bool test_xattrs; - int r; + int root_xattrs, r; if (geteuid() != 0) return (void) log_tests_skipped("not root"); @@ -140,10 +141,16 @@ static void test_oomd_cgroup_context_acquire_and_insert(void) { ctx = oomd_cgroup_context_free(ctx); /* Test the root cgroup */ + /* Root cgroup is live and not made on demand like the cgroup the test runs in. It can have varying + * xattrs set already so let's read in the booleans first to get the final preference value. */ + root_xattrs = cg_get_xattr_bool(SYSTEMD_CGROUP_CONTROLLER, "", "user.oomd_omit"); + root_pref = root_xattrs > 0 ? MANAGED_OOM_PREFERENCE_OMIT : MANAGED_OOM_PREFERENCE_NONE; + root_xattrs = cg_get_xattr_bool(SYSTEMD_CGROUP_CONTROLLER, "", "user.oomd_avoid"); + root_pref = root_xattrs > 0 ? MANAGED_OOM_PREFERENCE_AVOID : MANAGED_OOM_PREFERENCE_NONE; assert_se(oomd_cgroup_context_acquire("", &ctx) == 0); assert_se(streq(ctx->path, "/")); assert_se(ctx->current_memory_usage > 0); - assert_se(ctx->preference == MANAGED_OOM_PREFERENCE_NONE); + assert_se(ctx->preference == root_pref); /* Test hashmap inserts */ assert_se(h1 = hashmap_new(&oomd_cgroup_ctx_hash_ops));