?? tcbtest.c
字號(hào):
if(++i >= argc) usage(); lsmax = tcatoi(argv[i]); } else if(!strcmp(argv[i], "-ca")){ if(++i >= argc) usage(); capnum = tcatoi(argv[i]); } else if(!strcmp(argv[i], "-nl")){ omode |= BDBONOLCK; } else if(!strcmp(argv[i], "-nb")){ omode |= BDBOLCKNB; } else if(!strcmp(argv[i], "-pn")){ if(++i >= argc) usage(); pnum = tcatoi(argv[i]); } else if(!strcmp(argv[i], "-dai")){ dai = true; } else if(!strcmp(argv[i], "-dad")){ dad = true; } else if(!strcmp(argv[i], "-rl")){ rl = true; } else { usage(); } } else if(!path){ path = argv[i]; } else if(!rstr){ rstr = argv[i]; } else if(!lmstr){ lmstr = argv[i]; } else if(!nmstr){ nmstr = argv[i]; } else if(!bstr){ bstr = argv[i]; } else if(!astr){ astr = argv[i]; } else if(!fstr){ fstr = argv[i]; } else { usage(); } } if(!path || !rstr) usage(); int rnum = tcatoi(rstr); if(rnum < 1) usage(); int lmemb = lmstr ? tcatoi(lmstr) : -1; int nmemb = nmstr ? tcatoi(nmstr) : -1; int bnum = bstr ? tcatoi(bstr) : -1; int apow = astr ? tcatoi(astr) : -1; int fpow = fstr ? tcatoi(fstr) : -1; int rv = procrcat(path, rnum, lmemb, nmemb, bnum, apow, fpow, mt, cmp, opts, lcnum, ncnum, xmsiz, lsmax, capnum, omode, pnum, dai, dad, rl); return rv;}/* parse arguments of queue command */static int runqueue(int argc, char **argv){ char *path = NULL; char *rstr = NULL; char *lmstr = NULL; char *nmstr = NULL; char *bstr = NULL; char *astr = NULL; char *fstr = NULL; bool mt = false; BDBCMP cmp = NULL; int opts = 0; int lcnum = 0; int ncnum = 0; int xmsiz = 0; int lsmax = 0; int capnum = 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], "-cd")){ cmp = tcbdbcmpdecimal; } else if(!strcmp(argv[i], "-ci")){ cmp = tcbdbcmpint32; } else if(!strcmp(argv[i], "-cj")){ cmp = tcbdbcmpint64; } else if(!strcmp(argv[i], "-tl")){ opts |= BDBTLARGE; } else if(!strcmp(argv[i], "-td")){ opts |= BDBTDEFLATE; } else if(!strcmp(argv[i], "-tb")){ opts |= BDBTBZIP; } else if(!strcmp(argv[i], "-tt")){ opts |= BDBTTCBS; } else if(!strcmp(argv[i], "-tx")){ opts |= BDBTEXCODEC; } else if(!strcmp(argv[i], "-lc")){ if(++i >= argc) usage(); lcnum = tcatoi(argv[i]); } else if(!strcmp(argv[i], "-nc")){ if(++i >= argc) usage(); ncnum = tcatoi(argv[i]); } else if(!strcmp(argv[i], "-xm")){ if(++i >= argc) usage(); xmsiz = tcatoi(argv[i]); } else if(!strcmp(argv[i], "-ls")){ if(++i >= argc) usage(); lsmax = tcatoi(argv[i]); } else if(!strcmp(argv[i], "-ca")){ if(++i >= argc) usage(); capnum = tcatoi(argv[i]); } else if(!strcmp(argv[i], "-nl")){ omode |= BDBONOLCK; } else if(!strcmp(argv[i], "-nb")){ omode |= BDBOLCKNB; } else { usage(); } } else if(!path){ path = argv[i]; } else if(!rstr){ rstr = argv[i]; } else if(!lmstr){ lmstr = argv[i]; } else if(!nmstr){ nmstr = argv[i]; } else if(!bstr){ bstr = argv[i]; } else if(!astr){ astr = argv[i]; } else if(!fstr){ fstr = argv[i]; } else { usage(); } } if(!path || !rstr) usage(); int rnum = tcatoi(rstr); if(rnum < 1) usage(); int lmemb = lmstr ? tcatoi(lmstr) : -1; int nmemb = nmstr ? tcatoi(nmstr) : -1; int bnum = bstr ? tcatoi(bstr) : -1; int apow = astr ? tcatoi(astr) : -1; int fpow = fstr ? tcatoi(fstr) : -1; int rv = procqueue(path, rnum, lmemb, nmemb, bnum, apow, fpow, mt, cmp, opts, lcnum, ncnum, xmsiz, lsmax, capnum, omode); 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 |= BDBTLARGE; } else if(!strcmp(argv[i], "-td")){ opts |= BDBTDEFLATE; } else if(!strcmp(argv[i], "-tb")){ opts |= BDBTBZIP; } else if(!strcmp(argv[i], "-tt")){ opts |= BDBTTCBS; } else if(!strcmp(argv[i], "-tx")){ opts |= BDBTEXCODEC; } else if(!strcmp(argv[i], "-nl")){ omode |= BDBONOLCK; } else if(!strcmp(argv[i], "-nb")){ omode |= BDBOLCKNB; } else { usage(); } } else if(!path){ path = argv[i]; } else if(!rstr){ rstr = argv[i]; } else { usage(); } } if(!path || !rstr) usage(); int rnum = tcatoi(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 |= BDBTLARGE; } else if(!strcmp(argv[i], "-td")){ opts |= BDBTDEFLATE; } else if(!strcmp(argv[i], "-tb")){ opts |= BDBTBZIP; } else if(!strcmp(argv[i], "-tt")){ opts |= BDBTTCBS; } else if(!strcmp(argv[i], "-tx")){ opts |= BDBTEXCODEC; } else if(!strcmp(argv[i], "-nl")){ omode |= BDBONOLCK; } else if(!strcmp(argv[i], "-nb")){ omode |= BDBOLCKNB; } else { usage(); } } else if(!path){ path = argv[i]; } else if(!rstr){ rstr = argv[i]; } else { usage(); } } if(!path || !rstr) usage(); int rnum = tcatoi(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 lmemb, int nmemb, int bnum, int apow, int fpow, bool mt, BDBCMP cmp, int opts, int lcnum, int ncnum, int xmsiz, int lsmax, int capnum, int omode, bool rnd){ iprintf("<Writing Test>\n path=%s rnum=%d lmemb=%d nmemb=%d bnum=%d apow=%d fpow=%d" " mt=%d cmp=%p opts=%d lcnum=%d ncnum=%d xmsiz=%d lsmax=%d capnum=%d omode=%d" " rnd=%d\n\n", path, rnum, lmemb, nmemb, bnum, apow, fpow, mt, (void *)(intptr_t)cmp, opts, lcnum, ncnum, xmsiz, lsmax, capnum, omode, rnd); bool err = false; double stime = tctime(); TCBDB *bdb = tcbdbnew(); if(g_dbgfd >= 0) tcbdbsetdbgfd(bdb, g_dbgfd); if(mt && !tcbdbsetmutex(bdb)){ eprint(bdb, "tcbdbsetmutex"); err = true; } if(cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)){ eprint(bdb, "tcbdbsetcmpfunc"); err = true; } if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){ eprint(bdb, "tcbdbsetcodecfunc"); err = true; } if(!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)){ eprint(bdb, "tcbdbtune"); err = true; } if(!tcbdbsetcache(bdb, lcnum, ncnum)){ eprint(bdb, "tcbdbsetcache"); err = true; } if(xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)){ eprint(bdb, "tcbdbsetxmsiz"); err = true; } if(!tcbdbsetlsmax(bdb, lsmax)){ eprint(bdb, "tcbdbsetlsmax"); err = true; } if(!tcbdbsetcapnum(bdb, capnum)){ eprint(bdb, "tcbdbsetcapnum"); err = true; } if(!rnd) omode |= BDBOTRUNC; if(!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | omode)){ eprint(bdb, "tcbdbopen"); err = true; } for(int i = 1; i <= rnum; i++){ char buf[RECBUFSIZ]; int len; if(cmp == tcbdbcmpdecimal){ len = sprintf(buf, "%d", rnd ? myrand(rnum) + 1 : i); } else if(cmp == tcbdbcmpint32){ int32_t lnum = rnd ? myrand(rnum) + 1 : i; memcpy(buf, &lnum, sizeof(lnum)); len = sizeof(lnum); } else if(cmp == tcbdbcmpint64){ int64_t llnum = rnd ? myrand(rnum) + 1 : i; memcpy(buf, &llnum, sizeof(llnum)); len = sizeof(llnum); } else { len = sprintf(buf, "%08d", rnd ? myrand(rnum) + 1 : i); } if(!tcbdbput(bdb, buf, len, buf, len)){ eprint(bdb, "tcbdbput"); 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)tcbdbrnum(bdb)); iprintf("size: %llu\n", (unsigned long long)tcbdbfsiz(bdb)); mprint(bdb); if(!tcbdbclose(bdb)){ eprint(bdb, "tcbdbclose"); err = true; } tcbdbdel(bdb); 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, BDBCMP cmp, int lcnum, int ncnum, int xmsiz, int omode, bool wb, bool rnd){ iprintf("<Reading Test>\n path=%s mt=%d cmp=%p lcnum=%d ncnum=%d xmsiz=%d omode=%d" " wb=%d rnd=%d\n\n", path, mt, (void *)(intptr_t)cmp, lcnum, ncnum, xmsiz, omode, wb, rnd); bool err = false; double stime = tctime(); TCBDB *bdb = tcbdbnew(); if(g_dbgfd >= 0) tcbdbsetdbgfd(bdb, g_dbgfd); if(mt && !tcbdbsetmutex(bdb)){ eprint(bdb, "tcbdbsetmutex"); err = true; } if(cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)){ eprint(bdb, "tcbdbsetcmpfunc"); err = true; } if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){ eprint(bdb, "tcbdbsetcodecfunc"); err = true; } if(!tcbdbsetcache(bdb, lcnum, ncnum)){ eprint(bdb, "tcbdbsetcache"); err = true; } if(xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)){ eprint(bdb, "tcbdbsetxmsiz"); err = true; } if(!tcbdbopen(bdb, path, BDBOREADER | omode)){ eprint(bdb, "tcbdbopen"); err = true; } int rnum = tcbdbrnum(bdb); for(int i = 1; i <= rnum; i++){ char kbuf[RECBUFSIZ]; int ksiz; if(cmp == tcbdbcmpdecimal){ ksiz = sprintf(kbuf, "%d", rnd ? myrand(rnum) + 1 : i); } else if(cmp == tcbdbcmpint32){ int32_t lnum = rnd ? myrand(rnum) + 1 : i; memcpy(kbuf, &lnum, sizeof(lnum)); ksiz = sizeof(lnum); } else if(cmp == tcbdbcmpint64){ int64_t llnum = rnd ? myrand(rnum) + 1 : i; memcpy(kbuf, &llnum, sizeof(llnum)); ksiz = sizeof(llnum); } else { ksiz = sprintf(kbuf, "%08d", rnd ? myrand(rnum) + 1 : i); } int vsiz; if(wb){ int vsiz; const char *vbuf = tcbdbget3(bdb, kbuf, ksiz, &vsiz); if(!vbuf && !(rnd && tcbdbecode(bdb) == TCENOREC)){ eprint(bdb, "tcbdbget3"); err = true; break; } } else { char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz); if(!vbuf && !(rnd && tcbdbecode(bdb) == TCENOREC)){ eprint(bdb, "tcbdbget"); err = true; break; } tcfree(vbuf); } 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)tcbdbrnum(bdb)); iprintf("size: %llu\n", (unsigned long long)tcbdbfsiz(bdb)); mprint(bdb); if(!tcbdbclose(bdb)){ eprint(bdb, "tcbdbclose"); err = true; } tcbdbdel(bdb); 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, BDBCMP cmp, int lcnum, int ncnum, int xmsiz, int omode, bool rnd){ iprintf("<Removing Test>\n path=%s mt=%d cmp=%p lcnum=%d ncnum=%d xmsiz=%d" " omode=%d rnd=%d\n\n", path, mt, (void *)(intptr_t)cmp, lcnum, ncnum, xmsiz, omode, rnd); bool err = false; double stime = tctime(); TCBDB *bdb = tcbdbnew(); if(g_dbgfd >= 0) tcbdbsetdbgfd(bdb, g_dbgfd); if(mt && !tcbdbsetmutex(bdb)){ eprint(bdb, "tcbdbsetmutex"); err = true; } if(cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)){ eprint(bdb, "tcbdbsetcmpfunc"); err = true; } if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){ eprint(bdb, "tcbdbsetcodecfunc"); err = true;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -