Prevent deep recursions on nested COLLATE operators.
[sqlite.git] / test / fuzz_malloc.test
blob531da55c1a40e4afd92e5302c2a737ad6df3434f
2 # 2007 May 10
4 # The author disclaims copyright to this source code.  In place of
5 # a legal notice, here is a blessing:
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.
11 #***********************************************************************
13 # This file tests malloc failures in concert with fuzzy SQL generation.
15 # $Id: fuzz_malloc.test,v 1.10 2008/08/20 16:35:10 drh Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 ifcapable !memdebug {
21   finish_test
22   return
25 source $testdir/malloc_common.tcl
26 source $testdir/fuzz_common.tcl
28 if {[info exists G(isquick)]} {
29   set ::REPEATS 20
30 } elseif {[info exists G(issoak)]} {
31   set ::REPEATS 100
32 } else {
33   set ::REPEATS 40
37 # Usage: do_fuzzy_malloc_test <testname> ?<options>?
38
39 #     -template
40 #     -sqlprep
41 #     -repeats
42 #     
43 proc do_fuzzy_malloc_test {testname args} {
44   set ::fuzzyopts(-repeats) $::REPEATS
45   set ::fuzzyopts(-sqlprep) {}
46   array set ::fuzzyopts $args
48   sqlite3_memdebug_fail -1
49   db close
50   delete_file test.db test.db-journal
51   sqlite3 db test.db
52   set ::prep $::fuzzyopts(-sqlprep)
53   execsql $::prep
54   set jj 0
55   for {set ii 0} {$ii < $::fuzzyopts(-repeats)} {incr ii} {
56     expr srand($jj)
57     incr jj
58     set ::sql [subst $::fuzzyopts(-template)]
59     # puts fuzyy-sql=\[$::sql\]; flush stdout
60     foreach {rc ::fmtres} [catchsql "$::sql"] {}
61     if {$rc==0} {
62       set nErr1 [set_test_counter errors]
63       do_faultsim_test $testname-$ii -faults oom* -body {
64         execsql $::sql
65       } -test {
66         if {$testrc && $testresult!="datatype mismatch"} { 
67           faultsim_test_result {0 {}}
68         }
69       }
70       if {[set_test_counter errors]>$nErr1} {
71         puts "Previous fuzzy-sql=\[$::sql\]"
72         flush stdout
73       }
74     } else {
75       incr ii -1
76     }
77   }
80 #----------------------------------------------------------------
81 # Test malloc failure during parsing (and execution) of a fuzzily 
82 # generated expressions.
84 do_fuzzy_malloc_test fuzzy_malloc-1 -template {Select [Expr]}
85 do_fuzzy_malloc_test fuzzy_malloc-2 -template {[Select]}
87 set ::SQLPREP {
88   BEGIN;
89     CREATE TABLE abc(a, b, c);
90     CREATE TABLE def(a, b, c);
91     CREATE TABLE ghi(a, b, c);
92     INSERT INTO abc VALUES(1.5, 3, 'a short string');
93     INSERT INTO def VALUES(NULL, X'ABCDEF', 
94         'a longer string. Long enough that it doesn''t fit in Mem.zShort');
95     INSERT INTO ghi VALUES(zeroblob(1000), 'hello world', -1257900987654321);
96   COMMIT;
98 set ::TableList  [list abc def ghi]
99 set ::ColumnList [list a b c]
101 do_fuzzy_malloc_test fuzzy_malloc-3 \
102   -template {[Select]}              \
103   -sqlprep $::SQLPREP
105 finish_test