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)]} {
34 sqlite3_config_pagecache 0 0
35 sqlite3_config_scratch 0 0
37 autoinstall_test_functions
40 # Make sure sqlite3_db_config() and sqlite3_db_status are working.
42 do_test lookaside-1.1 {
43 catch {sqlite3_config_error db}
46 do_test lookaside-1.2 {
47 sqlite3_db_config_lookaside db 1 18 18
49 do_test lookaside-1.3.1 {
50 sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0
52 do_test lookaside-1.3.2 {
53 sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 0
55 do_test lookaside-1.3.3 {
56 sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 0
58 do_test lookaside-1.3.4 {
59 sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 0
62 do_test lookaside-1.4 {
63 db eval {CREATE TABLE t1(w,x,y,z);}
64 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
65 set p [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 0] 2]
66 set q [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 0] 2]
67 set r [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 0] 2]
68 expr {$x==0 && $y<$z && $z==18 && $p>0 && $q>0 && $r>0}
70 do_test lookaside-1.5 {
71 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break
72 expr {$x==0 && $y<$z && $z==18}
74 do_test lookaside-1.6 {
75 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
76 expr {$x==0 && $y==$z && $y<18}
78 do_test lookaside-1.7 {
80 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
81 expr {$x==0 && $y==0 && $z<18}
83 do_test lookaside-1.8 {
85 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break
86 expr {$x==0 && $y==0 && $z<18}
88 do_test lookaside-1.9 {
90 sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0
93 do_test lookaside-2.1 {
94 sqlite3_db_config_lookaside db 0 100 1000
96 do_test lookaside-2.2 {
97 db eval {CREATE TABLE t2(x);}
98 foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
99 expr {$x==0 && $y<$z && $z>10 && $z<100}
101 do_test lookaside-2.3 {
102 sqlite3_db_config_lookaside db 0 50 50
104 do_test lookaside-2.4 {
106 sqlite3_db_config_lookaside db 0 50 50
108 do_test lookaside-2.5 {
109 sqlite3_db_config_lookaside db 0 -1 50
111 do_test lookaside-2.6 {
112 sqlite3_db_config_lookaside db 0 50 -1
115 # sqlite3_db_status() with an invalid verb returns an error.
117 do_test lookaside-3.1 {
118 sqlite3_db_status db 99999 0
121 # Test that an invalid verb on sqlite3_config() is detected and
122 # reported as an error.
124 do_test lookaside-4.1 {
127 catch sqlite3_config_error
130 autoinstall_test_functions