dan | b0ac3e3 | 2010-06-16 10:55:42 +0000 | [diff] [blame] | 1 | # 2010 June 15 |
| 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/lock_common.tcl |
| 16 | source $testdir/malloc_common.tcl |
| 17 | |
| 18 | set a_string_counter 1 |
| 19 | proc a_string {n} { |
| 20 | global a_string_counter |
| 21 | incr a_string_counter |
| 22 | string range [string repeat "${a_string_counter}." $n] 1 $n |
| 23 | } |
| 24 | db func a_string a_string |
| 25 | |
dan | 273f3f0 | 2010-06-26 15:42:33 +0000 | [diff] [blame] | 26 | if 1 { |
| 27 | |
dan | b0ac3e3 | 2010-06-16 10:55:42 +0000 | [diff] [blame] | 28 | #------------------------------------------------------------------------- |
| 29 | # Test fault-injection while rolling back a hot-journal file. |
| 30 | # |
| 31 | do_test pagerfault-1-pre1 { |
| 32 | execsql { |
| 33 | PRAGMA journal_mode = DELETE; |
| 34 | PRAGMA cache_size = 10; |
| 35 | CREATE TABLE t1(a UNIQUE, b UNIQUE); |
| 36 | INSERT INTO t1 VALUES(a_string(200), a_string(300)); |
| 37 | INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1; |
| 38 | INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1; |
| 39 | BEGIN; |
| 40 | INSERT INTO t1 SELECT a_string(201), a_string(301) FROM t1; |
| 41 | INSERT INTO t1 SELECT a_string(202), a_string(302) FROM t1; |
| 42 | INSERT INTO t1 SELECT a_string(203), a_string(303) FROM t1; |
| 43 | INSERT INTO t1 SELECT a_string(204), a_string(304) FROM t1; |
| 44 | } |
| 45 | faultsim_save_and_close |
| 46 | } {} |
| 47 | do_faultsim_test pagerfault-1 -prep { |
| 48 | faultsim_restore_and_reopen |
| 49 | } -body { |
| 50 | execsql { SELECT count(*) FROM t1 } |
| 51 | } -test { |
| 52 | faultsim_test_result {0 4} |
| 53 | faultsim_integrity_check |
| 54 | if {[db one { SELECT count(*) FROM t1 }] != 4} { |
| 55 | error "Database content appears incorrect" |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | #------------------------------------------------------------------------- |
dan | de4996e | 2010-06-19 11:30:41 +0000 | [diff] [blame] | 60 | # Test fault-injection while rolling back a hot-journal file with a |
| 61 | # page-size different from the current value stored on page 1 of the |
| 62 | # database file. |
| 63 | # |
| 64 | do_test pagerfault-2-pre1 { |
| 65 | testvfs tv -default 1 |
| 66 | tv filter xSync |
| 67 | tv script xSyncCb |
| 68 | proc xSyncCb {filename args} { |
| 69 | if {[string match *journal filename]==0} faultsim_save |
| 70 | } |
| 71 | faultsim_delete_and_reopen |
| 72 | execsql { |
| 73 | PRAGMA page_size = 4096; |
| 74 | BEGIN; |
| 75 | CREATE TABLE abc(a, b, c); |
| 76 | INSERT INTO abc VALUES('o', 't', 't'); |
| 77 | INSERT INTO abc VALUES('f', 'f', 's'); |
| 78 | INSERT INTO abc SELECT * FROM abc; -- 4 |
| 79 | INSERT INTO abc SELECT * FROM abc; -- 8 |
| 80 | INSERT INTO abc SELECT * FROM abc; -- 16 |
| 81 | INSERT INTO abc SELECT * FROM abc; -- 32 |
| 82 | INSERT INTO abc SELECT * FROM abc; -- 64 |
| 83 | INSERT INTO abc SELECT * FROM abc; -- 128 |
| 84 | INSERT INTO abc SELECT * FROM abc; -- 256 |
| 85 | COMMIT; |
| 86 | PRAGMA page_size = 1024; |
| 87 | VACUUM; |
| 88 | } |
| 89 | db close |
| 90 | tv delete |
| 91 | } {} |
| 92 | do_faultsim_test pagerfault-2 -prep { |
| 93 | faultsim_restore_and_reopen |
| 94 | } -body { |
| 95 | execsql { SELECT * FROM abc } |
| 96 | } -test { |
| 97 | set answer [split [string repeat "ottffs" 128] ""] |
| 98 | faultsim_test_result [list 0 $answer] |
| 99 | faultsim_integrity_check |
| 100 | set res [db eval { SELECT * FROM abc }] |
| 101 | if {$res != $answer} { error "Database content appears incorrect ($res)" } |
dan | ec6ffc1 | 2010-06-24 19:16:06 +0000 | [diff] [blame] | 102 | } |
dan | de4996e | 2010-06-19 11:30:41 +0000 | [diff] [blame] | 103 | |
| 104 | #------------------------------------------------------------------------- |
dan | b0ac3e3 | 2010-06-16 10:55:42 +0000 | [diff] [blame] | 105 | # Test fault-injection while rolling back hot-journals that were created |
| 106 | # as part of a multi-file transaction. |
| 107 | # |
dan | de4996e | 2010-06-19 11:30:41 +0000 | [diff] [blame] | 108 | do_test pagerfault-3-pre1 { |
dan | b0ac3e3 | 2010-06-16 10:55:42 +0000 | [diff] [blame] | 109 | testvfs tstvfs -default 1 |
| 110 | tstvfs filter xDelete |
| 111 | tstvfs script xDeleteCallback |
| 112 | |
| 113 | proc xDeleteCallback {method file args} { |
| 114 | set file [file tail $file] |
| 115 | if { [string match *mj* $file] } { faultsim_save } |
| 116 | } |
| 117 | |
| 118 | faultsim_delete_and_reopen |
| 119 | db func a_string a_string |
| 120 | |
| 121 | execsql { |
| 122 | ATTACH 'test.db2' AS aux; |
| 123 | PRAGMA journal_mode = DELETE; |
| 124 | PRAGMA main.cache_size = 10; |
| 125 | PRAGMA aux.cache_size = 10; |
| 126 | |
| 127 | CREATE TABLE t1(a UNIQUE, b UNIQUE); |
| 128 | CREATE TABLE aux.t2(a UNIQUE, b UNIQUE); |
| 129 | INSERT INTO t1 VALUES(a_string(200), a_string(300)); |
| 130 | INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1; |
| 131 | INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1; |
| 132 | INSERT INTO t2 SELECT * FROM t1; |
| 133 | |
| 134 | BEGIN; |
| 135 | INSERT INTO t1 SELECT a_string(201), a_string(301) FROM t1; |
| 136 | INSERT INTO t1 SELECT a_string(202), a_string(302) FROM t1; |
| 137 | INSERT INTO t1 SELECT a_string(203), a_string(303) FROM t1; |
| 138 | INSERT INTO t1 SELECT a_string(204), a_string(304) FROM t1; |
| 139 | REPLACE INTO t2 SELECT * FROM t1; |
| 140 | COMMIT; |
| 141 | } |
| 142 | |
| 143 | db close |
| 144 | tstvfs delete |
| 145 | } {} |
dan | ec6ffc1 | 2010-06-24 19:16:06 +0000 | [diff] [blame] | 146 | do_faultsim_test pagerfault-3 -prep { |
dan | b0ac3e3 | 2010-06-16 10:55:42 +0000 | [diff] [blame] | 147 | faultsim_restore_and_reopen |
| 148 | } -body { |
| 149 | execsql { |
| 150 | ATTACH 'test.db2' AS aux; |
| 151 | SELECT count(*) FROM t2; |
| 152 | SELECT count(*) FROM t1; |
| 153 | } |
| 154 | } -test { |
| 155 | faultsim_test_result {0 {4 4}} {1 {unable to open database: test.db2}} |
| 156 | faultsim_integrity_check |
dan | b0ac3e3 | 2010-06-16 10:55:42 +0000 | [diff] [blame] | 157 | catchsql { ATTACH 'test.db2' AS aux } |
| 158 | if {[db one { SELECT count(*) FROM t1 }] != 4 |
| 159 | || [db one { SELECT count(*) FROM t2 }] != 4 |
| 160 | } { |
| 161 | error "Database content appears incorrect" |
| 162 | } |
| 163 | } |
| 164 | |
dan | de4996e | 2010-06-19 11:30:41 +0000 | [diff] [blame] | 165 | #------------------------------------------------------------------------- |
| 166 | # Test fault-injection as part of a vanilla, no-transaction, INSERT |
| 167 | # statement. |
| 168 | # |
| 169 | do_faultsim_test pagerfault-4 -prep { |
| 170 | faultsim_delete_and_reopen |
| 171 | } -body { |
| 172 | execsql { |
| 173 | CREATE TABLE x(y); |
| 174 | INSERT INTO x VALUES('z'); |
| 175 | SELECT * FROM x; |
| 176 | } |
| 177 | } -test { |
| 178 | faultsim_test_result {0 z} |
| 179 | faultsim_integrity_check |
| 180 | } |
| 181 | |
| 182 | #------------------------------------------------------------------------- |
| 183 | # Test fault-injection as part of a commit when using journal_mode=PERSIST. |
dan | 146ed78 | 2010-06-19 17:26:37 +0000 | [diff] [blame] | 184 | # Three different cases: |
| 185 | # |
| 186 | # pagerfault-5.1: With no journal_size_limit configured. |
| 187 | # pagerfault-5.2: With a journal_size_limit configured. |
| 188 | # pagerfault-5.4: Multi-file transaction. One connection has a |
| 189 | # journal_size_limit of 0, the other has no limit. |
dan | de4996e | 2010-06-19 11:30:41 +0000 | [diff] [blame] | 190 | # |
| 191 | do_test pagerfault-5-pre1 { |
| 192 | faultsim_delete_and_reopen |
| 193 | db func a_string a_string |
| 194 | execsql { |
| 195 | CREATE TABLE t1(a UNIQUE, b UNIQUE); |
| 196 | INSERT INTO t1 VALUES(a_string(200), a_string(300)); |
| 197 | INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1; |
| 198 | INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1; |
| 199 | } |
| 200 | faultsim_save_and_close |
| 201 | } {} |
| 202 | do_faultsim_test pagerfault-5.1 -prep { |
| 203 | faultsim_restore_and_reopen |
| 204 | db func a_string a_string |
| 205 | execsql { PRAGMA journal_mode = PERSIST } |
| 206 | } -body { |
| 207 | execsql { INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1 } |
| 208 | } -test { |
| 209 | faultsim_test_result {0 {}} |
| 210 | faultsim_integrity_check |
| 211 | } |
| 212 | do_faultsim_test pagerfault-5.2 -prep { |
| 213 | faultsim_restore_and_reopen |
| 214 | db func a_string a_string |
| 215 | execsql { |
| 216 | PRAGMA journal_mode = PERSIST; |
| 217 | PRAGMA journal_size_limit = 2048; |
| 218 | } |
| 219 | } -body { |
| 220 | execsql { INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1 } |
| 221 | } -test { |
| 222 | faultsim_test_result {0 {}} |
| 223 | faultsim_integrity_check |
| 224 | } |
dan | ec6ffc1 | 2010-06-24 19:16:06 +0000 | [diff] [blame] | 225 | do_faultsim_test pagerfault-5.3 -faults oom-transient -prep { |
dan | de4996e | 2010-06-19 11:30:41 +0000 | [diff] [blame] | 226 | faultsim_restore_and_reopen |
| 227 | db func a_string a_string |
| 228 | file delete -force test2.db test2.db-journal test2.db-wal |
| 229 | execsql { |
| 230 | PRAGMA journal_mode = PERSIST; |
| 231 | ATTACH 'test2.db' AS aux; |
| 232 | PRAGMA aux.journal_mode = PERSIST; |
| 233 | PRAGMA aux.journal_size_limit = 0; |
| 234 | } |
| 235 | } -body { |
| 236 | execsql { |
| 237 | BEGIN; |
| 238 | INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1; |
| 239 | CREATE TABLE aux.t2 AS SELECT * FROM t1; |
| 240 | COMMIT; |
| 241 | } |
| 242 | } -test { |
| 243 | faultsim_test_result {0 {}} |
dan | ec6ffc1 | 2010-06-24 19:16:06 +0000 | [diff] [blame] | 244 | faultsim_integrity_check |
| 245 | |
| 246 | set res "" |
| 247 | set rc [catch { set res [db one { PRAGMA aux.integrity_check }] }] |
| 248 | if {$rc!=0 || $res != "ok"} {error "integrity-check problem:$rc $res"} |
dan | de4996e | 2010-06-19 11:30:41 +0000 | [diff] [blame] | 249 | } |
| 250 | |
dan | 153eda0 | 2010-06-21 07:45:47 +0000 | [diff] [blame] | 251 | #------------------------------------------------------------------------- |
| 252 | # Test fault-injection as part of a commit when using |
| 253 | # journal_mode=TRUNCATE. |
| 254 | # |
| 255 | do_test pagerfault-6-pre1 { |
| 256 | faultsim_delete_and_reopen |
| 257 | db func a_string a_string |
| 258 | execsql { |
| 259 | CREATE TABLE t1(a UNIQUE, b UNIQUE); |
| 260 | INSERT INTO t1 VALUES(a_string(200), a_string(300)); |
| 261 | } |
| 262 | faultsim_save_and_close |
| 263 | } {} |
dan | f9b4419 | 2010-06-25 19:09:48 +0000 | [diff] [blame] | 264 | |
dan | 153eda0 | 2010-06-21 07:45:47 +0000 | [diff] [blame] | 265 | do_faultsim_test pagerfault-6.1 -prep { |
| 266 | faultsim_restore_and_reopen |
| 267 | db func a_string a_string |
| 268 | execsql { PRAGMA journal_mode = TRUNCATE } |
| 269 | } -body { |
| 270 | execsql { INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1 } |
dan | f9b4419 | 2010-06-25 19:09:48 +0000 | [diff] [blame] | 271 | execsql { INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1 } |
| 272 | } -test { |
| 273 | faultsim_test_result {0 {}} |
| 274 | faultsim_integrity_check |
| 275 | } |
| 276 | |
| 277 | # The unix vfs xAccess() method considers a file zero bytes in size to |
| 278 | # "not exist". This proc overrides that behaviour so that a zero length |
| 279 | # file is considered to exist. |
| 280 | # |
| 281 | proc xAccess {method filename op args} { |
| 282 | if {$op != "SQLITE_ACCESS_EXISTS"} { return "" } |
| 283 | return [file exists $filename] |
| 284 | } |
| 285 | do_faultsim_test pagerfault-6.2 -faults cantopen-* -prep { |
| 286 | shmfault filter xAccess |
| 287 | shmfault script xAccess |
| 288 | |
| 289 | faultsim_restore_and_reopen |
| 290 | db func a_string a_string |
| 291 | execsql { PRAGMA journal_mode = TRUNCATE } |
| 292 | } -body { |
| 293 | execsql { INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1 } |
| 294 | execsql { INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1 } |
dan | 153eda0 | 2010-06-21 07:45:47 +0000 | [diff] [blame] | 295 | } -test { |
| 296 | faultsim_test_result {0 {}} |
| 297 | faultsim_integrity_check |
| 298 | } |
| 299 | |
dan | 146ed78 | 2010-06-19 17:26:37 +0000 | [diff] [blame] | 300 | # The following was an attempt to get a bitvec malloc to fail. Didn't work. |
| 301 | # |
| 302 | # do_test pagerfault-6-pre1 { |
| 303 | # faultsim_delete_and_reopen |
| 304 | # execsql { |
| 305 | # CREATE TABLE t1(x, y, UNIQUE(x, y)); |
| 306 | # INSERT INTO t1 VALUES(1, randomblob(1501)); |
| 307 | # INSERT INTO t1 VALUES(2, randomblob(1502)); |
| 308 | # INSERT INTO t1 VALUES(3, randomblob(1503)); |
| 309 | # INSERT INTO t1 VALUES(4, randomblob(1504)); |
| 310 | # INSERT INTO t1 |
| 311 | # SELECT x, randomblob(1500+oid+(SELECT max(oid) FROM t1)) FROM t1; |
| 312 | # INSERT INTO t1 |
| 313 | # SELECT x, randomblob(1500+oid+(SELECT max(oid) FROM t1)) FROM t1; |
| 314 | # INSERT INTO t1 |
| 315 | # SELECT x, randomblob(1500+oid+(SELECT max(oid) FROM t1)) FROM t1; |
| 316 | # INSERT INTO t1 |
| 317 | # SELECT x, randomblob(1500+oid+(SELECT max(oid) FROM t1)) FROM t1; |
| 318 | # } |
| 319 | # faultsim_save_and_close |
| 320 | # } {} |
| 321 | # do_faultsim_test pagerfault-6 -prep { |
| 322 | # faultsim_restore_and_reopen |
| 323 | # } -body { |
| 324 | # execsql { |
| 325 | # BEGIN; |
| 326 | # UPDATE t1 SET x=x+4 WHERE x=1; |
| 327 | # SAVEPOINT one; |
| 328 | # UPDATE t1 SET x=x+4 WHERE x=2; |
| 329 | # SAVEPOINT three; |
| 330 | # UPDATE t1 SET x=x+4 WHERE x=3; |
| 331 | # SAVEPOINT four; |
| 332 | # UPDATE t1 SET x=x+4 WHERE x=4; |
| 333 | # RELEASE three; |
| 334 | # COMMIT; |
| 335 | # SELECT DISTINCT x FROM t1; |
| 336 | # } |
| 337 | # } -test { |
| 338 | # faultsim_test_result {0 {5 6 7 8}} |
| 339 | # faultsim_integrity_check |
| 340 | # } |
dan | 346e426 | 2010-06-23 19:27:36 +0000 | [diff] [blame] | 341 | # |
dan | dca321a | 2010-06-24 10:50:17 +0000 | [diff] [blame] | 342 | |
| 343 | # This is designed to provoke a special case in the pager code: |
| 344 | # |
| 345 | # If an error (specifically, a FULL or IOERR error) occurs while writing a |
| 346 | # dirty page to the file-system in order to free up memory, the pager enters |
| 347 | # the "error state". An IO error causes SQLite to roll back the current |
| 348 | # transaction (exiting the error state). A FULL error, however, may only |
| 349 | # rollback the current statement. |
| 350 | # |
| 351 | # This block tests that nothing goes wrong if a FULL error occurs while |
| 352 | # writing a dirty page out to free memory from within a statement that has |
| 353 | # opened a statement transaction. |
| 354 | # |
dan | 346e426 | 2010-06-23 19:27:36 +0000 | [diff] [blame] | 355 | do_test pagerfault-7-pre1 { |
| 356 | faultsim_delete_and_reopen |
| 357 | execsql { |
| 358 | CREATE TABLE t2(a INTEGER PRIMARY KEY, b); |
| 359 | BEGIN; |
| 360 | INSERT INTO t2 VALUES(NULL, randomblob(1500)); |
| 361 | INSERT INTO t2 VALUES(NULL, randomblob(1500)); |
| 362 | INSERT INTO t2 SELECT NULL, randomblob(1500) FROM t2; -- 4 |
| 363 | INSERT INTO t2 SELECT NULL, randomblob(1500) FROM t2; -- 8 |
| 364 | INSERT INTO t2 SELECT NULL, randomblob(1500) FROM t2; -- 16 |
| 365 | INSERT INTO t2 SELECT NULL, randomblob(1500) FROM t2; -- 32 |
| 366 | INSERT INTO t2 SELECT NULL, randomblob(1500) FROM t2; -- 64 |
| 367 | COMMIT; |
| 368 | CREATE TABLE t1(a PRIMARY KEY, b); |
| 369 | INSERT INTO t1 SELECT * FROM t2; |
| 370 | DROP TABLE t2; |
| 371 | } |
| 372 | faultsim_save_and_close |
| 373 | } {} |
dan | ec6ffc1 | 2010-06-24 19:16:06 +0000 | [diff] [blame] | 374 | do_faultsim_test pagerfault-7 -prep { |
dan | 346e426 | 2010-06-23 19:27:36 +0000 | [diff] [blame] | 375 | faultsim_restore_and_reopen |
| 376 | execsql { |
| 377 | PRAGMA cache_size = 10; |
| 378 | BEGIN; |
| 379 | UPDATE t1 SET b = randomblob(1500); |
| 380 | } |
| 381 | } -body { |
| 382 | execsql { UPDATE t1 SET a = 65, b = randomblob(1500) WHERE (a+1)>200 } |
| 383 | execsql COMMIT |
| 384 | } -test { |
| 385 | faultsim_test_result {0 {}} |
| 386 | faultsim_integrity_check |
| 387 | } |
dan | 146ed78 | 2010-06-19 17:26:37 +0000 | [diff] [blame] | 388 | |
dan | dca321a | 2010-06-24 10:50:17 +0000 | [diff] [blame] | 389 | do_test pagerfault-8-pre1 { |
| 390 | faultsim_delete_and_reopen |
| 391 | execsql { |
| 392 | PRAGMA auto_vacuum = 1; |
| 393 | CREATE TABLE t1(a INTEGER PRIMARY KEY, b); |
| 394 | BEGIN; |
| 395 | INSERT INTO t1 VALUES(NULL, randomblob(1500)); |
| 396 | INSERT INTO t1 VALUES(NULL, randomblob(1500)); |
| 397 | INSERT INTO t1 SELECT NULL, randomblob(1500) FROM t1; -- 4 |
| 398 | INSERT INTO t1 SELECT NULL, randomblob(1500) FROM t1; -- 8 |
| 399 | INSERT INTO t1 SELECT NULL, randomblob(1500) FROM t1; -- 16 |
| 400 | INSERT INTO t1 SELECT NULL, randomblob(1500) FROM t1; -- 32 |
| 401 | INSERT INTO t1 SELECT NULL, randomblob(1500) FROM t1; -- 64 |
| 402 | COMMIT; |
| 403 | } |
| 404 | faultsim_save_and_close |
| 405 | set filesize [file size test.db] |
| 406 | set {} {} |
| 407 | } {} |
| 408 | do_test pagerfault-8-pre2 { |
| 409 | faultsim_restore_and_reopen |
| 410 | execsql { DELETE FROM t1 WHERE a>32 } |
| 411 | expr {[file size test.db] < $filesize} |
| 412 | } {1} |
dan | dca321a | 2010-06-24 10:50:17 +0000 | [diff] [blame] | 413 | do_faultsim_test pagerfault-8 -prep { |
| 414 | faultsim_restore_and_reopen |
| 415 | execsql { |
| 416 | BEGIN; |
| 417 | DELETE FROM t1 WHERE a>32; |
| 418 | } |
| 419 | } -body { |
| 420 | execsql COMMIT |
| 421 | } -test { |
| 422 | faultsim_test_result {0 {}} |
| 423 | faultsim_integrity_check |
| 424 | } |
| 425 | |
dan | 273f3f0 | 2010-06-26 15:42:33 +0000 | [diff] [blame] | 426 | #------------------------------------------------------------------------- |
| 427 | # This test case is specially designed so that during a savepoint |
| 428 | # rollback, a new cache entry must be allocated (see comments surrounding |
| 429 | # the call to sqlite3PagerAcquire() from within pager_playback_one_page() |
| 430 | # for details). Test the effects of injecting an OOM at this point. |
| 431 | # |
dan | 0a6052e | 2010-06-24 13:24:26 +0000 | [diff] [blame] | 432 | do_test pagerfault-9-pre1 { |
| 433 | faultsim_delete_and_reopen |
| 434 | execsql { |
| 435 | PRAGMA auto_vacuum = incremental; |
| 436 | CREATE TABLE t1(x); |
| 437 | CREATE TABLE t2(y); |
| 438 | CREATE TABLE t3(z); |
| 439 | |
| 440 | INSERT INTO t1 VALUES(randomblob(900)); |
| 441 | INSERT INTO t1 VALUES(randomblob(900)); |
| 442 | DELETE FROM t1; |
| 443 | } |
| 444 | faultsim_save_and_close |
| 445 | } {} |
dan | 273f3f0 | 2010-06-26 15:42:33 +0000 | [diff] [blame] | 446 | do_faultsim_test pagerfault-9.1 -prep { |
dan | 0a6052e | 2010-06-24 13:24:26 +0000 | [diff] [blame] | 447 | faultsim_restore_and_reopen |
| 448 | execsql { |
| 449 | BEGIN; |
| 450 | INSERT INTO t1 VALUES(randomblob(900)); |
| 451 | INSERT INTO t1 VALUES(randomblob(900)); |
| 452 | DROP TABLE t3; |
| 453 | DROP TABLE t2; |
| 454 | SAVEPOINT abc; |
| 455 | PRAGMA incremental_vacuum; |
| 456 | } |
| 457 | } -body { |
| 458 | execsql { |
| 459 | ROLLBACK TO abc; |
| 460 | COMMIT; |
| 461 | PRAGMA freelist_count |
| 462 | } |
| 463 | } -test { |
| 464 | faultsim_test_result {0 2} |
| 465 | faultsim_integrity_check |
| 466 | |
| 467 | set sl [db one { SELECT COALESCE(sum(length(x)), 'null') FROM t1 }] |
| 468 | if {$sl!="null" && $sl!=1800} { |
| 469 | error "Content looks no good... ($sl)" |
| 470 | } |
| 471 | } |
| 472 | |
dan | 273f3f0 | 2010-06-26 15:42:33 +0000 | [diff] [blame] | 473 | #------------------------------------------------------------------------- |
| 474 | # Test fault injection with a temporary database file. |
| 475 | # |
| 476 | do_faultsim_test pagerfault-10 -prep { |
| 477 | sqlite3 db "" |
| 478 | db func a_string a_string; |
| 479 | execsql { |
| 480 | PRAGMA cache_size = 10; |
| 481 | BEGIN; |
| 482 | CREATE TABLE xx(a, b, UNIQUE(a, b)); |
| 483 | INSERT INTO xx VALUES(a_string(200), a_string(200)); |
| 484 | INSERT INTO xx SELECT a_string(200), a_string(200) FROM xx; |
| 485 | INSERT INTO xx SELECT a_string(200), a_string(200) FROM xx; |
| 486 | INSERT INTO xx SELECT a_string(200), a_string(200) FROM xx; |
| 487 | INSERT INTO xx SELECT a_string(200), a_string(200) FROM xx; |
| 488 | COMMIT; |
| 489 | } |
| 490 | } -body { |
| 491 | execsql { UPDATE xx SET a = a_string(300) } |
| 492 | } -test { |
| 493 | faultsim_test_result {0 {}} |
| 494 | faultsim_integrity_check |
| 495 | faultsim_integrity_check |
| 496 | } |
| 497 | |
dan | 273f3f0 | 2010-06-26 15:42:33 +0000 | [diff] [blame] | 498 | #------------------------------------------------------------------------- |
| 499 | # Test fault injection with transaction savepoints (savepoints created |
| 500 | # when a SAVEPOINT command is executed outside of any other savepoint |
| 501 | # or transaction context). |
| 502 | # |
| 503 | do_test pagerfault-9-pre1 { |
| 504 | faultsim_delete_and_reopen |
| 505 | db func a_string a_string; |
| 506 | execsql { |
| 507 | PRAGMA auto_vacuum = on; |
| 508 | CREATE TABLE t1(x UNIQUE); |
| 509 | CREATE TABLE t2(y UNIQUE); |
| 510 | CREATE TABLE t3(z UNIQUE); |
| 511 | BEGIN; |
| 512 | INSERT INTO t1 VALUES(a_string(202)); |
| 513 | INSERT INTO t2 VALUES(a_string(203)); |
| 514 | INSERT INTO t3 VALUES(a_string(204)); |
| 515 | INSERT INTO t1 SELECT a_string(202) FROM t1; |
| 516 | INSERT INTO t1 SELECT a_string(203) FROM t1; |
| 517 | INSERT INTO t1 SELECT a_string(204) FROM t1; |
| 518 | INSERT INTO t1 SELECT a_string(205) FROM t1; |
| 519 | INSERT INTO t2 SELECT a_string(length(x)) FROM t1; |
| 520 | INSERT INTO t3 SELECT a_string(length(x)) FROM t1; |
| 521 | COMMIT; |
| 522 | } |
| 523 | faultsim_save_and_close |
| 524 | } {} |
| 525 | do_faultsim_test pagerfault-11 -prep { |
| 526 | faultsim_restore_and_reopen |
| 527 | execsql { PRAGMA cache_size = 10 } |
| 528 | } -body { |
| 529 | execsql { |
| 530 | SAVEPOINT trans; |
| 531 | UPDATE t2 SET y = y||'2'; |
| 532 | INSERT INTO t3 SELECT * FROM t2; |
| 533 | DELETE FROM t1; |
| 534 | ROLLBACK TO trans; |
| 535 | UPDATE t1 SET x = x||'3'; |
| 536 | INSERT INTO t2 SELECT * FROM t1; |
| 537 | DELETE FROM t3; |
| 538 | RELEASE trans; |
| 539 | } |
| 540 | } -test { |
| 541 | faultsim_test_result {0 {}} |
| 542 | faultsim_integrity_check |
| 543 | } |
| 544 | |
dan | d353331 | 2010-06-28 19:04:02 +0000 | [diff] [blame^] | 545 | } |
| 546 | |
| 547 | do_test pagerfault-12-pre1 { |
| 548 | testvfs ss_layer -default 1 |
| 549 | ss_layer sectorsize 4096 |
| 550 | faultsim_delete_and_reopen |
| 551 | db func a_string a_string; |
| 552 | |
| 553 | execsql { |
| 554 | PRAGMA page_size = 1024; |
| 555 | PRAGMA journal_mode = PERSIST; |
| 556 | PRAGMA cache_size = 10; |
| 557 | BEGIN; |
| 558 | CREATE TABLE t1(x, y UNIQUE); |
| 559 | INSERT INTO t1 VALUES(a_string(333), a_string(444)); |
| 560 | INSERT INTO t1 SELECT a_string(333+rowid), a_string(444+rowid) FROM t1; |
| 561 | INSERT INTO t1 SELECT a_string(333+rowid), a_string(444+rowid) FROM t1; |
| 562 | INSERT INTO t1 SELECT a_string(333+rowid), a_string(444+rowid) FROM t1; |
| 563 | INSERT INTO t1 SELECT a_string(333+rowid), a_string(444+rowid) FROM t1; |
| 564 | INSERT INTO t1 SELECT a_string(44), a_string(55) FROM t1 LIMIT 13; |
| 565 | COMMIT; |
| 566 | } |
| 567 | faultsim_save_and_close |
| 568 | } {} |
| 569 | do_faultsim_test pagerfault-12 -prep { |
| 570 | faultsim_restore_and_reopen |
| 571 | execsql { PRAGMA cache_size = 10 } |
| 572 | db func a_string a_string; |
| 573 | } -body { |
| 574 | execsql { |
| 575 | UPDATE t1 SET x = a_string(length(x)), y = a_string(length(y)); |
| 576 | } |
| 577 | } -test { |
| 578 | faultsim_test_result {0 {}} |
| 579 | faultsim_integrity_check |
| 580 | } |
| 581 | |
| 582 | |
dan | 273f3f0 | 2010-06-26 15:42:33 +0000 | [diff] [blame] | 583 | |
dan | b0ac3e3 | 2010-06-16 10:55:42 +0000 | [diff] [blame] | 584 | finish_test |