[LTP] [PATCH 6/6] syscalls/madvise06: Convert to new test API

Li Wang liwang@redhat.com
Thu May 12 10:49:53 CEST 2016


Signed-off-by: Li Wang <liwang@redhat.com>
---
 testcases/kernel/syscalls/madvise/madvise06.c | 64 +++++++++------------------
 1 file changed, 21 insertions(+), 43 deletions(-)

diff --git a/testcases/kernel/syscalls/madvise/madvise06.c b/testcases/kernel/syscalls/madvise/madvise06.c
index 366827c..6b081fd 100644
--- a/testcases/kernel/syscalls/madvise/madvise06.c
+++ b/testcases/kernel/syscalls/madvise/madvise06.c
@@ -33,39 +33,15 @@
  *       mm: madvise: fix MADV_WILLNEED on shmem swapouts
  */
 
-#include <stdio.h>
 #include <errno.h>
 #include <sys/sysinfo.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID = "madvise06";
-int TST_TOTAL = 1;
+#include "tst_test.h"
 
 #define GB_SZ  (1024*1024*1024)
 
 static long dst_max;
 static int pg_sz;
 
-static void setup(void);
-static int  get_page_fault_num(void);
-static void test_advice_willneed(void);
-
-int main(int argc, char *argv[])
-{
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++)
-		test_advice_willneed();
-
-	tst_exit();
-}
-
 static void setup(void)
 {
 	struct sysinfo sys_buf;
@@ -73,25 +49,21 @@ static void setup(void)
 	sysinfo(&sys_buf);
 
 	if (sys_buf.totalram < 2L * GB_SZ)
-		tst_brkm(TCONF, NULL, "Test requires more than 2GB of RAM");
+		tst_brk(TCONF, "Test requires more than 2GB of RAM");
 	if (sys_buf.totalram > 100L * GB_SZ)
-		tst_brkm(TCONF, NULL, "System RAM is too large, skip test");
+		tst_brk(TCONF, "System RAM is too large, skip test");
 
 	dst_max = sys_buf.totalram / GB_SZ;
-	tst_resm(TINFO, "dst_max = %ld", dst_max);
+	tst_res(TINFO, "dst_max = %ld", dst_max);
 
 	pg_sz = getpagesize();
-
-	tst_sig(NOFORK, DEF_HANDLER, NULL);
-
-	TEST_PAUSE;
 }
 
 static int get_page_fault_num(void)
 {
 	int pg;
 
-	SAFE_FILE_SCANF(NULL, "/proc/self/stat",
+	SAFE_FILE_SCANF("/proc/self/stat",
 			"%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %d",
 			&pg);
 
@@ -107,13 +79,13 @@ static void test_advice_willneed(void)
 	int page_fault_num_2;
 
 	/* allocate source memory (1GB only) */
-	src = SAFE_MMAP(NULL, NULL, 1 * GB_SZ, PROT_READ | PROT_WRITE,
+	src = SAFE_MMAP(NULL, 1 * GB_SZ, PROT_READ | PROT_WRITE,
 			MAP_SHARED | MAP_ANONYMOUS,
 			-1, 0);
 
 	/* allocate destination memory (array) */
 	for (i = 0; i < dst_max; ++i)
-		dst[i] = SAFE_MMAP(NULL, NULL, 1 * GB_SZ,
+		dst[i] = SAFE_MMAP(NULL, 1 * GB_SZ,
 				PROT_READ | PROT_WRITE,
 				MAP_SHARED | MAP_ANONYMOUS,
 				-1, 0);
@@ -122,28 +94,34 @@ static void test_advice_willneed(void)
 	for (i = 0; i < dst_max; ++i)
 		memmove(dst[i], src, 1 * GB_SZ);
 
-	tst_resm(TINFO, "PageFault(no madvice): %d", get_page_fault_num());
+	tst_res(TINFO, "PageFault(no madvice): %d", get_page_fault_num());
 
 	/* Do madvice() to dst[0] */
 	TEST(madvise(dst[0], pg_sz, MADV_WILLNEED));
 	if (TEST_RETURN == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "madvise failed");
+		tst_brk(TBROK | TERRNO, "madvise failed");
 
 	page_fault_num_1 = get_page_fault_num();
-	tst_resm(TINFO, "PageFault(madvice / no mem access): %d",
+	tst_res(TINFO, "PageFault(madvice / no mem access): %d",
 			page_fault_num_1);
 
 	*dst[0] = 'a';
 	page_fault_num_2 = get_page_fault_num();
-	tst_resm(TINFO, "PageFault(madvice / mem access): %d",
+	tst_res(TINFO, "PageFault(madvice / mem access): %d",
 			page_fault_num_2);
 
 	if (page_fault_num_1 != page_fault_num_2)
-		tst_resm(TFAIL, "Bug has been reproduced");
+		tst_res(TFAIL, "Bug has been reproduced");
 	else
-		tst_resm(TPASS, "Regression test pass");
+		tst_res(TPASS, "Regression test pass");
 
-	SAFE_MUNMAP(NULL, src, 1 * GB_SZ);
+	SAFE_MUNMAP(src, 1 * GB_SZ);
 	for (i = 0; i < dst_max; ++i)
-		SAFE_MUNMAP(NULL, dst[i], 1 * GB_SZ);
+		SAFE_MUNMAP(dst[i], 1 * GB_SZ);
 }
+
+static struct tst_test test = {
+	.tid = "madvice06",
+	.test_all = test_advice_willneed,
+	.setup = setup,
+};
-- 
1.8.3.1



More information about the ltp mailing list