1 /* testvm - service-started code that goes with test73.o
4 #include <minix/drivers.h>
5 #include <minix/chardriver.h>
15 #include "testcache.h"
17 #define MYMAJOR 40 /* doesn't really matter, shouldn't be NO_DEV though */
18 #define MYDEV makedev(MYMAJOR, 1)
20 static char *pipefilename
= NULL
, *progname
;
25 static char *bdata
= NULL
;
27 int dowriteblock(int b
, int blocksize
, u32_t seed
, char *block
)
32 u64_t dev_off
= (u64_t
) b
* blocksize
;
34 if((bdata
= vm_map_cacheblock(MYDEV
, dev_off
,
35 VMC_NO_INODE
, 0, NULL
, blocksize
)) == MAP_FAILED
) {
36 if((bdata
= mmap(0, blocksize
,
37 PROT_READ
|PROT_WRITE
, MAP_ANON
, -1, 0)) == MAP_FAILED
) {
38 printf("mmap failed\n");
44 memcpy(bdata
, block
, blocksize
);
46 if(mustset
&& (r
=vm_set_cacheblock(bdata
, MYDEV
, dev_off
,
47 VMC_NO_INODE
, 0, NULL
, blocksize
)) != OK
) {
48 printf("dowriteblock: vm_set_cacheblock failed %d\n", r
);
52 if(munmap(bdata
, blocksize
) < 0) {
53 printf("dowriteblock: munmap failed %d\n", r
);
60 int readblock(int b
, int blocksize
, u32_t seed
, char *block
)
63 u64_t dev_off
= (u64_t
) b
* blocksize
;
65 if((bdata
= vm_map_cacheblock(MYDEV
, dev_off
,
66 VMC_NO_INODE
, 0, NULL
, blocksize
)) == MAP_FAILED
) {
70 memcpy(block
, bdata
, blocksize
);
72 if(munmap(bdata
, blocksize
) < 0) {
73 printf("dowriteblock: munmap failed\n");
80 void testend(void) { }
83 writepipe(struct info
*i
)
85 if(write(pipefd
, i
, sizeof(*i
)) != sizeof(*i
)) {
86 printf("%s: pipe write failed\n", progname
);
97 for(attempts
= 0; attempts
< 5 && pipefd
< 0; attempts
++) {
98 if(attempts
> 0) sleep(1);
99 pipefd
= open(pipefilename
, O_WRONLY
| O_NONBLOCK
);
103 printf("%s: could not open pipe %s, errno %d\n",
104 progname
, pipefilename
, errno
);
108 if(fstat(pipefd
, &st
) < 0) {
109 printf("%s: could not fstat pipe %s\n", progname
, pipefilename
);
113 if(!(st
.st_mode
& I_NAMED_PIPE
)) {
114 printf("%s: file %s is not a pipe\n", progname
, pipefilename
);
122 sef_cb_init(int type
, sef_init_info_t
*UNUSED(info
))
131 sef_setcb_init_fresh(sef_cb_init
);
132 sef_setcb_init_lu(sef_cb_init
);
133 sef_setcb_init_restart(sef_cb_init
);
141 main(int argc
, char *argv
[])
145 u32_t totalmem
, freemem
, cachedmem
;
149 if(argc
< 2) { printf("no args\n"); return 1; }
151 pipefilename
=argv
[1];
153 big
= !!strstr(pipefilename
, "big");
157 info
.result
= time(NULL
);
159 if(testinit() != OK
) { printf("%s: testinit failed\n", progname
); return 1; }
163 if(!(bdata
= alloc_contig(PAGE_SIZE
, 0, NULL
))) {
164 printf("could not allocate block\n");
168 if(dotest(PAGE_SIZE
, 10, 3)) { e(11); exit(1); }
169 if(dotest(PAGE_SIZE
, 1000, 3)) { e(11); exit(1); }
170 if(dotest(PAGE_SIZE
, 50000, 3)) { e(11); exit(1); }
172 getmem(&totalmem
, &freemem
, &cachedmem
);
173 if(dotest(PAGE_SIZE
, totalmem
*1.5, 3)) { e(11); exit(1); }
180 vm_clear_cache(MYDEV
);