xref: /sqlite-3.40.0/test/fuzz.test (revision def0fec8)
1
2# 2001 September 15
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# This file implements regression tests for SQLite library.  The
13# focus of this file is testing the SELECT statement.
14#
15# $Id: fuzz.test,v 1.1 2007/05/10 15:37:53 danielk1977 Exp $
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20proc fuzz {TemplateList} {
21  set n [llength $TemplateList]
22  set i [expr {int(rand()*$n)}]
23  return [subst -novar [lindex $TemplateList $i]]
24}
25
26proc Value {} {
27  set TemplateList {
28    456 0 -456 1 -1
29    2147483648 2147483647 2147483649 -2147483647 -2147483648 -2147483649
30    'The' 'first' 'experiments' 'in' 'hardware' 'fault' 'injection'
31    zeroblob(1000)
32    NULL
33    56.1 -56.1
34    123456789.1234567899
35  }
36  fuzz $TemplateList
37}
38
39proc UnaryOp {} {
40  set TemplateList {+ - NOT}
41  fuzz $TemplateList
42}
43
44proc BinaryOp {} {
45  set TemplateList {+ - % * / AND OR LIKE GLOB}
46  fuzz $TemplateList
47}
48
49set ::ExprDepth 0
50proc Expr {} {
51  incr ::ExprDepth
52
53  set TemplateList {[Value]}
54  if {$::ExprDepth < 100} {
55    lappend TemplateList \
56      {[Expr] [BinaryOp] [Expr]}   \
57      {[UnaryOp] [Expr]}           \
58      {([Select])}                 \
59      {[Value]}
60  }
61  if {$::SelectDepth < 10} {
62    lappend TemplateList {([Select])}
63  }
64  set res [fuzz $TemplateList]
65  incr ::ExprDepth -1
66  return $res
67}
68
69set ::SelectDepth 0
70proc Select {} {
71  incr ::SelectDepth
72  set TemplateList {
73      {SELECT [Expr]}
74  }
75  set res [fuzz $TemplateList]
76  incr ::SelectDepth -1
77  set res
78}
79
80do_test fuzz-1.1 {
81  execsql {
82    SELECT 'abc' LIKE X'ABCD';
83  }
84} {0}
85do_test fuzz-1.2 {
86  execsql {
87    SELECT 'abc' LIKE zeroblob(10);
88  }
89} {0}
90do_test fuzz-1.3 {
91  execsql {
92    SELECT zeroblob(10) LIKE 'abc';
93  }
94} {0}
95do_test fuzz-1.4 {
96  execsql {
97    SELECT (- -21) % NOT (456 LIKE zeroblob(10));
98  }
99} {0}
100
101do_test fuzz-2.1 {
102  for {set ii 0} {$ii < 2000} {incr ii} {
103    set ::expr [Expr]
104    execsql "SELECT $::expr"
105  }
106  set a ""
107} {}
108
109finish_test
110
111