2008-08-01 16:31:14 +00:00
# 2008 August 01
#
# 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.
#
#***********************************************************************
#
# Tests for the lookaside memory allocator.
#
2009-04-09 01:23:49 +00:00
# $Id: lookaside.test,v 1.10 2009/04/09 01:23:49 drh Exp $
2008-08-01 16:31:14 +00:00
set testdir [file dirname $argv0]
source $testdir/tester.tcl
2008-10-11 17:06:04 +00:00
ifcapable !lookaside {
finish_test
return
}
2010-07-03 16:37:45 +00:00
# The tests in this file configure the lookaside allocator after a
# connection is opened. This will not work if there is any "presql"
# configured (SQL run within the [sqlite3] wrapper in tester.tcl).
2018-09-18 17:50:34 +00:00
if {[info exists ::G(perm:dbconfig)] && $::G(perm:dbconfig)!=""} {
2010-07-03 16:37:45 +00:00
finish_test
return
}
2015-07-24 14:17:17 +00:00
test_set_config_pagecache 0 0
2008-08-01 18:47:01 +00:00
catch {db close}
sqlite3_shutdown
sqlite3_initialize
2009-04-09 01:23:49 +00:00
autoinstall_test_functions
2018-09-18 17:50:34 +00:00
2008-08-01 18:47:01 +00:00
sqlite3 db test.db
2018-09-18 17:50:34 +00:00
db cache size 4
2008-08-01 18:47:01 +00:00
2008-08-01 16:31:14 +00:00
# Make sure sqlite3_db_config() and sqlite3_db_status are working.
#
do_test lookaside-1.1 {
catch {sqlite3_config_error db}
} {0}
2010-07-03 16:37:45 +00:00
2008-08-01 16:31:14 +00:00
do_test lookaside-1.2 {
2008-09-30 00:31:38 +00:00
sqlite3_db_config_lookaside db 1 18 18
2008-08-01 16:31:14 +00:00
} {0}
2010-12-21 21:28:38 +00:00
do_test lookaside-1.3.1 {
sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0
} {0 0 0}
do_test lookaside-1.3.2 {
sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 0
} {0 0 0}
do_test lookaside-1.3.3 {
sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 0
} {0 0 0}
do_test lookaside-1.3.4 {
sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 0
2008-08-01 16:31:14 +00:00
} {0 0 0}
2010-07-03 16:37:45 +00:00
2008-08-01 16:31:14 +00:00
do_test lookaside-1.4 {
2008-08-12 15:48:25 +00:00
db eval {CREATE TABLE t1(w,x,y,z);}
2010-12-21 21:28:38 +00:00
foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
set p [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 0] 2]
set q [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 0] 2]
set r [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 0] 2]
expr {$x==0 && $y<$z && $z==18 && $p>0 && $q>0 && $r>0}
2009-03-24 15:08:09 +00:00
} {0}
2008-08-01 16:31:14 +00:00
do_test lookaside-1.5 {
2010-12-21 21:28:38 +00:00
foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break
2008-09-30 00:31:38 +00:00
expr {$x==0 && $y<$z && $z==18}
2009-03-24 15:08:09 +00:00
} {0}
2008-08-01 16:31:14 +00:00
do_test lookaside-1.6 {
2010-12-21 21:28:38 +00:00
foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
2008-09-30 00:31:38 +00:00
expr {$x==0 && $y==$z && $y<18}
2008-08-01 18:47:01 +00:00
} {1}
2008-08-01 16:31:14 +00:00
do_test lookaside-1.7 {
db cache flush
2010-12-21 21:28:38 +00:00
foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
2008-09-30 00:31:38 +00:00
expr {$x==0 && $y==0 && $z<18}
2008-08-01 18:47:01 +00:00
} {1}
2008-08-01 16:31:14 +00:00
do_test lookaside-1.8 {
db cache flush
2010-12-21 21:28:38 +00:00
foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break
2008-09-30 00:31:38 +00:00
expr {$x==0 && $y==0 && $z<18}
2008-08-01 18:47:01 +00:00
} {1}
2008-08-01 16:31:14 +00:00
do_test lookaside-1.9 {
db cache flush
2010-12-21 21:28:38 +00:00
sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0
2008-08-01 16:31:14 +00:00
} {0 0 0}
do_test lookaside-2.1 {
2008-08-04 20:13:26 +00:00
sqlite3_db_config_lookaside db 0 100 1000
2008-08-01 16:31:14 +00:00
} {0}
do_test lookaside-2.2 {
db eval {CREATE TABLE t2(x);}
2010-12-21 21:28:38 +00:00
foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
2008-08-01 18:47:01 +00:00
expr {$x==0 && $y<$z && $z>10 && $z<100}
} {1}
2008-08-01 16:31:14 +00:00
do_test lookaside-2.3 {
2018-09-18 17:50:34 +00:00
db eval {SELECT 1}
2008-08-04 20:13:26 +00:00
sqlite3_db_config_lookaside db 0 50 50
2008-08-01 16:31:14 +00:00
} {5} ;# SQLITE_BUSY
do_test lookaside-2.4 {
db cache flush
2008-08-04 20:13:26 +00:00
sqlite3_db_config_lookaside db 0 50 50
2008-08-01 16:31:14 +00:00
} {0} ;# SQLITE_OK
2008-10-10 17:41:28 +00:00
do_test lookaside-2.5 {
sqlite3_db_config_lookaside db 0 -1 50
} {0} ;# SQLITE_OK
do_test lookaside-2.6 {
sqlite3_db_config_lookaside db 0 50 -1
} {0} ;# SQLITE_OK
2008-08-01 16:31:14 +00:00
# sqlite3_db_status() with an invalid verb returns an error.
#
do_test lookaside-3.1 {
sqlite3_db_status db 99999 0
} {1 0 0}
# Test that an invalid verb on sqlite3_config() is detected and
# reported as an error.
#
do_test lookaside-4.1 {
db close
sqlite3_shutdown
catch sqlite3_config_error
} {0}
sqlite3_initialize
2009-04-09 01:23:49 +00:00
autoinstall_test_functions
2008-08-05 17:53:22 +00:00
2015-07-24 14:17:17 +00:00
test_restore_config_pagecache
2008-08-05 17:53:22 +00:00
finish_test