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
25 source $testdir/malloc_common.tcl
26 source $testdir/fuzz_common.tcl
28 if {[info exists G(isquick)]} {
30 } elseif {[info exists G(issoak)]} {
37 # Usage: do_fuzzy_malloc_test <testname> ?<options>?
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
50 delete_file test.db test.db-journal
52 set ::prep $::fuzzyopts(-sqlprep)
55 for {set ii 0} {$ii < $::fuzzyopts(-repeats)} {incr ii} {
58 set ::sql [subst $::fuzzyopts(-template)]
59 # puts fuzyy-sql=\[$::sql\]; flush stdout
60 foreach {rc res} [catchsql "$::sql"] {}
62 do_malloc_test $testname-$ii -sqlbody $::sql -sqlprep $::prep
69 #----------------------------------------------------------------
70 # Test malloc failure during parsing (and execution) of a fuzzily
71 # generated expressions.
73 do_fuzzy_malloc_test fuzzy_malloc-1 -template {Select [Expr]}
74 do_fuzzy_malloc_test fuzzy_malloc-2 -template {[Select]}
78 CREATE TABLE abc(a, b, c);
79 CREATE TABLE def(a, b, c);
80 CREATE TABLE ghi(a, b, c);
81 INSERT INTO abc VALUES(1.5, 3, 'a short string');
82 INSERT INTO def VALUES(NULL, X'ABCDEF',
83 'a longer string. Long enough that it doesn''t fit in Mem.zShort');
84 INSERT INTO ghi VALUES(zeroblob(1000), 'hello world', -1257900987654321);
87 set ::TableList [list abc def ghi]
88 set ::ColumnList [list a b c]
90 do_fuzzy_malloc_test fuzzy_malloc-3 \
91 -template {[Select]} \