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 fault-injection test cases for the
13 # sqlite3_db_cacheflush API.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 set testprefix cffault
19 source $testdir/malloc_common.tcl
21 # Run the supplied SQL on a copy of the database currently stored on
22 # disk in file $dbfile.
23 proc diskquery {dbfile sql} {
24 forcecopy $dbfile dq.db
26 set res [execsql $sql dq]
32 CREATE TABLE t1(a PRIMARY KEY, b);
33 CREATE INDEX i1 ON t1(b);
34 INSERT INTO t1 VALUES(1, 2);
35 INSERT INTO t1 VALUES(3, 4);
36 INSERT INTO t1 VALUES(5, 6);
37 INSERT INTO t1 VALUES(7, 8);
39 faultsim_save_and_close
41 do_faultsim_test 1.1 -prep {
42 faultsim_restore_and_reopen
48 sqlite3_db_cacheflush db
50 if {[sqlite3_get_autocommit db]} { error "Transaction rolled back!" }
51 faultsim_test_result {0 {}} {1 {disk I/O error}}
52 catch { db eval COMMIT }
53 faultsim_integrity_check
56 do_faultsim_test 1.2 -prep {
57 faultsim_restore_and_reopen
64 db eval { SELECT * FROM t1 } {
65 if {$a==5} { catch { sqlite3_db_cacheflush db } }
70 faultsim_test_result {0 {1 3 3 5 5 7 7 9}} {1 {disk I/O error}}
71 catch { db eval COMMIT }
72 faultsim_integrity_check
75 #-------------------------------------------------------------------------
78 CREATE TABLE t1(a PRIMARY KEY, b, c);
79 CREATE INDEX i1 ON t1(b);
80 CREATE INDEX i2 ON t1(c, b);
81 INSERT INTO t1 VALUES(1, 2, randomblob(600));
82 INSERT INTO t1 VALUES(3, 4, randomblob(600));
83 INSERT INTO t1 VALUES(5, 6, randomblob(600));
84 INSERT INTO t1 VALUES(7, 8, randomblob(600));
85 INSERT INTO t1 VALUES(9, 10, randomblob(600));
87 faultsim_save_and_close
89 do_faultsim_test 2.1 -prep {
90 faultsim_restore_and_reopen
97 db eval { SELECT * FROM t1 } {
98 if {$a==5} { catch { sqlite3_db_cacheflush db } }
103 faultsim_test_result {0 {1 3 3 5 5 7 7 9 9 11}} {1 {disk I/O error}}
104 catch { db eval { INSERT INTO t1 VALUES(11, 12, randomblob(600)) } }
105 catch { db eval COMMIT }
106 faultsim_integrity_check
109 do_faultsim_test 2.2 -prep {
110 faultsim_restore_and_reopen
116 sqlite3_db_cacheflush db
118 if {[sqlite3_get_autocommit db]} { error "Transaction rolled back!" }
119 faultsim_test_result {0 {}} {1 {disk I/O error}}
120 catch { db eval { SELECT * FROM t1 } }
121 catch { db eval COMMIT }
122 faultsim_integrity_check
125 do_faultsim_test 2.3 -prep {
126 faultsim_restore_and_reopen
132 sqlite3_db_cacheflush db
134 if {[sqlite3_get_autocommit db]} { error "Transaction rolled back!" }
135 faultsim_test_result {0 {}} {1 {disk I/O error}}
136 catch { db eval { INSERT INTO t1 VALUES(11, 12, randomblob(600)) } }
137 catch { db eval COMMIT }
138 faultsim_integrity_check
141 do_faultsim_test 2.4 -prep {
142 faultsim_restore_and_reopen
148 catch { sqlite3_db_cacheflush db }
149 catch { sqlite3_db_release_memory db }
150 catch { sqlite3_db_cacheflush db }
151 execsql { SELECT a, b FROM t1 }
153 faultsim_test_result {0 {1 1 3 3 5 5 7 7 9 9}} {1 {disk I/O error}}
155 faultsim_integrity_check