Annotation of embedaddon/sqlite3/test/lookaside.test, revision 1.1.1.1
1.1 misho 1: # 2008 August 01
2: #
3: # The author disclaims copyright to this source code. In place of
4: # 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:
16: set testdir [file dirname $argv0]
17: source $testdir/tester.tcl
18:
19: ifcapable !lookaside {
20: finish_test
21: return
22: }
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).
27: if {[info exists ::G(perm:presql)]} {
28: finish_test
29: return
30: }
31:
32: catch {db close}
33: sqlite3_shutdown
34: sqlite3_config_pagecache 0 0
35: sqlite3_config_scratch 0 0
36: sqlite3_initialize
37: autoinstall_test_functions
38: sqlite3 db test.db
39:
40: # Make sure sqlite3_db_config() and sqlite3_db_status are working.
41: #
42: do_test lookaside-1.1 {
43: catch {sqlite3_config_error db}
44: } {0}
45:
46: do_test lookaside-1.2 {
47: sqlite3_db_config_lookaside db 1 18 18
48: } {0}
49: do_test lookaside-1.3.1 {
50: sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0
51: } {0 0 0}
52: do_test lookaside-1.3.2 {
53: sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 0
54: } {0 0 0}
55: do_test lookaside-1.3.3 {
56: sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 0
57: } {0 0 0}
58: do_test lookaside-1.3.4 {
59: sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 0
60: } {0 0 0}
61:
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}
69: } {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}
73: } {0}
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}
77: } {1}
78: do_test lookaside-1.7 {
79: db cache flush
80: foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
81: expr {$x==0 && $y==0 && $z<18}
82: } {1}
83: do_test lookaside-1.8 {
84: db cache flush
85: foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break
86: expr {$x==0 && $y==0 && $z<18}
87: } {1}
88: do_test lookaside-1.9 {
89: db cache flush
90: sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0
91: } {0 0 0}
92:
93: do_test lookaside-2.1 {
94: sqlite3_db_config_lookaside db 0 100 1000
95: } {0}
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}
100: } {1}
101: do_test lookaside-2.3 {
102: sqlite3_db_config_lookaside db 0 50 50
103: } {5} ;# SQLITE_BUSY
104: do_test lookaside-2.4 {
105: db cache flush
106: sqlite3_db_config_lookaside db 0 50 50
107: } {0} ;# SQLITE_OK
108: do_test lookaside-2.5 {
109: sqlite3_db_config_lookaside db 0 -1 50
110: } {0} ;# SQLITE_OK
111: do_test lookaside-2.6 {
112: sqlite3_db_config_lookaside db 0 50 -1
113: } {0} ;# SQLITE_OK
114:
115: # sqlite3_db_status() with an invalid verb returns an error.
116: #
117: do_test lookaside-3.1 {
118: sqlite3_db_status db 99999 0
119: } {1 0 0}
120:
121: # Test that an invalid verb on sqlite3_config() is detected and
122: # reported as an error.
123: #
124: do_test lookaside-4.1 {
125: db close
126: sqlite3_shutdown
127: catch sqlite3_config_error
128: } {0}
129: sqlite3_initialize
130: autoinstall_test_functions
131:
132: finish_test
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>