Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: third_party/sqlite/src/mptest/mptest.c

Issue 2765553002: [sql] Import SQLite 3.17.0. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 ** 2013-04-05 2 ** 2013-04-05
3 ** 3 **
4 ** The author disclaims copyright to this source code. In place of 4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing: 5 ** a legal notice, here is a blessing:
6 ** 6 **
7 ** May you do good and not evil. 7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others. 8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give. 9 ** May you share freely, never taking more than you give.
10 ** 10 **
(...skipping 23 matching lines...) Expand all
34 ** test script. 34 ** test script.
35 */ 35 */
36 #include "sqlite3.h" 36 #include "sqlite3.h"
37 #include <stdio.h> 37 #include <stdio.h>
38 #if defined(_WIN32) 38 #if defined(_WIN32)
39 # define WIN32_LEAN_AND_MEAN 39 # define WIN32_LEAN_AND_MEAN
40 # include <windows.h> 40 # include <windows.h>
41 #else 41 #else
42 # include <unistd.h> 42 # include <unistd.h>
43 #endif 43 #endif
44 #include <errno.h>
44 #include <stdlib.h> 45 #include <stdlib.h>
45 #include <string.h> 46 #include <string.h>
46 #include <assert.h> 47 #include <assert.h>
47 #include <ctype.h> 48 #include <ctype.h>
48 49
49 #define ISSPACE(X) isspace((unsigned char)(X)) 50 #define ISSPACE(X) isspace((unsigned char)(X))
50 #define ISDIGIT(X) isdigit((unsigned char)(X)) 51 #define ISDIGIT(X) isdigit((unsigned char)(X))
51 52
52 /* The suffix to append to the child command lines, if any */ 53 /* The suffix to append to the child command lines, if any */
53 #if defined(_WIN32) 54 #if defined(_WIN32)
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 } 1238 }
1238 1239
1239 /* Print a usage message for the program and exit */ 1240 /* Print a usage message for the program and exit */
1240 static void usage(const char *argv0){ 1241 static void usage(const char *argv0){
1241 int i; 1242 int i;
1242 const char *zTail = argv0; 1243 const char *zTail = argv0;
1243 for(i=0; argv0[i]; i++){ 1244 for(i=0; argv0[i]; i++){
1244 if( isDirSep(argv0[i]) ) zTail = argv0+i+1; 1245 if( isDirSep(argv0[i]) ) zTail = argv0+i+1;
1245 } 1246 }
1246 fprintf(stderr,"Usage: %s DATABASE ?OPTIONS? ?SCRIPT?\n", zTail); 1247 fprintf(stderr,"Usage: %s DATABASE ?OPTIONS? ?SCRIPT?\n", zTail);
1248 fprintf(stderr,
1249 "Options:\n"
1250 " --errlog FILENAME Write errors to FILENAME\n"
1251 " --journalmode MODE Use MODE as the journal_mode\n"
1252 " --log FILENAME Log messages to FILENAME\n"
1253 " --quiet Suppress unnecessary output\n"
1254 " --vfs NAME Use NAME as the VFS\n"
1255 " --repeat N Repeat the test N times\n"
1256 " --sqltrace Enable SQL tracing\n"
1257 " --sync Enable synchronous disk writes\n"
1258 " --timeout MILLISEC Busy timeout is MILLISEC\n"
1259 " --trace BOOLEAN Enable or disable tracing\n"
1260 );
1247 exit(1); 1261 exit(1);
1248 } 1262 }
1249 1263
1250 /* Report on unrecognized arguments */ 1264 /* Report on unrecognized arguments */
1251 static void unrecognizedArguments( 1265 static void unrecognizedArguments(
1252 const char *argv0, 1266 const char *argv0,
1253 int nArg, 1267 int nArg,
1254 char **azArg 1268 char **azArg
1255 ){ 1269 ){
1256 int i; 1270 int i;
(...skipping 11 matching lines...) Expand all
1268 int n, i; 1282 int n, i;
1269 int openFlags = SQLITE_OPEN_READWRITE; 1283 int openFlags = SQLITE_OPEN_READWRITE;
1270 int rc; 1284 int rc;
1271 char *zScript; 1285 char *zScript;
1272 int taskId; 1286 int taskId;
1273 const char *zTrace; 1287 const char *zTrace;
1274 const char *zCOption; 1288 const char *zCOption;
1275 const char *zJMode; 1289 const char *zJMode;
1276 const char *zNRep; 1290 const char *zNRep;
1277 int nRep = 1, iRep; 1291 int nRep = 1, iRep;
1292 int iTmout = 0; /* Default: no timeout */
1293 const char *zTmout;
1278 1294
1279 g.argv0 = argv[0]; 1295 g.argv0 = argv[0];
1280 g.iTrace = 1; 1296 g.iTrace = 1;
1281 if( argc<2 ) usage(argv[0]); 1297 if( argc<2 ) usage(argv[0]);
1282 g.zDbFile = argv[1]; 1298 g.zDbFile = argv[1];
1283 if( strglob("*.test", g.zDbFile) ) usage(argv[0]); 1299 if( strglob("*.test", g.zDbFile) ) usage(argv[0]);
1284 if( strcmp(sqlite3_sourceid(), SQLITE_SOURCE_ID)!=0 ){ 1300 if( strcmp(sqlite3_sourceid(), SQLITE_SOURCE_ID)!=0 ){
1285 fprintf(stderr, "SQLite library and header mismatch\n" 1301 fprintf(stderr, "SQLite library and header mismatch\n"
1286 "Library: %s\n" 1302 "Library: %s\n"
1287 "Header: %s\n", 1303 "Header: %s\n",
1288 sqlite3_sourceid(), SQLITE_SOURCE_ID); 1304 sqlite3_sourceid(), SQLITE_SOURCE_ID);
1289 exit(1); 1305 exit(1);
1290 } 1306 }
1291 n = argc-2; 1307 n = argc-2;
1292 sqlite3_snprintf(sizeof(g.zName), g.zName, "%05d.mptest", GETPID()); 1308 sqlite3_snprintf(sizeof(g.zName), g.zName, "%05d.mptest", GETPID());
1293 zJMode = findOption(argv+2, &n, "journalmode", 1); 1309 zJMode = findOption(argv+2, &n, "journalmode", 1);
1294 zNRep = findOption(argv+2, &n, "repeat", 1); 1310 zNRep = findOption(argv+2, &n, "repeat", 1);
1295 if( zNRep ) nRep = atoi(zNRep); 1311 if( zNRep ) nRep = atoi(zNRep);
1296 if( nRep<1 ) nRep = 1; 1312 if( nRep<1 ) nRep = 1;
1297 g.zVfs = findOption(argv+2, &n, "vfs", 1); 1313 g.zVfs = findOption(argv+2, &n, "vfs", 1);
1298 zClient = findOption(argv+2, &n, "client", 1); 1314 zClient = findOption(argv+2, &n, "client", 1);
1299 g.zErrLog = findOption(argv+2, &n, "errlog", 1); 1315 g.zErrLog = findOption(argv+2, &n, "errlog", 1);
1300 g.zLog = findOption(argv+2, &n, "log", 1); 1316 g.zLog = findOption(argv+2, &n, "log", 1);
1301 zTrace = findOption(argv+2, &n, "trace", 1); 1317 zTrace = findOption(argv+2, &n, "trace", 1);
1302 if( zTrace ) g.iTrace = atoi(zTrace); 1318 if( zTrace ) g.iTrace = atoi(zTrace);
1303 if( findOption(argv+2, &n, "quiet", 0)!=0 ) g.iTrace = 0; 1319 if( findOption(argv+2, &n, "quiet", 0)!=0 ) g.iTrace = 0;
1320 zTmout = findOption(argv+2, &n, "timeout", 1);
1321 if( zTmout ) iTmout = atoi(zTmout);
1304 g.bSqlTrace = findOption(argv+2, &n, "sqltrace", 0)!=0; 1322 g.bSqlTrace = findOption(argv+2, &n, "sqltrace", 0)!=0;
1305 g.bSync = findOption(argv+2, &n, "sync", 0)!=0; 1323 g.bSync = findOption(argv+2, &n, "sync", 0)!=0;
1306 if( g.zErrLog ){ 1324 if( g.zErrLog ){
1307 g.pErrLog = fopen(g.zErrLog, "a"); 1325 g.pErrLog = fopen(g.zErrLog, "a");
1308 }else{ 1326 }else{
1309 g.pErrLog = stderr; 1327 g.pErrLog = stderr;
1310 } 1328 }
1311 if( g.zLog ){ 1329 if( g.zLog ){
1312 g.pLog = fopen(g.zLog, "a"); 1330 g.pLog = fopen(g.zLog, "a");
1313 }else{ 1331 }else{
1314 g.pLog = stdout; 1332 g.pLog = stdout;
1315 } 1333 }
1316 1334
1317 sqlite3_config(SQLITE_CONFIG_LOG, sqlErrorCallback, 0); 1335 sqlite3_config(SQLITE_CONFIG_LOG, sqlErrorCallback, 0);
1318 if( zClient ){ 1336 if( zClient ){
1319 iClient = atoi(zClient); 1337 iClient = atoi(zClient);
1320 if( iClient<1 ) fatalError("illegal client number: %d\n", iClient); 1338 if( iClient<1 ) fatalError("illegal client number: %d\n", iClient);
1321 sqlite3_snprintf(sizeof(g.zName), g.zName, "%05d.client%02d", 1339 sqlite3_snprintf(sizeof(g.zName), g.zName, "%05d.client%02d",
1322 GETPID(), iClient); 1340 GETPID(), iClient);
1323 }else{ 1341 }else{
1342 int nTry = 0;
1324 if( g.iTrace>0 ){ 1343 if( g.iTrace>0 ){
1325 printf("BEGIN: %s", argv[0]); 1344 printf("BEGIN: %s", argv[0]);
1326 for(i=1; i<argc; i++) printf(" %s", argv[i]); 1345 for(i=1; i<argc; i++) printf(" %s", argv[i]);
1327 printf("\n"); 1346 printf("\n");
1328 printf("With SQLite " SQLITE_VERSION " " SQLITE_SOURCE_ID "\n" ); 1347 printf("With SQLite " SQLITE_VERSION " " SQLITE_SOURCE_ID "\n" );
1329 for(i=0; (zCOption = sqlite3_compileoption_get(i))!=0; i++){ 1348 for(i=0; (zCOption = sqlite3_compileoption_get(i))!=0; i++){
1330 printf("-DSQLITE_%s\n", zCOption); 1349 printf("-DSQLITE_%s\n", zCOption);
1331 } 1350 }
1332 fflush(stdout); 1351 fflush(stdout);
1333 } 1352 }
1334 iClient = 0; 1353 iClient = 0;
1335 unlink(g.zDbFile); 1354 do{
1355 if( (nTry%5)==4 ) printf("... %strying to unlink '%s'\n",
1356 nTry>5 ? "still " : "", g.zDbFile);
1357 rc = unlink(g.zDbFile);
1358 if( rc && errno==ENOENT ) rc = 0;
1359 }while( rc!=0 && (++nTry)<60 && sqlite3_sleep(1000)>0 );
1360 if( rc!=0 ){
1361 fatalError("unable to unlink '%s' after %d attempts\n",
1362 g.zDbFile, nTry);
1363 }
1336 openFlags |= SQLITE_OPEN_CREATE; 1364 openFlags |= SQLITE_OPEN_CREATE;
1337 } 1365 }
1338 rc = sqlite3_open_v2(g.zDbFile, &g.db, openFlags, g.zVfs); 1366 rc = sqlite3_open_v2(g.zDbFile, &g.db, openFlags, g.zVfs);
1339 if( rc ) fatalError("cannot open [%s]", g.zDbFile); 1367 if( rc ) fatalError("cannot open [%s]", g.zDbFile);
1368 if( iTmout>0 ) sqlite3_busy_timeout(g.db, iTmout);
1369
1340 if( zJMode ){ 1370 if( zJMode ){
1341 #if defined(_WIN32) 1371 #if defined(_WIN32)
1342 if( sqlite3_stricmp(zJMode,"persist")==0 1372 if( sqlite3_stricmp(zJMode,"persist")==0
1343 || sqlite3_stricmp(zJMode,"truncate")==0 1373 || sqlite3_stricmp(zJMode,"truncate")==0
1344 ){ 1374 ){
1345 printf("Changing journal mode to DELETE from %s", zJMode); 1375 printf("Changing journal mode to DELETE from %s", zJMode);
1346 zJMode = "DELETE"; 1376 zJMode = "DELETE";
1347 } 1377 }
1348 #endif 1378 #endif
1349 runSql("PRAGMA journal_mode=%Q;", zJMode); 1379 runSql("PRAGMA journal_mode=%Q;", zJMode);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 maybeClose(g.pLog); 1461 maybeClose(g.pLog);
1432 maybeClose(g.pErrLog); 1462 maybeClose(g.pErrLog);
1433 if( iClient==0 ){ 1463 if( iClient==0 ){
1434 printf("Summary: %d errors out of %d tests\n", g.nError, g.nTest); 1464 printf("Summary: %d errors out of %d tests\n", g.nError, g.nTest);
1435 printf("END: %s", argv[0]); 1465 printf("END: %s", argv[0]);
1436 for(i=1; i<argc; i++) printf(" %s", argv[i]); 1466 for(i=1; i<argc; i++) printf(" %s", argv[i]);
1437 printf("\n"); 1467 printf("\n");
1438 } 1468 }
1439 return g.nError>0; 1469 return g.nError>0;
1440 } 1470 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698