From 820fc4933ba9ad6afff0adfbc88f7458689e317d Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 7 May 2016 18:02:53 +0000 Subject: [PATCH] Add options to bc_test1.c to make it more flexible. FossilOrigin-Name: ec6ef5f2c2dc18e1a19c205f365f4071f0870b68 --- manifest | 14 +++--- manifest.uuid | 2 +- test/bc_test1.c | 113 +++++++++++++++++++----------------------- test/tt3_core.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 188 insertions(+), 70 deletions(-) diff --git a/manifest b/manifest index 161feb3e40..9b43e47d70 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stest/bc_test1.c,\sfor\stesting\sthe\sdegree\sof\sconcurrency\sprovided\sby\sthis\sbranch\sunder\svarious\sconditions. -D 2016-05-06T21:04:47.598 +C Add\soptions\sto\sbc_test1.c\sto\smake\sit\smore\sflexible. +D 2016-05-07T18:02:53.432 F Makefile.in 9e816d0323e418fbc0f8b2c05fc14e0b3763d9e8 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 71b8b16cf9393f68e2e2035486ca104872558836 @@ -521,7 +521,7 @@ F test/backup_malloc.test 7162d604ec2b4683c4b3799a48657fb8b5e2d450 F test/badutf.test d5360fc31f643d37a973ab0d8b4fb85799c3169f F test/badutf2.test f5bc7f2d280670ecd79b9cf4f0f1760c607fe51f F test/bc_common.tcl b5e42d80305be95697e6370e015af571e5333a1c -F test/bc_test1.c d67cb1a933ae3a9116c8dc6da31e9ebf1c06ac23 +F test/bc_test1.c 3f10831d71c7e0bc53640c1989d31ded030a0fcc F test/bestindex1.test 0cf1bd2d7b97d3a3a8c10736125274f64765c4ee F test/bestindex2.test 4a06b8922ab2fd09434870da8d1cdf525aaf7060 F test/between.test 34d375fb5ce1ae283ffe82b6b233e9f38e84fc6c @@ -1295,7 +1295,7 @@ F test/triggerC.test 302d8995f5ffe63bbc15053abb3ef7a39cf5a092 F test/triggerD.test 8e7f3921a92a5797d472732108109e44575fa650 F test/triggerE.test 15fa63f1097db1f83dd62d121616006978063d1f F test/tt3_checkpoint.c 9e75cf7c1c364f52e1c47fd0f14c4340a9db0fe1 -F test/tt3_core.c 13c19feb4fe127bc86ae86d2c1237eb71c73f2ab +F test/tt3_core.c 77d7acbe43f78802284da8ef04650f6f5f32f7a0 F test/tt3_index.c 39eec10a35f57672225be4d182862152896dee4a F test/tt3_lookaside1.c 0377e202c3c2a50d688cb65ba203afeda6fafeb9 F test/tt3_stress.c c57d804716165811d979d4a719e05baccd79277f @@ -1491,7 +1491,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 91e5c07eaf884d3598df8eb54f0910a80df48397 -R 4bab1825e8924fd8c0c1d12f2130ddfc +P 128c7eaed5479b615d75ebce1d781ea661e0fb2d +R 86fffa805f6f27d07092161192388b60 U dan -Z 8e9093e5b020040f9bd55508cf282679 +Z aab288310f3155f4f7b4c6e3e47a2d89 diff --git a/manifest.uuid b/manifest.uuid index 86543cee78..c99acbf3cf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -128c7eaed5479b615d75ebce1d781ea661e0fb2d \ No newline at end of file +ec6ef5f2c2dc18e1a19c205f365f4071f0870b68 \ No newline at end of file diff --git a/test/bc_test1.c b/test/bc_test1.c index dd8ab30440..bb41e9d4ed 100644 --- a/test/bc_test1.c +++ b/test/bc_test1.c @@ -1,24 +1,35 @@ +/* +** 2016-05-07 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +*/ #include - #include - +#include #include "tt3_core.c" typedef struct Config Config; - struct Config { int nIPT; /* --inserts-per-transaction */ int nThread; /* --threads */ int nSecond; /* --seconds */ int bMutex; /* --mutex */ - + int nAutoCkpt; /* --autockpt */ int bRm; /* --rm */ sqlite3_mutex *pMutex; }; + static char *thread_main(int iTid, void *pArg){ Config *pConfig = (Config*)pArg; Error err = {0}; /* Error code and message */ @@ -29,7 +40,10 @@ static char *thread_main(int iTid, void *pArg){ opendb(&err, &db, "xyz.db", 0); sqlite3_busy_handler(db.db, 0, 0); - execsql(&err, &db, "PRAGMA wal_autocheckpoint = 0"); + sql_script_printf(&err, &db, + "PRAGMA wal_autocheckpoint = %d;" + "PRAGMA synchronous = 0;", pConfig->nAutoCkpt + ); while( !timetostop(&err) ){ execsql(&err, &db, "BEGIN CONCURRENT"); @@ -55,67 +69,35 @@ static char *thread_main(int iTid, void *pArg){ return sqlite3_mprintf("%d/%d successful commits", nCommit, nAttempt); } -static void usage(char *zName){ - fprintf(stderr, "Usage: %s ?SWITCHES?\n", zName); - fprintf(stderr, "\n"); - fprintf(stderr, "where switches are\n"); - fprintf(stderr, " --seconds N\n"); - fprintf(stderr, " --inserts N\n"); - fprintf(stderr, " --threads N\n"); - fprintf(stderr, " --rm BOOL\n"); - fprintf(stderr, " --mutex BOOL\n"); - fprintf(stderr, "\n"); - exit(-1); -} - -int main(int argc, char **argv){ +int main(int argc, const char **argv){ Error err = {0}; /* Error code and message */ Sqlite db = {0}; /* SQLite database connection */ Threadset threads = {0}; /* Test threads */ - Config sConfig = {5, 3, 5}; + Config conf = {5, 3, 5}; int i; - for(i=1; i=3 && 0==sqlite3_strnicmp(z, "--seconds", n) ){ - if( (++i)==argc ) usage(argv[0]); - sConfig.nSecond = atoi(argv[i]); - } - - else if( n>=3 && 0==sqlite3_strnicmp(z, "--inserts", n) ){ - if( (++i)==argc ) usage(argv[0]); - sConfig.nIPT = atoi(argv[i]); - } - - else if( n>=3 && 0==sqlite3_strnicmp(z, "--threads", n) ){ - if( (++i)==argc ) usage(argv[0]); - sConfig.nThread = atoi(argv[i]); - } - - else if( n>=3 && 0==sqlite3_strnicmp(z, "--rm", n) ){ - if( (++i)==argc ) usage(argv[0]); - sConfig.bRm = atoi(argv[i]); - } - - else if( n>=3 && 0==sqlite3_strnicmp(z, "--mutex", n) ){ - if( (++i)==argc ) usage(argv[0]); - sConfig.bMutex = atoi(argv[i]); - } - - else usage(argv[0]); + CmdlineArg apArg[] = { + { "--seconds", CMDLINE_INT, offsetof(Config, nSecond) }, + { "--inserts", CMDLINE_INT, offsetof(Config, nIPT) }, + { "--threads", CMDLINE_INT, offsetof(Config, nThread) }, + { "--mutex", CMDLINE_BOOL, offsetof(Config, bMutex) }, + { "--rm", CMDLINE_BOOL, offsetof(Config, bRm) }, + { "--autockpt",CMDLINE_INT, offsetof(Config, nAutoCkpt) }, + { 0, 0, 0 } + }; + + cmdline_process(apArg, argc, argv, (void*)&conf); + if( err.rc==SQLITE_OK ){ + char *z = cmdline_construct(apArg, (void*)&conf); + printf("With: %s\n", z); + sqlite3_free(z); } - printf("With: --threads %d --inserts %d --seconds %d --rm %d --mutex %d\n", - sConfig.nThread, sConfig.nIPT, sConfig.nSecond, sConfig.bRm, - sConfig.bMutex - ); - /* Ensure the schema has been created */ - if( sConfig.bMutex ){ - sConfig.pMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_RECURSIVE); + if( conf.bMutex ){ + conf.pMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_RECURSIVE); } - opendb(&err, &db, "xyz.db", sConfig.bRm); + opendb(&err, &db, "xyz.db", conf.bRm); sql_script(&err, &db, "PRAGMA journal_mode = wal;" @@ -123,15 +105,22 @@ int main(int argc, char **argv){ "CREATE INDEX IF NOT EXISTS t1b ON t1(b);" "CREATE INDEX IF NOT EXISTS t1c ON t1(c);" ); - closedb(&err, &db); - setstoptime(&err, sConfig.nSecond*1000); - for(i=0; ieType ){ + case CMDLINE_INT: { + zRet = sqlite3_mprintf("%z%s%s %d", zRet, zSpace, pArg->zSwitch, + *(int*)(p + pArg->iOffset) + ); + break; + }; + + case CMDLINE_BOOL: + if( *(int*)(p + pArg->iOffset) ){ + zRet = sqlite3_mprintf("%z%s%s", zRet, zSpace, pArg->zSwitch); + } + break; + + default: + zRet = sqlite3_mprintf("%z%s%s ???", zRet, zSpace, pArg->zSwitch); + } + } + + return zRet; +} + +static void cmdline_process( + CmdlineArg *apArg, + int argc, + const char **argv, + void *pObj +){ + int i; + int iArg; + unsigned char *p = (unsigned char*)pObj; + + for(i=1; i=0 ){ + cmdline_error("ambiguous switch: %s", z); + } + iOpt = iArg; + switch( apArg[iArg].eType ){ + case CMDLINE_INT: + i++; + if( i==argc ){ + cmdline_error("option requires an argument: %s", z); + } + *(int*)(p + apArg[iArg].iOffset) = atoi(argv[i]); + break; + + case CMDLINE_BOOL: + *(int*)(p + apArg[iArg].iOffset) = 1; + break; + + default: + assert( 0 ); + cmdline_error("internal error"); + return; + } + } + } + + if( iOpt<0 ){ + cmdline_usage(argv[0], apArg); + } + } +} + +/* +** End of command line processing utilities. +*************************************************************************/ + + /* * This code implements the MD5 message-digest algorithm. * The algorithm is due to Ron Rivest. This code was -- 2.47.3