Fix a typo inside an assert() statement introduced by the previous commit.
[sqlite.git] / test / crash6.test
blob69c19464b3f4ad55318cd98280f24322b6492557
1 # 2001 September 15
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 tests that rollback journals for databases that use a 
12 # page-size other than the default page-size can be rolled back Ok.
14 # $Id: crash6.test,v 1.2 2008/04/14 15:27:19 drh Exp $
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
19 ifcapable !crashtest {
20   finish_test
21   return
24 for {set ii 0} {$ii < 10} {incr ii} {
25   catch {db close}
26   forcedelete test.db test.db-journal
27   crashsql -delay 2 -file test.db {
28     PRAGMA auto_vacuum=OFF;
29     PRAGMA page_size=4096;
30     BEGIN;
31     CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c;
32     COMMIT;
33     BEGIN;
34     CREATE TABLE def AS SELECT 1 AS d, 2 AS e, 3 AS f;
35     COMMIT;
36   }
37   sqlite3 db test.db
38   integrity_check crash6-1.$ii
41 for {set ii 0} {$ii < 10} {incr ii} {
42   catch {db close}
43   forcedelete test.db test.db-journal
44   sqlite3 db test.db
45   execsql {
46     PRAGMA auto_vacuum=OFF;
47     PRAGMA page_size=2048;
48     BEGIN;
49     CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c;
50     COMMIT;
51   }
52   db close
53   crashsql -delay 1 -file test.db {
54     INSERT INTO abc VALUES(5, 6, 7);
55   }
56   sqlite3 db test.db
57   integrity_check crash6-2.$ii
60 proc signature {} {
61   return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}]
64 # Test case for crashing during database sync with page-size values 
65 # from 1024 to 8192.
67 for {set ii 0} {$ii < 30} {incr ii} {
68   db close
69   forcedelete test.db
70   sqlite3 db test.db
72   set pagesize [expr 1024 << ($ii % 4)]
73   if {$pagesize>$::SQLITE_MAX_PAGE_SIZE} {
74     set pagesize $::SQLITE_MAX_PAGE_SIZE
75   }
76   do_test crash6-3.$ii.0 {
77     execsql "pragma page_size = $pagesize"
78     execsql "pragma page_size"
79   } $pagesize
81   do_test crash6-3.$ii.1 {
82   
83     execsql BEGIN
84     execsql {CREATE TABLE abc(a, b, c)}
85     for {set n 0} {$n < 1000} {incr n} {
86       execsql "INSERT INTO abc VALUES($n, [expr 2*$n], [expr 3*$n])"
87     }
88     execsql {
89       INSERT INTO abc SELECT * FROM abc;
90       INSERT INTO abc SELECT * FROM abc;
91       INSERT INTO abc SELECT * FROM abc;
92       INSERT INTO abc SELECT * FROM abc;
93       INSERT INTO abc SELECT * FROM abc;
94     }
95     execsql COMMIT
96     expr ([file size test.db] / 1024) > 450
97   } {1}
99   set sig [signature]
100   db close
102   do_test crash6-3.$ii.2 {
103      crashsql -file test.db "
104        BEGIN;
105        SELECT random() FROM abc LIMIT $ii;
106        INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0;
107        DELETE FROM abc WHERE random()%2!=0;
108        COMMIT;
109      "
110   } {1 {child process exited abnormally}}
112   do_test crash6-3.$ii.3 {
113     sqlite3 db test.db
114     signature
115   } $sig
118 finish_test