xref: /third_party/ltp/testcases/kernel/mem/oom/oom02.c (revision f08c3bdf)
1f08c3bdfSopenharmony_ci/*
2f08c3bdfSopenharmony_ci * Out Of Memory (OOM) for mempolicy - need NUMA system support
3f08c3bdfSopenharmony_ci *
4f08c3bdfSopenharmony_ci * The program is designed to cope with unpredictable like amount and
5f08c3bdfSopenharmony_ci * system physical memory, swap size and other VMM technology like KSM,
6f08c3bdfSopenharmony_ci * memcg, memory hotplug and so on which may affect the OOM
7f08c3bdfSopenharmony_ci * behaviours. It simply increase the memory consumption 3G each time
8f08c3bdfSopenharmony_ci * until all the available memory is consumed and OOM is triggered.
9f08c3bdfSopenharmony_ci *
10f08c3bdfSopenharmony_ci * Copyright (C) 2010-2017  Red Hat, Inc.
11f08c3bdfSopenharmony_ci *
12f08c3bdfSopenharmony_ci * This program is free software;  you can redistribute it and/or modify
13f08c3bdfSopenharmony_ci * it under the terms of the GNU General Public License as published by
14f08c3bdfSopenharmony_ci * the Free Software Foundation; either version 2 of the License, or
15f08c3bdfSopenharmony_ci * (at your option) any later version.
16f08c3bdfSopenharmony_ci *
17f08c3bdfSopenharmony_ci * This program is distributed in the hope that it will be useful,
18f08c3bdfSopenharmony_ci * but WITHOUT ANY WARRANTY;  without even the implied warranty of
19f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
20f08c3bdfSopenharmony_ci * the GNU General Public License for more details.
21f08c3bdfSopenharmony_ci */
22f08c3bdfSopenharmony_ci
23f08c3bdfSopenharmony_ci#include "config.h"
24f08c3bdfSopenharmony_ci#include <sys/types.h>
25f08c3bdfSopenharmony_ci#include <sys/stat.h>
26f08c3bdfSopenharmony_ci#include <errno.h>
27f08c3bdfSopenharmony_ci#include <fcntl.h>
28f08c3bdfSopenharmony_ci#include <stdio.h>
29f08c3bdfSopenharmony_ci#if HAVE_NUMA_H
30f08c3bdfSopenharmony_ci#include <numa.h>
31f08c3bdfSopenharmony_ci#endif
32f08c3bdfSopenharmony_ci
33f08c3bdfSopenharmony_ci#include "lapi/abisize.h"
34f08c3bdfSopenharmony_ci#include "numa_helper.h"
35f08c3bdfSopenharmony_ci#include "mem.h"
36f08c3bdfSopenharmony_ci
37f08c3bdfSopenharmony_ci#ifdef HAVE_NUMA_V2
38f08c3bdfSopenharmony_ci
39f08c3bdfSopenharmony_cistatic void verify_oom(void)
40f08c3bdfSopenharmony_ci{
41f08c3bdfSopenharmony_ci#ifdef TST_ABI32
42f08c3bdfSopenharmony_ci	tst_brk(TCONF, "test is not designed for 32-bit system.");
43f08c3bdfSopenharmony_ci#endif
44f08c3bdfSopenharmony_ci
45f08c3bdfSopenharmony_ci	tst_res(TINFO, "OOM on MPOL_BIND mempolicy...");
46f08c3bdfSopenharmony_ci	testoom(MPOL_BIND, 0, ENOMEM, 1);
47f08c3bdfSopenharmony_ci
48f08c3bdfSopenharmony_ci	tst_res(TINFO, "OOM on MPOL_INTERLEAVE mempolicy...");
49f08c3bdfSopenharmony_ci	testoom(MPOL_INTERLEAVE, 0, ENOMEM, 1);
50f08c3bdfSopenharmony_ci
51f08c3bdfSopenharmony_ci	tst_res(TINFO, "OOM on MPOL_PREFERRED mempolicy...");
52f08c3bdfSopenharmony_ci	testoom(MPOL_PREFERRED, 0, ENOMEM, 1);
53f08c3bdfSopenharmony_ci}
54f08c3bdfSopenharmony_ci
55f08c3bdfSopenharmony_cistatic void setup(void)
56f08c3bdfSopenharmony_ci{
57f08c3bdfSopenharmony_ci	if (!is_numa(NULL, NH_MEMS, 2))
58f08c3bdfSopenharmony_ci		tst_brk(TCONF, "The case need a NUMA system.");
59f08c3bdfSopenharmony_ci}
60f08c3bdfSopenharmony_ci
61f08c3bdfSopenharmony_cistatic struct tst_test test = {
62f08c3bdfSopenharmony_ci	.needs_root = 1,
63f08c3bdfSopenharmony_ci	.forks_child = 1,
64f08c3bdfSopenharmony_ci        .max_runtime = TST_UNLIMITED_RUNTIME,
65f08c3bdfSopenharmony_ci	.setup = setup,
66f08c3bdfSopenharmony_ci	.test_all = verify_oom,
67f08c3bdfSopenharmony_ci	.save_restore = (const struct tst_path_val[]) {
68f08c3bdfSopenharmony_ci		{"/proc/sys/vm/overcommit_memory", "1", TST_SR_TBROK},
69f08c3bdfSopenharmony_ci		{}
70f08c3bdfSopenharmony_ci	},
71f08c3bdfSopenharmony_ci};
72f08c3bdfSopenharmony_ci
73f08c3bdfSopenharmony_ci#else
74f08c3bdfSopenharmony_ci	TST_TEST_TCONF(NUMA_ERROR_MSG);
75f08c3bdfSopenharmony_ci#endif
76