Copy some extra test infrastructure from the mutexfree-shmlock branch to trunk.

FossilOrigin-Name: 883337ffdb434b6856ceaada121c0be67e2fdec7b447675f45e85568ef28d7d9
This commit is contained in:
dan 2018-12-24 15:22:47 +00:00
parent 29e9af8848
commit 94e95ea46e
6 changed files with 289 additions and 57 deletions

View File

@ -1,5 +1,5 @@
C Change\sthe\sway\sa\scomparison\sused\sto\sdetect\scorrupt\sdatabases\sin\sfts3\sis\sdone\nto\savoid\spotential\spointer\soverflow\sin\s32-bit\sbuilds.
D 2018-12-24T13:34:36.984
C Copy\ssome\sextra\stest\sinfrastructure\sfrom\sthe\smutexfree-shmlock\sbranch\sto\strunk.
D 2018-12-24T15:22:47.398
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in d8b254f8bb81bab43c340d70d17dc3babab40fcc8a348c8255881f780a45fee6
@ -566,7 +566,7 @@ F src/test_syscall.c 1073306ba2e9bfc886771871a13d3de281ed3939
F src/test_tclsh.c 06317648b0d85a85fd823f7973b55535c59a3156c1ef59394fe511f932cfa78d
F src/test_tclvar.c 33ff42149494a39c5fbb0df3d25d6fafb2f668888e41c0688d07273dcb268dfc
F src/test_thread.c 911d15fb14e19c0c542bdc8aabf981c2f10a4858
F src/test_vfs.c 4e31a7b98a401431c55590a0ac05f001f520f716d0707ec916b4022b8937fd06
F src/test_vfs.c 9a53b40290db75833db58295485b955276daed99a2e57d7215719e175c0cfae0
F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698
F src/test_windirent.c a895e2c068a06644eef91a7f0a32182445a893b9a0f33d0cdb4283dca2486ac1
F src/test_windirent.h 90dfbe95442c9762357fe128dc7ae3dc199d006de93eb33ba3972e0a90484215
@ -1084,7 +1084,7 @@ F test/lock4.test 27143363eda1622f03c133efc8db808fc331afd973486cb571ea71cd717d37
F test/lock5.test c6c5e0ebcb21c61a572870cc86c0cb9f14cede38
F test/lock6.test ad5b387a3a8096afd3c68a55b9535056431b0cf5
F test/lock7.test 49f1eaff1cdc491cc5dee3669f3c671d9f172431
F test/lock_common.tcl 7ffb45accf6ee91c736df9bafe0806a44358f035
F test/lock_common.tcl 2f3f7f2e9637f93ccf609df48ef5b27a50278b6b1cd752b445d52262e5841413
F test/lookaside.test 5a828e7256f1ee4da8e1bdaa03373a3ccdb0f1ff98dfa82e9b76cb41a45b1083
F test/main.test 6bbb3999fd461eb8fb335cbab97409a3d7f91bbb8da60635e8be3e4a04a77772
F test/make-where7.tcl 05c16b5d4f5d6512881dfec560cb793915932ef9
@ -1291,6 +1291,7 @@ F test/shell5.test 23939a4c51f0421330ea61dbd3c74f9c215f5f8d3d1a94846da6ffc777a35
F test/shell6.test 1ceb51b2678c472ba6cf1e5da96679ce8347889fe2c3bf93a0e0fa73f00b00d3
F test/shell7.test 115132f66d0463417f408562cc2cf534f6bbc6d83a6d50f0072a9eb171bae97f
F test/shell8.test 96be02ea0c21f05b24c1883d7b711a1fa8525a68ab7b636aacf6057876941013
F test/shmlock.test 3d1868f0386923c0592a235f2dd87ae52286b217bc695fbfd9d39a828e7be374
F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
F test/show_speedtest1_rtree.tcl 32e6c5f073d7426148a6936a0408f4b5b169aba5
F test/shrink.test 1b4330b1fd9e818c04726d45cb28db73087535ce
@ -1599,7 +1600,7 @@ F test/vtabJ.test d7b73675708cf63cfcb9d443bb451fc01a028347275b7311e51f9fdf3ca675
F test/vtab_alter.test 736e66fb5ec7b4fee58229aa3ada2f27ec58bc58c00edae4836890c3784c6783
F test/vtab_err.test dcc8b7b9cb67522b3fe7a272c73856829dae4ab7fdb30399aea1b6981bda2b65
F test/vtab_shared.test 5253bff2355a9a3f014c15337da7e177ab0ef8ad
F test/wal.test 613efec03e517e1775d86b993a54877d2e29a477
F test/wal.test cdf0ca6cc0447520d19ef1c83287824ebeb3e82d75af856511ba96841a79fc9b
F test/wal2.test 155b9efa999bdb38ce1cd729b9a4fcdbffd6b88be27f039bad1d2929d287d918
F test/wal3.test 2a93004bc0fb2b5c29888964024695bade278ab2
F test/wal4.test 4744e155cd6299c6bd99d3eab1c82f77db9cdb3c
@ -1792,7 +1793,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 2b6494b1509f0d0189f98aa34c990eee99c775ff57826e79b2c5b0a12b4c97ad
R a02ab00644ca16cf9661dd1e6ee9ef5e
P 95a9a39ff784b960b62dd6298e722a620ba3f9c8b76839a49bbef35d7bc84a8e
R 28c998f6164dc0f7405ec208c028201d
U dan
Z a6822b20c230c488499f3dd180c02a24
Z 8b99907344be3f4f9e4d165ba038528b

View File

@ -1 +1 @@
95a9a39ff784b960b62dd6298e722a620ba3f9c8b76839a49bbef35d7bc84a8e
883337ffdb434b6856ceaada121c0be67e2fdec7b447675f45e85568ef28d7d9

View File

@ -1564,8 +1564,62 @@ static int SQLITE_TCLAPI testvfs_cmd(
return TCL_ERROR;
}
extern int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb);
extern const char *sqlite3ErrName(int);
/*
** tclcmd: vfs_shmlock DB DBNAME (shared|exclusive) (lock|unlock) OFFSET N
*/
static int SQLITE_TCLAPI test_vfs_shmlock(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
const char *azArg1[] = {"shared", "exclusive", 0};
const char *azArg2[] = {"lock", "unlock", 0};
sqlite3 *db = 0;
int rc = SQLITE_OK;
const char *zDbname = 0;
int iArg1 = 0;
int iArg2 = 0;
int iOffset = 0;
int n = 0;
sqlite3_file *pFd;
if( objc!=7 ){
Tcl_WrongNumArgs(interp, 1, objv,
"DB DBNAME (shared|exclusive) (lock|unlock) OFFSET N"
);
return TCL_ERROR;
}
zDbname = Tcl_GetString(objv[2]);
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db)
|| Tcl_GetIndexFromObj(interp, objv[3], azArg1, "ARG", 0, &iArg1)
|| Tcl_GetIndexFromObj(interp, objv[4], azArg2, "ARG", 0, &iArg2)
|| Tcl_GetIntFromObj(interp, objv[5], &iOffset)
|| Tcl_GetIntFromObj(interp, objv[6], &n)
){
return TCL_ERROR;
}
sqlite3_file_control(db, zDbname, SQLITE_FCNTL_FILE_POINTER, (void*)&pFd);
if( pFd==0 ){
return TCL_ERROR;
}
rc = pFd->pMethods->xShmLock(pFd, iOffset, n,
(iArg1==0 ? SQLITE_SHM_SHARED : SQLITE_SHM_EXCLUSIVE)
| (iArg2==0 ? SQLITE_SHM_LOCK : SQLITE_SHM_UNLOCK)
);
Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
return TCL_OK;
}
int Sqlitetestvfs_Init(Tcl_Interp *interp){
Tcl_CreateObjCommand(interp, "testvfs", testvfs_cmd, 0, 0);
Tcl_CreateObjCommand(interp, "vfs_shmlock", test_vfs_shmlock, 0, 0);
return TCL_OK;
}

View File

@ -15,18 +15,20 @@
proc do_multiclient_test {varname script} {
foreach code [list {
foreach {tn code} [list 1 {
if {[info exists ::G(valgrind)]} { db close ; continue }
set ::code2_chan [launch_testfixture]
set ::code3_chan [launch_testfixture]
proc code2 {tcl} { testfixture $::code2_chan $tcl }
proc code3 {tcl} { testfixture $::code3_chan $tcl }
set tn 1
} {
} 2 {
proc code2 {tcl} { uplevel #0 $tcl }
proc code3 {tcl} { uplevel #0 $tcl }
set tn 2
}] {
# Do not run multi-process tests with the unix-excl VFS.
#
if {$tn==1 && [permutation]=="unix-excl"} continue
faultsim_delete_and_reopen
proc code1 {tcl} { uplevel #0 $tcl }

173
test/shmlock.test Normal file
View File

@ -0,0 +1,173 @@
# 2018 December 6
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix shmlock
ifcapable !wal {finish_test ; return }
sqlite3 db2 test.db
sqlite3 db3 test.db
do_execsql_test 1.0 {
PRAGMA journal_mode = wal;
CREATE TABLE t1(a, b);
INSERT INTO t1 VALUES(1, 2);
} {wal}
do_test 1.1 { execsql { SELECT * FROM t1 } db2 } {1 2}
do_test 1.2 { execsql { SELECT * FROM t1 } db3 } {1 2}
foreach {tn dbhandle cmd res} {
1 db {shared lock 7 1} OK
2 db2 {exclusive lock 7 1} BUSY
3 db {shared unlock 7 1} OK
4 db2 {exclusive lock 7 1} OK
5 db {shared lock 7 1} BUSY
6 db {exclusive lock 7 1} BUSY
7 db2 {exclusive unlock 7 1} OK
8 db {exclusive lock 0 8} OK
9 db {exclusive unlock 0 8} OK
10 db2 {exclusive lock 0 8} OK
11 db2 {exclusive unlock 0 8} OK
12 db {shared lock 0 1} OK
13 db2 {shared lock 0 1} OK
14 db3 {shared lock 0 1} OK
15 db3 {shared unlock 0 1} OK
16 db3 {exclusive lock 0 1} BUSY
17 db2 {shared unlock 0 1} OK
18 db3 {exclusive lock 0 1} BUSY
19 db {shared unlock 0 1} OK
20 db3 {exclusive lock 0 1} OK
21 db3 {exclusive unlock 0 1} OK
22 db {shared lock 3 1} OK
23 db2 {exclusive lock 2 2} BUSY
24 db {shared lock 2 1} OK
25 db2 {exclusive lock 0 5} BUSY
26 db2 {exclusive lock 0 4} BUSY
27 db2 {exclusive lock 0 3} BUSY
28 db {shared unlock 3 1} OK
29 db2 {exclusive lock 2 2} BUSY
28 db {shared unlock 2 1} OK
29 db2 {exclusive lock 2 2} OK
29 db2 {exclusive unlock 2 2} OK
} {
do_test 1.3.$tn [list vfs_shmlock $dbhandle main {*}$cmd] "SQLITE_$res"
}
db close
db2 close
db3 close
if {[permutation]=="unix-excl"} {
do_test 2.0 {
for {set i 0} {$i < 256} {incr i} {
sqlite3 db$i test.db
execsql { SELECT * FROM t1 } db$i
}
for {set i 0} {$i < 255} {incr i} {
set rc [vfs_shmlock db$i main shared lock 4 1]
if {$rc != "SQLITE_OK"} { error $rc }
}
vfs_shmlock db255 main shared lock 4 1
} {SQLITE_BUSY}
do_test 2.1 { vfs_shmlock db255 main exclusive lock 4 1 } SQLITE_BUSY
do_test 2.2 { vfs_shmlock db0 main shared unlock 4 1 } SQLITE_OK
do_test 2.3 { vfs_shmlock db255 main shared lock 4 1 } SQLITE_OK
do_test 2.4 { vfs_shmlock db255 main shared unlock 4 1 } SQLITE_OK
do_test 2.5 { vfs_shmlock db255 main exclusive lock 4 1 } SQLITE_BUSY
do_test 2.6 {
for {set i 1} {$i < 255} {incr i} {
set rc [vfs_shmlock db255 main exclusive lock 4 1]
if {$rc != "SQLITE_BUSY"} { error $rc }
set rc [vfs_shmlock db$i main shared unlock 4 1]
if {$rc != "SQLITE_OK"} { error $rc }
}
vfs_shmlock db255 main exclusive lock 4 1
} {SQLITE_OK}
vfs_shmlock db255 main exclusive unlock 4 1
for {set i 0} {$i < 256} {incr i} {
db$i close
}
}
sqlite3 db0 test.db
sqlite3 db1 test.db
do_test 3.1 { execsql { SELECT * FROM t1 } db0 } {1 2}
do_test 3.2 { execsql { SELECT * FROM t1 } db1 } {1 2}
set L(0) {n n n n n n n n}
set L(1) {n n n n n n n n}
proc random_lock_test {idx} {
global L
set iSlot [expr int(rand()*8)]
if {[expr int(rand()*2)]} {
# Unlock operation
if {[lindex $L($idx) $iSlot]!="n"} {
vfs_shmlock db$idx main [lindex $L($idx) $iSlot] unlock $iSlot 1
lset L($idx) $iSlot n
}
} else {
# Lock operation
if {[lindex $L($idx) $iSlot]=="n"} {
set locktype [lindex {e s} [expr int(rand()*2)]]
set n 1
if {$locktype=="e"} {
for {set l $iSlot} {$l<8 && [lindex $L($idx) $l]=="n"} {incr l} {}
set n [expr int(rand()*($l-$iSlot))+1]
# puts "iSlot=$iSlot l=$l L=$L($idx)"
# puts "$iSlot $n"
}
set res [vfs_shmlock db$idx main $locktype lock $iSlot $n]
set bBusy 0
for {set i $iSlot} {$i<($iSlot+$n)} {incr i} {
set other [lindex $L([expr ($idx+1)%2]) $i]
if {($other!="n" && $locktype=="e")||($other=="e" && $locktype=="s")} {
if {$res != "SQLITE_BUSY"} { error "BUSY not detected" }
set bBusy 1
break
}
}
if {$bBusy==0} {
if {$res != "SQLITE_OK"} { error "BUSY false-positive" }
for {set i $iSlot} {$i<($iSlot+$n)} {incr i} {
lset L($idx) $i $locktype
}
}
}
}
}
set nStep 100000
for {set i 0} {$i < $nStep} {incr i} {
random_lock_test 0
random_lock_test 1
}
db0 close
db1 close
finish_test

View File

@ -1297,51 +1297,53 @@ do_test wal-19.4 {
# At one point, SQLite was failing to grow the mapping of the wal-index
# file in step 3 and the checkpoint was corrupting the database file.
#
do_test wal-20.1 {
catch {db close}
forcedelete test.db test.db-wal test.db-journal
sqlite3 db test.db
execsql {
PRAGMA journal_mode = WAL;
CREATE TABLE t1(x);
INSERT INTO t1 VALUES(randomblob(900));
SELECT count(*) FROM t1;
}
} {wal 1}
do_test wal-20.2 {
set ::buddy [launch_testfixture]
testfixture $::buddy {
if {[permutation]!="unix-excl"} {
do_test wal-20.1 {
catch {db close}
forcedelete test.db test.db-wal test.db-journal
sqlite3 db test.db
db transaction { db eval {
PRAGMA wal_autocheckpoint = 0;
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 2 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 4 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 8 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 16 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 32 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 64 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 128 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 256 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 512 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 1024 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 2048 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 4096 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 8192 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 16384 */
} }
}
} {0}
do_test wal-20.3 {
close $::buddy
execsql { PRAGMA wal_checkpoint }
execsql { SELECT count(*) FROM t1 }
} {16384}
do_test wal-20.4 {
db close
sqlite3 db test.db
execsql { SELECT count(*) FROM t1 }
} {16384}
integrity_check wal-20.5
execsql {
PRAGMA journal_mode = WAL;
CREATE TABLE t1(x);
INSERT INTO t1 VALUES(randomblob(900));
SELECT count(*) FROM t1;
}
} {wal 1}
do_test wal-20.2 {
set ::buddy [launch_testfixture]
testfixture $::buddy {
sqlite3 db test.db
db transaction { db eval {
PRAGMA wal_autocheckpoint = 0;
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 2 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 4 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 8 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 16 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 32 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 64 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 128 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 256 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 512 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 1024 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 2048 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 4096 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 8192 */
INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 16384 */
} }
}
} {0}
do_test wal-20.3 {
close $::buddy
execsql { PRAGMA wal_checkpoint }
execsql { SELECT count(*) FROM t1 }
} {16384}
do_test wal-20.4 {
db close
sqlite3 db test.db
execsql { SELECT count(*) FROM t1 }
} {16384}
integrity_check wal-20.5
}
catch { db2 close }
catch { db close }