1 /* testvm - service-started code that goes with test73.o
4 #include <minix/drivers.h>
5 #include <minix/chardriver.h>
14 #include "testcache.h"
16 static char *pipefilename
= NULL
, *progname
;
21 static char *bdata
= NULL
;
23 int dowriteblock(int b
, int blocksize
, u32_t seed
, char *block
)
27 r
=vm_yield_block_get_block(VM_BLOCKID_NONE
, b
, bdata
, blocksize
);
29 if(r
!= OK
&& r
!= ESRCH
) {
30 printf("dowriteblock: vm_yield_block_get_block get %d\n", r
);
34 memcpy(bdata
, block
, blocksize
);
36 r
=vm_yield_block_get_block(b
, VM_BLOCKID_NONE
, bdata
, blocksize
);
39 printf("dowriteblock: vm_yield_block_get_block yield %d\n", r
);
46 int readblock(int b
, int blocksize
, u32_t seed
, char *block
)
50 r
=vm_yield_block_get_block(VM_BLOCKID_NONE
, b
, bdata
, blocksize
);
55 printf("readblock: vm_yield_block_get_block get %d\n", r
);
59 memcpy(block
, bdata
, blocksize
);
60 r
=vm_yield_block_get_block(b
, VM_BLOCKID_NONE
, bdata
, blocksize
);
62 printf("readblock: vm_yield_block_get_block yield %d\n", r
);
69 void testend(void) { vm_forgetblocks(); }
72 writepipe(struct info
*i
)
74 if(write(pipefd
, i
, sizeof(*i
)) != sizeof(*i
)) {
75 printf("%s: pipe write failed\n", progname
);
86 for(attempts
= 0; attempts
< 5 && pipefd
< 0; attempts
++) {
87 if(attempts
> 0) sleep(1);
88 pipefd
= open(pipefilename
, O_WRONLY
| O_NONBLOCK
);
92 printf("%s: could not open pipe %s, errno %d\n",
93 progname
, pipefilename
, errno
);
97 if(fstat(pipefd
, &st
) < 0) {
98 printf("%s: could not fstat pipe %s\n", progname
, pipefilename
);
102 if(!(st
.st_mode
& I_NAMED_PIPE
)) {
103 printf("%s: file %s is not a pipe\n", progname
, pipefilename
);
111 sef_cb_init(int type
, sef_init_info_t
*UNUSED(info
))
120 sef_setcb_init_fresh(sef_cb_init
);
121 sef_setcb_init_lu(sef_cb_init
);
122 sef_setcb_init_restart(sef_cb_init
);
130 main(int argc
, char *argv
[])
134 u32_t totalmem
, freemem
, cachedmem
;
138 if(argc
< 2) { printf("no args\n"); return 1; }
140 pipefilename
=argv
[1];
142 big
= !!strstr(pipefilename
, "big");
146 info
.result
= time(NULL
);
148 if(testinit() != OK
) { printf("%s: testinit failed\n", progname
); return 1; }
152 if(!(bdata
= alloc_contig(PAGE_SIZE
, 0, NULL
))) {
153 printf("could not allocate block\n");
157 if(dotest(PAGE_SIZE
, 10, 3)) { e(11); exit(1); }
158 if(dotest(PAGE_SIZE
, 1000, 3)) { e(11); exit(1); }
159 if(dotest(PAGE_SIZE
, 50000, 3)) { e(11); exit(1); }
161 getmem(&totalmem
, &freemem
, &cachedmem
);
162 if(dotest(PAGE_SIZE
, totalmem
*1.5, 3)) { e(11); exit(1); }