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 #***********************************************************************
12 # This file contains tests for the "unix-excl" VFS module (part of
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 source $testdir/lock_common.tcl
19 source $testdir/malloc_common.tcl
21 if {$::tcl_platform(platform)!="unix" || [info commands test_syscall]==""} {
25 set testprefix unixexcl
29 # Test that when using VFS "unix-excl", the first time the database is read
30 # a process-wide exclusive lock is taken on it. This means other connections
31 # within the process may still access the db normally, but connections from
32 # outside the process cannot.
34 do_multiclient_test tn {
35 do_test unixexcl-1.$tn.1 {
37 CREATE TABLE t1(a, b);
38 INSERT INTO t1 VALUES('hello', 'world');
41 do_test unixexcl-1.$tn.2 { sql2 { SELECT * FROM t1 } } {hello world}
42 do_test unixexcl-1.$tn.3 {
45 sqlite3 db test.db -vfs unix-excl
46 db eval { SELECT * FROM t1 }
50 do_test unixexcl-1.$tn.4.multiproc {
51 csql2 { SELECT * FROM t1 }
52 } {1 {database is locked}}
54 do_test unixexcl-1.$tn.4.singleproc {
55 csql2 { SELECT * FROM t1 }
60 # Test that when using VFS "unix-excl", if a file is opened in read-only mode
61 # the behaviour is the same as if VFS "unix" were used.
63 do_multiclient_test tn {
64 do_test unixexcl-2.$tn.1 {
66 CREATE TABLE t1(a, b);
67 INSERT INTO t1 VALUES('hello', 'world');
70 do_test unixexcl-2.$tn.2 { sql2 { SELECT * FROM t1 } } {hello world}
71 do_test unixexcl-2.$tn.3 {
74 sqlite3 db test.db -readonly yes -vfs unix-excl
75 db eval { SELECT * FROM t1 }
78 do_test unixexcl-2.$tn.4 {
79 csql2 { SELECT * FROM t1 }