xref: /sqlite-3.40.0/test/walcrash4.test (revision dfe4e6bb)
1# 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
20do_not_use_codec
21
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
39# 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
47for {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 {
58          PRAGMA main.synchronous=FULL;
59          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
75    } "1 {$msg}"
76
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
86