diff --git a/manifest b/manifest index 2fa718ed9b..1408c67ea4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sbugs\sin\sthe\saltermalloc.test\sand\sincrblob_err.test\sscripts.\s(CVS\s4295) -D 2007-08-25T13:09:26 +C Update\sthe\srest\sof\sthe\smalloc\sfailure\stest\sscripts\sto\suse\sthe\snew\sinterface.\s(CVS\s4296) +D 2007-08-25T13:37:49 F Makefile.in 938f2769921fa1b30c633548f153804021eb1512 F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -138,7 +138,7 @@ F src/test4.c c2c0f5dc907f1346f5d4b65eb5799f11eb9e4071 F src/test5.c 3a6a5717a149d7ca2e6d14f5be72cf7555d54dc4 F src/test6.c a6223d9d938aba83f20611a2c01680d8043cd2f7 F src/test7.c a9d509d0e9ad214b4772696f49f6e61be26213d1 -F src/test8.c e6a543c8b248efe120ae33a6859fcd55dcf46a96 +F src/test8.c a91b8d28341bbd168f5ba1ecad2be1008ddf15d1 F src/test9.c b46c8fe02ac7cca1a7316436d8d38d50c66f4b2f F src/test_async.c 12ff3db0e052f561596d4dbdd29272f28b25060d F src/test_autoext.c 855157d97aa28cf84233847548bfacda21807436 @@ -180,7 +180,7 @@ F test/async2.test 8f2c70b831dac7292450d0a42580cf2dab497dbb F test/attach.test cf289abdb120053136649efd1306ab9d47fa41b2 F test/attach2.test 78bc1a25ea8785c7571b44f5947ada2bd5d78127 F test/attach3.test eafcafb107585aecc2ed1569a77914138eef46a9 -F test/attachmalloc.test 03eeddd06e685ddbe975efd51824e4941847e5f4 +F test/attachmalloc.test c558251bcc3a2408d11fca42b9cee574fa3d74c2 F test/auth.test 66923137cf78475f5671b5e6e6274935e055aea0 F test/auth2.test 8da06f0ffcfd98154dda78e0f3b35a6503c27b64 F test/autoinc.test 60005a676e3e4e17dfa9dbd08aa0b76587ff97e3 @@ -207,9 +207,9 @@ F test/btree9.test 5d8711b241145b90f65dd1795d5dd8290846fa5e F test/busy.test 0271c854738e23ad76e10d4096a698e5af29d211 F test/cache.test 3ff445c445742a7b6b9ba6e1d62a25263f9424b9 F test/capi2.test 3c5066836cbaa9923bcc8282c010aa227bb5efd4 -F test/capi3.test b436e762c01a9cb2235d4de8b55af3b887f0e384 +F test/capi3.test e1b40aa127de9ecfcca707f359d68b993ef38b4c F test/capi3b.test 664eb55318132f292f2c436f90906f578cad6b97 -F test/capi3c.test 76a3fb94755288a2977ee387e95305e6224c0198 +F test/capi3c.test 787ce050fd5e09e419c920f91c7f404e62e20cd8 F test/cast.test c4780b58b569bab4947458195410ae8791ac216b F test/check.test 024ed399600b799160378cf9d9f436bdf5dfd184 F test/collate1.test e3eaa48c21e150814be1a7b852d2a8af24458d04 @@ -301,7 +301,7 @@ F test/func.test 605989453d1b42cec1d05c17aa232dc98e3e04e6 F test/fuzz.test 62fc19dd36a427777fd671b569df07166548628a F test/fuzz2.test ea38692ce2da99ad79fe0be5eb1a452c1c4d37bb F test/fuzz_common.tcl ff4bc2dfc465f6878f8e2d819620914365382731 -F test/fuzz_malloc.test e2f1e74127ad7ab8fbeacc0f16d059a81c8f3ea6 +F test/fuzz_malloc.test 18f1502b2d926b47dba90728f1573928abd96a80 F test/hook.test 7e7645fd9a033f79cce8fdff151e32715e7ec50a F test/icu.test e6bfae7f625c88fd14df6f540fe835bdfc1e4329 F test/in.test 369cb2aa1eab02296b4ec470732fe8c131260b1d @@ -398,7 +398,7 @@ F test/server1.test e328b8e641ba8fe9273132cfef497383185dc1f5 F test/shared.test 08b30d5f1939efff0517e7ff8ec7b74ad31c151b F test/shared2.test 0ee9de8964d70e451936a48c41cb161d9134ccf4 F test/shared3.test 01e3e124dbb3859788aabc7cfb82f7ea04421749 -F test/shared_err.test cc528f6e78665787e93d9ce3a782a2ce5179d821 +F test/shared_err.test 9fa070e3e7d63022a81b6156ac71f114c0678e3d F test/soak.test 64f9b27fbcdec43335a88c546ce1983e6ba40d7b F test/softheap1.test 0c49aa6eee25e7d32943e85e8d1f20eff566b1dc F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5 @@ -475,7 +475,7 @@ F test/vtab8.test e19fa4a538fcd1bb66c22825fa8f71618fb13583 F test/vtab9.test ea58d2b95d61955f87226381716b2d0b1d4e4f9b F test/vtabA.test 9cb6b1afead6fdd91bbdf1ca65c44ccfd9b10936 F test/vtab_alter.test 87617789086fd1767aa071e7805f1af7e1dac144 -F test/vtab_err.test 9eabf98b26838fed8bac4aea986580be0a2bd52e +F test/vtab_err.test f63f4c96bcd403076d49393136fb4fd9e0c5b402 F test/vtab_shared.test d631d1f820c38c18939d53aab1fc35db5f0a8094 F test/where.test 1bcde8984c63747ac6d6bafcacd20fd6e8a223de F test/where2.test 3249d426b3fc7a106713d784e1628307fc308d2e @@ -561,7 +561,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P 686fcfeda407c29cdb51fe814da616f1ccac5414 -R 79030448b310160e2ed68e6b77c89fcc +P e5ec17071720a973bbd213a8b23038d3aff25315 +R a2a459ce4d89b3260dd62868dc774bc5 U danielk1977 -Z f916d879cdbedc415720abb0ce0c3ff1 +Z 07d9ea0b58d791968ed1c4e04f1541a3 diff --git a/manifest.uuid b/manifest.uuid index b93ec58904..bf9c1afedb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e5ec17071720a973bbd213a8b23038d3aff25315 \ No newline at end of file +b076e1655d6bae5ae10e6ceee646f502435da66a \ No newline at end of file diff --git a/src/test8.c b/src/test8.c index 8e7d50d540..b27bd31c4a 100644 --- a/src/test8.c +++ b/src/test8.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test8.c,v 1.53 2007/08/23 02:47:53 drh Exp $ +** $Id: test8.c,v 1.54 2007/08/25 13:37:49 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -303,30 +303,32 @@ static int echoDeclareVtab( if( pVtab->zTableName ){ sqlite3_stmt *pStmt = 0; - sqlite3_prepare(db, + rc = sqlite3_prepare(db, "SELECT sql FROM sqlite_master WHERE type = 'table' AND name = ?", -1, &pStmt, 0); - sqlite3_bind_text(pStmt, 1, pVtab->zTableName, -1, 0); - if( sqlite3_step(pStmt)==SQLITE_ROW ){ - int rc2; - const char *zCreateTable = (const char *)sqlite3_column_text(pStmt, 0); - rc = sqlite3_declare_vtab(db, zCreateTable); - rc2 = sqlite3_finalize(pStmt); + if( rc==SQLITE_OK ){ + sqlite3_bind_text(pStmt, 1, pVtab->zTableName, -1, 0); + if( sqlite3_step(pStmt)==SQLITE_ROW ){ + int rc2; + const char *zCreateTable = (const char *)sqlite3_column_text(pStmt, 0); + rc = sqlite3_declare_vtab(db, zCreateTable); + rc2 = sqlite3_finalize(pStmt); + if( rc==SQLITE_OK ){ + rc = rc2; + } + } else { + rc = sqlite3_finalize(pStmt); + if( rc==SQLITE_OK ){ + rc = SQLITE_ERROR; + } + } if( rc==SQLITE_OK ){ - rc = rc2; + rc = getColumnNames(db, pVtab->zTableName, &pVtab->aCol, &pVtab->nCol); } - } else { - rc = sqlite3_finalize(pStmt); - if( rc==SQLITE_OK ){ - rc = SQLITE_ERROR; + if( rc==SQLITE_OK ){ + rc = getIndexArray(db, pVtab->zTableName, pVtab->nCol, &pVtab->aIndex); } } - if( rc==SQLITE_OK ){ - rc = getColumnNames(db, pVtab->zTableName, &pVtab->aCol, &pVtab->nCol); - } - if( rc==SQLITE_OK ){ - rc = getIndexArray(db, pVtab->zTableName, pVtab->nCol, &pVtab->aIndex); - } } return rc; @@ -784,6 +786,9 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ appendToEchoModule(pVtab->interp, "xBestIndex");; appendToEchoModule(pVtab->interp, zQuery); + if( !zQuery ){ + return SQLITE_NOMEM; + } pIdxInfo->idxNum = hashString(zQuery); pIdxInfo->idxStr = zQuery; pIdxInfo->needToFreeIdxStr = 1; diff --git a/test/attachmalloc.test b/test/attachmalloc.test index fb9d4f868f..785af235e1 100644 --- a/test/attachmalloc.test +++ b/test/attachmalloc.test @@ -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 -# -# The first argument, , 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 diff --git a/test/capi3.test b/test/capi3.test index 3fa8040064..563d7aa889 100644 --- a/test/capi3.test +++ b/test/capi3.test @@ -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 diff --git a/test/capi3c.test b/test/capi3c.test index 3500a818ec..2d039a6838 100644 --- a/test/capi3c.test +++ b/test/capi3c.test @@ -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 diff --git a/test/fuzz_malloc.test b/test/fuzz_malloc.test index 30cdc50aee..4cf4556842 100644 --- a/test/fuzz_malloc.test +++ b/test/fuzz_malloc.test @@ -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 diff --git a/test/shared_err.test b/test/shared_err.test index 56055810c8..2272cf34bd 100644 --- a/test/shared_err.test +++ b/test/shared_err.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 -# -# The first argument, , 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 { diff --git a/test/vtab_err.test b/test/vtab_err.test index 7101e13e83..ccd01082b8 100644 --- a/test/vtab_err.test +++ b/test/vtab_err.test @@ -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 -# -# The first argument, , 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