os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/fuzz_malloc.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/fuzz_malloc.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,94 @@
     1.4 +#
     1.5 +# 2007 May 10
     1.6 +#
     1.7 +# The author disclaims copyright to this source code.  In place of
     1.8 +# a legal notice, here is a blessing:
     1.9 +#
    1.10 +#    May you do good and not evil.
    1.11 +#    May you find forgiveness for yourself and forgive others.
    1.12 +#    May you share freely, never taking more than you give.
    1.13 +#
    1.14 +#***********************************************************************
    1.15 +#
    1.16 +# This file tests malloc failures in concert with fuzzy SQL generation.
    1.17 +#
    1.18 +# $Id: fuzz_malloc.test,v 1.10 2008/08/20 16:35:10 drh Exp $
    1.19 +
    1.20 +set testdir [file dirname $argv0]
    1.21 +source $testdir/tester.tcl
    1.22 +
    1.23 +ifcapable !memdebug {
    1.24 +  finish_test
    1.25 +  return
    1.26 +}
    1.27 +
    1.28 +source $testdir/malloc_common.tcl
    1.29 +source $testdir/fuzz_common.tcl
    1.30 +
    1.31 +if {[info exists ISQUICK]} {
    1.32 +  set ::REPEATS 20
    1.33 +} elseif {[info exists SOAKTEST]} {
    1.34 +  set ::REPEATS 100
    1.35 +} else {
    1.36 +  set ::REPEATS 40
    1.37 +}
    1.38 +
    1.39 +#
    1.40 +# Usage: do_fuzzy_malloc_test <testname> ?<options>?
    1.41 +# 
    1.42 +#     -template
    1.43 +#     -sqlprep
    1.44 +#     -repeats
    1.45 +#     
    1.46 +proc do_fuzzy_malloc_test {testname args} {
    1.47 +  set ::fuzzyopts(-repeats) $::REPEATS
    1.48 +  set ::fuzzyopts(-sqlprep) {}
    1.49 +  array set ::fuzzyopts $args
    1.50 +
    1.51 +  sqlite3_memdebug_fail -1
    1.52 +  db close
    1.53 +  file delete test.db test.db-journal
    1.54 +  sqlite3 db test.db
    1.55 +  set ::prep $::fuzzyopts(-sqlprep)
    1.56 +  execsql $::prep
    1.57 +  set jj 0
    1.58 +  for {set ii 0} {$ii < $::fuzzyopts(-repeats)} {incr ii} {
    1.59 +    expr srand($jj)
    1.60 +    incr jj
    1.61 +    set ::sql [subst $::fuzzyopts(-template)]
    1.62 +    # puts fuzyy-sql=\[$::sql\]; flush stdout
    1.63 +    foreach {rc res} [catchsql "$::sql"] {}
    1.64 +    if {$rc==0} {
    1.65 +      do_malloc_test $testname-$ii -sqlbody $::sql -sqlprep $::prep
    1.66 +    } else {
    1.67 +      incr ii -1
    1.68 +    }
    1.69 +  }
    1.70 +}
    1.71 +
    1.72 +#----------------------------------------------------------------
    1.73 +# Test malloc failure during parsing (and execution) of a fuzzily 
    1.74 +# generated expressions.
    1.75 +#
    1.76 +do_fuzzy_malloc_test fuzzy_malloc-1 -template {Select [Expr]}
    1.77 +do_fuzzy_malloc_test fuzzy_malloc-2 -template {[Select]}
    1.78 +
    1.79 +set ::SQLPREP {
    1.80 +  BEGIN;
    1.81 +    CREATE TABLE abc(a, b, c);
    1.82 +    CREATE TABLE def(a, b, c);
    1.83 +    CREATE TABLE ghi(a, b, c);
    1.84 +    INSERT INTO abc VALUES(1.5, 3, 'a short string');
    1.85 +    INSERT INTO def VALUES(NULL, X'ABCDEF', 
    1.86 +        'a longer string. Long enough that it doesn''t fit in Mem.zShort');
    1.87 +    INSERT INTO ghi VALUES(zeroblob(1000), 'hello world', -1257900987654321);
    1.88 +  COMMIT;
    1.89 +}
    1.90 +set ::TableList  [list abc def ghi]
    1.91 +set ::ColumnList [list a b c]
    1.92 +
    1.93 +do_fuzzy_malloc_test fuzzy_malloc-3 \
    1.94 +  -template {[Select]}              \
    1.95 +  -sqlprep $::SQLPREP
    1.96 +
    1.97 +finish_test