mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-05 15:55:57 +03:00
Add some test infrastructure and cases for the new mutex api. (CVS 5230)
FossilOrigin-Name: 262baee9952b28afe5dc77eb7365ebb11a480906
This commit is contained in:
1
main.mk
1
main.mk
@@ -226,6 +226,7 @@ TESTSRC = \
|
||||
$(TOP)/src/test_hexio.c \
|
||||
$(TOP)/src/test_malloc.c \
|
||||
$(TOP)/src/test_md5.c \
|
||||
$(TOP)/src/test_mutex.c \
|
||||
$(TOP)/src/test_onefile.c \
|
||||
$(TOP)/src/test_osinst.c \
|
||||
$(TOP)/src/test_schema.c \
|
||||
|
26
manifest
26
manifest
@@ -1,5 +1,5 @@
|
||||
C Remove\smem3.c\sand\smem5.c\sfrom\sthe\samalgamation\sfor\sthe\stime\sbeing,\ssince\nthey\sdo\snot\scurrently\swork.\s\sWe\swill\sadd\sthem\sback\slater\sonce\sthey\sare\sfixed.\s(CVS\s5229)
|
||||
D 2008-06-18T02:01:07
|
||||
C Add\ssome\stest\sinfrastructure\sand\scases\sfor\sthe\snew\smutex\sapi.\s(CVS\s5230)
|
||||
D 2008-06-18T09:45:56
|
||||
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
|
||||
F Makefile.in dc5608df93faf4406cfd7a1c8ed9ab93d8bfbfd5
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
@@ -76,7 +76,7 @@ F ext/rtree/rtree_util.tcl ee0a0311eb12175319d78bfb37302320496cee6e
|
||||
F ext/rtree/viewrtree.tcl 09526398dae87a5a87c5aac2b3854dbaf8376869
|
||||
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
|
||||
F ltmain.sh 09fe5815427dc7d0abb188bbcdf0e34896577210
|
||||
F main.mk 5ef9aba69a7c8a585348d1ce77bfc927e456fbc7
|
||||
F main.mk 8a6820d4ed89c95b4c28c88412bb8bf0513cfc5c
|
||||
F mkdll.sh 712e74f3efe08a6ba12b2945d018a29a89d7fe3b
|
||||
F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f
|
||||
F mkextw.sh 1a866b53637dab137191341cc875575a5ca110fb
|
||||
@@ -115,7 +115,7 @@ F src/insert.c c2ead6c36566de8e3f130e7ab1431723a269d5d7
|
||||
F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e
|
||||
F src/legacy.c 3626c71fb70912abec9a4312beba753a9ce800df
|
||||
F src/loadext.c f99a75534a53e281fa2461239ee4a4b4bf6ad564
|
||||
F src/main.c 02f11264d00bec0a450b3570a7232eec6a4cdf5d
|
||||
F src/main.c 21807e7bff6176030ac14ebf49c8a85479349689
|
||||
F src/malloc.c 7b622d22f29e3be56d271a5a921f3b5788330189
|
||||
F src/md5.c 008216bbb5d34c6fbab5357aa68575ad8a31516a
|
||||
F src/mem1.c 159f10e280f2d9aea597cf938851e61652dd5c3d
|
||||
@@ -123,10 +123,10 @@ F src/mem2.c 594270b8f0ed6c09ae5fb729eca2864139f9e293
|
||||
F src/mem3.c 617c2e2a72a10ecc5c01af14efc8c2596d2c2e87
|
||||
F src/mem4.c 45c328ec6dcb7e8d319cb383615b5fe547ca5409
|
||||
F src/mem5.c 3d2ff00c6e3bc37f5d82cd82e1a123b246fb7b39
|
||||
F src/mutex.c d367b079d61f4b4c2925e321209da04fe226590f
|
||||
F src/mutex.c 890b83ccf19de17e88b612b2b3f18009a9f1bfa1
|
||||
F src/mutex.h b9b9baf7050f3bb1c723e1d22088a704783a2927
|
||||
F src/mutex_os2.c b8c1231319e966875f251a7ec137bea353546b87
|
||||
F src/mutex_unix.c 74a6755912ad2a924026b54b4b5a64d327748aa5
|
||||
F src/mutex_unix.c 469a35c105435794375d683f75cad9e848817d19
|
||||
F src/mutex_w32.c e03baa369c5e8e7ea4dd2e5b3d098e047f7a2f06
|
||||
F src/os.c cf7e09d4215f35fc8269f0fa99f03fd2c2978658
|
||||
F src/os.h c9a7f94e80193fd4cf27f5c5698eb56753f1b05a
|
||||
@@ -143,12 +143,12 @@ F src/printf.c 8b063da9dcde26b7c500a01444b718d86f21bc6e
|
||||
F src/random.c 2b2db2de4ab491f5a14d3480466f8f4b5a5db74a
|
||||
F src/select.c 669687459e7d0193c89de06c5dbed55b4a41191c
|
||||
F src/shell.c a12ea645271b7876c8f080146f48e20b00d367ec
|
||||
F src/sqlite.h.in d77f7a34f7655721cd887728874b8931a046fabb
|
||||
F src/sqlite.h.in 4724c4c3fb66c0e696edd6aec3b3d79c33c09d0a
|
||||
F src/sqlite3ext.h faacd0e6a81aabee0861c6d7883c9172e74ef5b3
|
||||
F src/sqliteInt.h f465a6d45e9cabadad5c6c097d17df3c054616d0
|
||||
F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
|
||||
F src/table.c 1fa8f8113ac9cbc09ae4801c6d2a7f0af82c5822
|
||||
F src/tclsqlite.c c57e740e30bd6dda678796eed62c7f0e64689834
|
||||
F src/tclsqlite.c 4dd9ee4cb44846ad9bcc4d0da8088c1e7d4b33d9
|
||||
F src/test1.c 736be7dea5cc126356bbb61a4b1ac5ff4fac7994
|
||||
F src/test2.c c46d146019ab6e37474e66b3c789e5237d9ea7b7
|
||||
F src/test3.c b5c1d1047a45af03375d66b3eec603faafa3ddc6
|
||||
@@ -168,6 +168,7 @@ F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f
|
||||
F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
|
||||
F src/test_malloc.c 5c2c698355613d321f216ece25901be1040cc1fb
|
||||
F src/test_md5.c 28209a4e2068711b5443c33104fe41f21d160071
|
||||
F src/test_mutex.c f3e1f04fd6a42f9e7ff47784db8bc81e497b5c65
|
||||
F src/test_onefile.c 1f87d4a21cbfb24a7c35e4333fa0bd34d641f68d
|
||||
F src/test_osinst.c 867f1317bd135f942a63eab5a78da40fc70d1493
|
||||
F src/test_schema.c e3f93725f7c5b2cff84a69dc4332040dfbc8f81a
|
||||
@@ -415,6 +416,7 @@ F test/misc5.test 0b68dcb630d44af2dbcdca94dd2b17c8d580f6fa
|
||||
F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
|
||||
F test/misc7.test 26e0d948a413bca61ed031159907a03d64647409
|
||||
F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33
|
||||
F test/mutex1.test 6494fe9e6747328a0b1b0d2676ff4cf1a12fb51d
|
||||
F test/nan.test 14c41572ff52dbc740b1c3303dd313a90dc6084c
|
||||
F test/notnull.test 44d600f916b770def8b095a9962dbe3be5a70d82
|
||||
F test/null.test a8b09b8ed87852742343b33441a9240022108993
|
||||
@@ -594,7 +596,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
|
||||
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
P af1835bb5f5e3fb78d782c7c287e20db169e883f
|
||||
R f52e17178b7cffb0eea0931f117949b1
|
||||
U drh
|
||||
Z 9696bf70dd1d33bb99b1db9b6b6af8a7
|
||||
P 39b4e1ff4e3db3278c35eff10bbabdf4d87793a4
|
||||
R a0d49cf1341289981a00a4ad9da3e9bc
|
||||
U danielk1977
|
||||
Z 963819c2af16f4cb39a0c216ae54cc59
|
||||
|
@@ -1 +1 @@
|
||||
39b4e1ff4e3db3278c35eff10bbabdf4d87793a4
|
||||
262baee9952b28afe5dc77eb7365ebb11a480906
|
@@ -14,7 +14,7 @@
|
||||
** other files are for internal use by SQLite and should not be
|
||||
** accessed by users of the library.
|
||||
**
|
||||
** $Id: main.c,v 1.446 2008/06/17 18:57:49 danielk1977 Exp $
|
||||
** $Id: main.c,v 1.447 2008/06/18 09:45:56 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -156,6 +156,11 @@ int sqlite3_config(int op, ...){
|
||||
sqlite3Config.mutex = *va_arg(ap, sqlite3_mutex_methods*);
|
||||
break;
|
||||
}
|
||||
case SQLITE_CONFIG_GETMUTEX: {
|
||||
/* Retrieve the current mutex implementation */
|
||||
*va_arg(ap, sqlite3_mutex_methods*) = sqlite3Config.mutex;
|
||||
break;
|
||||
}
|
||||
case SQLITE_CONFIG_MEMSTATUS: {
|
||||
/* Enable or disable the malloc status collection */
|
||||
sqlite3Config.bMemstat = va_arg(ap, int);
|
||||
|
@@ -19,7 +19,7 @@
|
||||
** implementation is suitable for testing.
|
||||
** debugging purposes
|
||||
**
|
||||
** $Id: mutex.c,v 1.22 2008/06/17 18:57:49 danielk1977 Exp $
|
||||
** $Id: mutex.c,v 1.23 2008/06/18 09:45:56 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -237,9 +237,9 @@ static int noopMutexTry(sqlite3_mutex *p){
|
||||
** is not currently allocated. SQLite will never do either.
|
||||
*/
|
||||
static void noopMutexLeave(sqlite3_mutex *p){
|
||||
assert( sqlite3_mutex_held(p) );
|
||||
assert( noopMutexHeld(p) );
|
||||
p->cnt--;
|
||||
assert( p->id==SQLITE_MUTEX_RECURSIVE || sqlite3_mutex_notheld(p) );
|
||||
assert( p->id==SQLITE_MUTEX_RECURSIVE || noopMutexNotheld(p) );
|
||||
}
|
||||
|
||||
sqlite3_mutex_methods *sqlite3DefaultMutex(void){
|
||||
|
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** This file contains the C functions that implement mutexes for pthreads
|
||||
**
|
||||
** $Id: mutex_unix.c,v 1.9 2008/06/17 17:21:18 danielk1977 Exp $
|
||||
** $Id: mutex_unix.c,v 1.10 2008/06/18 09:45:56 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -285,7 +285,7 @@ static int pthreadMutexTry(sqlite3_mutex *p){
|
||||
** is not currently allocated. SQLite will never do either.
|
||||
*/
|
||||
static void pthreadMutexLeave(sqlite3_mutex *p){
|
||||
assert( sqlite3_mutex_held(p) );
|
||||
assert( pthreadMutexHeld(p) );
|
||||
p->nRef--;
|
||||
assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE );
|
||||
|
||||
|
@@ -30,7 +30,7 @@
|
||||
** the version number) and changes its name to "sqlite3.h" as
|
||||
** part of the build process.
|
||||
**
|
||||
** @(#) $Id: sqlite.h.in,v 1.331 2008/06/17 18:57:49 danielk1977 Exp $
|
||||
** @(#) $Id: sqlite.h.in,v 1.332 2008/06/18 09:45:56 danielk1977 Exp $
|
||||
*/
|
||||
#ifndef _SQLITE3_H_
|
||||
#define _SQLITE3_H_
|
||||
@@ -1051,9 +1051,10 @@ struct sqlite3_mem_methods {
|
||||
#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
|
||||
#define SQLITE_CONFIG_MEMSTATUS 5 /* boolean */
|
||||
#define SQLITE_CONFIG_MUTEX 6 /* sqlite3_mutex_methods* */
|
||||
#define SQLITE_CONFIG_GETMUTEX 7 /* sqlite3_mutex_methods* */
|
||||
|
||||
/* These options are to be added later. Currently unused and undocumented. */
|
||||
#define SQLITE_CONFIG_HEAP 6 /* void*, int64, min, max, tmp */
|
||||
#define SQLITE_CONFIG_HEAP 8 /* void*, int64, min, max, tmp */
|
||||
|
||||
|
||||
/*
|
||||
|
@@ -12,7 +12,7 @@
|
||||
** A TCL Interface to SQLite. Append this file to sqlite3.c and
|
||||
** compile the whole thing to build a TCL-enabled version of SQLite.
|
||||
**
|
||||
** $Id: tclsqlite.c,v 1.217 2008/05/01 17:16:53 drh Exp $
|
||||
** $Id: tclsqlite.c,v 1.218 2008/06/18 09:45:56 danielk1977 Exp $
|
||||
*/
|
||||
#include "tcl.h"
|
||||
#include <errno.h>
|
||||
@@ -2528,6 +2528,7 @@ int TCLSH_MAIN(int argc, char **argv){
|
||||
extern int Sqlitetest_func_Init(Tcl_Interp*);
|
||||
extern int Sqlitetest_hexio_Init(Tcl_Interp*);
|
||||
extern int Sqlitetest_malloc_Init(Tcl_Interp*);
|
||||
extern int Sqlitetest_mutex_Init(Tcl_Interp*);
|
||||
extern int Sqlitetestschema_Init(Tcl_Interp*);
|
||||
extern int Sqlitetestsse_Init(Tcl_Interp*);
|
||||
extern int Sqlitetesttclvar_Init(Tcl_Interp*);
|
||||
@@ -2551,6 +2552,7 @@ int TCLSH_MAIN(int argc, char **argv){
|
||||
Sqlitetest_func_Init(interp);
|
||||
Sqlitetest_hexio_Init(interp);
|
||||
Sqlitetest_malloc_Init(interp);
|
||||
Sqlitetest_mutex_Init(interp);
|
||||
Sqlitetestschema_Init(interp);
|
||||
Sqlitetesttclvar_Init(interp);
|
||||
SqlitetestThread_Init(interp);
|
||||
|
269
src/test_mutex.c
Normal file
269
src/test_mutex.c
Normal file
@@ -0,0 +1,269 @@
|
||||
/*
|
||||
** 2008 June 18
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** $Id: test_mutex.c,v 1.1 2008/06/18 09:45:56 danielk1977 Exp $
|
||||
*/
|
||||
|
||||
#include "tcl.h"
|
||||
#include "sqlite3.h"
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
const char *sqlite3TestErrorName(int);
|
||||
|
||||
struct sqlite3_mutex {
|
||||
sqlite3_mutex *pReal;
|
||||
int eType;
|
||||
};
|
||||
|
||||
static struct test_mutex_globals {
|
||||
int isInstalled;
|
||||
sqlite3_mutex_methods m; /* Interface to "real" mutex system */
|
||||
int aCounter[8]; /* Number of grabs of each type of mutex */
|
||||
sqlite3_mutex aStatic[6]; /* The six static mutexes */
|
||||
} g;
|
||||
|
||||
static int counterMutexHeld(sqlite3_mutex *p){
|
||||
return g.m.xMutexHeld(p->pReal);
|
||||
}
|
||||
|
||||
static int counterMutexNotheld(sqlite3_mutex *p){
|
||||
return g.m.xMutexNotheld(p->pReal);
|
||||
}
|
||||
|
||||
static int counterMutexInit(void){
|
||||
return g.m.xMutexInit();
|
||||
}
|
||||
|
||||
static int counterMutexEnd(void){
|
||||
return g.m.xMutexEnd();
|
||||
}
|
||||
|
||||
static sqlite3_mutex *counterMutexAlloc(int eType){
|
||||
sqlite3_mutex *pReal;
|
||||
sqlite3_mutex *pRet = 0;
|
||||
|
||||
assert(eType<8 && eType>=0);
|
||||
|
||||
pReal = g.m.xMutexAlloc(eType);
|
||||
if( !pReal ) return 0;
|
||||
|
||||
if( eType==0 || eType==1 ){
|
||||
pRet = (sqlite3_mutex *)malloc(sizeof(sqlite3_mutex));
|
||||
}else{
|
||||
pRet = &g.aStatic[eType-2];
|
||||
}
|
||||
|
||||
pRet->eType = eType;
|
||||
pRet->pReal = pReal;
|
||||
return pRet;
|
||||
}
|
||||
|
||||
static void counterMutexFree(sqlite3_mutex *p){
|
||||
g.m.xMutexFree(p->pReal);
|
||||
if( p->eType==0 || p->eType==1 ){
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
|
||||
static void counterMutexEnter(sqlite3_mutex *p){
|
||||
g.aCounter[p->eType]++;
|
||||
g.m.xMutexEnter(p->pReal);
|
||||
}
|
||||
|
||||
static int counterMutexTry(sqlite3_mutex *p){
|
||||
g.aCounter[p->eType]++;
|
||||
return g.m.xMutexTry(p->pReal);
|
||||
}
|
||||
|
||||
static void counterMutexLeave(sqlite3_mutex *p){
|
||||
g.m.xMutexLeave(p->pReal);
|
||||
}
|
||||
|
||||
/*
|
||||
** sqlite3_shutdown
|
||||
*/
|
||||
static int test_shutdown(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
int rc;
|
||||
|
||||
if( objc!=1 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
rc = sqlite3_shutdown();
|
||||
Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** sqlite3_initialize
|
||||
*/
|
||||
static int test_initialize(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
int rc;
|
||||
|
||||
if( objc!=1 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
rc = sqlite3_initialize();
|
||||
Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** install_mutex_counters BOOLEAN
|
||||
*/
|
||||
static int test_install_mutex_counters(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
int isInstall;
|
||||
|
||||
sqlite3_mutex_methods counter_methods = {
|
||||
counterMutexInit,
|
||||
counterMutexAlloc,
|
||||
counterMutexFree,
|
||||
counterMutexEnter,
|
||||
counterMutexTry,
|
||||
counterMutexLeave,
|
||||
counterMutexEnd,
|
||||
counterMutexHeld,
|
||||
counterMutexNotheld
|
||||
};
|
||||
|
||||
if( objc!=2 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "BOOLEAN");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[1], &isInstall) ){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
assert(isInstall==0 || isInstall==1);
|
||||
assert(g.isInstalled==0 || g.isInstalled==1);
|
||||
if( isInstall==g.isInstalled ){
|
||||
Tcl_AppendResult(interp, "mutex counters are ", 0);
|
||||
Tcl_AppendResult(interp, isInstall?"already installed":"not installed", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
if( isInstall ){
|
||||
assert( g.m.xMutexAlloc==0 );
|
||||
rc = sqlite3_config(SQLITE_CONFIG_GETMUTEX, &g.m);
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3_config(SQLITE_CONFIG_MUTEX, &counter_methods);
|
||||
}
|
||||
}else{
|
||||
assert( g.m.xMutexAlloc );
|
||||
rc = sqlite3_config(SQLITE_CONFIG_MUTEX, &g.m);
|
||||
memset(&g.m, 0, sizeof(sqlite3_mutex_methods));
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
g.isInstalled = isInstall;
|
||||
}
|
||||
|
||||
Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** read_mutex_counters
|
||||
*/
|
||||
static int test_read_mutex_counters(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
Tcl_Obj *pRet;
|
||||
int ii;
|
||||
char *aName[8] = {
|
||||
"fast", "recursive", "static_master", "static_mem",
|
||||
"static_mem2", "static_prng", "static_lru", "static_lru2"
|
||||
};
|
||||
|
||||
if( objc!=1 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
pRet = Tcl_NewObj();
|
||||
Tcl_IncrRefCount(pRet);
|
||||
for(ii=0; ii<8; ii++){
|
||||
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(aName[ii], -1));
|
||||
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(g.aCounter[ii]));
|
||||
}
|
||||
Tcl_SetObjResult(interp, pRet);
|
||||
Tcl_DecrRefCount(pRet);
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** clear_mutex_counters
|
||||
*/
|
||||
static int test_clear_mutex_counters(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
int ii;
|
||||
|
||||
if( objc!=1 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
for(ii=0; ii<8; ii++){
|
||||
g.aCounter[ii] = 0;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
int Sqlitetest_mutex_Init(Tcl_Interp *interp){
|
||||
static struct {
|
||||
char *zName;
|
||||
Tcl_ObjCmdProc *xProc;
|
||||
} aCmd[] = {
|
||||
{ "sqlite3_shutdown", (Tcl_ObjCmdProc*)test_shutdown },
|
||||
{ "sqlite3_initialize", (Tcl_ObjCmdProc*)test_initialize },
|
||||
|
||||
{ "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 },
|
||||
};
|
||||
int i;
|
||||
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
|
||||
Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
|
||||
}
|
||||
memset(&g, 0, sizeof(g));
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
86
test/mutex1.test
Normal file
86
test/mutex1.test
Normal file
@@ -0,0 +1,86 @@
|
||||
# 2008 June 17
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# $Id: mutex1.test,v 1.1 2008/06/18 09:45:56 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
proc mutex_counters {varname} {
|
||||
upvar $varname var
|
||||
set var(total) 0
|
||||
foreach {name value} [read_mutex_counters] {
|
||||
set var($name) $value
|
||||
incr var(total) $value
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Tests mutex1-1.* test that sqlite3_config() returns SQLITE_MISUSE if
|
||||
# is called at the wrong time. And that the first time sqlite3_initialize
|
||||
# is called it obtains the 'static_master' mutex. Subsequent calls are
|
||||
# no-ops that do not require a mutex.
|
||||
#
|
||||
do_test mutex1-1.0 {
|
||||
install_mutex_counters 1
|
||||
} {SQLITE_MISUSE}
|
||||
|
||||
do_test mutex1-1.1 {
|
||||
db close
|
||||
install_mutex_counters 1
|
||||
} {SQLITE_MISUSE}
|
||||
|
||||
do_test mutex1-1.2 {
|
||||
sqlite3_shutdown
|
||||
install_mutex_counters 1
|
||||
} {SQLITE_OK}
|
||||
|
||||
do_test mutex1-1.3 {
|
||||
install_mutex_counters 0
|
||||
} {SQLITE_OK}
|
||||
|
||||
do_test mutex1-1.4 {
|
||||
install_mutex_counters 1
|
||||
} {SQLITE_OK}
|
||||
|
||||
do_test mutex1-1.5 {
|
||||
mutex_counters counters
|
||||
set counters(total)
|
||||
} {0}
|
||||
|
||||
do_test mutex1-1.6 {
|
||||
sqlite3_initialize
|
||||
} {SQLITE_OK}
|
||||
|
||||
do_test mutex1-1.7 {
|
||||
mutex_counters counters
|
||||
list $counters(total) $counters(static_master)
|
||||
} {1 1}
|
||||
|
||||
do_test mutex1-1.8 {
|
||||
clear_mutex_counters
|
||||
sqlite3_initialize
|
||||
} {SQLITE_OK}
|
||||
|
||||
do_test mutex1-1.9 {
|
||||
mutex_counters counters
|
||||
list $counters(total) $counters(static_master)
|
||||
} {0 0}
|
||||
|
||||
|
||||
do_test mutex1-X {
|
||||
sqlite3_shutdown
|
||||
clear_mutex_counters
|
||||
install_mutex_counters 0
|
||||
} {SQLITE_OK}
|
||||
|
||||
finish_test
|
||||
|
Reference in New Issue
Block a user