summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-09-30 11:19:34 +0200
committerLennart Poettering <lennart@poettering.net>2021-10-04 16:27:10 +0200
commitbb2d1d8ea40a2330c5f0a9245c32e5a05829bbf2 (patch)
treea0c6b48d478825a9945ded28362d4ed41b10d58e /src
parent2c37c613a78637059a6b219912946b50c8109aee (diff)
downloadsystemd-bb2d1d8ea40a2330c5f0a9245c32e5a05829bbf2.tar.gz
test: add test case for {get,set}_oom_score_adjust()
Diffstat (limited to 'src')
-rw-r--r--src/test/test-process-util.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c
index 8c76392ae9..bee39d567b 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 <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;
}