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:presql)]} {
32 test_set_config_pagecache 0 0
36 sqlite3_config_scratch 0 0
38 autoinstall_test_functions
41 # Make sure sqlite3_db_config() and sqlite3_db_status are working.
43 do_test lookaside-1.1 {
44 catch {sqlite3_config_error db}
47 do_test lookaside-1.2 {
48 sqlite3_db_config_lookaside db 1 18 18
50 do_test lookaside-1.3.1 {
51 sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0
53 do_test lookaside-1.3.2 {
54 sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 0
56 do_test lookaside-1.3.3 {
57 sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 0
59 do_test lookaside-1.3.4 {
60 sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 0
63 do_test lookaside-1.4 {
64 db eval {CREATE TABLE t1(w,x,y,z);}
65 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
66 set p [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 0] 2]
67 set q [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 0] 2]
68 set r [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 0] 2]
69 expr {$x==0 && $y<$z && $z==18 && $p>0 && $q>0 && $r>0}
71 do_test lookaside-1.5 {
72 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break
73 expr {$x==0 && $y<$z && $z==18}
75 do_test lookaside-1.6 {
76 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
77 expr {$x==0 && $y==$z && $y<18}
79 do_test lookaside-1.7 {
81 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
82 expr {$x==0 && $y==0 && $z<18}
84 do_test lookaside-1.8 {
86 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break
87 expr {$x==0 && $y==0 && $z<18}
89 do_test lookaside-1.9 {
91 sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0
94 do_test lookaside-2.1 {
95 sqlite3_db_config_lookaside db 0 100 1000
97 do_test lookaside-2.2 {
98 db eval {CREATE TABLE t2(x);}
99 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
100 expr {$x==0 && $y<$z && $z>10 && $z<100}
102 do_test lookaside-2.3 {
103 sqlite3_db_config_lookaside db 0 50 50
105 do_test lookaside-2.4 {
107 sqlite3_db_config_lookaside db 0 50 50
109 do_test lookaside-2.5 {
110 sqlite3_db_config_lookaside db 0 -1 50
112 do_test lookaside-2.6 {
113 sqlite3_db_config_lookaside db 0 50 -1
116 # sqlite3_db_status() with an invalid verb returns an error.
118 do_test lookaside-3.1 {
119 sqlite3_db_status db 99999 0
122 # Test that an invalid verb on sqlite3_config() is detected and
123 # reported as an error.
125 do_test lookaside-4.1 {
128 catch sqlite3_config_error
131 autoinstall_test_functions
133 test_restore_config_pagecache