Fix an incorrect tcl comment that appeared in many fts5 test files.
[sqlite.git] / test / fuzz_malloc.test
blob4449ea8fc439f7a390250126533897f924e315d6
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 source $testdir/malloc_common.tcl
21 source $testdir/fuzz_common.tcl
23 if {[info exists G(isquick)]} {
24   set ::REPEATS 20
25 } elseif {[info exists G(issoak)]} {
26   set ::REPEATS 100
27 } else {
28   set ::REPEATS 40
32 # Usage: do_fuzzy_malloc_test <testname> ?<options>?
33
34 #     -template
35 #     -sqlprep
36 #     -repeats
37 #     
38 proc do_fuzzy_malloc_test {testname args} {
39   set ::fuzzyopts(-repeats) $::REPEATS
40   set ::fuzzyopts(-sqlprep) {}
41   array set ::fuzzyopts $args
43   sqlite3_memdebug_fail -1
44   db close
45   delete_file test.db test.db-journal
46   sqlite3 db test.db
47   set ::prep $::fuzzyopts(-sqlprep)
48   execsql $::prep
49   set jj 0
50   for {set ii 0} {$ii < $::fuzzyopts(-repeats)} {incr ii} {
51     expr srand($jj)
52     incr jj
53     set ::sql [subst $::fuzzyopts(-template)]
54     # puts fuzyy-sql=\[$::sql\]; flush stdout
55     foreach {rc ::fmtres} [catchsql "$::sql"] {}
56     if {$rc==0} {
57       set nErr1 [set_test_counter errors]
58       do_faultsim_test $testname-$ii -faults oom* -body {
59         execsql $::sql
60       } -test {
61         if {$testrc && $testresult!="datatype mismatch"} { 
62           faultsim_test_result {0 {}}
63         }
64       }
65       if {[set_test_counter errors]>$nErr1} {
66         puts "Previous fuzzy-sql=\[$::sql\]"
67         flush stdout
68       }
69     } else {
70       incr ii -1
71     }
72   }
75 #----------------------------------------------------------------
76 # Test malloc failure during parsing (and execution) of a fuzzily 
77 # generated expressions.
79 do_fuzzy_malloc_test fuzzy_malloc-1 -template {Select [Expr]}
80 do_fuzzy_malloc_test fuzzy_malloc-2 -template {[Select]}
82 set ::SQLPREP {
83   BEGIN;
84     CREATE TABLE abc(a, b, c);
85     CREATE TABLE def(a, b, c);
86     CREATE TABLE ghi(a, b, c);
87     INSERT INTO abc VALUES(1.5, 3, 'a short string');
88     INSERT INTO def VALUES(NULL, X'ABCDEF', 
89         'a longer string. Long enough that it doesn''t fit in Mem.zShort');
90     INSERT INTO ghi VALUES(zeroblob(1000), 'hello world', -1257900987654321);
91   COMMIT;
93 set ::TableList  [list abc def ghi]
94 set ::ColumnList [list a b c]
96 do_fuzzy_malloc_test fuzzy_malloc-3 \
97   -template {[Select]}              \
98   -sqlprep $::SQLPREP
100 finish_test