📄 tchmttest.c
字号:
tstr = argv[i]; } else if(!rstr){ rstr = argv[i]; } else if(!bstr){ bstr = argv[i]; } else if(!astr){ astr = argv[i]; } else if(!fstr){ fstr = argv[i]; } else { usage(); } } if(!path || !tstr || !rstr) usage(); int tnum = tcatoi(tstr); int rnum = tcatoi(rstr); if(tnum < 1 || rnum < 1) usage(); int bnum = bstr ? tcatoi(bstr) : -1; int apow = astr ? tcatoi(astr) : -1; int fpow = fstr ? tcatoi(fstr) : -1; int rv = proctypical(path, tnum, rnum, bnum, apow, fpow, opts, rcnum, xmsiz, omode, nc, rratio); return rv;}/* perform write command */static int procwrite(const char *path, int tnum, int rnum, int bnum, int apow, int fpow, int opts, int rcnum, int xmsiz, int omode, bool as, bool rnd){ iprintf("<Writing Test>\n path=%s tnum=%d rnum=%d bnum=%d apow=%d fpow=%d" " opts=%d rcnum=%d xmsiz=%d omode=%d as=%d rnd=%d\n\n", path, tnum, rnum, bnum, apow, fpow, opts, rcnum, xmsiz, omode, as, rnd); bool err = false; double stime = tctime(); TCHDB *hdb = tchdbnew(); if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd); if(!tchdbsetmutex(hdb)){ eprint(hdb, "tchdbsetmutex"); err = true; } if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){ eprint(hdb, "tchdbsetcodecfunc"); err = true; } if(!tchdbtune(hdb, bnum, apow, fpow, opts)){ eprint(hdb, "tchdbtune"); err = true; } if(!tchdbsetcache(hdb, rcnum)){ eprint(hdb, "tchdbsetcache"); err = true; } if(xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)){ eprint(hdb, "tchdbsetxmsiz"); err = true; } if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)){ eprint(hdb, "tchdbopen"); err = true; } TARGWRITE targs[tnum]; pthread_t threads[tnum]; if(tnum == 1){ targs[0].hdb = hdb; targs[0].rnum = rnum; targs[0].as = as; targs[0].rnd = rnd; targs[0].id = 0; if(threadwrite(targs) != NULL) err = true; } else { for(int i = 0; i < tnum; i++){ targs[i].hdb = hdb; targs[i].rnum = rnum; targs[i].as = as; targs[i].rnd = rnd; targs[i].id = i; if(pthread_create(threads + i, NULL, threadwrite, targs + i) != 0){ eprint(hdb, "pthread_create"); targs[i].id = -1; err = true; } } for(int i = 0; i < tnum; i++){ if(targs[i].id == -1) continue; void *rv; if(pthread_join(threads[i], &rv) != 0){ eprint(hdb, "pthread_join"); err = true; } else if(rv){ err = true; } } } iprintf("record number: %llu\n", (unsigned long long)tchdbrnum(hdb)); iprintf("size: %llu\n", (unsigned long long)tchdbfsiz(hdb)); mprint(hdb); if(!tchdbclose(hdb)){ eprint(hdb, "tchdbclose"); err = true; } tchdbdel(hdb); iprintf("time: %.3f\n", tctime() - stime); iprintf("%s\n\n", err ? "error" : "ok"); return err ? 1 : 0;}/* perform read command */static int procread(const char *path, int tnum, int rcnum, int xmsiz, int omode, bool wb, bool rnd){ iprintf("<Reading Test>\n path=%s tnum=%d rcnum=%d xmsiz=%d omode=%d wb=%d rnd=%d\n\n", path, tnum, rcnum, xmsiz, omode, wb, rnd); bool err = false; double stime = tctime(); TCHDB *hdb = tchdbnew(); if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd); if(!tchdbsetmutex(hdb)){ eprint(hdb, "tchdbsetmutex"); err = true; } if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){ eprint(hdb, "tchdbsetcodecfunc"); err = true; } if(!tchdbsetcache(hdb, rcnum)){ eprint(hdb, "tchdbsetcache"); err = true; } if(xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)){ eprint(hdb, "tchdbsetxmsiz"); err = true; } if(!tchdbopen(hdb, path, HDBOREADER | omode)){ eprint(hdb, "tchdbopen"); err = true; } int rnum = tchdbrnum(hdb) / tnum; TARGREAD targs[tnum]; pthread_t threads[tnum]; if(tnum == 1){ targs[0].hdb = hdb; targs[0].rnum = rnum; targs[0].wb = wb; targs[0].rnd = rnd; targs[0].id = 0; if(threadread(targs) != NULL) err = true; } else { for(int i = 0; i < tnum; i++){ targs[i].hdb = hdb; targs[i].rnum = rnum; targs[i].wb = wb; targs[i].rnd = rnd; targs[i].id = i; if(pthread_create(threads + i, NULL, threadread, targs + i) != 0){ eprint(hdb, "pthread_create"); targs[i].id = -1; err = true; } } for(int i = 0; i < tnum; i++){ if(targs[i].id == -1) continue; void *rv; if(pthread_join(threads[i], &rv) != 0){ eprint(hdb, "pthread_join"); err = true; } else if(rv){ err = true; } } } iprintf("record number: %llu\n", (unsigned long long)tchdbrnum(hdb)); iprintf("size: %llu\n", (unsigned long long)tchdbfsiz(hdb)); mprint(hdb); if(!tchdbclose(hdb)){ eprint(hdb, "tchdbclose"); err = true; } tchdbdel(hdb); iprintf("time: %.3f\n", tctime() - stime); iprintf("%s\n\n", err ? "error" : "ok"); return err ? 1 : 0;}/* perform remove command */static int procremove(const char *path, int tnum, int rcnum, int xmsiz, int omode, bool rnd){ iprintf("<Removing Test>\n path=%s tnum=%d rcnum=%d xmsiz=%d omode=%d rnd=%d\n\n", path, tnum, rcnum, xmsiz, omode, rnd); bool err = false; double stime = tctime(); TCHDB *hdb = tchdbnew(); if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd); if(!tchdbsetmutex(hdb)){ eprint(hdb, "tchdbsetmutex"); err = true; } if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){ eprint(hdb, "tchdbsetcodecfunc"); err = true; } if(!tchdbsetcache(hdb, rcnum)){ eprint(hdb, "tchdbsetcache"); err = true; } if(xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)){ eprint(hdb, "tchdbsetxmsiz"); err = true; } if(!tchdbopen(hdb, path, HDBOWRITER | omode)){ eprint(hdb, "tchdbopen"); err = true; } int rnum = tchdbrnum(hdb) / tnum; TARGREMOVE targs[tnum]; pthread_t threads[tnum]; if(tnum == 1){ targs[0].hdb = hdb; targs[0].rnum = rnum; targs[0].rnd = rnd; targs[0].id = 0; if(threadremove(targs) != NULL) err = true; } else { for(int i = 0; i < tnum; i++){ targs[i].hdb = hdb; targs[i].rnum = rnum; targs[i].rnd = rnd; targs[i].id = i; if(pthread_create(threads + i, NULL, threadremove, targs + i) != 0){ eprint(hdb, "pthread_create"); targs[i].id = -1; err = true; } } for(int i = 0; i < tnum; i++){ if(targs[i].id == -1) continue; void *rv; if(pthread_join(threads[i], &rv) != 0){ eprint(hdb, "pthread_join"); err = true; } else if(rv){ err = true; } } } iprintf("record number: %llu\n", (unsigned long long)tchdbrnum(hdb)); iprintf("size: %llu\n", (unsigned long long)tchdbfsiz(hdb)); mprint(hdb); if(!tchdbclose(hdb)){ eprint(hdb, "tchdbclose"); err = true; } tchdbdel(hdb); iprintf("time: %.3f\n", tctime() - stime); iprintf("%s\n\n", err ? "error" : "ok"); return err ? 1 : 0;}/* perform wicked command */static int procwicked(const char *path, int tnum, int rnum, int opts, int omode, bool nc){ iprintf("<Writing Test>\n path=%s tnum=%d rnum=%d opts=%d omode=%d nc=%d\n\n", path, tnum, rnum, opts, omode, nc); bool err = false; double stime = tctime(); TCHDB *hdb = tchdbnew(); if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd); if(!tchdbsetmutex(hdb)){ eprint(hdb, "tchdbsetmutex"); err = true; } if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){ eprint(hdb, "tchdbsetcodecfunc"); err = true; } if(!tchdbtune(hdb, rnum / 50, 2, -1, opts)){ eprint(hdb, "tchdbtune"); err = true; } if(!tchdbsetcache(hdb, rnum / 2)){ eprint(hdb, "tchdbsetcache"); err = true; } if(!tchdbsetxmsiz(hdb, rnum * sizeof(int))){ eprint(hdb, "tchdbsetxmsiz"); err = true; } if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)){ eprint(hdb, "tchdbopen"); err = true; } if(!tchdbiterinit(hdb)){ eprint(hdb, "tchdbiterinit"); err = true; } TARGWICKED targs[tnum]; pthread_t threads[tnum]; TCMAP *map = tcmapnew(); if(tnum == 1){ targs[0].hdb = hdb; targs[0].rnum = rnum; targs[0].nc = nc; targs[0].id = 0; targs[0].map = map; if(threadwicked(targs) != NULL) err = true; } else { for(int i = 0; i < tnum; i++){ targs[i].hdb = hdb; targs[i].rnum = rnum; targs[i].nc = nc; targs[i].id = i; targs[i].map = map; if(pthread_create(threads + i, NULL, threadwicked, targs + i) != 0){ eprint(hdb, "pthread_create"); targs[i].id = -1; err = true; } } for(int i = 0; i < tnum; i++){ if(targs[i].id == -1) continue; void *rv; if(pthread_join(threads[i], &rv) != 0){ eprint(hdb, "pthread_join"); err = true; } else if(rv){ err = true; } } } if(!nc){ if(!tchdbsync(hdb)){ eprint(hdb, "tchdbsync"); err = true; } if(tchdbrnum(hdb) != tcmaprnum(map)){ eprint(hdb, "(validation)"); err = true; } int end = rnum * tnum; for(int i = 1; i <= end && !err; i++){ char kbuf[RECBUFSIZ]; int ksiz = sprintf(kbuf, "%d", i - 1); int vsiz; const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz); int rsiz; char *rbuf = tchdbget(hdb, kbuf, ksiz, &rsiz); if(vbuf){ iputchar('.'); if(!rbuf){ eprint(hdb, "tchdbget"); err = true; } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){ eprint(hdb, "(validation)"); err = true; } } else { iputchar('*'); if(rbuf || tchdbecode(hdb) != TCENOREC){ eprint(hdb, "(validation)"); err = true; } } tcfree(rbuf); if(i % 50 == 0) iprintf(" (%08d)\n", i); } if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum); } tcmapdel(map); iprintf("record number: %llu\n", (unsigned long long)tchdbrnum(hdb)); iprintf("size: %llu\n", (unsigned long long)tchdbfsiz(hdb)); mprint(hdb); if(!tchdbclose(hdb)){ eprint(hdb, "tchdbclose"); err = true; } tchdbdel(hdb); iprintf("time: %.3f\n", tctime() - stime); iprintf("%s\n\n", err ? "error" : "ok"); return err ? 1 : 0;}/* perform typical command */static int proctypical(const char *path, int tnum, int rnum, int bnum, int apow, int fpow, int opts, int rcnum, int xmsiz, int omode, bool nc, int rratio){ iprintf("<Typical Access Test>\n path=%s tnum=%d rnum=%d bnum=%d apow=%d fpow=%d" " opts=%d rcnum=%d xmsiz=%d omode=%d nc=%d rratio=%d\n\n", path, tnum, rnum, bnum, apow, fpow, opts, rcnum, xmsiz, omode, nc, rratio); bool err = false; double stime = tctime(); TCHDB *hdb = tchdbnew(); if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd); if(!tchdbsetmutex(hdb)){ eprint(hdb, "tchdbsetmutex"); err = true; } if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){ eprint(hdb, "tchdbsetcodecfunc"); err = true; } if(!tchdbtune(hdb, bnum, apow, fpow, opts)){ eprint(hdb, "tchdbtune"); err = true; } if(!tchdbsetcache(hdb, rcnum)){ eprint(hdb, "tchdbsetcache"); err = true; } if(xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)){ eprint(hdb, "tchdbsetxmsiz"); err = true; } if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)){ eprint(hdb, "tchdbopen"); err = true; } TARGTYPICAL targs[tnum]; pthread_t threads[tnum]; if(tnum == 1){ targs[0].hdb = hdb; targs[0].rnum = rnum; targs[0].nc = nc; targs[0].rratio = rratio; targs[0].id = 0; if(threadtypical(targs) != NULL) err = true; } else { for(int i = 0; i < tnum; i++){ targs[i].hdb = hdb; targs[i].rnum = rnum; targs[i].nc = nc; targs[i].rratio= rratio; targs[i].id = i; if(pthread_create(threads + i, NULL, threadtypical, targs + i) != 0){ eprint(hdb, "pthread_create"); targs[i].id = -1; err = true; } } for(int i = 0; i < tnum; i++){ if(targs[i].id == -1) continue; void *rv; if(pthread_join(threads[i], &rv) != 0){ eprint(hdb, "pthread_join"); err = true; } else if(rv){ err = true; } } } iprintf("record number: %llu\n", (unsigned long long)tchdbrnum(hdb)); iprintf("size: %llu\n", (unsigned long long)tchdbfsiz(hdb)); mprint(hdb); if(!tchdbclose(hdb)){ eprint(hdb, "tchdbclose"); err = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -