1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/mallocC.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,107 @@
1.4 +# 2007 Aug 13
1.5 +#
1.6 +# The author disclaims copyright to this source code. In place of
1.7 +# a legal notice, here is a blessing:
1.8 +#
1.9 +# May you do good and not evil.
1.10 +# May you find forgiveness for yourself and forgive others.
1.11 +# May you share freely, never taking more than you give.
1.12 +#
1.13 +#***********************************************************************
1.14 +#
1.15 +# This file tests aspects of the malloc failure while parsing
1.16 +# CREATE TABLE statements in auto_vacuum mode.
1.17 +#
1.18 +# $Id: mallocC.test,v 1.9 2008/02/18 22:24:58 drh Exp $
1.19 +
1.20 +set testdir [file dirname $argv0]
1.21 +source $testdir/tester.tcl
1.22 +source $testdir/malloc_common.tcl
1.23 +
1.24 +# Only run these tests if memory debugging is turned on.
1.25 +#
1.26 +if {!$MEMDEBUG} {
1.27 + puts "Skipping mallocC tests: not compiled with -DSQLITE_MEMDEBUG..."
1.28 + finish_test
1.29 + return
1.30 +}
1.31 +
1.32 +proc do_mallocC_test {tn args} {
1.33 + array set ::mallocopts $args
1.34 + #set sum [allcksum db]
1.35 +
1.36 + for {set ::n 1} {true} {incr ::n} {
1.37 +
1.38 + # Run the SQL. Malloc number $::n is set to fail. A malloc() failure
1.39 + # may or may not be reported.
1.40 + sqlite3_memdebug_fail $::n -repeat 1
1.41 + do_test mallocC-$tn.$::n.1 {
1.42 + set res [catchsql [string trim $::mallocopts(-sql)]]
1.43 + set rc [expr {
1.44 + 0==[string compare $res {1 {out of memory}}] ||
1.45 + [db errorcode] == 3082 ||
1.46 + 0==[lindex $res 0]
1.47 + }]
1.48 + if {$rc!=1} {
1.49 + puts "Error: $res"
1.50 + }
1.51 + set rc
1.52 + } {1}
1.53 +
1.54 + # If $::n is greater than the number of malloc() calls required to
1.55 + # execute the SQL, then this test is finished. Break out of the loop.
1.56 + set nFail [sqlite3_memdebug_fail -1]
1.57 + if {$nFail==0} {
1.58 + break
1.59 + }
1.60 +
1.61 + # Recover from the malloc failure.
1.62 + #
1.63 + # Update: The new malloc() failure handling means that a transaction may
1.64 + # still be active even if a malloc() has failed. But when these tests were
1.65 + # written this was not the case. So do a manual ROLLBACK here so that the
1.66 + # tests pass.
1.67 + do_test mallocC-$tn.$::n.2 {
1.68 + catch {
1.69 + execsql {
1.70 + ROLLBACK;
1.71 + }
1.72 + }
1.73 + expr 0
1.74 + } {0}
1.75 +
1.76 + # Checksum the database.
1.77 + #do_test mallocC-$tn.$::n.3 {
1.78 + # allcksum db
1.79 + #} $sum
1.80 +
1.81 + #integrity_check mallocC-$tn.$::n.4
1.82 + if {$::nErr>1} return
1.83 + }
1.84 + unset ::mallocopts
1.85 +}
1.86 +
1.87 +sqlite3_extended_result_codes db 1
1.88 +
1.89 +execsql {
1.90 + PRAGMA auto_vacuum=1;
1.91 + CREATE TABLE t0(a, b, c);
1.92 +}
1.93 +do_mallocC_test 1 -sql {
1.94 + BEGIN;
1.95 + -- Allocate 32 new root pages. This will exercise the 'extract specific
1.96 + -- page from the freelist' code when in auto-vacuum mode (see the
1.97 + -- allocatePage() routine in btree.c).
1.98 + CREATE TABLE t1(a UNIQUE, b UNIQUE, c UNIQUE);
1.99 + CREATE TABLE t2(a UNIQUE, b UNIQUE, c UNIQUE);
1.100 + CREATE TABLE t3(a UNIQUE, b UNIQUE, c UNIQUE);
1.101 + CREATE TABLE t4(a UNIQUE, b UNIQUE, c UNIQUE);
1.102 + CREATE TABLE t5(a UNIQUE, b UNIQUE, c UNIQUE);
1.103 + CREATE TABLE t6(a UNIQUE, b UNIQUE, c UNIQUE);
1.104 + CREATE TABLE t7(a UNIQUE, b UNIQUE, c UNIQUE);
1.105 + CREATE TABLE t8(a UNIQUE, b UNIQUE, c UNIQUE);
1.106 +
1.107 + ROLLBACK;
1.108 +}
1.109 +
1.110 +finish_test