3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # The focus of this file is testing the ability of the database to
14 # uses its rollback journal to recover intact (no database corruption)
15 # from a power failure during the middle of a COMMIT. Even more
16 # specifically, the tests in this file verify this functionality
17 # for storage mediums with various sector sizes.
19 # $Id: crash2.test,v 1.6 2008/08/25 07:12:29 danielk1977 Exp $
21 set testdir [file dirname $argv0]
22 source $testdir/tester.tcl
24 ifcapable !crashtest {
31 # This test is designed to check that the crash-test infrastructure
32 # can create files that do not consist of an integer number of
33 # simulated disk blocks (i.e. 3KB file using 2KB disk blocks).
36 crashsql -delay 500 -file test.db -blocksize 2048 {
37 PRAGMA auto_vacuum=OFF;
38 PRAGMA page_size=1024;
40 CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c;
41 CREATE TABLE def AS SELECT 1 AS d, 2 AS e, 3 AS f;
47 for {set ii 0} {$ii < 5} {incr ii} {
49 # Simple test using the database created above: Create a new
50 # table so that page 1 and page 4 are modified. Using a
51 # block-size of 2048 and page-size of 1024, this means
52 # pages 2 and 3 must also be saved in the journal to avoid
55 # The loop is so that this test can be run with a couple
56 # of different seeds for the random number generator.
58 do_test crash2-1.2.$ii {
59 crashsql -file test.db -blocksize 2048 [subst {
60 [string repeat {SELECT random();} $ii]
61 CREATE TABLE hij(h, i, j);
64 db eval {PRAGMA integrity_check}
69 return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}]
72 # Test case for crashing during journal sync with simulated
73 # sector-size values from 1024 to 8192.
77 for {set n 0} {$n < 1000} {incr n} {
78 execsql "INSERT INTO abc VALUES($n, [expr 2*$n], [expr 3*$n])"
81 INSERT INTO abc SELECT * FROM abc;
82 INSERT INTO abc SELECT * FROM abc;
83 INSERT INTO abc SELECT * FROM abc;
84 INSERT INTO abc SELECT * FROM abc;
85 INSERT INTO abc SELECT * FROM abc;
88 expr ([file size test.db] / 1024) > 450
90 for {set i 1} {$i < 30} {incr i} {
92 set sector [expr 1024 * 1<<($i%4)]
94 do_test crash2-2.$i.1 {
95 crashsql -blocksize $sector -delay [expr $i%5 + 1] -file test.db-journal "
96 PRAGMA temp_store = memory;
98 SELECT random() FROM abc LIMIT $i;
99 INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0;
100 DELETE FROM abc WHERE random()%2!=0;
103 } {1 {child process exited abnormally}}
104 do_test crash2-2.$i.2 {
111 # Test case for crashing during database sync with simulated
112 # sector-size values from 1024 to 8192.
114 for {set i 1} {$i < 10} {incr i} {
116 set sector [expr 1024 * 1<<($i%4)]
118 do_test crash2-3.$i.1 {
119 crashsql -blocksize $sector -file test.db "
121 SELECT random() FROM abc LIMIT $i;
122 INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0;
123 DELETE FROM abc WHERE random()%2!=0;
126 } {1 {child process exited abnormally}}
127 do_test crash2-3.$i.2 {