dan | 67330a1 | 2016-04-11 18:07:47 +0000 | [diff] [blame] | 1 | # 2016 April 11 |
| 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 tests for fault-injection when SQLite is used with |
| 13 | # a temp file database. |
| 14 | # |
| 15 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
| 18 | source $testdir/malloc_common.tcl |
| 19 | set testprefix tempfault |
| 20 | |
dan | 6572c16 | 2016-04-23 14:55:28 +0000 | [diff] [blame] | 21 | # sqlite3_memdebug_vfs_oom_test 0 |
dan | 67330a1 | 2016-04-11 18:07:47 +0000 | [diff] [blame] | 22 | |
dan | 6572c16 | 2016-04-23 14:55:28 +0000 | [diff] [blame] | 23 | do_faultsim_test 1 -faults * -prep { |
dan | 67330a1 | 2016-04-11 18:07:47 +0000 | [diff] [blame] | 24 | sqlite3 db "" |
| 25 | db eval { |
| 26 | PRAGMA page_size = 1024; |
| 27 | CREATE TABLE t1(a, b); |
| 28 | INSERT INTO t1 VALUES(1, 2); |
| 29 | INSERT INTO t1 VALUES(3, 4); |
| 30 | } |
| 31 | } -body { |
| 32 | execsql { INSERT INTO t1 VALUES(5, 6) } |
| 33 | } -test { |
| 34 | faultsim_test_result {0 {}} |
| 35 | set rc [catch { execsql { SELECT * FROM t1 } } msg] |
| 36 | if {$rc==0 && $msg != "1 2 3 4 5 6" && $msg != "1 2 3 4"} { |
| 37 | error "data mismatch 1: $msg" |
| 38 | } |
| 39 | if {$testrc==0 && $msg != "1 2 3 4 5 6"} { |
| 40 | error "data mismatch 2: $msg" |
| 41 | } |
| 42 | faultsim_integrity_check |
| 43 | } |
| 44 | |
dan | 6572c16 | 2016-04-23 14:55:28 +0000 | [diff] [blame] | 45 | do_faultsim_test 2 -faults * -prep { |
dan | 67330a1 | 2016-04-11 18:07:47 +0000 | [diff] [blame] | 46 | sqlite3 db "" |
| 47 | db eval { |
| 48 | PRAGMA page_size = 1024; |
| 49 | PRAGMA cache_size = 10; |
| 50 | CREATE TABLE t1(a, b); |
| 51 | CREATE INDEX i1 ON t1(b, a); |
dan | 6572c16 | 2016-04-23 14:55:28 +0000 | [diff] [blame] | 52 | WITH x(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<100) |
dan | 67330a1 | 2016-04-11 18:07:47 +0000 | [diff] [blame] | 53 | INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM x; |
| 54 | } |
| 55 | } -body { |
| 56 | execsql { UPDATE t1 SET a = randomblob(99) } |
| 57 | } -test { |
| 58 | faultsim_test_result {0 {}} |
| 59 | faultsim_integrity_check db |
| 60 | } |
| 61 | |
dan | 6572c16 | 2016-04-23 14:55:28 +0000 | [diff] [blame] | 62 | catch { db close } |
| 63 | do_faultsim_test 2.1 -faults * -prep { |
| 64 | if {[info commands db]==""} { |
| 65 | sqlite3 db "" |
| 66 | execsql { |
| 67 | PRAGMA page_size = 1024; |
| 68 | PRAGMA cache_size = 10; |
| 69 | CREATE TABLE t1(a, b); |
| 70 | CREATE INDEX i1 ON t1(b, a); |
| 71 | WITH x(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<100) |
| 72 | INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM x; |
| 73 | } |
| 74 | } |
| 75 | } -body { |
| 76 | execsql { UPDATE t1 SET a = randomblob(99) } |
| 77 | } -test { |
| 78 | faultsim_test_result {0 {}} |
| 79 | faultsim_integrity_check db |
| 80 | } |
| 81 | |
| 82 | do_faultsim_test 3 -faults * -prep { |
dan | 67330a1 | 2016-04-11 18:07:47 +0000 | [diff] [blame] | 83 | sqlite3 db "" |
| 84 | db eval { |
| 85 | PRAGMA page_size = 1024; |
| 86 | PRAGMA cache_size = 10; |
| 87 | CREATE TABLE t1(a, b); |
| 88 | CREATE INDEX i1 ON t1(b, a); |
| 89 | WITH x(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<50) |
| 90 | INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM x; |
| 91 | } |
| 92 | } -body { |
| 93 | execsql { |
| 94 | BEGIN; |
| 95 | UPDATE t1 SET a = randomblob(99); |
| 96 | SAVEPOINT abc; |
| 97 | UPDATE t1 SET a = randomblob(98) WHERE (rowid%10)==0; |
| 98 | ROLLBACK TO abc; |
| 99 | UPDATE t1 SET a = randomblob(97) WHERE (rowid%5)==0; |
| 100 | ROLLBACK TO abc; |
| 101 | COMMIT; |
| 102 | } |
| 103 | } -test { |
| 104 | faultsim_test_result {0 {}} |
| 105 | faultsim_integrity_check db |
| 106 | } |
| 107 | |
| 108 | do_faultsim_test 4 -faults * -prep { |
| 109 | sqlite3 db "" |
| 110 | db eval { |
| 111 | PRAGMA page_size = 1024; |
| 112 | PRAGMA cache_size = 10; |
| 113 | CREATE TABLE t1(a, b); |
| 114 | CREATE INDEX i1 ON t1(b, a); |
| 115 | WITH x(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<50) |
| 116 | INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM x; |
| 117 | } |
| 118 | } -body { |
| 119 | execsql { |
| 120 | BEGIN; |
| 121 | UPDATE t1 SET a = randomblob(99); |
| 122 | SAVEPOINT abc; |
| 123 | UPDATE t1 SET a = randomblob(98) WHERE (rowid%10)==0; |
| 124 | ROLLBACK TO abc; |
| 125 | UPDATE t1 SET a = randomblob(97) WHERE (rowid%5)==0; |
| 126 | ROLLBACK TO abc; |
| 127 | COMMIT; |
| 128 | } |
| 129 | } -test { |
| 130 | faultsim_test_result {0 {}} |
| 131 | } |
| 132 | |
| 133 | sqlite3_memdebug_vfs_oom_test 1 |
| 134 | finish_test |