xref: /sqlite-3.40.0/test/ioerr6.test (revision 5822d6fe)
1985cd59cSdan# 2012 December 18
2985cd59cSdan#
3985cd59cSdan# The author disclaims copyright to this source code.  In place of
4985cd59cSdan# a legal notice, here is a blessing:
5985cd59cSdan#
6985cd59cSdan#    May you do good and not evil.
7985cd59cSdan#    May you find forgiveness for yourself and forgive others.
8985cd59cSdan#    May you share freely, never taking more than you give.
9985cd59cSdan#
10985cd59cSdan#***********************************************************************
11985cd59cSdan#
12985cd59cSdan
13985cd59cSdanset testdir [file dirname $argv0]
14985cd59cSdansource $testdir/tester.tcl
15985cd59cSdansource $testdir/malloc_common.tcl
16985cd59cSdanset ::testprefix ioerr6
17985cd59cSdan
18985cd59cSdanifcapable !atomicwrite {
19985cd59cSdan  puts "skipping tests - not compiled with SQLITE_ENABLE_ATOMIC_WRITE..."
20985cd59cSdan  finish_test
21985cd59cSdan  return
22985cd59cSdan}
23*42c4bd02Sdan
24*42c4bd02Sdanif {[permutation]=="inmemory_journal"} {
25*42c4bd02Sdan  # These tests will not work with in-memory journals (as persistent VFS
26*42c4bd02Sdan  # errors commencing after a transaction has started to write to the db
27*42c4bd02Sdan  # cannot be recovered from).
28*42c4bd02Sdan  finish_test
29*42c4bd02Sdan  return
30*42c4bd02Sdan}
31*42c4bd02Sdan
32985cd59cSdanfaultsim_save_and_close
33985cd59cSdan
34985cd59cSdando_test 1.1 {
35985cd59cSdan  testvfs shmfault -default true
36985cd59cSdan  shmfault devchar atomic
37985cd59cSdan  sqlite3 db test.db
38985cd59cSdan  execsql {
39985cd59cSdan    CREATE TABLE t1(a, b);
40985cd59cSdan    CREATE INDEX i1 ON t1(a, b);
41985cd59cSdan    INSERT INTO t1 VALUES(1, 2);
42985cd59cSdan    INSERT INTO t1 VALUES(2, 4);
43985cd59cSdan    INSERT INTO t1 VALUES(3, 6);
44985cd59cSdan    INSERT INTO t1 VALUES(4, 8);
45985cd59cSdan  }
46985cd59cSdan
47985cd59cSdan  # Cause the first call to xWrite() to fail with SQLITE_FULL.
48985cd59cSdan  shmfault full 2 1
49985cd59cSdan  catchsql { INSERT INTO t1 VALUES(5, 10) }
50985cd59cSdan} {1 {database or disk is full}}
51985cd59cSdan
52985cd59cSdando_test 1.2 {
53985cd59cSdan  execsql { PRAGMA integrity_check }
54985cd59cSdan} {ok}
55985cd59cSdan
56985cd59cSdandb close
57985cd59cSdanshmfault delete
58985cd59cSdan
59985cd59cSdando_faultsim_test 2 -faults full* -prep {
60985cd59cSdan  shmfault devchar atomic
61985cd59cSdan  faultsim_restore
62985cd59cSdan  sqlite3 db test.db
63985cd59cSdan} -body {
64985cd59cSdan  db eval {
65985cd59cSdan    CREATE TABLE t1(x PRIMARY KEY);
66985cd59cSdan    INSERT INTO t1 VALUES('abc');
67985cd59cSdan  }
68985cd59cSdan} -test {
69985cd59cSdan  set res [db one { PRAGMA integrity_check }]
70985cd59cSdan  if {$res != "ok"} {
71985cd59cSdan    error "integrity check: $res"
72985cd59cSdan  }
73985cd59cSdan}
74985cd59cSdan
75*42c4bd02Sdando_faultsim_test 3 -faults full* -prep {
76985cd59cSdan  shmfault devchar atomic
77985cd59cSdan  faultsim_restore
78985cd59cSdan  sqlite3 db test.db
79985cd59cSdan} -body {
80985cd59cSdan  db eval {
81985cd59cSdan    CREATE TABLE t1(x);
82985cd59cSdan    CREATE TABLE t2(x);
83985cd59cSdan  }
84985cd59cSdan} -test {
85985cd59cSdan  db eval { CREATE TABLE t3(x) }
86985cd59cSdan  if {[db one { PRAGMA integrity_check }] != "ok"} {
87985cd59cSdan    error "integrity check failed"
88985cd59cSdan  }
89985cd59cSdan}
90985cd59cSdan
91985cd59cSdanfinish_test
92