[LTP] [PATCH 1/5] syscalls/mmap08: Rewrite the test using new LTP API

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


Hi!
Pushed with a minor changes, thanks.

Apart from changes similar to the previous tests I've also removed the
whole part that writes the file. There is no point in writing the file
if we are closing the fd before we pass it to the mmap() since the fd is
no longer associated with the file content. So now the test just open
and closes file and then uses that fd as an invalid one.

Full diff:

--- a/testcases/kernel/syscalls/mmap/mmap08.c
+++ b/testcases/kernel/syscalls/mmap/mmap08.c
@@ -21,30 +21,22 @@ static int fd;
 
 static void setup(void)
 {
-	char *buf;
-
-	page_sz = getpagesize();
-
-	buf = SAFE_CALLOC(page_sz, sizeof(char));
-	memset(buf, 'A', page_sz);
-
 	fd = SAFE_OPEN(TEMPFILE, O_RDWR | O_CREAT, 0666);
-	SAFE_WRITE(SAFE_WRITE_ALL, fd, buf, page_sz);
-	free(buf);
 	SAFE_CLOSE(fd);
 }
 
 static void run(void)
 {
-	TESTPTR(mmap(0, page_sz, PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0));
+	TESTPTR(mmap(NULL, page_sz, PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0));
 
 	if (TST_RET_PTR != MAP_FAILED) {
 		tst_res(TFAIL, "mmap() passed unexpectedly");
 		SAFE_MUNMAP(TST_RET_PTR, page_sz);
-	} else if (TST_ERR == EBADF)
+	} else if (TST_ERR == EBADF) {
 		tst_res(TPASS, "mmap() failed with EBADF");
-	else
+	} else {
 		tst_res(TFAIL | TERRNO, "mmap() failed with an invalid errno");
+	}
 }
 
 static void cleanup(void)


-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list