mem/oom: check for multiple outcomes if overcommit_memory is 0 or 1
There is no guarantee that mmap() will fail before OOM tries to kill the
process if overcommit is set to 0 or 1. So allow such tests to
PASS if child is killed with SIGKILL.
This patch adds 2 parameters to oom()/testoom() functions:
retcode - expected child return code
allow_sigkill - flag which specifies if child killed by SIGKILL
is also PASS result
Child process will return 0 if all allocations succeeded,
otherwise it returns last errno.
Signed-off-by: Jan Stancek <jstancek@redhat.com>
Acked-by: Cyril Hrubis <chrubis@suse.cz>
diff --git a/testcases/kernel/mem/oom/oom01.c b/testcases/kernel/mem/oom/oom01.c
index 076427c..4f57a9a 100644
--- a/testcases/kernel/mem/oom/oom01.c
+++ b/testcases/kernel/mem/oom/oom01.c
@@ -60,14 +60,17 @@
for (lc = 0; TEST_LOOPING(lc); lc++) {
tst_count = 0;
+ /* we expect mmap to fail before OOM is hit */
set_sys_tune("overcommit_memory", 2, 1);
- oom(OVERCOMMIT, 0);
+ oom(OVERCOMMIT, 0, ENOMEM, 0);
+ /* with overcommit_memory set to 0 or 1 there's no
+ * guarantee that mmap fails before OOM */
set_sys_tune("overcommit_memory", 0, 1);
- oom(OVERCOMMIT, 0);
+ oom(OVERCOMMIT, 0, ENOMEM, 1);
set_sys_tune("overcommit_memory", 1, 1);
- testoom(0, 0);
+ testoom(0, 0, ENOMEM, 1);
}
cleanup();
tst_exit();
diff --git a/testcases/kernel/mem/oom/oom02.c b/testcases/kernel/mem/oom/oom02.c
index 3f17400..7a726c8 100644
--- a/testcases/kernel/mem/oom/oom02.c
+++ b/testcases/kernel/mem/oom/oom02.c
@@ -65,13 +65,13 @@
tst_count = 0;
tst_resm(TINFO, "OOM on MPOL_BIND mempolicy...");
- testoom(MPOL_BIND, 0);
+ testoom(MPOL_BIND, 0, ENOMEM, 1);
tst_resm(TINFO, "OOM on MPOL_INTERLEAVE mempolicy...");
- testoom(MPOL_INTERLEAVE, 0);
+ testoom(MPOL_INTERLEAVE, 0, ENOMEM, 1);
tst_resm(TINFO, "OOM on MPOL_PREFERRED mempolicy...");
- testoom(MPOL_PREFERRED, 0);
+ testoom(MPOL_PREFERRED, 0, ENOMEM, 1);
}
cleanup();
tst_exit();
diff --git a/testcases/kernel/mem/oom/oom03.c b/testcases/kernel/mem/oom/oom03.c
index dcb493c..dfc2a64 100644
--- a/testcases/kernel/mem/oom/oom03.c
+++ b/testcases/kernel/mem/oom/oom03.c
@@ -66,7 +66,7 @@
"%d", getpid());
SAFE_FILE_PRINTF(cleanup, MEMCG_LIMIT, "%ld", TESTMEM);
- testoom(0, 0);
+ testoom(0, 0, ENOMEM, 1);
if (access(MEMCG_SW_LIMIT, F_OK) == -1) {
if (errno == ENOENT)
@@ -77,15 +77,15 @@
} else {
SAFE_FILE_PRINTF(cleanup, MEMCG_SW_LIMIT,
"%ld", TESTMEM);
- testoom(0, 1);
+ testoom(0, 1, ENOMEM, 1);
}
/* OOM for MEMCG with mempolicy */
if (is_numa(cleanup)) {
tst_resm(TINFO, "OOM on MEMCG & mempolicy...");
- testoom(MPOL_BIND, 0);
- testoom(MPOL_INTERLEAVE, 0);
- testoom(MPOL_PREFERRED, 0);
+ testoom(MPOL_BIND, 0, ENOMEM, 1);
+ testoom(MPOL_INTERLEAVE, 0, ENOMEM, 1);
+ testoom(MPOL_PREFERRED, 0, ENOMEM, 1);
}
}
cleanup();
diff --git a/testcases/kernel/mem/oom/oom04.c b/testcases/kernel/mem/oom/oom04.c
index 40360c3..c0f1f92 100644
--- a/testcases/kernel/mem/oom/oom04.c
+++ b/testcases/kernel/mem/oom/oom04.c
@@ -65,7 +65,7 @@
tst_count = 0;
tst_resm(TINFO, "OOM on CPUSET...");
- testoom(0, 0);
+ testoom(0, 0, ENOMEM, 1);
if (is_numa(cleanup)) {
/*
@@ -76,7 +76,7 @@
write_cpuset_files(CPATH_NEW,
"memory_migrate", "1");
tst_resm(TINFO, "OOM on CPUSET with mem migrate:");
- testoom(0, 0);
+ testoom(0, 0, ENOMEM, 1);
}
}
cleanup();
diff --git a/testcases/kernel/mem/oom/oom05.c b/testcases/kernel/mem/oom/oom05.c
index 7ca53ad..e12c2dd 100644
--- a/testcases/kernel/mem/oom/oom05.c
+++ b/testcases/kernel/mem/oom/oom05.c
@@ -66,7 +66,7 @@
tst_count = 0;
tst_resm(TINFO, "OOM on CPUSET & MEMCG...");
- testoom(0, 0);
+ testoom(0, 0, ENOMEM, 1);
/*
* Under NUMA system, the migration of cpuset's memory
@@ -77,7 +77,7 @@
write_cpuset_files(CPATH_NEW, "memory_migrate", "1");
tst_resm(TINFO, "OOM on CPUSET & MEMCG with "
"cpuset.memory_migrate=1");
- testoom(0, 0);
+ testoom(0, 0, ENOMEM, 1);
}
if (access(MEMCG_SW_LIMIT, F_OK) == -1) {
@@ -93,12 +93,12 @@
tst_resm(TINFO, "OOM on CPUSET & MEMCG with "
"special memswap limitation:");
SAFE_FILE_PRINTF(cleanup, MEMCG_SW_LIMIT, "%ld", TESTMEM);
- testoom(0, 0);
+ testoom(0, 0, ENOMEM, 1);
tst_resm(TINFO, "OOM on CPUSET & MEMCG with "
"disabled memswap limitation:");
SAFE_FILE_PRINTF(cleanup, MEMCG_SW_LIMIT, "-1");
- testoom(0, 0);
+ testoom(0, 0, ENOMEM, 1);
}
}