AryaWu/sqlite
0
1# 2008 August 012#3# The author disclaims copyright to this source code. In place of4# a legal notice, here is a blessing:5#6# May you do good and not evil.7# May you find forgiveness for yourself and forgive others.8# May you share freely, never taking more than you give.9#10#***********************************************************************11#12# Tests for the lookaside memory allocator.13#14# $Id: lookaside.test,v 1.10 2009/04/09 01:23:49 drh Exp $15 16set testdir [file dirname $argv0]17source $testdir/tester.tcl18 19ifcapable !lookaside {20 finish_test21 return22}23 24# The tests in this file configure the lookaside allocator after a 25# connection is opened. This will not work if there is any "presql"26# configured (SQL run within the [sqlite3] wrapper in tester.tcl).27if {[info exists ::G(perm:dbconfig)] && $::G(perm:dbconfig)!=""} {28 finish_test29 return30}31 32test_set_config_pagecache 0 033 34catch {db close}35sqlite3_shutdown36sqlite3_initialize37autoinstall_test_functions38 39sqlite3 db test.db40db cache size 441 42# Make sure sqlite3_db_config() and sqlite3_db_status are working.43#44do_test lookaside-1.1 {45 catch {sqlite3_config_error db}46} {0}47 48do_test lookaside-1.2 {49 sqlite3_db_config_lookaside db 1 18 1850} {0}51do_test lookaside-1.3.1 {52 sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 053} {0 0 0}54do_test lookaside-1.3.2 {55 sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 056} {0 0 0}57do_test lookaside-1.3.3 {58 sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 059} {0 0 0}60do_test lookaside-1.3.4 {61 sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 062} {0 0 0}63 64do_test lookaside-1.4 {65 db eval {CREATE TABLE t1(w,x,y,z);}66 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break67 set p [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 0] 2]68 set q [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 0] 2]69 set r [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 0] 2]70 expr {$x==0 && $y<$z && $z==18 && $p>0 && $q>0 && $r>0}71} {0}72do_test lookaside-1.5 {73 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break74 expr {$x==0 && $y<$z && $z==18}75} {0}76do_test lookaside-1.6 {77 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break78 expr {$x==0 && $y==$z && $y<18}79} {1}80do_test lookaside-1.7 {81 db cache flush82 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break83 expr {$x==0 && $y==0 && $z<18}84} {1}85do_test lookaside-1.8 {86 db cache flush87 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break88 expr {$x==0 && $y==0 && $z<18}89} {1}90do_test lookaside-1.9 {91 db cache flush92 sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 093} {0 0 0}94 95do_test lookaside-2.1 {96 sqlite3_db_config_lookaside db 0 100 100097} {0}98do_test lookaside-2.2 {99 db eval {CREATE TABLE t2(x);}100 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break101 expr {$x==0 && $y<$z && $z>10 && $z<100}102} {1}103do_test lookaside-2.3 {104 db eval {SELECT 1}105 sqlite3_db_config_lookaside db 0 50 50106} {5} ;# SQLITE_BUSY107do_test lookaside-2.4 {108 db cache flush109 sqlite3_db_config_lookaside db 0 50 50110} {0} ;# SQLITE_OK111do_test lookaside-2.5 {112 sqlite3_db_config_lookaside db 0 -1 50113} {0} ;# SQLITE_OK114do_test lookaside-2.6 {115 sqlite3_db_config_lookaside db 0 50 -1116} {0} ;# SQLITE_OK117 118# sqlite3_db_status() with an invalid verb returns an error.119#120do_test lookaside-3.1 {121 sqlite3_db_status db 99999 0122} {1 0 0}123 124# Test that an invalid verb on sqlite3_config() is detected and125# reported as an error.126#127do_test lookaside-4.1 {128 db close129 sqlite3_shutdown130 catch sqlite3_config_error131} {0}132sqlite3_initialize133autoinstall_test_functions134 135test_restore_config_pagecache136finish_test137 