From e36d23a85ebff914d74bb541558c2b6082b78edb Mon Sep 17 00:00:00 2001 From: dan miller Date: Sat, 20 Oct 2007 02:49:29 +0000 Subject: sqlite source (unix build) added to libraries --- .../sqlite/unix/sqlite-3.5.1/test/fuzz_malloc.test | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 libraries/sqlite/unix/sqlite-3.5.1/test/fuzz_malloc.test (limited to 'libraries/sqlite/unix/sqlite-3.5.1/test/fuzz_malloc.test') diff --git a/libraries/sqlite/unix/sqlite-3.5.1/test/fuzz_malloc.test b/libraries/sqlite/unix/sqlite-3.5.1/test/fuzz_malloc.test new file mode 100644 index 0000000..2d78807 --- /dev/null +++ b/libraries/sqlite/unix/sqlite-3.5.1/test/fuzz_malloc.test @@ -0,0 +1,93 @@ +# +# 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. +# +# $Id: fuzz_malloc.test,v 1.9 2007/09/03 15:42:48 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !memdebug { + finish_test + return +} + +source $testdir/malloc_common.tcl +source $testdir/fuzz_common.tcl + +if {[info exists ISQUICK]} { + set ::REPEATS 20 +} elseif {[info exists SOAKTEST]} { + set ::REPEATS 100 +} else { + set ::REPEATS 40 +} + +# +# Usage: do_fuzzy_malloc_test ?? +# +# -template +# -sqlprep +# -repeats +# +proc do_fuzzy_malloc_test {testname args} { + set ::fuzzyopts(-repeats) $::REPEATS + set ::fuzzyopts(-sqlprep) {} + array set ::fuzzyopts $args + + sqlite3_memdebug_fail -1 + db close + file delete test.db test.db-journal + sqlite3 db test.db + set ::prep $::fuzzyopts(-sqlprep) + execsql $::prep + set jj 0 + for {set ii 0} {$ii < $::fuzzyopts(-repeats)} {incr ii} { + expr srand($jj) + incr jj + set ::sql [subst $::fuzzyopts(-template)] + foreach {rc res} [catchsql "$::sql"] {} + if {$rc==0} { + do_malloc_test $testname-$ii -sqlbody $::sql -sqlprep $::prep + } 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]} +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 + +finish_test -- cgit v1.1