sl@0
|
1 |
# 2008 August 01
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
#
|
sl@0
|
12 |
# Tests for the lookaside memory allocator.
|
sl@0
|
13 |
#
|
sl@0
|
14 |
# $Id: lookaside.test,v 1.6 2008/09/30 00:31:38 drh Exp $
|
sl@0
|
15 |
|
sl@0
|
16 |
set testdir [file dirname $argv0]
|
sl@0
|
17 |
source $testdir/tester.tcl
|
sl@0
|
18 |
|
sl@0
|
19 |
catch {db close}
|
sl@0
|
20 |
sqlite3_shutdown
|
sl@0
|
21 |
sqlite3_config_pagecache 0 0
|
sl@0
|
22 |
sqlite3_config_scratch 0 0
|
sl@0
|
23 |
sqlite3_initialize
|
sl@0
|
24 |
sqlite3 db test.db
|
sl@0
|
25 |
|
sl@0
|
26 |
# Make sure sqlite3_db_config() and sqlite3_db_status are working.
|
sl@0
|
27 |
#
|
sl@0
|
28 |
do_test lookaside-1.1 {
|
sl@0
|
29 |
catch {sqlite3_config_error db}
|
sl@0
|
30 |
} {0}
|
sl@0
|
31 |
do_test lookaside-1.2 {
|
sl@0
|
32 |
sqlite3_db_config_lookaside db 1 18 18
|
sl@0
|
33 |
} {0}
|
sl@0
|
34 |
do_test lookaside-1.3 {
|
sl@0
|
35 |
sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
|
sl@0
|
36 |
} {0 0 0}
|
sl@0
|
37 |
do_test lookaside-1.4 {
|
sl@0
|
38 |
db eval {CREATE TABLE t1(w,x,y,z);}
|
sl@0
|
39 |
foreach {x y z} [sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0] break
|
sl@0
|
40 |
expr {$x==0 && $y<$z && $z==18}
|
sl@0
|
41 |
} {1}
|
sl@0
|
42 |
do_test lookaside-1.5 {
|
sl@0
|
43 |
foreach {x y z} [sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 1] break
|
sl@0
|
44 |
expr {$x==0 && $y<$z && $z==18}
|
sl@0
|
45 |
} {1}
|
sl@0
|
46 |
do_test lookaside-1.6 {
|
sl@0
|
47 |
foreach {x y z} [sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0] break
|
sl@0
|
48 |
expr {$x==0 && $y==$z && $y<18}
|
sl@0
|
49 |
} {1}
|
sl@0
|
50 |
do_test lookaside-1.7 {
|
sl@0
|
51 |
db cache flush
|
sl@0
|
52 |
foreach {x y z} [sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0] break
|
sl@0
|
53 |
expr {$x==0 && $y==0 && $z<18}
|
sl@0
|
54 |
} {1}
|
sl@0
|
55 |
do_test lookaside-1.8 {
|
sl@0
|
56 |
db cache flush
|
sl@0
|
57 |
foreach {x y z} [sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 1] break
|
sl@0
|
58 |
expr {$x==0 && $y==0 && $z<18}
|
sl@0
|
59 |
} {1}
|
sl@0
|
60 |
do_test lookaside-1.9 {
|
sl@0
|
61 |
db cache flush
|
sl@0
|
62 |
sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
|
sl@0
|
63 |
} {0 0 0}
|
sl@0
|
64 |
|
sl@0
|
65 |
do_test lookaside-2.1 {
|
sl@0
|
66 |
sqlite3_db_config_lookaside db 0 100 1000
|
sl@0
|
67 |
} {0}
|
sl@0
|
68 |
do_test lookaside-2.2 {
|
sl@0
|
69 |
db eval {CREATE TABLE t2(x);}
|
sl@0
|
70 |
foreach {x y z} [sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0] break
|
sl@0
|
71 |
expr {$x==0 && $y<$z && $z>10 && $z<100}
|
sl@0
|
72 |
} {1}
|
sl@0
|
73 |
do_test lookaside-2.3 {
|
sl@0
|
74 |
sqlite3_db_config_lookaside db 0 50 50
|
sl@0
|
75 |
} {5} ;# SQLITE_BUSY
|
sl@0
|
76 |
do_test lookaside-2.4 {
|
sl@0
|
77 |
db cache flush
|
sl@0
|
78 |
sqlite3_db_config_lookaside db 0 50 50
|
sl@0
|
79 |
} {0} ;# SQLITE_OK
|
sl@0
|
80 |
|
sl@0
|
81 |
# sqlite3_db_status() with an invalid verb returns an error.
|
sl@0
|
82 |
#
|
sl@0
|
83 |
do_test lookaside-3.1 {
|
sl@0
|
84 |
sqlite3_db_status db 99999 0
|
sl@0
|
85 |
} {1 0 0}
|
sl@0
|
86 |
|
sl@0
|
87 |
# Test that an invalid verb on sqlite3_config() is detected and
|
sl@0
|
88 |
# reported as an error.
|
sl@0
|
89 |
#
|
sl@0
|
90 |
do_test lookaside-4.1 {
|
sl@0
|
91 |
db close
|
sl@0
|
92 |
sqlite3_shutdown
|
sl@0
|
93 |
catch sqlite3_config_error
|
sl@0
|
94 |
} {0}
|
sl@0
|
95 |
sqlite3_initialize
|
sl@0
|
96 |
|
sl@0
|
97 |
finish_test
|