1# 2012 December 18 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 13set testdir [file dirname $argv0] 14source $testdir/tester.tcl 15source $testdir/malloc_common.tcl 16set ::testprefix ioerr6 17 18ifcapable !atomicwrite { 19 puts "skipping tests - not compiled with SQLITE_ENABLE_ATOMIC_WRITE..." 20 finish_test 21 return 22} 23faultsim_save_and_close 24 25do_test 1.1 { 26 testvfs shmfault -default true 27 shmfault devchar atomic 28 sqlite3 db test.db 29 execsql { 30 CREATE TABLE t1(a, b); 31 CREATE INDEX i1 ON t1(a, b); 32 INSERT INTO t1 VALUES(1, 2); 33 INSERT INTO t1 VALUES(2, 4); 34 INSERT INTO t1 VALUES(3, 6); 35 INSERT INTO t1 VALUES(4, 8); 36 } 37 38 # Cause the first call to xWrite() to fail with SQLITE_FULL. 39 shmfault full 2 1 40 catchsql { INSERT INTO t1 VALUES(5, 10) } 41} {1 {database or disk is full}} 42 43do_test 1.2 { 44 execsql { PRAGMA integrity_check } 45} {ok} 46 47db close 48shmfault delete 49 50do_faultsim_test 2 -faults full* -prep { 51 shmfault devchar atomic 52 faultsim_restore 53 sqlite3 db test.db 54} -body { 55 db eval { 56 CREATE TABLE t1(x PRIMARY KEY); 57 INSERT INTO t1 VALUES('abc'); 58 } 59} -test { 60 set res [db one { PRAGMA integrity_check }] 61 if {$res != "ok"} { 62 error "integrity check: $res" 63 } 64} 65 66do_faultsim_test 2 -faults full* -prep { 67 shmfault devchar atomic 68 faultsim_restore 69 sqlite3 db test.db 70} -body { 71 db eval { 72 CREATE TABLE t1(x); 73 CREATE TABLE t2(x); 74 } 75} -test { 76 db eval { CREATE TABLE t3(x) } 77 if {[db one { PRAGMA integrity_check }] != "ok"} { 78 error "integrity check failed" 79 } 80} 81 82finish_test 83 84