Improve coverage of btree.c. (CVS 5363)

FossilOrigin-Name: f6d9cb835b8f75545f455328d61ba225e7da9bc4
This commit is contained in:
danielk1977
2008-07-08 10:19:58 +00:00
parent 983e230939
commit 3aa4b67f04
5 changed files with 134 additions and 13 deletions
+91 -2
View File
@@ -13,7 +13,7 @@
# 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 $
# $Id: corrupt2.test,v 1.9 2008/07/08 10:19:58 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -177,7 +177,7 @@ do_test corrupt2-4.1 {
} db2
} {1 {database disk image is malformed}}
do_test corrupt2-4.1 {
do_test corrupt2-5.1 {
file delete -force corrupt.db
file delete -force corrupt.db-journal
sqlite3 db2 corrupt.db
@@ -227,4 +227,93 @@ 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
+20 -1
View File
@@ -15,7 +15,7 @@
# 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 $
# $Id: ioerr.test,v 1.38 2008/07/08 10:19:58 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -288,4 +288,23 @@ ifcapable memorymanage {
}
}
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
+14 -1
View File
@@ -13,7 +13,7 @@
# 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 $
# $Id: rdonly.test,v 1.2 2008/07/08 10:19:58 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -62,4 +62,17 @@ do_test rdonly-1.5 {
}
} {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