| 1 |
# 2013 April 02 |
| 2 |
# |
| 3 |
# The author disclaims copyright to this source code. In place of |
| 4 |
# a legal notice, here is a blessing: |
| 5 |
# |
| 6 |
# May you do good and not evil. |
| 7 |
# May you find forgiveness for yourself and forgive others. |
| 8 |
# May you share freely, never taking more than you give. |
| 9 |
# |
| 10 |
#*********************************************************************** |
| 11 |
# |
| 12 |
# This file contains fault injection tests designed to test the btree.c |
| 13 |
# module. |
| 14 |
# |
| 15 |
|
| 16 |
set testdir [file dirname $argv0] |
| 17 |
source $testdir/tester.tcl |
| 18 |
source $testdir/malloc_common.tcl |
| 19 |
set testprefix btreefault |
| 20 |
|
| 21 |
# This test will not work with an in-memory journal, as the database will |
| 22 |
# become corrupt if an error is injected into a transaction after it starts |
| 23 |
# writing data out to the db file. |
| 24 |
if {[permutation]=="inmemory_journal"} { |
| 25 |
finish_test |
| 26 |
return |
| 27 |
} |
| 28 |
|
| 29 |
do_test 1-pre1 { |
| 30 |
execsql { |
| 31 |
PRAGMA auto_vacuum = incremental; |
| 32 |
PRAGMA journal_mode = DELETE; |
| 33 |
CREATE TABLE t1(a PRIMARY KEY, b); |
| 34 |
INSERT INTO t1 VALUES(randomblob(1000), randomblob(100)); |
| 35 |
INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; |
| 36 |
INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; |
| 37 |
INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; |
| 38 |
INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; |
| 39 |
DELETE FROM t1 WHERE rowid%2; |
| 40 |
} |
| 41 |
faultsim_save_and_close |
| 42 |
} {} |
| 43 |
|
| 44 |
do_faultsim_test 1 -prep { |
| 45 |
faultsim_restore_and_reopen |
| 46 |
set ::STMT [sqlite3_prepare db "SELECT * FROM t1 ORDER BY a" -1 DUMMY] |
| 47 |
sqlite3_step $::STMT |
| 48 |
sqlite3_step $::STMT |
| 49 |
} -body { |
| 50 |
execsql { PRAGMA incremental_vacuum = 10 } |
| 51 |
} -test { |
| 52 |
sqlite3_finalize $::STMT |
| 53 |
faultsim_test_result {0 {}} |
| 54 |
faultsim_integrity_check |
| 55 |
} |
| 56 |
|
| 57 |
#------------------------------------------------------------------------- |
| 58 |
# dbsqlfuzz crash-6ef3cd3b18ccc5de86120950a0498641acd90a33.txt |
| 59 |
# |
| 60 |
reset_db |
| 61 |
|
| 62 |
do_execsql_test 2.0 { |
| 63 |
CREATE TABLE t1(i INTEGER PRIMARY KEY, a, b); |
| 64 |
CREATE INDEX i1 ON t1(b); |
| 65 |
CREATE TABLE t2(x, y); |
| 66 |
} |
| 67 |
|
| 68 |
do_execsql_test 2.1 { |
| 69 |
INSERT INTO t1 VALUES(25, 25, 25); |
| 70 |
INSERT INTO t2 VALUES(25, 'a'), (25, 'b'), (25, 'c'); |
| 71 |
} |
| 72 |
|
| 73 |
faultsim_save |
| 74 |
do_test 2.2 { |
| 75 |
set res [list] |
| 76 |
db eval { |
| 77 |
SELECT x, y FROM t1 CROSS JOIN t2 WHERE t2.x=t1.i AND +t1.i=25 ORDER BY b |
| 78 |
} { |
| 79 |
lappend res $x $y |
| 80 |
if {$y=="b"} { |
| 81 |
db eval { DELETE FROM t1 WHERE i=25 } |
| 82 |
} |
| 83 |
} |
| 84 |
set res |
| 85 |
} {25 a 25 b} |
| 86 |
|
| 87 |
do_faultsim_test 2 -faults oom-t* -prep { |
| 88 |
faultsim_restore_and_reopen |
| 89 |
db eval {SELECT * FROM sqlite_master} |
| 90 |
} -body { |
| 91 |
set ::myres [list] |
| 92 |
db eval { |
| 93 |
SELECT x, y FROM t1 CROSS JOIN t2 WHERE t2.x=t1.i AND +t1.i=25 ORDER BY b |
| 94 |
} { |
| 95 |
lappend ::myres $x $y |
| 96 |
if {$y=="b"} { |
| 97 |
db eval { DELETE FROM t1 WHERE i=25 } |
| 98 |
} |
| 99 |
} |
| 100 |
set ::myres |
| 101 |
} -test { |
| 102 |
faultsim_test_result {0 {25 a 25 b}} |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
finish_test |