[LTP] [PATCH v1 3/4] mmapstress01: use FILE_OFFSET_BITS=64

Edward Liaw edliaw@google.com
Mon Sep 26 20:26:24 CEST 2022


Build tests with FILE_OFFSET_BITS=64 instead of doing LARGE_FILE checks
to switch between 32 and 64 bit types and syscalls.

Signed-off-by: Edward Liaw <edliaw@google.com>
---
 testcases/kernel/mem/mmapstress/Makefile      |  2 +
 .../kernel/mem/mmapstress/mmapstress01.c      | 57 +------------------
 2 files changed, 4 insertions(+), 55 deletions(-)

diff --git a/testcases/kernel/mem/mmapstress/Makefile b/testcases/kernel/mem/mmapstress/Makefile
index 744f099d8..b30bd34b8 100644
--- a/testcases/kernel/mem/mmapstress/Makefile
+++ b/testcases/kernel/mem/mmapstress/Makefile
@@ -5,3 +5,5 @@ top_srcdir              ?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
+
+mmapstress01: CFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c
index aad4ba942..cb18241de 100644
--- a/testcases/kernel/mem/mmapstress/mmapstress01.c
+++ b/testcases/kernel/mem/mmapstress/mmapstress01.c
@@ -140,14 +140,14 @@ static void setup(void)
 	if (!opt_nprocs)
 		tst_brk(TBROK, "missing number of mapping children, specify with -p nprocs");
 
-#ifdef LARGE_FILE
+#if _FILE_OFFSET_BITS == 64
 	if (tst_parse_filesize(opt_filesize, &filesize, 0, LONG_MAX))
 #else
 	if (tst_parse_filesize(opt_filesize, &filesize, 0, INT_MAX))
 #endif
 		tst_brk(TBROK, "invalid initial filesize '%s'", opt_filesize);
 
-#ifdef LARGE_FILE
+#if _FILE_OFFSET_BITS == 64
 	if (tst_parse_filesize(opt_sparseoffset, &sparseoffset, LONG_MIN, LONG_MAX))
 #else
 	if (tst_parse_filesize(opt_sparseoffset, &sparseoffset, INT_MIN, INT_MAX))
@@ -186,11 +186,7 @@ static void run(void)
 	int i;
 	int write_cnt;
 	unsigned char data;
-#ifdef LARGE_FILE
-	off64_t bytes_left;
-#else /* LARGE_FILE */
 	off_t bytes_left;
-#endif /* LARGE_FILE */
 
 	seed = initrand();
 	pattern = seed & 0xff;
@@ -217,11 +213,7 @@ static void run(void)
 			tst_brk(TFAIL, "sigaction error");
 		(void)alarm(alarmtime);
 	}
-#ifdef LARGE_FILE
-	if ((fd = open64(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, 0664)) == -1) {
-#else /* LARGE_FILE */
 	if ((fd = open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, 0664)) == -1) {
-#endif /* LARGE_FILE */
 		tst_brk(TFAIL, "open error");
 	}
 
@@ -238,11 +230,7 @@ static void run(void)
 		if (++data == nprocs)
 			data = 0;
 	}
-#ifdef LARGE_FILE
-	if (lseek64(fd, (off64_t)sparseoffset, SEEK_SET) < 0) {
-#else /* LARGE_FILE */
 	if (lseek(fd, (off_t)sparseoffset, SEEK_SET) < 0) {
-#endif /* LARGE_FILE */
 		tst_brk(TFAIL, "lseek");
 	}
 	for (bytes_left = filesize; bytes_left; bytes_left -= c) {
@@ -371,15 +359,9 @@ static void cleanup(void)
  */
 void child_mapper(char *file, unsigned int procno, unsigned int nprocs)
 {
-#ifdef LARGE_FILE
-	struct stat64 statbuf;
-	off64_t filesize;
-	off64_t offset;
-#else /* LARGE_FILE */
 	struct stat statbuf;
 	off_t filesize;
 	off_t offset;
-#endif /* LARGE_FILE */
 	size_t validsize;
 	size_t mapsize;
 	char *maddr = NULL, *paddr;
@@ -394,19 +376,11 @@ void child_mapper(char *file, unsigned int procno, unsigned int nprocs)
 
 	seed = initrand();	/* initialize random seed */
 
-#ifdef LARGE_FILE
-	if (stat64(file, &statbuf) == -1)
-#else /* LARGE_FILE */
 	if (stat(file, &statbuf) == -1)
-#endif /* LARGE_FILE */
 		tst_brk(TFAIL, "stat error");
 	filesize = statbuf.st_size;
 
-#ifdef LARGE_FILE
-	if ((fd = open64(file, O_RDWR)) == -1)
-#else /* LARGE_FILE */
 	if ((fd = open(file, O_RDWR)) == -1)
-#endif /* LARGE_FILE */
 		tst_brk(TFAIL, "open error");
 
 	if (statbuf.st_size - sparseoffset > UINT_MAX)
@@ -428,13 +402,8 @@ void child_mapper(char *file, unsigned int procno, unsigned int nprocs)
 			     "mapsize %ld, off %lld, loop %d",
 			     procno, getpid(), seed, (long long)filesize, (long)mapsize,
 			     (long long)offset / pagesize, nloops);
-#ifdef LARGE_FILE
-	if ((maddr = mmap64(0, mapsize, PROT_READ | PROT_WRITE, MAP_SHARED,
-			    fd, offset)) == (caddr_t) - 1)
-#else /* LARGE_FILE */
 	if ((maddr = mmap(0, mapsize, PROT_READ | PROT_WRITE, MAP_SHARED,
 			  fd, offset)) == (caddr_t) - 1)
-#endif /* LARGE_FILE */
 		tst_brk(TFAIL, "mmap error");
 
 	(void)close(fd);
@@ -485,11 +454,7 @@ void child_mapper(char *file, unsigned int procno, unsigned int nprocs)
  */
 int fileokay(char *file, unsigned char *expbuf)
 {
-#ifdef LARGE_FILE
-	struct stat64 statbuf;
-#else /* LARGE_FILE */
 	struct stat statbuf;
-#endif /* LARGE_FILE */
 	size_t mapsize;
 	unsigned int mappages;
 	unsigned int pagesize = sysconf(_SC_PAGE_SIZE);
@@ -498,25 +463,13 @@ int fileokay(char *file, unsigned char *expbuf)
 	int cnt;
 	unsigned int i, j;
 
-#ifdef LARGE_FILE
-	if ((fd = open64(file, O_RDONLY)) == -1)
-#else /* LARGE_FILE */
 	if ((fd = open(file, O_RDONLY)) == -1)
-#endif /* LARGE_FILE */
 		tst_brk(TFAIL, "open error");
 
-#ifdef LARGE_FILE
-	if (fstat64(fd, &statbuf) == -1)
-#else /* LARGE_FILE */
 	if (fstat(fd, &statbuf) == -1)
-#endif /* LARGE_FILE */
 		tst_brk(TFAIL, "stat error");
 
-#ifdef LARGE_FILE
-	if (lseek64(fd, sparseoffset, SEEK_SET) < 0)
-#else /* LARGE_FILE */
 	if (lseek(fd, sparseoffset, SEEK_SET) < 0)
-#endif /* LARGE_FILE */
 		tst_brk(TFAIL, "lseek");
 
 	if (statbuf.st_size - sparseoffset > UINT_MAX)
@@ -549,15 +502,9 @@ int fileokay(char *file, unsigned char *expbuf)
 				tst_res(TINFO,
 					      "read bad data: exp %c got %c)",
 					      expbuf[j], readbuf[j]);
-#ifdef LARGE_FILE
-				tst_res(TINFO, ", pg %d off %d, "
-					      "(fsize %Ld)", i, j,
-					      statbuf.st_size);
-#else /* LARGE_FILE */
 				tst_res(TINFO, ", pg %d off %d, "
 					      "(fsize %ld)", i, j,
 					      statbuf.st_size);
-#endif /* LARGE_FILE */
 				close(fd);
 				return 0;
 			}
-- 
2.37.3.998.g577e59143f-goog



More information about the ltp mailing list