3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # Tests for the lookaside memory allocator.
14 # $Id: lookaside.test,v 1.10 2009/04/09 01:23:49 drh Exp $
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
19 ifcapable !lookaside {
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).
27 if {[info exists ::G(perm:dbconfig)] && $::G(perm:dbconfig)!=""} {
32 test_set_config_pagecache 0 0
37 autoinstall_test_functions
42 # Make sure sqlite3_db_config() and sqlite3_db_status are working.
44 do_test lookaside-1.1 {
45 catch {sqlite3_config_error db}
48 do_test lookaside-1.2 {
49 sqlite3_db_config_lookaside db 1 18 18
51 do_test lookaside-1.3.1 {
52 sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0
54 do_test lookaside-1.3.2 {
55 sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 0
57 do_test lookaside-1.3.3 {
58 sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 0
60 do_test lookaside-1.3.4 {
61 sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 0
64 do_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] break
67 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}
72 do_test lookaside-1.5 {
73 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break
74 expr {$x==0 && $y<$z && $z==18}
76 do_test lookaside-1.6 {
77 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
78 expr {$x==0 && $y==$z && $y<18}
80 do_test lookaside-1.7 {
82 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
83 expr {$x==0 && $y==0 && $z<18}
85 do_test lookaside-1.8 {
87 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break
88 expr {$x==0 && $y==0 && $z<18}
90 do_test lookaside-1.9 {
92 sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0
95 do_test lookaside-2.1 {
96 sqlite3_db_config_lookaside db 0 100 1000
98 do_test lookaside-2.2 {
99 db eval {CREATE TABLE t2(x);}
100 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
101 expr {$x==0 && $y<$z && $z>10 && $z<100}
103 do_test lookaside-2.3 {
105 sqlite3_db_config_lookaside db 0 50 50
107 do_test lookaside-2.4 {
109 sqlite3_db_config_lookaside db 0 50 50
111 do_test lookaside-2.5 {
112 sqlite3_db_config_lookaside db 0 -1 50
114 do_test lookaside-2.6 {
115 sqlite3_db_config_lookaside db 0 50 -1
118 # sqlite3_db_status() with an invalid verb returns an error.
120 do_test lookaside-3.1 {
121 sqlite3_db_status db 99999 0
124 # Test that an invalid verb on sqlite3_config() is detected and
125 # reported as an error.
127 do_test lookaside-4.1 {
130 catch sqlite3_config_error
133 autoinstall_test_functions
135 test_restore_config_pagecache