danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 1 | # |
| 2 | # 2007 May 10 |
| 3 | # |
| 4 | # The author disclaims copyright to this source code. In place of |
| 5 | # a legal notice, here is a blessing: |
| 6 | # |
| 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. |
| 10 | # |
| 11 | #*********************************************************************** |
| 12 | # |
| 13 | # This file tests malloc failures in concert with fuzzy SQL generation. |
| 14 | # |
danielk1977 | 9afe689 | 2007-05-31 08:20:43 +0000 | [diff] [blame^] | 15 | # $Id: fuzz_malloc.test,v 1.2 2007/05/31 08:20:44 danielk1977 Exp $ |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 16 | |
| 17 | set testdir [file dirname $argv0] |
| 18 | source $testdir/tester.tcl |
| 19 | source $testdir/fuzz_common.tcl |
| 20 | source $testdir/malloc_common.tcl |
| 21 | |
| 22 | set ::REPEATS 20 |
| 23 | |
| 24 | # |
| 25 | # Usage: do_fuzzy_malloc_test <testname> ?<options>? |
| 26 | # |
| 27 | # -template |
danielk1977 | 9afe689 | 2007-05-31 08:20:43 +0000 | [diff] [blame^] | 28 | # -sqlprep |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 29 | # -repeats |
| 30 | # |
| 31 | proc do_fuzzy_malloc_test {testname args} { |
| 32 | set ::fuzzyopts(-repeats) $::REPEATS |
danielk1977 | 9afe689 | 2007-05-31 08:20:43 +0000 | [diff] [blame^] | 33 | set ::fuzzyopts(-sqlprep) {} |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 34 | array set ::fuzzyopts $args |
| 35 | |
danielk1977 | 9afe689 | 2007-05-31 08:20:43 +0000 | [diff] [blame^] | 36 | sqlite_malloc_fail 0 |
| 37 | db close |
| 38 | file delete test.db test.db-journal |
| 39 | sqlite3 db test.db |
| 40 | set ::prep $::fuzzyopts(-sqlprep) |
| 41 | execsql $::prep |
| 42 | |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 43 | for {set ii 0} {$ii < $::fuzzyopts(-repeats)} {incr ii} { |
| 44 | set ::sql [subst $::fuzzyopts(-template)] |
danielk1977 | 9afe689 | 2007-05-31 08:20:43 +0000 | [diff] [blame^] | 45 | foreach {rc res} [catchsql "$::sql"] {} |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 46 | if {$rc==0} { |
danielk1977 | 9afe689 | 2007-05-31 08:20:43 +0000 | [diff] [blame^] | 47 | do_malloc_test $testname-$ii -sqlbody $::sql -sqlprep $::prep |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 48 | } else { |
| 49 | incr ii -1 |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | #---------------------------------------------------------------- |
| 55 | # Test malloc failure during parsing (and execution) of a fuzzily |
| 56 | # generated expressions. |
| 57 | # |
| 58 | do_fuzzy_malloc_test fuzzy_malloc-1 -template {Select [Expr]} |
danielk1977 | 9afe689 | 2007-05-31 08:20:43 +0000 | [diff] [blame^] | 59 | do_fuzzy_malloc_test fuzzy_malloc-2 -template {[Select]} |
| 60 | |
| 61 | set ::SQLPREP { |
| 62 | BEGIN; |
| 63 | CREATE TABLE abc(a, b, c); |
| 64 | CREATE TABLE def(a, b, c); |
| 65 | CREATE TABLE ghi(a, b, c); |
| 66 | INSERT INTO abc VALUES(1.5, 3, 'a short string'); |
| 67 | INSERT INTO def VALUES(NULL, X'ABCDEF', |
| 68 | 'a longer string. Long enough that it doesn''t fit in Mem.zShort'); |
| 69 | INSERT INTO ghi VALUES(zeroblob(1000), 'hello world', -1257900987654321); |
| 70 | COMMIT; |
| 71 | } |
| 72 | set ::TableList [list abc def ghi] |
| 73 | set ::ColumnList [list a b c] |
| 74 | |
| 75 | do_fuzzy_malloc_test fuzzy_malloc-3 \ |
| 76 | -template {[Select]} \ |
| 77 | -sqlprep $::SQLPREP |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 78 | |
| 79 | sqlite_malloc_fail 0 |
| 80 | finish_test |
danielk1977 | 9afe689 | 2007-05-31 08:20:43 +0000 | [diff] [blame^] | 81 | |