From 5ef47bf002251c7e702065006f55d4901679e118 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 29 Mar 2011 18:28:35 +0000 Subject: [PATCH] Add tests to syscall.test and sysfault.test. FossilOrigin-Name: 3d2de011814002e2e25b7645f94ff8fc7aab9cdd --- manifest | 16 ++++----- manifest.uuid | 2 +- src/test_syscall.c | 4 ++- test/syscall.test | 90 +++++++++++++++++++++++++++++++++++++++++++++- test/sysfault.test | 36 +++++++++++++++---- 5 files changed, 130 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index e1497c5c61..1af4f54adf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\swhereby\sfollowing\san\sIO\serror\sin\sCommitPhaseTwo()\sof\sa\smulti-file\stransaction\sthe\sb-tree\slayer\scould\sbe\sleft\sin\sTRANS_WRITE\sstate,\scausing\sproblems\slater\son. -D 2011-03-29T15:40:55.407 +C Add\stests\sto\ssyscall.test\sand\ssysfault.test. +D 2011-03-29T18:28:35.749 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 27701a1653595a1f2187dc61c8117e00a6c1d50f F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -220,7 +220,7 @@ F src/test_schema.c 8c06ef9ddb240c7a0fcd31bc221a6a2aade58bf0 F src/test_server.c bbba05c144b5fc4b52ff650a4328027b3fa5fcc6 F src/test_stat.c f682704b5d1ba8e1d4e7e882a6d7922e2dcf066c F src/test_superlock.c 2b97936ca127d13962c3605dbc9a4ef269c424cd -F src/test_syscall.c bbdc88d0a5e42d0c35eaff8ae7ec86e8867f5543 +F src/test_syscall.c d12e8cd163cd33b66d0a3d1b8daaf136d09d65c2 F src/test_tclvar.c f4dc67d5f780707210d6bb0eb6016a431c04c7fa F src/test_thread.c bedd05cad673dba53326f3aa468cc803038896c0 F src/test_vfs.c 2ed8853c1e51ac6f9ea091f7ce4e0d618bba8b86 @@ -672,8 +672,8 @@ F test/subselect.test d24fd8757daf97dafd2e889c73ea4c4272dcf4e4 F test/substr.test 18f57c4ca8a598805c4d64e304c418734d843c1a F test/superlock.test 5d7a4954b0059c903f82c7b67867bc5451a7c082 F test/sync.test ded6b39d8d8ca3c0c5518516c6371b3316d3e3a3 -F test/syscall.test 5ae4b3d4f2aca2ef3c3a777f619e0c6b0cf592aa -F test/sysfault.test 359ea90a58788c867ac0f9cb52431f56ed975672 +F test/syscall.test 125d9781d914c408e8629053b5f914dc920ab3eb +F test/sysfault.test be42aa42f89a82305cf3807047d419595e430480 F test/table.test 04ba066432430657712d167ebf28080fe878d305 F test/tableapi.test 2674633fa95d80da917571ebdd759a14d9819126 F test/tclsqlite.test 8c154101e704170c2be10f137a5499ac2c6da8d3 @@ -919,7 +919,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P bc6cce81565b17f886478bd51500bba2ed11ec1d -R 4ba5c752b69008d11d64e0bac5b06138 +P dbe569a099c2855480e35c0cc4d9332821ad80da +R 3d53fb9ad6916c3f10485806a35396e6 U dan -Z d0374b5c64afa57baa2ab5bac0bd8f73 +Z cababf145f4f0436acd3441acb25d038 diff --git a/manifest.uuid b/manifest.uuid index e5596a7f20..fd74feecd2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dbe569a099c2855480e35c0cc4d9332821ad80da \ No newline at end of file +3d2de011814002e2e25b7645f94ff8fc7aab9cdd \ No newline at end of file diff --git a/src/test_syscall.c b/src/test_syscall.c index 0ecf6c4001..61508ec450 100644 --- a/src/test_syscall.c +++ b/src/test_syscall.c @@ -253,7 +253,7 @@ static int ts_stat(const char *zPath, struct stat *p){ ** A wrapper around fstat(). */ static int ts_fstat(int fd, struct stat *p){ - if( tsIsFail() ){ + if( tsIsFailErrno("fstat") ){ return -1; } return orig_fstat(fd, p); @@ -534,6 +534,8 @@ static int test_syscall_errno( { "EACCES", EACCES }, { "EINTR", EINTR }, { "EIO", EIO }, + { "EOVERFLOW", EOVERFLOW }, + { "ENOMEM", ENOMEM }, { 0, 0 } }; diff --git a/test/syscall.test b/test/syscall.test index 836e00dd86..610c529866 100644 --- a/test/syscall.test +++ b/test/syscall.test @@ -103,9 +103,97 @@ foreach jrnl [list wal delete] { } } {1 2 5 6 3 4 7 8} } - } +#------------------------------------------------------------------------- +# This test verifies that closing database handles does not drop locks +# held by other database handles in the same process on the same file. +# +# The os_unix.c module has to take precautions to prevent this as the +# close() system call drops locks held by other file-descriptors on the +# same file. From the Linux man page: +# +# close() closes a file descriptor, so that it no longer refers to any file +# and may be reused. Any record locks (see fcntl(2)) held on the file it +# was associated with, and owned by the process, are removed (regardless +# of the file descriptor that was used to obtain the lock). +# +catch { db close } +forcedelete test.db test.db2 + +do_multiclient_test tn { + code1 { + sqlite3 dbX1 test.db + sqlite3 dbX2 test.db + } + + do_test syscall-5.$tn.1 { + sql1 { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + BEGIN; + INSERT INTO t1 VALUES(3, 4); + } + } {} + + do_test syscall-5.$tn.2 { sql2 { SELECT * FROM t1 } } {1 2} + do_test syscall-5.$tn.3 { + csql2 { INSERT INTO t1 VALUES(5, 6) } + } {1 {database is locked}} + + do_test syscall-5.$tn.4 { + code1 { + dbX1 close + dbX2 close + } + } {} + + do_test syscall-5.$tn.5 { + csql2 { INSERT INTO t1 VALUES(5, 6) } + } {1 {database is locked}} + + do_test syscall-5.$tn.6 { sql1 { COMMIT } } {} + + do_test syscall-5.$tn.7 { + csql2 { INSERT INTO t1 VALUES(5, 6) } + } {0 {}} +} + +catch {db close} +do_test 6.1 { + sqlite3 db1 test.db1 + sqlite3 db2 test.db2 + sqlite3 db3 test.db3 + sqlite3 dbM "" + + db2 close + db3 close + dbM close + db1 close +} {} + +do_test 6.2 { + sqlite3 db test.db + execsql { + PRAGMA temp_store = file; + + PRAGMA main.cache_size = 10; + PRAGMA temp.cache_size = 10; + CREATE TABLE temp.tt(a, b); + INSERT INTO tt VALUES(randomblob(500), randomblob(600)); + INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt; + INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt; + INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt; + INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt; + INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt; + INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt; + INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt; + INSERT INTO tt SELECT randomblob(500), randomblob(600) FROM tt; + } + + db close +} {} + finish_test diff --git a/test/sysfault.test b/test/sysfault.test index 2e958642df..f6d1eabbc1 100644 --- a/test/sysfault.test +++ b/test/sysfault.test @@ -43,13 +43,8 @@ proc vfsfault_injectstop {} { test_syscall fault } faultsim_save_and_close -proc vfsfault_install {} { - test_syscall install {open getcwd} -} -do_faultsim_test 1 -faults vfsfault-* -prep { - faultsim_restore -} -body { +set open_and_write_body { sqlite3 db test.db db eval { CREATE TABLE t1(a, b); @@ -60,12 +55,36 @@ do_faultsim_test 1 -faults vfsfault-* -prep { CREATE TEMP TABLE t2(x); INSERT INTO t2 VALUES('y'); } -} -test { +} + +proc vfsfault_install {} { test_syscall install {open getcwd} } +do_faultsim_test 1 -faults vfsfault-* -prep { + faultsim_restore +} -body $open_and_write_body -test { faultsim_test_result {0 {wal 1 2 3 4}} \ {1 {unable to open database file}} \ {1 {attempt to write a readonly database}} } +# Errors in the fstat() function when opening and writing a file. +# +foreach {tn errno errlist} { + 1 ENOMEM {{disk I/O error}} + 2 EOVERFLOW {{disk I/O error} {large file support is disabled}} +} { + proc vfsfault_install {} { test_syscall install fstat } + set errs [list] + foreach e $errlist { lappend errs [list 1 $e] } + do_faultsim_test 1.2.$tn -faults vfsfault-* -prep { + faultsim_restore + } -body " + test_syscall errno fstat $errno + $open_and_write_body + " -test " + faultsim_test_result {0 {wal 1 2 3 4}} $errs + " +} + #------------------------------------------------------------------------- # Check that a single EINTR error does not affect processing. # @@ -139,6 +158,9 @@ do_faultsim_test 2.2 -faults vfsfault-* -prep { {1 {disk I/O error}} } +#------------------------------------------------------------------------- +# + finish_test