64-bit VFS_LSEEK_OFF
[minix3.git] / test / test74.c
blobda92740dc4ca71b38750b04e07ec40539ff2e589
1 /* Test 74 - mmap functionality test.
2 */
4 #include <sys/types.h>
5 #include <sys/mman.h>
6 #include <sys/ioc_memory.h>
7 #include <stdio.h>
8 #include <assert.h>
9 #include <string.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <fcntl.h>
14 #include "common.h"
15 #include "testcache.h"
17 int
18 dowriteblock(int b, int blocksize, u32_t seed, char *data)
20 u64_t offset;
21 int fd;
23 get_fd_offset(b, blocksize, &offset, &fd);
25 if(pwrite(fd, data, blocksize, offset) < blocksize) {
26 perror("pwrite");
27 return -1;
30 return blocksize;
33 int
34 readblock(int b, int blocksize, u32_t seed, char *data)
36 u64_t offset;
37 int fd;
38 char *mmapdata;
39 int pread_first = random() % 2;
41 get_fd_offset(b, blocksize, &offset, &fd);
43 if(pread_first) {
44 if(pread(fd, data, blocksize, offset) < blocksize) {
45 perror("pread");
46 return -1;
50 if((mmapdata = mmap(NULL, blocksize, PROT_READ, MAP_PRIVATE | MAP_FILE,
51 fd, offset)) == MAP_FAILED) {
52 perror("mmap");
53 return -1;
56 if(!pread_first) {
57 if(pread(fd, data, blocksize, offset) < blocksize) {
58 perror("pread");
59 return -1;
63 if(memcmp(mmapdata, data, blocksize)) {
64 fprintf(stderr, "readblock: mmap, pread mismatch\n");
65 return -1;
68 if(munmap(mmapdata, blocksize) < 0) {
69 perror("munmap");
70 return -1;
73 return blocksize;
76 void testend(void) { }
78 void basic_regression(void)
80 void *block;
81 #define BLOCKSIZE (PAGE_SIZE*10)
82 block = mmap(0, BLOCKSIZE, PROT_READ | PROT_WRITE,
83 MAP_PRIVATE | MAP_ANON, -1, 0);
85 if(block == MAP_FAILED) { e(1); exit(1); }
87 memset(block, 0, BLOCKSIZE);
89 /* shrink from bottom */
90 munmap(block, PAGE_SIZE);
93 int
94 main(int argc, char *argv[])
96 int iter = 2;
98 start(74);
100 basic_regression();
102 makefiles(MAXFILES);
104 cachequiet(!bigflag);
105 if(bigflag) iter = 3;
107 /* Try various combinations working set sizes
108 * and block sizes in order to specifically
109 * target the primary cache, then primary+secondary
110 * cache, then primary+secondary cache+secondary
111 * cache eviction.
114 if(dotest(PAGE_SIZE, 100, iter)) e(5);
115 if(dotest(PAGE_SIZE*2, 100, iter)) e(2);
116 if(dotest(PAGE_SIZE*3, 100, iter)) e(3);
117 if(dotest(PAGE_SIZE, 20000, iter)) e(5);
119 if(bigflag) {
120 u32_t totalmem, freemem, cachedmem;
121 if(dotest(PAGE_SIZE, 150000, iter)) e(5);
122 getmem(&totalmem, &freemem, &cachedmem);
123 if(dotest(PAGE_SIZE, totalmem*1.5, iter)) e(6);
126 quit();
128 return 0;