/ Check-in [14a64df3]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add a few more test cases to walvfs.test.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 14a64df36efe0dc36795311d58385f9c65dc465b214059e07c2ee6b95ea99c87
User & Date: dan 2018-12-26 17:49:57
Context
2018-12-26
18:34
Update the coverage-wal permutation to cover branches enabled by SQLITE_ENABLE_SNAPSHOT. check-in: 6821c61f user: dan tags: trunk
17:49
Add a few more test cases to walvfs.test. check-in: 14a64df3 user: dan tags: trunk
16:57
Avoid an "uninitialized value read" problem in fts5 that can occur with a corrupt database. check-in: 6cae81cd user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/test_vfs.c.

   230    230     } aCode[] = {
   231    231       { SQLITE_OK,       "SQLITE_OK"     },
   232    232       { SQLITE_ERROR,    "SQLITE_ERROR"  },
   233    233       { SQLITE_IOERR,    "SQLITE_IOERR"  },
   234    234       { SQLITE_LOCKED,   "SQLITE_LOCKED" },
   235    235       { SQLITE_BUSY,     "SQLITE_BUSY"   },
   236    236       { SQLITE_READONLY, "SQLITE_READONLY"   },
          237  +    { SQLITE_READONLY_CANTINIT, "SQLITE_READONLY_CANTINIT"   },
   237    238     };
   238    239   
   239    240     const char *z;
   240    241     int i;
   241    242   
   242    243     z = Tcl_GetStringResult(p->interp);
   243    244     for(i=0; i<ArraySize(aCode); i++){
................................................................................
   915    916     if( rc==SQLITE_OK && p->mask&TESTVFS_SHMMAP_MASK && tvfsInjectIoerr(p) ){
   916    917       rc = SQLITE_IOERR;
   917    918     }
   918    919   
   919    920     if( rc==SQLITE_OK && isWrite && !pFd->pShm->aPage[iPage] ){
   920    921       tvfsAllocPage(pFd->pShm, iPage, pgsz);
   921    922     }
   922         -  *pp = (void volatile *)pFd->pShm->aPage[iPage];
          923  +  if( rc==SQLITE_OK || rc==SQLITE_READONLY ){
          924  +    *pp = (void volatile *)pFd->pShm->aPage[iPage];
          925  +  }
   923    926   
   924    927     return rc;
   925    928   }
   926    929   
   927    930   
   928    931   static int tvfsShmLock(
   929    932     sqlite3_file *pFile,

Changes to test/walvfs.test.

    28     28   tvfs filter xSync
    29     29   set ::sync_count 0
    30     30   proc xSync {method file args} {
    31     31     if {[file tail $file]=="test.db-wal"} {
    32     32       incr ::sync_count
    33     33     }
    34     34   }
           35  +
    35     36   
    36     37   #-------------------------------------------------------------------------
    37     38   # Test that if IOCAP_SEQUENTIAL is set, the wal-header is not synced to
    38     39   # disk immediately after it is written.
    39     40   #
    40     41   sqlite3 db test.db -vfs tvfs
    41     42   do_execsql_test 1.0 {
................................................................................
   101    102       INSERT INTO t1 VALUES(randomblob(750));
   102    103     }
   103    104     file size test.db-wal
   104    105   } {8000}
   105    106   
   106    107   #-------------------------------------------------------------------------
   107    108   # Test that a checkpoint may be interrupted using sqlite3_interrupt().
          109  +# And that the error code is SQLITE_NOMEM, not SQLITE_INTERRUPT, if
          110  +# an OOM error occurs just before the sqlite3_interrupt() call.
   108    111   #
   109    112   reset_db
   110    113   db close
   111    114   sqlite3 db test.db -vfs tvfs
   112    115   tvfs filter {}
   113    116   
   114    117   do_execsql_test 3.0 {
................................................................................
   133    136     return SQLITE_OK
   134    137   }
   135    138   
   136    139   do_catchsql_test 3.1 {
   137    140     PRAGMA wal_checkpoint
   138    141   } {1 interrupted}
   139    142   
          143  +set ::cnt 2
          144  +proc xWrite {method file args} {
          145  +  if {[file tail $file]=="test.db"} {
          146  +    incr ::cnt -1
          147  +    if {$::cnt==0} {
          148  +      sqlite3_memdebug_fail 5 -repeat 0
          149  +      catchsql { SELECT 'a big long string!' }
          150  +      sqlite3_interrupt db
          151  +    }
          152  +  }
          153  +  return SQLITE_OK
          154  +}
          155  +
          156  +do_catchsql_test 3.2 {
          157  +  PRAGMA wal_checkpoint
          158  +} {1 {out of memory}}
          159  +
   140    160   #-------------------------------------------------------------------------
   141    161   #
   142    162   reset_db
   143    163   db close
   144    164   do_test 4.0 {
   145    165     sqlite3 db test.db -vfs tvfs
   146    166     execsql {
................................................................................
   230    250     return SQLITE_OK
   231    251   }
   232    252   
   233    253   do_test 5.4 {
   234    254     vfs_set_readmark db main 1 100
   235    255     execsql { SELECT count(*) FROM t1 }
   236    256   } {20}
          257  +
          258  +vfs_set_readmark db main 1 100
          259  +vfs_set_readmark db main 2 100
          260  +vfs_set_readmark db main 3 100
          261  +vfs_set_readmark db main 4 100
          262  +
          263  +tvfs script xShmMapLock
          264  +tvfs filter {xShmLock xShmMap}
          265  +proc xShmMapLock {method args} {
          266  +  if {$method=="xShmMap"} {
          267  +    return "SQLITE_READONLY"
          268  +  }
          269  +  return SQLITE_BUSY
          270  +}
          271  +
          272  +sqlite3 db2 test.db -vfs tvfs
          273  +breakpoint
          274  +do_test 5.5 {
          275  +  list [catch { execsql { SELECT count(*) FROM t1 } db2 } msg] $msg
          276  +} {1 {attempt to write a readonly database}}
          277  +
          278  +tvfs filter {}
          279  +vfs_set_readmark db main 1 1
          280  +
          281  +do_test 5.6 {
          282  +  list [catch { execsql { SELECT count(*) FROM t1 } db2 } msg] $msg
          283  +} {0 20}
          284  +db2 close
          285  +db close
   237    286   
   238    287   #-------------------------------------------------------------------------
   239    288   # Cause an SQLITE_PROTOCOL while attempting to restart the wal file.
   240    289   #
   241    290   reset_db
   242    291   tvfs filter {}
   243    292   db close
................................................................................
   255    304   
   256    305   do_test 6.1 {
   257    306     execsql { PRAGMA wal_checkpoint } 
   258    307     set {} {}
   259    308   } {}
   260    309   
   261    310   tvfs filter xShmLock
          311  +tvfs script xShmLock
   262    312   set ::flag 0
   263    313   proc xShmLock {method file handle spec} {
   264    314     if {$::flag && [lrange $spec 2 end]=="lock shared"} {
   265    315       return SQLITE_BUSY
   266    316     }
   267    317     if {$spec=="3 1 unlock shared"} {
   268    318       set ::flag 1
................................................................................
   302    352     return SQLITE_OK
   303    353   }
   304    354   
   305    355   do_execsql_test 7.1 {
   306    356     PRAGMA wal_checkpoint
   307    357   } {1 -1 -1}
   308    358   
          359  +#-------------------------------------------------------------------------
          360  +# Check that the page cache is correctly flushed if a checkpointer using
          361  +# a version 2 VFS makes a checkpoint with an out-of-date cache.
          362  +#
          363  +reset_db
          364  +testvfs tvfs2 -iversion 2
          365  +db close
          366  +sqlite3 db test.db -vfs tvfs2
          367  +do_execsql_test 8.0 {
          368  +  PRAGMA auto_vacuum = 0;
          369  +  PRAGMA page_size = 1024;
          370  +  CREATE TABLE t1(x);
          371  +  PRAGMA journal_mode = wal;
          372  +  WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 20 )
          373  +  INSERT INTO t1 SELECT randomblob(75) FROM s;
          374  +} {wal}
          375  +
          376  +do_execsql_test 8.1 { SELECT count(*) FROM t1 } {20}
          377  +
          378  +do_test 8.2 {
          379  +  sqlite3 db2 test.db -vfs tvfs2
          380  +  execsql {
          381  +    INSERT INTO t1 VALUES(randomblob(75));
          382  +  } db2
          383  +  db2 close
          384  +} {}
          385  +
          386  +do_execsql_test 8.3 { 
          387  +  PRAGMA wal_checkpoint;
          388  +  SELECT count(*) FROM t1 
          389  +} {0 5 5 21}
          390  +tvfs2 delete
          391  +
          392  +#-------------------------------------------------------------------------
          393  +reset_db
          394  +db close
          395  +sqlite3 db test.db -vfs tvfs
          396  +do_execsql_test 9.0 {
          397  +  PRAGMA auto_vacuum = 0;
          398  +  PRAGMA page_size = 1024;
          399  +  CREATE TABLE t1(x);
          400  +  PRAGMA journal_mode = wal;
          401  +  WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 20 )
          402  +  INSERT INTO t1 SELECT randomblob(75) FROM s;
          403  +} {wal}
          404  +
          405  +sqlite3 db2 test.db -vfs tvfs
          406  +tvfs filter {xShmMap xShmLock}
          407  +tvfs script xShmMap
          408  +proc xShmMap {method file handle args} {
          409  +  switch -- $method {
          410  +    xShmMap {
          411  +      return "SQLITE_READONLY_CANTINIT"
          412  +    }
          413  +    xShmLock {
          414  +      if {$args=="{3 1 lock shared}"} {
          415  +        return "SQLITE_IOERR"
          416  +      }
          417  +    }
          418  +  }
          419  +}
          420  +
          421  +do_test 9.1 {
          422  +  catchsql { SELECT count(*) FROM t1 } db2
          423  +} {1 {disk I/O error}}
          424  +
   309    425   db close
          426  +db2 close
   310    427   tvfs delete
   311    428   finish_test
   312    429