sl@0: # sl@0: # 2007 May 10 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # sl@0: # This file tests malloc failures in concert with fuzzy SQL generation. sl@0: # sl@0: # $Id: fuzz_malloc.test,v 1.10 2008/08/20 16:35:10 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: ifcapable !memdebug { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: source $testdir/malloc_common.tcl sl@0: source $testdir/fuzz_common.tcl sl@0: sl@0: if {[info exists ISQUICK]} { sl@0: set ::REPEATS 20 sl@0: } elseif {[info exists SOAKTEST]} { sl@0: set ::REPEATS 100 sl@0: } else { sl@0: set ::REPEATS 40 sl@0: } sl@0: sl@0: # sl@0: # Usage: do_fuzzy_malloc_test ?? sl@0: # sl@0: # -template sl@0: # -sqlprep sl@0: # -repeats sl@0: # sl@0: proc do_fuzzy_malloc_test {testname args} { sl@0: set ::fuzzyopts(-repeats) $::REPEATS sl@0: set ::fuzzyopts(-sqlprep) {} sl@0: array set ::fuzzyopts $args sl@0: sl@0: sqlite3_memdebug_fail -1 sl@0: db close sl@0: file delete test.db test.db-journal sl@0: sqlite3 db test.db sl@0: set ::prep $::fuzzyopts(-sqlprep) sl@0: execsql $::prep sl@0: set jj 0 sl@0: for {set ii 0} {$ii < $::fuzzyopts(-repeats)} {incr ii} { sl@0: expr srand($jj) sl@0: incr jj sl@0: set ::sql [subst $::fuzzyopts(-template)] sl@0: # puts fuzyy-sql=\[$::sql\]; flush stdout sl@0: foreach {rc res} [catchsql "$::sql"] {} sl@0: if {$rc==0} { sl@0: do_malloc_test $testname-$ii -sqlbody $::sql -sqlprep $::prep sl@0: } else { sl@0: incr ii -1 sl@0: } sl@0: } sl@0: } sl@0: sl@0: #---------------------------------------------------------------- sl@0: # Test malloc failure during parsing (and execution) of a fuzzily sl@0: # generated expressions. sl@0: # sl@0: do_fuzzy_malloc_test fuzzy_malloc-1 -template {Select [Expr]} sl@0: do_fuzzy_malloc_test fuzzy_malloc-2 -template {[Select]} sl@0: sl@0: set ::SQLPREP { sl@0: BEGIN; sl@0: CREATE TABLE abc(a, b, c); sl@0: CREATE TABLE def(a, b, c); sl@0: CREATE TABLE ghi(a, b, c); sl@0: INSERT INTO abc VALUES(1.5, 3, 'a short string'); sl@0: INSERT INTO def VALUES(NULL, X'ABCDEF', sl@0: 'a longer string. Long enough that it doesn''t fit in Mem.zShort'); sl@0: INSERT INTO ghi VALUES(zeroblob(1000), 'hello world', -1257900987654321); sl@0: COMMIT; sl@0: } sl@0: set ::TableList [list abc def ghi] sl@0: set ::ColumnList [list a b c] sl@0: sl@0: do_fuzzy_malloc_test fuzzy_malloc-3 \ sl@0: -template {[Select]} \ sl@0: -sqlprep $::SQLPREP sl@0: sl@0: finish_test