/ Check-in [1e9e6fe7]
Login

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

Overview
Comment:Add new test file fuzz.test, to test SQLite with fuzzily generated SQL. (CVS 3971)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1e9e6fe75d01d8cf4e1a23505c45f28491f1e902
User & Date: danielk1977 2007-05-10 15:37:53
Context
2007-05-10
17:23
Add some UTF-8 test infrastructure. Treat NaN as NULL. The printf routines print infinity as "Inf" not as "NaN". Ticket #2345. (CVS 3972) check-in: ffe615a7 user: drh tags: trunk
15:37
Add new test file fuzz.test, to test SQLite with fuzzily generated SQL. (CVS 3971) check-in: 1e9e6fe7 user: danielk1977 tags: trunk
13:23
Fix a C++ism in func.c. (CVS 3970) check-in: 9c0050a1 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/vdbemem.c.

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
...
184
185
186
187
188
189
190

191
192
193
194
195
196
197
...
382
383
384
385
386
387
388

389
390
391
392
393
394
395
    }
    memcpy(pNew, pMem->z, pMem->n);
    memset(&pNew[pMem->n], 0, pMem->u.i);
    sqlite3VdbeMemRelease(pMem);
    pMem->z = pNew;
    pMem->n += pMem->u.i;
    pMem->u.i = 0;
    pMem->flags &= MEM_Zero|MEM_Static|MEM_Ephem|MEM_Short;
    pMem->flags |= MEM_Term|MEM_Dyn;
  }
  return SQLITE_OK;
}


/*
** Make the given Mem object either MEM_Short or MEM_Dyn so that bytes
................................................................................
** user and the later is an internal programming error.
*/
int sqlite3VdbeMemStringify(Mem *pMem, int enc){
  int rc = SQLITE_OK;
  int fg = pMem->flags;
  char *z = pMem->zShort;


  assert( !(fg&(MEM_Str|MEM_Blob)) );
  assert( fg&(MEM_Int|MEM_Real) );

  /* For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8
  ** string representation of the value. Then, if the required encoding
  ** is UTF-16le or UTF-16be do a translation.
  ** 
................................................................................
void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){
  sqlite3VdbeMemRelease(pMem);
  pMem->flags = MEM_Blob|MEM_Zero|MEM_Short;
  pMem->type = SQLITE_BLOB;
  pMem->n = 0;
  pMem->u.i = n;
  pMem->z = pMem->zShort;

}

/*
** Delete any previous value and set the value stored in *pMem to val,
** manifest type INTEGER.
*/
void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){







|
|







 







>







 







>







97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
...
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
...
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
    }
    memcpy(pNew, pMem->z, pMem->n);
    memset(&pNew[pMem->n], 0, pMem->u.i);
    sqlite3VdbeMemRelease(pMem);
    pMem->z = pNew;
    pMem->n += pMem->u.i;
    pMem->u.i = 0;
    pMem->flags &= ~(MEM_Zero|MEM_Static|MEM_Ephem|MEM_Short);
    pMem->flags |= (MEM_Term|MEM_Dyn);
  }
  return SQLITE_OK;
}


/*
** Make the given Mem object either MEM_Short or MEM_Dyn so that bytes
................................................................................
** user and the later is an internal programming error.
*/
int sqlite3VdbeMemStringify(Mem *pMem, int enc){
  int rc = SQLITE_OK;
  int fg = pMem->flags;
  char *z = pMem->zShort;

  assert( !(fg&MEM_Zero) );
  assert( !(fg&(MEM_Str|MEM_Blob)) );
  assert( fg&(MEM_Int|MEM_Real) );

  /* For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8
  ** string representation of the value. Then, if the required encoding
  ** is UTF-16le or UTF-16be do a translation.
  ** 
................................................................................
void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){
  sqlite3VdbeMemRelease(pMem);
  pMem->flags = MEM_Blob|MEM_Zero|MEM_Short;
  pMem->type = SQLITE_BLOB;
  pMem->n = 0;
  pMem->u.i = n;
  pMem->z = pMem->zShort;
  pMem->enc = SQLITE_UTF8;
}

/*
** Delete any previous value and set the value stored in *pMem to val,
** manifest type INTEGER.
*/
void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){

Added test/fuzz.test.





























































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

# 2001 September 15
#
# 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.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing the SELECT statement.
#
# $Id: fuzz.test,v 1.1 2007/05/10 15:37:53 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

proc fuzz {TemplateList} {
  set n [llength $TemplateList]
  set i [expr {int(rand()*$n)}]
  return [subst -novar [lindex $TemplateList $i]]
}

proc Value {} {
  set TemplateList {
    456 0 -456 1 -1 
    2147483648 2147483647 2147483649 -2147483647 -2147483648 -2147483649
    'The' 'first' 'experiments' 'in' 'hardware' 'fault' 'injection'
    zeroblob(1000)
    NULL
    56.1 -56.1
    123456789.1234567899
  }
  fuzz $TemplateList
}

proc UnaryOp {} {
  set TemplateList {+ - NOT}
  fuzz $TemplateList
}

proc BinaryOp {} {
  set TemplateList {+ - % * / AND OR LIKE GLOB}
  fuzz $TemplateList
}

set ::ExprDepth 0
proc Expr {} {
  incr ::ExprDepth

  set TemplateList {[Value]}
  if {$::ExprDepth < 100} {
    lappend TemplateList \
      {[Expr] [BinaryOp] [Expr]}   \
      {[UnaryOp] [Expr]}           \
      {([Select])}                 \
      {[Value]}                    
  }
  if {$::SelectDepth < 10} {
    lappend TemplateList {([Select])}
  } 
  set res [fuzz $TemplateList]
  incr ::ExprDepth -1
  return $res
}

set ::SelectDepth 0
proc Select {} {
  incr ::SelectDepth
  set TemplateList {
      {SELECT [Expr]}
  }
  set res [fuzz $TemplateList]
  incr ::SelectDepth -1
  set res
}

do_test fuzz-1.1 {
  execsql {
    SELECT 'abc' LIKE X'ABCD';
  }
} {0}
do_test fuzz-1.2 {
  execsql {
    SELECT 'abc' LIKE zeroblob(10);
  }
} {0}
do_test fuzz-1.3 {
  execsql {
    SELECT zeroblob(10) LIKE 'abc';
  }
} {0}
do_test fuzz-1.4 {
  execsql {
    SELECT (- -21) % NOT (456 LIKE zeroblob(10));
  }
} {0}

do_test fuzz-2.1 {
  for {set ii 0} {$ii < 2000} {incr ii} {
    set ::expr [Expr]
    execsql "SELECT $::expr"
  }
  set a ""
} {}

finish_test

Changes to test/quick.test.

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
41
42
43
44
45
46
47

48
49
50
51
52
53
54
#    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.
#
#***********************************************************************
# This file runs all tests.
#
# $Id: quick.test,v 1.54 2007/05/08 15:59:06 danielk1977 Exp $

proc lshift {lvar} {
  upvar $lvar l
  set ret [lindex $l 0]
  set l [lrange $l 1 end]
  return $ret
}
................................................................................
  btree4.test
  btree5.test
  btree6.test
  corrupt.test
  crash.test
  crash2.test
  exclusive3.test

  loadext.test
  malloc.test
  malloc2.test
  malloc3.test
  memleak.test
  misc7.test
  misuse.test







|







 







>







2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#    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.
#
#***********************************************************************
# This file runs all tests.
#
# $Id: quick.test,v 1.55 2007/05/10 15:37:53 danielk1977 Exp $

proc lshift {lvar} {
  upvar $lvar l
  set ret [lindex $l 0]
  set l [lrange $l 1 end]
  return $ret
}
................................................................................
  btree4.test
  btree5.test
  btree6.test
  corrupt.test
  crash.test
  crash2.test
  exclusive3.test
  fuzz.test
  loadext.test
  malloc.test
  malloc2.test
  malloc3.test
  memleak.test
  misc7.test
  misuse.test