[LTP] [RFC][PATCH 2/2] Use safe_get_nodemap()

Petr Vorel pvorel@suse.cz
Fri Mar 28 12:43:11 CET 2025


Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/kernel/mem/ksm/ksm06.c                          | 4 +---
 testcases/kernel/syscalls/get_mempolicy/get_mempolicy01.c | 4 +---
 testcases/kernel/syscalls/get_mempolicy/get_mempolicy02.c | 4 +---
 testcases/kernel/syscalls/mbind/mbind02.c                 | 4 +---
 testcases/kernel/syscalls/mbind/mbind03.c                 | 4 +---
 testcases/kernel/syscalls/mbind/mbind04.c                 | 4 +---
 testcases/kernel/syscalls/set_mempolicy/set_mempolicy01.c | 4 +---
 testcases/kernel/syscalls/set_mempolicy/set_mempolicy02.c | 4 +---
 testcases/kernel/syscalls/set_mempolicy/set_mempolicy03.c | 4 +---
 testcases/kernel/syscalls/set_mempolicy/set_mempolicy04.c | 4 +---
 10 files changed, 10 insertions(+), 30 deletions(-)

diff --git a/testcases/kernel/mem/ksm/ksm06.c b/testcases/kernel/mem/ksm/ksm06.c
index a8e73275dd..936980dee6 100644
--- a/testcases/kernel/mem/ksm/ksm06.c
+++ b/testcases/kernel/mem/ksm/ksm06.c
@@ -124,9 +124,7 @@ static void setup(void)
 
 	page_size = getpagesize();
 
-	nodes = tst_get_nodemap(TST_NUMA_MEM, nr_pages * page_size / 1024);
-	if (nodes->cnt <= 1)
-		tst_brk(TCONF, "Test requires at least two NUMA memory nodes");
+	nodes = safe_get_nodemap(TST_NUMA_MEM, nr_pages * page_size / 1024, 2);
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/get_mempolicy/get_mempolicy01.c b/testcases/kernel/syscalls/get_mempolicy/get_mempolicy01.c
index 3c854d1096..031c35f40e 100644
--- a/testcases/kernel/syscalls/get_mempolicy/get_mempolicy01.c
+++ b/testcases/kernel/syscalls/get_mempolicy/get_mempolicy01.c
@@ -142,9 +142,7 @@ static void setup(void)
 {
 	unsigned int i;
 
-	node = tst_get_nodemap(TST_NUMA_MEM, PAGES_ALLOCATED * getpagesize() / 1024);
-	if (node->cnt < 1)
-		tst_brk(TCONF, "test requires at least one NUMA memory node");
+	node = safe_get_nodemap(TST_NUMA_MEM, PAGES_ALLOCATED * getpagesize() / 1024, 1);
 
 	nodemask = numa_allocate_nodemask();
 	empty_nodemask = numa_allocate_nodemask();
diff --git a/testcases/kernel/syscalls/get_mempolicy/get_mempolicy02.c b/testcases/kernel/syscalls/get_mempolicy/get_mempolicy02.c
index 79ff5d94f8..9344cdbb12 100644
--- a/testcases/kernel/syscalls/get_mempolicy/get_mempolicy02.c
+++ b/testcases/kernel/syscalls/get_mempolicy/get_mempolicy02.c
@@ -55,9 +55,7 @@ static struct test_case tcase[] = {
 
 static void setup(void)
 {
-	node = tst_get_nodemap(TST_NUMA_MEM, PAGES_ALLOCATED * getpagesize() / 1024);
-	if (node->cnt < 1)
-		tst_brk(TCONF, "test requires at least one NUMA memory node");
+	node = safe_get_nodemap(TST_NUMA_MEM, PAGES_ALLOCATED * getpagesize() / 1024, 1);
 
 	nodemask = numa_allocate_nodemask();
 }
diff --git a/testcases/kernel/syscalls/mbind/mbind02.c b/testcases/kernel/syscalls/mbind/mbind02.c
index cd6a032269..c690ac858e 100644
--- a/testcases/kernel/syscalls/mbind/mbind02.c
+++ b/testcases/kernel/syscalls/mbind/mbind02.c
@@ -32,9 +32,7 @@ static void setup(void)
 {
 	page_size = getpagesize();
 
-	nodes = tst_get_nodemap(TST_NUMA_MEM, 2 * page_size / 1024);
-	if (nodes->cnt <= 1)
-		tst_brk(TCONF, "Test requires at least two NUMA memory nodes");
+	nodes = safe_get_nodemap(TST_NUMA_MEM, 2 * page_size / 1024, 2);
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/mbind/mbind03.c b/testcases/kernel/syscalls/mbind/mbind03.c
index 3d477c9cbb..58967cc06a 100644
--- a/testcases/kernel/syscalls/mbind/mbind03.c
+++ b/testcases/kernel/syscalls/mbind/mbind03.c
@@ -29,9 +29,7 @@ static void setup(void)
 {
 	page_size = getpagesize();
 
-	nodes = tst_get_nodemap(TST_NUMA_MEM, 2 * page_size / 1024);
-	if (nodes->cnt <= 1)
-		tst_brk(TCONF, "Test requires at least two NUMA memory nodes");
+	nodes = safe_get_nodemap(TST_NUMA_MEM, 2 * page_size / 1024, 2);
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/mbind/mbind04.c b/testcases/kernel/syscalls/mbind/mbind04.c
index 50028835f9..795905cc14 100644
--- a/testcases/kernel/syscalls/mbind/mbind04.c
+++ b/testcases/kernel/syscalls/mbind/mbind04.c
@@ -31,9 +31,7 @@ static void setup(void)
 {
 	page_size = getpagesize();
 
-	nodes = tst_get_nodemap(TST_NUMA_MEM, 2 * PAGES_ALLOCATED * page_size / 1024);
-	if (nodes->cnt <= 1)
-		tst_brk(TCONF, "Test requires at least two NUMA memory nodes");
+	nodes = safe_get_nodemap(TST_NUMA_MEM, 2 * PAGES_ALLOCATED * page_size / 1024, 2);
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/set_mempolicy/set_mempolicy01.c b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy01.c
index 39e7156d06..92ef165d79 100644
--- a/testcases/kernel/syscalls/set_mempolicy/set_mempolicy01.c
+++ b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy01.c
@@ -32,9 +32,7 @@ static void setup(void)
 {
 	page_size = getpagesize();
 
-	nodes = tst_get_nodemap(TST_NUMA_MEM, 2 * PAGES_ALLOCATED * page_size / 1024);
-	if (nodes->cnt <= 1)
-		tst_brk(TCONF, "Test requires at least two NUMA memory nodes");
+	nodes = safe_get_nodemap(TST_NUMA_MEM, 2 * PAGES_ALLOCATED * page_size / 1024, 2);
 
 	/*
 	 * In most cases, set_mempolicy01 finish quickly, but when the platform
diff --git a/testcases/kernel/syscalls/set_mempolicy/set_mempolicy02.c b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy02.c
index 3db9c20090..57fef862da 100644
--- a/testcases/kernel/syscalls/set_mempolicy/set_mempolicy02.c
+++ b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy02.c
@@ -33,9 +33,7 @@ static void setup(void)
 {
 	page_size = getpagesize();
 
-	nodes = tst_get_nodemap(TST_NUMA_MEM, 2 * ALLOC_ON_NODE * page_size / 1024);
-	if (nodes->cnt <= 1)
-		tst_brk(TCONF, "Test requires at least two NUMA memory nodes");
+	nodes = safe_get_nodemap(TST_NUMA_MEM, 2 * ALLOC_ON_NODE * page_size / 1024, 2);
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/set_mempolicy/set_mempolicy03.c b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy03.c
index 5cfcda6d8c..ac464e5bc1 100644
--- a/testcases/kernel/syscalls/set_mempolicy/set_mempolicy03.c
+++ b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy03.c
@@ -31,9 +31,7 @@ static void setup(void)
 {
 	page_size = getpagesize();
 
-	nodes = tst_get_nodemap(TST_NUMA_MEM, 2 * PAGES_ALLOCATED * page_size / 1024);
-	if (nodes->cnt <= 1)
-		tst_brk(TCONF, "Test requires at least two NUMA memory nodes");
+	nodes = safe_get_nodemap(TST_NUMA_MEM, 2 * PAGES_ALLOCATED * page_size / 1024, 2);
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/set_mempolicy/set_mempolicy04.c b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy04.c
index 2a1d2e1b9a..8e0ed2dc2a 100644
--- a/testcases/kernel/syscalls/set_mempolicy/set_mempolicy04.c
+++ b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy04.c
@@ -44,9 +44,7 @@ static void setup(void)
 
 	page_size = getpagesize();
 
-	nodes = tst_get_nodemap(TST_NUMA_MEM, node_min_pages * page_size / 1024);
-	if (nodes->cnt <= 1)
-		tst_brk(TCONF, "Test requires at least two NUMA memory nodes");
+	nodes = safe_get_nodemap(TST_NUMA_MEM, node_min_pages * page_size / 1024, 2);
 }
 
 static void cleanup(void)
-- 
2.49.0



More information about the ltp mailing list