Re: [LTP] [PATCH] hugemmap/hugemmap37: migrated task-size-overrun.c from libhugetlbfs

Cyril Hrubis <[email protected]>
Newsgroups it.linux.lists.ltp
Message-ID <[email protected]>
Hi!
Pushed with following diff, thanks.

Changes:

- use TDEBUG for the verbose messages
- use TST_EXP_* macros, on Linux mmap() without MAP_FIXED ignores the
  address hint and always succeeds
- moved the code that locates task_size into the test setup() so that
  it's called exactly once on test with -i 10

diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c
index c15b4ad33..addd717e3 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c
@@ -34,6 +34,7 @@
 #define MNTPOINT "hugetlbfs/"
 
 static long hpage_size;
+static unsigned long task_size;
 static int fd = -1;
 
 static unsigned long find_last_mapped(void)
@@ -100,10 +101,10 @@ static unsigned long find_task_size(void)
 		p = mmap((void *)addr, page_size, PROT_READ,
 			   MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
 		if (p == MAP_FAILED) {
-			tst_res(TINFO | TERRNO, "Map failed at 0x%lx", addr);
+			tst_res(TDEBUG | TERRNO, "Map failed at 0x%lx", addr);
 			high = pfn;
 		} else {
-			tst_res(TINFO, "Map succeeded at 0x%lx", addr);
+			tst_res(TDEBUG, "Map succeeded at 0x%lx", addr);
 			SAFE_MUNMAP(p, page_size);
 			low = pfn;
 		}
@@ -114,45 +115,35 @@ static unsigned long find_task_size(void)
 
 static void run_test(void)
 {
-	void *p;
-	unsigned long task_size;
 	unsigned long straddle_addr;
 
-	task_size = find_task_size();
-	tst_res(TINFO, "TASK_SIZE = 0x%lx", task_size);
-
 	straddle_addr = task_size - hpage_size;
 	straddle_addr = LTP_ALIGN(straddle_addr, hpage_size);
 
 	tst_res(TINFO, "Mapping without MAP_FIXED at %lx...", straddle_addr);
-	errno = 0;
-	p = mmap((void *)straddle_addr, 2*hpage_size, PROT_READ|PROT_WRITE,
-		 MAP_SHARED, fd, 0);
-	if (p == (void *)straddle_addr) {
-		tst_res(TFAIL, "Apparently succeeded in mapping across TASK_SIZE boundary");
-		SAFE_MUNMAP(p, 2*hpage_size);
-	} else if (p != MAP_FAILED) {
-		tst_res(TPASS, "mmap without MAP_FIXED correctly avoided TASK_SIZE boundary");
-		SAFE_MUNMAP(p, 2*hpage_size);
-	} else {
-		tst_res(TPASS, "mmap without MAP_FIXED correctly failed");
-	}
+
+	TST_EXP_PASS_PTR_VOID(mmap((void *)straddle_addr, 2*hpage_size,
+	                      PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0));
+
+	if (TST_RET_PTR != MAP_FAILED)
+		SAFE_MUNMAP(TST_RET_PTR, 2*hpage_size);
 
 	tst_res(TINFO, "Mapping with MAP_FIXED at %lx...", straddle_addr);
-	errno = 0;
-	p = mmap((void *)straddle_addr, 2*hpage_size, PROT_READ|PROT_WRITE,
-		 MAP_SHARED|MAP_FIXED, fd, 0);
-	if (p != MAP_FAILED) {
-		tst_res(TFAIL, "Apparently succeeded in mapping across TASK_SIZE boundary");
-		SAFE_MUNMAP(p, 2*hpage_size);
-	} else {
-		tst_res(TPASS, "mmap with MAP_FIXED correctly failed");
-	}
+
+	TST_EXP_FAIL_PTR_VOID(mmap((void *)straddle_addr, 2*hpage_size,
+	                      PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, 0), ENOMEM);
+
+	if (TST_RET_PTR != MAP_FAILED)
+		SAFE_MUNMAP(TST_RET_PTR, 2*hpage_size);
 }
 
 static void setup(void)
 {
 	hpage_size = tst_get_hugepage_size();
+
+	task_size = find_task_size();
+	tst_res(TINFO, "TASK_SIZE = 0x%lx", task_size);
+
 	fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
 }
 



-- 
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.