From: larrybr Date: Mon, 8 Mar 2021 14:32:26 +0000 (+0000) Subject: Added test/avfs.test (missing from branch merge for some reason.) X-Git-Tag: version-3.35.0~31 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b47e4c2819548dae7f7e7d21543337b87358b3e8;p=thirdparty%2Fsqlite.git Added test/avfs.test (missing from branch merge for some reason.) FossilOrigin-Name: 08fa67053c20d223c9b5334fe2e85adc95588b91046c100d7fe8e8e2535e485f --- diff --git a/manifest b/manifest index c40f25dac0..fa636cd04c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\sappendvfs\supdates\sand\stesting. -D 2021-03-08T14:26:22.390 +C Added\stest/avfs.test\s(missing\sfrom\sbranch\smerge\sfor\ssome\sreason.) +D 2021-03-08T14:32:26.373 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -699,6 +699,7 @@ F test/autoindex4.test 49d3cd791a9baa16fb461d7ea3de80d019a819cf F test/autoindex5.test a5d72fe8c217cc0ea356dc6fa06a282a8a3fc53aa807709d79dba07a8f248102 F test/autovacuum.test 0831cd34e14695d297187f7f6519265e3121c5b0a1720e548e86829e796129e9 F test/autovacuum_ioerr2.test 8a367b224183ad801e0e24dcb7d1501f45f244b4 +F test/avfs.test fcef698d4363182e54f4288c09799313c7b8074db81804a8e0680d4739607ff0 F test/avtrans.test b7dc25459ecbd86c6fa9c606ee3068f59d81e225118617dcf2bbb6ded2ade89e F test/backcompat.test 3e64cedda754c778ef6bbe417b6e7a295e662a4d F test/backup.test dd4a5ff756e3df3931dacb1791db0584d4bad989 @@ -1909,7 +1910,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5ddd8032ef9ecd5b53909d304c8f1375a72f270fd7810964cb4e385e25bedd4f aeb87cc70495dd172e170eff31fd754331d4b979c0b649ab239f8c5c0c76e695 -R 8ccab392163487da9b54671965ff97af +P 63fcf301fedf1f3708e2226ed499a53b3e9c1d2cc2b17d4b0b736e36aff0ae74 +R 95e6ca76a30ea77bdd3f5fbf1f80121b U larrybr -Z 884cfbe97fea0184c4337b606da309e4 +Z 49c48cadd3907bebdbe489bc225ec6e8 diff --git a/manifest.uuid b/manifest.uuid index 91a73abd3d..06894446de 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -63fcf301fedf1f3708e2226ed499a53b3e9c1d2cc2b17d4b0b736e36aff0ae74 \ No newline at end of file +08fa67053c20d223c9b5334fe2e85adc95588b91046c100d7fe8e8e2535e485f \ No newline at end of file diff --git a/test/avfs.test b/test/avfs.test new file mode 100644 index 0000000000..bf647990ee --- /dev/null +++ b/test/avfs.test @@ -0,0 +1,255 @@ +# 2021-03-06 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests for the appendvfs extension. +# +# Tests performed: +# avfs-1.0. Test that an appendvfs DB can be added to an empty file. +# avfs-1.1. Test that the DB can be read with correct content upon reopen. +# avfs-1.2. Test that an appendvfs DB can be added to a simple text file. +# avfs-1.3. Test that the DB can be read with correct content upon reopen. +# avfs-2.1. Test that the simple text file retains its initial text. +# avfs-3.1. Test that the appendvfs can grow and shrink, remaining intact. +# avfs-3.2. Test that appendvfs is intact after grow/shrink/close/reopen. +# avfs-4.1. Test shell's ability to append to a non-appendvfs file. +# avfs-4.2. Test shell's ability to append to empty or nonexistent file. +# avfs-4.3. Test shell's ability to reopen and alter an appendvfs file. +# ... +# (more to come) + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix avfs +set CLI [test_find_cli] +db close +forcedelete test.db + +load_static_extension db appendvfs + +set ::fa avfs.adb +set ::fza avfs.sdb +forcedelete $::fa $::fza +set ::result {} + +set ::vf "&vfs=apndvfs" + +# Return file offset of appendvfs portion of a file, or {} if none such. +proc fosAvfs {fname} { + if {[file size $fname] < 25} { + return {} + } + if {[catch {set fd [open $fname rb]}]} { + return {} + } + seek $fd -25 end + set am [read $fd 17] + set ao [read $fd 8] + close $fd + if {$am ne "Start-Of-SQLite3-"} { + return {} + } + binary scan $ao "W" rvo + return $rvo +} + +do_test 1.0 { + set results {} + set out [open $::fza wb] + close $out + sqlite3 adb "file:$::fza?mode=rwc$::vf" -uri 1 + adb eval { + PRAGMA page_size=1024; + PRAGMA cache_size=10; + CREATE TABLE t1(a TEXT); + INSERT INTO t1 VALUES ('dog'),('cat'); + SELECT group_concat(a) as pets FROM (SELECT a FROM t1 ORDER BY a); + } { lappend results $pets } + adb close + lappend results [fosAvfs $fza] + set ::result [join $results " | "] +} {cat,dog | 0} + +do_test 1.1 { + set results {} + sqlite3 adb "file:$::fza?mode=rw$::vf" -uri 1 + adb eval { + SELECT group_concat(a) as pets FROM (SELECT a FROM t1 ORDER BY a DESC); + } { lappend results $pets } + adb close + set ::result [join $results " | "] +} {dog,cat} + +do_test 1.2 { + set results {} + set out [open $::fa wb] + set ::tlo { "Just some text," "and more text," "ending at 3 lines." } + puts $out [join $::tlo "\n"] + close $out + set adbSz [file size $::fa] + sqlite3 adb "file:$::fa?mode=rwc$::vf" -uri 1 + adb eval { + PRAGMA page_size=512; + PRAGMA cache_size=0; + CREATE TABLE t1(a TEXT); + INSERT INTO t1 VALUES ('dog'),('cat'),('pig'); + SELECT group_concat(a) as pets FROM (SELECT a FROM t1 ORDER BY a); + } { lappend results $pets } + adb close + set adaSz [file size $::fa] + lappend results "Bytes before/after $adbSz/$adaSz" + set ::result [join $results " | "] +} {cat,dog,pig | Bytes before/after 50/5145} + +do_test 1.3 { + set results {} + sqlite3 adb "file:$::fa?mode=rw$::vf" -uri 1 + adb eval { + SELECT group_concat(a) as pets FROM (SELECT a FROM t1 ORDER BY a DESC); + } { lappend results $pets } + adb close + lappend results [fosAvfs $fa] + set ::result [join $results " | "] +} {pig,dog,cat | 4096} + +do_test 2.1 { + set in [open $::fa r] + set tli {} + for {set i [llength $::tlo]} {$i > 0} {incr i -1} { + lappend tli [gets $in] + } + close $in + if { [join $tli ":"] ne [join $::tlo ":"] } { + set ::result "Appendee changed." + } else { + set ::result "Appendee intact." + } +} {Appendee intact.} + +# Set of repeatable random integers for a couple tests. +proc rint {v} { + return [::tcl::mathfunc::int [expr $v * 100000]] +} +array set ::randints [list 0 [rint [::tcl::mathfunc::srand 0]]] +for {set i 1} {$i < 10000} {incr i} { + set ::randints($i) [rint [::tcl::mathfunc::rand]] +} + +do_test 3.1 { + set results {} + sqlite3 adb "file:$::fa?mode=rw$::vf" -uri 1 + adb eval { + DROP TABLE t1; + PRAGMA cache_size=10; + CREATE TABLE ri (i INTEGER); + BEGIN; + } + for {set i 0} {$i < 10000} {incr i} { + set r $::randints($i) + set s $::randints([incr i]) + set t $::randints([incr i]) + set u $::randints([incr i]) + set v $::randints([incr i]) + adb eval { + INSERT INTO ri VALUES ($r),($s),($t),($u),($v) + } + } + adb eval { + COMMIT; + SELECT integrity_check as ic FROM pragma_integrity_check(); + } { lappend results $ic } + set adbSz [file size $::fa] + set qr {} + adb eval { + SELECT count(*) as ic FROM ri; + DELETE FROM ri WHERE (i % 50) <> 25; + SELECT integrity_check as ic FROM pragma_integrity_check(); + VACUUM; + SELECT integrity_check as ic FROM pragma_integrity_check(); + SELECT count(*) as ic FROM ri; + } { lappend qr $ic } + adb close + set adaSz [file size $::fa] + set adba [expr ($adbSz + 0.1)/$adaSz] + # lappend results $adbSz $adaSz + set results [concat $results [lrange $qr 0 2]] + lappend results [expr {$adba > 10.0 && $adba < 20.0}] + set ::result [join $results " | "] +} {ok | 10000 | ok | ok | 1} + +do_test 3.2 { + set results {} + sqlite3 adb "file:$::fa?mode=rw$::vf" -uri 1 + adb eval { + SELECT integrity_check as ic FROM pragma_integrity_check(); + } { lappend results $ic } + adb close + set ::result [join $results " | "] +} {ok} + +do_test 4.1 { + set shdo "sh_app1.sql" + set shod "sh_app1.adb" + forcedelete $shdo $shod + set ofd [open $shdo w] + puts $ofd ".ar -c" + puts $ofd ".tables" + puts $ofd ".q" + close $ofd + set ofd [open $shod wb] + puts $ofd "Some text." + close $ofd + set res [catchcmd "-append -batch -init $shdo $shod" ""] + lappend res [fosAvfs $shod] + forcedelete $shdo $shod + set ::result [join $res " | "] +} {0 | sqlar | 4096} + +do_test 4.2 { + set shdo "sh_app1.sql" + set shod "sh_app1.adb" + forcedelete $shdo $shod + set ofd [open $shdo w] + puts $ofd ".ar -c" + puts $ofd ".tables" + puts $ofd ".q" + close $ofd + set ofd [open $shod wb] + close $ofd + set res [catchcmd "-append -batch -init $shdo $shod" ""] + lappend res [fosAvfs $shod] + forcedelete $shdo ; # Leave $shod for next test. + set ::result [join $res " | "] +} {0 | sqlar | 0} + +do_test 4.3 { + set shdo "sh_app1.sql" + set shod "sh_app1.adb" ; # Same as test 4.2, reusing ADB. + forcedelete $shdo + set ofd [open $shdo w] + puts $ofd ".ar -u $shdo" + puts $ofd "select count(*) from sqlar where name = '$shdo';" + puts $ofd ".q" + close $ofd + set res [catchcmd "-append -batch -init $shdo $shod" ""] + sqlite3 adb "file:$shod?mode=rw$::vf" -uri 1 + adb eval { + SELECT count(*) as n FROM sqlar + } { lappend res $n } + adb close + forcedelete $shdo $shod; + set ::result [join $res " | "] +} {0 | 1 | 1} + +forcedelete $::fa $::fza + +unset -nocomplain ::fa ::fza ::tlo ::result ::randints + +finish_test