1 /* Test 74 - mmap functionality test.
6 #include <sys/ioc_memory.h>
15 #include "testcache.h"
18 dowriteblock(int b
, int blocksize
, u32_t seed
, char *data
)
23 get_fd_offset(b
, blocksize
, &offset
, &fd
);
25 if(pwrite(fd
, data
, blocksize
, offset
) < blocksize
) {
34 readblock(int b
, int blocksize
, u32_t seed
, char *data
)
39 int pread_first
= random() % 2;
41 get_fd_offset(b
, blocksize
, &offset
, &fd
);
44 if(pread(fd
, data
, blocksize
, offset
) < blocksize
) {
50 if((mmapdata
= mmap(NULL
, blocksize
, PROT_READ
, MAP_PRIVATE
| MAP_FILE
,
51 fd
, offset
)) == MAP_FAILED
) {
57 if(pread(fd
, data
, blocksize
, offset
) < blocksize
) {
63 if(memcmp(mmapdata
, data
, blocksize
)) {
64 fprintf(stderr
, "readblock: mmap, pread mismatch\n");
68 if(munmap(mmapdata
, blocksize
) < 0) {
76 void testend(void) { }
78 void basic_regression(void)
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
);
94 main(int argc
, char *argv
[])
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
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);
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);