From: Lennart Poettering Date: Thu, 30 Sep 2021 09:19:34 +0000 (+0200) Subject: test: add test case for {get,set}_oom_score_adjust() X-Git-Tag: v250-rc1~569^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bb2d1d8ea40a2330c5f0a9245c32e5a05829bbf2;p=thirdparty%2Fsystemd.git test: add test case for {get,set}_oom_score_adjust() --- diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index 8c76392ae96..bee39d567b3 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include #include #include #include @@ -874,6 +875,24 @@ static void test_get_process_ppid(void) { } } +static void test_set_oom_score_adjust(void) { + int a, b, r; + + assert_se(get_oom_score_adjust(&a) >= 0); + + r = set_oom_score_adjust(OOM_SCORE_ADJ_MIN); + assert_se(r >= 0 || ERRNO_IS_PRIVILEGE(r)); + + if (r >= 0) { + assert_se(get_oom_score_adjust(&b) >= 0); + assert_se(b == OOM_SCORE_ADJ_MIN); + } + + assert_se(set_oom_score_adjust(a) >= 0); + assert_se(get_oom_score_adjust(&b) >= 0); + assert_se(b == a); +} + int main(int argc, char *argv[]) { log_show_color(true); test_setup_logging(LOG_INFO); @@ -904,6 +923,7 @@ int main(int argc, char *argv[]) { test_ioprio_class_from_to_string(); test_setpriority_closest(); test_get_process_ppid(); + test_set_oom_score_adjust(); return 0; }