Fix compilation issues with the VFS stat extension.
[sqlite.git] / test / walcrash4.test
blobd2f07730a0d644640376819f13e75c755d7427ce
1 # 2010 May 25
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 #***********************************************************************
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
16 source $testdir/lock_common.tcl
17 source $testdir/wal_common.tcl
18 ifcapable !wal {finish_test ; return }
19 set testprefix walcrash4
21 #-------------------------------------------------------------------------
22 # At one point, if "PRAGMA synchronous=full" is set and the platform
23 # does not support POWERSAFE_OVERWRITE, and the last frame written to 
24 # the wal file in a transaction is aligned with a sector boundary, the
25 # xSync() call was omitted. 
27 # The following test verifies that this has been fixed.
29 do_execsql_test 1.0 {
30   PRAGMA autovacuum = 0;
31   PRAGMA page_size = 1024;
32   PRAGMA journal_mode = wal;
33   PRAGMA main.synchronous = full;
34 } {wal}
36 faultsim_save_and_close
38 for {set nExtra 0} {$nExtra < 10} {incr nExtra} {
39   for {set i 0} {$i < 10} {incr i} {
40     do_test 1.nExtra=$nExtra.i=$i.1 {
41       faultsim_restore_and_reopen
42     
43       set fd [open crash.tcl w]
44       puts $fd [subst -nocommands {
45         sqlite3_crash_enable 1
46         sqlite3_test_control_pending_byte $::sqlite_pending_byte
47         sqlite3 db test.db -vfs crash
48         db eval {
49           PRAGMA main.synchronous=FULL;
50           BEGIN;
51           CREATE TABLE t1(x UNIQUE);
52         }
53         for {set e 2} {[set e] < ($nExtra+2)} {incr e} {
54           db eval "CREATE TABLE t[set e] (x)"
55         }
56         db eval {
57           INSERT INTO t1 VALUES( randomblob(170000) );
58           COMMIT;
59         }
60         sqlite3_crash_now
61       }]
62       close $fd
63     
64       set r [catch { exec [info nameofexec] crash.tcl >@stdout } msg]
65       list $r $msg
66     } {1 {child process exited abnormally}}
67   
68     do_execsql_test 1.nExtra=$nExtra.i=$i.2 { 
69       SELECT count(*) FROM t1;
70       PRAGMA integrity_check;
71     } {1 ok}
72   } 
76 finish_test