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.
18 if {$tcl_platform(platform)!="windows"} return
20 set testdir [file dirname $argv0]
21 source $testdir/tester.tcl
23 set testprefix win32lock
28 proc xLog {error_code msg} {
32 db eval {PRAGMA mmap_size=0}
34 do_test win32lock-1.1 {
38 INSERT INTO t1 VALUES(1,randomblob(100000));
39 INSERT INTO t1 VALUES(2,randomblob(50000));
40 INSERT INTO t1 VALUES(3,randomblob(25000));
41 INSERT INTO t1 VALUES(4,randomblob(12500));
42 SELECT x, length(y) FROM t1 ORDER BY rowid;
44 } {1 100000 2 50000 3 25000 4 12500}
46 unset -nocomplain delay1 rc msg
47 set old_pending_byte [sqlite3_test_control_pending_byte 0x40000000]
49 set win32_lock_ok [list]
50 set win32_lock_error [list]
53 lock_win32_file test.db 0 $::delay1
55 set rc [catch {db eval {SELECT x, length(y) FROM t1 ORDER BY rowid}} msg]
57 lappend win32_lock_error $::delay1
58 do_test win32lock-1.2-$delay1-error {
62 lappend win32_lock_ok $::delay1
63 do_test win32lock-1.2-$delay1-ok {
65 } {1 100000 2 50000 3 25000 4 12500}
66 if {[info exists ::log] && $::log!=""} {
67 do_test win32lock-1.2-$delay1-log1 {
68 regsub {\d+} $::log # x
69 regsub { at line \d+} $x "" x
71 } {{delayed #ms for lock/sharing conflict}}
74 if {[llength $win32_lock_ok] && [llength $win32_lock_error]} break
76 if {$delay1 > 12500} {
77 puts "Timed out waiting for \"ok\" and \"error\" results."
83 do_test win32lock-2.0 {
84 file_control_win32_av_retry db -1 -1
86 do_test win32lock-2.1 {
87 file_control_win32_av_retry db 1 1
91 # NOTE: It is known that the win32lock-2.2-* tests may fail if the system is
92 # experiencing heavy load (i.e. they are very timing sensitive). This is
93 # primarily due to the AV retry delay being set to 1 millisecond in the
94 # win32lock-2.1 test (above). While it is important to test this corner
95 # case for the AV retry logic, a failure of this test should probably not
96 # be interpreted as a bug in SQLite or these test cases.
98 set win32_lock_ok [list]
99 set win32_lock_error [list]
102 lock_win32_file test.db 0 $::delay1
104 set rc [catch {db eval {SELECT x, length(y) FROM t1 ORDER BY rowid}} msg]
106 lappend win32_lock_error $::delay1
107 do_test win32lock-2.2-$delay1-error {
111 lappend win32_lock_ok $::delay1
112 do_test win32lock-2.2-$delay1-ok {
114 } {1 100000 2 50000 3 25000 4 12500}
115 if {[info exists ::log] && $::log!=""} {
116 do_test win32lock-2.2-$delay1-log1 {
117 regsub {\d+} $::log # x
118 regsub { at line \d+} $x "" x
120 } {{delayed #ms for lock/sharing conflict}}
123 if {[llength $win32_lock_ok] && [llength $win32_lock_error]} break
126 puts "Timed out waiting for \"ok\" and \"error\" results."
132 file_control_win32_av_retry db 10 25
133 sqlite3_test_control_pending_byte $old_pending_byte
140 do_test win32lock-3.0 {
143 INSERT INTO t1 VALUES(1);
144 INSERT INTO t1 VALUES(2);
145 INSERT INTO t1 VALUES(3);
149 do_test win32lock-3.1 {
152 INSERT INTO t1 VALUES(4);
156 do_test win32lock-3.2 {
159 INSERT INTO t1 VALUES(5);
162 } {1 {database is locked}}
164 do_test win32lock-3.3 {
170 do_test win32lock-3.4 {
171 set handle [lindex [file_control_win32_set_handle db 0] end]
174 INSERT INTO t1 VALUES(6);
176 }] [file_control_win32_set_handle db $handle] [sqlite3_extended_errcode db]
177 } {{1 {disk I/O error}} {0 0} SQLITE_IOERR_LOCK}