blob: d1847b2877b71e439be717d2987b3e332795b3b9 [file] [log] [blame]
dan985cd592012-12-18 11:59:39 +00001# 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}
dan42c4bd02013-03-06 11:44:57 +000023
24if {[permutation]=="inmemory_journal"} {
25 # These tests will not work with in-memory journals (as persistent VFS
26 # errors commencing after a transaction has started to write to the db
27 # cannot be recovered from).
28 finish_test
29 return
30}
31
dan985cd592012-12-18 11:59:39 +000032faultsim_save_and_close
33
34do_test 1.1 {
35 testvfs shmfault -default true
36 shmfault devchar atomic
37 sqlite3 db test.db
38 execsql {
39 CREATE TABLE t1(a, b);
40 CREATE INDEX i1 ON t1(a, b);
41 INSERT INTO t1 VALUES(1, 2);
42 INSERT INTO t1 VALUES(2, 4);
43 INSERT INTO t1 VALUES(3, 6);
44 INSERT INTO t1 VALUES(4, 8);
45 }
46
47 # Cause the first call to xWrite() to fail with SQLITE_FULL.
48 shmfault full 2 1
49 catchsql { INSERT INTO t1 VALUES(5, 10) }
50} {1 {database or disk is full}}
51
52do_test 1.2 {
53 execsql { PRAGMA integrity_check }
54} {ok}
55
56db close
57shmfault delete
58
59do_faultsim_test 2 -faults full* -prep {
60 shmfault devchar atomic
61 faultsim_restore
62 sqlite3 db test.db
63} -body {
64 db eval {
65 CREATE TABLE t1(x PRIMARY KEY);
66 INSERT INTO t1 VALUES('abc');
67 }
68} -test {
69 set res [db one { PRAGMA integrity_check }]
70 if {$res != "ok"} {
71 error "integrity check: $res"
72 }
73}
74
dan42c4bd02013-03-06 11:44:57 +000075do_faultsim_test 3 -faults full* -prep {
dan985cd592012-12-18 11:59:39 +000076 shmfault devchar atomic
77 faultsim_restore
78 sqlite3 db test.db
79} -body {
80 db eval {
81 CREATE TABLE t1(x);
82 CREATE TABLE t2(x);
83 }
84} -test {
85 db eval { CREATE TABLE t3(x) }
86 if {[db one { PRAGMA integrity_check }] != "ok"} {
87 error "integrity check failed"
88 }
89}
90
91finish_test