[LTP] [PATCH 2/2] kernel: make use of .min_mem_avail

Li Wang liwang@redhat.com
Wed Feb 9 09:57:00 CET 2022


Set the minimum size of MemAvailable for tests.

Signed-off-by: Li Wang <liwang@redhat.com>
---
 testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c |  7 ++-----
 testcases/kernel/mem/swapping/swapping01.c           |  5 +----
 testcases/kernel/syscalls/getrusage/getrusage03.c    | 10 +---------
 3 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
index b76da93a1..128671051 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
@@ -81,20 +81,16 @@ static void shared_hugepage(void)
 
 static void setup(void)
 {
-	long mem_total, hpage_size, orig_hugepages;
+	long hpage_size, orig_hugepages;
 
 	if (tst_hugepages == 0)
 		tst_brk(TCONF, "Not enough hugepages for testing.");
 
 	orig_hugepages = get_sys_tune("nr_hugepages");
-	mem_total = SAFE_READ_MEMINFO("MemTotal:");
 	SAFE_FILE_SCANF(PATH_SHMMAX, "%ld", &orig_shmmax);
 	SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", (long)SIZE);
 	SAFE_FILE_SCANF(PATH_SHMMAX, "%ld", &new_shmmax);
 
-	if (mem_total < 2L*1024*1024)
-		tst_brk(TCONF,	"Needed > 2GB RAM, have: %ld", mem_total);
-
 	if (new_shmmax < SIZE)
 		tst_brk(TCONF,	"shmmax too low, have: %ld", new_shmmax);
 
@@ -122,6 +118,7 @@ static struct tst_test test = {
 	.needs_tmpdir = 1,
 	.tcnt = 3,
 	.test = test_hugeshmat,
+	.min_mem_avail = 2048,
 	.setup = setup,
 	.cleanup = cleanup,
 	.request_hugepages = 1,
diff --git a/testcases/kernel/mem/swapping/swapping01.c b/testcases/kernel/mem/swapping/swapping01.c
index 6db0f9866..1a494bf69 100644
--- a/testcases/kernel/mem/swapping/swapping01.c
+++ b/testcases/kernel/mem/swapping/swapping01.c
@@ -95,10 +95,6 @@ static void init_meminfo(void)
 	mem_over = mem_available_init * COE_SLIGHT_OVER;
 	mem_over_max = mem_available_init * COE_DELTA;
 
-	/* at least 10MB available physical memory needed */
-	if (mem_available_init < 10240)
-		tst_brk(TCONF, "Not enough available mem to test.");
-
 	if (swap_free_init < mem_over_max)
 		tst_brk(TCONF, "Not enough swap space to test: swap_free_init(%ldkB) < mem_over_max(%ldkB)",
 				swap_free_init, mem_over_max);
@@ -162,6 +158,7 @@ static void check_swapping(void)
 static struct tst_test test = {
 	.needs_root = 1,
 	.forks_child = 1,
+	.min_mem_avail = 10,
 	.test_all = test_swapping,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "50a15981a1fa"},
diff --git a/testcases/kernel/syscalls/getrusage/getrusage03.c b/testcases/kernel/syscalls/getrusage/getrusage03.c
index 201d258fa..676fea1c9 100644
--- a/testcases/kernel/syscalls/getrusage/getrusage03.c
+++ b/testcases/kernel/syscalls/getrusage/getrusage03.c
@@ -173,24 +173,16 @@ static void run(unsigned int i)
 	}
 }
 
-static void setup(void)
-{
-	long long mem_avail = tst_available_mem();
-
-	if (mem_avail < 512L*1024)
-		tst_brk(TCONF, "Needed > 512MB available, only have: %ld kB", mem_avail);
-}
-
 static struct tst_test test = {
 	.forks_child = 1,
 	.child_needs_reinit = 1,
 	.resource_files = resource,
 	.min_kver = "2.6.32",
+	.min_mem_avail = 512,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "1f10206cf8e9"},
 		{}
 	},
-	.setup = setup,
 	.test = run,
 	.tcnt = ARRAY_SIZE(testfunc_list),
 };
-- 
2.31.1



More information about the ltp mailing list