aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c38
-rw-r--r--src/sqlite.h.in41
-rw-r--r--src/test_malloc.c17
3 files changed, 87 insertions, 9 deletions
diff --git a/src/main.c b/src/main.c
index 62500441b..d4e862ed7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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.415 2008/01/31 13:35:49 drh Exp $
+** $Id: main.c,v 1.416 2008/01/31 14:43:24 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -1470,3 +1470,39 @@ int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
sqlite3_mutex_leave(db->mutex);
return rc;
}
+
+/*
+** Interface to the testing logic.
+*/
+int sqlite3_test_control(int op, ...){
+ va_list ap;
+ int rc = 0;
+ va_start(ap, op);
+ switch( op ){
+#ifndef SQLITE_OMIT_FAULTINJECTOR
+ case SQLITE_TESTCTRL_FAULT_CONFIG: {
+ int id = va_arg(ap, int);
+ int nDelay = va_arg(ap, int);
+ int nRepeat = va_arg(ap, int);
+ sqlite3FaultConfig(id, nDelay, nRepeat);
+ break;
+ }
+ case SQLITE_TESTCTRL_FAULT_FAILURES: {
+ int id = va_arg(ap, int);
+ rc = sqlite3FaultFailures(id);
+ break;
+ }
+ case SQLITE_TESTCTRL_FAULT_BENIGN_FAILURES: {
+ int id = va_arg(ap, int);
+ rc = sqlite3FaultBenignFailures(id);
+ break;
+ }
+ case SQLITE_TESTCTRL_FAULT_PENDING: {
+ int id = va_arg(ap, int);
+ rc = sqlite3FaultPending(id);
+ break;
+ }
+#endif /* SQLITE_OMIT_FAULTINJECTOR */
+ }
+ va_end(ap);
+}
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index b1d066971..f3d2d9d4a 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -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.280 2008/01/31 12:26:50 drh Exp $
+** @(#) $Id: sqlite.h.in,v 1.281 2008/01/31 14:43:24 drh Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
@@ -4749,6 +4749,45 @@ int sqlite3_mutex_notheld(sqlite3_mutex*);
int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
/*
+** CAPI3REF: Testing Interface {F11400}
+**
+** The sqlite3_test_control() interface is used to read out internal
+** state of SQLite and to inject faults into SQLite for testing
+** purposes. The first parameter a operation code that determines
+** the number, meaning, and operation of all subsequent parameters.
+**
+** This interface is not for use by applications. It exists solely
+** for verifying the correct operation of the SQLite library. Depending
+** on how the SQLite library is compiled, this interface might not exist.
+**
+** The details of the operation codes, their meanings, the parameters
+** they take, and what they do are all subject to change without notice.
+** Unlike most of the SQLite API, this function is not guaranteed to
+** operate consistently from one release to the next.
+*/
+int sqlite3_test_control(int op, ...);
+
+/*
+** CAPI3REF: Testing Interface Operation Codes {F11410}
+**
+** These constants are the valid operation code parameters used
+** as the first argument to [sqlite3_test_control()].
+**
+** These parameters and their meansing are subject to change
+** without notice. These values are for testing purposes only.
+** Applications should not use any of these parameters or the
+** [sqlite3_test_control()] interface.
+*/
+#define SQLITE_TESTCTRL_FAULT_CONFIG 1
+#define SQLITE_TESTCTRL_FAULT_FAILURES 2
+#define SQLITE_TESTCTRL_FAULT_BENIGN_FAILURES 3
+#define SQLITE_TESTCTRL_FAULT_PENDING 4
+
+
+
+
+
+/*
** Undo the hack that converts floating point types to integer for
** builds on processors without floating point support.
*/
diff --git a/src/test_malloc.c b/src/test_malloc.c
index 237cb96aa..d581ea3bf 100644
--- a/src/test_malloc.c
+++ b/src/test_malloc.c
@@ -13,7 +13,7 @@
** This file contains code used to implement test interfaces to the
** memory allocation subsystem.
**
-** $Id: test_malloc.c,v 1.10 2008/01/22 21:30:53 drh Exp $
+** $Id: test_malloc.c,v 1.11 2008/01/31 14:43:24 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -410,9 +410,12 @@ static int test_memdebug_fail(
}
}
- nBenign = sqlite3FaultBenignFailures(SQLITE_FAULTINJECTOR_MALLOC);
- nFail = sqlite3FaultFailures(SQLITE_FAULTINJECTOR_MALLOC);
- sqlite3FaultConfig(SQLITE_FAULTINJECTOR_MALLOC, iFail, nRepeat);
+ nBenign = sqlite3_test_control(SQLITE_TESTCTRL_FAULT_BENIGN_FAILURES,
+ SQLITE_FAULTINJECTOR_MALLOC);
+ nFail = sqlite3_test_control(SQLITE_TESTCTRL_FAULT_FAILURES,
+ SQLITE_FAULTINJECTOR_MALLOC);
+ sqlite3_test_control(SQLITE_TESTCTRL_FAULT_CONFIG,
+ SQLITE_FAULTINJECTOR_MALLOC, iFail, nRepeat);
if( pBenignCnt ){
Tcl_ObjSetVar2(interp, pBenignCnt, 0, Tcl_NewIntObj(nBenign), 0);
}
@@ -440,9 +443,9 @@ static int test_memdebug_pending(
#ifdef SQLITE_MEMDEBUG
{
- Tcl_SetObjResult(interp,
- Tcl_NewIntObj(sqlite3FaultPending(SQLITE_FAULTINJECTOR_MALLOC))
- );
+ int nPending = sqlite3_test_control(SQLITE_TESTCTRL_FAULT_PENDING,
+ SQLITE_FAULTINJECTOR_MALLOC);
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(nPending));
}
#endif
return TCL_OK;