Add tests for the invalid file handle detection logic in the winLock() function.

FossilOrigin-Name: ed5a9eb4f30a395bc641e79254217c7d7cf0aa5d
This commit is contained in:
mistachkin 2014-05-30 16:42:35 +00:00
parent 8e86b6a3df
commit 6b98d67b2b
6 changed files with 126 additions and 15 deletions

View File

@ -1,5 +1,5 @@
C Revise\slocking\sretry\ssemantics\sin\sWin32\sVFS\sto\sabort\searly\sif\sthe\sfile\shandle\sis\sreported\sas\sinvalid.
D 2014-05-28T03:27:42.937
C Add\stests\sfor\sthe\sinvalid\sfile\shandle\sdetection\slogic\sin\sthe\swinLock()\sfunction.
D 2014-05-30T16:42:35.024
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in dd2b1aba364ff9b05de41086f74407f285c57670
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -206,7 +206,7 @@ F src/os.h 60d419395e32a8029fa380a80a3da2e9030f635e
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa
F src/os_unix.c ae4b5240af4619d711301d7992396e182585269f
F src/os_win.c a5b9ed90eed522925135f1cc5f0e737a624a6b5c
F src/os_win.c 8dbf6c11780fe2eb96c1f289e664d0c7b2911d37
F src/os_win.h 057344a6720b4c8405d9bd98f58cb37a6ee46c25
F src/pager.c f6bb1fa6cdf2062f2d8aec3e64db302bca519ab8
F src/pager.h ffd5607f7b3e4590b415b007a4382f693334d428
@ -222,7 +222,7 @@ F src/resolve.c 273d5f47c4e2c05b2d3d2bffeda939551ab59e66
F src/rowset.c a9c9aae3234b44a6d7c6f5a3cadf90dce1e627be
F src/select.c 7df17ec5506c2427576d412bee0e6ea740e12563
F src/shell.c bfac06fb15f3cd0d447e2e72ab3a283fac301813
F src/sqlite.h.in 564fc23db33870b5096b20d72df7491ce0b8b74f
F src/sqlite.h.in a98eb3e8c86c934ea6f5bcfc6b69653dde2f4ed4
F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e
F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc
F src/sqliteInt.h fccdc735c27b3dc12322fec7cdad8bc76be8d00b
@ -230,7 +230,7 @@ F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
F src/tclsqlite.c e87c99e28a145943666b51b212dacae35fcea0bd
F src/test1.c 899bddeb0c7fb2b8062de6f03af4a4e4f48f9df5
F src/test1.c 4edf8810c86d77ae7ac6d56d563965a9beeea2ce
F src/test2.c 98049e51a17dc62606a99a9eb95ee477f9996712
F src/test3.c 1c0e5d6f080b8e33c1ce8b3078e7013fdbcd560c
F src/test4.c 9b32d22f5f150abe23c1830e2057c4037c45b3df
@ -1110,7 +1110,7 @@ F test/whereI.test 1d89199697919d4930be05a71e7fe620f114e622
F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31
F test/wild001.test bca33f499866f04c24510d74baf1e578d4e44b1c
F test/win32heap.test ea19770974795cff26e11575e12d422dbd16893c
F test/win32lock.test 7a6bd73a5dcdee39b5bb93e92395e1773a194361
F test/win32lock.test 31ac36515037a6244204d234aa117d88e1657acb
F test/win32longpath.test 169c75a3b2e43481f4a62122510210c67b08f26d
F test/with1.test 268081a6b14817a262ced4d0ee34d4d2a1dd2068
F test/with2.test ee227a663586aa09771cafd4fa269c5217eaf775
@ -1173,10 +1173,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P c405f971cf03e29110019ff863cbfb026d97e1e6
R 80dc0ba2eb26692fe89f4430050446dd
T *branch * winLockHandle
T *sym-winLockHandle *
T -sym-trunk *
P d43e2e59b5647655595fd953febf2beefa480006
R 8cf30fccc468f8f912423f19e0dc97b6
U mistachkin
Z 89844ed2f261cecaceceb182643fd2e9
Z eef6c127dd0b165b8d2b10d5b85e8cb6

View File

@ -1 +1 @@
d43e2e59b5647655595fd953febf2beefa480006
ed5a9eb4f30a395bc641e79254217c7d7cf0aa5d

View File

@ -3177,6 +3177,17 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){
OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
return SQLITE_OK;
}
#ifdef SQLITE_TEST
case SQLITE_FCNTL_WIN32_SET_HANDLE: {
LPHANDLE phFile = (LPHANDLE)pArg;
HANDLE hOldFile = pFile->h;
pFile->h = *phFile;
*phFile = hOldFile;
OSTRACE(("FCNTL oldFile=%p, newFile=%p, rc=SQLITE_OK\n",
hOldFile, pFile->h));
return SQLITE_OK;
}
#endif
case SQLITE_FCNTL_TEMPFILENAME: {
char *zTFile = 0;
int rc = winGetTempname(pFile->pVfs, &zTFile);

View File

@ -942,6 +942,12 @@ struct sqlite3_io_methods {
** on whether or not the file has been renamed, moved, or deleted since it
** was first opened.
**
** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
** opcode causes the xFileControl method to swap the file handle with the one
** pointed to by the pArg argument. This capability is used during testing
** and only needs to be supported when SQLITE_TEST is defined.
**
** </ul>
*/
#define SQLITE_FCNTL_LOCKSTATE 1
@ -965,6 +971,7 @@ struct sqlite3_io_methods {
#define SQLITE_FCNTL_HAS_MOVED 20
#define SQLITE_FCNTL_SYNC 21
#define SQLITE_FCNTL_COMMIT_PHASETWO 22
#define SQLITE_FCNTL_WIN32_SET_HANDLE 23
/*
** CAPI3REF: Mutex Handle

View File

@ -117,6 +117,16 @@ int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){
return TCL_OK;
}
#if SQLITE_OS_WIN
/*
** Decode a Win32 HANDLE object.
*/
int getWin32Handle(Tcl_Interp *interp, const char *zA, LPHANDLE phFile){
*phFile = (HANDLE)sqlite3TestTextToPtr(zA);
return TCL_OK;
}
#endif
extern const char *sqlite3ErrName(int);
#define t1ErrorName sqlite3ErrName
@ -5210,6 +5220,7 @@ static int file_control_lockproxy_test(
return TCL_OK;
}
#if SQLITE_OS_WIN
/*
** tclcmd: file_control_win32_av_retry DB NRETRY DELAY
**
@ -5243,6 +5254,42 @@ static int file_control_win32_av_retry(
return TCL_OK;
}
/*
** tclcmd: file_control_win32_set_handle DB HANDLE
**
** This TCL command runs the sqlite3_file_control interface with
** the SQLITE_FCNTL_WIN32_SET_HANDLE opcode.
*/
static int file_control_win32_set_handle(
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
int objc, /* Number of arguments */
Tcl_Obj *CONST objv[] /* Command arguments */
){
sqlite3 *db;
int rc;
HANDLE hFile = NULL;
char z[100];
if( objc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"",
Tcl_GetStringFromObj(objv[0], 0), " DB HANDLE", 0);
return TCL_ERROR;
}
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
return TCL_ERROR;
}
if( getWin32Handle(interp, Tcl_GetString(objv[2]), &hFile) ){
return TCL_ERROR;
}
rc = sqlite3_file_control(db, NULL, SQLITE_FCNTL_WIN32_SET_HANDLE,
(void*)&hFile);
sqlite3_snprintf(sizeof(z), z, "%d %p", rc, (void*)hFile);
Tcl_AppendResult(interp, z, (char*)0);
return TCL_OK;
}
#endif
/*
** tclcmd: file_control_persist_wal DB PERSIST-FLAG
**
@ -6472,7 +6519,10 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "file_control_lockproxy_test", file_control_lockproxy_test, 0 },
{ "file_control_chunksize_test", file_control_chunksize_test, 0 },
{ "file_control_sizehint_test", file_control_sizehint_test, 0 },
#if SQLITE_OS_WIN
{ "file_control_win32_av_retry", file_control_win32_av_retry, 0 },
{ "file_control_win32_set_handle", file_control_win32_set_handle, 0 },
#endif
{ "file_control_persist_wal", file_control_persist_wal, 0 },
{ "file_control_powersafe_overwrite",file_control_powersafe_overwrite,0},
{ "file_control_vfsname", file_control_vfsname, 0 },

View File

@ -128,6 +128,52 @@ while {1} {
file_control_win32_av_retry db 10 25
sqlite3_test_control_pending_byte $old_pending_byte
db close
forcedelete test.db
sqlite3 db test.db
sqlite3 db2 test.db
do_test win32lock-3.0 {
db eval {
CREATE TABLE t1(x);
INSERT INTO t1 VALUES(1);
INSERT INTO t1 VALUES(2);
INSERT INTO t1 VALUES(3);
}
} {}
do_test win32lock-3.1 {
db eval {
BEGIN EXCLUSIVE;
INSERT INTO t1 VALUES(4);
}
} {}
do_test win32lock-3.2 {
catchsql {
BEGIN EXCLUSIVE;
INSERT INTO t1 VALUES(5);
COMMIT;
} db2
} {1 {database is locked}}
do_test win32lock-3.3 {
db eval {
COMMIT;
}
} {}
do_test win32lock-3.4 {
set handle [lindex [file_control_win32_set_handle db 0] end]
list [catchsql {
BEGIN EXCLUSIVE;
INSERT INTO t1 VALUES(6);
COMMIT;
}] [file_control_win32_set_handle db $handle]
} {{1 {disk I/O error}} {0 0}}
db2 close
db close
sqlite3_shutdown
test_sqlite3_log
sqlite3_initialize