📄 tcttest.c
字号:
} else if(!fstr){ fstr = argv[i]; } else { usage(); } } if(!path || !rstr) usage(); int rnum = tcatoix(rstr); if(rnum < 1) usage(); int bnum = bstr ? tcatoix(bstr) : -1; int apow = astr ? tcatoix(astr) : -1; int fpow = fstr ? tcatoix(fstr) : -1; int rv = procrcat(path, rnum, bnum, apow, fpow, mt, opts, rcnum, lcnum, ncnum, xmsiz, iflags, omode, pnum, dai, dad, rl, ru); return rv;}/* parse arguments of misc command */static int runmisc(int argc, char **argv){ char *path = NULL; char *rstr = NULL; bool mt = false; int opts = 0; int omode = 0; for(int i = 2; i < argc; i++){ if(!path && argv[i][0] == '-'){ if(!strcmp(argv[i], "-mt")){ mt = true; } else if(!strcmp(argv[i], "-tl")){ opts |= TDBTLARGE; } else if(!strcmp(argv[i], "-td")){ opts |= TDBTDEFLATE; } else if(!strcmp(argv[i], "-tb")){ opts |= TDBTBZIP; } else if(!strcmp(argv[i], "-tt")){ opts |= TDBTTCBS; } else if(!strcmp(argv[i], "-tx")){ opts |= TDBTEXCODEC; } else if(!strcmp(argv[i], "-nl")){ omode |= TDBONOLCK; } else if(!strcmp(argv[i], "-nb")){ omode |= TDBOLCKNB; } else { usage(); } } else if(!path){ path = argv[i]; } else if(!rstr){ rstr = argv[i]; } else { usage(); } } if(!path || !rstr) usage(); int rnum = tcatoix(rstr); if(rnum < 1) usage(); int rv = procmisc(path, rnum, mt, opts, omode); return rv;}/* parse arguments of wicked command */static int runwicked(int argc, char **argv){ char *path = NULL; char *rstr = NULL; bool mt = false; int opts = 0; int omode = 0; for(int i = 2; i < argc; i++){ if(!path && argv[i][0] == '-'){ if(!strcmp(argv[i], "-mt")){ mt = true; } else if(!strcmp(argv[i], "-tl")){ opts |= TDBTLARGE; } else if(!strcmp(argv[i], "-td")){ opts |= TDBTDEFLATE; } else if(!strcmp(argv[i], "-tb")){ opts |= TDBTBZIP; } else if(!strcmp(argv[i], "-tt")){ opts |= TDBTTCBS; } else if(!strcmp(argv[i], "-tx")){ opts |= TDBTEXCODEC; } else if(!strcmp(argv[i], "-nl")){ omode |= TDBONOLCK; } else if(!strcmp(argv[i], "-nb")){ omode |= TDBOLCKNB; } else { usage(); } } else if(!path){ path = argv[i]; } else if(!rstr){ rstr = argv[i]; } else { usage(); } } if(!path || !rstr) usage(); int rnum = tcatoix(rstr); if(rnum < 1) usage(); int rv = procwicked(path, rnum, mt, opts, omode); return rv;}/* perform write command */static int procwrite(const char *path, int rnum, int bnum, int apow, int fpow, bool mt, int opts, int rcnum, int lcnum, int ncnum, int xmsiz, int iflags, int omode, bool rnd){ iprintf("<Writing Test>\n seed=%u path=%s rnum=%d bnum=%d apow=%d fpow=%d mt=%d" " opts=%d rcnum=%d lcnum=%d ncnum=%d xmsiz=%d iflags=%d omode=%d rnd=%d\n\n", g_randseed, path, rnum, bnum, apow, fpow, mt, opts, rcnum, lcnum, ncnum, xmsiz, iflags, omode, rnd); bool err = false; double stime = tctime(); TCTDB *tdb = tctdbnew(); if(g_dbgfd >= 0) tctdbsetdbgfd(tdb, g_dbgfd); if(mt && !tctdbsetmutex(tdb)){ eprint(tdb, "tctdbsetmutex"); err = true; } if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)){ eprint(tdb, "tctdbsetcodecfunc"); err = true; } if(!tctdbtune(tdb, bnum, apow, fpow, opts)){ eprint(tdb, "tctdbtune"); err = true; } if(!tctdbsetcache(tdb, rcnum, lcnum, ncnum)){ eprint(tdb, "tctdbsetcache"); err = true; } if(xmsiz >= 0 && !tctdbsetxmsiz(tdb, xmsiz)){ eprint(tdb, "tctdbsetxmsiz"); err = true; } if(!rnd) omode |= TDBOTRUNC; if(!tctdbopen(tdb, path, TDBOWRITER | TDBOCREAT | omode)){ eprint(tdb, "tctdbopen"); err = true; } if((iflags & (1 << 0)) && !tctdbsetindex(tdb, "", TDBITDECIMAL)){ eprint(tdb, "tctdbsetindex"); err = true; } if((iflags & (1 << 1)) && !tctdbsetindex(tdb, "str", TDBITLEXICAL)){ eprint(tdb, "tctdbsetindex"); err = true; } if((iflags & (1 << 2)) && !tctdbsetindex(tdb, "num", TDBITDECIMAL)){ eprint(tdb, "tctdbsetindex"); err = true; } if((iflags & (1 << 3)) && !tctdbsetindex(tdb, "type", TDBITDECIMAL)){ eprint(tdb, "tctdbsetindex"); err = true; } if((iflags & (1 << 4)) && !tctdbsetindex(tdb, "flag", TDBITLEXICAL)){ eprint(tdb, "tctdbsetindex"); err = true; } for(int i = 1; i <= rnum; i++){ int id = rnd ? myrand(rnum) + 1 : (int)tctdbgenuid(tdb); char pkbuf[RECBUFSIZ]; int pksiz = sprintf(pkbuf, "%d", id); TCMAP *cols = tcmapnew2(7); char vbuf[RECBUFSIZ*5]; int vsiz = sprintf(vbuf, "%d", id); tcmapput(cols, "str", 3, vbuf, vsiz); vsiz = sprintf(vbuf, "%d", myrand(i) + 1); tcmapput(cols, "num", 3, vbuf, vsiz); vsiz = sprintf(vbuf, "%d", myrand(32) + 1); tcmapput(cols, "type", 4, vbuf, vsiz); int num = myrand(5); int pt = 0; char *wp = vbuf; for(int j = 0; j < num; j++){ pt += myrand(5) + 1; if(wp > vbuf) *(wp++) = ','; wp += sprintf(wp, "%d", pt); } *wp = '\0'; if(*vbuf != '\0') tcmapput(cols, "flag", 4, vbuf, wp - vbuf); if(!tctdbput(tdb, pkbuf, pksiz, cols)){ eprint(tdb, "tctdbput"); err = true; break; } tcmapdel(cols); if(rnum > 250 && i % (rnum / 250) == 0){ iputchar('.'); if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i); } } iprintf("record number: %llu\n", (unsigned long long)tctdbrnum(tdb)); iprintf("size: %llu\n", (unsigned long long)tctdbfsiz(tdb)); sysprint(); if(!tctdbclose(tdb)){ eprint(tdb, "tctdbclose"); err = true; } tctdbdel(tdb); 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, bool mt, int rcnum, int lcnum, int ncnum, int xmsiz, int omode, bool rnd){ iprintf("<Reading Test>\n seed=%u path=%s mt=%d rcnum=%d lcnum=%d ncnum=%d xmsiz=%d" " omode=%d rnd=%d\n\n", g_randseed, path, mt, rcnum, lcnum, ncnum, xmsiz, omode, rnd); bool err = false; double stime = tctime(); TCTDB *tdb = tctdbnew(); if(g_dbgfd >= 0) tctdbsetdbgfd(tdb, g_dbgfd); if(mt && !tctdbsetmutex(tdb)){ eprint(tdb, "tctdbsetmutex"); err = true; } if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)){ eprint(tdb, "tctdbsetcodecfunc"); err = true; } if(!tctdbsetcache(tdb, rcnum, lcnum, ncnum)){ eprint(tdb, "tctdbsetcache"); err = true; } if(xmsiz >= 0 && !tctdbsetxmsiz(tdb, xmsiz)){ eprint(tdb, "tctdbsetxmsiz"); err = true; } if(!tctdbopen(tdb, path, TDBOREADER | omode)){ eprint(tdb, "tctdbopen"); err = true; } int rnum = tctdbrnum(tdb); for(int i = 1; i <= rnum; i++){ char pkbuf[RECBUFSIZ]; int pksiz = sprintf(pkbuf, "%d", rnd ? myrand(rnum) + 1 : i); TCMAP *cols = tctdbget(tdb, pkbuf, pksiz); if(cols){ tcmapdel(cols); } else if(!rnd || tctdbecode(tdb) != TCENOREC){ eprint(tdb, "tctdbget"); err = true; break; } if(rnum > 250 && i % (rnum / 250) == 0){ iputchar('.'); if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i); } } iprintf("record number: %llu\n", (unsigned long long)tctdbrnum(tdb)); iprintf("size: %llu\n", (unsigned long long)tctdbfsiz(tdb)); sysprint(); if(!tctdbclose(tdb)){ eprint(tdb, "tctdbclose"); err = true; } tctdbdel(tdb); 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, bool mt, int rcnum, int lcnum, int ncnum, int xmsiz, int omode, bool rnd){ iprintf("<Removing Test>\n seed=%u path=%s mt=%d rcnum=%d lcnum=%d ncnum=%d xmsiz=%d" " omode=%d rnd=%d\n\n", g_randseed, path, mt, rcnum, lcnum, ncnum, xmsiz, omode, rnd); bool err = false; double stime = tctime(); TCTDB *tdb = tctdbnew(); if(g_dbgfd >= 0) tctdbsetdbgfd(tdb, g_dbgfd); if(mt && !tctdbsetmutex(tdb)){ eprint(tdb, "tctdbsetmutex"); err = true; } if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)){ eprint(tdb, "tctdbsetcodecfunc"); err = true; } if(!tctdbsetcache(tdb, rcnum, lcnum, ncnum)){ eprint(tdb, "tctdbsetcache"); err = true; } if(xmsiz >= 0 && !tctdbsetxmsiz(tdb, xmsiz)){ eprint(tdb, "tctdbsetxmsiz"); err = true; } if(!tctdbopen(tdb, path, TDBOWRITER | omode)){ eprint(tdb, "tctdbopen"); err = true; } int rnum = tctdbrnum(tdb); for(int i = 1; i <= rnum; i++){ char pkbuf[RECBUFSIZ]; int pksiz = sprintf(pkbuf, "%d", rnd ? myrand(rnum) + 1 : i); if(!tctdbout(tdb, pkbuf, pksiz) && !(rnd && tctdbecode(tdb) == TCENOREC)){ eprint(tdb, "tctdbout"); err = true; break; } if(rnum > 250 && i % (rnum / 250) == 0){ iputchar('.'); if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i); } } iprintf("record number: %llu\n", (unsigned long long)tctdbrnum(tdb)); iprintf("size: %llu\n", (unsigned long long)tctdbfsiz(tdb)); sysprint(); if(!tctdbclose(tdb)){ eprint(tdb, "tctdbclose"); err = true; } tctdbdel(tdb); iprintf("time: %.3f\n", tctime() - stime); iprintf("%s\n\n", err ? "error" : "ok"); return err ? 1 : 0;}/* perform rcat command */static int procrcat(const char *path, int rnum, int bnum, int apow, int fpow, bool mt, int opts, int rcnum, int lcnum, int ncnum, int xmsiz, int iflags, int omode, int pnum, bool dai, bool dad, bool rl, bool ru){ iprintf("<Random Concatenating Test>\n" " seed=%u path=%s rnum=%d bnum=%d apow=%d fpow=%d mt=%d opts=%d" " rcnum=%d lcnum=%d ncnum=%d xmsiz=%d iflags=%d" " omode=%d pnum=%d dai=%d dad=%d rl=%d ru=%d\n\n", g_randseed, path, rnum, bnum, apow, fpow, mt, opts, rcnum, lcnum, rcnum, xmsiz, iflags, omode, pnum, dai, dad, rl, ru); if(pnum < 1) pnum = rnum; bool err = false; double stime = tctime(); TCTDB *tdb = tctdbnew(); if(g_dbgfd >= 0) tctdbsetdbgfd(tdb, g_dbgfd); if(mt && !tctdbsetmutex(tdb)){ eprint(tdb, "tctdbsetmutex"); err = true; } if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)){ eprint(tdb, "tctdbsetcodecfunc"); err = true; } if(!tctdbtune(tdb, bnum, apow, fpow, opts)){ eprint(tdb, "tctdbtune"); err = true; } if(!tctdbsetcache(tdb, rcnum, lcnum, ncnum)){ eprint(tdb, "tctdbsetcache"); err = true; } if(xmsiz >= 0 && !tctdbsetxmsiz(tdb, xmsiz)){ eprint(tdb, "tctdbsetxmsiz"); err = true; } if(!tctdbopen(tdb, path, TDBOWRITER | TDBOCREAT | TDBOTRUNC | omode)){ eprint(tdb, "tctdbopen"); err = true; } if((iflags & (1 << 0)) && !tctdbsetindex(tdb, "", TDBITDECIMAL)){ eprint(tdb, "tctdbsetindex"); err = true; } if((iflags & (1 << 1)) && !tctdbsetindex(tdb, "str", TDBITLEXICAL)){ eprint(tdb, "tctdbsetindex"); err = true; } if((iflags & (1 << 2)) && !tctdbsetindex(tdb, "num", TDBITDECIMAL)){ eprint(tdb, "tctdbsetindex"); err = true; } if((iflags & (1 << 3)) && !tctdbsetindex(tdb, "type", TDBITDECIMAL)){ eprint(tdb, "tctdbsetindex"); err = true; } if((iflags & (1 << 4)) && !tctdbsetindex(tdb, "flag", TDBITLEXICAL)){ eprint(tdb, "tctdbsetindex"); err = true; } for(int i = 1; i <= rnum; i++){ int id = myrand(pnum) + 1; char pkbuf[RECBUFSIZ]; int pksiz = sprintf(pkbuf, "%d", id); TCMAP *cols = tcmapnew2(7); char vbuf[RECBUFSIZ*5]; int vsiz = sprintf(vbuf, "%d", id); tcmapput(cols, "str", 3, vbuf, vsiz); vsiz = sprintf(vbuf, "%d", myrand(i) + 1); tcmapput(cols, "num", 3, vbuf, vsiz); vsiz = sprintf(vbuf, "%d", myrand(32) + 1); tcmapput(cols, "type", 4, vbuf, vsiz); int num = myrand(5); int pt = 0; char *wp = vbuf; for(int j = 0; j < num; j++){ pt += myrand(5) + 1; if(wp > vbuf) *(wp++) = ','; wp += sprintf(wp, "%d", pt); } *wp = '\0'; if(*vbuf != '\0') tcmapput(cols, "flag", 4, vbuf, wp - vbuf); char nbuf[RECBUFSIZ]; int nsiz = sprintf(nbuf, "c%d", myrand(pnum) + 1); vsiz = sprintf(vbuf, "%d", myrand(rnum) + 1); tcmapput(cols, nbuf, nsiz, vbuf, vsiz); if(ru){ switch(myrand(7)){ case 0: if(!tctdbput(tdb, pkbuf, pksiz, cols)){ eprint(tdb, "tctdbput"); err = true; } break; case 1: if(!tctdbputkeep(tdb, pkbuf, pksiz, cols) && tctdbecode(tdb) != TCEKEEP){ eprint(tdb, "tctdbputkeep"); err = true; } break; case 2: if(!tctdbout(tdb, pkbuf, pksiz) && tctdbecode(tdb) != TCENOREC){ eprint(tdb, "tctdbout"); err = true; } break; case 3: if(tctdbaddint(tdb, pkbuf, pksiz, 1) == INT_MIN && tctdbecode(tdb) != TCEKEEP){ eprint(tdb, "tctdbaddint"); err = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -