Index: src/test_malloc.c ================================================================== --- src/test_malloc.c +++ src/test_malloc.c @@ -937,30 +937,33 @@ Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ int sz, N, rc; - Tcl_Obj *pResult; + Tcl_Obj *pRes; static char *buf = 0; if( objc!=3 ){ Tcl_WrongNumArgs(interp, 1, objv, "SIZE N"); return TCL_ERROR; } if( Tcl_GetIntFromObj(interp, objv[1], &sz) ) return TCL_ERROR; if( Tcl_GetIntFromObj(interp, objv[2], &N) ) return TCL_ERROR; free(buf); + buf = 0; + + /* Set the return value */ + pRes = Tcl_NewObj(); + Tcl_ListObjAppendElement(0, pRes, Tcl_NewIntObj(sqlite3GlobalConfig.szPage)); + Tcl_ListObjAppendElement(0, pRes, Tcl_NewIntObj(sqlite3GlobalConfig.nPage)); + Tcl_SetObjResult(interp, pRes); + if( sz<0 ){ - buf = 0; rc = sqlite3_config(SQLITE_CONFIG_PAGECACHE, 0, 0, 0); }else{ buf = malloc( sz*N ); rc = sqlite3_config(SQLITE_CONFIG_PAGECACHE, buf, sz, N); } - pResult = Tcl_NewObj(); - Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(rc)); - Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(N)); - Tcl_SetObjResult(interp, pResult); return TCL_OK; } /* ** Usage: sqlite3_config_alt_pcache INSTALL_FLAG DISCARD_CHANCE PRNG_SEED Index: test/fuzz3.test ================================================================== --- test/fuzz3.test +++ test/fuzz3.test @@ -19,16 +19,11 @@ source $testdir/tester.tcl # These tests deal with corrupt database files # database_may_be_corrupt -db close -sqlite3_shutdown -sqlite3_config_pagecache 0 0 -sqlite3_initialize -autoinstall_test_functions -sqlite3 db test.db +test_set_config_pagecache 0 0 expr srand(123) proc rstring {n} { @@ -174,6 +169,8 @@ do_test fuzz3-$ii.$iNew.[incr iTest] { db_checksum } $::cksum } +test_restore_config_pagecache finish_test + Index: test/lookaside.test ================================================================== --- test/lookaside.test +++ test/lookaside.test @@ -27,13 +27,14 @@ if {[info exists ::G(perm:presql)]} { finish_test return } +test_set_config_pagecache 0 0 + catch {db close} sqlite3_shutdown -sqlite3_config_pagecache 0 0 sqlite3_config_scratch 0 0 sqlite3_initialize autoinstall_test_functions sqlite3 db test.db @@ -127,6 +128,7 @@ catch sqlite3_config_error } {0} sqlite3_initialize autoinstall_test_functions +test_restore_config_pagecache finish_test Index: test/malloc5.test ================================================================== --- test/malloc5.test +++ test/malloc5.test @@ -18,15 +18,10 @@ # no longer the case. In version 3.6.2, sqlite3_release_memory() only # reclaims clean pages. This test file has been updated accordingly. # # $Id: malloc5.test,v 1.22 2009/04/11 19:09:54 drh Exp $ -sqlite3_shutdown -sqlite3_config_pagecache 0 100 -sqlite3_initialize -autoinstall_test_functions - set testdir [file dirname $argv0] source $testdir/tester.tcl source $testdir/malloc_common.tcl db close @@ -41,10 +36,12 @@ # Skip these tests if OMIT_MEMORY_MANAGEMENT was defined at compile time. ifcapable !memorymanage { finish_test return } + +test_set_config_pagecache 0 100 sqlite3_soft_heap_limit 0 sqlite3 db test.db db eval {PRAGMA cache_size=1} @@ -413,7 +410,8 @@ } {1 3} db2 close sqlite3_soft_heap_limit $::soft_limit +test_restore_config_pagecache finish_test catch {db close} Index: test/memsubsys1.test ================================================================== --- test/memsubsys1.test +++ test/memsubsys1.test @@ -22,10 +22,12 @@ # if {[permutation] == "memsubsys1"} { finish_test return } + +test_set_config_pagecache 0 0 # This procedure constructs a new database in test.db. It fills # this database with many small records (enough to force multiple # rebalance operations in the btree-layer and to require a large # page cache), verifies correct results, then returns. @@ -308,12 +310,13 @@ db close sqlite3_shutdown sqlite3_config_memstatus 1 -sqlite3_config_pagecache 0 0 sqlite3_config_scratch 0 0 sqlite3_config_lookaside 100 500 sqlite3_config serialized sqlite3_initialize autoinstall_test_functions + +test_restore_config_pagecache finish_test Index: test/pcache2.test ================================================================== --- test/pcache2.test +++ test/pcache2.test @@ -13,10 +13,12 @@ # # $Id: pcache2.test,v 1.5 2009/07/18 14:36:24 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl + +test_set_config_pagecache 0 0 # Set up a pcache memory pool so that we can easily track how many # pages are being used for cache. # do_test pcache2-1.1 { @@ -76,6 +78,7 @@ sqlite3_config_pagecache 0 0 sqlite3_config serialized sqlite3_initialize autoinstall_test_functions +test_restore_config_pagecache finish_test Index: test/permutations.test ================================================================== --- test/permutations.test +++ test/permutations.test @@ -415,20 +415,20 @@ test_suite "memsubsys1" -description { Tests using pre-allocated page and scratch blocks } -files [ test_set $::allquicktests -exclude ioerr5.test malloc5.test mmap1.test ] -initialize { + test_set_config_pagecache 4096 24 catch {db close} sqlite3_shutdown - sqlite3_config_pagecache 4096 24 sqlite3_config_scratch 25000 1 sqlite3_initialize autoinstall_test_functions } -shutdown { + test_restore_config_pagecache catch {db close} sqlite3_shutdown - sqlite3_config_pagecache 0 0 sqlite3_config_scratch 0 0 sqlite3_initialize autoinstall_test_functions } @@ -442,20 +442,20 @@ test_suite "memsubsys2" -description { Tests using small pre-allocated page and scratch blocks } -files [ test_set $::allquicktests -exclude ioerr5.test malloc5.test ] -initialize { + test_set_config_pagecache 512 5 catch {db close} sqlite3_shutdown - sqlite3_config_pagecache 512 5 sqlite3_config_scratch 1000 1 sqlite3_initialize autoinstall_test_functions } -shutdown { + test_restore_config_pagecache catch {db close} sqlite3_shutdown - sqlite3_config_pagecache 0 0 sqlite3_config_scratch 0 0 sqlite3_initialize autoinstall_test_functions } Index: test/tester.tcl ================================================================== --- test/tester.tcl +++ test/tester.tcl @@ -2038,10 +2038,49 @@ proc db_delete_and_reopen {{file test.db}} { catch { db close } foreach f [glob -nocomplain test.db*] { forcedelete $f } sqlite3 db $file } + +# Close any connections named [db], [db2] or [db3]. Then use sqlite3_config +# to configure the size of the PAGECACHE allocation using the parameters +# provided to this command. Save the old PAGECACHE parameters in a global +# variable so that [test_restore_config_pagecache] can restore the previous +# configuration. +# +# Before returning, reopen connection [db] on file test.db. +# +proc test_set_config_pagecache {sz nPg} { + catch {db close} + catch {db2 close} + catch {db3 close} + + sqlite3_shutdown + set ::old_pagecache_config [sqlite3_config_pagecache $sz $nPg] + sqlite3_initialize + autoinstall_test_functions + sqlite3 db test.db +} + +# Close any connections named [db], [db2] or [db3]. Then use sqlite3_config +# to configure the size of the PAGECACHE allocation to the size saved in +# the global variable by an earlier call to [test_set_config_pagecache]. +# +# Before returning, reopen connection [db] on file test.db. +# +proc test_restore_config_pagecache {} { + catch {db close} + catch {db2 close} + catch {db3 close} + + sqlite3_shutdown + eval sqlite3_config_pagecache $::old_pagecache_config + unset ::old_pagecache_config + sqlite3_initialize + autoinstall_test_functions + sqlite3 db test.db +} # If the library is compiled with the SQLITE_DEFAULT_AUTOVACUUM macro set # to non-zero, then set the global variable $AUTOVACUUM to 1. set AUTOVACUUM $sqlite_options(default_autovacuum) Index: test/zeroblob.test ================================================================== --- test/zeroblob.test +++ test/zeroblob.test @@ -20,10 +20,12 @@ ifcapable !incrblob { finish_test return } + +test_set_config_pagecache 0 0 # When zeroblob() is used for the last field of a column, then the # content of the zeroblob is never instantiated on the VDBE stack. # But it does get inserted into the database correctly. # @@ -39,10 +41,11 @@ execsql { INSERT INTO t1 VALUES(2,3,4,zeroblob(1000000)); } set ::sqlite3_max_blobsize } {10} + do_test zeroblob-1.1.1 { expr {[sqlite3_memory_highwater]<$::memused+25000} } {1} do_test zeroblob-1.2 { execsql { @@ -263,6 +266,7 @@ } catchsql {INSERT INTO t10 VALUES(zeroblob(1e9),zeroblob(1e9),zeroblob(1e9))} } {1 {string or blob too big}} +test_restore_config_pagecache finish_test