1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-31 14:50:15 +03:00

test: add test case for {get,set}_oom_score_adjust()

This commit is contained in:
Lennart Poettering 2021-09-30 11:19:34 +02:00
parent 2c37c613a7
commit bb2d1d8ea4

View 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;
}