public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Li Wang <liwang@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH V2 02/14] mem/oom: convert to new API
Date: Mon, 10 Apr 2017 18:05:44 +0800	[thread overview]
Message-ID: <20170410100556.4465-3-liwang@redhat.com> (raw)
In-Reply-To: <20170410100556.4465-1-liwang@redhat.com>

Signed-off-by: Li Wang <liwang@redhat.com>
---
 testcases/kernel/mem/oom/oom01.c |  83 ++++++++++---------------
 testcases/kernel/mem/oom/oom02.c |  83 +++++++++----------------
 testcases/kernel/mem/oom/oom03.c | 110 +++++++++++++--------------------
 testcases/kernel/mem/oom/oom04.c |  98 +++++++++++------------------
 testcases/kernel/mem/oom/oom05.c | 130 ++++++++++++++++-----------------------
 5 files changed, 196 insertions(+), 308 deletions(-)

diff --git a/testcases/kernel/mem/oom/oom01.c b/testcases/kernel/mem/oom/oom01.c
index e39394b..64a368e 100644
--- a/testcases/kernel/mem/oom/oom01.c
+++ b/testcases/kernel/mem/oom/oom01.c
@@ -7,27 +7,19 @@
  * behaviours. It simply increase the memory consumption 3G each time
  * until all the available memory is consumed and OOM is triggered.
  *
- * Copyright (C) 2010  Red Hat, Inc.
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
+ * Copyright (C) 2010-2017  Red Hat, Inc.
  *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like.  Any license provided herein, whether
- * implied or otherwise, applies only to this software file.  Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  */
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <errno.h>
@@ -35,53 +27,42 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include "test.h"
 #include "mem.h"
 
-char *TCID = "oom01";
-int TST_TOTAL = 1;
-
-int main(int argc, char *argv[])
+static void verify_oom(void)
 {
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
 #if __WORDSIZE == 32
-	tst_brkm(TCONF, NULL, "test is not designed for 32-bit system.");
+	tst_brk(TCONF, "test is not designed for 32-bit system.");
 #endif
 
-	setup();
+	/* we expect mmap to fail before OOM is hit */
+	set_sys_tune("overcommit_memory", 2, 1);
+	oom(NORMAL, 0, ENOMEM, 0);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 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(NORMAL, 0, ENOMEM, 1);
 
-		/* we expect mmap to fail before OOM is hit */
-		set_sys_tune("overcommit_memory", 2, 1);
-		oom(NORMAL, 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(NORMAL, 0, ENOMEM, 1);
-
-		set_sys_tune("overcommit_memory", 1, 1);
-		testoom(0, 0, ENOMEM, 1);
-	}
-	cleanup();
-	tst_exit();
+	set_sys_tune("overcommit_memory", 1, 1);
+	testoom(0, 0, ENOMEM, 1);
 }
 
-void setup(void)
+static void setup(void)
 {
-	tst_require_root();
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	TEST_PAUSE;
-
 	overcommit = get_sys_tune("overcommit_memory");
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
 	set_sys_tune("overcommit_memory", overcommit, 0);
 }
+
+static struct tst_test test = {
+	.tid = "oom01",
+	.needs_root = 1,
+	.forks_child = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_oom,
+};
diff --git a/testcases/kernel/mem/oom/oom02.c b/testcases/kernel/mem/oom/oom02.c
index 8bbb18a..f315ee2 100644
--- a/testcases/kernel/mem/oom/oom02.c
+++ b/testcases/kernel/mem/oom/oom02.c
@@ -7,26 +7,17 @@
  * behaviours. It simply increase the memory consumption 3G each time
  * until all the available memory is consumed and OOM is triggered.
  *
- * Copyright (C) 2010  Red Hat, Inc.
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
+ * Copyright (C) 2010-2017  Red Hat, Inc.
  *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like.  Any license provided herein, whether
- * implied or otherwise, applies only to this software file.  Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  */
 
 #include "config.h"
@@ -36,64 +27,50 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include "numa_helper.h"
-#include "test.h"
 #include "mem.h"
 
-char *TCID = "oom02";
-int TST_TOTAL = 1;
-
 #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
 	&& HAVE_MPOL_CONSTANTS
 
-int main(int argc, char *argv[])
+static void verify_oom(void)
 {
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
 #if __WORDSIZE == 32
-	tst_brkm(TCONF, NULL, "test is not designed for 32-bit system.");
+	tst_brk(TCONF, "test is not designed for 32-bit system.");
 #endif
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
+	tst_res(TINFO, "OOM on MPOL_BIND mempolicy...");
+	testoom(MPOL_BIND, 0, ENOMEM, 1);
 
-		tst_resm(TINFO, "OOM on MPOL_BIND mempolicy...");
-		testoom(MPOL_BIND, 0, ENOMEM, 1);
+	tst_res(TINFO, "OOM on MPOL_INTERLEAVE mempolicy...");
+	testoom(MPOL_INTERLEAVE, 0, ENOMEM, 1);
 
-		tst_resm(TINFO, "OOM on MPOL_INTERLEAVE mempolicy...");
-		testoom(MPOL_INTERLEAVE, 0, ENOMEM, 1);
-
-		tst_resm(TINFO, "OOM on MPOL_PREFERRED mempolicy...");
-		testoom(MPOL_PREFERRED, 0, ENOMEM, 1);
-	}
-	cleanup();
-	tst_exit();
+	tst_res(TINFO, "OOM on MPOL_PREFERRED mempolicy...");
+	testoom(MPOL_PREFERRED, 0, ENOMEM, 1);
 }
 
-void setup(void)
+static void setup(void)
 {
-	tst_require_root();
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	TEST_PAUSE;
-
 	if (!is_numa(NULL, NH_MEMS, 2))
-		tst_brkm(TCONF, NULL, "The case need a NUMA system.");
+		tst_brk(TCONF, "The case need a NUMA system.");
 
 	overcommit = get_sys_tune("overcommit_memory");
 	set_sys_tune("overcommit_memory", 1, 1);
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
 	set_sys_tune("overcommit_memory", overcommit, 0);
 }
 
+static struct tst_test test = {
+	.tid = "oom02",
+	.needs_root = 1,
+	.forks_child = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_oom,
+};
+
 #else /* no NUMA */
-int main(void)
-{
-	tst_brkm(TCONF, NULL, "no NUMA development packages installed.");
-}
+	TST_TEST_TCONF("no NUMA development packages installed.");
 #endif
diff --git a/testcases/kernel/mem/oom/oom03.c b/testcases/kernel/mem/oom/oom03.c
index 879fdae..d3aed60 100644
--- a/testcases/kernel/mem/oom/oom03.c
+++ b/testcases/kernel/mem/oom/oom03.c
@@ -7,107 +7,83 @@
  * behaviours. It simply increase the memory consumption 3G each time
  * until all the available memory is consumed and OOM is triggered.
  *
- * Copyright (C) 2010  Red Hat, Inc.
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
+ * Copyright (C) 2010-2017  Red Hat, Inc.
  *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like.  Any license provided herein, whether
- * implied or otherwise, applies only to this software file.  Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  */
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include "numa_helper.h"
-#include "test.h"
 #include "mem.h"
 
-char *TCID = "oom03";
-int TST_TOTAL = 1;
-
 #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
 	&& HAVE_MPOL_CONSTANTS
 
-int main(int argc, char *argv[])
+static void verify_oom(void)
 {
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
 #if __WORDSIZE == 32
-	tst_brkm(TCONF, NULL, "test is not designed for 32-bit system.");
+	tst_brk(TCONF, "test is not designed for 32-bit system.");
 #endif
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
+	SAFE_FILE_PRINTF(MEMCG_PATH_NEW "/tasks", "%d", getpid());
+	SAFE_FILE_PRINTF(MEMCG_LIMIT, "%ld", TESTMEM);
 
-		SAFE_FILE_PRINTF(cleanup, MEMCG_PATH_NEW "/tasks",
-				 "%d", getpid());
-		SAFE_FILE_PRINTF(cleanup, MEMCG_LIMIT, "%ld", TESTMEM);
+	testoom(0, 0, ENOMEM, 1);
 
-		testoom(0, 0, ENOMEM, 1);
-
-		if (access(MEMCG_SW_LIMIT, F_OK) == -1) {
-			if (errno == ENOENT)
-				tst_resm(TCONF,
-					 "memcg swap accounting is disabled");
-			else
-				tst_brkm(TBROK | TERRNO, cleanup, "access");
-		} else {
-			SAFE_FILE_PRINTF(cleanup, MEMCG_SW_LIMIT,
-					 "%ld", TESTMEM);
-			testoom(0, 1, ENOMEM, 1);
-		}
+	if (access(MEMCG_SW_LIMIT, F_OK) == -1) {
+		if (errno == ENOENT)
+			tst_res(TCONF,
+				"memcg swap accounting is disabled");
+		else
+			tst_brk(TBROK | TERRNO, "access");
+	} else {
+		SAFE_FILE_PRINTF(MEMCG_SW_LIMIT, "%ld", TESTMEM);
+		testoom(0, 1, ENOMEM, 1);
+	}
 
-		/* OOM for MEMCG with mempolicy */
-		if (is_numa(cleanup, NH_MEMS, 2)) {
-			tst_resm(TINFO, "OOM on MEMCG & mempolicy...");
-			testoom(MPOL_BIND, 0, ENOMEM, 1);
-			testoom(MPOL_INTERLEAVE, 0, ENOMEM, 1);
-			testoom(MPOL_PREFERRED, 0, ENOMEM, 1);
-		}
+	/* OOM for MEMCG with mempolicy */
+	if (is_numa(NULL, NH_MEMS, 2)) {
+		tst_res(TINFO, "OOM on MEMCG & mempolicy...");
+		testoom(MPOL_BIND, 0, ENOMEM, 1);
+		testoom(MPOL_INTERLEAVE, 0, ENOMEM, 1);
+		testoom(MPOL_PREFERRED, 0, ENOMEM, 1);
 	}
-	cleanup();
-	tst_exit();
 }
 
-void setup(void)
+static void setup(void)
 {
-	tst_require_root();
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	TEST_PAUSE;
-
 	overcommit = get_sys_tune("overcommit_memory");
 	set_sys_tune("overcommit_memory", 1, 1);
 	mount_mem("memcg", "cgroup", "memory", MEMCG_PATH, MEMCG_PATH_NEW);
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
 	set_sys_tune("overcommit_memory", overcommit, 0);
 	umount_mem(MEMCG_PATH, MEMCG_PATH_NEW);
 }
 
+static struct tst_test test = {
+	.tid = "oom03",
+	.needs_root = 1,
+	.forks_child = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_oom,
+};
+
 #else
-int main(void)
-{
-	tst_brkm(TCONF, NULL, "no NUMA development packages installed.");
-}
+	TST_TEST_TCONF("no NUMA development packages installed.");
 #endif
diff --git a/testcases/kernel/mem/oom/oom04.c b/testcases/kernel/mem/oom/oom04.c
index 4829d95..afe35b2 100644
--- a/testcases/kernel/mem/oom/oom04.c
+++ b/testcases/kernel/mem/oom/oom04.c
@@ -7,26 +7,17 @@
  * behaviours. It simply increase the memory consumption 3G each time
  * until all the available memory is consumed and OOM is triggered.
  *
- * Copyright (C) 2010  Red Hat, Inc.
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
+ * Copyright (C) 2010-2017  Red Hat, Inc.
  *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like.  Any license provided herein, whether
- * implied or otherwise, applies only to this software file.  Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  */
 
 #include "config.h"
@@ -36,59 +27,38 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include "numa_helper.h"
-#include "test.h"
 #include "mem.h"
 
-char *TCID = "oom04";
-int TST_TOTAL = 1;
-
 #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
 	&& HAVE_MPOL_CONSTANTS
 
-int main(int argc, char *argv[])
+static void verify_oom(void)
 {
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
 #if __WORDSIZE == 32
-	tst_brkm(TCONF, NULL, "test is not designed for 32-bit system.");
+	tst_brk(TCONF, "test is not designed for 32-bit system.");
 #endif
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		tst_resm(TINFO, "OOM on CPUSET...");
+	tst_res(TINFO, "OOM on CPUSET...");
+	testoom(0, 0, ENOMEM, 1);
+
+	if (is_numa(NULL, NH_MEMS, 2)) {
+		/*
+		 * Under NUMA system, the migration of cpuset's memory
+		 * is in charge of cpuset.memory_migrate, we can write
+		 * 1 to cpuset.memory_migrate to enable the migration.
+		 */
+		write_cpuset_files(CPATH_NEW, "memory_migrate", "1");
+		tst_res(TINFO, "OOM on CPUSET with mem migrate:");
 		testoom(0, 0, ENOMEM, 1);
-
-		if (is_numa(cleanup, NH_MEMS, 2)) {
-			/*
-			 * Under NUMA system, the migration of cpuset's memory
-			 * is in charge of cpuset.memory_migrate, we can write
-			 * 1 to cpuset.memory_migrate to enable the migration.
-			 */
-			write_cpuset_files(CPATH_NEW,
-					   "memory_migrate", "1");
-			tst_resm(TINFO, "OOM on CPUSET with mem migrate:");
-			testoom(0, 0, ENOMEM, 1);
-		}
 	}
-	cleanup();
-	tst_exit();
 }
 
-void setup(void)
+static void setup(void)
 {
 	int memnode, ret;
 
-	tst_require_root();
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	TEST_PAUSE;
-
 	if (!is_numa(NULL, NH_MEMS, 1))
-		tst_brkm(TCONF, NULL, "requires NUMA with at least 1 node");
+		tst_brk(TCONF, "requires NUMA with at least 1 node");
 
 	overcommit = get_sys_tune("overcommit_memory");
 	set_sys_tune("overcommit_memory", 1, 1);
@@ -103,20 +73,26 @@ void setup(void)
 	 */
 	ret = get_allowed_nodes(NH_MEMS, 1, &memnode);
 	if (ret < 0)
-		tst_brkm(TBROK, cleanup, "Failed to get a memory node "
-				      "using get_allowed_nodes()");
+		tst_brk(TBROK, "Failed to get a memory node "
+			      "using get_allowed_nodes()");
 	write_cpusets(memnode);
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
 	set_sys_tune("overcommit_memory", overcommit, 0);
 	umount_mem(CPATH, CPATH_NEW);
 }
 
+static struct tst_test test = {
+	.tid = "oom04",
+	.needs_root = 1,
+	.forks_child = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_oom,
+};
+
 #else /* no NUMA */
-int main(void)
-{
-	tst_brkm(TCONF, NULL, "no NUMA development packages installed.");
-}
+	TST_TEST_TCONF("no NUMA development packages installed.");
 #endif
diff --git a/testcases/kernel/mem/oom/oom05.c b/testcases/kernel/mem/oom/oom05.c
index ccf456f..d97fe7d 100644
--- a/testcases/kernel/mem/oom/oom05.c
+++ b/testcases/kernel/mem/oom/oom05.c
@@ -7,26 +7,17 @@
  * behaviours. It simply increase the memory consumption 3G each time
  * until all the available memory is consumed and OOM is triggered.
  *
- * Copyright (C) 2013  Red Hat, Inc.
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
+ * Copyright (C) 2013-2017  Red Hat, Inc.
  *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like.  Any license provided herein, whether
- * implied or otherwise, applies only to this software file.  Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  */
 
 #include "config.h"
@@ -36,82 +27,63 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include "numa_helper.h"
-#include "test.h"
 #include "mem.h"
 
-char *TCID = "oom05";
-int TST_TOTAL = 1;
-
 #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
 	&& HAVE_MPOL_CONSTANTS
 
-int main(int argc, char *argv[])
+static void verify_oom(void)
 {
-	int lc;
 	int swap_acc_on = 1;
 
-	tst_parse_opts(argc, argv, NULL, NULL);
-
 #if __WORDSIZE == 32
-	tst_brkm(TCONF, NULL, "test is not designed for 32-bit system.");
+	tst_brk(TCONF, "test is not designed for 32-bit system.");
 #endif
 
-	setup();
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
+	tst_res(TINFO, "OOM on CPUSET & MEMCG...");
+	testoom(0, 0, ENOMEM, 1);
 
-		tst_resm(TINFO, "OOM on CPUSET & MEMCG...");
+	/*
+	 * Under NUMA system, the migration of cpuset's memory
+	 * is in charge of cpuset.memory_migrate, we can write
+	 * 1 to cpuset.memory_migrate to enable the migration.
+	 */
+	if (is_numa(NULL, NH_MEMS, 2)) {
+		write_cpuset_files(CPATH_NEW, "memory_migrate", "1");
+		tst_res(TINFO, "OOM on CPUSET & MEMCG with "
+				"cpuset.memory_migrate=1");
 		testoom(0, 0, ENOMEM, 1);
+	}
 
-		/*
-		 * Under NUMA system, the migration of cpuset's memory
-		 * is in charge of cpuset.memory_migrate, we can write
-		 * 1 to cpuset.memory_migrate to enable the migration.
-		 */
-		if (is_numa(cleanup, NH_MEMS, 2)) {
-			write_cpuset_files(CPATH_NEW, "memory_migrate", "1");
-			tst_resm(TINFO, "OOM on CPUSET & MEMCG with "
-					"cpuset.memory_migrate=1");
-			testoom(0, 0, ENOMEM, 1);
-		}
-
-		if (access(MEMCG_SW_LIMIT, F_OK) == -1) {
-			if (errno == ENOENT) {
-				tst_resm(TCONF,
-					 "memcg swap accounting is disabled");
-				swap_acc_on = 0;
-			} else
-				tst_brkm(TBROK|TERRNO, cleanup, "access");
-		}
-
-		if (swap_acc_on) {
-			tst_resm(TINFO, "OOM on CPUSET & MEMCG with "
-					"special memswap limitation:");
-			SAFE_FILE_PRINTF(cleanup, MEMCG_SW_LIMIT, "%ld", TESTMEM);
-			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, ENOMEM, 1);
-		}
+	if (access(MEMCG_SW_LIMIT, F_OK) == -1) {
+		if (errno == ENOENT) {
+			tst_res(TCONF,
+					"memcg swap accounting is disabled");
+			swap_acc_on = 0;
+		} else
+			tst_brk(TBROK|TERRNO, "access");
 	}
 
-	cleanup();
-	tst_exit();
+	if (swap_acc_on) {
+		tst_res(TINFO, "OOM on CPUSET & MEMCG with "
+				"special memswap limitation:");
+		SAFE_FILE_PRINTF(MEMCG_SW_LIMIT, "%ld", TESTMEM);
+		testoom(0, 0, ENOMEM, 1);
+
+		tst_res(TINFO, "OOM on CPUSET & MEMCG with "
+				"disabled memswap limitation:");
+		SAFE_FILE_PRINTF(MEMCG_SW_LIMIT, "-1");
+		testoom(0, 0, ENOMEM, 1);
+	}
 }
 
 void setup(void)
 {
 	int ret, memnode;
 
-	tst_require_root();
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	TEST_PAUSE;
-
 	if (!is_numa(NULL, NH_MEMS, 1))
-		tst_brkm(TCONF, NULL, "requires NUMA with at least 1 node");
+		tst_brk(TCONF, "requires NUMA with at least 1 node");
 
 	overcommit = get_sys_tune("overcommit_memory");
 	set_sys_tune("overcommit_memory", 1, 1);
@@ -128,8 +100,8 @@ void setup(void)
 	 */
 	ret = get_allowed_nodes(NH_MEMS, 1, &memnode);
 	if (ret < 0)
-		tst_brkm(TBROK, cleanup, "Failed to get a memory node "
-				      "using get_allowed_nodes()");
+		tst_brk(TBROK, "Failed to get a memory node "
+			      "using get_allowed_nodes()");
 	write_cpusets(memnode);
 }
 
@@ -140,9 +112,15 @@ void cleanup(void)
 	umount_mem(MEMCG_PATH, MEMCG_PATH_NEW);
 }
 
+static struct tst_test test = {
+	.tid = "oom05",
+	.needs_root = 1,
+	.forks_child = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_oom,
+};
+
 #else /* no NUMA */
-int main(void)
-{
-	tst_brkm(TCONF, NULL, "no NUMA development packages installed.");
-}
+	TST_TEST_TCONF("no NUMA development packages installed.");
 #endif
-- 
2.9.3


  parent reply	other threads:[~2017-04-10 10:05 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-10 10:05 [LTP] [PATCH V2 00/14] Convert LTP kernel/mem/testcase to New API Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 01/14] mem/lib: convert to new API Li Wang
2017-04-10 10:05 ` Li Wang [this message]
2017-04-10 10:05 ` [LTP] [PATCH V2 03/14] mem/oom: fix the timeout issue Li Wang
2017-07-07 15:11   ` Cyril Hrubis
2017-07-10  7:01     ` Li Wang
2017-07-13  9:06       ` Richard Palethorpe
2017-07-14  3:16         ` Li Wang
2017-07-10  7:38     ` Jan Stancek
2017-04-10 10:05 ` [LTP] [PATCH V2 04/14] mem/ksm: convert to new API Li Wang
2017-07-07 14:49   ` Cyril Hrubis
2017-07-07 15:29     ` Cyril Hrubis
2017-07-10  7:33     ` Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 05/14] mem/thp: " Li Wang
2017-07-07 15:27   ` Cyril Hrubis
2017-07-11  4:32     ` Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 06/14] mem/hugetlb: " Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 07/14] mem/hugemmap: " Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 08/14] mem/hugeshmat: " Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 09/14] mem/hugeshmctl: " Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 10/14] mm/hugeshmdt: " Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 11/14] mem/hugeshmget: " Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 12/14] mem/cpuset: " Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 13/14] mem/swapping: " Li Wang
2017-04-10 10:05 ` [LTP] [PATCH V2 14/14] mem/tunable: " Li Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170410100556.4465-3-liwang@redhat.com \
    --to=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox