Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/test/walseh1.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / test / walseh1.test` 148 lines ยท 3648 bytes Raw Blame History 1 # 2021 August 16 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 13 set testdir [file dirname $argv0] 14 source $testdir/tester.tcl 15 source $testdir/malloc_common.tcl 16 set testprefix walseh1 17 18 set ::seh_countdown 0 19 set ::seh_errno 10 20 proc seh_faultsim_callback {iFault} { 21 if {$iFault==650} { 22 incr ::seh_countdown -1 23 if {$::seh_countdown==0} { return $::seh_errno } 24 } 25 return 0 26 } 27 28 proc seh_injectinstall {} { 29 sqlite3_test_control_fault_install seh_faultsim_callback 30 } 31 proc seh_injectuninstall {} { 32 sqlite3_test_control_fault_install 33 } 34 proc seh_injectstart {iFail} { 35 set ::seh_errno [expr 2+$iFail*10] 36 set ::seh_countdown $iFail 37 } 38 proc seh_injectstop {} { 39 set res [expr $::seh_countdown<=0] 40 set ::seh_countdown 0 41 set res 42 } 43 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 \ 50 ] 51 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" 56 } 57 } 58 59 do_execsql_test 1.0 { 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); 64 } {wal} 65 faultsim_save_and_close 66 67 do_faultsim_test 1 -faults seh -prep { 68 catch { db2 close } 69 faultsim_restore_and_reopen 70 execsql { SELECT * FROM sqlite_schema } 71 sqlite3 db2 test.db 72 } -body { 73 execsql { SELECT * FROM t1 } db2 74 } -test { 75 faultsim_test_result {0 {1 2 3 4}} 76 if {$testrc} { test_system_errno db2 $::seh_errno } 77 } 78 catch { db2 close } 79 80 faultsim_save_and_close 81 82 do_faultsim_test 2 -faults seh -prep { 83 catch { db close } 84 faultsim_restore_and_reopen 85 } -body { 86 execsql { SELECT * FROM t1 } 87 } -test { 88 faultsim_test_result {0 {1 2 3 4}} 89 if {$testrc} { test_system_errno db $::seh_errno } 90 } 91 92 do_faultsim_test 3 -faults seh -prep { 93 catch { db close } 94 faultsim_restore_and_reopen 95 } -body { 96 execsql { INSERT INTO t1 VALUES(5, 6) } 97 execsql { SELECT * FROM t1 } 98 } -test { 99 faultsim_test_result {0 {1 2 3 4 5 6}} 100 if {$testrc} { test_system_errno db $::seh_errno } 101 } 102 103 do_faultsim_test 4 -faults seh -prep { 104 catch { db close } 105 faultsim_restore_and_reopen 106 } -body { 107 execsql { PRAGMA wal_checkpoint } 108 execsql { INSERT INTO t1 VALUES(7, 8) } 109 execsql { SELECT * FROM t1 } 110 } -test { 111 faultsim_test_result {0 {1 2 3 4 7 8}} 112 if {$testrc} { test_system_errno db $::seh_errno } 113 } 114 catch { db close } 115 116 do_faultsim_test 5 -faults seh -prep { 117 catch { db close } 118 faultsim_restore_and_reopen 119 execsql { 120 PRAGMA cache_size = 5; 121 BEGIN; 122 WITH s(i) AS ( 123 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50 124 ) 125 INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM s; 126 } 127 } -body { 128 execsql ROLLBACK 129 } -test { 130 faultsim_test_result {0 {}} 131 if {$testrc} { test_system_errno db $::seh_errno } 132 } 133 catch { db close } 134 135 do_faultsim_test 6 -faults seh -prep { 136 catch { db close } 137 faultsim_restore_and_reopen 138 } -body { 139 execsql { PRAGMA wal_checkpoint = TRUNCATE } 140 execsql { INSERT INTO t1 VALUES(7, 8) } 141 execsql { SELECT * FROM t1 } 142 } -test { 143 faultsim_test_result {0 {1 2 3 4 7 8}} 144 if {$testrc} { test_system_errno db $::seh_errno } 145 } 146 catch { db close } 147 148 finish_test