mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Update the rest of the malloc failure test scripts to use the new interface. (CVS 4296)
FossilOrigin-Name: b076e1655d6bae5ae10e6ceee646f502435da66a
This commit is contained in:
@ -12,98 +12,13 @@
|
||||
# focus of this script is testing the ATTACH statement and
|
||||
# specifically out-of-memory conditions within that command.
|
||||
#
|
||||
# $Id: attachmalloc.test,v 1.3 2006/09/04 18:54:14 drh Exp $
|
||||
# $Id: attachmalloc.test,v 1.4 2007/08/25 13:37:49 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Only run these tests if memory debugging is turned on.
|
||||
#
|
||||
if {[info command sqlite_malloc_stat]==""} {
|
||||
puts "Skipping malloc tests: not compiled with -DSQLITE_MEMDEBUG=1"
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
# Usage: do_malloc_test <test name> <options...>
|
||||
#
|
||||
# The first argument, <test number>, is an integer used to name the
|
||||
# tests executed by this proc. Options are as follows:
|
||||
#
|
||||
# -tclprep TCL script to run to prepare test.
|
||||
# -sqlprep SQL script to run to prepare test.
|
||||
# -tclbody TCL script to run with malloc failure simulation.
|
||||
# -sqlbody TCL script to run with malloc failure simulation.
|
||||
# -cleanup TCL script to run after the test.
|
||||
#
|
||||
# This command runs a series of tests to verify SQLite's ability
|
||||
# to handle an out-of-memory condition gracefully. It is assumed
|
||||
# that if this condition occurs a malloc() call will return a
|
||||
# NULL pointer. Linux, for example, doesn't do that by default. See
|
||||
# the "BUGS" section of malloc(3).
|
||||
#
|
||||
# Each iteration of a loop, the TCL commands in any argument passed
|
||||
# to the -tclbody switch, followed by the SQL commands in any argument
|
||||
# passed to the -sqlbody switch are executed. Each iteration the
|
||||
# Nth call to sqliteMalloc() is made to fail, where N is increased
|
||||
# each time the loop runs starting from 1. When all commands execute
|
||||
# successfully, the loop ends.
|
||||
#
|
||||
proc do_malloc_test {tn args} {
|
||||
array set ::mallocopts $args
|
||||
|
||||
set ::go 1
|
||||
for {set ::n 1} {$::go} {incr ::n} {
|
||||
|
||||
do_test $tn.$::n {
|
||||
|
||||
sqlite_malloc_fail 0
|
||||
catch {db close}
|
||||
catch {file delete -force test.db}
|
||||
catch {file delete -force test.db-journal}
|
||||
catch {file delete -force test2.db}
|
||||
catch {file delete -force test2.db-journal}
|
||||
set ::DB [sqlite3 db test.db]
|
||||
|
||||
if {[info exists ::mallocopts(-tclprep)]} {
|
||||
eval $::mallocopts(-tclprep)
|
||||
}
|
||||
if {[info exists ::mallocopts(-sqlprep)]} {
|
||||
execsql $::mallocopts(-sqlprep)
|
||||
}
|
||||
|
||||
sqlite_malloc_fail $::n
|
||||
set ::mallocbody {}
|
||||
if {[info exists ::mallocopts(-tclbody)]} {
|
||||
append ::mallocbody "$::mallocopts(-tclbody)\n"
|
||||
}
|
||||
if {[info exists ::mallocopts(-sqlbody)]} {
|
||||
append ::mallocbody "db eval {$::mallocopts(-sqlbody)}"
|
||||
}
|
||||
|
||||
set v [catch $::mallocbody msg]
|
||||
|
||||
set leftover [lindex [sqlite_malloc_stat] 2]
|
||||
if {$leftover>0} {
|
||||
if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v Message=$msg"}
|
||||
set ::go 0
|
||||
set v {1 1}
|
||||
} else {
|
||||
set v2 [expr {$msg=="" || $msg=="out of memory"}]
|
||||
if {!$v2} {puts "\nError message returned: $msg"}
|
||||
lappend v $v2
|
||||
}
|
||||
} {1 1}
|
||||
sqlite_malloc_fail 0
|
||||
|
||||
if {[info exists ::mallocopts(-cleanup)]} {
|
||||
catch $::mallocopts(-cleanup)
|
||||
}
|
||||
}
|
||||
unset ::mallocopts
|
||||
}
|
||||
source $testdir/malloc_common.tcl
|
||||
|
||||
do_malloc_test attachmalloc-1 -tclprep {
|
||||
db close
|
||||
|
@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script testing the callback-free C/C++ API.
|
||||
#
|
||||
# $Id: capi3.test,v 1.52 2007/08/22 02:56:44 drh Exp $
|
||||
# $Id: capi3.test,v 1.53 2007/08/25 13:37:49 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@ -750,26 +750,25 @@ foreach {code english} $code2english {
|
||||
}
|
||||
|
||||
# Test the error message when a "real" out of memory occurs.
|
||||
if {[info command sqlite_malloc_stat]!=""} {
|
||||
set sqlite_malloc_fail 1
|
||||
do_test capi3-10-1 {
|
||||
sqlite3 db test.db
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
sqlite_malloc_fail 1
|
||||
catchsql {
|
||||
select * from sqlite_master;
|
||||
}
|
||||
} {1 {out of memory}}
|
||||
do_test capi3-10-2 {
|
||||
sqlite3_errmsg $::DB
|
||||
} {out of memory}
|
||||
ifcapable {utf16} {
|
||||
do_test capi3-10-3 {
|
||||
utf8 [sqlite3_errmsg16 $::DB]
|
||||
if {[info command sqlite3_memdebug_fail]!=""} {
|
||||
do_test capi3-10-1 {
|
||||
sqlite3 db test.db
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
sqlite3_memdebug_fail 0 0
|
||||
catchsql {
|
||||
select * from sqlite_master;
|
||||
}
|
||||
} {1 {out of memory}}
|
||||
do_test capi3-10-2 {
|
||||
sqlite3_errmsg $::DB
|
||||
} {out of memory}
|
||||
}
|
||||
db close
|
||||
sqlite_malloc_fail 0
|
||||
ifcapable {utf16} {
|
||||
do_test capi3-10-3 {
|
||||
utf8 [sqlite3_errmsg16 $::DB]
|
||||
} {out of memory}
|
||||
}
|
||||
db close
|
||||
sqlite3_memdebug_fail -1 0
|
||||
}
|
||||
|
||||
# The following tests - capi3-11.* - test that a COMMIT or ROLLBACK
|
||||
|
@ -13,7 +13,7 @@
|
||||
# This is a copy of the capi3.test file that has been adapted to
|
||||
# test the new sqlite3_prepare_v2 interface.
|
||||
#
|
||||
# $Id: capi3c.test,v 1.9 2007/07/19 22:30:19 drh Exp $
|
||||
# $Id: capi3c.test,v 1.10 2007/08/25 13:37:49 danielk1977 Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@ -745,26 +745,25 @@ foreach {code english} $code2english {
|
||||
}
|
||||
|
||||
# Test the error message when a "real" out of memory occurs.
|
||||
if {[info command sqlite_malloc_stat]!=""} {
|
||||
set sqlite_malloc_fail 1
|
||||
do_test capi3c-10-1 {
|
||||
sqlite3 db test.db
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
sqlite_malloc_fail 1
|
||||
catchsql {
|
||||
select * from sqlite_master;
|
||||
}
|
||||
} {1 {out of memory}}
|
||||
do_test capi3c-10-2 {
|
||||
sqlite3_errmsg $::DB
|
||||
} {out of memory}
|
||||
ifcapable {utf16} {
|
||||
do_test capi3c-10-3 {
|
||||
utf8 [sqlite3_errmsg16 $::DB]
|
||||
if {[info command sqlite3_memdebug_fail]!=""} {
|
||||
do_test capi3c-10-1 {
|
||||
sqlite3 db test.db
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
sqlite3_memdebug_fail 0 0
|
||||
catchsql {
|
||||
select * from sqlite_master;
|
||||
}
|
||||
} {1 {out of memory}}
|
||||
do_test capi3c-10-2 {
|
||||
sqlite3_errmsg $::DB
|
||||
} {out of memory}
|
||||
}
|
||||
db close
|
||||
sqlite_malloc_fail 0
|
||||
ifcapable {utf16} {
|
||||
do_test capi3c-10-3 {
|
||||
utf8 [sqlite3_errmsg16 $::DB]
|
||||
} {out of memory}
|
||||
}
|
||||
db close
|
||||
sqlite3_memdebug_fail -1 0
|
||||
}
|
||||
|
||||
# The following tests - capi3c-11.* - test that a COMMIT or ROLLBACK
|
||||
|
@ -12,21 +12,13 @@
|
||||
#
|
||||
# This file tests malloc failures in concert with fuzzy SQL generation.
|
||||
#
|
||||
# $Id: fuzz_malloc.test,v 1.5 2007/06/18 12:22:43 drh Exp $
|
||||
# $Id: fuzz_malloc.test,v 1.6 2007/08/25 13:37:49 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Only run these tests if memory debugging is turned on.
|
||||
#
|
||||
if {[info command sqlite_malloc_stat]==""} {
|
||||
puts "Skipping fuzz_malloc tests: not compiled with -DSQLITE_MEMDEBUG=1"
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
source $testdir/fuzz_common.tcl
|
||||
source $testdir/malloc_common.tcl
|
||||
source $testdir/fuzz_common.tcl
|
||||
|
||||
if {[info exists ISQUICK]} {
|
||||
set ::REPEATS 20
|
||||
@ -48,7 +40,7 @@ proc do_fuzzy_malloc_test {testname args} {
|
||||
set ::fuzzyopts(-sqlprep) {}
|
||||
array set ::fuzzyopts $args
|
||||
|
||||
sqlite_malloc_fail 0
|
||||
sqlite3_memdebug_fail -1 0
|
||||
db close
|
||||
file delete test.db test.db-journal
|
||||
sqlite3 db test.db
|
||||
@ -93,5 +85,5 @@ do_fuzzy_malloc_test fuzzy_malloc-3 \
|
||||
-template {[Select]} \
|
||||
-sqlprep $::SQLPREP
|
||||
|
||||
sqlite_malloc_fail 0
|
||||
sqlite3_memdebug_fail -1 0
|
||||
finish_test
|
||||
|
@ -13,115 +13,23 @@
|
||||
# cache context. What happens to connection B if one connection A encounters
|
||||
# an IO-error whilst reading or writing the file-system?
|
||||
#
|
||||
# $Id: shared_err.test,v 1.11 2007/04/06 01:04:40 drh Exp $
|
||||
# $Id: shared_err.test,v 1.12 2007/08/25 13:37:49 danielk1977 Exp $
|
||||
|
||||
proc skip {args} {}
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
source $testdir/malloc_common.tcl
|
||||
db close
|
||||
|
||||
ifcapable !shared_cache||!subquery {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
|
||||
|
||||
# Todo: This is a copy of the [do_malloc_test] proc in malloc.test
|
||||
# It would be better if these were consolidated.
|
||||
|
||||
# Usage: do_malloc_test <test number> <options...>
|
||||
#
|
||||
# The first argument, <test number>, is an integer used to name the
|
||||
# tests executed by this proc. Options are as follows:
|
||||
#
|
||||
# -tclprep TCL script to run to prepare test.
|
||||
# -sqlprep SQL script to run to prepare test.
|
||||
# -tclbody TCL script to run with malloc failure simulation.
|
||||
# -sqlbody TCL script to run with malloc failure simulation.
|
||||
# -cleanup TCL script to run after the test.
|
||||
#
|
||||
# This command runs a series of tests to verify SQLite's ability
|
||||
# to handle an out-of-memory condition gracefully. It is assumed
|
||||
# that if this condition occurs a malloc() call will return a
|
||||
# NULL pointer. Linux, for example, doesn't do that by default. See
|
||||
# the "BUGS" section of malloc(3).
|
||||
#
|
||||
# Each iteration of a loop, the TCL commands in any argument passed
|
||||
# to the -tclbody switch, followed by the SQL commands in any argument
|
||||
# passed to the -sqlbody switch are executed. Each iteration the
|
||||
# Nth call to sqliteMalloc() is made to fail, where N is increased
|
||||
# each time the loop runs starting from 1. When all commands execute
|
||||
# successfully, the loop ends.
|
||||
#
|
||||
proc do_malloc_test {tn args} {
|
||||
array unset ::mallocopts
|
||||
array set ::mallocopts $args
|
||||
|
||||
set ::go 1
|
||||
for {set ::n 1} {$::go && $::n < 50000} {incr ::n} {
|
||||
do_test shared_malloc-$tn.$::n {
|
||||
|
||||
# Remove all traces of database files test.db and test2.db from the files
|
||||
# system. Then open (empty database) "test.db" with the handle [db].
|
||||
#
|
||||
sqlite_malloc_fail 0
|
||||
catch {db close}
|
||||
catch {file delete -force test.db}
|
||||
catch {file delete -force test.db-journal}
|
||||
catch {file delete -force test2.db}
|
||||
catch {file delete -force test2.db-journal}
|
||||
catch {sqlite3 db test.db}
|
||||
set ::DB [sqlite3_connection_pointer db]
|
||||
|
||||
# Execute any -tclprep and -sqlprep scripts.
|
||||
#
|
||||
if {[info exists ::mallocopts(-tclprep)]} {
|
||||
eval $::mallocopts(-tclprep)
|
||||
}
|
||||
if {[info exists ::mallocopts(-sqlprep)]} {
|
||||
execsql $::mallocopts(-sqlprep)
|
||||
}
|
||||
|
||||
# Now set the ${::n}th malloc() to fail and execute the -tclbody and
|
||||
# -sqlbody scripts.
|
||||
#
|
||||
sqlite_malloc_fail $::n
|
||||
set ::mallocbody {}
|
||||
if {[info exists ::mallocopts(-tclbody)]} {
|
||||
append ::mallocbody "$::mallocopts(-tclbody)\n"
|
||||
}
|
||||
if {[info exists ::mallocopts(-sqlbody)]} {
|
||||
append ::mallocbody "db eval {$::mallocopts(-sqlbody)}"
|
||||
}
|
||||
set v [catch $::mallocbody msg]
|
||||
|
||||
set leftover [lindex [sqlite_malloc_stat] 2]
|
||||
if {$leftover>0} {
|
||||
if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v Message=$msg"}
|
||||
set ::go 0
|
||||
if {$v} {
|
||||
puts "\nError message returned: $msg"
|
||||
} else {
|
||||
set v {1 1}
|
||||
}
|
||||
} else {
|
||||
set v2 [expr {$msg=="" || $msg=="out of memory"}]
|
||||
if {!$v2} {puts "\nError message returned: $msg"}
|
||||
lappend v $v2
|
||||
}
|
||||
} {1 1}
|
||||
|
||||
sqlite_malloc_fail 0
|
||||
if {[info exists ::mallocopts(-cleanup)]} {
|
||||
catch [list uplevel #0 $::mallocopts(-cleanup)] msg
|
||||
}
|
||||
}
|
||||
unset ::mallocopts
|
||||
}
|
||||
|
||||
|
||||
do_ioerr_test shared_ioerr-1 -tclprep {
|
||||
sqlite3 db2 test.db
|
||||
execsql {
|
||||
|
@ -9,124 +9,18 @@
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# $Id: vtab_err.test,v 1.5 2007/04/19 11:09:02 danielk1977 Exp $
|
||||
# $Id: vtab_err.test,v 1.6 2007/08/25 13:37:49 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Only run these tests if memory debugging is turned on.
|
||||
#
|
||||
if {[info command sqlite_malloc_stat]==""} {
|
||||
puts "Skipping vtab_err tests: not compiled with -DSQLITE_MEMDEBUG=1"
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
source $testdir/malloc_common.tcl
|
||||
|
||||
ifcapable !vtab {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# Usage: do_malloc_test <test number> <options...>
|
||||
#
|
||||
# The first argument, <test number>, is an integer used to name the
|
||||
# tests executed by this proc. Options are as follows:
|
||||
#
|
||||
# -tclprep TCL script to run to prepare test.
|
||||
# -sqlprep SQL script to run to prepare test.
|
||||
# -tclbody TCL script to run with malloc failure simulation.
|
||||
# -sqlbody TCL script to run with malloc failure simulation.
|
||||
# -cleanup TCL script to run after the test.
|
||||
#
|
||||
# This command runs a series of tests to verify SQLite's ability
|
||||
# to handle an out-of-memory condition gracefully. It is assumed
|
||||
# that if this condition occurs a malloc() call will return a
|
||||
# NULL pointer. Linux, for example, doesn't do that by default. See
|
||||
# the "BUGS" section of malloc(3).
|
||||
#
|
||||
# Each iteration of a loop, the TCL commands in any argument passed
|
||||
# to the -tclbody switch, followed by the SQL commands in any argument
|
||||
# passed to the -sqlbody switch are executed. Each iteration the
|
||||
# Nth call to sqliteMalloc() is made to fail, where N is increased
|
||||
# each time the loop runs starting from 1. When all commands execute
|
||||
# successfully, the loop ends.
|
||||
#
|
||||
proc do_malloc_test {tn args} {
|
||||
array unset ::mallocopts
|
||||
array set ::mallocopts $args
|
||||
|
||||
set ::go 1
|
||||
for {set ::n 1} {$::go && $::n < 50000} {incr ::n} {
|
||||
do_test $tn.$::n {
|
||||
|
||||
# Remove all traces of database files test.db and test2.db from the files
|
||||
# system. Then open (empty database) "test.db" with the handle [db].
|
||||
#
|
||||
sqlite_malloc_fail 0
|
||||
catch {db close}
|
||||
catch {file delete -force test.db}
|
||||
catch {file delete -force test.db-journal}
|
||||
catch {file delete -force test2.db}
|
||||
catch {file delete -force test2.db-journal}
|
||||
catch {sqlite3 db test.db}
|
||||
set ::DB [sqlite3_connection_pointer db]
|
||||
|
||||
# Execute any -tclprep and -sqlprep scripts.
|
||||
#
|
||||
if {[info exists ::mallocopts(-tclprep)]} {
|
||||
eval $::mallocopts(-tclprep)
|
||||
}
|
||||
if {[info exists ::mallocopts(-sqlprep)]} {
|
||||
execsql $::mallocopts(-sqlprep)
|
||||
}
|
||||
|
||||
# Now set the ${::n}th malloc() to fail and execute the -tclbody and
|
||||
# -sqlbody scripts.
|
||||
#
|
||||
sqlite_malloc_fail $::n
|
||||
set ::mallocbody {}
|
||||
if {[info exists ::mallocopts(-tclbody)]} {
|
||||
append ::mallocbody "$::mallocopts(-tclbody)\n"
|
||||
}
|
||||
if {[info exists ::mallocopts(-sqlbody)]} {
|
||||
append ::mallocbody "db eval {$::mallocopts(-sqlbody)}"
|
||||
}
|
||||
set v [catch $::mallocbody msg]
|
||||
|
||||
# If the test fails (if $v!=0) and the database connection actually
|
||||
# exists, make sure the failure code is SQLITE_NOMEM.
|
||||
if {$v&&[info command db]=="db"&&[info exists ::mallocopts(-sqlbody)]} {
|
||||
if {[db errorcode]!=7 && $msg!="vtable constructor failed: e"} {
|
||||
set v 999
|
||||
}
|
||||
}
|
||||
|
||||
set leftover [lindex [sqlite_malloc_stat] 2]
|
||||
if {$leftover>0} {
|
||||
if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v Message=$msg"}
|
||||
set ::go 0
|
||||
if {$v} {
|
||||
puts "\nError message returned: $msg"
|
||||
} else {
|
||||
set v {1 1}
|
||||
}
|
||||
} else {
|
||||
set v2 [expr {
|
||||
$msg == "" || $msg == "out of memory" ||
|
||||
$msg == "vtable constructor failed: e"
|
||||
}]
|
||||
if {!$v2} {puts "\nError message returned: $msg"}
|
||||
lappend v $v2
|
||||
}
|
||||
} {1 1}
|
||||
|
||||
if {[info exists ::mallocopts(-cleanup)]} {
|
||||
catch [list uplevel #0 $::mallocopts(-cleanup)] msg
|
||||
}
|
||||
}
|
||||
unset ::mallocopts
|
||||
}
|
||||
|
||||
unset -nocomplain echo_module_begin_fail
|
||||
do_ioerr_test vtab_err-1 -tclprep {
|
||||
register_echo_module [sqlite3_connection_pointer db]
|
||||
@ -164,5 +58,6 @@ do_malloc_test vtab_err-2 -tclprep {
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
sqlite_malloc_fail 0
|
||||
sqlite3_memdebug_fail -1 0
|
||||
|
||||
finish_test
|
||||
|
Reference in New Issue
Block a user