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 | 7751940 | 2007-08-30 11:48:31 +0000 | [diff] [blame^] | 15 | # $Id: fuzz_malloc.test,v 1.8 2007/08/30 11:48:32 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 |
drh | 9142a83 | 2007-06-15 13:57:19 +0000 | [diff] [blame] | 19 | |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 20 | source $testdir/malloc_common.tcl |
danielk1977 | 222a757 | 2007-08-25 13:37:48 +0000 | [diff] [blame] | 21 | source $testdir/fuzz_common.tcl |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 22 | |
drh | 44548ec | 2007-06-18 12:22:43 +0000 | [diff] [blame] | 23 | if {[info exists ISQUICK]} { |
| 24 | set ::REPEATS 20 |
| 25 | } elseif {[info exists SOAKTEST]} { |
| 26 | set ::REPEATS 100 |
| 27 | } else { |
| 28 | set ::REPEATS 40 |
| 29 | } |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 30 | |
| 31 | # |
| 32 | # Usage: do_fuzzy_malloc_test <testname> ?<options>? |
| 33 | # |
| 34 | # -template |
danielk1977 | 9afe689 | 2007-05-31 08:20:43 +0000 | [diff] [blame] | 35 | # -sqlprep |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 36 | # -repeats |
| 37 | # |
| 38 | proc do_fuzzy_malloc_test {testname args} { |
| 39 | set ::fuzzyopts(-repeats) $::REPEATS |
danielk1977 | 9afe689 | 2007-05-31 08:20:43 +0000 | [diff] [blame] | 40 | set ::fuzzyopts(-sqlprep) {} |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 41 | array set ::fuzzyopts $args |
| 42 | |
danielk1977 | 7751940 | 2007-08-30 11:48:31 +0000 | [diff] [blame^] | 43 | sqlite3_memdebug_fail -1 |
danielk1977 | 9afe689 | 2007-05-31 08:20:43 +0000 | [diff] [blame] | 44 | db close |
| 45 | file delete test.db test.db-journal |
| 46 | sqlite3 db test.db |
| 47 | set ::prep $::fuzzyopts(-sqlprep) |
| 48 | execsql $::prep |
drh | 43b7882 | 2007-06-15 17:03:14 +0000 | [diff] [blame] | 49 | set jj 0 |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 50 | for {set ii 0} {$ii < $::fuzzyopts(-repeats)} {incr ii} { |
drh | 43b7882 | 2007-06-15 17:03:14 +0000 | [diff] [blame] | 51 | expr srand($jj) |
| 52 | incr jj |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 53 | set ::sql [subst $::fuzzyopts(-template)] |
danielk1977 | 9afe689 | 2007-05-31 08:20:43 +0000 | [diff] [blame] | 54 | foreach {rc res} [catchsql "$::sql"] {} |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 55 | if {$rc==0} { |
danielk1977 | 9afe689 | 2007-05-31 08:20:43 +0000 | [diff] [blame] | 56 | do_malloc_test $testname-$ii -sqlbody $::sql -sqlprep $::prep |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 57 | } else { |
| 58 | incr ii -1 |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | #---------------------------------------------------------------- |
| 64 | # Test malloc failure during parsing (and execution) of a fuzzily |
| 65 | # generated expressions. |
| 66 | # |
| 67 | do_fuzzy_malloc_test fuzzy_malloc-1 -template {Select [Expr]} |
danielk1977 | 9afe689 | 2007-05-31 08:20:43 +0000 | [diff] [blame] | 68 | do_fuzzy_malloc_test fuzzy_malloc-2 -template {[Select]} |
| 69 | |
| 70 | set ::SQLPREP { |
| 71 | BEGIN; |
| 72 | CREATE TABLE abc(a, b, c); |
| 73 | CREATE TABLE def(a, b, c); |
| 74 | CREATE TABLE ghi(a, b, c); |
| 75 | INSERT INTO abc VALUES(1.5, 3, 'a short string'); |
| 76 | INSERT INTO def VALUES(NULL, X'ABCDEF', |
| 77 | 'a longer string. Long enough that it doesn''t fit in Mem.zShort'); |
| 78 | INSERT INTO ghi VALUES(zeroblob(1000), 'hello world', -1257900987654321); |
| 79 | COMMIT; |
| 80 | } |
| 81 | set ::TableList [list abc def ghi] |
| 82 | set ::ColumnList [list a b c] |
| 83 | |
| 84 | do_fuzzy_malloc_test fuzzy_malloc-3 \ |
| 85 | -template {[Select]} \ |
| 86 | -sqlprep $::SQLPREP |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 87 | |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 88 | finish_test |