3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # This file contains tests for fault-injection when SQLite is used with
13 # a temp file database.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 source $testdir/malloc_common.tcl
19 set testprefix tempfault
21 # sqlite3_memdebug_vfs_oom_test 0
23 do_faultsim_test 1 -faults * -prep {
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);
32 execsql { INSERT INTO t1 VALUES(5, 6) }
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"
39 if {$testrc==0 && $msg != "1 2 3 4 5 6"} {
40 error "data mismatch 2: $msg"
42 faultsim_integrity_check
45 do_faultsim_test 2 -faults * -prep {
48 PRAGMA page_size = 1024;
49 PRAGMA cache_size = 10;
50 CREATE TABLE t1(a, b);
51 CREATE INDEX i1 ON t1(b, a);
52 WITH x(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<100)
53 INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM x;
56 execsql { UPDATE t1 SET a = randomblob(99) }
58 faultsim_test_result {0 {}}
59 faultsim_integrity_check db
63 do_faultsim_test 2.1 -faults * -prep {
64 if {[info commands db]==""} {
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;
76 execsql { UPDATE t1 SET a = randomblob(99) }
78 faultsim_test_result {0 {}}
79 faultsim_integrity_check db
82 do_faultsim_test 3 -faults * -prep {
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;
95 UPDATE t1 SET a = randomblob(99);
97 UPDATE t1 SET a = randomblob(98) WHERE (rowid%10)==0;
99 UPDATE t1 SET a = randomblob(97) WHERE (rowid%5)==0;
104 faultsim_test_result {0 {}}
105 faultsim_integrity_check db
108 do_faultsim_test 4 -faults * -prep {
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;
121 UPDATE t1 SET a = randomblob(99);
123 UPDATE t1 SET a = randomblob(98) WHERE (rowid%10)==0;
125 UPDATE t1 SET a = randomblob(97) WHERE (rowid%5)==0;
130 faultsim_test_result {0 {}}
133 sqlite3_memdebug_vfs_oom_test 1