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/ext/rbu/rbufault.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 / ext / rbu / rbufault.test` 234 lines ยท 6698 bytes Raw Blame History 1 # 2014 October 22 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 source [file join [file dirname [info script]] rbu_common.tcl] 14 if_no_rbu_support { finish_test ; return } 15 source $testdir/malloc_common.tcl 16 set ::testprefix rbufault 17 18 proc copy_if_exists {src target} { 19 if {[file exists $src]} { 20 forcecopy $src $target 21 } else { 22 forcedelete $target 23 } 24 } 25 26 foreach {tn2 setup sql expect} { 27 1 { 28 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); 29 CREATE INDEX t1cb ON t1(c, b); 30 INSERT INTO t1 VALUES(1, 1, 1); 31 INSERT INTO t1 VALUES(2, 2, 2); 32 INSERT INTO t1 VALUES(3, 3, 3); 33 34 CREATE TABLE rbu.data_t1(a, b, c, rbu_control); 35 INSERT INTO data_t1 VALUES(2, NULL, NULL, 1); 36 INSERT INTO data_t1 VALUES(3, 'three', NULL, '.x.'); 37 INSERT INTO data_t1 VALUES(4, 4, 4, 0); 38 } { 39 SELECT * FROM t1 40 } {1 1 1 3 three 3 4 4 4} 41 42 2 { 43 CREATE TABLE t2(a PRIMARY KEY, b, c) WITHOUT ROWID; 44 CREATE INDEX t2cb ON t2(c, b); 45 INSERT INTO t2 VALUES('a', 'a', 'a'); 46 INSERT INTO t2 VALUES('b', 'b', 'b'); 47 INSERT INTO t2 VALUES('c', 'c', 'c'); 48 49 CREATE TABLE rbu.data_t2(a, b, c, rbu_control); 50 INSERT INTO data_t2 VALUES('b', NULL, NULL, 1); 51 INSERT INTO data_t2 VALUES('c', 'see', NULL, '.x.'); 52 INSERT INTO data_t2 VALUES('d', 'd', 'd', 0); 53 } { 54 SELECT * FROM t2 55 } {a a a c see c d d d} 56 57 3 { 58 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); 59 CREATE TABLE t2(a PRIMARY KEY, b, c) WITHOUT ROWID; 60 CREATE INDEX t1cb ON t1(c, b); 61 CREATE INDEX t2cb ON t2(c, b); 62 63 CREATE TABLE rbu.data_t1(a, b, c, rbu_control); 64 CREATE TABLE rbu.data_t2(a, b, c, rbu_control); 65 INSERT INTO data_t1 VALUES(1, 2, 3, 0); 66 INSERT INTO data_t2 VALUES(4, 5, 6, 0); 67 } { 68 SELECT * FROM t1 UNION ALL SELECT * FROM t2 69 } {1 2 3 4 5 6} 70 71 4 { 72 CREATE TABLE t1(a PRIMARY KEY, b, c); 73 CREATE INDEX t1c ON t1(c); 74 INSERT INTO t1 VALUES('A', 'B', 'C'); 75 INSERT INTO t1 VALUES('D', 'E', 'F'); 76 77 CREATE TABLE rbu.data_t1(a, b, c, rbu_control); 78 INSERT INTO data_t1 VALUES('D', NULL, NULL, 1); 79 INSERT INTO data_t1 VALUES('A', 'Z', NULL, '.x.'); 80 INSERT INTO data_t1 VALUES('G', 'H', 'I', 0); 81 } { 82 SELECT * FROM t1 ORDER BY a; 83 } {A Z C G H I} 84 85 5 { 86 CREATE TABLE t1(a, b, c); 87 CREATE INDEX t1c ON t1(c, b); 88 89 CREATE TABLE rbu.data_t1(a, b, c, rbu_rowid, rbu_control); 90 INSERT INTO data_t1 VALUES('a', 'b', 'c', 1, 0); 91 INSERT INTO data_t1 VALUES('d', 'e', 'f', '2', 0); 92 } { 93 SELECT * FROM t1 ORDER BY a; 94 } {a b c d e f} 95 96 } { 97 catch {db close} 98 forcedelete rbu.db test.db 99 sqlite3 db test.db 100 execsql { 101 PRAGMA encoding = utf16; 102 ATTACH 'rbu.db' AS rbu; 103 } 104 execsql $setup 105 db close 106 107 forcecopy test.db test.db.bak 108 forcecopy rbu.db rbu.db.bak 109 110 foreach {tn f reslist} { 111 1 oom-tra* { 112 {0 SQLITE_DONE} 113 {1 {SQLITE_NOMEM - out of memory}} 114 {1 SQLITE_NOMEM} 115 {1 SQLITE_IOERR_NOMEM} 116 {1 {SQLITE_NOMEM - unable to open a temporary database file for storing temporary tables}} 117 } 118 119 2 ioerr-* { 120 {0 SQLITE_DONE} 121 {1 {SQLITE_IOERR - disk I/O error}} 122 {1 SQLITE_IOERR} 123 {1 SQLITE_IOERR_WRITE} 124 {1 SQLITE_IOERR_READ} 125 {1 SQLITE_IOERR_FSYNC} 126 {1 {SQLITE_ERROR - SQL logic error}} 127 {1 {SQLITE_ERROR - unable to open database: rbu.db}} 128 {1 {SQLITE_IOERR - unable to open database: rbu.db}} 129 } 130 131 3 shmerr-* { 132 {0 SQLITE_DONE} 133 {1 {SQLITE_IOERR - disk I/O error}} 134 {1 SQLITE_IOERR} 135 } 136 } { 137 138 catch {db close} 139 sqlite3_shutdown 140 set lookaside_config [sqlite3_config_lookaside 0 0] 141 sqlite3_initialize 142 autoinstall_test_functions 143 144 do_faultsim_test 2.$tn2 -faults $::f -prep { 145 catch { db close } 146 forcedelete test.db-journal test.db-wal rbu.db-journal rbu.db-wal 147 forcecopy test.db.bak test.db 148 forcecopy rbu.db.bak rbu.db 149 } -body { 150 sqlite3rbu rbu test.db rbu.db 151 while {[rbu step]=="SQLITE_OK"} {} 152 rbu close 153 } -test { 154 faultsim_test_result {*}$::reslist 155 if {$testrc==0} { 156 sqlite3 db test.db 157 faultsim_integrity_check 158 set res [db eval $::sql] 159 if {$res != [list {*}$::expect]} { 160 puts "" 161 puts "res: $res" 162 puts "exp: $expect" 163 error "data not as expected!" 164 } 165 } 166 } 167 168 catch {db close} 169 sqlite3_shutdown 170 sqlite3_config_lookaside {*}$lookaside_config 171 sqlite3_initialize 172 autoinstall_test_functions 173 174 175 for {set iStep 0} {$iStep<=21} {incr iStep} { 176 177 forcedelete test.db-journal test.db-wal rbu.db-journal rbu.db-wal 178 179 copy_if_exists test.db.bak test.db 180 copy_if_exists rbu.db.bak rbu.db 181 182 sqlite3rbu rbu test.db rbu.db 183 for {set x 0} {$x < $::iStep} {incr x} { rbu step } 184 rbu close 185 186 # sqlite3 x rbu.db ; puts "XYZ [x eval { SELECT * FROM rbu_state } ]" ; x close 187 188 copy_if_exists test.db test.db.bak.2 189 copy_if_exists test.db-wal test.db.bak.2-wal 190 copy_if_exists test.db-oal test.db.bak.2-oal 191 copy_if_exists rbu.db rbu.db.bak.2 192 193 do_faultsim_test 3.$tn.$iStep -faults $::f -prep { 194 catch { db close } 195 forcedelete test.db-journal test.db-wal rbu.db-journal rbu.db-wal 196 copy_if_exists test.db.bak.2 test.db 197 copy_if_exists test.db.bak.2-wal test.db-wal 198 copy_if_exists test.db.bak.2-oal test.db-oal 199 copy_if_exists rbu.db.bak.2 rbu.db 200 } -body { 201 sqlite3rbu rbu test.db rbu.db 202 rbu step 203 rbu close 204 } -test { 205 206 if {$testresult=="SQLITE_OK"} {set testresult "SQLITE_DONE"} 207 faultsim_test_result {*}$::reslist 208 209 if {$testrc==0} { 210 # No error occurred. If the RBU has not already been fully applied, 211 # apply the rest of it now. Then ensure that the final state of the 212 # target db is as expected. And that "PRAGMA integrity_check" 213 # passes. 214 sqlite3rbu rbu test.db rbu.db 215 while {[rbu step] == "SQLITE_OK"} {} 216 rbu close 217 218 sqlite3 db test.db 219 faultsim_integrity_check 220 221 set res [db eval $::sql] 222 if {$res != [list {*}$::expect]} { 223 puts "" 224 puts "res: $res" 225 puts "exp: $::expect" 226 error "data not as expected!" 227 } 228 } 229 } 230 } 231 } 232 } 233 234 finish_test