#include #include #include #include #include enum { STACK = 32768 }; void xxxsrand(long); long xxxlrand(void); Channel *cw; Channel *cr; char *host; int blocksize, seed, randpct; int doread, dowrite, packets, permute; vlong totalbytes, cur; VtConn *z; int multi; int maxpackets; int sequence; int doublecheck = 1; uint *order; void usage(void) { fprint(2, "usage: randtest [-q] [-h host] [-s seed] [-b blocksize] [-p randpct] [-n totalbytes] [-M maxblocks] [-P] [-r] [-w]\n"); threadexitsall("usage"); } void wr(char *buf, char *buf2) { uchar score[VtScoreSize], score2[VtScoreSize]; DigestState ds; USED(buf2); memset(&ds, 0, sizeof ds); if(doublecheck) sha1((uchar*)buf, blocksize, score, &ds); if(vtwrite(z, score2, VtDataType, (uchar*)buf, blocksize) < 0) sysfatal("vtwrite %V at %,lld: %r", score, cur); if(doublecheck && memcmp(score, score2, VtScoreSize) != 0) sysfatal("score mismatch! %V %V", score, score2); } void wrthread(void *v) { char *p; USED(v); while((p = recvp(cw)) != nil){ wr(p, nil); free(p); } } void rd(char *buf, char *buf2) { uchar score[VtScoreSize]; DigestState ds; memset(&ds, 0, sizeof ds); sha1((uchar*)buf, blocksize, score, &ds); if(vtread(z, score, VtDataType, (uchar*)buf2, blocksize) < 0) sysfatal("vtread %V at %,lld: %r", score, cur); if(memcmp(buf, buf2, blocksize) != 0) sysfatal("bad data read! %V", score); } void rdthread(void *v) { char *p, *buf2; buf2 = vtmalloc(blocksize); USED(v); while((p = recvp(cr)) != nil){ rd(p, buf2); free(p); } } char *template; void run(void (*fn)(char*, char*), Channel *c) { int i, t, j, packets; char *buf2, *buf; buf2 = vtmalloc(blocksize); buf = vtmalloc(blocksize); cur = 0; packets = totalbytes/blocksize; if(maxpackets == 0) maxpackets = packets; order = vtmalloc(packets*sizeof order[0]); for(i=0; i= 0) rng_vec[i] = x; } } void xxxsrand(long seed) { isrand(seed); } long xxxlrand(void) { ulong x; rng_tap--; if(rng_tap < rng_vec) { if(rng_feed == 0) { isrand(1); rng_tap--; } rng_tap += LEN; } rng_feed--; if(rng_feed < rng_vec) rng_feed += LEN; x = (*rng_feed + *rng_tap) & MASK; *rng_feed = x; return x; }