summaryrefslogtreecommitdiff
path: root/test/lookaside.test
blob: 0b239a04d5e1c0bd57b73e24d2c05cfe379f922e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# 2008 August 01
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# Tests for the lookaside memory allocator.
#
# $Id: lookaside.test,v 1.10 2009/04/09 01:23:49 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !lookaside {
  finish_test
  return
}

# The tests in this file configure the lookaside allocator after a 
# connection is opened. This will not work if there is any "presql"
# configured (SQL run within the [sqlite3] wrapper in tester.tcl).
if {[info exists ::G(perm:presql)]} {
  finish_test
  return
}

catch {db close}
sqlite3_shutdown
sqlite3_config_pagecache 0 0
sqlite3_config_scratch 0 0
sqlite3_initialize
autoinstall_test_functions
sqlite3 db test.db

# Make sure sqlite3_db_config() and sqlite3_db_status are working.
#
do_test lookaside-1.1 {
  catch {sqlite3_config_error db}
} {0}

do_test lookaside-1.2 {
  sqlite3_db_config_lookaside db 1 18 18
} {0}
do_test lookaside-1.3.1 {
  sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0
} {0 0 0}
do_test lookaside-1.3.2 {
  sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 0
} {0 0 0}
do_test lookaside-1.3.3 {
  sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 0
} {0 0 0}
do_test lookaside-1.3.4 {
  sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 0
} {0 0 0}

do_test lookaside-1.4 {
  db eval {CREATE TABLE t1(w,x,y,z);}
  foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
  set p [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_HIT 0] 2]
  set q [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_SIZE 0] 2]
  set r [lindex [sqlite3_db_status db DBSTATUS_LOOKASIDE_MISS_FULL 0] 2]
  expr {$x==0 && $y<$z && $z==18 && $p>0 && $q>0 && $r>0}
} {0}
do_test lookaside-1.5 {
  foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break
  expr {$x==0 && $y<$z && $z==18}
} {0}
do_test lookaside-1.6 {
  foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
  expr {$x==0 && $y==$z && $y<18}
} {1}
do_test lookaside-1.7 {
  db cache flush
  foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
  expr {$x==0 && $y==0 && $z<18}
} {1}
do_test lookaside-1.8 {
  db cache flush
  foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 1] break
  expr {$x==0 && $y==0 && $z<18}
} {1}
do_test lookaside-1.9 {
  db cache flush
  sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0
} {0 0 0}

do_test lookaside-2.1 {
  sqlite3_db_config_lookaside db 0 100 1000
} {0}
do_test lookaside-2.2 {
  db eval {CREATE TABLE t2(x);}
  foreach {x y z} [sqlite3_db_status db DBSTATUS_LOOKASIDE_USED 0] break
  expr {$x==0 && $y<$z && $z>10 && $z<100}
} {1}
do_test lookaside-2.3 {
  sqlite3_db_config_lookaside db 0 50 50
} {5}  ;# SQLITE_BUSY
do_test lookaside-2.4 {
  db cache flush
  sqlite3_db_config_lookaside db 0 50 50
} {0}  ;# SQLITE_OK
do_test lookaside-2.5 {
  sqlite3_db_config_lookaside db 0 -1 50
} {0}  ;# SQLITE_OK
do_test lookaside-2.6 {
  sqlite3_db_config_lookaside db 0 50 -1
} {0}  ;# SQLITE_OK

# sqlite3_db_status() with an invalid verb returns an error.
#
do_test lookaside-3.1 {
  sqlite3_db_status db 99999 0
} {1 0 0}

# Test that an invalid verb on sqlite3_config() is detected and
# reported as an error.
#
do_test lookaside-4.1 {
  db close
  sqlite3_shutdown
  catch sqlite3_config_error
} {0}
sqlite3_initialize
autoinstall_test_functions

finish_test