2 #pragma ident "%Z%%M% %I% %E% SMI"
6 # The author disclaims copyright to this source code. In place of
7 # a legal notice, here is a blessing:
9 # May you do good and not evil.
10 # May you find forgiveness for yourself and forgive others.
11 # May you share freely, never taking more than you give.
13 #***********************************************************************
14 # This file implements regression tests for SQLite library. The
15 # focus of this script is page cache subsystem.
17 # $Id: pager.test,v 1.14 2004/02/25 02:20:42 drh Exp $
20 set testdir [file dirname $argv0]
21 source $testdir/tester.tcl
23 if {[info commands pager_open]!=""} {
26 # Basic sanity check. Open and close a pager.
29 catch {file delete -force ptf1.db}
30 catch {file delete -force ptf1.db-journal}
32 set ::p1 [pager_open ptf1.db 10]
37 } {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 0 ovfl 0}
43 } {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 0 ovfl 0}
48 # Try to write a few pages.
52 set ::p1 [pager_open ptf1.db 10]
57 # set ::g1 [page_get $::p1 0]
62 set ::gx [page_lookup $::p1 1]
66 } {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 0 ovfl 0}
69 set ::g1 [page_get $::p1 1]
71 if {$v} {lappend v $msg}
76 } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
78 set ::gx [page_lookup $::p1 1]
83 } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
90 } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
93 } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
99 } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
111 } {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 1 ovfl 0}
113 set ::g1 [page_get $::p1 1]
121 } {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 2 ovfl 0}
124 page_write $::g1 "Page-One"
130 } {ref 1 page 1 max 10 size 1 state 2 err 0 hit 0 miss 2 ovfl 0}
142 } {ref 1 page 1 max 10 size -1 state 1 err 0 hit 0 miss 2 ovfl 0}
144 pager_pagecount $::p1
148 } {ref 1 page 1 max 10 size 1 state 1 err 0 hit 0 miss 2 ovfl 0}
154 } {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 2 ovfl 0}
159 if {$v} {lappend v $::g1}
167 page_write $::g1 {page-one}
182 set ::g1 [page_get $::p1 1]
191 set ::p1 [pager_open ptf1.db 15]
193 if {$v} {lappend v $msg}
197 pager_pagecount $::p1
201 set ::g(1) [page_get $::p1 1]
203 if {$v} {lappend v $msg}
210 for {set i 2} {$i<=20} {incr i} {
211 set gx [page_get $::p1 $i]
212 page_write $gx "Page-$i"
217 for {set i 2} {$i<=20} {incr i} {
218 do_test pager-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 pager-3.7.$i.1 $body {1}
235 set vy [page_read $::g1]
238 do_test pager-3.7.$i.2 $body {1}
241 set gx [page_get $::p1 CNT]
242 set vy [page_read $gx]
246 do_test pager-3.7.$i.3 $body {1}
252 # tests of the checkpoint mechanism and api
256 file delete -force ptf1.db
257 set ::p1 [pager_open ptf1.db 15]
259 if {$v} {lappend v $msg}
263 set g1 [page_get $::p1 1]
264 page_write $g1 "Page-1 v0"
265 for {set i 2} {$i<=20} {incr i} {
266 set gx [page_get $::p1 $i]
267 page_write $gx "Page-$i v0"
272 for {set i 1} {$i<=20} {incr i} {
273 do_test pager-4.2.$i {
274 set gx [page_get $p1 $i]
275 set v [page_read $gx]
281 lrange [pager_stats $::p1] 0 1
284 lrange [pager_stats $::p1] 8 9
287 for {set i 1} {$i<20} {incr i} {
288 do_test pager-4.5.$i.0 {
290 for {set j 2} {$j<=20} {incr j} {
291 set gx [page_get $p1 $j]
292 set value [page_read $gx]
294 set shouldbe "Page-$j v[expr {$i-1}]"
295 if {$value!=$shouldbe} {
296 lappend res $value $shouldbe
301 do_test pager-4.5.$i.1 {
302 page_write $g1 "Page-1 v$i"
303 lrange [pager_stats $p1] 8 9
305 do_test pager-4.5.$i.2 {
306 for {set j 2} {$j<=20} {incr j} {
307 set gx [page_get $p1 $j]
308 page_write $gx "Page-$j v$i"
315 do_test pager-4.5.$i.3 {
317 for {set j 2} {$j<=20} {incr j} {
318 set gx [page_get $p1 $j]
319 set value [page_read $gx]
321 set shouldbe "Page-$j v$i"
322 if {$value!=$shouldbe} {
323 lappend res $value $shouldbe
328 do_test pager-4.5.$i.4 {
331 for {set j 2} {$j<=20} {incr j} {
332 set gx [page_get $p1 $j]
333 set value [page_read $gx]
335 set shouldbe "Page-$j v[expr {$i-1}]"
336 if {$value!=$shouldbe} {
337 lappend res $value $shouldbe
342 do_test pager-4.5.$i.5 {
343 page_write $g1 "Page-1 v$i"
344 lrange [pager_stats $p1] 8 9
346 do_test pager-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 pager-4.5.$i.7 {
357 pager_ckpt_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 pager-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 pager-4.5.$i.9 {
384 pager_ckpt_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 pager-4.5.$i.10 {
398 lrange [pager_stats $p1] 8 9
408 file delete -force ptf1.db
410 } ;# end if( not mem: and has pager_open command );
412 # Ticket #615: an assertion fault inside the pager. It is a benign
413 # fault, but we might as well test for it.
420 PRAGMA synchronous=off;