blob: c73bc422561081df5cfaab7ab82f458e5fdf957c [file] [log] [blame]
danb0ac3e32010-06-16 10:55:42 +00001# 2010 June 15
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/lock_common.tcl
16source $testdir/malloc_common.tcl
17
danb3f43512010-07-03 16:37:45 +000018if {[permutation] == "inmemory_journal"} {
19 finish_test
20 return
21}
22
danb0ac3e32010-06-16 10:55:42 +000023set a_string_counter 1
24proc a_string {n} {
25 global a_string_counter
26 incr a_string_counter
27 string range [string repeat "${a_string_counter}." $n] 1 $n
28}
29db func a_string a_string
30
31#-------------------------------------------------------------------------
32# Test fault-injection while rolling back a hot-journal file.
33#
34do_test pagerfault-1-pre1 {
35 execsql {
36 PRAGMA journal_mode = DELETE;
37 PRAGMA cache_size = 10;
38 CREATE TABLE t1(a UNIQUE, b UNIQUE);
39 INSERT INTO t1 VALUES(a_string(200), a_string(300));
40 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
41 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
42 BEGIN;
43 INSERT INTO t1 SELECT a_string(201), a_string(301) FROM t1;
44 INSERT INTO t1 SELECT a_string(202), a_string(302) FROM t1;
45 INSERT INTO t1 SELECT a_string(203), a_string(303) FROM t1;
46 INSERT INTO t1 SELECT a_string(204), a_string(304) FROM t1;
47 }
48 faultsim_save_and_close
49} {}
50do_faultsim_test pagerfault-1 -prep {
51 faultsim_restore_and_reopen
52} -body {
53 execsql { SELECT count(*) FROM t1 }
54} -test {
dan22b328b2010-08-11 18:56:45 +000055 faultsim_test_result {0 4}
danb0ac3e32010-06-16 10:55:42 +000056 faultsim_integrity_check
57 if {[db one { SELECT count(*) FROM t1 }] != 4} {
58 error "Database content appears incorrect"
59 }
60}
61
62#-------------------------------------------------------------------------
dande4996e2010-06-19 11:30:41 +000063# Test fault-injection while rolling back a hot-journal file with a
64# page-size different from the current value stored on page 1 of the
65# database file.
66#
67do_test pagerfault-2-pre1 {
68 testvfs tv -default 1
69 tv filter xSync
70 tv script xSyncCb
71 proc xSyncCb {filename args} {
72 if {[string match *journal filename]==0} faultsim_save
73 }
74 faultsim_delete_and_reopen
75 execsql {
76 PRAGMA page_size = 4096;
77 BEGIN;
78 CREATE TABLE abc(a, b, c);
79 INSERT INTO abc VALUES('o', 't', 't');
80 INSERT INTO abc VALUES('f', 'f', 's');
81 INSERT INTO abc SELECT * FROM abc; -- 4
82 INSERT INTO abc SELECT * FROM abc; -- 8
83 INSERT INTO abc SELECT * FROM abc; -- 16
84 INSERT INTO abc SELECT * FROM abc; -- 32
85 INSERT INTO abc SELECT * FROM abc; -- 64
86 INSERT INTO abc SELECT * FROM abc; -- 128
87 INSERT INTO abc SELECT * FROM abc; -- 256
88 COMMIT;
89 PRAGMA page_size = 1024;
90 VACUUM;
91 }
92 db close
93 tv delete
94} {}
95do_faultsim_test pagerfault-2 -prep {
96 faultsim_restore_and_reopen
97} -body {
98 execsql { SELECT * FROM abc }
99} -test {
100 set answer [split [string repeat "ottffs" 128] ""]
101 faultsim_test_result [list 0 $answer]
102 faultsim_integrity_check
103 set res [db eval { SELECT * FROM abc }]
104 if {$res != $answer} { error "Database content appears incorrect ($res)" }
danec6ffc12010-06-24 19:16:06 +0000105}
dande4996e2010-06-19 11:30:41 +0000106
107#-------------------------------------------------------------------------
danb0ac3e32010-06-16 10:55:42 +0000108# Test fault-injection while rolling back hot-journals that were created
109# as part of a multi-file transaction.
110#
dande4996e2010-06-19 11:30:41 +0000111do_test pagerfault-3-pre1 {
danb0ac3e32010-06-16 10:55:42 +0000112 testvfs tstvfs -default 1
113 tstvfs filter xDelete
114 tstvfs script xDeleteCallback
115
116 proc xDeleteCallback {method file args} {
117 set file [file tail $file]
118 if { [string match *mj* $file] } { faultsim_save }
119 }
120
121 faultsim_delete_and_reopen
122 db func a_string a_string
123
124 execsql {
125 ATTACH 'test.db2' AS aux;
126 PRAGMA journal_mode = DELETE;
127 PRAGMA main.cache_size = 10;
128 PRAGMA aux.cache_size = 10;
129
130 CREATE TABLE t1(a UNIQUE, b UNIQUE);
131 CREATE TABLE aux.t2(a UNIQUE, b UNIQUE);
132 INSERT INTO t1 VALUES(a_string(200), a_string(300));
133 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
134 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
135 INSERT INTO t2 SELECT * FROM t1;
136
137 BEGIN;
138 INSERT INTO t1 SELECT a_string(201), a_string(301) FROM t1;
139 INSERT INTO t1 SELECT a_string(202), a_string(302) FROM t1;
140 INSERT INTO t1 SELECT a_string(203), a_string(303) FROM t1;
141 INSERT INTO t1 SELECT a_string(204), a_string(304) FROM t1;
142 REPLACE INTO t2 SELECT * FROM t1;
143 COMMIT;
144 }
145
146 db close
147 tstvfs delete
148} {}
danec6ffc12010-06-24 19:16:06 +0000149do_faultsim_test pagerfault-3 -prep {
danb0ac3e32010-06-16 10:55:42 +0000150 faultsim_restore_and_reopen
151} -body {
152 execsql {
153 ATTACH 'test.db2' AS aux;
154 SELECT count(*) FROM t2;
155 SELECT count(*) FROM t1;
156 }
157} -test {
158 faultsim_test_result {0 {4 4}} {1 {unable to open database: test.db2}}
159 faultsim_integrity_check
danb0ac3e32010-06-16 10:55:42 +0000160 catchsql { ATTACH 'test.db2' AS aux }
161 if {[db one { SELECT count(*) FROM t1 }] != 4
162 || [db one { SELECT count(*) FROM t2 }] != 4
163 } {
164 error "Database content appears incorrect"
165 }
166}
167
dande4996e2010-06-19 11:30:41 +0000168#-------------------------------------------------------------------------
169# Test fault-injection as part of a vanilla, no-transaction, INSERT
170# statement.
171#
172do_faultsim_test pagerfault-4 -prep {
173 faultsim_delete_and_reopen
174} -body {
175 execsql {
176 CREATE TABLE x(y);
177 INSERT INTO x VALUES('z');
178 SELECT * FROM x;
179 }
180} -test {
181 faultsim_test_result {0 z}
182 faultsim_integrity_check
183}
184
185#-------------------------------------------------------------------------
186# Test fault-injection as part of a commit when using journal_mode=PERSIST.
dan146ed782010-06-19 17:26:37 +0000187# Three different cases:
188#
189# pagerfault-5.1: With no journal_size_limit configured.
190# pagerfault-5.2: With a journal_size_limit configured.
191# pagerfault-5.4: Multi-file transaction. One connection has a
192# journal_size_limit of 0, the other has no limit.
dande4996e2010-06-19 11:30:41 +0000193#
194do_test pagerfault-5-pre1 {
195 faultsim_delete_and_reopen
196 db func a_string a_string
197 execsql {
198 CREATE TABLE t1(a UNIQUE, b UNIQUE);
199 INSERT INTO t1 VALUES(a_string(200), a_string(300));
200 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
201 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
202 }
203 faultsim_save_and_close
204} {}
205do_faultsim_test pagerfault-5.1 -prep {
206 faultsim_restore_and_reopen
207 db func a_string a_string
208 execsql { PRAGMA journal_mode = PERSIST }
209} -body {
210 execsql { INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1 }
211} -test {
212 faultsim_test_result {0 {}}
213 faultsim_integrity_check
214}
215do_faultsim_test pagerfault-5.2 -prep {
216 faultsim_restore_and_reopen
217 db func a_string a_string
218 execsql {
219 PRAGMA journal_mode = PERSIST;
220 PRAGMA journal_size_limit = 2048;
221 }
222} -body {
223 execsql { INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1 }
224} -test {
225 faultsim_test_result {0 {}}
226 faultsim_integrity_check
227}
danec6ffc12010-06-24 19:16:06 +0000228do_faultsim_test pagerfault-5.3 -faults oom-transient -prep {
dande4996e2010-06-19 11:30:41 +0000229 faultsim_restore_and_reopen
230 db func a_string a_string
231 file delete -force test2.db test2.db-journal test2.db-wal
232 execsql {
233 PRAGMA journal_mode = PERSIST;
234 ATTACH 'test2.db' AS aux;
235 PRAGMA aux.journal_mode = PERSIST;
236 PRAGMA aux.journal_size_limit = 0;
237 }
238} -body {
239 execsql {
240 BEGIN;
241 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
242 CREATE TABLE aux.t2 AS SELECT * FROM t1;
243 COMMIT;
244 }
245} -test {
246 faultsim_test_result {0 {}}
danec6ffc12010-06-24 19:16:06 +0000247
danf43d7fc2010-07-03 10:00:00 +0000248 catchsql { COMMIT }
249 catchsql { ROLLBACK }
250
251 faultsim_integrity_check
danec6ffc12010-06-24 19:16:06 +0000252 set res ""
253 set rc [catch { set res [db one { PRAGMA aux.integrity_check }] }]
254 if {$rc!=0 || $res != "ok"} {error "integrity-check problem:$rc $res"}
dande4996e2010-06-19 11:30:41 +0000255}
256
dan153eda02010-06-21 07:45:47 +0000257#-------------------------------------------------------------------------
258# Test fault-injection as part of a commit when using
259# journal_mode=TRUNCATE.
260#
261do_test pagerfault-6-pre1 {
262 faultsim_delete_and_reopen
263 db func a_string a_string
264 execsql {
265 CREATE TABLE t1(a UNIQUE, b UNIQUE);
266 INSERT INTO t1 VALUES(a_string(200), a_string(300));
267 }
268 faultsim_save_and_close
269} {}
danf9b44192010-06-25 19:09:48 +0000270
dan153eda02010-06-21 07:45:47 +0000271do_faultsim_test pagerfault-6.1 -prep {
272 faultsim_restore_and_reopen
273 db func a_string a_string
274 execsql { PRAGMA journal_mode = TRUNCATE }
275} -body {
276 execsql { INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1 }
danf9b44192010-06-25 19:09:48 +0000277 execsql { INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1 }
278} -test {
279 faultsim_test_result {0 {}}
280 faultsim_integrity_check
281}
282
283# The unix vfs xAccess() method considers a file zero bytes in size to
284# "not exist". This proc overrides that behaviour so that a zero length
285# file is considered to exist.
286#
287proc xAccess {method filename op args} {
288 if {$op != "SQLITE_ACCESS_EXISTS"} { return "" }
289 return [file exists $filename]
290}
291do_faultsim_test pagerfault-6.2 -faults cantopen-* -prep {
292 shmfault filter xAccess
293 shmfault script xAccess
294
295 faultsim_restore_and_reopen
296 db func a_string a_string
297 execsql { PRAGMA journal_mode = TRUNCATE }
298} -body {
299 execsql { INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1 }
300 execsql { INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1 }
dan153eda02010-06-21 07:45:47 +0000301} -test {
302 faultsim_test_result {0 {}}
303 faultsim_integrity_check
304}
305
dan146ed782010-06-19 17:26:37 +0000306# The following was an attempt to get a bitvec malloc to fail. Didn't work.
307#
308# do_test pagerfault-6-pre1 {
309# faultsim_delete_and_reopen
310# execsql {
311# CREATE TABLE t1(x, y, UNIQUE(x, y));
312# INSERT INTO t1 VALUES(1, randomblob(1501));
313# INSERT INTO t1 VALUES(2, randomblob(1502));
314# INSERT INTO t1 VALUES(3, randomblob(1503));
315# INSERT INTO t1 VALUES(4, randomblob(1504));
316# INSERT INTO t1
317# SELECT x, randomblob(1500+oid+(SELECT max(oid) FROM t1)) FROM t1;
318# INSERT INTO t1
319# SELECT x, randomblob(1500+oid+(SELECT max(oid) FROM t1)) FROM t1;
320# INSERT INTO t1
321# SELECT x, randomblob(1500+oid+(SELECT max(oid) FROM t1)) FROM t1;
322# INSERT INTO t1
323# SELECT x, randomblob(1500+oid+(SELECT max(oid) FROM t1)) FROM t1;
324# }
325# faultsim_save_and_close
326# } {}
327# do_faultsim_test pagerfault-6 -prep {
328# faultsim_restore_and_reopen
329# } -body {
330# execsql {
331# BEGIN;
332# UPDATE t1 SET x=x+4 WHERE x=1;
333# SAVEPOINT one;
334# UPDATE t1 SET x=x+4 WHERE x=2;
335# SAVEPOINT three;
336# UPDATE t1 SET x=x+4 WHERE x=3;
337# SAVEPOINT four;
338# UPDATE t1 SET x=x+4 WHERE x=4;
339# RELEASE three;
340# COMMIT;
341# SELECT DISTINCT x FROM t1;
342# }
343# } -test {
344# faultsim_test_result {0 {5 6 7 8}}
345# faultsim_integrity_check
346# }
dan346e4262010-06-23 19:27:36 +0000347#
dandca321a2010-06-24 10:50:17 +0000348
349# This is designed to provoke a special case in the pager code:
350#
351# If an error (specifically, a FULL or IOERR error) occurs while writing a
352# dirty page to the file-system in order to free up memory, the pager enters
353# the "error state". An IO error causes SQLite to roll back the current
354# transaction (exiting the error state). A FULL error, however, may only
355# rollback the current statement.
356#
357# This block tests that nothing goes wrong if a FULL error occurs while
358# writing a dirty page out to free memory from within a statement that has
359# opened a statement transaction.
360#
dan346e4262010-06-23 19:27:36 +0000361do_test pagerfault-7-pre1 {
362 faultsim_delete_and_reopen
363 execsql {
364 CREATE TABLE t2(a INTEGER PRIMARY KEY, b);
365 BEGIN;
366 INSERT INTO t2 VALUES(NULL, randomblob(1500));
367 INSERT INTO t2 VALUES(NULL, randomblob(1500));
368 INSERT INTO t2 SELECT NULL, randomblob(1500) FROM t2; -- 4
369 INSERT INTO t2 SELECT NULL, randomblob(1500) FROM t2; -- 8
370 INSERT INTO t2 SELECT NULL, randomblob(1500) FROM t2; -- 16
371 INSERT INTO t2 SELECT NULL, randomblob(1500) FROM t2; -- 32
372 INSERT INTO t2 SELECT NULL, randomblob(1500) FROM t2; -- 64
373 COMMIT;
374 CREATE TABLE t1(a PRIMARY KEY, b);
375 INSERT INTO t1 SELECT * FROM t2;
376 DROP TABLE t2;
377 }
378 faultsim_save_and_close
379} {}
danec6ffc12010-06-24 19:16:06 +0000380do_faultsim_test pagerfault-7 -prep {
dan346e4262010-06-23 19:27:36 +0000381 faultsim_restore_and_reopen
382 execsql {
383 PRAGMA cache_size = 10;
384 BEGIN;
385 UPDATE t1 SET b = randomblob(1500);
386 }
387} -body {
388 execsql { UPDATE t1 SET a = 65, b = randomblob(1500) WHERE (a+1)>200 }
389 execsql COMMIT
390} -test {
391 faultsim_test_result {0 {}}
392 faultsim_integrity_check
393}
dan146ed782010-06-19 17:26:37 +0000394
dandca321a2010-06-24 10:50:17 +0000395do_test pagerfault-8-pre1 {
396 faultsim_delete_and_reopen
397 execsql {
398 PRAGMA auto_vacuum = 1;
399 CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
400 BEGIN;
401 INSERT INTO t1 VALUES(NULL, randomblob(1500));
402 INSERT INTO t1 VALUES(NULL, randomblob(1500));
403 INSERT INTO t1 SELECT NULL, randomblob(1500) FROM t1; -- 4
404 INSERT INTO t1 SELECT NULL, randomblob(1500) FROM t1; -- 8
405 INSERT INTO t1 SELECT NULL, randomblob(1500) FROM t1; -- 16
406 INSERT INTO t1 SELECT NULL, randomblob(1500) FROM t1; -- 32
407 INSERT INTO t1 SELECT NULL, randomblob(1500) FROM t1; -- 64
408 COMMIT;
409 }
410 faultsim_save_and_close
411 set filesize [file size test.db]
412 set {} {}
413} {}
414do_test pagerfault-8-pre2 {
415 faultsim_restore_and_reopen
416 execsql { DELETE FROM t1 WHERE a>32 }
417 expr {[file size test.db] < $filesize}
418} {1}
dandca321a2010-06-24 10:50:17 +0000419do_faultsim_test pagerfault-8 -prep {
420 faultsim_restore_and_reopen
421 execsql {
422 BEGIN;
423 DELETE FROM t1 WHERE a>32;
424 }
425} -body {
426 execsql COMMIT
427} -test {
428 faultsim_test_result {0 {}}
429 faultsim_integrity_check
430}
431
dan273f3f02010-06-26 15:42:33 +0000432#-------------------------------------------------------------------------
433# This test case is specially designed so that during a savepoint
434# rollback, a new cache entry must be allocated (see comments surrounding
435# the call to sqlite3PagerAcquire() from within pager_playback_one_page()
436# for details). Test the effects of injecting an OOM at this point.
437#
dan0a6052e2010-06-24 13:24:26 +0000438do_test pagerfault-9-pre1 {
439 faultsim_delete_and_reopen
440 execsql {
441 PRAGMA auto_vacuum = incremental;
442 CREATE TABLE t1(x);
443 CREATE TABLE t2(y);
444 CREATE TABLE t3(z);
445
446 INSERT INTO t1 VALUES(randomblob(900));
447 INSERT INTO t1 VALUES(randomblob(900));
448 DELETE FROM t1;
449 }
450 faultsim_save_and_close
451} {}
dan273f3f02010-06-26 15:42:33 +0000452do_faultsim_test pagerfault-9.1 -prep {
dan0a6052e2010-06-24 13:24:26 +0000453 faultsim_restore_and_reopen
454 execsql {
455 BEGIN;
456 INSERT INTO t1 VALUES(randomblob(900));
457 INSERT INTO t1 VALUES(randomblob(900));
458 DROP TABLE t3;
459 DROP TABLE t2;
460 SAVEPOINT abc;
461 PRAGMA incremental_vacuum;
462 }
463} -body {
464 execsql {
465 ROLLBACK TO abc;
466 COMMIT;
467 PRAGMA freelist_count
468 }
469} -test {
470 faultsim_test_result {0 2}
471 faultsim_integrity_check
472
473 set sl [db one { SELECT COALESCE(sum(length(x)), 'null') FROM t1 }]
474 if {$sl!="null" && $sl!=1800} {
475 error "Content looks no good... ($sl)"
476 }
477}
478
dan273f3f02010-06-26 15:42:33 +0000479#-------------------------------------------------------------------------
480# Test fault injection with a temporary database file.
481#
danc8ce3972010-06-29 10:30:23 +0000482foreach v {a b} {
483 do_faultsim_test pagerfault-10$v -prep {
484 sqlite3 db ""
485 db func a_string a_string;
486 execsql {
487 PRAGMA cache_size = 10;
488 BEGIN;
489 CREATE TABLE xx(a, b, UNIQUE(a, b));
490 INSERT INTO xx VALUES(a_string(200), a_string(200));
491 INSERT INTO xx SELECT a_string(200), a_string(200) FROM xx;
492 INSERT INTO xx SELECT a_string(200), a_string(200) FROM xx;
493 INSERT INTO xx SELECT a_string(200), a_string(200) FROM xx;
494 INSERT INTO xx SELECT a_string(200), a_string(200) FROM xx;
495 COMMIT;
496 }
497 } -body {
498 execsql { UPDATE xx SET a = a_string(300) }
499 } -test {
500 faultsim_test_result {0 {}}
501 if {$::v == "b"} { execsql { PRAGMA journal_mode = TRUNCATE } }
502 faultsim_integrity_check
503 faultsim_integrity_check
dan273f3f02010-06-26 15:42:33 +0000504 }
dan273f3f02010-06-26 15:42:33 +0000505}
506
dan273f3f02010-06-26 15:42:33 +0000507#-------------------------------------------------------------------------
508# Test fault injection with transaction savepoints (savepoints created
509# when a SAVEPOINT command is executed outside of any other savepoint
510# or transaction context).
511#
512do_test pagerfault-9-pre1 {
513 faultsim_delete_and_reopen
514 db func a_string a_string;
515 execsql {
516 PRAGMA auto_vacuum = on;
517 CREATE TABLE t1(x UNIQUE);
518 CREATE TABLE t2(y UNIQUE);
519 CREATE TABLE t3(z UNIQUE);
520 BEGIN;
521 INSERT INTO t1 VALUES(a_string(202));
522 INSERT INTO t2 VALUES(a_string(203));
523 INSERT INTO t3 VALUES(a_string(204));
524 INSERT INTO t1 SELECT a_string(202) FROM t1;
525 INSERT INTO t1 SELECT a_string(203) FROM t1;
526 INSERT INTO t1 SELECT a_string(204) FROM t1;
527 INSERT INTO t1 SELECT a_string(205) FROM t1;
528 INSERT INTO t2 SELECT a_string(length(x)) FROM t1;
529 INSERT INTO t3 SELECT a_string(length(x)) FROM t1;
530 COMMIT;
531 }
532 faultsim_save_and_close
533} {}
534do_faultsim_test pagerfault-11 -prep {
535 faultsim_restore_and_reopen
536 execsql { PRAGMA cache_size = 10 }
537} -body {
538 execsql {
539 SAVEPOINT trans;
540 UPDATE t2 SET y = y||'2';
541 INSERT INTO t3 SELECT * FROM t2;
542 DELETE FROM t1;
543 ROLLBACK TO trans;
544 UPDATE t1 SET x = x||'3';
545 INSERT INTO t2 SELECT * FROM t1;
546 DELETE FROM t3;
547 RELEASE trans;
548 }
549} -test {
550 faultsim_test_result {0 {}}
551 faultsim_integrity_check
552}
553
danc396d4a2010-07-02 11:27:43 +0000554
danc8ce3972010-06-29 10:30:23 +0000555#-------------------------------------------------------------------------
556# Test fault injection when writing to a database file that resides on
557# a file-system with a sector-size larger than the database page-size.
558#
dand3533312010-06-28 19:04:02 +0000559do_test pagerfault-12-pre1 {
560 testvfs ss_layer -default 1
561 ss_layer sectorsize 4096
562 faultsim_delete_and_reopen
563 db func a_string a_string;
564
565 execsql {
566 PRAGMA page_size = 1024;
567 PRAGMA journal_mode = PERSIST;
568 PRAGMA cache_size = 10;
569 BEGIN;
570 CREATE TABLE t1(x, y UNIQUE);
571 INSERT INTO t1 VALUES(a_string(333), a_string(444));
572 INSERT INTO t1 SELECT a_string(333+rowid), a_string(444+rowid) FROM t1;
573 INSERT INTO t1 SELECT a_string(333+rowid), a_string(444+rowid) FROM t1;
574 INSERT INTO t1 SELECT a_string(333+rowid), a_string(444+rowid) FROM t1;
575 INSERT INTO t1 SELECT a_string(333+rowid), a_string(444+rowid) FROM t1;
576 INSERT INTO t1 SELECT a_string(44), a_string(55) FROM t1 LIMIT 13;
577 COMMIT;
578 }
579 faultsim_save_and_close
580} {}
danc396d4a2010-07-02 11:27:43 +0000581
582do_faultsim_test pagerfault-12a -prep {
dand3533312010-06-28 19:04:02 +0000583 faultsim_restore_and_reopen
584 execsql { PRAGMA cache_size = 10 }
585 db func a_string a_string;
586} -body {
587 execsql {
588 UPDATE t1 SET x = a_string(length(x)), y = a_string(length(y));
589 }
590} -test {
591 faultsim_test_result {0 {}}
592 faultsim_integrity_check
593}
594
danc396d4a2010-07-02 11:27:43 +0000595do_test pagerfault-12-pre2 {
596 faultsim_restore_and_reopen
597 execsql {
598 CREATE TABLE t2 AS SELECT * FROM t1 LIMIT 10;
599 }
600 faultsim_save_and_close
601} {}
602do_faultsim_test pagerfault-12b -prep {
603 faultsim_restore_and_reopen
604 db func a_string a_string;
605 execsql { SELECT * FROM t1 }
606} -body {
607 set sql(1) { UPDATE t2 SET x = a_string(280) }
608 set sql(2) { UPDATE t1 SET x = a_string(280) WHERE rowid = 5 }
609
610 db eval { SELECT rowid FROM t1 LIMIT 2 } { db eval $sql($rowid) }
611
612} -test {
613 faultsim_test_result {0 {}}
614 faultsim_integrity_check
615}
616
617catch { db close }
618ss_layer delete
619
dand3533312010-06-28 19:04:02 +0000620
danc8ce3972010-06-29 10:30:23 +0000621#-------------------------------------------------------------------------
danba3cbf32010-06-30 04:29:03 +0000622# Test fault injection when SQLite opens a database where the size of the
623# database file is zero bytes but the accompanying journal file is larger
624# than that. In this scenario SQLite should delete the journal file
625# without rolling it back, even if it is in all other respects a valid
626# hot-journal file.
danc8ce3972010-06-29 10:30:23 +0000627#
628do_test pagerfault-13-pre1 {
629 faultsim_delete_and_reopen
630 db func a_string a_string;
631 execsql {
632 PRAGMA journal_mode = PERSIST;
633 BEGIN;
634 CREATE TABLE t1(x, y UNIQUE);
635 INSERT INTO t1 VALUES(a_string(333), a_string(444));
636 COMMIT;
637 }
638 db close
639 file delete -force test.db
640 faultsim_save
641} {}
642do_faultsim_test pagerfault-13 -prep {
643 faultsim_restore_and_reopen
644} -body {
645 execsql { CREATE TABLE xx(a, b) }
646} -test {
647 faultsim_test_result {0 {}}
648}
649
danba3cbf32010-06-30 04:29:03 +0000650#---------------------------------------------------------------------------
651# Test fault injection into a small backup operation.
652#
653do_test pagerfault-14-pre1 {
654 faultsim_delete_and_reopen
655 db func a_string a_string;
656 execsql {
657 PRAGMA journal_mode = PERSIST;
658 ATTACH 'test.db2' AS two;
659 BEGIN;
660 CREATE TABLE t1(x, y UNIQUE);
661 CREATE TABLE two.t2(x, y UNIQUE);
662 INSERT INTO t1 VALUES(a_string(333), a_string(444));
663 INSERT INTO t2 VALUES(a_string(333), a_string(444));
664 COMMIT;
665 }
666 faultsim_save_and_close
667} {}
dan6b63ab42010-06-30 10:36:18 +0000668
669do_faultsim_test pagerfault-14a -prep {
danba3cbf32010-06-30 04:29:03 +0000670 faultsim_restore_and_reopen
671} -body {
672 if {[catch {db backup test.db2} msg]} { error [regsub {.*: } $msg {}] }
673} -test {
674 faultsim_test_result {0 {}} {1 {}} {1 {SQL logic error or missing database}}
danc8ce3972010-06-29 10:30:23 +0000675}
dan6b63ab42010-06-30 10:36:18 +0000676do_faultsim_test pagerfault-14b -prep {
shanehcaace922010-07-08 13:33:47 +0000677 catch { db2 close }
dan6b63ab42010-06-30 10:36:18 +0000678 faultsim_restore_and_reopen
679 sqlite3 db2 ""
680 db2 eval { PRAGMA page_size = 4096; CREATE TABLE xx(a) }
681} -body {
682 sqlite3_backup B db2 main db main
683 B step 200
684 set rc [B finish]
685 if {[string match SQLITE_IOERR_* $rc]} {set rc SQLITE_IOERR}
686 if {$rc != "SQLITE_OK"} { error [sqlite3_test_errstr $rc] }
687 set {} {}
688} -test {
689 faultsim_test_result {0 {}}
690}
dand0b0d4d2010-07-01 19:01:56 +0000691do_faultsim_test pagerfault-14c -prep {
shanehcaace922010-07-08 13:33:47 +0000692 catch { db2 close }
dand0b0d4d2010-07-01 19:01:56 +0000693 faultsim_restore_and_reopen
694 sqlite3 db2 test.db2
695 db2 eval {
696 PRAGMA synchronous = off;
697 PRAGMA page_size = 4096;
698 CREATE TABLE xx(a);
699 }
700} -body {
701 sqlite3_backup B db2 main db main
702 B step 200
703 set rc [B finish]
704 if {[string match SQLITE_IOERR_* $rc]} {set rc SQLITE_IOERR}
705 if {$rc != "SQLITE_OK"} { error [sqlite3_test_errstr $rc] }
706 set {} {}
707} -test {
708 faultsim_test_result {0 {}}
709}
danc8ce3972010-06-29 10:30:23 +0000710
danba3cbf32010-06-30 04:29:03 +0000711do_test pagerfault-15-pre1 {
712 faultsim_delete_and_reopen
713 db func a_string a_string;
714 execsql {
715 BEGIN;
716 CREATE TABLE t1(x, y UNIQUE);
717 INSERT INTO t1 VALUES(a_string(11), a_string(22));
718 INSERT INTO t1 VALUES(a_string(11), a_string(22));
719 COMMIT;
720 }
721 faultsim_save_and_close
722} {}
723do_faultsim_test pagerfault-15 -prep {
724 faultsim_restore_and_reopen
725 db func a_string a_string;
726} -body {
727 db eval { SELECT * FROM t1 LIMIT 1 } {
728 execsql {
729 BEGIN; INSERT INTO t1 VALUES(a_string(333), a_string(555)); COMMIT;
730 BEGIN; INSERT INTO t1 VALUES(a_string(333), a_string(555)); COMMIT;
731 }
732 }
733} -test {
734 faultsim_test_result {0 {}}
735 faultsim_integrity_check
736}
737
danba3cbf32010-06-30 04:29:03 +0000738
739do_test pagerfault-16-pre1 {
740 faultsim_delete_and_reopen
741 execsql { CREATE TABLE t1(x, y UNIQUE) }
742 faultsim_save_and_close
743} {}
744do_faultsim_test pagerfault-16 -prep {
745 faultsim_restore_and_reopen
746} -body {
747 execsql {
748 PRAGMA locking_mode = exclusive;
749 PRAGMA journal_mode = wal;
750 INSERT INTO t1 VALUES(1, 2);
751 INSERT INTO t1 VALUES(3, 4);
752 PRAGMA journal_mode = delete;
753 INSERT INTO t1 VALUES(4, 5);
754 PRAGMA journal_mode = wal;
755 INSERT INTO t1 VALUES(6, 7);
756 PRAGMA journal_mode = persist;
757 INSERT INTO t1 VALUES(8, 9);
758 }
759} -test {
760 faultsim_test_result {0 {exclusive wal delete wal persist}}
761 faultsim_integrity_check
762}
763
764
dan89ccf442010-07-01 15:09:47 +0000765#-------------------------------------------------------------------------
766# Test fault injection while changing into and out of WAL mode.
767#
768do_test pagerfault-17-pre1 {
769 faultsim_delete_and_reopen
770 execsql {
771 CREATE TABLE t1(a PRIMARY KEY, b);
772 INSERT INTO t1 VALUES(1862, 'Botha');
773 INSERT INTO t1 VALUES(1870, 'Smuts');
774 INSERT INTO t1 VALUES(1866, 'Hertzog');
775 }
776 faultsim_save_and_close
777} {}
778do_faultsim_test pagerfault-17a -prep {
779 faultsim_restore_and_reopen
780} -body {
781 execsql {
782 PRAGMA journal_mode = wal;
783 PRAGMA journal_mode = delete;
784 }
785} -test {
786 faultsim_test_result {0 {wal delete}}
787 faultsim_integrity_check
788}
789do_faultsim_test pagerfault-17b -prep {
790 faultsim_restore_and_reopen
791 execsql { PRAGMA synchronous = OFF }
792} -body {
793 execsql {
794 PRAGMA journal_mode = wal;
795 INSERT INTO t1 VALUES(22, 'Clarke');
796 PRAGMA journal_mode = delete;
797 }
798} -test {
799 faultsim_test_result {0 {wal delete}}
800 faultsim_integrity_check
801}
802do_faultsim_test pagerfault-17c -prep {
803 faultsim_restore_and_reopen
804 execsql {
805 PRAGMA locking_mode = exclusive;
806 PRAGMA journal_mode = wal;
807 }
808} -body {
809 execsql { PRAGMA journal_mode = delete }
810} -test {
811 faultsim_test_result {0 delete}
812 faultsim_integrity_check
813}
814do_faultsim_test pagerfault-17d -prep {
shanehcaace922010-07-08 13:33:47 +0000815 catch { db2 close }
dan89ccf442010-07-01 15:09:47 +0000816 faultsim_restore_and_reopen
817 sqlite3 db2 test.db
818 execsql { PRAGMA journal_mode = delete }
819 execsql { PRAGMA journal_mode = wal }
820 execsql { INSERT INTO t1 VALUES(99, 'Bradman') } db2
821} -body {
822 execsql { PRAGMA journal_mode = delete }
823} -test {
824 faultsim_test_result {1 {database is locked}}
825 faultsim_integrity_check
826}
827do_faultsim_test pagerfault-17e -prep {
shanehcaace922010-07-08 13:33:47 +0000828 catch { db2 close }
dan89ccf442010-07-01 15:09:47 +0000829 faultsim_restore_and_reopen
830 sqlite3 db2 test.db
831 execsql { PRAGMA journal_mode = delete }
832 execsql { PRAGMA journal_mode = wal }
833 set ::chan [launch_testfixture]
834 testfixture $::chan {
835 sqlite3 db test.db
836 db eval { INSERT INTO t1 VALUES(101, 'Latham') }
837 }
838 catch { testfixture $::chan sqlite_abort }
839 catch { close $::chan }
840} -body {
841 execsql { PRAGMA journal_mode = delete }
842} -test {
843 faultsim_test_result {0 delete}
844 faultsim_integrity_check
845}
846
847#-------------------------------------------------------------------------
848# Test fault-injection when changing from journal_mode=persist to
849# journal_mode=delete (this involves deleting the journal file).
850#
851do_test pagerfault-18-pre1 {
852 faultsim_delete_and_reopen
853 execsql {
854 CREATE TABLE qq(x);
855 INSERT INTO qq VALUES('Herbert');
856 INSERT INTO qq VALUES('Macalister');
857 INSERT INTO qq VALUES('Mackenzie');
858 INSERT INTO qq VALUES('Lilley');
859 INSERT INTO qq VALUES('Palmer');
860 }
861 faultsim_save_and_close
862} {}
863do_faultsim_test pagerfault-18 -prep {
864 faultsim_restore_and_reopen
865 execsql {
866 PRAGMA journal_mode = PERSIST;
867 INSERT INTO qq VALUES('Beatty');
868 }
869} -body {
870 execsql { PRAGMA journal_mode = delete }
871} -test {
872 faultsim_test_result {0 delete}
873 faultsim_integrity_check
874}
875
dan89ccf442010-07-01 15:09:47 +0000876do_faultsim_test pagerfault-19a -prep {
877 sqlite3 db :memory:
878 db func a_string a_string
879 execsql {
880 PRAGMA auto_vacuum = FULL;
881 BEGIN;
882 CREATE TABLE t1(a, b);
883 INSERT INTO t1 VALUES(a_string(5000), a_string(6000));
884 COMMIT;
885 }
886} -body {
887 execsql {
888 CREATE TABLE t2(a, b);
889 INSERT INTO t2 SELECT * FROM t1;
890 DELETE FROM t1;
891 }
892} -test {
893 faultsim_test_result {0 {}}
894}
895
896do_test pagerfault-19-pre1 {
897 faultsim_delete_and_reopen
898 execsql {
899 PRAGMA auto_vacuum = FULL;
900 CREATE TABLE t1(x); INSERT INTO t1 VALUES(1);
901 CREATE TABLE t2(x); INSERT INTO t2 VALUES(2);
902 CREATE TABLE t3(x); INSERT INTO t3 VALUES(3);
903 CREATE TABLE t4(x); INSERT INTO t4 VALUES(4);
904 CREATE TABLE t5(x); INSERT INTO t5 VALUES(5);
905 CREATE TABLE t6(x); INSERT INTO t6 VALUES(6);
906 }
907 faultsim_save_and_close
908} {}
909do_faultsim_test pagerfault-19b -prep {
910 faultsim_restore_and_reopen
911} -body {
912 execsql {
913 BEGIN;
914 UPDATE t4 SET x = x+1;
915 UPDATE t6 SET x = x+1;
916 SAVEPOINT one;
917 UPDATE t3 SET x = x+1;
918 SAVEPOINT two;
919 DROP TABLE t2;
920 ROLLBACK TO one;
921 COMMIT;
922 SELECT * FROM t3;
923 SELECT * FROM t4;
924 SELECT * FROM t6;
925 }
926} -test {
927 faultsim_test_result {0 {3 5 7}}
928}
929
dand0b0d4d2010-07-01 19:01:56 +0000930#-------------------------------------------------------------------------
931# This tests fault-injection in a special case in the auto-vacuum code.
932#
dan89ccf442010-07-01 15:09:47 +0000933do_test pagerfault-20-pre1 {
934 faultsim_delete_and_reopen
dan89ccf442010-07-01 15:09:47 +0000935 execsql {
dand0b0d4d2010-07-01 19:01:56 +0000936 PRAGMA cache_size = 10;
937 PRAGMA auto_vacuum = FULL;
938 CREATE TABLE t0(a, b);
dan89ccf442010-07-01 15:09:47 +0000939 }
940 faultsim_save_and_close
941} {}
942do_faultsim_test pagerfault-20 -prep {
943 faultsim_restore_and_reopen
dan89ccf442010-07-01 15:09:47 +0000944} -body {
945 execsql {
946 BEGIN;
dand0b0d4d2010-07-01 19:01:56 +0000947 CREATE TABLE t1(a, b);
948 CREATE TABLE t2(a, b);
949 DROP TABLE t1;
dan89ccf442010-07-01 15:09:47 +0000950 COMMIT;
951 }
952} -test {
953 faultsim_test_result {0 {}}
dan89ccf442010-07-01 15:09:47 +0000954}
dan273f3f02010-06-26 15:42:33 +0000955
dand0b0d4d2010-07-01 19:01:56 +0000956do_test pagerfault-21-pre1 {
957 faultsim_delete_and_reopen
958 execsql {
959 PRAGMA cache_size = 10;
960 CREATE TABLE t0(a PRIMARY KEY, b);
961 INSERT INTO t0 VALUES(1, 2);
962 }
963 faultsim_save_and_close
964} {}
965do_faultsim_test pagerfault-21 -prep {
966 faultsim_restore_and_reopen
967} -body {
968 db eval { SELECT * FROM t0 LIMIT 1 } {
969 db eval { INSERT INTO t0 SELECT a+1, b FROM t0 }
970 db eval { INSERT INTO t0 SELECT a+2, b FROM t0 }
971 }
972} -test {
973 faultsim_test_result {0 {}}
974}
975
dand0b0d4d2010-07-01 19:01:56 +0000976
dan9d08d642010-07-14 08:20:35 +0000977#-------------------------------------------------------------------------
978# Test fault-injection and rollback when the nReserve header value
979# is non-zero.
980#
981do_test pagerfault-21-pre1 {
982 faultsim_delete_and_reopen
983 execsql {
984 PRAGMA page_size = 1024;
985 PRAGMA journal_mode = WAL;
986 PRAGMA journal_mode = DELETE;
987 }
988 db close
989 hexio_write test.db 20 10
990 hexio_write test.db 105 03F0
991 sqlite3 db test.db
992 db func a_string a_string
993 execsql {
994 CREATE TABLE t0(a PRIMARY KEY, b UNIQUE);
995 INSERT INTO t0 VALUES(a_string(222), a_string(333));
996 INSERT INTO t0 VALUES(a_string(223), a_string(334));
997 INSERT INTO t0 VALUES(a_string(224), a_string(335));
998 INSERT INTO t0 VALUES(a_string(225), a_string(336));
999 }
1000 faultsim_save_and_close
1001} {}
1002
1003do_faultsim_test pagerfault-21 -prep {
1004 faultsim_restore_and_reopen
1005} -body {
1006 execsql { INSERT INTO t0 SELECT a||'x', b||'x' FROM t0 }
1007} -test {
1008 faultsim_test_result {0 {}}
1009 faultsim_integrity_check
1010}
1011ifcapable crashtest {
1012 faultsim_delete_and_reopen
1013 execsql {
1014 PRAGMA page_size = 1024;
1015 PRAGMA journal_mode = WAL;
1016 PRAGMA journal_mode = DELETE;
1017 }
1018 db close
1019 hexio_write test.db 20 10
1020 hexio_write test.db 105 03F0
1021
1022 sqlite3 db test.db
1023 db func a_string a_string
1024 execsql {
1025 CREATE TABLE t0(a PRIMARY KEY, b UNIQUE);
1026 INSERT INTO t0 VALUES(a_string(222), a_string(333));
1027 INSERT INTO t0 VALUES(a_string(223), a_string(334));
1028 }
1029 faultsim_save_and_close
1030
1031 for {set iTest 1} {$iTest<50} {incr iTest} {
1032 do_test pagerfault-21.crash.$iTest.1 {
1033 crashsql -delay 1 -file test.db -seed $iTest {
1034 BEGIN;
1035 CREATE TABLE t1(a PRIMARY KEY, b UNIQUE);
1036 INSERT INTO t1 SELECT a, b FROM t0;
1037 COMMIT;
1038 }
1039 } {1 {child process exited abnormally}}
1040 do_test pagerfault-22.$iTest.2 {
1041 sqlite3 db test.db
1042 execsql { PRAGMA integrity_check }
1043 } {ok}
1044 db close
1045 }
1046}
1047
dan59257dc2010-08-04 11:34:31 +00001048
1049#-------------------------------------------------------------------------
1050# When a 3.7.0 client opens a write-transaction on a database file that
1051# has been appended to or truncated by a pre-370 client, it updates
1052# the db-size in the file header immediately. This test case provokes
1053# errors during that operation.
1054#
1055do_test pagerfault-22-pre1 {
1056 faultsim_delete_and_reopen
1057 db func a_string a_string
1058 execsql {
1059 PRAGMA page_size = 1024;
1060 PRAGMA auto_vacuum = 0;
1061 CREATE TABLE t1(a);
1062 CREATE INDEX i1 ON t1(a);
1063 INSERT INTO t1 VALUES(a_string(3000));
1064 CREATE TABLE t2(a);
1065 INSERT INTO t2 VALUES(1);
1066 }
1067 db close
1068 sql36231 { INSERT INTO t1 VALUES(a_string(3000)) }
1069 faultsim_save_and_close
1070} {}
1071do_faultsim_test pagerfault-22 -prep {
1072 faultsim_restore_and_reopen
1073} -body {
1074 execsql { INSERT INTO t2 VALUES(2) }
1075 execsql { SELECT * FROM t2 }
1076} -test {
1077 faultsim_test_result {0 {1 2}}
1078 faultsim_integrity_check
1079}
1080
dan22b328b2010-08-11 18:56:45 +00001081#-------------------------------------------------------------------------
1082# Provoke an OOM error during a commit of multi-file transaction. One of
1083# the databases written during the transaction is an in-memory database.
1084# This test causes rollback of the in-memory database after CommitPhaseOne()
1085# has successfully returned. i.e. the series of calls for the aborted commit
1086# is:
1087#
1088# PagerCommitPhaseOne(<in-memory-db>) -> SQLITE_OK
1089# PagerCommitPhaseOne(<file-db>) -> SQLITE_IOERR
1090# PagerRollback(<in-memory-db>)
1091# PagerRollback(<file-db>)
1092#
1093do_faultsim_test pagerfault-23 -prep {
1094 foreach f [glob -nocomplain test.db*] { file delete -force $f }
1095 sqlite3 db :memory:
1096 db eval {
1097 ATTACH 'test.db2' AS aux;
1098 CREATE TABLE t1(a, b);
1099 CREATE TABLE aux.t2(a, b);
1100 }
1101} -body {
1102 execsql {
1103 BEGIN;
1104 INSERT INTO t1 VALUES(1,2);
1105 INSERT INTO t2 VALUES(3,4);
1106 COMMIT;
1107 }
1108} -test {
1109 faultsim_test_result {0 {}}
1110 faultsim_integrity_check
1111}
1112
1113do_faultsim_test pagerfault-24 -prep {
1114 faultsim_delete_and_reopen
1115 db eval { PRAGMA temp_store = file }
1116 execsql { CREATE TABLE x(a, b) }
1117} -body {
1118 execsql { CREATE TEMP TABLE t1(a, b) }
1119} -test {
dan5653e4d2010-08-12 11:25:47 +00001120 faultsim_test_result {0 {}} \
1121 {1 {unable to open a temporary database file for storing temporary tables}}
dan22b328b2010-08-11 18:56:45 +00001122 set ic [db eval { PRAGMA temp.integrity_check }]
1123 if {$ic != "ok"} { error "Integrity check: $ic" }
1124}
1125
dan5653e4d2010-08-12 11:25:47 +00001126proc lockrows {n} {
1127 if {$n==0} { return "" }
1128 db eval { SELECT * FROM t1 WHERE oid = $n } {
1129 return [lockrows [expr {$n-1}]]
1130 }
1131}
1132
dan1879b082010-08-12 16:36:34 +00001133
dan5653e4d2010-08-12 11:25:47 +00001134do_test pagerfault-25-pre1 {
1135 faultsim_delete_and_reopen
1136 db func a_string a_string
1137 execsql {
1138 PRAGMA page_size = 1024;
1139 PRAGMA auto_vacuum = 0;
1140 CREATE TABLE t1(a);
1141 INSERT INTO t1 VALUES(a_string(500));
1142 INSERT INTO t1 SELECT a_string(500) FROM t1;
1143 INSERT INTO t1 SELECT a_string(500) FROM t1;
1144 INSERT INTO t1 SELECT a_string(500) FROM t1;
1145 INSERT INTO t1 SELECT a_string(500) FROM t1;
1146 INSERT INTO t1 SELECT a_string(500) FROM t1;
1147 }
1148 faultsim_save_and_close
1149} {}
dan1879b082010-08-12 16:36:34 +00001150do_faultsim_test pagerfault-25 -prep {
dan5653e4d2010-08-12 11:25:47 +00001151 faultsim_restore_and_reopen
1152 db func a_string a_string
1153 set ::channel [db incrblob -readonly t1 a 1]
1154 execsql {
1155 PRAGMA cache_size = 10;
1156 BEGIN;
1157 INSERT INTO t1 VALUES(a_string(3000));
1158 INSERT INTO t1 VALUES(a_string(3000));
1159 }
1160} -body {
1161 lockrows 30
1162} -test {
1163 catch { lockrows 30 }
dan1879b082010-08-12 16:36:34 +00001164 catch { db eval COMMIT }
dan5653e4d2010-08-12 11:25:47 +00001165 close $::channel
1166 faultsim_test_result {0 {}}
1167}
dan22b328b2010-08-11 18:56:45 +00001168
dan1879b082010-08-12 16:36:34 +00001169do_faultsim_test pagerfault-26 -prep {
1170 faultsim_delete_and_reopen
1171 execsql {
1172 PRAGMA page_size = 1024;
1173 PRAGMA journal_mode = truncate;
1174 PRAGMA auto_vacuum = full;
1175 PRAGMA locking_mode=exclusive;
1176 CREATE TABLE t1(a, b);
1177 INSERT INTO t1 VALUES(1, 2);
1178 PRAGMA page_size = 4096;
1179 }
1180} -body {
1181 execsql {
1182 VACUUM;
1183 }
1184} -test {
1185 faultsim_test_result {0 {}}
1186
1187 set contents [db eval {SELECT * FROM t1}]
1188 if {$contents != "1 2"} { error "Bad database contents ($contents)" }
1189
1190 set sz [file size test.db]
1191 if {$testrc!=0 && $sz!=1024*3 && $sz!=4096*3} {
1192 error "Expected file size to be 3072 or 12288 bytes - actual size $sz bytes"
1193 }
1194 if {$testrc==0 && $sz!=4096*3} {
1195 error "Expected file size to be 12288 bytes - actual size $sz bytes"
1196 }
1197}
1198
danf5d3df42010-08-21 15:51:05 +00001199do_test pagerfault-27-pre {
1200 faultsim_delete_and_reopen
1201 db func a_string a_string
1202 execsql {
1203 PRAGMA page_size = 1024;
1204 CREATE TABLE t1(a, b);
1205 CREATE TABLE t2(a UNIQUE, b UNIQUE);
1206 INSERT INTO t2 VALUES( a_string(800), a_string(800) );
1207 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1208 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1209 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1210 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1211 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1212 INSERT INTO t2 SELECT a_string(800), a_string(800) FROM t2;
1213 INSERT INTO t1 VALUES (a_string(20000), a_string(20000));
1214 }
1215 faultsim_save_and_close
1216} {}
1217do_faultsim_test pagerfault-27 -faults ioerr-persistent -prep {
1218 faultsim_restore_and_reopen
1219 db func a_string a_string
1220 execsql {
1221 PRAGMA cache_size = 10;
1222 BEGIN EXCLUSIVE;
1223 }
1224 set ::channel [db incrblob t1 a 1]
1225} -body {
1226 puts $::channel [string repeat abc 6000]
1227 flush $::channel
1228} -test {
dan5f848c32010-08-23 18:19:31 +00001229 catchsql { UPDATE t2 SET a = a_string(800), b = a_string(800) }
danf5d3df42010-08-21 15:51:05 +00001230 catch { close $::channel }
dan5f848c32010-08-23 18:19:31 +00001231 catchsql { ROLLBACK }
danf5d3df42010-08-21 15:51:05 +00001232 faultsim_integrity_check
1233}
dan22b328b2010-08-11 18:56:45 +00001234
danb0ac3e32010-06-16 10:55:42 +00001235finish_test
danf5d3df42010-08-21 15:51:05 +00001236