]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add test case for {get,set}_oom_score_adjust()
authorLennart Poettering <lennart@poettering.net>
Thu, 30 Sep 2021 09:19:34 +0000 (11:19 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 4 Oct 2021 14:27:10 +0000 (16:27 +0200)
src/test/test-process-util.c

index 8c76392ae96953ca90a40cfa63c18ae92c171e8e..bee39d567b3147b3b6a2b6cf8ee9b408bd9f89c7 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include <fcntl.h>
+#include <linux/oom.h>
 #include <sys/mount.h>
 #include <sys/personality.h>
 #include <sys/prctl.h>
@@ -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;
 }