From: dan Date: Wed, 26 Dec 2018 17:49:57 +0000 (+0000) Subject: Add a few more test cases to walvfs.test. X-Git-Tag: version-3.27.0~244 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=89dec01e4867f2ab888bc33adbf4a65c2cf7b16a;p=thirdparty%2Fsqlite.git Add a few more test cases to walvfs.test. FossilOrigin-Name: 14a64df36efe0dc36795311d58385f9c65dc465b214059e07c2ee6b95ea99c87 --- diff --git a/manifest b/manifest index 9a7dcdc8f0..1faeea8276 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\san\s"unitialized\svalue\sread"\sproblem\sin\sfts5\sthat\scan\soccur\swith\sa\ncorrupt\sdatabase. -D 2018-12-26T16:57:47.391 +C Add\sa\sfew\smore\stest\scases\sto\swalvfs.test. +D 2018-12-26T17:49:57.369 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in d8b254f8bb81bab43c340d70d17dc3babab40fcc8a348c8255881f780a45fee6 @@ -566,7 +566,7 @@ F src/test_syscall.c 1073306ba2e9bfc886771871a13d3de281ed3939 F src/test_tclsh.c 06317648b0d85a85fd823f7973b55535c59a3156c1ef59394fe511f932cfa78d F src/test_tclvar.c 33ff42149494a39c5fbb0df3d25d6fafb2f668888e41c0688d07273dcb268dfc F src/test_thread.c 911d15fb14e19c0c542bdc8aabf981c2f10a4858 -F src/test_vfs.c 4c02cd8457e29fab36ab4101535fa6ba380299bae35cd594def9d3df9b1de946 +F src/test_vfs.c c6c6a58f66b26876c7b5769fb323a58b2c7120299b5084e7212c4116f902cbaa F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698 F src/test_windirent.c a895e2c068a06644eef91a7f0a32182445a893b9a0f33d0cdb4283dca2486ac1 F src/test_windirent.h 90dfbe95442c9762357fe128dc7ae3dc199d006de93eb33ba3972e0a90484215 @@ -1634,7 +1634,7 @@ F test/walrofault.test c70cb6e308c443867701856cce92ad8288cd99488fa52afab77cca6cf F test/walshared.test 0befc811dcf0b287efae21612304d15576e35417 F test/walslow.test c05c68d4dc2700a982f89133ce103a1a84cc285f F test/walthread.test 14b20fcfa6ae152f5d8e12f5dc8a8a724b7ef189f5d8ef1e2ceab79f2af51747 -F test/walvfs.test 238920d258d5aa9327a08d61721c3f12273c821c2f537d7e91f21982f86f65e6 +F test/walvfs.test c0faffda13d045a96dfc541347886bb1a3d6f3205857fc98e683edfab766ea88 F test/where.test 8215d220633f08da331781cf9ede7fb7aed50eb113473c10acd39a643fd258ba F test/where2.test 478d2170637b9211f593120648858593bf2445a1 F test/where3.test 2341a294e17193a6b1699ea7f192124a5286ca6acfcc3f4b06d16c931fbcda2c @@ -1794,7 +1794,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 9bad745d373f4686a2726c3f77a2ccad60e7181645d7ed483a2e43075a4ef30c -R af614ee0c541623b14b452f16a3d180b +P 6cae81cd1ffb0180e0260d5ba921502c7dee2f54637bff3558a4d1cb5dfd3f32 +R c36b08f16a117e4abeb7fdc6926070c6 U dan -Z eecd655d888913690f7b7084cee8af3a +Z 91f513680519082fc3e014da1dc90f66 diff --git a/manifest.uuid b/manifest.uuid index abf5366120..7aa5beccaa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6cae81cd1ffb0180e0260d5ba921502c7dee2f54637bff3558a4d1cb5dfd3f32 \ No newline at end of file +14a64df36efe0dc36795311d58385f9c65dc465b214059e07c2ee6b95ea99c87 \ No newline at end of file diff --git a/src/test_vfs.c b/src/test_vfs.c index b741b33dd5..bf9fa6b537 100644 --- a/src/test_vfs.c +++ b/src/test_vfs.c @@ -234,6 +234,7 @@ static int tvfsResultCode(Testvfs *p, int *pRc){ { SQLITE_LOCKED, "SQLITE_LOCKED" }, { SQLITE_BUSY, "SQLITE_BUSY" }, { SQLITE_READONLY, "SQLITE_READONLY" }, + { SQLITE_READONLY_CANTINIT, "SQLITE_READONLY_CANTINIT" }, }; const char *z; @@ -919,7 +920,9 @@ static int tvfsShmMap( if( rc==SQLITE_OK && isWrite && !pFd->pShm->aPage[iPage] ){ tvfsAllocPage(pFd->pShm, iPage, pgsz); } - *pp = (void volatile *)pFd->pShm->aPage[iPage]; + if( rc==SQLITE_OK || rc==SQLITE_READONLY ){ + *pp = (void volatile *)pFd->pShm->aPage[iPage]; + } return rc; } diff --git a/test/walvfs.test b/test/walvfs.test index f41f4cbeaf..cb8005c1c6 100644 --- a/test/walvfs.test +++ b/test/walvfs.test @@ -33,6 +33,7 @@ proc xSync {method file args} { } } + #------------------------------------------------------------------------- # Test that if IOCAP_SEQUENTIAL is set, the wal-header is not synced to # disk immediately after it is written. @@ -105,6 +106,8 @@ do_test 2.3 { #------------------------------------------------------------------------- # Test that a checkpoint may be interrupted using sqlite3_interrupt(). +# And that the error code is SQLITE_NOMEM, not SQLITE_INTERRUPT, if +# an OOM error occurs just before the sqlite3_interrupt() call. # reset_db db close @@ -137,6 +140,23 @@ do_catchsql_test 3.1 { PRAGMA wal_checkpoint } {1 interrupted} +set ::cnt 2 +proc xWrite {method file args} { + if {[file tail $file]=="test.db"} { + incr ::cnt -1 + if {$::cnt==0} { + sqlite3_memdebug_fail 5 -repeat 0 + catchsql { SELECT 'a big long string!' } + sqlite3_interrupt db + } + } + return SQLITE_OK +} + +do_catchsql_test 3.2 { + PRAGMA wal_checkpoint +} {1 {out of memory}} + #------------------------------------------------------------------------- # reset_db @@ -235,6 +255,35 @@ do_test 5.4 { execsql { SELECT count(*) FROM t1 } } {20} +vfs_set_readmark db main 1 100 +vfs_set_readmark db main 2 100 +vfs_set_readmark db main 3 100 +vfs_set_readmark db main 4 100 + +tvfs script xShmMapLock +tvfs filter {xShmLock xShmMap} +proc xShmMapLock {method args} { + if {$method=="xShmMap"} { + return "SQLITE_READONLY" + } + return SQLITE_BUSY +} + +sqlite3 db2 test.db -vfs tvfs +breakpoint +do_test 5.5 { + list [catch { execsql { SELECT count(*) FROM t1 } db2 } msg] $msg +} {1 {attempt to write a readonly database}} + +tvfs filter {} +vfs_set_readmark db main 1 1 + +do_test 5.6 { + list [catch { execsql { SELECT count(*) FROM t1 } db2 } msg] $msg +} {0 20} +db2 close +db close + #------------------------------------------------------------------------- # Cause an SQLITE_PROTOCOL while attempting to restart the wal file. # @@ -259,6 +308,7 @@ do_test 6.1 { } {} tvfs filter xShmLock +tvfs script xShmLock set ::flag 0 proc xShmLock {method file handle spec} { if {$::flag && [lrange $spec 2 end]=="lock shared"} { @@ -306,7 +356,74 @@ do_execsql_test 7.1 { PRAGMA wal_checkpoint } {1 -1 -1} +#------------------------------------------------------------------------- +# Check that the page cache is correctly flushed if a checkpointer using +# a version 2 VFS makes a checkpoint with an out-of-date cache. +# +reset_db +testvfs tvfs2 -iversion 2 +db close +sqlite3 db test.db -vfs tvfs2 +do_execsql_test 8.0 { + PRAGMA auto_vacuum = 0; + PRAGMA page_size = 1024; + CREATE TABLE t1(x); + PRAGMA journal_mode = wal; + WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 20 ) + INSERT INTO t1 SELECT randomblob(75) FROM s; +} {wal} + +do_execsql_test 8.1 { SELECT count(*) FROM t1 } {20} + +do_test 8.2 { + sqlite3 db2 test.db -vfs tvfs2 + execsql { + INSERT INTO t1 VALUES(randomblob(75)); + } db2 + db2 close +} {} + +do_execsql_test 8.3 { + PRAGMA wal_checkpoint; + SELECT count(*) FROM t1 +} {0 5 5 21} +tvfs2 delete + +#------------------------------------------------------------------------- +reset_db +db close +sqlite3 db test.db -vfs tvfs +do_execsql_test 9.0 { + PRAGMA auto_vacuum = 0; + PRAGMA page_size = 1024; + CREATE TABLE t1(x); + PRAGMA journal_mode = wal; + WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 20 ) + INSERT INTO t1 SELECT randomblob(75) FROM s; +} {wal} + +sqlite3 db2 test.db -vfs tvfs +tvfs filter {xShmMap xShmLock} +tvfs script xShmMap +proc xShmMap {method file handle args} { + switch -- $method { + xShmMap { + return "SQLITE_READONLY_CANTINIT" + } + xShmLock { + if {$args=="{3 1 lock shared}"} { + return "SQLITE_IOERR" + } + } + } +} + +do_test 9.1 { + catchsql { SELECT count(*) FROM t1 } db2 +} {1 {disk I/O error}} + db close +db2 close tvfs delete finish_test