/* thread the read function */ static void *threadread(void *targ){ TCFDB *fdb = ((TARGREAD *)targ)->fdb; int rnum = ((TARGREAD *)targ)->rnum; bool wb = ((TARGREAD *)targ)->wb; bool rnd = ((TARGREAD *)targ)->rnd; int id = ((TARGREAD *)targ)->id; bool err = false; int base = id * rnum; for(int i = 1; i <= rnum && !err; i++){ uint64_t kid = base + (rnd ? myrandnd(i) + 1 : i); int vsiz; if(wb){ char vbuf[RECBUFSIZ]; int vsiz = tcfdbget4(fdb, kid, vbuf, RECBUFSIZ); if(vsiz < 0 && (!rnd || tcfdbecode(fdb) != TCENOREC)){ eprint(fdb, __LINE__, "tcfdbget4"); err = true; } } else { char *vbuf = tcfdbget(fdb, kid, &vsiz); if(!vbuf && (!rnd || tcfdbecode(fdb) != TCENOREC)){ eprint(fdb, __LINE__, "tcfdbget"); err = true; } tcfree(vbuf); } if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){ iputchar('.'); if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i); } } return err ? "error" : NULL; }
/* thread the typical function */ static void *threadtypical(void *targ){ TCFDB *fdb = ((TARGTYPICAL *)targ)->fdb; int rnum = ((TARGTYPICAL *)targ)->rnum; bool nc = ((TARGTYPICAL *)targ)->nc; int rratio = ((TARGTYPICAL *)targ)->rratio; int id = ((TARGTYPICAL *)targ)->id; bool err = false; TCMAP *map = (!nc && id == 0) ? tcmapnew2(rnum + 1) : NULL; int base = id * rnum; int mrange = tclmax(50 + rratio, 100); int width = tcfdbwidth(fdb); for(int i = 1; !err && i <= rnum; i++){ char buf[RECBUFSIZ]; int len = sprintf(buf, "%08d", base + myrandnd(i) + 1); int rnd = myrand(mrange); if(rnd < 10){ if(!tcfdbput2(fdb, buf, len, buf, len)){ eprint(fdb, __LINE__, "tcfdbput2"); err = true; } if(map) tcmapput(map, buf, len, buf, len); } else if(rnd < 15){ if(!tcfdbputkeep2(fdb, buf, len, buf, len) && tcfdbecode(fdb) != TCEKEEP){ eprint(fdb, __LINE__, "tcfdbputkeep2"); err = true; } if(map) tcmapputkeep(map, buf, len, buf, len); } else if(rnd < 20){ if(!tcfdbputcat2(fdb, buf, len, buf, len)){ eprint(fdb, __LINE__, "tcfdbputcat2"); err = true; } if(map) tcmapputcat(map, buf, len, buf, len); } else if(rnd < 25){ if(!tcfdbout2(fdb, buf, len) && tcfdbecode(fdb) && tcfdbecode(fdb) != TCENOREC){ eprint(fdb, __LINE__, "tcfdbout"); err = true; } if(map) tcmapout(map, buf, len); } else if(rnd < 26){ if(myrand(10) == 0 && !tcfdbiterinit(fdb) && tcfdbecode(fdb) != TCENOREC){ eprint(fdb, __LINE__, "tcfdbiterinit"); err = true; } for(int j = 0; !err && j < 10; j++){ if(tcfdbiternext(fdb) < 1 && tcfdbecode(fdb) != TCEINVALID && tcfdbecode(fdb) != TCENOREC){ eprint(fdb, __LINE__, "tcfdbiternext"); err = true; } } } else { int vsiz; char *vbuf = tcfdbget2(fdb, buf, len, &vsiz); if(vbuf){ if(map){ int msiz = 0; const char *mbuf = tcmapget(map, buf, len, &msiz); if(msiz > width) msiz = width; if(!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){ eprint(fdb, __LINE__, "(validation)"); err = true; } } tcfree(vbuf); } else { if(tcfdbecode(fdb) != TCENOREC){ eprint(fdb, __LINE__, "tcfdbget"); err = true; } if(map && tcmapget(map, buf, len, &vsiz)){ eprint(fdb, __LINE__, "(validation)"); err = true; } } } if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){ iputchar('.'); if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i); } } if(map){ tcmapiterinit(map); int ksiz; const char *kbuf; while(!err && (kbuf = tcmapiternext(map, &ksiz)) != NULL){ int vsiz; char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz); if(vbuf){ int msiz = 0; const char *mbuf = tcmapget(map, kbuf, ksiz, &msiz); if(msiz > width) msiz = width; if(!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){ eprint(fdb, __LINE__, "(validation)"); err = true; } tcfree(vbuf); } else { eprint(fdb, __LINE__, "(validation)"); err = true; } } tcmapdel(map); } return err ? "error" : NULL; }
/* thread the typical function */ static void *threadtypical(void *targ){ TCMDB *mdb = ((TARGTYPICAL *)targ)->mdb; TCNDB *ndb = ((TARGCOMBO *)targ)->ndb; int rnum = ((TARGTYPICAL *)targ)->rnum; bool nc = ((TARGTYPICAL *)targ)->nc; int rratio = ((TARGTYPICAL *)targ)->rratio; int id = ((TARGTYPICAL *)targ)->id; bool err = false; TCMAP *map = (!nc && id == 0) ? tcmapnew2(rnum + 1) : NULL; int base = id * rnum; int mrange = tclmax(50 + rratio, 100); for(int i = 1; !err && i <= rnum; i++){ char buf[RECBUFSIZ]; int len = sprintf(buf, "%08d", base + myrandnd(i)); int rnd = myrand(mrange); if(rnd < 10){ if(ndb){ tcndbput(ndb, buf, len, buf, len); } else { tcmdbput(mdb, buf, len, buf, len); } if(map) tcmapput(map, buf, len, buf, len); } else if(rnd < 15){ if(ndb){ tcndbputkeep(ndb, buf, len, buf, len); } else { tcmdbputkeep(mdb, buf, len, buf, len); } if(map) tcmapputkeep(map, buf, len, buf, len); } else if(rnd < 20){ if(ndb){ tcndbputcat(ndb, buf, len, buf, len); } else { tcmdbputcat(mdb, buf, len, buf, len); } if(map) tcmapputcat(map, buf, len, buf, len); } else if(rnd < 30){ if(ndb){ tcndbout(ndb, buf, len); } else { tcmdbout(mdb, buf, len); } if(map) tcmapout(map, buf, len); } else if(rnd < 31){ if(myrand(10) == 0) tcmdbiterinit(mdb); for(int j = 0; !err && j < 10; j++){ int ksiz; char *kbuf = ndb ? tcndbiternext(ndb, &ksiz) : tcmdbiternext(mdb, &ksiz); if(kbuf) tcfree(kbuf); } } else { int vsiz; char *vbuf = ndb ? tcndbget(ndb, buf, len, &vsiz) : tcmdbget(mdb, buf, len, &vsiz); if(vbuf){ if(map){ int msiz; const char *mbuf = tcmapget(map, buf, len, &msiz); if(msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){ eprint(__LINE__, "(validation)"); err = true; } } tcfree(vbuf); } else { if(map && tcmapget(map, buf, len, &vsiz)){ eprint(__LINE__, "(validation)"); err = true; } } } if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){ iputchar('.'); if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i); } } if(map){ tcmapiterinit(map); int ksiz; const char *kbuf; while(!err && (kbuf = tcmapiternext(map, &ksiz)) != NULL){ int vsiz; char *vbuf = ndb ? tcndbget(ndb, kbuf, ksiz, &vsiz) : tcmdbget(mdb, kbuf, ksiz, &vsiz); if(vbuf){ int msiz; const char *mbuf = tcmapget(map, kbuf, ksiz, &msiz); if(!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){ eprint(__LINE__, "(validation)"); err = true; } tcfree(vbuf); } else { eprint(__LINE__, "(validation)"); err = true; } } tcmapdel(map); } return err ? "error" : NULL; }