First public contribution.
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 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this script is page cache subsystem.
14 # $Id: pager2.test,v 1.7 2008/08/20 14:49:25 danielk1977 Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 # Don't run this test file if the pager test interface [pager_open] is not
21 # available, or the library was compiled without in-memory database support.
23 if {[info commands pager_open]!=""} {
27 # Basic sanity check. Open and close a pager.
31 set ::p1 [pager_open :memory: 10]
36 } {ref 0 page 0 max 10 size 0 state 0 err 0 hit 0 miss 0 ovfl 0}
42 } {ref 0 page 0 max 10 size 0 state 0 err 0 hit 0 miss 0 ovfl 0}
47 # Try to write a few pages.
51 set ::p1 [pager_open :memory: 10]
56 # set ::g1 [page_get $::p1 0]
60 do_test pager2-2.3.1 {
61 set ::gx [page_lookup $::p1 1]
63 do_test pager2-2.3.2 {
65 } {ref 0 page 0 max 10 size 0 state 0 err 0 hit 0 miss 0 ovfl 0}
66 do_test pager2-2.3.3 {
68 set ::g1 [page_get $::p1 1]
70 if {$v} {lappend v $msg}
73 do_test pager2-2.3.3 {
75 } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
76 do_test pager2-2.3.4 {
77 set ::gx [page_lookup $::p1 1]
81 do_test pager2-2.3.5 {
83 } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
84 do_test pager2-2.3.6 {
87 do_test pager2-2.3.7 {
89 } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
92 } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
98 } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
108 do_test pager2-2.10 {
110 } {ref 0 page 1 max 10 size 0 state 0 err 0 hit 0 miss 1 ovfl 0}
111 do_test pager2-2.11 {
112 set ::g1 [page_get $::p1 1]
115 do_test pager2-2.12 {
118 do_test pager2-2.13 {
120 } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 1 miss 1 ovfl 0}
121 do_test pager2-2.14 {
123 page_write $::g1 "Page-One"
127 do_test pager2-2.15 {
129 } {ref 1 page 1 max 10 size 1 state 4 err 0 hit 1 miss 1 ovfl 0}
130 do_test pager2-2.16 {
133 do_test pager2-2.17 {
139 do_test pager2-2.20 {
141 } {ref 1 page 1 max 10 size 1 state 1 err 0 hit 1 miss 1 ovfl 0}
142 do_test pager2-2.19 {
143 pager_pagecount $::p1
145 do_test pager2-2.21 {
147 } {ref 1 page 1 max 10 size 1 state 1 err 0 hit 1 miss 1 ovfl 0}
148 do_test pager2-2.22 {
151 do_test pager2-2.23 {
153 } {ref 0 page 1 max 10 size 1 state 0 err 0 hit 1 miss 1 ovfl 0}
154 do_test pager2-2.24 {
158 if {$v} {lappend v $::g1}
161 do_test pager2-2.25 {
164 do_test pager2-2.26 {
166 page_write $::g1 {page-one}
170 do_test pager2-2.27 {
173 do_test pager2-2.28 {
179 do_test pager2-2.29 {
181 set ::g1 [page_get $::p1 1]
184 do_test pager2-2.99 {
188 #do_test pager2-3.1 {
190 # set ::p1 [pager_open :memory: 15]
192 # if {$v} {lappend v $msg}
196 pager_pagecount $::p1
200 set ::g(1) [page_get $::p1 1]
202 if {$v} {lappend v $msg}
209 for {set i 2} {$i<=20} {incr i} {
210 set gx [page_get $::p1 $i]
211 page_write $gx "Page-$i"
217 for {set i 2} {$i<=20} {incr i} {
218 do_test pager2-3.6.[expr {$i-1}] [subst {
219 set gx \[page_get $::p1 $i\]
220 set v \[page_read \$gx\]
225 for {set i 1} {$i<=20} {incr i} {
227 set ::g1 [page_get $::p1 CNT]
228 set ::g2 [page_get $::p1 CNT]
229 set ::vx [page_read $::g2]
232 do_test pager2-3.7.$i.1 $body {1}
235 set vy [page_read $::g1]
238 do_test pager2-3.7.$i.2 $body {1}
241 set gx [page_get $::p1 CNT]
242 set vy [page_read $gx]
246 do_test pager2-3.7.$i.3 $body {1}
248 do_test pager2-3.99 {
252 # tests of the checkpoint mechanism and api
256 set ::p1 [pager_open :memory: 15]
258 if {$v} {lappend v $msg}
262 set g1 [page_get $::p1 1]
263 page_write $g1 "Page-1 v0"
264 for {set i 2} {$i<=20} {incr i} {
265 set gx [page_get $::p1 $i]
266 page_write $gx "Page-$i v0"
271 for {set i 1} {$i<=20} {incr i} {
272 do_test pager2-4.2.$i {
273 set gx [page_get $p1 $i]
274 set v [page_read $gx]
280 lrange [pager_stats $::p1] 0 1
283 lrange [pager_stats $::p1] 8 9
286 for {set i 1} {$i<20} {incr i} {
287 do_test pager2-4.5.$i.0 {
289 for {set j 2} {$j<=20} {incr j} {
290 set gx [page_get $p1 $j]
291 set value [page_read $gx]
293 set shouldbe "Page-$j v[expr {$i-1}]"
294 if {$value!=$shouldbe} {
295 lappend res $value $shouldbe
300 do_test pager2-4.5.$i.1 {
301 page_write $g1 "Page-1 v$i"
302 lrange [pager_stats $p1] 8 9
304 do_test pager2-4.5.$i.2 {
305 for {set j 2} {$j<=20} {incr j} {
306 set gx [page_get $p1 $j]
307 page_write $gx "Page-$j v$i"
314 do_test pager2-4.5.$i.3 {
316 for {set j 2} {$j<=20} {incr j} {
317 set gx [page_get $p1 $j]
318 set value [page_read $gx]
320 set shouldbe "Page-$j v$i"
321 if {$value!=$shouldbe} {
322 lappend res $value $shouldbe
327 do_test pager2-4.5.$i.4 {
330 for {set j 2} {$j<=20} {incr j} {
331 set gx [page_get $p1 $j]
332 set value [page_read $gx]
334 set shouldbe "Page-$j v[expr {$i-1}]"
335 if {$value!=$shouldbe} {
336 lappend res $value $shouldbe
342 do_test pager2-4.5.$i.5 {
343 page_write $g1 "Page-1 v$i"
344 lrange [pager_stats $p1] 8 9
346 do_test pager2-4.5.$i.6 {
347 for {set j 2} {$j<=20} {incr j} {
348 set gx [page_get $p1 $j]
349 page_write $gx "Page-$j v$i"
356 do_test pager2-4.5.$i.7 {
357 pager_stmt_rollback $p1
358 for {set j 2} {$j<=20} {incr j} {
359 set gx [page_get $p1 $j]
360 set value [page_read $gx]
362 if {$j<=$i || $i==1} {
363 set shouldbe "Page-$j v$i"
365 set shouldbe "Page-$j v[expr {$i-1}]"
367 if {$value!=$shouldbe} {
368 lappend res $value $shouldbe
373 do_test pager2-4.5.$i.8 {
374 for {set j 2} {$j<=20} {incr j} {
375 set gx [page_get $p1 $j]
376 page_write $gx "Page-$j v$i"
383 do_test pager2-4.5.$i.9 {
384 pager_stmt_commit $p1
385 for {set j 2} {$j<=20} {incr j} {
386 set gx [page_get $p1 $j]
387 set value [page_read $gx]
389 set shouldbe "Page-$j v$i"
390 if {$value!=$shouldbe} {
391 lappend res $value $shouldbe
396 do_test pager2-4.5.$i.10 {
398 lrange [pager_stats $p1] 8 9
402 do_test pager2-4.99 {
407 } ;# ifcapable inmemory
408 } ;# end if( has pager_open command );