1# 2016 April 11 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# This file contains tests for fault-injection when SQLite is used with 13# a temp file database. 14# 15 16set testdir [file dirname $argv0] 17source $testdir/tester.tcl 18source $testdir/malloc_common.tcl 19set testprefix tempfault 20 21sqlite3_memdebug_vfs_oom_test 0 22 23do_faultsim_test 1 -faults oom* -prep { 24 sqlite3 db "" 25 db eval { 26 PRAGMA page_size = 1024; 27 CREATE TABLE t1(a, b); 28 INSERT INTO t1 VALUES(1, 2); 29 INSERT INTO t1 VALUES(3, 4); 30 } 31} -body { 32 execsql { INSERT INTO t1 VALUES(5, 6) } 33} -test { 34 faultsim_test_result {0 {}} 35 set rc [catch { execsql { SELECT * FROM t1 } } msg] 36 if {$rc==0 && $msg != "1 2 3 4 5 6" && $msg != "1 2 3 4"} { 37 error "data mismatch 1: $msg" 38 } 39 if {$testrc==0 && $msg != "1 2 3 4 5 6"} { 40 error "data mismatch 2: $msg" 41 } 42 faultsim_integrity_check 43} 44 45do_faultsim_test 2 -faults oom* -prep { 46 sqlite3 db "" 47 db eval { 48 PRAGMA page_size = 1024; 49 PRAGMA cache_size = 10; 50 CREATE TABLE t1(a, b); 51 CREATE INDEX i1 ON t1(b, a); 52 WITH x(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<50) 53 INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM x; 54 } 55} -body { 56 execsql { UPDATE t1 SET a = randomblob(99) } 57} -test { 58 faultsim_test_result {0 {}} 59 faultsim_integrity_check db 60} 61 62do_faultsim_test 3 -faults oom* -prep { 63 sqlite3 db "" 64 db eval { 65 PRAGMA page_size = 1024; 66 PRAGMA cache_size = 10; 67 CREATE TABLE t1(a, b); 68 CREATE INDEX i1 ON t1(b, a); 69 WITH x(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<50) 70 INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM x; 71 } 72} -body { 73 execsql { 74 BEGIN; 75 UPDATE t1 SET a = randomblob(99); 76 SAVEPOINT abc; 77 UPDATE t1 SET a = randomblob(98) WHERE (rowid%10)==0; 78 ROLLBACK TO abc; 79 UPDATE t1 SET a = randomblob(97) WHERE (rowid%5)==0; 80 ROLLBACK TO abc; 81 COMMIT; 82 } 83} -test { 84 faultsim_test_result {0 {}} 85 faultsim_integrity_check db 86} 87 88do_faultsim_test 4 -faults * -prep { 89 sqlite3 db "" 90 db eval { 91 PRAGMA page_size = 1024; 92 PRAGMA cache_size = 10; 93 CREATE TABLE t1(a, b); 94 CREATE INDEX i1 ON t1(b, a); 95 WITH x(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<50) 96 INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM x; 97 } 98} -body { 99 execsql { 100 BEGIN; 101 UPDATE t1 SET a = randomblob(99); 102 SAVEPOINT abc; 103 UPDATE t1 SET a = randomblob(98) WHERE (rowid%10)==0; 104 ROLLBACK TO abc; 105 UPDATE t1 SET a = randomblob(97) WHERE (rowid%5)==0; 106 ROLLBACK TO abc; 107 COMMIT; 108 } 109} -test { 110 faultsim_test_result {0 {}} 111} 112 113sqlite3_memdebug_vfs_oom_test 1 114finish_test 115