2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A# 2001 September 15
2N/A#
2N/A# The author disclaims copyright to this source code. In place of
2N/A# a legal notice, here is a blessing:
2N/A#
2N/A# May you do good and not evil.
2N/A# May you find forgiveness for yourself and forgive others.
2N/A# May you share freely, never taking more than you give.
2N/A#
2N/A#***********************************************************************
2N/A# This file implements regression tests for SQLite library. The
2N/A# focus of this script is page cache subsystem.
2N/A#
2N/A# $Id: pager.test,v 1.14 2004/02/25 02:20:42 drh Exp $
2N/A
2N/A
2N/Aset testdir [file dirname $argv0]
2N/Asource $testdir/tester.tcl
2N/A
2N/Aif {[info commands pager_open]!=""} {
2N/Adb close
2N/A
2N/A# Basic sanity check. Open and close a pager.
2N/A#
2N/Ado_test pager-1.0 {
2N/A catch {file delete -force ptf1.db}
2N/A catch {file delete -force ptf1.db-journal}
2N/A set v [catch {
2N/A set ::p1 [pager_open ptf1.db 10]
2N/A } msg]
2N/A} {0}
2N/Ado_test pager-1.1 {
2N/A pager_stats $::p1
2N/A} {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 0 ovfl 0}
2N/Ado_test pager-1.2 {
2N/A pager_pagecount $::p1
2N/A} {0}
2N/Ado_test pager-1.3 {
2N/A pager_stats $::p1
2N/A} {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 0 ovfl 0}
2N/Ado_test pager-1.4 {
2N/A pager_close $::p1
2N/A} {}
2N/A
2N/A# Try to write a few pages.
2N/A#
2N/Ado_test pager-2.1 {
2N/A set v [catch {
2N/A set ::p1 [pager_open ptf1.db 10]
2N/A } msg]
2N/A} {0}
2N/A#do_test pager-2.2 {
2N/A# set v [catch {
2N/A# set ::g1 [page_get $::p1 0]
2N/A# } msg]
2N/A# lappend v $msg
2N/A#} {1 SQLITE_ERROR}
2N/Ado_test pager-2.3.1 {
2N/A set ::gx [page_lookup $::p1 1]
2N/A} {}
2N/Ado_test pager-2.3.2 {
2N/A pager_stats $::p1
2N/A} {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 0 ovfl 0}
2N/Ado_test pager-2.3.3 {
2N/A set v [catch {
2N/A set ::g1 [page_get $::p1 1]
2N/A } msg]
2N/A if {$v} {lappend v $msg}
2N/A set v
2N/A} {0}
2N/Ado_test pager-2.3.3 {
2N/A pager_stats $::p1
2N/A} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
2N/Ado_test pager-2.3.4 {
2N/A set ::gx [page_lookup $::p1 1]
2N/A expr {$::gx!=""}
2N/A} {1}
2N/Ado_test pager-2.3.5 {
2N/A pager_stats $::p1
2N/A} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
2N/Ado_test pager-2.3.6 {
2N/A expr $::g1==$::gx
2N/A} {1}
2N/Ado_test pager-2.3.7 {
2N/A page_unref $::gx
2N/A pager_stats $::p1
2N/A} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
2N/Ado_test pager-2.4 {
2N/A pager_stats $::p1
2N/A} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
2N/Ado_test pager-2.5 {
2N/A pager_pagecount $::p1
2N/A} {0}
2N/Ado_test pager-2.6 {
2N/A pager_stats $::p1
2N/A} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
2N/Ado_test pager-2.7 {
2N/A page_number $::g1
2N/A} {1}
2N/Ado_test pager-2.8 {
2N/A page_read $::g1
2N/A} {}
2N/Ado_test pager-2.9 {
2N/A page_unref $::g1
2N/A} {}
2N/Ado_test pager-2.10 {
2N/A pager_stats $::p1
2N/A} {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 1 ovfl 0}
2N/Ado_test pager-2.11 {
2N/A set ::g1 [page_get $::p1 1]
2N/A expr {$::g1!=0}
2N/A} {1}
2N/Ado_test pager-2.12 {
2N/A page_number $::g1
2N/A} {1}
2N/Ado_test pager-2.13 {
2N/A pager_stats $::p1
2N/A} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 2 ovfl 0}
2N/Ado_test pager-2.14 {
2N/A set v [catch {
2N/A page_write $::g1 "Page-One"
2N/A } msg]
2N/A lappend v $msg
2N/A} {0 {}}
2N/Ado_test pager-2.15 {
2N/A pager_stats $::p1
2N/A} {ref 1 page 1 max 10 size 1 state 2 err 0 hit 0 miss 2 ovfl 0}
2N/Ado_test pager-2.16 {
2N/A page_read $::g1
2N/A} {Page-One}
2N/Ado_test pager-2.17 {
2N/A set v [catch {
2N/A pager_commit $::p1
2N/A } msg]
2N/A lappend v $msg
2N/A} {0 {}}
2N/Ado_test pager-2.20 {
2N/A pager_stats $::p1
2N/A} {ref 1 page 1 max 10 size -1 state 1 err 0 hit 0 miss 2 ovfl 0}
2N/Ado_test pager-2.19 {
2N/A pager_pagecount $::p1
2N/A} {1}
2N/Ado_test pager-2.21 {
2N/A pager_stats $::p1
2N/A} {ref 1 page 1 max 10 size 1 state 1 err 0 hit 0 miss 2 ovfl 0}
2N/Ado_test pager-2.22 {
2N/A page_unref $::g1
2N/A} {}
2N/Ado_test pager-2.23 {
2N/A pager_stats $::p1
2N/A} {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 2 ovfl 0}
2N/Ado_test pager-2.24 {
2N/A set v [catch {
2N/A page_get $::p1 1
2N/A } ::g1]
2N/A if {$v} {lappend v $::g1}
2N/A set v
2N/A} {0}
2N/Ado_test pager-2.25 {
2N/A page_read $::g1
2N/A} {Page-One}
2N/Ado_test pager-2.26 {
2N/A set v [catch {
2N/A page_write $::g1 {page-one}
2N/A } msg]
2N/A lappend v $msg
2N/A} {0 {}}
2N/Ado_test pager-2.27 {
2N/A page_read $::g1
2N/A} {page-one}
2N/Ado_test pager-2.28 {
2N/A set v [catch {
2N/A pager_rollback $::p1
2N/A } msg]
2N/A lappend v $msg
2N/A} {0 {}}
2N/Ado_test pager-2.29 {
2N/A page_unref $::g1
2N/A set ::g1 [page_get $::p1 1]
2N/A page_read $::g1
2N/A} {Page-One}
2N/Ado_test pager-2.99 {
2N/A pager_close $::p1
2N/A} {}
2N/A
2N/Ado_test pager-3.1 {
2N/A set v [catch {
2N/A set ::p1 [pager_open ptf1.db 15]
2N/A } msg]
2N/A if {$v} {lappend v $msg}
2N/A set v
2N/A} {0}
2N/Ado_test pager-3.2 {
2N/A pager_pagecount $::p1
2N/A} {1}
2N/Ado_test pager-3.3 {
2N/A set v [catch {
2N/A set ::g(1) [page_get $::p1 1]
2N/A } msg]
2N/A if {$v} {lappend v $msg}
2N/A set v
2N/A} {0}
2N/Ado_test pager-3.4 {
2N/A page_read $::g(1)
2N/A} {Page-One}
2N/Ado_test pager-3.5 {
2N/A for {set i 2} {$i<=20} {incr i} {
2N/A set gx [page_get $::p1 $i]
2N/A page_write $gx "Page-$i"
2N/A page_unref $gx
2N/A }
2N/A pager_commit $::p1
2N/A} {}
2N/Afor {set i 2} {$i<=20} {incr i} {
2N/A do_test pager-3.6.[expr {$i-1}] [subst {
2N/A set gx \[page_get $::p1 $i\]
2N/A set v \[page_read \$gx\]
2N/A page_unref \$gx
2N/A set v
2N/A }] "Page-$i"
2N/A}
2N/Afor {set i 1} {$i<=20} {incr i} {
2N/A regsub -all CNT {
2N/A set ::g1 [page_get $::p1 CNT]
2N/A set ::g2 [page_get $::p1 CNT]
2N/A set ::vx [page_read $::g2]
2N/A expr {$::g1==$::g2}
2N/A } $i body;
2N/A do_test pager-3.7.$i.1 $body {1}
2N/A regsub -all CNT {
2N/A page_unref $::g2
2N/A set vy [page_read $::g1]
2N/A expr {$vy==$::vx}
2N/A } $i body;
2N/A do_test pager-3.7.$i.2 $body {1}
2N/A regsub -all CNT {
2N/A page_unref $::g1
2N/A set gx [page_get $::p1 CNT]
2N/A set vy [page_read $gx]
2N/A page_unref $gx
2N/A expr {$vy==$::vx}
2N/A } $i body;
2N/A do_test pager-3.7.$i.3 $body {1}
2N/A}
2N/Ado_test pager-3.99 {
2N/A pager_close $::p1
2N/A} {}
2N/A
2N/A# tests of the checkpoint mechanism and api
2N/A#
2N/Ado_test pager-4.0 {
2N/A set v [catch {
2N/A file delete -force ptf1.db
2N/A set ::p1 [pager_open ptf1.db 15]
2N/A } msg]
2N/A if {$v} {lappend v $msg}
2N/A set v
2N/A} {0}
2N/Ado_test pager-4.1 {
2N/A set g1 [page_get $::p1 1]
2N/A page_write $g1 "Page-1 v0"
2N/A for {set i 2} {$i<=20} {incr i} {
2N/A set gx [page_get $::p1 $i]
2N/A page_write $gx "Page-$i v0"
2N/A page_unref $gx
2N/A }
2N/A pager_commit $::p1
2N/A} {}
2N/Afor {set i 1} {$i<=20} {incr i} {
2N/A do_test pager-4.2.$i {
2N/A set gx [page_get $p1 $i]
2N/A set v [page_read $gx]
2N/A page_unref $gx
2N/A set v
2N/A } "Page-$i v0"
2N/A}
2N/Ado_test pager-4.3 {
2N/A lrange [pager_stats $::p1] 0 1
2N/A} {ref 1}
2N/Ado_test pager-4.4 {
2N/A lrange [pager_stats $::p1] 8 9
2N/A} {state 1}
2N/A
2N/Afor {set i 1} {$i<20} {incr i} {
2N/A do_test pager-4.5.$i.0 {
2N/A set res {}
2N/A for {set j 2} {$j<=20} {incr j} {
2N/A set gx [page_get $p1 $j]
2N/A set value [page_read $gx]
2N/A page_unref $gx
2N/A set shouldbe "Page-$j v[expr {$i-1}]"
2N/A if {$value!=$shouldbe} {
2N/A lappend res $value $shouldbe
2N/A }
2N/A }
2N/A set res
2N/A } {}
2N/A do_test pager-4.5.$i.1 {
2N/A page_write $g1 "Page-1 v$i"
2N/A lrange [pager_stats $p1] 8 9
2N/A } {state 2}
2N/A do_test pager-4.5.$i.2 {
2N/A for {set j 2} {$j<=20} {incr j} {
2N/A set gx [page_get $p1 $j]
2N/A page_write $gx "Page-$j v$i"
2N/A page_unref $gx
2N/A if {$j==$i} {
2N/A pager_ckpt_begin $p1
2N/A }
2N/A }
2N/A } {}
2N/A do_test pager-4.5.$i.3 {
2N/A set res {}
2N/A for {set j 2} {$j<=20} {incr j} {
2N/A set gx [page_get $p1 $j]
2N/A set value [page_read $gx]
2N/A page_unref $gx
2N/A set shouldbe "Page-$j v$i"
2N/A if {$value!=$shouldbe} {
2N/A lappend res $value $shouldbe
2N/A }
2N/A }
2N/A set res
2N/A } {}
2N/A do_test pager-4.5.$i.4 {
2N/A pager_rollback $p1
2N/A set res {}
2N/A for {set j 2} {$j<=20} {incr j} {
2N/A set gx [page_get $p1 $j]
2N/A set value [page_read $gx]
2N/A page_unref $gx
2N/A set shouldbe "Page-$j v[expr {$i-1}]"
2N/A if {$value!=$shouldbe} {
2N/A lappend res $value $shouldbe
2N/A }
2N/A }
2N/A set res
2N/A } {}
2N/A do_test pager-4.5.$i.5 {
2N/A page_write $g1 "Page-1 v$i"
2N/A lrange [pager_stats $p1] 8 9
2N/A } {state 2}
2N/A do_test pager-4.5.$i.6 {
2N/A for {set j 2} {$j<=20} {incr j} {
2N/A set gx [page_get $p1 $j]
2N/A page_write $gx "Page-$j v$i"
2N/A page_unref $gx
2N/A if {$j==$i} {
2N/A pager_ckpt_begin $p1
2N/A }
2N/A }
2N/A } {}
2N/A do_test pager-4.5.$i.7 {
2N/A pager_ckpt_rollback $p1
2N/A for {set j 2} {$j<=20} {incr j} {
2N/A set gx [page_get $p1 $j]
2N/A set value [page_read $gx]
2N/A page_unref $gx
2N/A if {$j<=$i || $i==1} {
2N/A set shouldbe "Page-$j v$i"
2N/A } else {
2N/A set shouldbe "Page-$j v[expr {$i-1}]"
2N/A }
2N/A if {$value!=$shouldbe} {
2N/A lappend res $value $shouldbe
2N/A }
2N/A }
2N/A set res
2N/A } {}
2N/A do_test pager-4.5.$i.8 {
2N/A for {set j 2} {$j<=20} {incr j} {
2N/A set gx [page_get $p1 $j]
2N/A page_write $gx "Page-$j v$i"
2N/A page_unref $gx
2N/A if {$j==$i} {
2N/A pager_ckpt_begin $p1
2N/A }
2N/A }
2N/A } {}
2N/A do_test pager-4.5.$i.9 {
2N/A pager_ckpt_commit $p1
2N/A for {set j 2} {$j<=20} {incr j} {
2N/A set gx [page_get $p1 $j]
2N/A set value [page_read $gx]
2N/A page_unref $gx
2N/A set shouldbe "Page-$j v$i"
2N/A if {$value!=$shouldbe} {
2N/A lappend res $value $shouldbe
2N/A }
2N/A }
2N/A set res
2N/A } {}
2N/A do_test pager-4.5.$i.10 {
2N/A pager_commit $p1
2N/A lrange [pager_stats $p1] 8 9
2N/A } {state 1}
2N/A}
2N/A
2N/Ado_test pager-4.99 {
2N/A pager_close $::p1
2N/A} {}
2N/A
2N/A
2N/A
2N/A file delete -force ptf1.db
2N/A
2N/A} ;# end if( not mem: and has pager_open command );
2N/A
2N/A# Ticket #615: an assertion fault inside the pager. It is a benign
2N/A# fault, but we might as well test for it.
2N/A#
2N/Ado_test pager-5.1 {
2N/A sqlite db test.db
2N/A execsql {
2N/A BEGIN;
2N/A CREATE TABLE t1(x);
2N/A PRAGMA synchronous=off;
2N/A COMMIT;
2N/A }
2N/A} {}
2N/A
2N/A
2N/Afinish_test