/ Check-in [d697f6f3]
Login

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

Overview
Comment:Add test cases to test file walvfs.test.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d697f6f3ca47350dad30feb529914fc5254fa662ece783408eea963d912918c1
User & Date: dan 2018-12-24 18:51:13
Context
2018-12-24
19:59
Change another fts5 assert() that may fail with a corrupt database to an assert_nc(). check-in: d9653380 user: dan tags: trunk
18:51
Add test cases to test file walvfs.test. check-in: d697f6f3 user: dan tags: trunk
18:10
Always include OP_Explain opcodes in the bytecode when SQLITE_DEBUG is enabled. check-in: d8c1235c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/test_vfs.c.

  1612   1612         (iArg1==0 ? SQLITE_SHM_SHARED : SQLITE_SHM_EXCLUSIVE)
  1613   1613       | (iArg2==0 ? SQLITE_SHM_LOCK : SQLITE_SHM_UNLOCK)
  1614   1614     );
  1615   1615     Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
  1616   1616     return TCL_OK;
  1617   1617   }
  1618   1618   
         1619  +static int SQLITE_TCLAPI test_vfs_set_readmark(
         1620  +  void * clientData,
         1621  +  Tcl_Interp *interp,
         1622  +  int objc,
         1623  +  Tcl_Obj *CONST objv[]
         1624  +){
         1625  +  sqlite3 *db = 0;
         1626  +  int rc = SQLITE_OK;
         1627  +  const char *zDbname = 0;
         1628  +  int iSlot = 0;
         1629  +  int iVal = -1;
         1630  +  sqlite3_file *pFd;
         1631  +  void volatile *pShm = 0;
         1632  +  u32 *aShm;
         1633  +  int iOff;
         1634  +
         1635  +  if( objc!=4 && objc!=5 ){
         1636  +    Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME SLOT ?VALUE?");
         1637  +    return TCL_ERROR;
         1638  +  }
         1639  +
         1640  +  zDbname = Tcl_GetString(objv[2]);
         1641  +  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) 
         1642  +   || Tcl_GetIntFromObj(interp, objv[3], &iSlot)
         1643  +   || (objc==5 && Tcl_GetIntFromObj(interp, objv[4], &iVal))
         1644  +  ){
         1645  +    return TCL_ERROR;
         1646  +  }
         1647  +
         1648  +  sqlite3_file_control(db, zDbname, SQLITE_FCNTL_FILE_POINTER, (void*)&pFd);
         1649  +  if( pFd==0 ){
         1650  +    return TCL_ERROR;
         1651  +  }
         1652  +  rc = pFd->pMethods->xShmMap(pFd, 0, 32*1024, 0, &pShm);
         1653  +  if( rc!=SQLITE_OK ){
         1654  +    Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
         1655  +    return TCL_ERROR;
         1656  +  }
         1657  +  if( pShm==0 ){
         1658  +    Tcl_AppendResult(interp, "*-shm is not yet mapped", 0);
         1659  +    return TCL_ERROR;
         1660  +  }
         1661  +  aShm = (u32*)pShm;
         1662  +  iOff = 12*2+1+iSlot;
         1663  +
         1664  +  if( objc==5 ){
         1665  +    aShm[iOff] = iVal;
         1666  +  }
         1667  +  Tcl_SetObjResult(interp, Tcl_NewIntObj(aShm[iOff]));
         1668  +
         1669  +  return TCL_OK;
         1670  +}
  1619   1671   
  1620   1672   int Sqlitetestvfs_Init(Tcl_Interp *interp){
  1621   1673     Tcl_CreateObjCommand(interp, "testvfs", testvfs_cmd, 0, 0);
  1622   1674     Tcl_CreateObjCommand(interp, "vfs_shmlock", test_vfs_shmlock, 0, 0);
         1675  +  Tcl_CreateObjCommand(interp, "vfs_set_readmark", test_vfs_set_readmark, 0, 0);
  1623   1676     return TCL_OK;
  1624   1677   }
  1625   1678   
  1626   1679   #endif

Changes to test/walvfs.test.

   178    178     }
   179    179     return SQLITE_OK
   180    180   }
   181    181   do_catchsql_test 4.2 {
   182    182     SELECT count(*) FROM t1
   183    183   } {1 {attempt to write a readonly database}}
   184    184   
          185  +#-------------------------------------------------------------------------
          186  +#
          187  +reset_db
          188  +db close 
          189  +sqlite3 db test.db -vfs tvfs
          190  +tvfs filter {}
          191  +do_execsql_test 5.0 {
          192  +  PRAGMA auto_vacuum = 0;
          193  +  PRAGMA page_size = 1024;
          194  +  CREATE TABLE t1(x);
          195  +  PRAGMA journal_mode = wal;
          196  +  WITH s(i) AS (
          197  +      SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 20
          198  +  )
          199  +  INSERT INTO t1 SELECT randomblob(750) FROM s;
          200  +} {wal}
          201  +
          202  +do_execsql_test 5.1 {
          203  +  SELECT count(*) FROM t1
          204  +} {20}
          205  +
          206  +do_test 5.2 {
          207  +  vfs_set_readmark db main 1 100
          208  +  vfs_set_readmark db main 2 100
          209  +  vfs_set_readmark db main 3 100
          210  +  vfs_set_readmark db main 4 100
          211  +} {100}
          212  +
          213  +do_execsql_test 5.3 {
          214  +  SELECT count(*) FROM t1
          215  +} {20}
          216  +
          217  +do_test 5.3 {
          218  +  list [vfs_set_readmark db main 1] \
          219  +       [vfs_set_readmark db main 2] \
          220  +       [vfs_set_readmark db main 3] \
          221  +       [vfs_set_readmark db main 4] 
          222  +} {24 100 100 100}
          223  +
          224  +tvfs script xShmLock
          225  +tvfs filter xShmLock
          226  +set ::cnt 20
          227  +proc xShmLock {args} {
          228  +  incr ::cnt -1
          229  +  if {$::cnt>0} { return SQLITE_BUSY }
          230  +  return SQLITE_OK
          231  +}
          232  +
          233  +do_test 5.4 {
          234  +  vfs_set_readmark db main 1 100
          235  +  execsql { SELECT count(*) FROM t1 }
          236  +} {20}
          237  +
          238  +#-------------------------------------------------------------------------
          239  +# Cause an SQLITE_PROTOCOL while attempting to restart the wal file.
          240  +reset_db
          241  +tvfs filter {}
          242  +db close
          243  +sqlite3 db test.db -vfs tvfs
          244  +do_execsql_test 6.0 {
          245  +  PRAGMA auto_vacuum = 0;
          246  +  PRAGMA page_size = 1024;
          247  +  CREATE TABLE t1(x);
          248  +  PRAGMA journal_mode = wal;
          249  +  WITH s(i) AS (
          250  +      SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 20
          251  +  )
          252  +  INSERT INTO t1 SELECT randomblob(750) FROM s;
          253  +} {wal}
          254  +
          255  +do_test 6.1 {
          256  +  execsql { PRAGMA wal_checkpoint } 
          257  +  set {} {}
          258  +} {}
          259  +
          260  +tvfs filter xShmLock
          261  +set ::flag 0
          262  +proc xShmLock {method file handle spec} {
          263  +  if {$::flag && [lrange $spec 2 end]=="lock shared"} {
          264  +    return SQLITE_BUSY
          265  +  }
          266  +  if {$spec=="3 1 unlock shared"} {
          267  +    set ::flag 1
          268  +  }
          269  +  return SQLITE_OK
          270  +}
          271  +
          272  +puts "# WARNING: This next test takes around 12 seconds"
          273  +do_catchsql_test 6.2 {
          274  +  INSERT INTO t1 VALUES(1);
          275  +} {1 {locking protocol}}
          276  +
   185    277   db close
   186    278   tvfs delete
   187    279   finish_test
          280  +