[LTP] [PATCH 2/3] syscalls/mmap06: Refactor and add scenarios for EACCES test

Cyril Hrubis chrubis@suse.cz
Wed Aug 30 14:21:30 CEST 2023


Hi!
Pushed with minor changes, thanks.

- sizeof(char) == 1 again
- first mmap() parameter is pointer, hence should be NULL
- there is no point in printing the TERRNO if mmap() succeeded
- LKML coding style prefers curly braces around else block if they are
  around the if block

diff --git a/testcases/kernel/syscalls/mmap/mmap06.c b/testcases/kernel/syscalls/mmap/mmap06.c
index 05e0ffc69..012e7de41 100644
--- a/testcases/kernel/syscalls/mmap/mmap06.c
+++ b/testcases/kernel/syscalls/mmap/mmap06.c
@@ -36,7 +36,7 @@ static void setup(void)
 	char *buf;
 
 	page_sz = getpagesize();
-	buf = SAFE_CALLOC(page_sz, sizeof(char));
+	buf = SAFE_MALLOC(page_sz);
 	memset(buf, 'A', page_sz);
 
 	fd = SAFE_OPEN(TEMPFILE, O_WRONLY | O_CREAT, 0666);
@@ -48,15 +48,16 @@ static void run(unsigned int i)
 {
 	struct tcase *tc = &tcases[i];
 
-	TESTPTR(mmap(0, page_sz, tc->prot, tc->flags, fd, 0));
+	TESTPTR(mmap(NULL, page_sz, tc->prot, tc->flags, fd, 0));
 
 	if (TST_RET_PTR != MAP_FAILED) {
-		tst_res(TFAIL | TERRNO, "mmap() was successful unexpectedly");
+		tst_res(TFAIL, "mmap() was successful unexpectedly");
 		SAFE_MUNMAP(TST_RET_PTR, page_sz);
-	} else if (TST_ERR == EACCES)
+	} else if (TST_ERR == EACCES) {
 		tst_res(TPASS, "mmap() failed with errno EACCES");
-	else
+	} else {
 		tst_res(TFAIL | TERRNO, "mmap() failed but unexpected errno");
+	}
 }
 
 static void cleanup(void)

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list