| OLD | NEW |
| 1 | |
| 2 /* | 1 /* |
| 2 ** 2010-07-22 |
| 3 ** |
| 4 ** The author disclaims copyright to this source code. In place of |
| 5 ** a legal notice, here is a blessing: |
| 6 ** |
| 7 ** May you do good and not evil. |
| 8 ** May you find forgiveness for yourself and forgive others. |
| 9 ** May you share freely, never taking more than you give. |
| 10 ** |
| 11 ************************************************************************* |
| 12 ** |
| 3 ** The code in this file runs a few multi-threaded test cases using the | 13 ** The code in this file runs a few multi-threaded test cases using the |
| 4 ** SQLite library. It can be compiled to an executable on unix using the | 14 ** SQLite library. It can be compiled to an executable on unix using the |
| 5 ** following command: | 15 ** following command: |
| 6 ** | 16 ** |
| 7 ** gcc -O2 threadtest3.c sqlite3.c -ldl -lpthread -lm | 17 ** gcc -O2 threadtest3.c sqlite3.c -ldl -lpthread -lm |
| 8 ** | 18 ** |
| 9 ** Then run the compiled program. The exit status is non-zero if any tests | 19 ** Even though threadtest3.c is the only C source code file mentioned on |
| 10 ** failed (hopefully there is also some output to stdout to clarify what went | 20 ** the compiler command-line, #include macros are used to pull in additional |
| 11 ** wrong). | 21 ** C code files named "tt3_*.c". |
| 12 ** | 22 ** |
| 13 ** There are three parts to the code in this file, in the following order: | 23 ** After compiling, run this program with an optional argument telling |
| 24 ** which test to run. All tests are run if no argument is given. The |
| 25 ** argument can be a glob pattern to match multiple tests. Examples: |
| 14 ** | 26 ** |
| 15 ** 1. Code for the SQL aggregate function md5sum() copied from | 27 ** ./a.out -- Run all tests |
| 16 ** tclsqlite.c in the SQLite distribution. The names of all the | 28 ** ./a.out walthread3 -- Run the "walthread3" test |
| 17 ** types and functions in this section begin with "MD5" or "md5". | 29 ** ./a.out 'wal*' -- Run all of the wal* tests |
| 30 ** ./a.out --help -- List all available tests |
| 18 ** | 31 ** |
| 19 ** 2. A set of utility functions that may be used to implement | 32 ** The exit status is non-zero if any test fails. |
| 20 ** multi-threaded test cases. These are all called by test code | |
| 21 ** via macros that help with error reporting. The macros are defined | |
| 22 ** immediately below this comment. | |
| 23 ** | |
| 24 ** 3. The test code itself. And a main() routine to drive the test | |
| 25 ** code. | |
| 26 */ | 33 */ |
| 27 | 34 |
| 28 /************************************************************************* | 35 /* |
| 29 ** Start of test code/infrastructure interface macros. | 36 ** The "Set Error Line" macro. |
| 30 ** | |
| 31 ** The following macros constitute the interface between the test | |
| 32 ** programs and the test infrastructure. Test infrastructure code | |
| 33 ** does not itself use any of these macros. Test code should not | |
| 34 ** call any of the macroname_x() functions directly. | |
| 35 ** | |
| 36 ** See the header comments above the corresponding macroname_x() | |
| 37 ** function for a description of each interface. | |
| 38 */ | 37 */ |
| 38 #define SEL(e) ((e)->iLine = ((e)->rc ? (e)->iLine : __LINE__)) |
| 39 | 39 |
| 40 /* Database functions */ | 40 /* Database functions */ |
| 41 #define opendb(w,x,y,z) (SEL(w), opendb_x(w,x,y,z)) | 41 #define opendb(w,x,y,z) (SEL(w), opendb_x(w,x,y,z)) |
| 42 #define closedb(y,z) (SEL(y), closedb_x(y,z)) | 42 #define closedb(y,z) (SEL(y), closedb_x(y,z)) |
| 43 | 43 |
| 44 /* Functions to execute SQL */ | 44 /* Functions to execute SQL */ |
| 45 #define sql_script(x,y,z) (SEL(x), sql_script_x(x,y,z)) | 45 #define sql_script(x,y,z) (SEL(x), sql_script_x(x,y,z)) |
| 46 #define integrity_check(x,y) (SEL(x), integrity_check_x(x,y)) | 46 #define integrity_check(x,y) (SEL(x), integrity_check_x(x,y)) |
| 47 #define execsql_i64(x,y,...) (SEL(x), execsql_i64_x(x,y,__VA_ARGS__)) | 47 #define execsql_i64(x,y,...) (SEL(x), execsql_i64_x(x,y,__VA_ARGS__)) |
| 48 #define execsql_text(x,y,z,...) (SEL(x), execsql_text_x(x,y,z,__VA_ARGS__)) | 48 #define execsql_text(x,y,z,...) (SEL(x), execsql_text_x(x,y,z,__VA_ARGS__)) |
| 49 #define execsql(x,y,...) (SEL(x), (void)execsql_i64_x(x,y,__VA_ARGS__)) | 49 #define execsql(x,y,...) (SEL(x), (void)execsql_i64_x(x,y,__VA_ARGS__)) |
| 50 #define sql_script_printf(x,y,z,...) ( \ |
| 51 SEL(x), sql_script_printf_x(x,y,z,__VA_ARGS__) \ |
| 52 ) |
| 50 | 53 |
| 51 /* Thread functions */ | 54 /* Thread functions */ |
| 52 #define launch_thread(w,x,y,z) (SEL(w), launch_thread_x(w,x,y,z)) | 55 #define launch_thread(w,x,y,z) (SEL(w), launch_thread_x(w,x,y,z)) |
| 53 #define join_all_threads(y,z) (SEL(y), join_all_threads_x(y,z)) | 56 #define join_all_threads(y,z) (SEL(y), join_all_threads_x(y,z)) |
| 54 | 57 |
| 55 /* Timer functions */ | 58 /* Timer functions */ |
| 56 #define setstoptime(y,z) (SEL(y), setstoptime_x(y,z)) | 59 #define setstoptime(y,z) (SEL(y), setstoptime_x(y,z)) |
| 57 #define timetostop(z) (SEL(z), timetostop_x(z)) | 60 #define timetostop(z) (SEL(z), timetostop_x(z)) |
| 58 | 61 |
| 59 /* Report/clear errors. */ | 62 /* Report/clear errors. */ |
| 60 #define test_error(z, ...) test_error_x(z, sqlite3_mprintf(__VA_ARGS__)) | 63 #define test_error(z, ...) test_error_x(z, sqlite3_mprintf(__VA_ARGS__)) |
| 61 #define clear_error(y,z) clear_error_x(y, z) | 64 #define clear_error(y,z) clear_error_x(y, z) |
| 62 | 65 |
| 63 /* File-system operations */ | 66 /* File-system operations */ |
| 64 #define filesize(y,z) (SEL(y), filesize_x(y,z)) | 67 #define filesize(y,z) (SEL(y), filesize_x(y,z)) |
| 65 #define filecopy(x,y,z) (SEL(x), filecopy_x(x,y,z)) | 68 #define filecopy(x,y,z) (SEL(x), filecopy_x(x,y,z)) |
| 66 | 69 |
| 70 #define PTR2INT(x) ((int)((intptr_t)x)) |
| 71 #define INT2PTR(x) ((void*)((intptr_t)x)) |
| 72 |
| 67 /* | 73 /* |
| 68 ** End of test code/infrastructure interface macros. | 74 ** End of test code/infrastructure interface macros. |
| 69 *************************************************************************/ | 75 *************************************************************************/ |
| 70 | 76 |
| 71 | 77 |
| 72 | 78 |
| 73 | 79 |
| 74 #include <sqlite3.h> | 80 #include <sqlite3.h> |
| 75 #include <unistd.h> | 81 #include <unistd.h> |
| 76 #include <stdio.h> | 82 #include <stdio.h> |
| 77 #include <pthread.h> | 83 #include <pthread.h> |
| 78 #include <assert.h> | 84 #include <assert.h> |
| 79 #include <sys/types.h> | 85 #include <sys/types.h> |
| 80 #include <sys/stat.h> | 86 #include <sys/stat.h> |
| 81 #include <string.h> | 87 #include <string.h> |
| 82 #include <fcntl.h> | 88 #include <fcntl.h> |
| 83 #include <errno.h> | 89 #include <errno.h> |
| 84 | 90 |
| 91 #include "test_multiplex.h" |
| 92 |
| 93 /* Required to link test_multiplex.c */ |
| 94 #ifndef SQLITE_OMIT_WSD |
| 95 int sqlite3PendingByte = 0x40000000; |
| 96 #endif |
| 97 |
| 85 /* | 98 /* |
| 86 * This code implements the MD5 message-digest algorithm. | 99 * This code implements the MD5 message-digest algorithm. |
| 87 * The algorithm is due to Ron Rivest. This code was | 100 * The algorithm is due to Ron Rivest. This code was |
| 88 * written by Colin Plumb in 1993, no copyright is claimed. | 101 * written by Colin Plumb in 1993, no copyright is claimed. |
| 89 * This code is in the public domain; do with it what you wish. | 102 * This code is in the public domain; do with it what you wish. |
| 90 * | 103 * |
| 91 * Equivalent code is available from RSA Data Security, Inc. | 104 * Equivalent code is available from RSA Data Security, Inc. |
| 92 * This code has been tested against that, and is equivalent, | 105 * This code has been tested against that, and is equivalent, |
| 93 * except that you don't need to include two pages of legalese | 106 * except that you don't need to include two pages of legalese |
| 94 * with every copy. | 107 * with every copy. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 108 * | 121 * |
| 109 */ | 122 */ |
| 110 #ifndef uint32 | 123 #ifndef uint32 |
| 111 # define uint32 unsigned int | 124 # define uint32 unsigned int |
| 112 #endif | 125 #endif |
| 113 | 126 |
| 114 struct MD5Context { | 127 struct MD5Context { |
| 115 int isInit; | 128 int isInit; |
| 116 uint32 buf[4]; | 129 uint32 buf[4]; |
| 117 uint32 bits[2]; | 130 uint32 bits[2]; |
| 118 unsigned char in[64]; | 131 union { |
| 132 unsigned char in[64]; |
| 133 uint32 in32[16]; |
| 134 } u; |
| 119 }; | 135 }; |
| 120 typedef struct MD5Context MD5Context; | 136 typedef struct MD5Context MD5Context; |
| 121 | 137 |
| 122 /* | 138 /* |
| 123 * Note: this code is harmless on little-endian machines. | 139 * Note: this code is harmless on little-endian machines. |
| 124 */ | 140 */ |
| 125 static void byteReverse (unsigned char *buf, unsigned longs){ | 141 static void byteReverse (unsigned char *buf, unsigned longs){ |
| 126 uint32 t; | 142 uint32 t; |
| 127 do { | 143 do { |
| 128 t = (uint32)((unsigned)buf[3]<<8 | buf[2]) << 16 | | 144 t = (uint32)((unsigned)buf[3]<<8 | buf[2]) << 16 | |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 t = ctx->bits[0]; | 273 t = ctx->bits[0]; |
| 258 if ((ctx->bits[0] = t + ((uint32)len << 3)) < t) | 274 if ((ctx->bits[0] = t + ((uint32)len << 3)) < t) |
| 259 ctx->bits[1]++; /* Carry from low to high */ | 275 ctx->bits[1]++; /* Carry from low to high */ |
| 260 ctx->bits[1] += len >> 29; | 276 ctx->bits[1] += len >> 29; |
| 261 | 277 |
| 262 t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ | 278 t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ |
| 263 | 279 |
| 264 /* Handle any leading odd-sized chunks */ | 280 /* Handle any leading odd-sized chunks */ |
| 265 | 281 |
| 266 if ( t ) { | 282 if ( t ) { |
| 267 unsigned char *p = (unsigned char *)ctx->in + t; | 283 unsigned char *p = (unsigned char *)ctx->u.in + t; |
| 268 | 284 |
| 269 t = 64-t; | 285 t = 64-t; |
| 270 if (len < t) { | 286 if (len < t) { |
| 271 memcpy(p, buf, len); | 287 memcpy(p, buf, len); |
| 272 return; | 288 return; |
| 273 } | 289 } |
| 274 memcpy(p, buf, t); | 290 memcpy(p, buf, t); |
| 275 byteReverse(ctx->in, 16); | 291 byteReverse(ctx->u.in, 16); |
| 276 MD5Transform(ctx->buf, (uint32 *)ctx->in); | 292 MD5Transform(ctx->buf, (uint32 *)ctx->u.in); |
| 277 buf += t; | 293 buf += t; |
| 278 len -= t; | 294 len -= t; |
| 279 } | 295 } |
| 280 | 296 |
| 281 /* Process data in 64-byte chunks */ | 297 /* Process data in 64-byte chunks */ |
| 282 | 298 |
| 283 while (len >= 64) { | 299 while (len >= 64) { |
| 284 memcpy(ctx->in, buf, 64); | 300 memcpy(ctx->u.in, buf, 64); |
| 285 byteReverse(ctx->in, 16); | 301 byteReverse(ctx->u.in, 16); |
| 286 MD5Transform(ctx->buf, (uint32 *)ctx->in); | 302 MD5Transform(ctx->buf, (uint32 *)ctx->u.in); |
| 287 buf += 64; | 303 buf += 64; |
| 288 len -= 64; | 304 len -= 64; |
| 289 } | 305 } |
| 290 | 306 |
| 291 /* Handle any remaining bytes of data. */ | 307 /* Handle any remaining bytes of data. */ |
| 292 | 308 |
| 293 memcpy(ctx->in, buf, len); | 309 memcpy(ctx->u.in, buf, len); |
| 294 } | 310 } |
| 295 | 311 |
| 296 /* | 312 /* |
| 297 * Final wrapup - pad to 64-byte boundary with the bit pattern | 313 * Final wrapup - pad to 64-byte boundary with the bit pattern |
| 298 * 1 0* (64-bit count of bits processed, MSB-first) | 314 * 1 0* (64-bit count of bits processed, MSB-first) |
| 299 */ | 315 */ |
| 300 static void MD5Final(unsigned char digest[16], MD5Context *ctx){ | 316 static void MD5Final(unsigned char digest[16], MD5Context *ctx){ |
| 301 unsigned count; | 317 unsigned count; |
| 302 unsigned char *p; | 318 unsigned char *p; |
| 303 | 319 |
| 304 /* Compute number of bytes mod 64 */ | 320 /* Compute number of bytes mod 64 */ |
| 305 count = (ctx->bits[0] >> 3) & 0x3F; | 321 count = (ctx->bits[0] >> 3) & 0x3F; |
| 306 | 322 |
| 307 /* Set the first char of padding to 0x80. This is safe since there is | 323 /* Set the first char of padding to 0x80. This is safe since there is |
| 308 always at least one byte free */ | 324 always at least one byte free */ |
| 309 p = ctx->in + count; | 325 p = ctx->u.in + count; |
| 310 *p++ = 0x80; | 326 *p++ = 0x80; |
| 311 | 327 |
| 312 /* Bytes of padding needed to make 64 bytes */ | 328 /* Bytes of padding needed to make 64 bytes */ |
| 313 count = 64 - 1 - count; | 329 count = 64 - 1 - count; |
| 314 | 330 |
| 315 /* Pad out to 56 mod 64 */ | 331 /* Pad out to 56 mod 64 */ |
| 316 if (count < 8) { | 332 if (count < 8) { |
| 317 /* Two lots of padding: Pad the first block to 64 bytes */ | 333 /* Two lots of padding: Pad the first block to 64 bytes */ |
| 318 memset(p, 0, count); | 334 memset(p, 0, count); |
| 319 byteReverse(ctx->in, 16); | 335 byteReverse(ctx->u.in, 16); |
| 320 MD5Transform(ctx->buf, (uint32 *)ctx->in); | 336 MD5Transform(ctx->buf, (uint32 *)ctx->u.in); |
| 321 | 337 |
| 322 /* Now fill the next block with 56 bytes */ | 338 /* Now fill the next block with 56 bytes */ |
| 323 memset(ctx->in, 0, 56); | 339 memset(ctx->u.in, 0, 56); |
| 324 } else { | 340 } else { |
| 325 /* Pad block to 56 bytes */ | 341 /* Pad block to 56 bytes */ |
| 326 memset(p, 0, count-8); | 342 memset(p, 0, count-8); |
| 327 } | 343 } |
| 328 byteReverse(ctx->in, 14); | 344 byteReverse(ctx->u.in, 14); |
| 329 | 345 |
| 330 /* Append length in bits and transform */ | 346 /* Append length in bits and transform */ |
| 331 ((uint32 *)ctx->in)[ 14 ] = ctx->bits[0]; | 347 ctx->u.in32[14] = ctx->bits[0]; |
| 332 ((uint32 *)ctx->in)[ 15 ] = ctx->bits[1]; | 348 ctx->u.in32[15] = ctx->bits[1]; |
| 333 | 349 |
| 334 MD5Transform(ctx->buf, (uint32 *)ctx->in); | 350 MD5Transform(ctx->buf, (uint32 *)ctx->u.in); |
| 335 byteReverse((unsigned char *)ctx->buf, 4); | 351 byteReverse((unsigned char *)ctx->buf, 4); |
| 336 memcpy(digest, ctx->buf, 16); | 352 memcpy(digest, ctx->buf, 16); |
| 337 memset(ctx, 0, sizeof(ctx)); /* In case it is sensitive */ | 353 memset(ctx, 0, sizeof(*ctx)); /* In case it is sensitive */ |
| 338 } | 354 } |
| 339 | 355 |
| 340 /* | 356 /* |
| 341 ** Convert a 128-bit MD5 digest into a 32-digit base-16 number. | 357 ** Convert a 128-bit MD5 digest into a 32-digit base-16 number. |
| 342 */ | 358 */ |
| 343 static void MD5DigestToBase16(unsigned char *digest, char *zBuf){ | 359 static void MD5DigestToBase16(unsigned char *digest, char *zBuf){ |
| 344 static char const zEncode[] = "0123456789abcdef"; | 360 static char const zEncode[] = "0123456789abcdef"; |
| 345 int i, j; | 361 int i, j; |
| 346 | 362 |
| 347 for(j=i=0; i<16; i++){ | 363 for(j=i=0; i<16; i++){ |
| (...skipping 27 matching lines...) Expand all Loading... |
| 375 static void md5finalize(sqlite3_context *context){ | 391 static void md5finalize(sqlite3_context *context){ |
| 376 MD5Context *p; | 392 MD5Context *p; |
| 377 unsigned char digest[16]; | 393 unsigned char digest[16]; |
| 378 char zBuf[33]; | 394 char zBuf[33]; |
| 379 p = sqlite3_aggregate_context(context, sizeof(*p)); | 395 p = sqlite3_aggregate_context(context, sizeof(*p)); |
| 380 MD5Final(digest,p); | 396 MD5Final(digest,p); |
| 381 MD5DigestToBase16(digest, zBuf); | 397 MD5DigestToBase16(digest, zBuf); |
| 382 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); | 398 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); |
| 383 } | 399 } |
| 384 | 400 |
| 385 /************************************************************************* | 401 /* |
| 386 ** End of copied md5sum() code. | 402 ** End of copied md5sum() code. |
| 387 */ | 403 **************************************************************************/ |
| 388 | 404 |
| 389 typedef sqlite3_int64 i64; | 405 typedef sqlite3_int64 i64; |
| 390 | 406 |
| 391 typedef struct Error Error; | 407 typedef struct Error Error; |
| 392 typedef struct Sqlite Sqlite; | 408 typedef struct Sqlite Sqlite; |
| 393 typedef struct Statement Statement; | 409 typedef struct Statement Statement; |
| 394 | 410 |
| 395 typedef struct Threadset Threadset; | 411 typedef struct Threadset Threadset; |
| 396 typedef struct Thread Thread; | 412 typedef struct Thread Thread; |
| 397 | 413 |
| 398 /* Total number of errors in this process so far. */ | 414 /* Total number of errors in this process so far. */ |
| 399 static int nGlobalErr = 0; | 415 static int nGlobalErr = 0; |
| 400 | 416 |
| 401 /* Set to true to run in "process" instead of "thread" mode. */ | |
| 402 static int bProcessMode = 0; | |
| 403 | |
| 404 struct Error { | 417 struct Error { |
| 405 int rc; | 418 int rc; |
| 406 int iLine; | 419 int iLine; |
| 407 char *zErr; | 420 char *zErr; |
| 408 }; | 421 }; |
| 409 | 422 |
| 410 struct Sqlite { | 423 struct Sqlite { |
| 411 sqlite3 *db; /* Database handle */ | 424 sqlite3 *db; /* Database handle */ |
| 412 Statement *pCache; /* Linked list of cached statements */ | 425 Statement *pCache; /* Linked list of cached statements */ |
| 413 int nText; /* Size of array at aText[] */ | 426 int nText; /* Size of array at aText[] */ |
| 414 char **aText; /* Stored text results */ | 427 char **aText; /* Stored text results */ |
| 415 }; | 428 }; |
| 416 | 429 |
| 417 struct Statement { | 430 struct Statement { |
| 418 sqlite3_stmt *pStmt; /* Pre-compiled statement handle */ | 431 sqlite3_stmt *pStmt; /* Pre-compiled statement handle */ |
| 419 Statement *pNext; /* Next statement in linked-list */ | 432 Statement *pNext; /* Next statement in linked-list */ |
| 420 }; | 433 }; |
| 421 | 434 |
| 422 struct Thread { | 435 struct Thread { |
| 423 int iTid; /* Thread number within test */ | 436 int iTid; /* Thread number within test */ |
| 424 int iArg; /* Integer argument passed by caller */ | 437 void* pArg; /* Pointer argument passed by caller */ |
| 425 | 438 |
| 426 pthread_t tid; /* Thread id */ | 439 pthread_t tid; /* Thread id */ |
| 427 char *(*xProc)(int, int); /* Thread main proc */ | 440 char *(*xProc)(int, void*); /* Thread main proc */ |
| 428 Thread *pNext; /* Next in this list of threads */ | 441 Thread *pNext; /* Next in this list of threads */ |
| 429 }; | 442 }; |
| 430 | 443 |
| 431 struct Threadset { | 444 struct Threadset { |
| 432 int iMaxTid; /* Largest iTid value allocated so far */ | 445 int iMaxTid; /* Largest iTid value allocated so far */ |
| 433 Thread *pThread; /* Linked list of threads */ | 446 Thread *pThread; /* Linked list of threads */ |
| 434 }; | 447 }; |
| 435 | 448 |
| 436 static void free_err(Error *p){ | 449 static void free_err(Error *p){ |
| 437 sqlite3_free(p->zErr); | 450 sqlite3_free(p->zErr); |
| 438 p->zErr = 0; | 451 p->zErr = 0; |
| 439 p->rc = 0; | 452 p->rc = 0; |
| 440 } | 453 } |
| 441 | 454 |
| 442 static void print_err(Error *p){ | 455 static void print_err(Error *p){ |
| 443 if( p->rc!=SQLITE_OK ){ | 456 if( p->rc!=SQLITE_OK ){ |
| 444 printf("Error: (%d) \"%s\" at line %d\n", p->rc, p->zErr, p->iLine); | 457 int isWarn = 0; |
| 445 nGlobalErr++; | 458 if( p->rc==SQLITE_SCHEMA ) isWarn = 1; |
| 459 if( sqlite3_strglob("* - no such table: *",p->zErr)==0 ) isWarn = 1; |
| 460 printf("%s: (%d) \"%s\" at line %d\n", isWarn ? "Warning" : "Error", |
| 461 p->rc, p->zErr, p->iLine); |
| 462 if( !isWarn ) nGlobalErr++; |
| 463 fflush(stdout); |
| 446 } | 464 } |
| 447 } | 465 } |
| 448 | 466 |
| 449 static void print_and_free_err(Error *p){ | 467 static void print_and_free_err(Error *p){ |
| 450 print_err(p); | 468 print_err(p); |
| 451 free_err(p); | 469 free_err(p); |
| 452 } | 470 } |
| 453 | 471 |
| 454 static void system_error(Error *pErr, int iSys){ | 472 static void system_error(Error *pErr, int iSys){ |
| 455 pErr->rc = iSys; | 473 pErr->rc = iSys; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 } | 517 } |
| 500 | 518 |
| 501 static void opendb_x( | 519 static void opendb_x( |
| 502 Error *pErr, /* IN/OUT: Error code */ | 520 Error *pErr, /* IN/OUT: Error code */ |
| 503 Sqlite *pDb, /* OUT: Database handle */ | 521 Sqlite *pDb, /* OUT: Database handle */ |
| 504 const char *zFile, /* Database file name */ | 522 const char *zFile, /* Database file name */ |
| 505 int bDelete /* True to delete db file before opening */ | 523 int bDelete /* True to delete db file before opening */ |
| 506 ){ | 524 ){ |
| 507 if( pErr->rc==SQLITE_OK ){ | 525 if( pErr->rc==SQLITE_OK ){ |
| 508 int rc; | 526 int rc; |
| 527 int flags = SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_URI; |
| 509 if( bDelete ) unlink(zFile); | 528 if( bDelete ) unlink(zFile); |
| 510 rc = sqlite3_open(zFile, &pDb->db); | 529 rc = sqlite3_open_v2(zFile, &pDb->db, flags, 0); |
| 511 if( rc ){ | 530 if( rc ){ |
| 512 sqlite_error(pErr, pDb, "open"); | 531 sqlite_error(pErr, pDb, "open"); |
| 513 sqlite3_close(pDb->db); | 532 sqlite3_close(pDb->db); |
| 514 pDb->db = 0; | 533 pDb->db = 0; |
| 515 }else{ | 534 }else{ |
| 516 sqlite3_create_function( | 535 sqlite3_create_function( |
| 517 pDb->db, "md5sum", -1, SQLITE_UTF8, 0, 0, md5step, md5finalize | 536 pDb->db, "md5sum", -1, SQLITE_UTF8, 0, 0, md5step, md5finalize |
| 518 ); | 537 ); |
| 519 sqlite3_busy_handler(pDb->db, busyhandler, 0); | 538 sqlite3_busy_handler(pDb->db, busyhandler, 0); |
| 520 sqlite3_exec(pDb->db, "PRAGMA synchronous=OFF", 0, 0, 0); | 539 sqlite3_exec(pDb->db, "PRAGMA synchronous=OFF", 0, 0, 0); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 549 static void sql_script_x( | 568 static void sql_script_x( |
| 550 Error *pErr, /* IN/OUT: Error code */ | 569 Error *pErr, /* IN/OUT: Error code */ |
| 551 Sqlite *pDb, /* Database handle */ | 570 Sqlite *pDb, /* Database handle */ |
| 552 const char *zSql /* SQL script to execute */ | 571 const char *zSql /* SQL script to execute */ |
| 553 ){ | 572 ){ |
| 554 if( pErr->rc==SQLITE_OK ){ | 573 if( pErr->rc==SQLITE_OK ){ |
| 555 pErr->rc = sqlite3_exec(pDb->db, zSql, 0, 0, &pErr->zErr); | 574 pErr->rc = sqlite3_exec(pDb->db, zSql, 0, 0, &pErr->zErr); |
| 556 } | 575 } |
| 557 } | 576 } |
| 558 | 577 |
| 578 static void sql_script_printf_x( |
| 579 Error *pErr, /* IN/OUT: Error code */ |
| 580 Sqlite *pDb, /* Database handle */ |
| 581 const char *zFormat, /* SQL printf format string */ |
| 582 ... /* Printf args */ |
| 583 ){ |
| 584 va_list ap; /* ... printf arguments */ |
| 585 va_start(ap, zFormat); |
| 586 if( pErr->rc==SQLITE_OK ){ |
| 587 char *zSql = sqlite3_vmprintf(zFormat, ap); |
| 588 pErr->rc = sqlite3_exec(pDb->db, zSql, 0, 0, &pErr->zErr); |
| 589 sqlite3_free(zSql); |
| 590 } |
| 591 va_end(ap); |
| 592 } |
| 593 |
| 559 static Statement *getSqlStatement( | 594 static Statement *getSqlStatement( |
| 560 Error *pErr, /* IN/OUT: Error code */ | 595 Error *pErr, /* IN/OUT: Error code */ |
| 561 Sqlite *pDb, /* Database handle */ | 596 Sqlite *pDb, /* Database handle */ |
| 562 const char *zSql /* SQL statement */ | 597 const char *zSql /* SQL statement */ |
| 563 ){ | 598 ){ |
| 564 Statement *pRet; | 599 Statement *pRet; |
| 565 int rc; | 600 int rc; |
| 566 | 601 |
| 567 for(pRet=pDb->pCache; pRet; pRet=pRet->pNext){ | 602 for(pRet=pDb->pCache; pRet; pRet=pRet->pNext){ |
| 568 if( 0==strcmp(sqlite3_sql(pRet->pStmt), zSql) ){ | 603 if( 0==strcmp(sqlite3_sql(pRet->pStmt), zSql) ){ |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 | 652 |
| 618 static i64 execsql_i64_x( | 653 static i64 execsql_i64_x( |
| 619 Error *pErr, /* IN/OUT: Error code */ | 654 Error *pErr, /* IN/OUT: Error code */ |
| 620 Sqlite *pDb, /* Database handle */ | 655 Sqlite *pDb, /* Database handle */ |
| 621 ... /* SQL and pointers to parameter values */ | 656 ... /* SQL and pointers to parameter values */ |
| 622 ){ | 657 ){ |
| 623 i64 iRet = 0; | 658 i64 iRet = 0; |
| 624 if( pErr->rc==SQLITE_OK ){ | 659 if( pErr->rc==SQLITE_OK ){ |
| 625 sqlite3_stmt *pStmt; /* SQL statement to execute */ | 660 sqlite3_stmt *pStmt; /* SQL statement to execute */ |
| 626 va_list ap; /* ... arguments */ | 661 va_list ap; /* ... arguments */ |
| 627 int i; /* Used to iterate through parameters */ | |
| 628 va_start(ap, pDb); | 662 va_start(ap, pDb); |
| 629 pStmt = getAndBindSqlStatement(pErr, pDb, ap); | 663 pStmt = getAndBindSqlStatement(pErr, pDb, ap); |
| 630 if( pStmt ){ | 664 if( pStmt ){ |
| 631 int rc; | |
| 632 int first = 1; | 665 int first = 1; |
| 633 while( SQLITE_ROW==sqlite3_step(pStmt) ){ | 666 while( SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 634 if( first && sqlite3_column_count(pStmt)>0 ){ | 667 if( first && sqlite3_column_count(pStmt)>0 ){ |
| 635 iRet = sqlite3_column_int64(pStmt, 0); | 668 iRet = sqlite3_column_int64(pStmt, 0); |
| 636 } | 669 } |
| 637 first = 0; | 670 first = 0; |
| 638 } | 671 } |
| 639 if( SQLITE_OK!=sqlite3_reset(pStmt) ){ | 672 if( SQLITE_OK!=sqlite3_reset(pStmt) ){ |
| 640 sqlite_error(pErr, pDb, "reset"); | 673 sqlite_error(pErr, pDb, "reset"); |
| 641 } | 674 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 656 if( iSlot>=pDb->nText ){ | 689 if( iSlot>=pDb->nText ){ |
| 657 int nByte = sizeof(char *)*(iSlot+1); | 690 int nByte = sizeof(char *)*(iSlot+1); |
| 658 pDb->aText = (char **)sqlite3_realloc(pDb->aText, nByte); | 691 pDb->aText = (char **)sqlite3_realloc(pDb->aText, nByte); |
| 659 memset(&pDb->aText[pDb->nText], 0, sizeof(char*)*(iSlot+1-pDb->nText)); | 692 memset(&pDb->aText[pDb->nText], 0, sizeof(char*)*(iSlot+1-pDb->nText)); |
| 660 pDb->nText = iSlot+1; | 693 pDb->nText = iSlot+1; |
| 661 } | 694 } |
| 662 | 695 |
| 663 if( pErr->rc==SQLITE_OK ){ | 696 if( pErr->rc==SQLITE_OK ){ |
| 664 sqlite3_stmt *pStmt; /* SQL statement to execute */ | 697 sqlite3_stmt *pStmt; /* SQL statement to execute */ |
| 665 va_list ap; /* ... arguments */ | 698 va_list ap; /* ... arguments */ |
| 666 int i; /* Used to iterate through parameters */ | |
| 667 va_start(ap, iSlot); | 699 va_start(ap, iSlot); |
| 668 pStmt = getAndBindSqlStatement(pErr, pDb, ap); | 700 pStmt = getAndBindSqlStatement(pErr, pDb, ap); |
| 669 if( pStmt ){ | 701 if( pStmt ){ |
| 670 int rc; | |
| 671 int first = 1; | 702 int first = 1; |
| 672 while( SQLITE_ROW==sqlite3_step(pStmt) ){ | 703 while( SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 673 if( first && sqlite3_column_count(pStmt)>0 ){ | 704 if( first && sqlite3_column_count(pStmt)>0 ){ |
| 674 zRet = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0)); | 705 zRet = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0)); |
| 675 sqlite3_free(pDb->aText[iSlot]); | 706 sqlite3_free(pDb->aText[iSlot]); |
| 676 pDb->aText[iSlot] = zRet; | 707 pDb->aText[iSlot] = zRet; |
| 677 } | 708 } |
| 678 first = 0; | 709 first = 0; |
| 679 } | 710 } |
| 680 if( SQLITE_OK!=sqlite3_reset(pStmt) ){ | 711 if( SQLITE_OK!=sqlite3_reset(pStmt) ){ |
| 681 sqlite_error(pErr, pDb, "reset"); | 712 sqlite_error(pErr, pDb, "reset"); |
| 682 } | 713 } |
| 683 } | 714 } |
| 684 va_end(ap); | 715 va_end(ap); |
| 685 } | 716 } |
| 686 | 717 |
| 687 return zRet; | 718 return zRet; |
| 688 } | 719 } |
| 689 | 720 |
| 690 static void integrity_check_x( | 721 static void integrity_check_x( |
| 691 Error *pErr, /* IN/OUT: Error code */ | 722 Error *pErr, /* IN/OUT: Error code */ |
| 692 Sqlite *pDb /* Database handle */ | 723 Sqlite *pDb /* Database handle */ |
| 693 ){ | 724 ){ |
| 694 if( pErr->rc==SQLITE_OK ){ | 725 if( pErr->rc==SQLITE_OK ){ |
| 695 Statement *pStatement; /* Statement to execute */ | 726 Statement *pStatement; /* Statement to execute */ |
| 696 int rc; /* Return code */ | |
| 697 char *zErr = 0; /* Integrity check error */ | 727 char *zErr = 0; /* Integrity check error */ |
| 698 | 728 |
| 699 pStatement = getSqlStatement(pErr, pDb, "PRAGMA integrity_check"); | 729 pStatement = getSqlStatement(pErr, pDb, "PRAGMA integrity_check"); |
| 700 if( pStatement ){ | 730 if( pStatement ){ |
| 701 sqlite3_stmt *pStmt = pStatement->pStmt; | 731 sqlite3_stmt *pStmt = pStatement->pStmt; |
| 702 while( SQLITE_ROW==sqlite3_step(pStmt) ){ | 732 while( SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 703 const char *z = sqlite3_column_text(pStmt, 0); | 733 const char *z = (const char*)sqlite3_column_text(pStmt, 0); |
| 704 if( strcmp(z, "ok") ){ | 734 if( strcmp(z, "ok") ){ |
| 705 if( zErr==0 ){ | 735 if( zErr==0 ){ |
| 706 zErr = sqlite3_mprintf("%s", z); | 736 zErr = sqlite3_mprintf("%s", z); |
| 707 }else{ | 737 }else{ |
| 708 zErr = sqlite3_mprintf("%z\n%s", zErr, z); | 738 zErr = sqlite3_mprintf("%z\n%s", zErr, z); |
| 709 } | 739 } |
| 710 } | 740 } |
| 711 } | 741 } |
| 712 sqlite3_reset(pStmt); | 742 sqlite3_reset(pStmt); |
| 713 | 743 |
| 714 if( zErr ){ | 744 if( zErr ){ |
| 715 pErr->zErr = zErr; | 745 pErr->zErr = zErr; |
| 716 pErr->rc = 1; | 746 pErr->rc = 1; |
| 717 } | 747 } |
| 718 } | 748 } |
| 719 } | 749 } |
| 720 } | 750 } |
| 721 | 751 |
| 722 static void *launch_thread_main(void *pArg){ | 752 static void *launch_thread_main(void *pArg){ |
| 723 Thread *p = (Thread *)pArg; | 753 Thread *p = (Thread *)pArg; |
| 724 return (void *)p->xProc(p->iTid, p->iArg); | 754 return (void *)p->xProc(p->iTid, p->pArg); |
| 725 } | 755 } |
| 726 | 756 |
| 727 static void launch_thread_x( | 757 static void launch_thread_x( |
| 728 Error *pErr, /* IN/OUT: Error code */ | 758 Error *pErr, /* IN/OUT: Error code */ |
| 729 Threadset *pThreads, /* Thread set */ | 759 Threadset *pThreads, /* Thread set */ |
| 730 char *(*xProc)(int, int), /* Proc to run */ | 760 char *(*xProc)(int, void*), /* Proc to run */ |
| 731 int iArg /* Argument passed to thread proc */ | 761 void *pArg /* Argument passed to thread proc */ |
| 732 ){ | 762 ){ |
| 733 if( pErr->rc==SQLITE_OK ){ | 763 if( pErr->rc==SQLITE_OK ){ |
| 734 int iTid = ++pThreads->iMaxTid; | 764 int iTid = ++pThreads->iMaxTid; |
| 735 Thread *p; | 765 Thread *p; |
| 736 int rc; | 766 int rc; |
| 737 | 767 |
| 738 p = (Thread *)sqlite3_malloc(sizeof(Thread)); | 768 p = (Thread *)sqlite3_malloc(sizeof(Thread)); |
| 739 memset(p, 0, sizeof(Thread)); | 769 memset(p, 0, sizeof(Thread)); |
| 740 p->iTid = iTid; | 770 p->iTid = iTid; |
| 741 p->iArg = iArg; | 771 p->pArg = pArg; |
| 742 p->xProc = xProc; | 772 p->xProc = xProc; |
| 743 | 773 |
| 744 rc = pthread_create(&p->tid, NULL, launch_thread_main, (void *)p); | 774 rc = pthread_create(&p->tid, NULL, launch_thread_main, (void *)p); |
| 745 if( rc!=0 ){ | 775 if( rc!=0 ){ |
| 746 system_error(pErr, rc); | 776 system_error(pErr, rc); |
| 747 sqlite3_free(p); | 777 sqlite3_free(p); |
| 748 }else{ | 778 }else{ |
| 749 p->pNext = pThreads->pThread; | 779 p->pNext = pThreads->pThread; |
| 750 pThreads->pThread = p; | 780 pThreads->pThread = p; |
| 751 } | 781 } |
| 752 } | 782 } |
| 753 } | 783 } |
| 754 | 784 |
| 755 static void join_all_threads_x( | 785 static void join_all_threads_x( |
| 756 Error *pErr, /* IN/OUT: Error code */ | 786 Error *pErr, /* IN/OUT: Error code */ |
| 757 Threadset *pThreads /* Thread set */ | 787 Threadset *pThreads /* Thread set */ |
| 758 ){ | 788 ){ |
| 759 Thread *p; | 789 Thread *p; |
| 760 Thread *pNext; | 790 Thread *pNext; |
| 761 for(p=pThreads->pThread; p; p=pNext){ | 791 for(p=pThreads->pThread; p; p=pNext){ |
| 762 void *ret; | 792 void *ret; |
| 763 pNext = p->pNext; | 793 pNext = p->pNext; |
| 764 int rc; | 794 int rc; |
| 765 rc = pthread_join(p->tid, &ret); | 795 rc = pthread_join(p->tid, &ret); |
| 766 if( rc!=0 ){ | 796 if( rc!=0 ){ |
| 767 if( pErr->rc==SQLITE_OK ) system_error(pErr, rc); | 797 if( pErr->rc==SQLITE_OK ) system_error(pErr, rc); |
| 768 }else{ | 798 }else{ |
| 769 printf("Thread %d says: %s\n", p->iTid, (ret==0 ? "..." : (char *)ret)); | 799 printf("Thread %d says: %s\n", p->iTid, (ret==0 ? "..." : (char *)ret)); |
| 800 fflush(stdout); |
| 770 } | 801 } |
| 771 sqlite3_free(p); | 802 sqlite3_free(p); |
| 772 } | 803 } |
| 773 pThreads->pThread = 0; | 804 pThreads->pThread = 0; |
| 774 } | 805 } |
| 775 | 806 |
| 776 static i64 filesize_x( | 807 static i64 filesize_x( |
| 777 Error *pErr, | 808 Error *pErr, |
| 778 const char *zFile | 809 const char *zFile |
| 779 ){ | 810 ){ |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 close(fd1); | 868 close(fd1); |
| 838 close(fd2); | 869 close(fd2); |
| 839 } | 870 } |
| 840 } | 871 } |
| 841 } | 872 } |
| 842 | 873 |
| 843 /* | 874 /* |
| 844 ** Used by setstoptime() and timetostop(). | 875 ** Used by setstoptime() and timetostop(). |
| 845 */ | 876 */ |
| 846 static double timelimit = 0.0; | 877 static double timelimit = 0.0; |
| 847 static sqlite3_vfs *pTimelimitVfs = 0; | 878 |
| 879 static double currentTime(void){ |
| 880 double t; |
| 881 static sqlite3_vfs *pTimelimitVfs = 0; |
| 882 if( pTimelimitVfs==0 ) pTimelimitVfs = sqlite3_vfs_find(0); |
| 883 if( pTimelimitVfs->iVersion>=1 && pTimelimitVfs->xCurrentTimeInt64!=0 ){ |
| 884 sqlite3_int64 tm; |
| 885 pTimelimitVfs->xCurrentTimeInt64(pTimelimitVfs, &tm); |
| 886 t = tm/86400000.0; |
| 887 }else{ |
| 888 pTimelimitVfs->xCurrentTime(pTimelimitVfs, &t); |
| 889 } |
| 890 return t; |
| 891 } |
| 848 | 892 |
| 849 static void setstoptime_x( | 893 static void setstoptime_x( |
| 850 Error *pErr, /* IN/OUT: Error code */ | 894 Error *pErr, /* IN/OUT: Error code */ |
| 851 int nMs /* Milliseconds until "stop time" */ | 895 int nMs /* Milliseconds until "stop time" */ |
| 852 ){ | 896 ){ |
| 853 if( pErr->rc==SQLITE_OK ){ | 897 if( pErr->rc==SQLITE_OK ){ |
| 854 double t; | 898 double t = currentTime(); |
| 855 int rc; | 899 timelimit = t + ((double)nMs)/(1000.0*60.0*60.0*24.0); |
| 856 pTimelimitVfs = sqlite3_vfs_find(0); | |
| 857 rc = pTimelimitVfs->xCurrentTime(pTimelimitVfs, &t); | |
| 858 if( rc!=SQLITE_OK ){ | |
| 859 pErr->rc = rc; | |
| 860 }else{ | |
| 861 timelimit = t + ((double)nMs)/(1000.0*60.0*60.0*24.0); | |
| 862 } | |
| 863 } | 900 } |
| 864 } | 901 } |
| 865 | 902 |
| 866 static int timetostop_x( | 903 static int timetostop_x( |
| 867 Error *pErr /* IN/OUT: Error code */ | 904 Error *pErr /* IN/OUT: Error code */ |
| 868 ){ | 905 ){ |
| 869 int ret = 1; | 906 int ret = 1; |
| 870 if( pErr->rc==SQLITE_OK ){ | 907 if( pErr->rc==SQLITE_OK ){ |
| 871 double t; | 908 double t = currentTime(); |
| 872 int rc; | 909 ret = (t >= timelimit); |
| 873 rc = pTimelimitVfs->xCurrentTime(pTimelimitVfs, &t); | |
| 874 if( rc!=SQLITE_OK ){ | |
| 875 pErr->rc = rc; | |
| 876 }else{ | |
| 877 ret = (t >= timelimit); | |
| 878 } | |
| 879 } | 910 } |
| 880 return ret; | 911 return ret; |
| 881 } | 912 } |
| 882 | 913 |
| 883 /* | |
| 884 ** The "Set Error Line" macro. | |
| 885 */ | |
| 886 #define SEL(e) ((e)->iLine = ((e)->rc ? (e)->iLine : __LINE__)) | |
| 887 | |
| 888 | 914 |
| 889 /************************************************************************* | 915 /************************************************************************* |
| 890 ************************************************************************** | 916 ************************************************************************** |
| 891 ************************************************************************** | 917 ************************************************************************** |
| 892 ** End infrastructure. Begin tests. | 918 ** End infrastructure. Begin tests. |
| 893 */ | 919 */ |
| 894 | 920 |
| 895 #define WALTHREAD1_NTHREAD 10 | 921 #define WALTHREAD1_NTHREAD 10 |
| 896 #define WALTHREAD3_NTHREAD 6 | 922 #define WALTHREAD3_NTHREAD 6 |
| 897 | 923 |
| 898 static char *walthread1_thread(int iTid, int iArg){ | 924 static char *walthread1_thread(int iTid, void *pArg){ |
| 899 Error err = {0}; /* Error code and message */ | 925 Error err = {0}; /* Error code and message */ |
| 900 Sqlite db = {0}; /* SQLite database connection */ | 926 Sqlite db = {0}; /* SQLite database connection */ |
| 901 int nIter = 0; /* Iterations so far */ | 927 int nIter = 0; /* Iterations so far */ |
| 902 | 928 |
| 903 opendb(&err, &db, "test.db", 0); | 929 opendb(&err, &db, "test.db", 0); |
| 904 while( !timetostop(&err) ){ | 930 while( !timetostop(&err) ){ |
| 905 const char *azSql[] = { | 931 const char *azSql[] = { |
| 906 "SELECT md5sum(x) FROM t1 WHERE rowid != (SELECT max(rowid) FROM t1)", | 932 "SELECT md5sum(x) FROM t1 WHERE rowid != (SELECT max(rowid) FROM t1)", |
| 907 "SELECT x FROM t1 WHERE rowid = (SELECT max(rowid) FROM t1)", | 933 "SELECT x FROM t1 WHERE rowid = (SELECT max(rowid) FROM t1)", |
| 908 }; | 934 }; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 927 "COMMIT;" | 953 "COMMIT;" |
| 928 ); | 954 ); |
| 929 nIter++; | 955 nIter++; |
| 930 } | 956 } |
| 931 closedb(&err, &db); | 957 closedb(&err, &db); |
| 932 | 958 |
| 933 print_and_free_err(&err); | 959 print_and_free_err(&err); |
| 934 return sqlite3_mprintf("%d iterations", nIter); | 960 return sqlite3_mprintf("%d iterations", nIter); |
| 935 } | 961 } |
| 936 | 962 |
| 937 static char *walthread1_ckpt_thread(int iTid, int iArg){ | 963 static char *walthread1_ckpt_thread(int iTid, void *pArg){ |
| 938 Error err = {0}; /* Error code and message */ | 964 Error err = {0}; /* Error code and message */ |
| 939 Sqlite db = {0}; /* SQLite database connection */ | 965 Sqlite db = {0}; /* SQLite database connection */ |
| 940 int nCkpt = 0; /* Checkpoints so far */ | 966 int nCkpt = 0; /* Checkpoints so far */ |
| 941 | 967 |
| 942 opendb(&err, &db, "test.db", 0); | 968 opendb(&err, &db, "test.db", 0); |
| 943 while( !timetostop(&err) ){ | 969 while( !timetostop(&err) ){ |
| 944 usleep(500*1000); | 970 usleep(500*1000); |
| 945 execsql(&err, &db, "PRAGMA wal_checkpoint"); | 971 execsql(&err, &db, "PRAGMA wal_checkpoint"); |
| 946 if( err.rc==SQLITE_OK ) nCkpt++; | 972 if( err.rc==SQLITE_OK ) nCkpt++; |
| 947 clear_error(&err, SQLITE_BUSY); | 973 clear_error(&err, SQLITE_BUSY); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 959 int i; /* Iterator variable */ | 985 int i; /* Iterator variable */ |
| 960 | 986 |
| 961 opendb(&err, &db, "test.db", 1); | 987 opendb(&err, &db, "test.db", 1); |
| 962 sql_script(&err, &db, | 988 sql_script(&err, &db, |
| 963 "PRAGMA journal_mode = WAL;" | 989 "PRAGMA journal_mode = WAL;" |
| 964 "CREATE TABLE t1(x PRIMARY KEY);" | 990 "CREATE TABLE t1(x PRIMARY KEY);" |
| 965 "INSERT INTO t1 VALUES(randomblob(100));" | 991 "INSERT INTO t1 VALUES(randomblob(100));" |
| 966 "INSERT INTO t1 VALUES(randomblob(100));" | 992 "INSERT INTO t1 VALUES(randomblob(100));" |
| 967 "INSERT INTO t1 SELECT md5sum(x) FROM t1;" | 993 "INSERT INTO t1 SELECT md5sum(x) FROM t1;" |
| 968 ); | 994 ); |
| 995 closedb(&err, &db); |
| 969 | 996 |
| 970 setstoptime(&err, nMs); | 997 setstoptime(&err, nMs); |
| 971 for(i=0; i<WALTHREAD1_NTHREAD; i++){ | 998 for(i=0; i<WALTHREAD1_NTHREAD; i++){ |
| 972 launch_thread(&err, &threads, walthread1_thread, 0); | 999 launch_thread(&err, &threads, walthread1_thread, 0); |
| 973 } | 1000 } |
| 974 launch_thread(&err, &threads, walthread1_ckpt_thread, 0); | 1001 launch_thread(&err, &threads, walthread1_ckpt_thread, 0); |
| 975 join_all_threads(&err, &threads); | 1002 join_all_threads(&err, &threads); |
| 976 | 1003 |
| 977 print_and_free_err(&err); | 1004 print_and_free_err(&err); |
| 978 } | 1005 } |
| 979 | 1006 |
| 980 static char *walthread2_thread(int iTid, int iArg){ | 1007 static char *walthread2_thread(int iTid, void *pArg){ |
| 981 Error err = {0}; /* Error code and message */ | 1008 Error err = {0}; /* Error code and message */ |
| 982 Sqlite db = {0}; /* SQLite database connection */ | 1009 Sqlite db = {0}; /* SQLite database connection */ |
| 983 int anTrans[2] = {0, 0}; /* Number of WAL and Rollback transactions */ | 1010 int anTrans[2] = {0, 0}; /* Number of WAL and Rollback transactions */ |
| 1011 int iArg = PTR2INT(pArg); |
| 984 | 1012 |
| 985 const char *zJournal = "PRAGMA journal_mode = WAL"; | 1013 const char *zJournal = "PRAGMA journal_mode = WAL"; |
| 986 if( iArg ){ zJournal = "PRAGMA journal_mode = DELETE"; } | 1014 if( iArg ){ zJournal = "PRAGMA journal_mode = DELETE"; } |
| 987 | 1015 |
| 988 while( !timetostop(&err) ){ | 1016 while( !timetostop(&err) ){ |
| 989 int journal_exists = 0; | 1017 int journal_exists = 0; |
| 990 int wal_exists = 0; | 1018 int wal_exists = 0; |
| 991 | 1019 |
| 992 opendb(&err, &db, "test.db", 0); | 1020 opendb(&err, &db, "test.db", 0); |
| 993 | 1021 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1019 Sqlite db = {0}; | 1047 Sqlite db = {0}; |
| 1020 Threadset threads = {0}; | 1048 Threadset threads = {0}; |
| 1021 | 1049 |
| 1022 opendb(&err, &db, "test.db", 1); | 1050 opendb(&err, &db, "test.db", 1); |
| 1023 sql_script(&err, &db, "CREATE TABLE t1(x INTEGER PRIMARY KEY, y UNIQUE)"); | 1051 sql_script(&err, &db, "CREATE TABLE t1(x INTEGER PRIMARY KEY, y UNIQUE)"); |
| 1024 closedb(&err, &db); | 1052 closedb(&err, &db); |
| 1025 | 1053 |
| 1026 setstoptime(&err, nMs); | 1054 setstoptime(&err, nMs); |
| 1027 launch_thread(&err, &threads, walthread2_thread, 0); | 1055 launch_thread(&err, &threads, walthread2_thread, 0); |
| 1028 launch_thread(&err, &threads, walthread2_thread, 0); | 1056 launch_thread(&err, &threads, walthread2_thread, 0); |
| 1029 launch_thread(&err, &threads, walthread2_thread, 1); | 1057 launch_thread(&err, &threads, walthread2_thread, (void*)1); |
| 1030 launch_thread(&err, &threads, walthread2_thread, 1); | 1058 launch_thread(&err, &threads, walthread2_thread, (void*)1); |
| 1031 join_all_threads(&err, &threads); | 1059 join_all_threads(&err, &threads); |
| 1032 | 1060 |
| 1033 print_and_free_err(&err); | 1061 print_and_free_err(&err); |
| 1034 } | 1062 } |
| 1035 | 1063 |
| 1036 static char *walthread3_thread(int iTid, int iArg){ | 1064 static char *walthread3_thread(int iTid, void *pArg){ |
| 1037 Error err = {0}; /* Error code and message */ | 1065 Error err = {0}; /* Error code and message */ |
| 1038 Sqlite db = {0}; /* SQLite database connection */ | 1066 Sqlite db = {0}; /* SQLite database connection */ |
| 1039 i64 iNextWrite; /* Next value this thread will write */ | 1067 i64 iNextWrite; /* Next value this thread will write */ |
| 1068 int iArg = PTR2INT(pArg); |
| 1040 | 1069 |
| 1041 opendb(&err, &db, "test.db", 0); | 1070 opendb(&err, &db, "test.db", 0); |
| 1042 sql_script(&err, &db, "PRAGMA wal_autocheckpoint = 10"); | 1071 sql_script(&err, &db, "PRAGMA wal_autocheckpoint = 10"); |
| 1043 | 1072 |
| 1044 iNextWrite = iArg+1; | 1073 iNextWrite = iArg+1; |
| 1045 while( 1 ){ | 1074 while( 1 ){ |
| 1046 i64 sum1; | 1075 i64 sum1; |
| 1047 i64 sum2; | 1076 i64 sum2; |
| 1048 int stop = 0; /* True to stop executing (test timed out) */ | 1077 int stop = 0; /* True to stop executing (test timed out) */ |
| 1049 | 1078 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1080 "PRAGMA journal_mode = WAL;" | 1109 "PRAGMA journal_mode = WAL;" |
| 1081 "CREATE TABLE t1(cnt PRIMARY KEY, sum1, sum2);" | 1110 "CREATE TABLE t1(cnt PRIMARY KEY, sum1, sum2);" |
| 1082 "CREATE INDEX i1 ON t1(sum1);" | 1111 "CREATE INDEX i1 ON t1(sum1);" |
| 1083 "CREATE INDEX i2 ON t1(sum2);" | 1112 "CREATE INDEX i2 ON t1(sum2);" |
| 1084 "INSERT INTO t1 VALUES(0, 0, 0);" | 1113 "INSERT INTO t1 VALUES(0, 0, 0);" |
| 1085 ); | 1114 ); |
| 1086 closedb(&err, &db); | 1115 closedb(&err, &db); |
| 1087 | 1116 |
| 1088 setstoptime(&err, nMs); | 1117 setstoptime(&err, nMs); |
| 1089 for(i=0; i<WALTHREAD3_NTHREAD; i++){ | 1118 for(i=0; i<WALTHREAD3_NTHREAD; i++){ |
| 1090 launch_thread(&err, &threads, walthread3_thread, i); | 1119 launch_thread(&err, &threads, walthread3_thread, INT2PTR(i)); |
| 1091 } | 1120 } |
| 1092 join_all_threads(&err, &threads); | 1121 join_all_threads(&err, &threads); |
| 1093 | 1122 |
| 1094 print_and_free_err(&err); | 1123 print_and_free_err(&err); |
| 1095 } | 1124 } |
| 1096 | 1125 |
| 1097 static char *walthread4_reader_thread(int iTid, int iArg){ | 1126 static char *walthread4_reader_thread(int iTid, void *pArg){ |
| 1098 Error err = {0}; /* Error code and message */ | 1127 Error err = {0}; /* Error code and message */ |
| 1099 Sqlite db = {0}; /* SQLite database connection */ | 1128 Sqlite db = {0}; /* SQLite database connection */ |
| 1100 | 1129 |
| 1101 opendb(&err, &db, "test.db", 0); | 1130 opendb(&err, &db, "test.db", 0); |
| 1102 while( !timetostop(&err) ){ | 1131 while( !timetostop(&err) ){ |
| 1103 integrity_check(&err, &db); | 1132 integrity_check(&err, &db); |
| 1104 } | 1133 } |
| 1105 closedb(&err, &db); | 1134 closedb(&err, &db); |
| 1106 | 1135 |
| 1107 print_and_free_err(&err); | 1136 print_and_free_err(&err); |
| 1108 return 0; | 1137 return 0; |
| 1109 } | 1138 } |
| 1110 | 1139 |
| 1111 static char *walthread4_writer_thread(int iTid, int iArg){ | 1140 static char *walthread4_writer_thread(int iTid, void *pArg){ |
| 1112 Error err = {0}; /* Error code and message */ | 1141 Error err = {0}; /* Error code and message */ |
| 1113 Sqlite db = {0}; /* SQLite database connection */ | 1142 Sqlite db = {0}; /* SQLite database connection */ |
| 1114 i64 iRow = 1; | 1143 i64 iRow = 1; |
| 1115 | 1144 |
| 1116 opendb(&err, &db, "test.db", 0); | 1145 opendb(&err, &db, "test.db", 0); |
| 1117 sql_script(&err, &db, "PRAGMA wal_autocheckpoint = 15;"); | 1146 sql_script(&err, &db, "PRAGMA wal_autocheckpoint = 15;"); |
| 1118 while( !timetostop(&err) ){ | 1147 while( !timetostop(&err) ){ |
| 1119 execsql_i64( | 1148 execsql_i64( |
| 1120 &err, &db, "REPLACE INTO t1 VALUES(:iRow, randomblob(300))", &iRow | 1149 &err, &db, "REPLACE INTO t1 VALUES(:iRow, randomblob(300))", &iRow |
| 1121 ); | 1150 ); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1141 closedb(&err, &db); | 1170 closedb(&err, &db); |
| 1142 | 1171 |
| 1143 setstoptime(&err, nMs); | 1172 setstoptime(&err, nMs); |
| 1144 launch_thread(&err, &threads, walthread4_reader_thread, 0); | 1173 launch_thread(&err, &threads, walthread4_reader_thread, 0); |
| 1145 launch_thread(&err, &threads, walthread4_writer_thread, 0); | 1174 launch_thread(&err, &threads, walthread4_writer_thread, 0); |
| 1146 join_all_threads(&err, &threads); | 1175 join_all_threads(&err, &threads); |
| 1147 | 1176 |
| 1148 print_and_free_err(&err); | 1177 print_and_free_err(&err); |
| 1149 } | 1178 } |
| 1150 | 1179 |
| 1151 static char *walthread5_thread(int iTid, int iArg){ | 1180 static char *walthread5_thread(int iTid, void *pArg){ |
| 1152 Error err = {0}; /* Error code and message */ | 1181 Error err = {0}; /* Error code and message */ |
| 1153 Sqlite db = {0}; /* SQLite database connection */ | 1182 Sqlite db = {0}; /* SQLite database connection */ |
| 1154 i64 nRow; | 1183 i64 nRow; |
| 1155 | 1184 |
| 1156 opendb(&err, &db, "test.db", 0); | 1185 opendb(&err, &db, "test.db", 0); |
| 1157 nRow = execsql_i64(&err, &db, "SELECT count(*) FROM t1"); | 1186 nRow = execsql_i64(&err, &db, "SELECT count(*) FROM t1"); |
| 1158 closedb(&err, &db); | 1187 closedb(&err, &db); |
| 1159 | 1188 |
| 1160 if( nRow!=65536 ) test_error(&err, "Bad row count: %d", (int)nRow); | 1189 if( nRow!=65536 ) test_error(&err, "Bad row count: %d", (int)nRow); |
| 1161 print_and_free_err(&err); | 1190 print_and_free_err(&err); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1273 } | 1302 } |
| 1274 | 1303 |
| 1275 /*------------------------------------------------------------------------ | 1304 /*------------------------------------------------------------------------ |
| 1276 ** Test case "dynamic_triggers" | 1305 ** Test case "dynamic_triggers" |
| 1277 ** | 1306 ** |
| 1278 ** Two threads executing statements that cause deeply nested triggers | 1307 ** Two threads executing statements that cause deeply nested triggers |
| 1279 ** to fire. And one thread busily creating and deleting triggers. This | 1308 ** to fire. And one thread busily creating and deleting triggers. This |
| 1280 ** is an attempt to find a bug reported to us. | 1309 ** is an attempt to find a bug reported to us. |
| 1281 */ | 1310 */ |
| 1282 | 1311 |
| 1283 static char *dynamic_triggers_1(int iTid, int iArg){ | 1312 static char *dynamic_triggers_1(int iTid, void *pArg){ |
| 1284 Error err = {0}; /* Error code and message */ | 1313 Error err = {0}; /* Error code and message */ |
| 1285 Sqlite db = {0}; /* SQLite database connection */ | 1314 Sqlite db = {0}; /* SQLite database connection */ |
| 1286 int nDrop = 0; | 1315 int nDrop = 0; |
| 1287 int nCreate = 0; | 1316 int nCreate = 0; |
| 1288 | 1317 |
| 1289 opendb(&err, &db, "test.db", 0); | 1318 opendb(&err, &db, "test.db", 0); |
| 1290 while( !timetostop(&err) ){ | 1319 while( !timetostop(&err) ){ |
| 1291 int i; | 1320 int i; |
| 1292 | 1321 |
| 1293 for(i=1; i<9; i++){ | 1322 for(i=1; i<9; i++){ |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1319 nDrop++; | 1348 nDrop++; |
| 1320 } | 1349 } |
| 1321 | 1350 |
| 1322 for(i=1; i<9; i++){ | 1351 for(i=1; i<9; i++){ |
| 1323 char *zSql = sqlite3_mprintf("DROP TRIGGER dtr%d", i); | 1352 char *zSql = sqlite3_mprintf("DROP TRIGGER dtr%d", i); |
| 1324 execsql(&err, &db, zSql); | 1353 execsql(&err, &db, zSql); |
| 1325 sqlite3_free(zSql); | 1354 sqlite3_free(zSql); |
| 1326 nDrop++; | 1355 nDrop++; |
| 1327 } | 1356 } |
| 1328 } | 1357 } |
| 1358 closedb(&err, &db); |
| 1329 | 1359 |
| 1330 print_and_free_err(&err); | 1360 print_and_free_err(&err); |
| 1331 return sqlite3_mprintf("%d created, %d dropped", nCreate, nDrop); | 1361 return sqlite3_mprintf("%d created, %d dropped", nCreate, nDrop); |
| 1332 } | 1362 } |
| 1333 | 1363 |
| 1334 static char *dynamic_triggers_2(int iTid, int iArg){ | 1364 static char *dynamic_triggers_2(int iTid, void *pArg){ |
| 1335 Error err = {0}; /* Error code and message */ | 1365 Error err = {0}; /* Error code and message */ |
| 1336 Sqlite db = {0}; /* SQLite database connection */ | 1366 Sqlite db = {0}; /* SQLite database connection */ |
| 1337 i64 iVal = 0; | 1367 i64 iVal = 0; |
| 1338 int nInsert = 0; | 1368 int nInsert = 0; |
| 1339 int nDelete = 0; | 1369 int nDelete = 0; |
| 1340 | 1370 |
| 1341 opendb(&err, &db, "test.db", 0); | 1371 opendb(&err, &db, "test.db", 0); |
| 1342 while( !timetostop(&err) ){ | 1372 while( !timetostop(&err) ){ |
| 1343 do { | 1373 do { |
| 1344 iVal = (iVal+1)%100; | 1374 iVal = (iVal+1)%100; |
| 1345 execsql(&err, &db, "INSERT INTO t1 VALUES(:iX, :iY+1)", &iVal, &iVal); | 1375 execsql(&err, &db, "INSERT INTO t1 VALUES(:iX, :iY+1)", &iVal, &iVal); |
| 1346 nInsert++; | 1376 nInsert++; |
| 1347 } while( iVal ); | 1377 } while( iVal ); |
| 1348 | 1378 |
| 1349 do { | 1379 do { |
| 1350 iVal = (iVal+1)%100; | 1380 iVal = (iVal+1)%100; |
| 1351 execsql(&err, &db, "DELETE FROM t1 WHERE x = :iX", &iVal); | 1381 execsql(&err, &db, "DELETE FROM t1 WHERE x = :iX", &iVal); |
| 1352 nDelete++; | 1382 nDelete++; |
| 1353 } while( iVal ); | 1383 } while( iVal ); |
| 1354 } | 1384 } |
| 1385 closedb(&err, &db); |
| 1355 | 1386 |
| 1356 print_and_free_err(&err); | 1387 print_and_free_err(&err); |
| 1357 return sqlite3_mprintf("%d inserts, %d deletes", nInsert, nDelete); | 1388 return sqlite3_mprintf("%d inserts, %d deletes", nInsert, nDelete); |
| 1358 } | 1389 } |
| 1359 | 1390 |
| 1360 static void dynamic_triggers(int nMs){ | 1391 static void dynamic_triggers(int nMs){ |
| 1361 Error err = {0}; | 1392 Error err = {0}; |
| 1362 Sqlite db = {0}; | 1393 Sqlite db = {0}; |
| 1363 Threadset threads = {0}; | 1394 Threadset threads = {0}; |
| 1364 | 1395 |
| 1365 opendb(&err, &db, "test.db", 1); | 1396 opendb(&err, &db, "test.db", 1); |
| 1366 sql_script(&err, &db, | 1397 sql_script(&err, &db, |
| 1367 "PRAGMA page_size = 1024;" | 1398 "PRAGMA page_size = 1024;" |
| 1368 "PRAGMA journal_mode = WAL;" | 1399 "PRAGMA journal_mode = WAL;" |
| 1369 "CREATE TABLE t1(x, y);" | 1400 "CREATE TABLE t1(x, y);" |
| 1370 "CREATE TABLE t2(x, y);" | 1401 "CREATE TABLE t2(x, y);" |
| 1371 "CREATE TABLE t3(x, y);" | 1402 "CREATE TABLE t3(x, y);" |
| 1372 "CREATE TABLE t4(x, y);" | 1403 "CREATE TABLE t4(x, y);" |
| 1373 "CREATE TABLE t5(x, y);" | 1404 "CREATE TABLE t5(x, y);" |
| 1374 "CREATE TABLE t6(x, y);" | 1405 "CREATE TABLE t6(x, y);" |
| 1375 "CREATE TABLE t7(x, y);" | 1406 "CREATE TABLE t7(x, y);" |
| 1376 "CREATE TABLE t8(x, y);" | 1407 "CREATE TABLE t8(x, y);" |
| 1377 "CREATE TABLE t9(x, y);" | 1408 "CREATE TABLE t9(x, y);" |
| 1378 ); | 1409 ); |
| 1410 closedb(&err, &db); |
| 1379 | 1411 |
| 1380 setstoptime(&err, nMs); | 1412 setstoptime(&err, nMs); |
| 1381 | 1413 |
| 1382 sqlite3_enable_shared_cache(1); | 1414 sqlite3_enable_shared_cache(1); |
| 1383 launch_thread(&err, &threads, dynamic_triggers_2, 0); | 1415 launch_thread(&err, &threads, dynamic_triggers_2, 0); |
| 1384 launch_thread(&err, &threads, dynamic_triggers_2, 0); | 1416 launch_thread(&err, &threads, dynamic_triggers_2, 0); |
| 1385 sqlite3_enable_shared_cache(0); | |
| 1386 | 1417 |
| 1387 sleep(2); | 1418 sleep(2); |
| 1419 sqlite3_enable_shared_cache(0); |
| 1388 | 1420 |
| 1389 launch_thread(&err, &threads, dynamic_triggers_2, 0); | 1421 launch_thread(&err, &threads, dynamic_triggers_2, 0); |
| 1390 launch_thread(&err, &threads, dynamic_triggers_1, 0); | 1422 launch_thread(&err, &threads, dynamic_triggers_1, 0); |
| 1391 | 1423 |
| 1392 join_all_threads(&err, &threads); | 1424 join_all_threads(&err, &threads); |
| 1393 | 1425 |
| 1394 print_and_free_err(&err); | 1426 print_and_free_err(&err); |
| 1395 } | 1427 } |
| 1396 | 1428 |
| 1397 | 1429 |
| 1398 | 1430 |
| 1399 #include "tt3_checkpoint.c" | 1431 #include "tt3_checkpoint.c" |
| 1400 #include "tt3_index.c" | 1432 #include "tt3_index.c" |
| 1433 #include "tt3_lookaside1.c" |
| 1434 #include "tt3_vacuum.c" |
| 1435 #include "tt3_stress.c" |
| 1401 | 1436 |
| 1402 int main(int argc, char **argv){ | 1437 int main(int argc, char **argv){ |
| 1403 struct ThreadTest { | 1438 struct ThreadTest { |
| 1404 void (*xTest)(int); | 1439 void (*xTest)(int); /* Routine for running this test */ |
| 1405 const char *zTest; | 1440 const char *zTest; /* Name of this test */ |
| 1406 int nMs; | 1441 int nMs; /* How long to run this test, in milliseconds */ |
| 1407 } aTest[] = { | 1442 } aTest[] = { |
| 1408 { walthread1, "walthread1", 20000 }, | 1443 { walthread1, "walthread1", 20000 }, |
| 1409 { walthread2, "walthread2", 20000 }, | 1444 { walthread2, "walthread2", 20000 }, |
| 1410 { walthread3, "walthread3", 20000 }, | 1445 { walthread3, "walthread3", 20000 }, |
| 1411 { walthread4, "walthread4", 20000 }, | 1446 { walthread4, "walthread4", 20000 }, |
| 1412 { walthread5, "walthread5", 1000 }, | 1447 { walthread5, "walthread5", 1000 }, |
| 1413 { walthread5, "walthread5", 1000 }, | |
| 1414 | 1448 |
| 1415 { cgt_pager_1, "cgt_pager_1", 0 }, | 1449 { cgt_pager_1, "cgt_pager_1", 0 }, |
| 1416 { dynamic_triggers, "dynamic_triggers", 20000 }, | 1450 { dynamic_triggers, "dynamic_triggers", 20000 }, |
| 1417 | 1451 |
| 1418 { checkpoint_starvation_1, "checkpoint_starvation_1", 10000 }, | 1452 { checkpoint_starvation_1, "checkpoint_starvation_1", 10000 }, |
| 1419 { checkpoint_starvation_2, "checkpoint_starvation_2", 10000 }, | 1453 { checkpoint_starvation_2, "checkpoint_starvation_2", 10000 }, |
| 1420 | 1454 |
| 1421 { create_drop_index_1, "create_drop_index_1", 10000 }, | 1455 { create_drop_index_1, "create_drop_index_1", 10000 }, |
| 1456 { lookaside1, "lookaside1", 10000 }, |
| 1457 { vacuum1, "vacuum1", 10000 }, |
| 1458 { stress1, "stress1", 10000 }, |
| 1459 { stress2, "stress2", 60000 }, |
| 1422 }; | 1460 }; |
| 1461 static char *substArgv[] = { 0, "*", 0 }; |
| 1462 int i, iArg; |
| 1463 int nTestfound = 0; |
| 1423 | 1464 |
| 1424 int i; | 1465 sqlite3_config(SQLITE_CONFIG_MULTITHREAD); |
| 1425 char *zTest = 0; | 1466 if( argc<2 ){ |
| 1426 int nTest = 0; | 1467 argc = 2; |
| 1427 int bTestfound = 0; | 1468 argv = substArgv; |
| 1428 int bPrefix = 0; | 1469 } |
| 1429 | 1470 |
| 1430 if( argc>2 ) goto usage; | 1471 /* Loop through the command-line arguments to ensure that each argument |
| 1431 if( argc==2 ){ | 1472 ** selects at least one test. If not, assume there is a typo on the |
| 1432 zTest = argv[1]; | 1473 ** command-line and bail out with the usage message. */ |
| 1433 nTest = strlen(zTest); | 1474 for(iArg=1; iArg<argc; iArg++){ |
| 1434 if( zTest[nTest-1]=='*' ){ | 1475 const char *zArg = argv[iArg]; |
| 1435 nTest--; | 1476 if( zArg[0]=='-' ){ |
| 1436 bPrefix = 1; | 1477 if( sqlite3_stricmp(zArg, "-multiplexor")==0 ){ |
| 1478 /* Install the multiplexor VFS as the default */ |
| 1479 int rc = sqlite3_multiplex_initialize(0, 1); |
| 1480 if( rc!=SQLITE_OK ){ |
| 1481 fprintf(stderr, "Failed to install multiplexor VFS (%d)\n", rc); |
| 1482 return 253; |
| 1483 } |
| 1484 } |
| 1485 else { |
| 1486 goto usage; |
| 1487 } |
| 1488 |
| 1489 continue; |
| 1490 } |
| 1491 |
| 1492 for(i=0; i<sizeof(aTest)/sizeof(aTest[0]); i++){ |
| 1493 if( sqlite3_strglob(zArg, aTest[i].zTest)==0 ) break; |
| 1494 } |
| 1495 if( i>=sizeof(aTest)/sizeof(aTest[0]) ) goto usage; |
| 1496 } |
| 1497 |
| 1498 for(iArg=1; iArg<argc; iArg++){ |
| 1499 if( argv[iArg][0]=='-' ) continue; |
| 1500 for(i=0; i<sizeof(aTest)/sizeof(aTest[0]); i++){ |
| 1501 char const *z = aTest[i].zTest; |
| 1502 if( sqlite3_strglob(argv[iArg],z)==0 ){ |
| 1503 printf("Running %s for %d seconds...\n", z, aTest[i].nMs/1000); |
| 1504 fflush(stdout); |
| 1505 aTest[i].xTest(aTest[i].nMs); |
| 1506 nTestfound++; |
| 1507 } |
| 1437 } | 1508 } |
| 1438 } | 1509 } |
| 1510 if( nTestfound==0 ) goto usage; |
| 1439 | 1511 |
| 1440 sqlite3_config(SQLITE_CONFIG_MULTITHREAD); | 1512 printf("%d errors out of %d tests\n", nGlobalErr, nTestfound); |
| 1441 | |
| 1442 for(i=0; i<sizeof(aTest)/sizeof(aTest[0]); i++){ | |
| 1443 char const *z = aTest[i].zTest; | |
| 1444 int n = strlen(z); | |
| 1445 if( !zTest || ((bPrefix || n==nTest) && 0==strncmp(zTest, z, nTest)) ){ | |
| 1446 printf("Running %s for %d seconds...\n", z, aTest[i].nMs/1000); | |
| 1447 aTest[i].xTest(aTest[i].nMs); | |
| 1448 bTestfound++; | |
| 1449 } | |
| 1450 } | |
| 1451 if( bTestfound==0 ) goto usage; | |
| 1452 | |
| 1453 printf("Total of %d errors across all tests\n", nGlobalErr); | |
| 1454 return (nGlobalErr>0 ? 255 : 0); | 1513 return (nGlobalErr>0 ? 255 : 0); |
| 1455 | 1514 |
| 1456 usage: | 1515 usage: |
| 1457 printf("Usage: %s [testname|testprefix*]\n", argv[0]); | 1516 printf("Usage: %s [-multiplexor] [testname|testprefix*]...\n", argv[0]); |
| 1458 printf("Available tests are:\n"); | 1517 printf("Available tests are:\n"); |
| 1459 for(i=0; i<sizeof(aTest)/sizeof(aTest[0]); i++){ | 1518 for(i=0; i<sizeof(aTest)/sizeof(aTest[0]); i++){ |
| 1460 printf(" %s\n", aTest[i].zTest); | 1519 printf(" %s\n", aTest[i].zTest); |
| 1461 } | 1520 } |
| 1462 | 1521 |
| 1463 return 254; | 1522 return 254; |
| 1464 } | 1523 } |
| 1465 | |
| 1466 | |
| OLD | NEW |