blob: 80839b39e59f20f8830147f6d328942661bdbbbd [file] [log] [blame]
danfe912512016-05-24 16:20:51 +00001# 2010 May 25
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#
12
13
14set testdir [file dirname $argv0]
15source $testdir/tester.tcl
16source $testdir/lock_common.tcl
17source $testdir/wal_common.tcl
18ifcapable !wal {finish_test ; return }
19set testprefix walcrash4
drh422dded2016-07-25 16:10:43 +000020do_not_use_codec
danfe912512016-05-24 16:20:51 +000021
22#-------------------------------------------------------------------------
23# At one point, if "PRAGMA synchronous=full" is set and the platform
24# does not support POWERSAFE_OVERWRITE, and the last frame written to
25# the wal file in a transaction is aligned with a sector boundary, the
26# xSync() call was omitted.
27#
28# The following test verifies that this has been fixed.
29#
30do_execsql_test 1.0 {
31 PRAGMA autovacuum = 0;
32 PRAGMA page_size = 1024;
33 PRAGMA journal_mode = wal;
34 PRAGMA main.synchronous = full;
35} {wal}
36
37faultsim_save_and_close
38
drha83a5c32016-06-07 20:25:19 +000039# The error message is different on unix and windows
40#
41if {$::tcl_platform(platform)=="windows"} {
42 set msg "child killed: unknown signal"
43} else {
44 set msg "child process exited abnormally"
45}
46
danfe912512016-05-24 16:20:51 +000047for {set nExtra 0} {$nExtra < 10} {incr nExtra} {
48 for {set i 0} {$i < 10} {incr i} {
49 do_test 1.nExtra=$nExtra.i=$i.1 {
50 faultsim_restore_and_reopen
51
52 set fd [open crash.tcl w]
53 puts $fd [subst -nocommands {
54 sqlite3_crash_enable 1
55 sqlite3_test_control_pending_byte $::sqlite_pending_byte
56 sqlite3 db test.db -vfs crash
57 db eval {
drhf34a25a2016-05-24 18:50:41 +000058 PRAGMA main.synchronous=FULL;
danfe912512016-05-24 16:20:51 +000059 BEGIN;
60 CREATE TABLE t1(x UNIQUE);
61 }
62 for {set e 2} {[set e] < ($nExtra+2)} {incr e} {
63 db eval "CREATE TABLE t[set e] (x)"
64 }
65 db eval {
66 INSERT INTO t1 VALUES( randomblob(170000) );
67 COMMIT;
68 }
69 sqlite3_crash_now
70 }]
71 close $fd
72
73 set r [catch { exec [info nameofexec] crash.tcl >@stdout } msg]
74 list $r $msg
drha83a5c32016-06-07 20:25:19 +000075 } "1 {$msg}"
danfe912512016-05-24 16:20:51 +000076
77 do_execsql_test 1.nExtra=$nExtra.i=$i.2 {
78 SELECT count(*) FROM t1;
79 PRAGMA integrity_check;
80 } {1 ok}
81 }
82}
83
84
85finish_test