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 mkdir rmdir
63 statvfs fchown umask mmap munmap mremap
66 if {[test_syscall exists $s]} {lappend syscall_list $s}
68 do_test 3.1 { lsort [test_syscall list] } [lsort $syscall_list]
70 #-------------------------------------------------------------------------
71 # This test verifies that if a call to open() fails and errno is set to
72 # EINTR, the call is retried. If it succeeds, execution continues as if
78 CREATE TABLE t1(x, y);
79 INSERT INTO t1 VALUES(1, 2);
80 ATTACH 'test.db2' AS aux;
81 CREATE TABLE aux.t2(x, y);
82 INSERT INTO t2 VALUES(3, 4);
86 test_syscall install open
87 foreach jrnl [list wal delete] {
88 for {set i 1} {$i < 20} {incr i} {
90 test_syscall fault $i 0
91 test_syscall errno open EINTR
93 do_test 4.2.$jrnl.$i {
95 execsql { ATTACH 'test.db2' AS aux }
96 execsql "PRAGMA main.journal_mode = $jrnl"
97 execsql "PRAGMA aux.journal_mode = $jrnl"
100 INSERT INTO t1 VALUES(5, 6);
101 INSERT INTO t2 VALUES(7, 8);
107 execsql { ATTACH 'test.db2' AS aux }
116 #-------------------------------------------------------------------------
117 # This test verifies that closing database handles does not drop locks
118 # held by other database handles in the same process on the same file.
120 # The os_unix.c module has to take precautions to prevent this as the
121 # close() system call drops locks held by other file-descriptors on the
122 # same file. From the Linux man page:
124 # close() closes a file descriptor, so that it no longer refers to any file
125 # and may be reused. Any record locks (see fcntl(2)) held on the file it
126 # was associated with, and owned by the process, are removed (regardless
127 # of the file descriptor that was used to obtain the lock).
130 forcedelete test.db test.db2
132 do_multiclient_test tn {
138 do_test syscall-5.$tn.1 {
140 CREATE TABLE t1(a, b);
141 INSERT INTO t1 VALUES(1, 2);
143 INSERT INTO t1 VALUES(3, 4);
147 do_test syscall-5.$tn.2 { sql2 { SELECT * FROM t1 } } {1 2}
148 do_test syscall-5.$tn.3 {
149 csql2 { INSERT INTO t1 VALUES(5, 6) }
150 } {1 {database is locked}}
152 do_test syscall-5.$tn.4 {
159 do_test syscall-5.$tn.5 {
160 csql2 { INSERT INTO t1 VALUES(5, 6) }
161 } {1 {database is locked}}
163 do_test syscall-5.$tn.6 { sql1 { COMMIT } } {}
165 do_test syscall-5.$tn.7 {
166 csql2 { INSERT INTO t1 VALUES(5, 6) }
186 PRAGMA temp_store = file;
188 PRAGMA main.cache_size = 10;
189 PRAGMA temp.cache_size = 10;
190 CREATE TABLE temp.tt(a, b);
191 INSERT INTO tt VALUES(randomblob(500), randomblob(600));
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;
198 INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt;
199 INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt;
205 #-------------------------------------------------------------------------
206 # Test that a database file a single byte in size is treated as an empty
207 # file. Whereas a file 2 bytes or larger might be considered corrupt.
210 forcedelete test.db test.db2
212 proc create_db_file {nByte} {
213 set fd [open test.db w]
214 fconfigure $fd -translation binary -encoding binary
215 puts -nonewline $fd [string range "xSQLite" 1 $nByte]
219 foreach {nByte res} {
221 2 {1 {file is encrypted or is not a database}}
222 3 {1 {file is encrypted or is not a database}}
225 create_db_file $nByte
228 execsql { CREATE TABLE t1(a, b) }
234 #-------------------------------------------------------------------------
237 forcedelete test.db test.db2
241 file_control_chunksize_test db main 4096
244 foreach {tn hint size} {
252 file_control_sizehint_test db main $hint
259 forcedelete test.db test.db2
261 file_control_chunksize_test db main 16
264 foreach {tn hint size} {
272 file_control_sizehint_test db main $hint