2007-05-30 14:36:47 +04:00
|
|
|
#
|
|
|
|
# 2007 May 10
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
#
|
|
|
|
# This file tests malloc failures in concert with fuzzy SQL generation.
|
|
|
|
#
|
2008-08-20 20:35:10 +04:00
|
|
|
# $Id: fuzz_malloc.test,v 1.10 2008/08/20 16:35:10 drh Exp $
|
2007-05-30 14:36:47 +04:00
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
2007-06-15 17:57:19 +04:00
|
|
|
|
2007-05-30 14:36:47 +04:00
|
|
|
source $testdir/malloc_common.tcl
|
2007-08-25 17:37:48 +04:00
|
|
|
source $testdir/fuzz_common.tcl
|
2007-05-30 14:36:47 +04:00
|
|
|
|
2010-06-07 21:47:26 +04:00
|
|
|
if {[info exists G(isquick)]} {
|
2007-06-18 16:22:43 +04:00
|
|
|
set ::REPEATS 20
|
2010-06-07 21:47:26 +04:00
|
|
|
} elseif {[info exists G(issoak)]} {
|
2007-06-18 16:22:43 +04:00
|
|
|
set ::REPEATS 100
|
|
|
|
} else {
|
|
|
|
set ::REPEATS 40
|
|
|
|
}
|
2007-05-30 14:36:47 +04:00
|
|
|
|
|
|
|
#
|
|
|
|
# Usage: do_fuzzy_malloc_test <testname> ?<options>?
|
|
|
|
#
|
|
|
|
# -template
|
2007-05-31 12:20:43 +04:00
|
|
|
# -sqlprep
|
2007-05-30 14:36:47 +04:00
|
|
|
# -repeats
|
|
|
|
#
|
|
|
|
proc do_fuzzy_malloc_test {testname args} {
|
|
|
|
set ::fuzzyopts(-repeats) $::REPEATS
|
2007-05-31 12:20:43 +04:00
|
|
|
set ::fuzzyopts(-sqlprep) {}
|
2007-05-30 14:36:47 +04:00
|
|
|
array set ::fuzzyopts $args
|
|
|
|
|
2007-08-30 15:48:31 +04:00
|
|
|
sqlite3_memdebug_fail -1
|
2007-05-31 12:20:43 +04:00
|
|
|
db close
|
2011-08-02 04:57:34 +04:00
|
|
|
delete_file test.db test.db-journal
|
2007-05-31 12:20:43 +04:00
|
|
|
sqlite3 db test.db
|
|
|
|
set ::prep $::fuzzyopts(-sqlprep)
|
|
|
|
execsql $::prep
|
2007-06-15 21:03:14 +04:00
|
|
|
set jj 0
|
2007-05-30 14:36:47 +04:00
|
|
|
for {set ii 0} {$ii < $::fuzzyopts(-repeats)} {incr ii} {
|
2007-06-15 21:03:14 +04:00
|
|
|
expr srand($jj)
|
|
|
|
incr jj
|
2007-05-30 14:36:47 +04:00
|
|
|
set ::sql [subst $::fuzzyopts(-template)]
|
2008-08-20 20:35:10 +04:00
|
|
|
# puts fuzyy-sql=\[$::sql\]; flush stdout
|
2018-04-27 19:35:44 +03:00
|
|
|
foreach {rc ::fmtres} [catchsql "$::sql"] {}
|
2007-05-30 14:36:47 +04:00
|
|
|
if {$rc==0} {
|
2018-04-26 11:56:40 +03:00
|
|
|
set nErr1 [set_test_counter errors]
|
2018-04-27 19:35:44 +03:00
|
|
|
do_faultsim_test $testname-$ii -faults oom* -body {
|
|
|
|
execsql $::sql
|
|
|
|
} -test {
|
|
|
|
if {$testrc && $testresult!="datatype mismatch"} {
|
|
|
|
faultsim_test_result {0 {}}
|
|
|
|
}
|
|
|
|
}
|
2018-04-26 11:56:40 +03:00
|
|
|
if {[set_test_counter errors]>$nErr1} {
|
|
|
|
puts "Previous fuzzy-sql=\[$::sql\]"
|
|
|
|
flush stdout
|
|
|
|
}
|
2007-05-30 14:36:47 +04:00
|
|
|
} else {
|
|
|
|
incr ii -1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#----------------------------------------------------------------
|
|
|
|
# Test malloc failure during parsing (and execution) of a fuzzily
|
|
|
|
# generated expressions.
|
|
|
|
#
|
|
|
|
do_fuzzy_malloc_test fuzzy_malloc-1 -template {Select [Expr]}
|
2007-05-31 12:20:43 +04:00
|
|
|
do_fuzzy_malloc_test fuzzy_malloc-2 -template {[Select]}
|
|
|
|
|
|
|
|
set ::SQLPREP {
|
|
|
|
BEGIN;
|
|
|
|
CREATE TABLE abc(a, b, c);
|
|
|
|
CREATE TABLE def(a, b, c);
|
|
|
|
CREATE TABLE ghi(a, b, c);
|
|
|
|
INSERT INTO abc VALUES(1.5, 3, 'a short string');
|
|
|
|
INSERT INTO def VALUES(NULL, X'ABCDEF',
|
|
|
|
'a longer string. Long enough that it doesn''t fit in Mem.zShort');
|
|
|
|
INSERT INTO ghi VALUES(zeroblob(1000), 'hello world', -1257900987654321);
|
|
|
|
COMMIT;
|
|
|
|
}
|
|
|
|
set ::TableList [list abc def ghi]
|
|
|
|
set ::ColumnList [list a b c]
|
|
|
|
|
|
|
|
do_fuzzy_malloc_test fuzzy_malloc-3 \
|
|
|
|
-template {[Select]} \
|
|
|
|
-sqlprep $::SQLPREP
|
2007-05-30 14:36:47 +04:00
|
|
|
|
|
|
|
finish_test
|