2007-08-13 16:39:03 +04:00
|
|
|
# 2007 Aug 13
|
|
|
|
#
|
|
|
|
# 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 aspects of the malloc failure while parsing
|
|
|
|
# CREATE TABLE statements in auto_vacuum mode.
|
|
|
|
#
|
2009-04-11 20:27:49 +04:00
|
|
|
# $Id: mallocC.test,v 1.10 2009/04/11 16:27:50 drh Exp $
|
2007-08-13 16:39:03 +04:00
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
2008-02-19 01:24:57 +03:00
|
|
|
source $testdir/malloc_common.tcl
|
2007-08-13 16:39:03 +04:00
|
|
|
|
|
|
|
# Only run these tests if memory debugging is turned on.
|
|
|
|
#
|
2008-02-19 01:24:57 +03:00
|
|
|
if {!$MEMDEBUG} {
|
2007-09-03 20:12:09 +04:00
|
|
|
puts "Skipping mallocC tests: not compiled with -DSQLITE_MEMDEBUG..."
|
2007-08-23 02:04:37 +04:00
|
|
|
finish_test
|
|
|
|
return
|
2007-08-13 16:39:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
proc do_mallocC_test {tn args} {
|
|
|
|
array set ::mallocopts $args
|
2008-01-16 20:46:38 +03:00
|
|
|
#set sum [allcksum db]
|
2007-08-13 16:39:03 +04:00
|
|
|
|
|
|
|
for {set ::n 1} {true} {incr ::n} {
|
|
|
|
|
|
|
|
# Run the SQL. Malloc number $::n is set to fail. A malloc() failure
|
|
|
|
# may or may not be reported.
|
2007-08-29 16:31:25 +04:00
|
|
|
sqlite3_memdebug_fail $::n -repeat 1
|
2007-08-13 16:58:18 +04:00
|
|
|
do_test mallocC-$tn.$::n.1 {
|
2007-08-13 16:39:03 +04:00
|
|
|
set res [catchsql [string trim $::mallocopts(-sql)]]
|
|
|
|
set rc [expr {
|
|
|
|
0==[string compare $res {1 {out of memory}}] ||
|
2007-10-03 12:46:44 +04:00
|
|
|
[db errorcode] == 3082 ||
|
2007-08-13 16:39:03 +04:00
|
|
|
0==[lindex $res 0]
|
|
|
|
}]
|
|
|
|
if {$rc!=1} {
|
|
|
|
puts "Error: $res"
|
|
|
|
}
|
|
|
|
set rc
|
|
|
|
} {1}
|
|
|
|
|
|
|
|
# If $::n is greater than the number of malloc() calls required to
|
|
|
|
# execute the SQL, then this test is finished. Break out of the loop.
|
2007-08-29 16:31:25 +04:00
|
|
|
set nFail [sqlite3_memdebug_fail -1]
|
2007-08-23 02:04:37 +04:00
|
|
|
if {$nFail==0} {
|
2007-08-13 16:39:03 +04:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
# Recover from the malloc failure.
|
|
|
|
#
|
|
|
|
# Update: The new malloc() failure handling means that a transaction may
|
|
|
|
# still be active even if a malloc() has failed. But when these tests were
|
|
|
|
# written this was not the case. So do a manual ROLLBACK here so that the
|
|
|
|
# tests pass.
|
2007-08-13 16:58:18 +04:00
|
|
|
do_test mallocC-$tn.$::n.2 {
|
2007-08-13 16:39:03 +04:00
|
|
|
catch {
|
|
|
|
execsql {
|
|
|
|
ROLLBACK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
expr 0
|
|
|
|
} {0}
|
|
|
|
|
|
|
|
# Checksum the database.
|
2007-08-13 16:58:18 +04:00
|
|
|
#do_test mallocC-$tn.$::n.3 {
|
2008-01-16 20:46:38 +03:00
|
|
|
# allcksum db
|
2007-08-13 16:39:03 +04:00
|
|
|
#} $sum
|
|
|
|
|
2007-08-13 16:58:18 +04:00
|
|
|
#integrity_check mallocC-$tn.$::n.4
|
2007-08-13 16:39:03 +04:00
|
|
|
if {$::nErr>1} return
|
|
|
|
}
|
|
|
|
unset ::mallocopts
|
|
|
|
}
|
|
|
|
|
2007-10-03 12:46:44 +04:00
|
|
|
sqlite3_extended_result_codes db 1
|
|
|
|
|
2007-08-13 16:39:03 +04:00
|
|
|
execsql {
|
|
|
|
PRAGMA auto_vacuum=1;
|
|
|
|
CREATE TABLE t0(a, b, c);
|
|
|
|
}
|
2009-04-11 20:27:49 +04:00
|
|
|
|
|
|
|
# The number of memory allocation failures is different on 64-bit
|
|
|
|
# and 32-bit systems due to larger structures on 64-bit systems
|
|
|
|
# overflowing the lookaside more often. To debug problems, it is
|
|
|
|
# sometimes helpful to reduce the size of the lookaside allocation
|
|
|
|
# blocks. But this is normally disabled.
|
|
|
|
#
|
|
|
|
if {0} {
|
|
|
|
db close
|
|
|
|
sqlite3_shutdown
|
|
|
|
sqlite3_config_lookaside 50 500
|
|
|
|
sqlite3_initialize
|
|
|
|
autoinstall_test_functions
|
|
|
|
sqlite3 db test.db
|
|
|
|
}
|
|
|
|
|
2007-08-13 16:39:03 +04:00
|
|
|
do_mallocC_test 1 -sql {
|
|
|
|
BEGIN;
|
|
|
|
-- Allocate 32 new root pages. This will exercise the 'extract specific
|
|
|
|
-- page from the freelist' code when in auto-vacuum mode (see the
|
|
|
|
-- allocatePage() routine in btree.c).
|
|
|
|
CREATE TABLE t1(a UNIQUE, b UNIQUE, c UNIQUE);
|
|
|
|
CREATE TABLE t2(a UNIQUE, b UNIQUE, c UNIQUE);
|
|
|
|
CREATE TABLE t3(a UNIQUE, b UNIQUE, c UNIQUE);
|
|
|
|
CREATE TABLE t4(a UNIQUE, b UNIQUE, c UNIQUE);
|
|
|
|
CREATE TABLE t5(a UNIQUE, b UNIQUE, c UNIQUE);
|
|
|
|
CREATE TABLE t6(a UNIQUE, b UNIQUE, c UNIQUE);
|
|
|
|
CREATE TABLE t7(a UNIQUE, b UNIQUE, c UNIQUE);
|
|
|
|
CREATE TABLE t8(a UNIQUE, b UNIQUE, c UNIQUE);
|
|
|
|
|
|
|
|
ROLLBACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
finish_test
|