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 #***********************************************************************
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
15 source $testdir/lock_common.tcl
16 source $testdir/malloc_common.tcl
18 if {[llength [info commands test_syscall]]==0} {
23 if {[test_syscall defaultvfs] != "unix"} {
27 set testprefix syscall
29 #-------------------------------------------------------------------------
30 # Tests for the xSetSystemCall method.
33 list [catch { test_syscall reset open } msg] $msg
36 list [catch { test_syscall reset nosuchcall } msg] $msg
39 list [catch { test_syscall reset open } msg] $msg
42 list [catch { test_syscall reset ""} msg] $msg
45 do_test 1.2 { test_syscall reset } {}
47 do_test 1.3.1 { test_syscall install {open getcwd access} } {}
48 do_test 1.3.2 { test_syscall reset } {}
50 #-------------------------------------------------------------------------
51 # Tests for the xGetSystemCall method.
53 do_test 2.1.1 { test_syscall exists open } 1
54 do_test 2.1.2 { test_syscall exists nosuchcall } 0
56 #-------------------------------------------------------------------------
57 # Tests for the xNextSystemCall method.
60 open close access getcwd stat fstat ftruncate
61 fcntl read pread write pwrite fchmod fallocate
62 pread64 pwrite64 unlink openDirectory
64 if {[test_syscall exists $s]} {lappend syscall_list $s}
66 do_test 3.1 { lsort [test_syscall list] } [lsort $syscall_list]
68 #-------------------------------------------------------------------------
69 # This test verifies that if a call to open() fails and errno is set to
70 # EINTR, the call is retried. If it succeeds, execution continues as if
76 CREATE TABLE t1(x, y);
77 INSERT INTO t1 VALUES(1, 2);
78 ATTACH 'test.db2' AS aux;
79 CREATE TABLE aux.t2(x, y);
80 INSERT INTO t2 VALUES(3, 4);
84 test_syscall install open
85 foreach jrnl [list wal delete] {
86 for {set i 1} {$i < 20} {incr i} {
88 test_syscall fault $i 0
89 test_syscall errno open EINTR
91 do_test 4.2.$jrnl.$i {
93 execsql { ATTACH 'test.db2' AS aux }
94 execsql "PRAGMA main.journal_mode = $jrnl"
95 execsql "PRAGMA aux.journal_mode = $jrnl"
98 INSERT INTO t1 VALUES(5, 6);
99 INSERT INTO t2 VALUES(7, 8);
105 execsql { ATTACH 'test.db2' AS aux }
114 #-------------------------------------------------------------------------
115 # This test verifies that closing database handles does not drop locks
116 # held by other database handles in the same process on the same file.
118 # The os_unix.c module has to take precautions to prevent this as the
119 # close() system call drops locks held by other file-descriptors on the
120 # same file. From the Linux man page:
122 # close() closes a file descriptor, so that it no longer refers to any file
123 # and may be reused. Any record locks (see fcntl(2)) held on the file it
124 # was associated with, and owned by the process, are removed (regardless
125 # of the file descriptor that was used to obtain the lock).
128 forcedelete test.db test.db2
130 do_multiclient_test tn {
136 do_test syscall-5.$tn.1 {
138 CREATE TABLE t1(a, b);
139 INSERT INTO t1 VALUES(1, 2);
141 INSERT INTO t1 VALUES(3, 4);
145 do_test syscall-5.$tn.2 { sql2 { SELECT * FROM t1 } } {1 2}
146 do_test syscall-5.$tn.3 {
147 csql2 { INSERT INTO t1 VALUES(5, 6) }
148 } {1 {database is locked}}
150 do_test syscall-5.$tn.4 {
157 do_test syscall-5.$tn.5 {
158 csql2 { INSERT INTO t1 VALUES(5, 6) }
159 } {1 {database is locked}}
161 do_test syscall-5.$tn.6 { sql1 { COMMIT } } {}
163 do_test syscall-5.$tn.7 {
164 csql2 { INSERT INTO t1 VALUES(5, 6) }
184 PRAGMA temp_store = file;
186 PRAGMA main.cache_size = 10;
187 PRAGMA temp.cache_size = 10;
188 CREATE TABLE temp.tt(a, b);
189 INSERT INTO tt VALUES(randomblob(500), randomblob(600));
190 INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt;
191 INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt;
192 INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt;
193 INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt;
194 INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt;
195 INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt;
196 INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt;
197 INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt;
203 #-------------------------------------------------------------------------
204 # Test that a database file a single byte in size is treated as an empty
205 # file. Whereas a file 2 bytes or larger might be considered corrupt.
208 forcedelete test.db test.db2
210 proc create_db_file {nByte} {
211 set fd [open test.db w]
212 fconfigure $fd -translation binary -encoding binary
213 puts -nonewline $fd [string range "xSQLite" 1 $nByte]
217 foreach {nByte res} {
219 2 {1 {file is encrypted or is not a database}}
220 3 {1 {file is encrypted or is not a database}}
223 create_db_file $nByte
226 execsql { CREATE TABLE t1(a, b) }
232 #-------------------------------------------------------------------------
235 forcedelete test.db test.db2
239 file_control_chunksize_test db main 4096
242 foreach {tn hint size} {
250 file_control_sizehint_test db main $hint
257 forcedelete test.db test.db2
259 file_control_chunksize_test db main 16
262 foreach {tn hint size} {
270 file_control_sizehint_test db main $hint