8 enum { STACK = 32768 };
15 int blocksize, seed, randpct;
16 int doread, dowrite, packets, permute;
17 vlong totalbytes, cur;
28 fprint(2, "usage: randtest [-q] [-h host] [-s seed] [-b blocksize] [-p randpct] [-n totalbytes] [-M maxblocks] [-P] [-r] [-w]\n");
29 threadexitsall("usage");
33 wr(char *buf, char *buf2)
35 uchar score[VtScoreSize], score2[VtScoreSize];
38 memset(&ds, 0, sizeof ds);
40 sha1((uchar*)buf, blocksize, score, &ds);
41 if(vtwrite(z, score2, VtDataType, (uchar*)buf, blocksize) < 0)
42 sysfatal("vtwrite %V at %,lld: %r", score, cur);
43 if(doublecheck && memcmp(score, score2, VtScoreSize) != 0)
44 sysfatal("score mismatch! %V %V", score, score2);
53 while((p = recvp(cw)) != nil){
60 rd(char *buf, char *buf2)
62 uchar score[VtScoreSize];
65 memset(&ds, 0, sizeof ds);
66 sha1((uchar*)buf, blocksize, score, &ds);
67 if(vtread(z, score, VtDataType, (uchar*)buf2, blocksize) < 0)
68 sysfatal("vtread %V at %,lld: %r", score, cur);
69 if(memcmp(buf, buf2, blocksize) != 0)
70 sysfatal("bad data read! %V", score);
78 buf2 = vtmalloc(blocksize);
80 while((p = recvp(cr)) != nil){
89 run(void (*fn)(char*, char*), Channel *c)
94 buf2 = vtmalloc(blocksize);
95 buf = vtmalloc(blocksize);
97 packets = totalbytes/blocksize;
100 order = vtmalloc(packets*sizeof order[0]);
101 for(i=0; i<packets; i++)
104 for(i=1; i<packets; i++){
111 for(i=0; i<packets && i<maxpackets; i++){
112 memmove(buf, template, blocksize);
113 *(uint*)buf = order[i];
116 buf = vtmalloc(blocksize);
124 #define TWID64 ((u64int)~(u64int)0)
134 n = strtoul(s, &es, 0);
135 if(*es == 'k' || *es == 'K'){
138 }else if(*es == 'm' || *es == 'M'){
141 }else if(*es == 'g' || *es == 'G'){
144 }else if(*es == 't' || *es == 'T'){
154 threadmain(int argc, char *argv[])
166 totalbytes = 1*1024*1024*1024;
167 fmtinstall('V', vtscorefmt);
168 fmtinstall('F', vtfcallfmt);
172 blocksize = unittoull(EARGF(usage()));
175 host = EARGF(usage());
178 maxpackets = unittoull(EARGF(usage()));
181 multi = atoi(EARGF(usage()));
184 totalbytes = unittoull(EARGF(usage()));
187 randpct = atoi(EARGF(usage()));
194 ventidoublechecksha1 = 0;
197 seed = atoi(EARGF(usage()));
212 if(doread==0 && dowrite==0){
219 sysfatal("could not connect to server: %r");
221 sysfatal("vtconnect: %r");
224 cr = chancreate(sizeof(void*), 0);
225 cw = chancreate(sizeof(void*), 0);
226 for(i=0; i<multi; i++){
227 proccreate(wrthread, nil, STACK);
228 proccreate(rdthread, nil, STACK);
232 template = vtmalloc(blocksize);
234 max = (256*randpct)/100;
237 for(i=0; i<blocksize; i++)
238 template[i] = xxxlrand()%max;
242 for(i=0; i<multi; i++)
244 t = (nsec() - t0)/1.e9;
245 print("write: %lld bytes / %.3f seconds = %.6f MB/s\n",
246 totalbytes, t, (double)totalbytes/1e6/t);
251 for(i=0; i<multi; i++)
253 t = (nsec() - t0)/1.e9;
254 print("read: %lld bytes / %.3f seconds = %.6f MB/s\n",
255 totalbytes, t, (double)totalbytes/1e6/t);
263 * D. P. Mitchell & J. A. Reeds
268 #define MASK 0x7fffffffL
273 #define NORM (1.0/(1.0+MASK))
275 static ulong rng_vec[LEN];
276 static ulong* rng_tap = rng_vec;
277 static ulong* rng_feed = 0;
286 rng_feed = rng_vec+LEN-TAP;
294 * Initialize by x[n+1] = 48271 * x[n] mod (2**31 - 1)
296 for(i = -20; i < LEN; i++) {
319 if(rng_tap < rng_vec) {
327 if(rng_feed < rng_vec)
329 x = (*rng_feed + *rng_tap) & MASK;