aboutsummaryrefslogtreecommitdiff
path: root/tool/fuzzershell.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2015-04-24 16:09:12 +0000
committerdrh <drh@noemail.net>2015-04-24 16:09:12 +0000
commite1a71a582f159b8e3bac6ad2b321238da7da1e52 (patch)
treead22be59941f85e499b174fe83f1b83d87e36768 /tool/fuzzershell.c
parent875bafa17a6d7f2b4ccf3bf146eaa3752c07011d (diff)
downloadsqlite-e1a71a582f159b8e3bac6ad2b321238da7da1e52.tar.gz
sqlite-e1a71a582f159b8e3bac6ad2b321238da7da1e52.zip
Add AFL-generated test cases in the test/fuzzdata1.txt file. Automatically
run fuzzershell against those cases on a "make test". FossilOrigin-Name: 627ea83c26b420088f101801eb8765127f47d2d0
Diffstat (limited to 'tool/fuzzershell.c')
-rw-r--r--tool/fuzzershell.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/tool/fuzzershell.c b/tool/fuzzershell.c
index 65c8fb78a..a35ed3aa7 100644
--- a/tool/fuzzershell.c
+++ b/tool/fuzzershell.c
@@ -373,6 +373,7 @@ int main(int argc, char **argv){
sqlite3 *dataDb = 0; /* Database holding compacted input data */
sqlite3_stmt *pStmt = 0; /* Statement to insert testcase into dataDb */
const char *zDataOut = 0; /* Write compacted data to this output file */
+ int nHeader = 0; /* Bytes of header comment text on input file */
g.zArgv0 = argv[0];
@@ -524,7 +525,12 @@ int main(int argc, char **argv){
abendError("unable to open initialization database \"%s\"", zInitDb);
}
}
- for(i=nTest=0; i<nIn; i=iNext, nTest++){
+ for(i=0; i<nIn; i=iNext+1){ /* Skip initial lines beginning with '#' */
+ if( zIn[i]!='#' ) break;
+ for(iNext=i+1; iNext<nIn && zIn[iNext]!='\n'; iNext++){}
+ }
+ nHeader = i;
+ for(nTest=0; i<nIn; i=iNext, nTest++){
char cSaved;
if( strncmp(&zIn[i], "/****<",6)==0 ){
char *z = strstr(&zIn[i], ">****/");
@@ -582,9 +588,10 @@ int main(int argc, char **argv){
printf("INPUT (offset: %d, size: %d): [%s]\n",
i, (int)strlen(&zIn[i]), &zIn[i]);
}else if( multiTest && !quietFlag ){
- int pct = 100*(i+strlen(zSql))/nIn;
+ int pct = 10*iNext/nIn;
if( pct!=lastPct ){
- printf("%d%%\r", pct);
+ if( lastPct<0 ) printf("fuzz test:");
+ printf(" %d%%", pct*10);
fflush(stdout);
lastPct = pct;
}
@@ -621,15 +628,24 @@ int main(int argc, char **argv){
if( sqlite3_memory_used()>0 ){
abendError("memory in use after close: %lld bytes", sqlite3_memory_used());
}
+ if( nTest==1 ){
+ /* Simulate an error if the TEST_FAILURE environment variable is "5" */
+ char *zFailCode = getenv("TEST_FAILURE");
+ if( zFailCode && zFailCode[0]=='5' && zFailCode[1]==0 ){
+ abendError("simulated failure");
+ }
+ }
}
+ if( !verboseFlag && multiTest && !quietFlag ) printf("\n");
if( nTest>1 && !quietFlag ){
- printf("%d tests with no errors\nSQLite %s %s\n",
+ printf("%d fuzz tests with no errors\nSQLite %s %s\n",
nTest, sqlite3_libversion(), sqlite3_sourceid());
}
if( zDataOut ){
- FILE *out = fopen(zDataOut, "wb");
int n = 0;
+ FILE *out = fopen(zDataOut, "wb");
if( out==0 ) abendError("cannot open %s for writing", zDataOut);
+ if( nHeader>0 ) fwrite(zIn, nHeader, 1, out);
sqlite3_finalize(pStmt);
rc = sqlite3_prepare_v2(dataDb, "SELECT sql FROM testcase", -1, &pStmt, 0);
if( rc ) abendError("%s", sqlite3_errmsg(dataDb));