SQLite4
Check-in [9638da92b6]
Not logged in

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

Overview
SHA1 Hash:9638da92b694b9876743d7633991516e64774094
Date: 2014-02-17 18:39:40
User: dan
Comment:Add IO error tests for the bt backend.
Tags And Properties
Context
2014-02-18
20:01
[cd8da865a4] Add crash simulation and recovery test infrastructure. And one test case. (user: dan, tags: trunk)
2014-02-17
18:39
[9638da92b6] Add IO error tests for the bt backend. (user: dan, tags: trunk)
09:26
[5aca057cad] Have the bt backend support "PRAGMA page_size". (user: dan, tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to main.mk.

225
226
227
228
229
230
231

232
233
234
235
236
237
238
  sqlite4.h


# Source code to the test files.
#
TESTSRC = \
  $(TOP)/test/test_auth.c \

  $(TOP)/test/test_config.c \
  $(TOP)/test/test_func.c \
  $(TOP)/test/test_hexio.c \
  $(TOP)/test/test_kv.c \
  $(TOP)/test/test_kv2.c \
  $(TOP)/test/test_lsm.c \
  $(TOP)/test/test_main.c \







>







225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
  sqlite4.h


# Source code to the test files.
#
TESTSRC = \
  $(TOP)/test/test_auth.c \
  $(TOP)/test/test_bt.c \
  $(TOP)/test/test_config.c \
  $(TOP)/test/test_func.c \
  $(TOP)/test/test_hexio.c \
  $(TOP)/test/test_kv.c \
  $(TOP)/test/test_kv2.c \
  $(TOP)/test/test_lsm.c \
  $(TOP)/test/test_main.c \

Changes to src/bt_lock.c.

158
159
160
161
162
163
164
165



166
167
168
169
170
171
172
173
174
175
...
332
333
334
335
336
337
338

339




340
341
342
343
344
345
346
...
432
433
434
435
436
437
438

439
440
441
442
443
444
445
      case BT_LOCK_SHARED:
        if( nExcl ){
          rc = SQLITE4_BUSY;
        }else{
          if( nShared==0 ){
            rc = btLockSharedFile(p, iLock, BT_LOCK_SHARED);
          }
          if( rc==SQLITE4_OK ){



            p->mSharedLock |= mask;
            p->mExclLock &= ~mask;
          }
        }
        break;

      default:
        assert( eOp==BT_LOCK_EXCL );
        if( nExcl || nShared ){
          rc = SQLITE4_BUSY;
................................................................................
        p->pFd = p->pBtFile->pFd;
      }else{
        p->pBtFile = (BtFile*)sqlite4_malloc(pEnv, sizeof(BtFile));
        if( p->pBtFile ){
          int flags = BT_OPEN_DATABASE;
          p->pBtFile->pNext = 0;
          rc = pVfs->xOpen(pEnv, pVfs, pShared->zName, flags, &p->pFd);

          p->pBtFile->pFd = p->pFd;




        }else{
          rc = btErrorBkpt(SQLITE4_NOMEM);
        }
      }
    }

    if( rc==SQLITE4_OK ){
................................................................................
  sqlite4_mutex_enter(pShared->pClientMutex);
  assert( p->pBtFile->pNext==0 );
  p->pBtFile->pNext = pShared->pBtFile;
  pShared->pBtFile = p->pBtFile;
  sqlite4_mutex_leave(pShared->pClientMutex);

  btLockSharedDeref(p->pEnv, p->pVfs, pShared);

  return rc;
}

#ifndef NDEBUG
static void assertNoLockedSlots(BtLock *pLock){
  u32 mask = (1 << (BT_LOCK_READER0+BT_NREADER+1)) - (1 << BT_LOCK_READER0);
  assert( (pLock->mExclLock & mask)==0 );







|
>
>
>
|
|
<







 







>
|
>
>
>
>







 







>







158
159
160
161
162
163
164
165
166
167
168
169
170

171
172
173
174
175
176
177
...
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
...
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
      case BT_LOCK_SHARED:
        if( nExcl ){
          rc = SQLITE4_BUSY;
        }else{
          if( nShared==0 ){
            rc = btLockSharedFile(p, iLock, BT_LOCK_SHARED);
          }
          /* If no error occurred, set the bit in the mask of SHARED locks
          ** held. Either way, clear the bit in the mask of EXCLUSIVE locks.
          ** The idea here is that when there is any uncertainty as to whether
          ** a lock is held, the corresponding bit is cleared.  */
          if( rc==SQLITE4_OK ) p->mSharedLock |= mask;
          p->mExclLock &= ~mask;

        }
        break;

      default:
        assert( eOp==BT_LOCK_EXCL );
        if( nExcl || nShared ){
          rc = SQLITE4_BUSY;
................................................................................
        p->pFd = p->pBtFile->pFd;
      }else{
        p->pBtFile = (BtFile*)sqlite4_malloc(pEnv, sizeof(BtFile));
        if( p->pBtFile ){
          int flags = BT_OPEN_DATABASE;
          p->pBtFile->pNext = 0;
          rc = pVfs->xOpen(pEnv, pVfs, pShared->zName, flags, &p->pFd);
          if( rc==SQLITE4_OK ){
            p->pBtFile->pFd = p->pFd;
          }else{
            sqlite4_free(pEnv, p->pBtFile);
            p->pBtFile = 0;
          }
        }else{
          rc = btErrorBkpt(SQLITE4_NOMEM);
        }
      }
    }

    if( rc==SQLITE4_OK ){
................................................................................
  sqlite4_mutex_enter(pShared->pClientMutex);
  assert( p->pBtFile->pNext==0 );
  p->pBtFile->pNext = pShared->pBtFile;
  pShared->pBtFile = p->pBtFile;
  sqlite4_mutex_leave(pShared->pClientMutex);

  btLockSharedDeref(p->pEnv, p->pVfs, pShared);
  p->pShared = 0;
  return rc;
}

#ifndef NDEBUG
static void assertNoLockedSlots(BtLock *pLock){
  u32 mask = (1 << (BT_LOCK_READER0+BT_NREADER+1)) - (1 << BT_LOCK_READER0);
  assert( (pLock->mExclLock & mask)==0 );

Changes to src/bt_pager.c.

494
495
496
497
498
499
500
501





502
503
504
505
506
507
508
    p->nFile = strlen(p->zFile);
    rc = sqlite4BtLockConnect((BtLock*)p, btRecover);
    if( rc==SQLITE4_OK && p->pLog==0 ){
      rc = sqlite4BtLogOpen(p, 0, &p->pLog);
    }
  }

  assert( (rc==SQLITE4_OK)==(p->btl.pFd!=0 && p->pLog!=0) );





  return rc;
}

/*
** Open a read-transaction.
*/
static int btOpenReadTransaction(BtPager *p){







|
>
>
>
>
>







494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
    p->nFile = strlen(p->zFile);
    rc = sqlite4BtLockConnect((BtLock*)p, btRecover);
    if( rc==SQLITE4_OK && p->pLog==0 ){
      rc = sqlite4BtLogOpen(p, 0, &p->pLog);
    }
  }

  if( rc!=SQLITE4_OK ){
    sqlite4BtLockDisconnect((BtLock*)p, btCheckpoint, btCleanup);
    sqlite4BtLogClose(p->pLog, 0);
    p->pLog = 0;
  }

  return rc;
}

/*
** Open a read-transaction.
*/
static int btOpenReadTransaction(BtPager *p){

Changes to test/fault1.test.

11
12
13
14
15
16
17

18
19




20






21






22

23
24

25
26
27
28

#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/malloc_common.tcl
set ::testprefix fault1



execsql { SELECT *  FROM  sqlite_master }











do_faultsim_test 1.0 -faults oom* -body {






  execsql { SELECT * FROM sqlite_master }

} -test {
  faultsim_test_result {0 {}} 

}

finish_test









>

<
>
>
>
>
|
>
>
>
>
>
>
|
>
>
>
>
>
>
|
>

|
>




>
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/malloc_common.tcl
set ::testprefix fault1

db close


proc open_test_db {} { 
  sqlite4 db test.db
  btenv testenv
  testenv attach db
}

proc close_test_db {} { 
  db close
  testenv delete
}

do_faultsim_test 2.0 -prep {
  forcedelete test.db test.db-wal
  open_test_db
} -body {
  execsql {
    CREATE TABLE t1(x,y);
    INSERT INTO t1 VALUES('abc', 'def');
    SELECT * FROM t1;
  }
} -test {
  faultsim_test_result {0 {abc def}}
  close_test_db
}

finish_test


Changes to test/malloc_common.tcl.

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200

201
202
203
204
205
206
207
]
  
# Transient and persistent IO errors:
#
set FAULTSIM(ioerr-transient) [list        \
  -injectstart   {ioerr_injectstart 0}     \
  -injectstop    ioerr_injectstop          \
  -injecterrlist {{1 {disk I/O error}}}    \
]
set FAULTSIM(ioerr-persistent) [list       \
  -injectstart   {ioerr_injectstart 1}     \
  -injectstop    ioerr_injectstop          \
  -injecterrlist {{1 {disk I/O error}}}    \
]

# SQLITE4_FULL errors (always persistent):
#
set FAULTSIM(full) [list                   \
  -injectinstall   fullerr_injectinstall   \
  -injectstart     fullerr_injectstart     \
  -injectstop      fullerr_injectstop      \
  -injecterrlist   {{1 {database or disk is full}}} \
  -injectuninstall fullerr_injectuninstall \
]

# Transient and persistent SHM errors:
#
set FAULTSIM(shmerr-transient) [list       \
  -injectinstall   shmerr_injectinstall    \
  -injectstart     {shmerr_injectstart 0}  \
  -injectstop      shmerr_injectstop       \
  -injecterrlist   {{1 {disk I/O error}}}  \
  -injectuninstall shmerr_injectuninstall  \
]
set FAULTSIM(shmerr-persistent) [list      \
  -injectinstall   shmerr_injectinstall    \
  -injectstart     {shmerr_injectstart 1}  \
  -injectstop      shmerr_injectstop       \
  -injecterrlist   {{1 {disk I/O error}}}  \
  -injectuninstall shmerr_injectuninstall  \
]

# Transient and persistent CANTOPEN errors:
#
set FAULTSIM(cantopen-transient) [list       \
  -injectinstall   cantopen_injectinstall    \
  -injectstart     {cantopen_injectstart 0}  \
  -injectstop      cantopen_injectstop       \
  -injecterrlist   {{1 {unable to open database file}}}  \
  -injectuninstall cantopen_injectuninstall  \
]
set FAULTSIM(cantopen-persistent) [list      \
  -injectinstall   cantopen_injectinstall    \
  -injectstart     {cantopen_injectstart 1}  \
  -injectstop      cantopen_injectstop       \
  -injecterrlist   {{1 {unable to open database file}}}  \
  -injectuninstall cantopen_injectuninstall  \
]



#--------------------------------------------------------------------------
# Usage do_faultsim_test NAME ?OPTIONS...? 
#
................................................................................
  return $nFault
}

# The following procs are used as [do_one_faultsim_test] callbacks when 
# injecting IO error faults into test cases.
#
proc ioerr_injectstart {persist iFail} {
  set ::sqlite_io_error_persist $persist
  set ::sqlite_io_error_pending $iFail
}
proc ioerr_injectstop {} {
  set sv $::sqlite_io_error_hit
  set ::sqlite_io_error_persist 0
  set ::sqlite_io_error_pending 0
  set ::sqlite_io_error_hardhit 0
  set ::sqlite_io_error_hit     0
  set ::sqlite_io_error_pending 0
  return $sv

}

# The following procs are used as [do_one_faultsim_test] callbacks when 
# injecting shared-memory related error faults into test cases.
#
proc shmerr_injectinstall {} {
  testvfs shmfault -default true







|




|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|
<


<
<
<
<
<
<
<
>







37
38
39
40
41
42
43
44
45
46
47
48
49












































50
51
52
53
54
55
56
...
139
140
141
142
143
144
145
146

147
148







149
150
151
152
153
154
155
156
]
  
# Transient and persistent IO errors:
#
set FAULTSIM(ioerr-transient) [list        \
  -injectstart   {ioerr_injectstart 0}     \
  -injectstop    ioerr_injectstop          \
  -injecterrlist {{1 {disk I/O error}} {1 {unable to open database file}}} \
]
set FAULTSIM(ioerr-persistent) [list       \
  -injectstart   {ioerr_injectstart 1}     \
  -injectstop    ioerr_injectstop          \
  -injecterrlist {{1 {disk I/O error}} {1 {unable to open database file}}} \












































]



#--------------------------------------------------------------------------
# Usage do_faultsim_test NAME ?OPTIONS...? 
#
................................................................................
  return $nFault
}

# The following procs are used as [do_one_faultsim_test] callbacks when 
# injecting IO error faults into test cases.
#
proc ioerr_injectstart {persist iFail} {
  testenv ioerr $iFail $persist

}
proc ioerr_injectstop {} {







  testenv ioerr 0 0
}

# The following procs are used as [do_one_faultsim_test] callbacks when 
# injecting shared-memory related error faults into test cases.
#
proc shmerr_injectinstall {} {
  testvfs shmfault -default true

Changes to test/select1.test.

12
13
14
15
16
17
18



19
20
21
22
23
24
25
# focus of this file is testing the SELECT statement.
#
# $Id: select1.test,v 1.70 2009/05/28 01:00:56 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl




# Try to select on a non-existant table.
#
do_test select1-1.1 {
  set v [catch {execsql {SELECT * FROM test1}} msg]
  lappend v $msg
} {1 {no such table: test1}}








>
>
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# focus of this file is testing the SELECT statement.
#
# $Id: select1.test,v 1.70 2009/05/28 01:00:56 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

btenv BT
BT attach db

# Try to select on a non-existant table.
#
do_test select1-1.1 {
  set v [catch {execsql {SELECT * FROM test1}} msg]
  lappend v $msg
} {1 {no such table: test1}}

Changes to test/testInt.h.

69
70
71
72
73
74
75



76
77

sqlite4_mm *test_mm_debug(sqlite4_mm *p);
sqlite4_mm *test_mm_faultsim(sqlite4_mm *p);

/* test_num.c */
int Sqlitetest_num_init(Tcl_Interp *interp);




#endif








>
>
>


69
70
71
72
73
74
75
76
77
78
79
80

sqlite4_mm *test_mm_debug(sqlite4_mm *p);
sqlite4_mm *test_mm_faultsim(sqlite4_mm *p);

/* test_num.c */
int Sqlitetest_num_init(Tcl_Interp *interp);

/* test_bt.c */
int SqlitetestBt_Init(Tcl_Interp *interp);

#endif

Added test/test_bt.c.

cannot compute difference between binary files

Changes to test/test_main.c.

4147
4148
4149
4150
4151
4152
4153

4154
4155
4156
4157
4158
4159
4160
  return TCL_OK;
}

void sqlite4TestInit(Tcl_Interp *interp){
  Sqlitetest_auth_init(interp);
  Sqlitetest_num_init(interp);
  Sqlitetest_func_Init(interp);

}

/*
** Register commands with the TCL interpreter.
*/
int Sqlitetest1_Init(Tcl_Interp *interp){
  extern int sqlite4_search_count;







>







4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
  return TCL_OK;
}

void sqlite4TestInit(Tcl_Interp *interp){
  Sqlitetest_auth_init(interp);
  Sqlitetest_num_init(interp);
  Sqlitetest_func_Init(interp);
  SqlitetestBt_Init(interp);
}

/*
** Register commands with the TCL interpreter.
*/
int Sqlitetest1_Init(Tcl_Interp *interp){
  extern int sqlite4_search_count;