[LTP] [v2, 1/1] hugeshmat04: make use of save_restore to simplify code

Leo Yu-Chi Liang ycliang@andestech.com
Mon Aug 7 05:35:36 CEST 2023


The type of shmmax is unsinged long in Linux kernel.
We should access it with the correct %lu format string.

Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Leo Yu-Chi Liang <ycliang@andestech.com>
---
 .../mem/hugetlb/hugeshmat/hugeshmat04.c       | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
index 50efa8a52..8ad745d5b 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
@@ -27,7 +27,6 @@
 
 static long huge_free;
 static long huge_free2;
-static long orig_shmmax = -1, new_shmmax;
 
 static void shared_hugepage(void);
 
@@ -81,14 +80,13 @@ static void shared_hugepage(void)
 static void setup(void)
 {
 	long hpage_size, orig_hugepages;
+	unsigned long new_shmmax;
 
 	orig_hugepages = get_sys_tune("nr_hugepages");
-	SAFE_FILE_SCANF(PATH_SHMMAX, "%ld", &orig_shmmax);
-	SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", (long)SIZE);
-	SAFE_FILE_SCANF(PATH_SHMMAX, "%ld", &new_shmmax);
+	SAFE_FILE_SCANF(PATH_SHMMAX, "%lu", &new_shmmax);
 
 	if (new_shmmax < SIZE)
-		tst_brk(TCONF,	"shmmax too low, have: %ld", new_shmmax);
+		tst_brk(TCONF,	"shmmax too low, have: %lu", new_shmmax);
 
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 
@@ -96,12 +94,6 @@ static void setup(void)
 	tst_reserve_hugepages(&hp);
 }
 
-static void cleanup(void)
-{
-	if (orig_shmmax != -1)
-		SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", orig_shmmax);
-}
-
 static struct tst_test test = {
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "c5c99429fa57"},
@@ -114,6 +106,9 @@ static struct tst_test test = {
 	.test = test_hugeshmat,
 	.min_mem_avail = 2048,
 	.setup = setup,
-	.cleanup = cleanup,
 	.hugepages = {1, TST_NEEDS},
+	.save_restore = (const struct tst_path_val[]) {
+		{PATH_SHMMAX, "1073741824", TST_SR_TCONF_MISSING | TST_SR_TBROK_RO},
+		{}
+	},
 };
-- 
2.34.1



More information about the ltp mailing list