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 #***********************************************************************
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
15 source $testdir/malloc_common.tcl
16 set testprefix walseh1
20 proc seh_faultsim_callback {iFault} {
22 incr ::seh_countdown -1
23 if {$::seh_countdown==0} { return $::seh_errno }
28 proc seh_injectinstall {} {
29 sqlite3_test_control_fault_install seh_faultsim_callback
31 proc seh_injectuninstall {} {
32 sqlite3_test_control_fault_install
34 proc seh_injectstart {iFail} {
35 set ::seh_errno [expr 2+$iFail*10]
36 set ::seh_countdown $iFail
38 proc seh_injectstop {} {
39 set res [expr $::seh_countdown<=0]
44 set FAULTSIM(seh) [list \
45 -injectinstall seh_injectinstall \
46 -injectstart seh_injectstart \
47 -injectstop seh_injectstop \
48 -injecterrlist {{1 {disk I/O error}}} \
49 -injectuninstall seh_injectuninstall \
52 proc test_system_errno {db expect} {
53 set serrno [sqlite3_system_errno $db]
54 if {$serrno!=$expect} {
55 error "surprising system_errno. Expected $expect, got $serrno"
60 PRAGMA journal_mode = wal;
61 CREATE TABLE t1(x, y);
62 INSERT INTO t1 VALUES(1, 2);
63 INSERT INTO t1 VALUES(3, 4);
65 faultsim_save_and_close
67 do_faultsim_test 1 -faults seh -prep {
69 faultsim_restore_and_reopen
70 execsql { SELECT * FROM sqlite_schema }
73 execsql { SELECT * FROM t1 } db2
75 faultsim_test_result {0 {1 2 3 4}}
76 if {$testrc} { test_system_errno db2 $::seh_errno }
80 faultsim_save_and_close
82 do_faultsim_test 2 -faults seh -prep {
84 faultsim_restore_and_reopen
86 execsql { SELECT * FROM t1 }
88 faultsim_test_result {0 {1 2 3 4}}
89 if {$testrc} { test_system_errno db $::seh_errno }
92 do_faultsim_test 3 -faults seh -prep {
94 faultsim_restore_and_reopen
96 execsql { INSERT INTO t1 VALUES(5, 6) }
97 execsql { SELECT * FROM t1 }
99 faultsim_test_result {0 {1 2 3 4 5 6}}
100 if {$testrc} { test_system_errno db $::seh_errno }
103 do_faultsim_test 4 -faults seh -prep {
105 faultsim_restore_and_reopen
107 execsql { PRAGMA wal_checkpoint }
108 execsql { INSERT INTO t1 VALUES(7, 8) }
109 execsql { SELECT * FROM t1 }
111 faultsim_test_result {0 {1 2 3 4 7 8}}
112 if {$testrc} { test_system_errno db $::seh_errno }
116 do_faultsim_test 5 -faults seh -prep {
118 faultsim_restore_and_reopen
120 PRAGMA cache_size = 5;
123 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50
125 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM s;
130 faultsim_test_result {0 {}}
131 if {$testrc} { test_system_errno db $::seh_errno }
135 do_faultsim_test 6 -faults seh -prep {
137 faultsim_restore_and_reopen
139 execsql { PRAGMA wal_checkpoint = TRUNCATE }
140 execsql { INSERT INTO t1 VALUES(7, 8) }
141 execsql { SELECT * FROM t1 }
143 faultsim_test_result {0 {1 2 3 4 7 8}}
144 if {$testrc} { test_system_errno db $::seh_errno }