blob: 4eae116a72e12e056adeaf0caf9e2aeef27c16b2 [file] [log] [blame]
dan67330a12016-04-11 18:07:47 +00001# 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
dan6572c162016-04-23 14:55:28 +000021# sqlite3_memdebug_vfs_oom_test 0
dan67330a12016-04-11 18:07:47 +000022
dan6572c162016-04-23 14:55:28 +000023do_faultsim_test 1 -faults * -prep {
dan67330a12016-04-11 18:07:47 +000024 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
dan6572c162016-04-23 14:55:28 +000045do_faultsim_test 2 -faults * -prep {
dan67330a12016-04-11 18:07:47 +000046 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);
dan6572c162016-04-23 14:55:28 +000052 WITH x(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<100)
dan67330a12016-04-11 18:07:47 +000053 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
dan6572c162016-04-23 14:55:28 +000062catch { db close }
63do_faultsim_test 2.1 -faults * -prep {
64 if {[info commands db]==""} {
65 sqlite3 db ""
66 execsql {
67 PRAGMA page_size = 1024;
68 PRAGMA cache_size = 10;
69 CREATE TABLE t1(a, b);
70 CREATE INDEX i1 ON t1(b, a);
71 WITH x(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<100)
72 INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM x;
73 }
74 }
75} -body {
76 execsql { UPDATE t1 SET a = randomblob(99) }
77} -test {
78 faultsim_test_result {0 {}}
79 faultsim_integrity_check db
80}
81
82do_faultsim_test 3 -faults * -prep {
dan67330a12016-04-11 18:07:47 +000083 sqlite3 db ""
84 db eval {
85 PRAGMA page_size = 1024;
86 PRAGMA cache_size = 10;
87 CREATE TABLE t1(a, b);
88 CREATE INDEX i1 ON t1(b, a);
89 WITH x(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<50)
90 INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM x;
91 }
92} -body {
93 execsql {
94 BEGIN;
95 UPDATE t1 SET a = randomblob(99);
96 SAVEPOINT abc;
97 UPDATE t1 SET a = randomblob(98) WHERE (rowid%10)==0;
98 ROLLBACK TO abc;
99 UPDATE t1 SET a = randomblob(97) WHERE (rowid%5)==0;
100 ROLLBACK TO abc;
101 COMMIT;
102 }
103} -test {
104 faultsim_test_result {0 {}}
105 faultsim_integrity_check db
106}
107
108do_faultsim_test 4 -faults * -prep {
109 sqlite3 db ""
110 db eval {
111 PRAGMA page_size = 1024;
112 PRAGMA cache_size = 10;
113 CREATE TABLE t1(a, b);
114 CREATE INDEX i1 ON t1(b, a);
115 WITH x(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<50)
116 INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM x;
117 }
118} -body {
119 execsql {
120 BEGIN;
121 UPDATE t1 SET a = randomblob(99);
122 SAVEPOINT abc;
123 UPDATE t1 SET a = randomblob(98) WHERE (rowid%10)==0;
124 ROLLBACK TO abc;
125 UPDATE t1 SET a = randomblob(97) WHERE (rowid%5)==0;
126 ROLLBACK TO abc;
127 COMMIT;
128 }
129} -test {
130 faultsim_test_result {0 {}}
131}
132
133sqlite3_memdebug_vfs_oom_test 1
134finish_test