From: dan Date: Mon, 7 Jun 2010 06:11:39 +0000 (+0000) Subject: Add a couple of extra coverage tests for wal.c. X-Git-Tag: version-3.7.2~292 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=23f719207f7e109f42ac17c976d264b4d97ea272;p=thirdparty%2Fsqlite.git Add a couple of extra coverage tests for wal.c. FossilOrigin-Name: cfe60254df50f086014b115f1a2d9e31c85d67fd --- diff --git a/manifest b/manifest index bc0be6d2d4..54dd3cb2e9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sfurther\stest\scases\sfor\sthe\slogic\sin\ssqlite3WalBeginReadTransaction(). -D 2010-06-05T19:18:59 +C Add\sa\scouple\sof\sextra\scoverage\stests\sfor\swal.c. +D 2010-06-07T06:11:40 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in a5cad1f8f3e021356bfcc6c77dc16f6f1952bbc3 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -762,8 +762,8 @@ F test/vtab_alter.test 9e374885248f69e251bdaacf480b04a197f125e5 F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8 F test/vtab_shared.test 0eff9ce4f19facbe0a3e693f6c14b80711a4222d F test/wal.test bfec61450b47cdf09f7d2269f9e9967683b8b0fc -F test/wal2.test 743d9b86041e57ba986dd7e3891c67725f9e2b2b -F test/wal3.test b82ac8268bac644d1d928d25316e5e7696ec47bf +F test/wal2.test f70bbe268891a70cc40dce659efe617e548c7491 +F test/wal3.test 887737b05f0aa37962182bf8c5e86f7342e1d386 F test/wal_common.tcl 3e953ae60919281688ea73e4d0aa0e1bc94becd9 F test/walbak.test e7650a26eb4b8abeca9b145b1af1e63026dde432 F test/walcksum.test 4efa8fb88c32bed8288ea4385a9cc113a5c8f0bf @@ -817,7 +817,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P c041c6a9786bc9ebb82527f7a2c96d255aec927f -R b34f0ea46ed4ddc81ab394ae4b47f8c2 +P a49713db39d0d6940b368206d4e669aa69aa1fe5 +R 2237cb7054d794b2f2b9d3b4c056e5fd U dan -Z b9b05ea832538d97e39aa0947439a601 +Z 13a82a94e40f48f124ae3e9a80db14d5 diff --git a/manifest.uuid b/manifest.uuid index 786185fab6..a3d609491d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a49713db39d0d6940b368206d4e669aa69aa1fe5 \ No newline at end of file +cfe60254df50f086014b115f1a2d9e31c85d67fd \ No newline at end of file diff --git a/test/wal2.test b/test/wal2.test index c6cbe394c2..595779049a 100644 --- a/test/wal2.test +++ b/test/wal2.test @@ -24,16 +24,20 @@ proc set_tvfs_hdr {file args} { set nHdr 40 set nInt [expr {$nHdr/4}] - if {[llength $args]>1} { - return -code error {wrong # args: should be "set_tvfs_hdr fileName ?val?"} + if {[llength $args]>2} { + error {wrong # args: should be "set_tvfs_hdr fileName ?val1? ?val2?"} } set blob [tvfs shm $file] if {[llength $args]} { set ia [lindex $args 0] + set ib $ia + if {[llength $args]==2} { + set ib [lindex $args 1] + } binary scan $blob a[expr $nHdr*2]a* dummy tail - set blob [binary format i${nInt}i${nInt}a* $ia $ia $tail] + set blob [binary format i${nInt}i${nInt}a* $ia $ib $tail] tvfs shm $file $blob } @@ -843,9 +847,9 @@ db close # Test that even if the checksums for both are valid, if the two copies # of the wal-index header in the wal-index do not match, the client # runs (or at least tries to run) database recovery. +# # - -proc get_name {method args} { set ::filename [lindex $args 0] } +proc get_name {method args} { set ::filename [lindex $args 0] ; tvfs filter {} } testvfs tvfs tvfs script get_name tvfs filter xShmOpen @@ -859,40 +863,39 @@ do_test wal2-9.1 { INSERT INTO x VALUES('Barton'); INSERT INTO x VALUES('Deakin'); } - set wal_index_hdr1 [string range [tvfs shm $::filename] 0 39] + + # Set $wih(1) to the contents of the wal-index header after + # the frames associated with the first two rows in table 'x' have + # been inserted. Then insert one more row and set $wih(2) + # to the new value of the wal-index header. + # + # If the $wih(1) is written into the wal-index before running + # a read operation, the client will see only the first two rows. If + # $wih(2) is written into the wal-index, the client will see + # three rows. If an invalid header is written into the wal-index, then + # the client will run recovery and see three rows. + # + set wih(1) [set_tvfs_hdr $::filename] execsql { INSERT INTO x VALUES('Watson') } -} {} -do_test wal2-9.2 { + set wih(2) [set_tvfs_hdr $::filename] + sqlite3 db2 test.db -vfs tvfs execsql { SELECT * FROM x } db2 } {Barton Deakin Watson} -do_test wal2-9.3 { - set wal_index_hdr2 [string range [tvfs shm $::filename] 0 39] - set content [string range [tvfs shm $::filename] 80 end] - set w [binary format a*a*a* $wal_index_hdr1 $wal_index_hdr1 $content] - tvfs shm $::filename $w - execsql { SELECT * FROM x } db2 -} {Barton Deakin} -do_test wal2-9.4 { - set w [binary format a*a*a* $wal_index_hdr2 $wal_index_hdr2 $content] - tvfs shm $::filename $w - execsql { SELECT * FROM x } db2 -} {Barton Deakin Watson} -do_test wal2-9.5 { - set w [binary format a*a*a* $wal_index_hdr1 $wal_index_hdr2 $content] - tvfs shm $::filename $w - execsql { SELECT * FROM x } db2 -} {Barton Deakin Watson} -do_test wal2-9.6 { - set w [binary format a*a*a* $wal_index_hdr2 $wal_index_hdr1 $content] - tvfs shm $::filename $w - execsql { SELECT * FROM x } db2 -} {Barton Deakin Watson} -do_test wal2-9.7 { - set w [binary format a*a*a* $wal_index_hdr1 $wal_index_hdr1 $content] - tvfs shm $::filename $w - execsql { SELECT * FROM x } db2 -} {Barton Deakin} + +foreach {tn hdr1 hdr2 res} [list \ + 3 $wih(1) $wih(1) {Barton Deakin} \ + 4 $wih(1) $wih(2) {Barton Deakin Watson} \ + 5 $wih(2) $wih(1) {Barton Deakin Watson} \ + 6 $wih(2) $wih(2) {Barton Deakin Watson} \ + 7 $wih(1) $wih(1) {Barton Deakin} \ + 8 {0 0 0 0 0 0 0 0 0 0} {0 0 0 0 0 0 0 0 0 0} {Barton Deakin Watson} \ +] { + do_test wal2-9.$tn { + set_tvfs_hdr $::filename $hdr1 $hdr2 + execsql { SELECT * FROM x } db2 + } $res +} db2 close db close diff --git a/test/wal3.test b/test/wal3.test index 746175d391..5cba55ad2f 100644 --- a/test/wal3.test +++ b/test/wal3.test @@ -635,5 +635,136 @@ db close db2 close T delete +#------------------------------------------------------------------------- +# +do_test wal3-8.1 { + file delete -force test.db test.db-journal test.db wal + sqlite3 db test.db + sqlite3 db2 test.db + execsql { + PRAGMA journal_mode = WAL; + CREATE TABLE b(c); + INSERT INTO b VALUES('Tehran'); + INSERT INTO b VALUES('Qom'); + INSERT INTO b VALUES('Markazi'); + PRAGMA wal_checkpoint; + } +} {wal} +do_test wal3-8.2 { + execsql { SELECT * FROM b } +} {Tehran Qom Markazi} +do_test wal3-8.3 { + db eval { SELECT * FROM b } { + db eval { INSERT INTO b VALUES('Qazvin') } + set r [db2 eval { SELECT * FROM b }] + break + } + set r +} {Tehran Qom Markazi Qazvin} +do_test wal3-8.4 { + execsql { + INSERT INTO b VALUES('Gilan'); + INSERT INTO b VALUES('Ardabil'); + } +} {} +db2 close + +faultsim_save_and_close +testvfs T -default 1 +faultsim_restore_and_reopen +T filter xShmLock +T script lock_callback + +proc lock_callback {method file handle spec} { + if {$spec == "4 1 unlock exclusive"} { + T filter {} + set ::r [catchsql { SELECT * FROM b } db2] + } +} +sqlite3 db test.db +sqlite3 db2 test.db +do_test wal3-8.5 { + execsql { SELECT * FROM b } +} {Tehran Qom Markazi Qazvin Gilan Ardabil} +do_test wal3-8.6 { + set ::r +} {1 {locking protocol}} + +db close +db2 close + +faultsim_restore_and_reopen +sqlite3 db2 test.db +T filter xShmLock +T script lock_callback +proc lock_callback {method file handle spec} { + if {$spec == "1 7 unlock exclusive"} { + T filter {} + set ::r [catchsql { SELECT * FROM b } db2] + } +} +unset ::r +do_test wal3-8.5 { + execsql { SELECT * FROM b } +} {Tehran Qom Markazi Qazvin Gilan Ardabil} +do_test wal3-8.6 { + set ::r +} {1 {locking protocol}} + +db close +db2 close +T delete + +#------------------------------------------------------------------------- +# When a connection opens a read-lock on the database, it searches for +# an aReadMark[] slot that is already set to the mxFrame value for the +# new transaction. If it cannot find one, it attempts to obtain an +# exclusive lock on an aReadMark[] slot for the purposes of modifying +# the value, then drops back to a shared-lock for the duration of the +# transaction. +# +# This test case verifies that if an exclusive lock cannot be obtained +# on any aReadMark[] slot (because there are already several readers), +# the client takes a shared-lock on a slot without modifying the value +# and continues. +# +do_test wal3-9.0 { + file delete -force test.db test.db-journal test.db wal + sqlite3 db test.db + execsql { + PRAGMA journal_mode = WAL; + CREATE TABLE whoami(x); + INSERT INTO whoami VALUES('nobody'); + } +} {wal} +for {set i 0} {$i < 50} {incr i} { + set c db$i + do_test wal3-9.1.$i { + sqlite3 $c test.db + execsql { UPDATE whoami SET x = $c } + execsql { + BEGIN; + SELECT * FROM whoami + } $c + } $c +} +for {set i 0} {$i < 50} {incr i} { + set c db$i + do_test wal3-9.2.$i { + execsql { SELECT * FROM whoami } $c + } $c +} +do_test wal3-9.3 { + for {set i 0} {$i < 49} {incr i} { db$i close } + execsql { PRAGMA wal_checkpoint } + set sz1 [file size test.db] + db49 close + execsql { PRAGMA wal_checkpoint } + set sz2 [file size test.db] + expr {$sz2 > $sz1} +} {1} + +db close + finish_test