diff mbox series

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

Message ID 20230807033536.1927020-1-ycliang@andestech.com
State Accepted
Headers show
Series [v2,1/1] hugeshmat04: make use of save_restore to simplify code | expand

Commit Message

Leo Liang Aug. 7, 2023, 3:35 a.m. UTC
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(-)

Comments

Li Wang Aug. 10, 2023, 7:29 a.m. UTC | #1
Hi Leo,

Thanks for your work, patch was applied.
diff mbox series

Patch

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},
+		{}
+	},
 };