/ Check-in [0dd18ec8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the --native-malloc option to fuzzcheck. Fix ossfuzz.c and fuzzcheck.c so that they both deallocate the temp_store_directory before closing.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0dd18ec882bb28a87629d6d8dfeb5ea5d82833634b3781a7d14b917272c4dfa0
User & Date: drh 2017-03-20 22:58:27
Context
2017-03-21
10:45
Do not run sync2.test as part of the "inmemory_journal" permutation. check-in: 9f680bc7 user: dan tags: trunk
2017-03-20
22:58
Add the --native-malloc option to fuzzcheck. Fix ossfuzz.c and fuzzcheck.c so that they both deallocate the temp_store_directory before closing. check-in: 0dd18ec8 user: drh tags: trunk
20:42
Fix the fuzzcheck program so that it can create new databases again. check-in: 021e8874 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/fuzzcheck.c.

   801    801   "  -q|--quiet           Reduced output\n"
   802    802   "  --limit-mem N        Limit memory used by test SQLite instance to N bytes\n"
   803    803   "  --limit-vdbe         Panic if any test runs for more than 100,000 cycles\n"
   804    804   "  --load-sql ARGS...   Load SQL scripts fro files into SOURCE-DB\n"
   805    805   "  --load-db ARGS...    Load template databases from files into SOURCE_DB\n"
   806    806   "  -m TEXT              Add a description to the database\n"
   807    807   "  --native-vfs         Use the native VFS for initially empty database files\n"
          808  +"  --native-malloc      Turn off MEMSYS3/5 and Lookaside\n"
   808    809   "  --oss-fuzz           Enable OSS-FUZZ testing\n"
   809    810   "  --prng-seed N        Seed value for the PRGN inside of SQLite\n"
   810    811   "  --rebuild            Rebuild and vacuum the database file\n"
   811    812   "  --result-trace       Show the results of each SQL command\n"
   812    813   "  --sqlid N            Use only SQL where sqlid=N\n"
   813    814   "  --timeout N          Abort if any single test needs more than N seconds\n"
   814    815   "  -v|--verbose         Increased output.  Repeat for more output.\n"
................................................................................
   847    848     int nMem = 0;                /* Memory limit */
   848    849     int nMemThisDb = 0;          /* Memory limit set by the CONFIG table */
   849    850     char *zExpDb = 0;            /* Write Databases to files in this directory */
   850    851     char *zExpSql = 0;           /* Write SQL to files in this directory */
   851    852     void *pHeap = 0;             /* Heap for use by SQLite */
   852    853     int ossFuzz = 0;             /* enable OSS-FUZZ testing */
   853    854     int ossFuzzThisDb = 0;       /* ossFuzz value for this particular database */
          855  +  int nativeMalloc = 0;        /* Turn off MEMSYS3/5 and lookaside if true */
   854    856     sqlite3_vfs *pDfltVfs;       /* The default VFS */
   855    857   
   856    858     iBegin = timeOfDay();
   857    859   #ifdef __unix__
   858    860     signal(SIGALRM, timeoutHandler);
   859    861   #endif
   860    862     g.zArgv0 = argv[0];
................................................................................
   906    908           zInsSql = "INSERT INTO db(dbcontent) VALUES(readfile(?1))";
   907    909           iFirstInsArg = i+1;
   908    910           break;
   909    911         }else
   910    912         if( strcmp(z,"m")==0 ){
   911    913           if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]);
   912    914           zMsg = argv[++i];
          915  +      }else
          916  +      if( strcmp(z,"native-malloc")==0 ){
          917  +        nativeMalloc = 1;
   913    918         }else
   914    919         if( strcmp(z,"native-vfs")==0 ){
   915    920           nativeFlag = 1;
   916    921         }else
   917    922         if( strcmp(z,"oss-fuzz")==0 ){
   918    923           ossFuzz = 1;
   919    924         }else
................................................................................
  1009   1014         while( SQLITE_ROW==sqlite3_step(pStmt) ){
  1010   1015           const char *zName = (const char *)sqlite3_column_text(pStmt,0);
  1011   1016           if( zName==0 ) continue;
  1012   1017           if( strcmp(zName, "oss-fuzz")==0 ){
  1013   1018             ossFuzzThisDb = sqlite3_column_int(pStmt,1);
  1014   1019             if( verboseFlag ) printf("Config: oss-fuzz=%d\n", ossFuzzThisDb);
  1015   1020           }
  1016         -        if( strcmp(zName, "limit-mem")==0 ){
         1021  +        if( strcmp(zName, "limit-mem")==0 && !nativeMalloc ){
  1017   1022   #if !defined(SQLITE_ENABLE_MEMSYS3) && !defined(SQLITE_ENABLE_MEMSYS5)
  1018   1023             fatalError("the limit-mem option requires -DSQLITE_ENABLE_MEMSYS5"
  1019   1024                        " or _MEMSYS3");
  1020   1025   #else
  1021   1026             nMemThisDb = sqlite3_column_int(pStmt,1);
  1022   1027             if( verboseFlag ) printf("Config: limit-mem=%d\n", nMemThisDb);
  1023   1028   #endif
................................................................................
  1139   1144       */
  1140   1145       sqlite3_close(db);
  1141   1146       if( sqlite3_memory_used()>0 ){
  1142   1147         fatalError("SQLite has memory in use before the start of testing");
  1143   1148       }
  1144   1149   
  1145   1150       /* Limit available memory, if requested */
  1146         -    if( nMemThisDb>0 ){
  1147         -      sqlite3_shutdown();
         1151  +    sqlite3_shutdown();
         1152  +    if( nMemThisDb>0 && !nativeMalloc ){
  1148   1153         pHeap = realloc(pHeap, nMemThisDb);
  1149   1154         if( pHeap==0 ){
  1150   1155           fatalError("failed to allocate %d bytes of heap memory", nMem);
  1151   1156         }
  1152   1157         sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nMemThisDb, 128);
  1153   1158       }
         1159  +
         1160  +    /* Disable lookaside with the --native-malloc option */
         1161  +    if( nativeMalloc ){
         1162  +      sqlite3_config(SQLITE_CONFIG_LOOKASIDE, 0, 0);
         1163  +    }
  1154   1164     
  1155   1165       /* Reset the in-memory virtual filesystem */
  1156   1166       formatVfs();
  1157   1167       
  1158   1168       /* Run a test using each SQL script against each database.
  1159   1169       */
  1160   1170       if( !verboseFlag && !quietFlag ) printf("%s:", zDbName);
................................................................................
  1203   1213               sqlite3_progress_handler(db, 100000, progressHandler, &vdbeLimitFlag);
  1204   1214             }
  1205   1215   #endif
  1206   1216             do{
  1207   1217               runSql(db, (char*)pSql->a, runFlags);
  1208   1218             }while( timeoutTest );
  1209   1219             setAlarm(0);
         1220  +          sqlite3_exec(db, "PRAGMA temp_store_directory=''", 0, 0, 0);
  1210   1221             sqlite3_close(db);
  1211   1222           }
  1212         -        if( sqlite3_memory_used()>0 ) fatalError("memory leak");
         1223  +        if( sqlite3_memory_used()>0 ){
         1224  +           fatalError("memory leak: %lld bytes outstanding",
         1225  +                      sqlite3_memory_used());
         1226  +        }
  1213   1227           reformatVfs();
  1214   1228           nTest++;
  1215   1229           g.zTestName[0] = 0;
  1216   1230   
  1217   1231           /* Simulate an error if the TEST_FAILURE environment variable is "5".
  1218   1232           ** This is used to verify that automated test script really do spot
  1219   1233           ** errors that occur in this test program.

Changes to test/ossfuzz.c.

   141    141     if( (mDebug & FUZZ_SHOW_ERRORS)!=0 && zErrMsg ){
   142    142       printf("Error: %s\n", zErrMsg);
   143    143     }
   144    144   
   145    145     /* Cleanup and return */
   146    146     sqlite3_free(zErrMsg);
   147    147     sqlite3_free(zSql);
          148  +  sqlite3_exec(cx.db, "PRAGMA temp_store_directory=''", 0, 0, 0);
   148    149     sqlite3_close(cx.db);
   149    150   
   150    151     if( mDebug & FUZZ_SHOW_MAX_DELAY ){
   151    152       printf("Progress callback count....... %d\n", cx.nCb);
   152    153       printf("Max time between callbacks.... %d ms\n", (int)cx.mxInterval);
   153    154     }
   154    155     return 0;
   155    156   }