/ Check-in [f6d9cb83]
Login

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

Overview
Comment:Improve coverage of btree.c. (CVS 5363)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f6d9cb835b8f75545f455328d61ba225e7da9bc4
User & Date: danielk1977 2008-07-08 10:19:58
Context
2008-07-08
12:02
Make sqlite3_shutdown() a no-op if the library is not initialized. (CVS 5364) check-in: d725d3bb user: danielk1977 tags: trunk
10:19
Improve coverage of btree.c. (CVS 5363) check-in: f6d9cb83 user: danielk1977 tags: trunk
07:35
Prohibit the user from changing the temporary storage medium (pragma temp_store) while there is a read transaction open on the temporary database. Add tests to shared.test to cover a few more lines in btree.c. (CVS 5362) check-in: 92e0cf9a user: danielk1977 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to test/corrupt2.test.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
...
222
223
224
225
226
227
228
229

























































































230
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests to make sure SQLite does not crash or
# segfault if it sees a corrupt database file.
#
# $Id: corrupt2.test,v 1.8 2008/07/07 17:55:29 danielk1977 Exp $

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

# The following tests - corrupt2-1.* - create some databases corrupted in
# specific ways and ensure that SQLite detects them as corrupt.
#
................................................................................

do_test corrupt2-4.1 {
  catchsql {
    SELECT * FROM t2;
  } db2
} {1 {database disk image is malformed}}

do_test corrupt2-4.1 {
  file delete -force corrupt.db
  file delete -force corrupt.db-journal
  sqlite3 db2 corrupt.db 

  execsql {
    PRAGMA page_size = 1024;
    CREATE TABLE t1(a, b, c);
................................................................................
Page 10: sqlite3BtreeInitPage() returns error code 11
On tree page 3 cell 1: Child page depth differs
On tree page 2 cell 0: 2nd reference to page 10
On tree page 2 cell 1: Child page depth differs
Page 4 is never used}}

db2 close


























































































finish_test







|







 







|







 








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
...
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests to make sure SQLite does not crash or
# segfault if it sees a corrupt database file.
#
# $Id: corrupt2.test,v 1.9 2008/07/08 10:19:58 danielk1977 Exp $

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

# The following tests - corrupt2-1.* - create some databases corrupted in
# specific ways and ensure that SQLite detects them as corrupt.
#
................................................................................

do_test corrupt2-4.1 {
  catchsql {
    SELECT * FROM t2;
  } db2
} {1 {database disk image is malformed}}

do_test corrupt2-5.1 {
  file delete -force corrupt.db
  file delete -force corrupt.db-journal
  sqlite3 db2 corrupt.db 

  execsql {
    PRAGMA page_size = 1024;
    CREATE TABLE t1(a, b, c);
................................................................................
Page 10: sqlite3BtreeInitPage() returns error code 11
On tree page 3 cell 1: Child page depth differs
On tree page 2 cell 0: 2nd reference to page 10
On tree page 2 cell 1: Child page depth differs
Page 4 is never used}}

db2 close

proc corruption_test {args} {
  array set A $args

  catch {db close}
  file delete -force corrupt.db
  file delete -force corrupt.db-journal

  sqlite3 db corrupt.db 
  db eval $A(-sqlprep)
  db close

  eval $A(-corrupt)

  sqlite3 db corrupt.db
  eval $A(-test)
}

ifcapable autovacuum {
  # The tests within this block - corrupt2-6.* - aim to test corruption
  # detection within an incremental-vacuum. When an incremental-vacuum
  # step is executed, the last non-free page of the database file is 
  # moved into a free space in the body of the file. After doing so,
  # the page reference in the parent page must be updated to refer
  # to the new location. These tests test the outcome of corrupting
  # that page reference before performing the incremental vacuum.
  #

  # The last page in the database page is the second page 
  # in an overflow chain.
  #
  corruption_test -sqlprep {
    PRAGMA auto_vacuum = incremental;
    PRAGMA page_size = 1024;
    CREATE TABLE t1(a, b);
    INSERT INTO t1 VALUES(1, randomblob(2500));
    INSERT INTO t1 VALUES(2, randomblob(2500));
    DELETE FROM t1 WHERE a = 1;
  } -corrupt {
    hexio_write corrupt.db [expr 1024*5] 00000008
  } -test {
    do_test corrupt2-6.1 {
      catchsql { pragma incremental_vacuum = 1 }
    } {1 {database disk image is malformed}}
  }

  # The last page in the database page is a non-root b-tree page.
  #
  corruption_test -sqlprep {
    PRAGMA auto_vacuum = incremental;
    PRAGMA page_size = 1024;
    CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
    INSERT INTO t1 VALUES(1, randomblob(2500));
    INSERT INTO t1 VALUES(2, randomblob(50));
    INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1;
    INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1;
    INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1;
    INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1;
    DELETE FROM t1 WHERE a = 1;
  } -corrupt {
    hexio_write corrupt.db [expr 1024*2 + 8] 00000009
  } -test {
    do_test corrupt2-6.2 {
      catchsql { pragma incremental_vacuum = 1 }
    } {1 {database disk image is malformed}}
  }

  # Set up a pointer-map entry so that the last page of the database
  # file appears to be a b-tree root page. This should be detected
  # as corruption.
  #
  corruption_test -sqlprep {
    PRAGMA auto_vacuum = incremental;
    PRAGMA page_size = 1024;
    CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
    INSERT INTO t1 VALUES(1, randomblob(2500));
    INSERT INTO t1 VALUES(2, randomblob(2500));
    INSERT INTO t1 VALUES(3, randomblob(2500));
    DELETE FROM t1 WHERE a = 1;
  } -corrupt {
    set nPage [expr [file size corrupt.db] / 1024]
    hexio_write corrupt.db [expr 1024 + ($nPage-3)*5] 010000000
  } -test {
    do_test corrupt2-6.3 {
      catchsql { pragma incremental_vacuum = 1 }
    } {1 {database disk image is malformed}}
  }

}

finish_test

Changes to test/ioerr.test.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
...
283
284
285
286
287
288
289
290


















291

# This file implements regression tests for SQLite library.  The
# focus of this file is testing for correct handling of I/O errors
# such as writes failing because the disk is full.
# 
# The tests in this file use special facilities that are only
# available in the SQLite test fixture.
#
# $Id: ioerr.test,v 1.37 2008/06/07 08:58:23 danielk1977 Exp $

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

# If SQLITE_DEFAULT_AUTOVACUUM is set to true, then a simulated IO error
# on the 8th IO operation in the SQL script below doesn't report an error.
#
................................................................................
    INSERT INTO t1 SELECT randstr(50,50), randstr(9,9), randstr(90,90) FROM t1;
  } -tclbody {
    sqlite3_release_memory 
  } -sqlbody {
    COMMIT;
  }
}



















finish_test








|







 








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
...
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# This file implements regression tests for SQLite library.  The
# focus of this file is testing for correct handling of I/O errors
# such as writes failing because the disk is full.
# 
# The tests in this file use special facilities that are only
# available in the SQLite test fixture.
#
# $Id: ioerr.test,v 1.38 2008/07/08 10:19:58 danielk1977 Exp $

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

# If SQLITE_DEFAULT_AUTOVACUUM is set to true, then a simulated IO error
# on the 8th IO operation in the SQL script below doesn't report an error.
#
................................................................................
    INSERT INTO t1 SELECT randstr(50,50), randstr(9,9), randstr(90,90) FROM t1;
  } -tclbody {
    sqlite3_release_memory 
  } -sqlbody {
    COMMIT;
  }
}

ifcapable pager_pragmas&&autovacuum {
  do_ioerr_test ioerr-12 -ckrefcount true -erc 1 -sqlprep {
     PRAGMA page_size = 512;
     PRAGMA auto_vacuum = incremental;
     CREATE TABLE t1(x);
     INSERT INTO t1 VALUES( randomblob(1   * (512-4)) );
     INSERT INTO t1 VALUES( randomblob(110 * (512-4)) );
     INSERT INTO t1 VALUES( randomblob(2   * (512-4)) );
     INSERT INTO t1 VALUES( randomblob(110 * (512-4)) );
     INSERT INTO t1 VALUES( randomblob(3 * (512-4)) );
     DELETE FROM t1 WHERE rowid = 3;
     PRAGMA incremental_vacuum = 2;
     DELETE FROM t1 WHERE rowid = 1;
  } -sqlbody {
     PRAGMA incremental_vacuum = 1;
  }
}

finish_test

Changes to test/rdonly.test.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
57
58
59
60
61
62
63
64













65
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests to make sure SQLite treats a database
# as readonly if its write version is set to  high.
#
# $Id: rdonly.test,v 1.1 2007/04/24 17:27:52 drh Exp $

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


# Create a database.
#
................................................................................
  hexio_write test.db 18 01
  sqlite3 db test.db
  catchsql {
    INSERT INTO t1 VALUES(2);
    SELECT * FROM t1;
  }
} {0 {1 2}}














finish_test







|







 








>
>
>
>
>
>
>
>
>
>
>
>
>

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests to make sure SQLite treats a database
# as readonly if its write version is set to  high.
#
# $Id: rdonly.test,v 1.2 2008/07/08 10:19:58 danielk1977 Exp $

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


# Create a database.
#
................................................................................
  hexio_write test.db 18 01
  sqlite3 db test.db
  catchsql {
    INSERT INTO t1 VALUES(2);
    SELECT * FROM t1;
  }
} {0 {1 2}}

# Now, after connection [db] has loaded the database schema, modify the
# write-version of the file (and the change-counter, so that the 
# write-version is reloaded). This way, SQLite does not discover that
# the database is read-only until after it is locked.
#
do_test rdonly-1.6 {
  hexio_write test.db 18 02              ; # write-version
  hexio_write test.db 24 11223344        ; # change-counter
  catchsql {
    INSERT INTO t1 VALUES(2);
  }
} {1 {attempt to write a readonly database}}

finish_test