1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/cache.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,63 @@
1.4 +# 2007 March 24
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 +# $Id: cache.test,v 1.4 2007/08/22 02:56:44 drh Exp $
1.16 +
1.17 +set testdir [file dirname $argv0]
1.18 +source $testdir/tester.tcl
1.19 +
1.20 +ifcapable {!pager_pragmas} {
1.21 + finish_test
1.22 + return
1.23 +}
1.24 +sqlite3_soft_heap_limit 0
1.25 +
1.26 +proc pager_cache_size {db} {
1.27 + set bt [btree_from_db $db]
1.28 + db_enter $db
1.29 + array set stats [btree_pager_stats $bt]
1.30 + db_leave $db
1.31 + return $stats(page)
1.32 +}
1.33 +
1.34 +do_test cache-1.1 {
1.35 + pager_cache_size db
1.36 +} {0}
1.37 +
1.38 +do_test cache-1.2 {
1.39 + execsql {
1.40 + PRAGMA auto_vacuum=OFF;
1.41 + CREATE TABLE abc(a, b, c);
1.42 + INSERT INTO abc VALUES(1, 2, 3);
1.43 + }
1.44 + pager_cache_size db
1.45 +} {2}
1.46 +
1.47 +# At one point, repeatedly locking and unlocking the cache was causing
1.48 +# a resource leak of one page per repetition. The page wasn't actually
1.49 +# leaked, but would not be reused until the pager-cache was full (i.e.
1.50 +# 2000 pages by default).
1.51 +#
1.52 +# This tests that once the pager-cache is initialised, it can be locked
1.53 +# and unlocked repeatedly without internally allocating any new pages.
1.54 +#
1.55 +set cache_size [pager_cache_size db]
1.56 +for {set ii 0} {$ii < 10} {incr ii} {
1.57 +
1.58 + do_test cache-1.3.$ii {
1.59 + execsql {SELECT * FROM abc}
1.60 + pager_cache_size db
1.61 + } $::cache_size
1.62 +
1.63 +}
1.64 +sqlite3_soft_heap_limit $soft_limit
1.65 +
1.66 +finish_test