]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add options to bc_test1.c to make it more flexible.
authordan <dan@noemail.net>
Sat, 7 May 2016 18:02:53 +0000 (18:02 +0000)
committerdan <dan@noemail.net>
Sat, 7 May 2016 18:02:53 +0000 (18:02 +0000)
FossilOrigin-Name: ec6ef5f2c2dc18e1a19c205f365f4071f0870b68

manifest
manifest.uuid
test/bc_test1.c
test/tt3_core.c

index 161feb3e403699caac7046457d57cb8dd3220ee0..9b43e47d700fc4968a4f1cf45105fc43ef310cbb 100644 (file)
--- 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
index 86543cee780d116f5c63dd7091eed9e05a047843..c99acbf3cfb1e0db4ea659dd39737f85ac5c4877 100644 (file)
@@ -1 +1 @@
-128c7eaed5479b615d75ebce1d781ea661e0fb2d
\ No newline at end of file
+ec6ef5f2c2dc18e1a19c205f365f4071f0870b68
\ No newline at end of file
index dd8ab3044081eab5a59764ba00d03784ce87a705..bb41e9d4ed1775e98f1990c4d00e6935a6af722b 100644 (file)
@@ -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 <sqlite3.h>
-
 #include <stdlib.h>
-
+#include <stddef.h>
 #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<argc; i++){
-    char *z = argv[i];
-    int n = strlen(z);
-    if( n>=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; i<sConfig.nThread; i++){
-    launch_thread(&err, &threads, thread_main, (void*)&sConfig);
+  setstoptime(&err, conf.nSecond*1000);
+  for(i=0; i<conf.nThread; i++){
+    launch_thread(&err, &threads, thread_main, (void*)&conf);
   }
   join_all_threads(&err, &threads);
 
-  sqlite3_mutex_free(sConfig.pMutex);
+  if( err.rc==SQLITE_OK ){
+    printf("Database is %dK\n", (int)(filesize(&err, "xyz.db") / 1024));
+  }
+  if( err.rc==SQLITE_OK ){
+    printf("Wal file is %dK\n", (int)(filesize(&err, "xyz.db-wal") / 1024));
+  }
+
+  closedb(&err, &db);
+  sqlite3_mutex_free(conf.pMutex);
   print_and_free_err(&err);
   return 0;
 }
index 21de432e98a931aaa33d9a43e2625bb2d61be319..65c04f0204ab4e704f030e5f620a8113fd7dc6e2 100644 (file)
 ** End of test code/infrastructure interface macros.
 *************************************************************************/
 
+
+/************************************************************************
+** Start of command line processing utilities.
+*/
+#define CMDLINE_INT   1
+#define CMDLINE_BOOL  2
+
+typedef struct CmdlineArg CmdlineArg;
+struct CmdlineArg {
+  const char *zSwitch;
+  int eType;
+  int iOffset;
+};
+
+static void cmdline_error(const char *zFmt, ...){
+  va_list ap;                   /* ... arguments */
+  char *zMsg = 0;
+  va_start(ap, zFmt);
+  zMsg = sqlite3_vmprintf(zFmt, ap);
+  fprintf(stderr, "%s\n", zMsg);
+  sqlite3_free(zMsg);
+  va_end(ap);
+  exit(-1);
+}
+
+static void cmdline_usage(const char *zPrg, CmdlineArg *apArg){
+  int i;
+  fprintf(stderr, "Usage: %s SWITCHES\n", zPrg);
+  fprintf(stderr, "\n");
+  fprintf(stderr, "where switches are\n");
+  for(i=0; apArg[i].zSwitch; i++){
+    const char *zExtra = "";
+    switch( apArg[i].eType ){
+      case CMDLINE_INT: zExtra = "N"; break;
+      case CMDLINE_BOOL: zExtra = ""; break;
+      default:
+        zExtra = "???";
+        break;
+    }
+    fprintf(stderr, "  %s %s\n", apArg[i].zSwitch, zExtra);
+  }
+  fprintf(stderr, "\n");
+  exit(-2);
+}
+
+static char *cmdline_construct(CmdlineArg *apArg, void *pObj){
+  unsigned char *p = (unsigned char*)pObj;
+  char *zRet = 0;
+  int iArg;
+
+  for(iArg=0; apArg[iArg].zSwitch; iArg++){
+    const char *zSpace = (zRet ? " " : "");
+    CmdlineArg *pArg = &apArg[iArg];
+
+    switch( pArg->eType ){
+      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<argc; i++){
+    const char *z = argv[i];
+    int n = strlen(z);
+    int iOpt = -1;
+
+    for(iArg=0; apArg[iArg].zSwitch; iArg++){
+      if( 0==sqlite3_strnicmp(apArg[iArg].zSwitch, z, n) ){
+        if( iOpt>=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