/ Check-in [87a15917]
Login

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

Overview
Comment:Add tests to improve coverage of vdbesort.c.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | experimental
Files: files | file ages | folders
SHA1: 87a15917d7d88285054e2a319506dd4a0cac9722
User & Date: dan 2011-08-12 11:59:57
Context
2011-08-12
15:02
Add the SQLITE_OMIT_MERGE_SORT pre-processor directive. To omit the code in vdbesort.c. check-in: 4ced2394 user: dan tags: experimental
11:59
Add tests to improve coverage of vdbesort.c. check-in: 87a15917 user: dan tags: experimental
2011-08-08
19:26
Remove redundant parameter from vdbeSorterInitMerge() in vdbesort.c. check-in: eec8c0df user: dan tags: experimental
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/test_vfs.c.

   119    119   #define TESTVFS_SYNC_MASK         0x00000200
   120    120   #define TESTVFS_DELETE_MASK       0x00000400
   121    121   #define TESTVFS_CLOSE_MASK        0x00000800
   122    122   #define TESTVFS_WRITE_MASK        0x00001000
   123    123   #define TESTVFS_TRUNCATE_MASK     0x00002000
   124    124   #define TESTVFS_ACCESS_MASK       0x00004000
   125    125   #define TESTVFS_FULLPATHNAME_MASK 0x00008000
          126  +#define TESTVFS_READ_MASK         0x00010000
          127  +
   126    128   #define TESTVFS_ALL_MASK          0x0001FFFF
   127    129   
   128    130   
   129    131   #define TESTVFS_MAX_PAGES 1024
   130    132   
   131    133   /*
   132    134   ** A shared-memory buffer. There is one of these objects for each shared
................................................................................
   321    323   */
   322    324   static int tvfsRead(
   323    325     sqlite3_file *pFile, 
   324    326     void *zBuf, 
   325    327     int iAmt, 
   326    328     sqlite_int64 iOfst
   327    329   ){
   328         -  TestvfsFd *p = tvfsGetFd(pFile);
   329         -  return sqlite3OsRead(p->pReal, zBuf, iAmt, iOfst);
          330  +  int rc = SQLITE_OK;
          331  +  TestvfsFd *pFd = tvfsGetFd(pFile);
          332  +  Testvfs *p = (Testvfs *)pFd->pVfs->pAppData;
          333  +  if( p->pScript && p->mask&TESTVFS_READ_MASK ){
          334  +    tvfsExecTcl(p, "xRead", 
          335  +        Tcl_NewStringObj(pFd->zFilename, -1), pFd->pShmId, 0
          336  +    );
          337  +    tvfsResultCode(p, &rc);
          338  +  }
          339  +  if( rc==SQLITE_OK && p->mask&TESTVFS_READ_MASK && tvfsInjectIoerr(p) ){
          340  +    rc = SQLITE_IOERR;
          341  +  }
          342  +  if( rc==SQLITE_OK ){
          343  +    rc = sqlite3OsRead(pFd->pReal, zBuf, iAmt, iOfst);
          344  +  }
          345  +  return rc;
   330    346   }
   331    347   
   332    348   /*
   333    349   ** Write data to an tvfs-file.
   334    350   */
   335    351   static int tvfsWrite(
   336    352     sqlite3_file *pFile, 
................................................................................
  1026   1042           { "xShmLock",      TESTVFS_SHMLOCK_MASK },
  1027   1043           { "xShmBarrier",   TESTVFS_SHMBARRIER_MASK },
  1028   1044           { "xShmUnmap",     TESTVFS_SHMCLOSE_MASK },
  1029   1045           { "xShmMap",       TESTVFS_SHMMAP_MASK },
  1030   1046           { "xSync",         TESTVFS_SYNC_MASK },
  1031   1047           { "xDelete",       TESTVFS_DELETE_MASK },
  1032   1048           { "xWrite",        TESTVFS_WRITE_MASK },
         1049  +        { "xRead",         TESTVFS_READ_MASK },
  1033   1050           { "xTruncate",     TESTVFS_TRUNCATE_MASK },
  1034   1051           { "xOpen",         TESTVFS_OPEN_MASK },
  1035   1052           { "xClose",        TESTVFS_CLOSE_MASK },
  1036   1053           { "xAccess",       TESTVFS_ACCESS_MASK },
  1037   1054           { "xFullPathname", TESTVFS_FULLPATHNAME_MASK },
  1038   1055         };
  1039   1056         Tcl_Obj **apElem = 0;

Changes to test/indexfault.test.

    12     12   
    13     13   set testdir [file dirname $argv0]
    14     14   source $testdir/tester.tcl
    15     15   source $testdir/lock_common.tcl
    16     16   source $testdir/malloc_common.tcl
    17     17   
    18     18   set testprefix indexfault
           19  +
           20  +# Set up the custom fault-injector. This is further configured by using
           21  +# different values for $::custom_filter and different implementations
           22  +# of Tcl proc [xCustom] for each test case.
           23  +#
           24  +proc install_custom_faultsim {} {
           25  +  set ::FAULTSIM(custom)            [list      \
           26  +    -injectinstall   custom_injectinstall    \
           27  +    -injectstart     custom_injectstart      \
           28  +    -injectstop      custom_injectstop       \
           29  +    -injecterrlist   {{1 {disk I/O error}}}  \
           30  +    -injectuninstall custom_injectuninstall  \
           31  +  ]
           32  +  proc custom_injectinstall {} {
           33  +    testvfs shmfault -default true
           34  +    shmfault filter $::custom_filter
           35  +    shmfault script xCustom
           36  +  }
           37  +  proc custom_injectuninstall {} {
           38  +    catch {db  close}
           39  +    catch {db2 close}
           40  +    shmfault delete
           41  +  }
           42  +  set ::custom_ifail -1
           43  +  set ::custom_nfail -1
           44  +  proc custom_injectstart {iFail} {
           45  +    set ::custom_ifail $iFail
           46  +    set ::custom_nfail 0
           47  +  }
           48  +  proc custom_injectstop {} {
           49  +    set ::custom_ifail -1
           50  +    return $::custom_nfail
           51  +  }
           52  +}
           53  +proc uninstall_custom_faultsim {} {
           54  +  unset -nocomplain ::FAULTSIM(custom)
           55  +}
           56  +
    19     57   
    20     58   #-------------------------------------------------------------------------
    21     59   # These tests - indexfault-1.* - Build an index on a smallish table with
    22     60   # all different kinds of fault-injection. The CREATE INDEX is run once
    23     61   # with default options and once with a 50KB soft-heap-limit.
    24     62   #
    25     63   do_execsql_test 1.0 {
................................................................................
   120    158   #   3.1: IO errors injected into xOpen() calls.
   121    159   #   3.2: As 7.1, but with a low (50KB) soft-heap-limit.
   122    160   #
   123    161   #   3.3: IO errors injected into the first 200 write() calls made on the
   124    162   #        second temporary file.
   125    163   #   3.4: As 7.3, but with a low (50KB) soft-heap-limit.
   126    164   #
   127         -#
   128         -
   129         -# Set up the custom fault-injector. This is further configured by using
   130         -# different values for $::custom_filter and different implementations
   131         -# of Tcl proc [xCustom] for each test case.
          165  +#   3.5: After a certain amount of data has been read from the main database
          166  +#        file (and written into the temporary b-tree), sqlite3_release_memory()
          167  +#        is called to free as much memory as possible. This causes the temp
          168  +#        b-tree to be flushed to disk. So that before its contents can be 
          169  +#        transfered to a PMA they must be read back from disk - creating extra
          170  +#        opportunities for IO errors.
   132    171   #
   133         -set FAULTSIM(custom)            [list      \
   134         -  -injectinstall   custom_injectinstall    \
   135         -  -injectstart     custom_injectstart      \
   136         -  -injectstop      custom_injectstop       \
   137         -  -injecterrlist   {{1 {disk I/O error}}}  \
   138         -  -injectuninstall custom_injectuninstall  \
   139         -]
   140         -proc custom_injectinstall {} {
   141         -  testvfs shmfault -default true
   142         -  shmfault filter $::custom_filter
   143         -  shmfault script xCustom
   144         -}
   145         -proc custom_injectuninstall {} {
   146         -  catch {db  close}
   147         -  catch {db2 close}
   148         -  shmfault delete
   149         -}
   150         -set ::custom_ifail -1
   151         -set ::custom_nfail -1
   152         -proc custom_injectstart {iFail} {
   153         -  set ::custom_ifail $iFail
   154         -  set ::custom_nfail 0
   155         -}
   156         -proc custom_injectstop {} {
   157         -  set ::custom_ifail -1
   158         -  return $::custom_nfail
   159         -}
          172  +install_custom_faultsim
   160    173   
   161    174   # Set up a table to build indexes on. Save the setup using the 
   162    175   # [faultsim_save_and_close] mechanism.
   163    176   # 
   164    177   sqlite3 db test.db
   165    178   do_execsql_test 3.0 {
   166    179     BEGIN;
................................................................................
   240    253       set ::nTmpOpen 0
   241    254     } -body {
   242    255       execsql { CREATE INDEX i1 ON t1(x) }
   243    256       faultsim_test_result {0 {}} 
   244    257     }
   245    258     sqlite3_soft_heap_limit $soft_limit
   246    259   }
          260  +
          261  +uninstall_custom_faultsim
          262  +
          263  +#-------------------------------------------------------------------------
          264  +# Test 4: After a certain amount of data has been read from the main database
          265  +# file (and written into the temporary b-tree), sqlite3_release_memory() is
          266  +# called to free as much memory as possible. This causes the temp b-tree to be
          267  +# flushed to disk. So that before its contents can be transfered to a PMA they
          268  +# must be read back from disk - creating extra opportunities for IO errors.
          269  +# 
          270  +install_custom_faultsim
          271  +
          272  +catch { db close }
          273  +forcedelete test.db
          274  +sqlite3 db test.db
          275  +
          276  +do_execsql_test 4.0 {
          277  +  BEGIN;
          278  +    DROP TABLE IF EXISTS t1;
          279  +    CREATE TABLE t1(x);
          280  +    INSERT INTO t1 VALUES(randomblob(11000));
          281  +    INSERT INTO t1 SELECT randomblob(11001) FROM t1;     --     2
          282  +    INSERT INTO t1 SELECT randomblob(11002) FROM t1;     --     4
          283  +    INSERT INTO t1 SELECT randomblob(11003) FROM t1;     --     8
          284  +    INSERT INTO t1 SELECT randomblob(11004) FROM t1;     --    16
          285  +    INSERT INTO t1 SELECT randomblob(11005) FROM t1;     --    32
          286  +    INSERT INTO t1 SELECT randomblob(11005) FROM t1;     --    64
          287  +  COMMIT;
          288  +}
          289  +faultsim_save_and_close
          290  +
          291  +testvfs tvfs 
          292  +tvfs script xRead
          293  +tvfs filter xRead
          294  +set ::nRead 0
          295  +proc xRead {method file args} {
          296  +  if {[file tail $file] == "test.db"} { incr ::nRead }
          297  +}
          298  +
          299  +do_test 4.1 {
          300  +  sqlite3 db test.db -vfs tvfs
          301  +  execsql { CREATE INDEX i1 ON t1(x) }
          302  +} {}
          303  +
          304  +db close
          305  +tvfs delete
          306  +
          307  +set ::custom_filter xRead
          308  +proc xCustom {method file args} {
          309  +  incr ::nReadCall
          310  +  if {$::nReadCall >= ($::nRead/5)} {
          311  +    if {$::nReadCall == ($::nRead/5)} {
          312  +      set nByte [sqlite3_release_memory [expr 64*1024*1024]]
          313  +      sqlite3_soft_heap_limit 20000
          314  +    }
          315  +    if {$file == ""} {
          316  +      incr ::custom_ifail -1
          317  +      if {$::custom_ifail==0} {
          318  +        incr ::custom_nfail
          319  +        return "SQLITE_IOERR"
          320  +      }
          321  +    }
          322  +  }
          323  +  return "SQLITE_OK"
          324  +}
          325  +
          326  +do_faultsim_test 4.2 -faults custom -prep {
          327  +  faultsim_restore_and_reopen
          328  +  set ::nReadCall 0
          329  +  sqlite3_soft_heap_limit 0
          330  +} -body {
          331  +  execsql { CREATE INDEX i1 ON t1(x) }
          332  +  faultsim_test_result {0 {}} 
          333  +}
          334  +
          335  +uninstall_custom_faultsim
   247    336   
   248    337   finish_test

Changes to test/wal2.test.

   602    602       set ::shm_file [lindex $args 0]
   603    603       if {$method == "xShmLock"} { lappend ::locks [lindex $args 2] }
   604    604       return "SQLITE_OK"
   605    605     }
   606    606     testvfs tvfs
   607    607     tvfs script tvfs_cb
   608    608     sqlite3 db test.db -vfs tvfs
          609  +  set {} {}
   609    610   } {}
   610    611   
   611    612   set RECOVERY {
   612    613     {0 1 lock exclusive} {1 7 lock exclusive} 
   613    614     {1 7 unlock exclusive} {0 1 unlock exclusive}
   614    615   }
   615    616   set READMARK0_READ {