aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/sqlite/unix/sqlite-3.5.1/test/crash2.test
diff options
context:
space:
mode:
authordan miller2007-10-20 02:49:29 +0000
committerdan miller2007-10-20 02:49:29 +0000
commite36d23a85ebff914d74bb541558c2b6082b78edb (patch)
tree54b58fdf162e78af64055282a6035c8d2443389d /libraries/sqlite/unix/sqlite-3.5.1/test/crash2.test
parent* Fixed an issue whereby avatar chat distances were being calculated against ... (diff)
downloadopensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.zip
opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.gz
opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.bz2
opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.xz
sqlite source (unix build) added to libraries
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/test/crash2.test')
-rw-r--r--libraries/sqlite/unix/sqlite-3.5.1/test/crash2.test132
1 files changed, 132 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/test/crash2.test b/libraries/sqlite/unix/sqlite-3.5.1/test/crash2.test
new file mode 100644
index 0000000..4320779
--- /dev/null
+++ b/libraries/sqlite/unix/sqlite-3.5.1/test/crash2.test
@@ -0,0 +1,132 @@
1# 2001 September 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# This file implements regression tests for SQLite library.
12#
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.
18#
19# $Id: crash2.test,v 1.5 2007/08/24 11:52:29 danielk1977 Exp $
20
21set testdir [file dirname $argv0]
22source $testdir/tester.tcl
23
24ifcapable !crashtest {
25 finish_test
26 return
27}
28
29db close
30
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).
34#
35do_test crash2-1.1 {
36 crashsql -delay 500 -file test.db -blocksize 2048 {
37 PRAGMA auto_vacuum=OFF;
38 PRAGMA page_size=1024;
39 BEGIN;
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;
42 COMMIT;
43 }
44 file size test.db
45} {3072}
46
47for {set ii 0} {$ii < 5} {incr ii} {
48
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
53 # risking corruption.
54 #
55 # The loop is so that this test can be run with a couple
56 # of different seeds for the random number generator.
57 #
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);
62 }]
63 sqlite3 db test.db
64 db eval {PRAGMA integrity_check}
65 } {ok}
66}
67
68proc signature {} {
69 return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}]
70}
71
72# Test case for crashing during journal sync with simulated
73# sector-size values from 1024 to 8192.
74#
75do_test crash2-2.0 {
76 execsql BEGIN
77 for {set n 0} {$n < 1000} {incr n} {
78 execsql "INSERT INTO abc VALUES($n, [expr 2*$n], [expr 3*$n])"
79 }
80 execsql {
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;
86 }
87 execsql COMMIT
88 expr ([file size test.db] / 1024) > 450
89} {1}
90for {set i 1} {$i < 30} {incr i} {
91 set sig [signature]
92 set sector [expr 1024 * 1<<($i%4)]
93 db close
94 do_test crash2-2.$i.1 {
95 crashsql -blocksize $sector -delay [expr $i%5 + 1] -file test.db-journal "
96 BEGIN;
97 SELECT random() FROM abc LIMIT $i;
98 INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0;
99 DELETE FROM abc WHERE random()%2!=0;
100 COMMIT;
101 "
102 } {1 {child process exited abnormally}}
103 do_test crash2-2.$i.2 {
104 sqlite3 db test.db
105 signature
106 } $sig
107}
108
109
110# Test case for crashing during database sync with simulated
111# sector-size values from 1024 to 8192.
112#
113for {set i 1} {$i < 10} {incr i} {
114 set sig [signature]
115 set sector [expr 1024 * 1<<($i%4)]
116 db close
117 do_test crash2-3.$i.1 {
118 crashsql -blocksize $sector -file test.db "
119 BEGIN;
120 SELECT random() FROM abc LIMIT $i;
121 INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0;
122 DELETE FROM abc WHERE random()%2!=0;
123 COMMIT;
124 "
125 } {1 {child process exited abnormally}}
126 do_test crash2-3.$i.2 {
127 sqlite3 db test.db
128 signature
129 } $sig
130}
131
132finish_test