sl@0
|
1 |
#
|
sl@0
|
2 |
# 2007 May 10
|
sl@0
|
3 |
#
|
sl@0
|
4 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
5 |
# a legal notice, here is a blessing:
|
sl@0
|
6 |
#
|
sl@0
|
7 |
# May you do good and not evil.
|
sl@0
|
8 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
9 |
# May you share freely, never taking more than you give.
|
sl@0
|
10 |
#
|
sl@0
|
11 |
#***********************************************************************
|
sl@0
|
12 |
#
|
sl@0
|
13 |
# This file tests malloc failures in concert with fuzzy SQL generation.
|
sl@0
|
14 |
#
|
sl@0
|
15 |
# $Id: fuzz_malloc.test,v 1.10 2008/08/20 16:35:10 drh Exp $
|
sl@0
|
16 |
|
sl@0
|
17 |
set testdir [file dirname $argv0]
|
sl@0
|
18 |
source $testdir/tester.tcl
|
sl@0
|
19 |
|
sl@0
|
20 |
ifcapable !memdebug {
|
sl@0
|
21 |
finish_test
|
sl@0
|
22 |
return
|
sl@0
|
23 |
}
|
sl@0
|
24 |
|
sl@0
|
25 |
source $testdir/malloc_common.tcl
|
sl@0
|
26 |
source $testdir/fuzz_common.tcl
|
sl@0
|
27 |
|
sl@0
|
28 |
if {[info exists ISQUICK]} {
|
sl@0
|
29 |
set ::REPEATS 20
|
sl@0
|
30 |
} elseif {[info exists SOAKTEST]} {
|
sl@0
|
31 |
set ::REPEATS 100
|
sl@0
|
32 |
} else {
|
sl@0
|
33 |
set ::REPEATS 40
|
sl@0
|
34 |
}
|
sl@0
|
35 |
|
sl@0
|
36 |
#
|
sl@0
|
37 |
# Usage: do_fuzzy_malloc_test <testname> ?<options>?
|
sl@0
|
38 |
#
|
sl@0
|
39 |
# -template
|
sl@0
|
40 |
# -sqlprep
|
sl@0
|
41 |
# -repeats
|
sl@0
|
42 |
#
|
sl@0
|
43 |
proc do_fuzzy_malloc_test {testname args} {
|
sl@0
|
44 |
set ::fuzzyopts(-repeats) $::REPEATS
|
sl@0
|
45 |
set ::fuzzyopts(-sqlprep) {}
|
sl@0
|
46 |
array set ::fuzzyopts $args
|
sl@0
|
47 |
|
sl@0
|
48 |
sqlite3_memdebug_fail -1
|
sl@0
|
49 |
db close
|
sl@0
|
50 |
file delete test.db test.db-journal
|
sl@0
|
51 |
sqlite3 db test.db
|
sl@0
|
52 |
set ::prep $::fuzzyopts(-sqlprep)
|
sl@0
|
53 |
execsql $::prep
|
sl@0
|
54 |
set jj 0
|
sl@0
|
55 |
for {set ii 0} {$ii < $::fuzzyopts(-repeats)} {incr ii} {
|
sl@0
|
56 |
expr srand($jj)
|
sl@0
|
57 |
incr jj
|
sl@0
|
58 |
set ::sql [subst $::fuzzyopts(-template)]
|
sl@0
|
59 |
# puts fuzyy-sql=\[$::sql\]; flush stdout
|
sl@0
|
60 |
foreach {rc res} [catchsql "$::sql"] {}
|
sl@0
|
61 |
if {$rc==0} {
|
sl@0
|
62 |
do_malloc_test $testname-$ii -sqlbody $::sql -sqlprep $::prep
|
sl@0
|
63 |
} else {
|
sl@0
|
64 |
incr ii -1
|
sl@0
|
65 |
}
|
sl@0
|
66 |
}
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
#----------------------------------------------------------------
|
sl@0
|
70 |
# Test malloc failure during parsing (and execution) of a fuzzily
|
sl@0
|
71 |
# generated expressions.
|
sl@0
|
72 |
#
|
sl@0
|
73 |
do_fuzzy_malloc_test fuzzy_malloc-1 -template {Select [Expr]}
|
sl@0
|
74 |
do_fuzzy_malloc_test fuzzy_malloc-2 -template {[Select]}
|
sl@0
|
75 |
|
sl@0
|
76 |
set ::SQLPREP {
|
sl@0
|
77 |
BEGIN;
|
sl@0
|
78 |
CREATE TABLE abc(a, b, c);
|
sl@0
|
79 |
CREATE TABLE def(a, b, c);
|
sl@0
|
80 |
CREATE TABLE ghi(a, b, c);
|
sl@0
|
81 |
INSERT INTO abc VALUES(1.5, 3, 'a short string');
|
sl@0
|
82 |
INSERT INTO def VALUES(NULL, X'ABCDEF',
|
sl@0
|
83 |
'a longer string. Long enough that it doesn''t fit in Mem.zShort');
|
sl@0
|
84 |
INSERT INTO ghi VALUES(zeroblob(1000), 'hello world', -1257900987654321);
|
sl@0
|
85 |
COMMIT;
|
sl@0
|
86 |
}
|
sl@0
|
87 |
set ::TableList [list abc def ghi]
|
sl@0
|
88 |
set ::ColumnList [list a b c]
|
sl@0
|
89 |
|
sl@0
|
90 |
do_fuzzy_malloc_test fuzzy_malloc-3 \
|
sl@0
|
91 |
-template {[Select]} \
|
sl@0
|
92 |
-sqlprep $::SQLPREP
|
sl@0
|
93 |
|
sl@0
|
94 |
finish_test
|