sl@0
|
1 |
# 2001 September 15
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
# This file implements regression tests for SQLite library.
|
sl@0
|
12 |
#
|
sl@0
|
13 |
# The focus of this file is testing the ability of the database to
|
sl@0
|
14 |
# uses its rollback journal to recover intact (no database corruption)
|
sl@0
|
15 |
# from a power failure during the middle of a COMMIT. Even more
|
sl@0
|
16 |
# specifically, the tests in this file verify this functionality
|
sl@0
|
17 |
# for storage mediums with various sector sizes.
|
sl@0
|
18 |
#
|
sl@0
|
19 |
# $Id: crash2.test,v 1.6 2008/08/25 07:12:29 danielk1977 Exp $
|
sl@0
|
20 |
|
sl@0
|
21 |
set testdir [file dirname $argv0]
|
sl@0
|
22 |
source $testdir/tester.tcl
|
sl@0
|
23 |
|
sl@0
|
24 |
ifcapable !crashtest {
|
sl@0
|
25 |
finish_test
|
sl@0
|
26 |
return
|
sl@0
|
27 |
}
|
sl@0
|
28 |
|
sl@0
|
29 |
db close
|
sl@0
|
30 |
|
sl@0
|
31 |
# This test is designed to check that the crash-test infrastructure
|
sl@0
|
32 |
# can create files that do not consist of an integer number of
|
sl@0
|
33 |
# simulated disk blocks (i.e. 3KB file using 2KB disk blocks).
|
sl@0
|
34 |
#
|
sl@0
|
35 |
do_test crash2-1.1 {
|
sl@0
|
36 |
crashsql -delay 500 -file test.db -blocksize 2048 {
|
sl@0
|
37 |
PRAGMA auto_vacuum=OFF;
|
sl@0
|
38 |
PRAGMA page_size=1024;
|
sl@0
|
39 |
BEGIN;
|
sl@0
|
40 |
CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c;
|
sl@0
|
41 |
CREATE TABLE def AS SELECT 1 AS d, 2 AS e, 3 AS f;
|
sl@0
|
42 |
COMMIT;
|
sl@0
|
43 |
}
|
sl@0
|
44 |
file size test.db
|
sl@0
|
45 |
} {3072}
|
sl@0
|
46 |
|
sl@0
|
47 |
for {set ii 0} {$ii < 5} {incr ii} {
|
sl@0
|
48 |
|
sl@0
|
49 |
# Simple test using the database created above: Create a new
|
sl@0
|
50 |
# table so that page 1 and page 4 are modified. Using a
|
sl@0
|
51 |
# block-size of 2048 and page-size of 1024, this means
|
sl@0
|
52 |
# pages 2 and 3 must also be saved in the journal to avoid
|
sl@0
|
53 |
# risking corruption.
|
sl@0
|
54 |
#
|
sl@0
|
55 |
# The loop is so that this test can be run with a couple
|
sl@0
|
56 |
# of different seeds for the random number generator.
|
sl@0
|
57 |
#
|
sl@0
|
58 |
do_test crash2-1.2.$ii {
|
sl@0
|
59 |
crashsql -file test.db -blocksize 2048 [subst {
|
sl@0
|
60 |
[string repeat {SELECT random();} $ii]
|
sl@0
|
61 |
CREATE TABLE hij(h, i, j);
|
sl@0
|
62 |
}]
|
sl@0
|
63 |
sqlite3 db test.db
|
sl@0
|
64 |
db eval {PRAGMA integrity_check}
|
sl@0
|
65 |
} {ok}
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
proc signature {} {
|
sl@0
|
69 |
return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}]
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
# Test case for crashing during journal sync with simulated
|
sl@0
|
73 |
# sector-size values from 1024 to 8192.
|
sl@0
|
74 |
#
|
sl@0
|
75 |
do_test crash2-2.0 {
|
sl@0
|
76 |
execsql BEGIN
|
sl@0
|
77 |
for {set n 0} {$n < 1000} {incr n} {
|
sl@0
|
78 |
execsql "INSERT INTO abc VALUES($n, [expr 2*$n], [expr 3*$n])"
|
sl@0
|
79 |
}
|
sl@0
|
80 |
execsql {
|
sl@0
|
81 |
INSERT INTO abc SELECT * FROM abc;
|
sl@0
|
82 |
INSERT INTO abc SELECT * FROM abc;
|
sl@0
|
83 |
INSERT INTO abc SELECT * FROM abc;
|
sl@0
|
84 |
INSERT INTO abc SELECT * FROM abc;
|
sl@0
|
85 |
INSERT INTO abc SELECT * FROM abc;
|
sl@0
|
86 |
}
|
sl@0
|
87 |
execsql COMMIT
|
sl@0
|
88 |
expr ([file size test.db] / 1024) > 450
|
sl@0
|
89 |
} {1}
|
sl@0
|
90 |
for {set i 1} {$i < 30} {incr i} {
|
sl@0
|
91 |
set sig [signature]
|
sl@0
|
92 |
set sector [expr 1024 * 1<<($i%4)]
|
sl@0
|
93 |
db close
|
sl@0
|
94 |
do_test crash2-2.$i.1 {
|
sl@0
|
95 |
crashsql -blocksize $sector -delay [expr $i%5 + 1] -file test.db-journal "
|
sl@0
|
96 |
PRAGMA temp_store = memory;
|
sl@0
|
97 |
BEGIN;
|
sl@0
|
98 |
SELECT random() FROM abc LIMIT $i;
|
sl@0
|
99 |
INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0;
|
sl@0
|
100 |
DELETE FROM abc WHERE random()%2!=0;
|
sl@0
|
101 |
COMMIT;
|
sl@0
|
102 |
"
|
sl@0
|
103 |
} {1 {child process exited abnormally}}
|
sl@0
|
104 |
do_test crash2-2.$i.2 {
|
sl@0
|
105 |
sqlite3 db test.db
|
sl@0
|
106 |
signature
|
sl@0
|
107 |
} $sig
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
|
sl@0
|
111 |
# Test case for crashing during database sync with simulated
|
sl@0
|
112 |
# sector-size values from 1024 to 8192.
|
sl@0
|
113 |
#
|
sl@0
|
114 |
for {set i 1} {$i < 10} {incr i} {
|
sl@0
|
115 |
set sig [signature]
|
sl@0
|
116 |
set sector [expr 1024 * 1<<($i%4)]
|
sl@0
|
117 |
db close
|
sl@0
|
118 |
do_test crash2-3.$i.1 {
|
sl@0
|
119 |
crashsql -blocksize $sector -file test.db "
|
sl@0
|
120 |
BEGIN;
|
sl@0
|
121 |
SELECT random() FROM abc LIMIT $i;
|
sl@0
|
122 |
INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0;
|
sl@0
|
123 |
DELETE FROM abc WHERE random()%2!=0;
|
sl@0
|
124 |
COMMIT;
|
sl@0
|
125 |
"
|
sl@0
|
126 |
} {1 {child process exited abnormally}}
|
sl@0
|
127 |
do_test crash2-3.$i.2 {
|
sl@0
|
128 |
sqlite3 db test.db
|
sl@0
|
129 |
signature
|
sl@0
|
130 |
} $sig
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
finish_test
|