1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2010-2017 Red Hat, Inc.
4 * Copyright (c) Linux Test Project, 2011-2023
5 */
6 /*\
7 * [Description]
8 *
9 * Out Of Memory (OOM) test for mempolicy - need NUMA system support
10 */
11
12 #include "config.h"
13 #include <sys/types.h>
14 #include <sys/stat.h>
15 #include <errno.h>
16 #include <fcntl.h>
17 #include <stdio.h>
18 #if HAVE_NUMA_H
19 #include <numa.h>
20 #endif
21
22 #include "numa_helper.h"
23 #include "mem.h"
24
25 #ifdef HAVE_NUMA_V2
26
verify_oom(void)27 static void verify_oom(void)
28 {
29 tst_res(TINFO, "OOM on MPOL_BIND mempolicy...");
30 testoom(MPOL_BIND, 0, ENOMEM, 1);
31
32 tst_res(TINFO, "OOM on MPOL_INTERLEAVE mempolicy...");
33 testoom(MPOL_INTERLEAVE, 0, ENOMEM, 1);
34
35 tst_res(TINFO, "OOM on MPOL_PREFERRED mempolicy...");
36 testoom(MPOL_PREFERRED, 0, ENOMEM, 1);
37 }
38
setup(void)39 static void setup(void)
40 {
41 if (!is_numa(NULL, NH_MEMS, 2))
42 tst_brk(TCONF, "The case need a NUMA system.");
43 }
44
45 static struct tst_test test = {
46 .needs_root = 1,
47 .forks_child = 1,
48 .max_runtime = TST_UNLIMITED_RUNTIME,
49 .setup = setup,
50 .test_all = verify_oom,
51 .skip_in_compat = 1,
52 .save_restore = (const struct tst_path_val[]) {
53 {"/proc/sys/vm/overcommit_memory", "1", TST_SR_TBROK},
54 {}
55 },
56 };
57
58 #else
59 TST_TEST_TCONF(NUMA_ERROR_MSG);
60 #endif
61