danielk1977 | 67c007b | 2008-03-20 04:45:49 +0000 | [diff] [blame] | 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 tests that rollback journals for databases that use a |
| 12 | # page-size other than the default page-size can be rolled back Ok. |
| 13 | # |
drh | 1c9f50a | 2008-04-14 15:27:19 +0000 | [diff] [blame] | 14 | # $Id: crash6.test,v 1.2 2008/04/14 15:27:19 drh Exp $ |
danielk1977 | 67c007b | 2008-03-20 04:45:49 +0000 | [diff] [blame] | 15 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
| 18 | |
| 19 | ifcapable !crashtest { |
| 20 | finish_test |
| 21 | return |
| 22 | } |
| 23 | |
| 24 | for {set ii 0} {$ii < 10} {incr ii} { |
| 25 | catch {db close} |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 26 | forcedelete test.db test.db-journal |
danielk1977 | 67c007b | 2008-03-20 04:45:49 +0000 | [diff] [blame] | 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 |
| 39 | } |
| 40 | |
| 41 | for {set ii 0} {$ii < 10} {incr ii} { |
| 42 | catch {db close} |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 43 | forcedelete test.db test.db-journal |
danielk1977 | 67c007b | 2008-03-20 04:45:49 +0000 | [diff] [blame] | 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 |
| 58 | } |
| 59 | |
| 60 | proc signature {} { |
| 61 | return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}] |
| 62 | } |
| 63 | |
| 64 | # Test case for crashing during database sync with page-size values |
| 65 | # from 1024 to 8192. |
| 66 | # |
| 67 | for {set ii 0} {$ii < 30} {incr ii} { |
| 68 | db close |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 69 | forcedelete test.db |
danielk1977 | 67c007b | 2008-03-20 04:45:49 +0000 | [diff] [blame] | 70 | sqlite3 db test.db |
| 71 | |
| 72 | set pagesize [expr 1024 << ($ii % 4)] |
drh | 1c9f50a | 2008-04-14 15:27:19 +0000 | [diff] [blame] | 73 | if {$pagesize>$::SQLITE_MAX_PAGE_SIZE} { |
| 74 | set pagesize $::SQLITE_MAX_PAGE_SIZE |
| 75 | } |
danielk1977 | 67c007b | 2008-03-20 04:45:49 +0000 | [diff] [blame] | 76 | do_test crash6-3.$ii.0 { |
| 77 | execsql "pragma page_size = $pagesize" |
| 78 | execsql "pragma page_size" |
| 79 | } $pagesize |
| 80 | |
| 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} |
| 98 | |
| 99 | set sig [signature] |
| 100 | db close |
| 101 | |
| 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}} |
| 111 | |
| 112 | do_test crash6-3.$ii.3 { |
| 113 | sqlite3 db test.db |
| 114 | signature |
| 115 | } $sig |
| 116 | } |
| 117 | |
| 118 | finish_test |