2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A# The author disclaims copyright to this source code. In place of
2N/A# a legal notice, here is a blessing:
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# This file implements regression tests for SQLite library. The
2N/A# focus of this script is page cache subsystem.
2N/Aset testdir [file dirname $argv0]
2N/Aif {[info commands pager_open]!=""} {
2N/A# Basic sanity check. Open and close a pager.
2N/A} {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 0 ovfl 0}
2N/A pager_pagecount $::p1
2N/A} {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 0 ovfl 0}
2N/A# Try to write a few pages.
2N/A# set ::g1 [page_get $::p1 0]
2N/Ado_test pager-2.3.1 {
2N/A set ::gx [page_lookup $::p1 1]
2N/Ado_test pager-2.3.2 {
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 ::g1 [page_get $::p1 1]
2N/A if {$v} {lappend v $msg}
2N/Ado_test pager-2.3.3 {
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/Ado_test pager-2.3.5 {
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/Ado_test pager-2.3.7 {
2N/A} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
2N/A} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
2N/A pager_pagecount $::p1
2N/A} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
2N/A} {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 1 ovfl 0}
2N/A set ::g1 [page_get $::p1 1]
2N/A} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 2 ovfl 0}
2N/A page_write $::g1 "Page-One"
2N/A} {ref 1 page 1 max 10 size 1 state 2 err 0 hit 0 miss 2 ovfl 0}
2N/A} {ref 1 page 1 max 10 size -1 state 1 err 0 hit 0 miss 2 ovfl 0}
2N/A pager_pagecount $::p1
2N/A} {ref 1 page 1 max 10 size 1 state 1 err 0 hit 0 miss 2 ovfl 0}
2N/A} {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 2 ovfl 0}
2N/A if {$v} {lappend v $::g1}
2N/A page_write $::g1 {page-one}
2N/A pager_rollback $::p1
2N/A set ::g1 [page_get $::p1 1]
2N/A if {$v} {lappend v $msg}
2N/A pager_pagecount $::p1
2N/A set ::g(1) [page_get $::p1 1]
2N/A if {$v} {lappend v $msg}
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/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/Afor {set i 1} {$i<=20} {incr i} {
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 do_test pager-3.7.$i.1 $body {1}
2N/A set vy [page_read $::g1]
2N/A do_test pager-3.7.$i.2 $body {1}
2N/A set gx [page_get $::p1 CNT]
2N/A set vy [page_read $gx]
2N/A do_test pager-3.7.$i.3 $body {1}
2N/A# tests of the checkpoint mechanism and api
2N/A if {$v} {lappend v $msg}
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/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 lrange [pager_stats $::p1] 0 1
2N/A lrange [pager_stats $::p1] 8 9
2N/Afor {set i 1} {$i<20} {incr i} {
2N/A do_test pager-4.5.$i.0 {
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 set shouldbe "Page-$j v[expr {$i-1}]"
2N/A if {$value!=$shouldbe} {
2N/A lappend res $value $shouldbe
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 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 pager_ckpt_begin $p1
2N/A do_test pager-4.5.$i.3 {
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 set shouldbe "Page-$j v$i"
2N/A if {$value!=$shouldbe} {
2N/A lappend res $value $shouldbe
2N/A do_test pager-4.5.$i.4 {
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 set shouldbe "Page-$j v[expr {$i-1}]"
2N/A if {$value!=$shouldbe} {
2N/A lappend res $value $shouldbe
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 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 pager_ckpt_begin $p1
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 if {$j<=$i || $i==1} {
2N/A set shouldbe "Page-$j v$i"
2N/A set shouldbe "Page-$j v[expr {$i-1}]"
2N/A if {$value!=$shouldbe} {
2N/A lappend res $value $shouldbe
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 pager_ckpt_begin $p1
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 set shouldbe "Page-$j v$i"
2N/A if {$value!=$shouldbe} {
2N/A lappend res $value $shouldbe
2N/A do_test pager-4.5.$i.10 {
2N/A lrange [pager_stats $p1] 8 9
2N/A} ;# end if( not mem: and has pager_open command );
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 PRAGMA synchronous=off;