diff options
author | drh <drh@noemail.net> | 2008-07-08 02:12:37 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2008-07-08 02:12:37 +0000 |
commit | c8d75674d6dff8ade0e423a6a56888394bb6fddb (patch) | |
tree | 07bfebd30752692d0e44b1cd6533dc33adec921f /src | |
parent | fb45d8c563db372c9a9cf67c5a58d2e3bf67152a (diff) | |
download | sqlite-c8d75674d6dff8ade0e423a6a56888394bb6fddb.tar.gz sqlite-c8d75674d6dff8ade0e423a6a56888394bb6fddb.zip |
Add tests to verify correct behavior when mutex initialization fails. (CVS 5359)
FossilOrigin-Name: 65875005ac8bc7988d7d7d8e8b999857449568fd
Diffstat (limited to 'src')
-rw-r--r-- | src/test1.c | 26 | ||||
-rw-r--r-- | src/test_autoext.c | 11 | ||||
-rw-r--r-- | src/test_mutex.c | 27 |
3 files changed, 55 insertions, 9 deletions
diff --git a/src/test1.c b/src/test1.c index 1baa8073f..2b98179fe 100644 --- a/src/test1.c +++ b/src/test1.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test1.c,v 1.311 2008/07/07 17:53:08 drh Exp $ +** $Id: test1.c,v 1.312 2008/07/08 02:12:37 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -4426,6 +4426,29 @@ static int vfs_unlink_test( } /* +** tclcmd: vfs_initfail_test +** +** This TCL command attempts to vfs_find and vfs_register when the +** sqlite3_initialize() interface is failing. All calls should fail. +*/ +static int vfs_initfail_test( + 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_vfs one; + one.zName = "__one"; + + if( sqlite3_vfs_find(0) ) return TCL_ERROR; + sqlite3_vfs_register(&one, 0); + if( sqlite3_vfs_find(0) ) return TCL_ERROR; + sqlite3_vfs_register(&one, 1); + if( sqlite3_vfs_find(0) ) return TCL_ERROR; + return TCL_OK; +} + +/* ** Saved VFSes */ static sqlite3_vfs *apVfs[20]; @@ -4778,6 +4801,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ { "sqlite3_global_recover", test_global_recover, 0 }, { "working_64bit_int", working_64bit_int, 0 }, { "vfs_unlink_test", vfs_unlink_test, 0 }, + { "vfs_initfail_test", vfs_initfail_test, 0 }, { "vfs_unregister_all", vfs_unregister_all, 0 }, { "vfs_reregister_all", vfs_reregister_all, 0 }, { "file_control_test", file_control_test, 0 }, diff --git a/src/test_autoext.c b/src/test_autoext.c index 6c5b98370..11f541360 100644 --- a/src/test_autoext.c +++ b/src/test_autoext.c @@ -11,7 +11,7 @@ ************************************************************************* ** Test extension for testing the sqlite3_auto_extension() function. ** -** $Id: test_autoext.c,v 1.4 2008/03/19 23:52:35 mlcreech Exp $ +** $Id: test_autoext.c,v 1.5 2008/07/08 02:12:37 drh Exp $ */ #include "tcl.h" #include "sqlite3ext.h" @@ -95,7 +95,8 @@ static int autoExtSqrObjCmd( int objc, Tcl_Obj *CONST objv[] ){ - sqlite3_auto_extension((void*)sqr_init); + int rc = sqlite3_auto_extension((void*)sqr_init); + Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); return SQLITE_OK; } @@ -110,7 +111,8 @@ static int autoExtCubeObjCmd( int objc, Tcl_Obj *CONST objv[] ){ - sqlite3_auto_extension((void*)cube_init); + int rc = sqlite3_auto_extension((void*)cube_init); + Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); return SQLITE_OK; } @@ -125,7 +127,8 @@ static int autoExtBrokenObjCmd( int objc, Tcl_Obj *CONST objv[] ){ - sqlite3_auto_extension((void*)broken_init); + int rc = sqlite3_auto_extension((void*)broken_init); + Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); return SQLITE_OK; } diff --git a/src/test_mutex.c b/src/test_mutex.c index c2df5563a..817de93ac 100644 --- a/src/test_mutex.c +++ b/src/test_mutex.c @@ -10,7 +10,7 @@ ** ************************************************************************* ** -** $Id: test_mutex.c,v 1.5 2008/07/08 00:06:50 drh Exp $ +** $Id: test_mutex.c,v 1.6 2008/07/08 02:12:37 drh Exp $ */ #include "tcl.h" @@ -65,7 +65,6 @@ static int counterMutexInit(void){ ** Uninitialize the mutex subsystem */ static int counterMutexEnd(void){ - assert( g.isInit ); g.isInit = 0; return g.m.xMutexEnd(); } @@ -83,7 +82,7 @@ static sqlite3_mutex *counterMutexAlloc(int eType){ pReal = g.m.xMutexAlloc(eType); if( !pReal ) return 0; - if( eType==0 || eType==1 ){ + if( eType==SQLITE_MUTEX_FAST || eType==SQLITE_MUTEX_RECURSIVE ){ pRet = (sqlite3_mutex *)malloc(sizeof(sqlite3_mutex)); }else{ pRet = &g.aStatic[eType-2]; @@ -100,7 +99,7 @@ static sqlite3_mutex *counterMutexAlloc(int eType){ static void counterMutexFree(sqlite3_mutex *p){ assert( g.isInit ); g.m.xMutexFree(p->pReal); - if( p->eType==0 || p->eType==1 ){ + if( p->eType==SQLITE_MUTEX_FAST || p->eType==SQLITE_MUTEX_RECURSIVE ){ free(p); } } @@ -288,6 +287,25 @@ static int test_clear_mutex_counters( } /* +** Create and free a mutex. Return the mutex pointer. The pointer +** will be invalid since the mutex has already been freed. The +** return pointer just checks to see if the mutex really was allocated. +*/ +static int test_alloc_mutex( + void * clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *CONST objv[] +){ + sqlite3_mutex *p = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); + char zBuf[100]; + sqlite3_mutex_free(p); + sqlite3_snprintf(sizeof(zBuf), zBuf, "%p", p); + Tcl_AppendResult(interp, zBuf, (char*)0); + return TCL_OK; +} + +/* ** sqlite3_config OPTION */ static int test_config( @@ -332,6 +350,7 @@ int Sqlitetest_mutex_Init(Tcl_Interp *interp){ { "sqlite3_initialize", (Tcl_ObjCmdProc*)test_initialize }, { "sqlite3_config", (Tcl_ObjCmdProc*)test_config }, + { "alloc_dealloc_mutex", (Tcl_ObjCmdProc*)test_alloc_mutex }, { "install_mutex_counters", (Tcl_ObjCmdProc*)test_install_mutex_counters }, { "read_mutex_counters", (Tcl_ObjCmdProc*)test_read_mutex_counters }, { "clear_mutex_counters", (Tcl_ObjCmdProc*)test_clear_mutex_counters }, |