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 implements regression tests for SQLite library. The
12 # focus of this script is recovery from transient manditory locks
13 # that sometimes appear on database files due to anti-virus software.
16 if {$tcl_platform(platform)!="windows"} return
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
21 set testprefix win32lock
26 proc xLog {error_code msg} {
30 db eval {PRAGMA mmap_size=0}
32 do_test win32lock-1.1 {
36 INSERT INTO t1 VALUES(1,randomblob(100000));
37 INSERT INTO t1 VALUES(2,randomblob(50000));
38 INSERT INTO t1 VALUES(3,randomblob(25000));
39 INSERT INTO t1 VALUES(4,randomblob(12500));
40 SELECT x, length(y) FROM t1 ORDER BY rowid;
42 } {1 100000 2 50000 3 25000 4 12500}
44 unset -nocomplain delay1 rc msg
45 set old_pending_byte [sqlite3_test_control_pending_byte 0x40000000]
47 set win32_lock_ok [list]
48 set win32_lock_error [list]
51 lock_win32_file test.db 0 $::delay1
53 set rc [catch {db eval {SELECT x, length(y) FROM t1 ORDER BY rowid}} msg]
55 lappend win32_lock_error $::delay1
56 do_test win32lock-1.2-$delay1-error {
60 lappend win32_lock_ok $::delay1
61 do_test win32lock-1.2-$delay1-ok {
63 } {1 100000 2 50000 3 25000 4 12500}
64 if {[info exists ::log] && $::log!=""} {
65 do_test win32lock-1.2-$delay1-log1 {
66 regsub {\d+} $::log # x
67 regsub { at line \d+} $x "" x
69 } {{delayed #ms for lock/sharing conflict}}
72 if {[llength $win32_lock_ok] && [llength $win32_lock_error]} break
74 if {$delay1 > 12500} {
75 puts "Timed out waiting for \"ok\" and \"error\" results."
81 do_test win32lock-2.0 {
82 file_control_win32_av_retry db -1 -1
84 do_test win32lock-2.1 {
85 file_control_win32_av_retry db 1 1
89 # NOTE: It is known that the win32lock-2.2-* tests may fail if the system is
90 # experiencing heavy load (i.e. they are very timing sensitive). This is
91 # primarily due to the AV retry delay being set to 1 millisecond in the
92 # win32lock-2.1 test (above). While it is important to test this corner
93 # case for the AV retry logic, a failure of this test should probably not
94 # be interpreted as a bug in SQLite or these test cases.
96 set win32_lock_ok [list]
97 set win32_lock_error [list]
100 lock_win32_file test.db 0 $::delay1
102 set rc [catch {db eval {SELECT x, length(y) FROM t1 ORDER BY rowid}} msg]
104 lappend win32_lock_error $::delay1
105 do_test win32lock-2.2-$delay1-error {
109 lappend win32_lock_ok $::delay1
110 do_test win32lock-2.2-$delay1-ok {
112 } {1 100000 2 50000 3 25000 4 12500}
113 if {[info exists ::log] && $::log!=""} {
114 do_test win32lock-2.2-$delay1-log1 {
115 regsub {\d+} $::log # x
116 regsub { at line \d+} $x "" x
118 } {{delayed #ms for lock/sharing conflict}}
121 if {[llength $win32_lock_ok] && [llength $win32_lock_error]} break
124 puts "Timed out waiting for \"ok\" and \"error\" results."
130 file_control_win32_av_retry db 10 25
131 sqlite3_test_control_pending_byte $old_pending_byte
138 do_test win32lock-3.0 {
141 INSERT INTO t1 VALUES(1);
142 INSERT INTO t1 VALUES(2);
143 INSERT INTO t1 VALUES(3);
147 do_test win32lock-3.1 {
150 INSERT INTO t1 VALUES(4);
154 do_test win32lock-3.2 {
157 INSERT INTO t1 VALUES(5);
160 } {1 {database is locked}}
162 do_test win32lock-3.3 {
168 do_test win32lock-3.4 {
169 set handle [lindex [file_control_win32_set_handle db 0] end]
172 INSERT INTO t1 VALUES(6);
174 }] [file_control_win32_set_handle db $handle] [sqlite3_extended_errcode db]
175 } {{1 {disk I/O error}} {0 0} SQLITE_IOERR_LOCK}