Add the sqlite3_test_control() API. Use it to control the fault injector. (CVS 4758)

FossilOrigin-Name: 413ddade6a13f993cddc57389d1107d82fa19972
This commit is contained in:
drh 2008-01-31 14:43:24 +00:00
parent 820a90694e
commit ed13d98c8c
5 changed files with 96 additions and 18 deletions

@ -1,5 +1,5 @@
C Version\snumber\sto\s3.5.5.\s\sInclude\sFTS3\sin\sthe\samalgamation\sby\sdefault\n(but\sdisabled\sunless\scompiled\swith\s-DSQLITE_ENABLE_FTS3).\s\sFix\sa\smemory\nallocation\sproblem.\s(CVS\s4757)
D 2008-01-31T13:35:49
C Add\sthe\ssqlite3_test_control()\sAPI.\s\sUse\sit\sto\scontrol\sthe\sfault\sinjector.\s(CVS\s4758)
D 2008-01-31T14:43:24
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in bc2b5df3e3d0d4b801b824b7ef6dec43812b049b
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -102,7 +102,7 @@ F src/journal.c 807bed7a158979ac8d63953e1774e8d85bff65e2
F src/legacy.c 4ac53191fad2e3c4d59bde1228879b2dc5a96d66
F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35
F src/loadext.c d17a0f760d6866aacf5262f97d8efaaad379cdd7
F src/main.c 2db3bc459cc7a79325d85468cd0502f51066b345
F src/main.c ecdc7669cd23c2e914b56e35b1fa14b47f6eee9e
F src/malloc.c 60e392a4c12c839517f9b0db7b995f825444fb35
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/mem1.c 6d1a11864963d249c67e72ad5f6533b040333880
@ -135,7 +135,7 @@ F src/random.c 02ef38b469237482f1ea14a78b2087cfbaec48bd
F src/select.c 1a5d0aaf8f420b164eb775d3b1ba2bfb79597f65
F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c ca06cb687c40a8bff6307b5fad41a0e86a0f8558
F src/sqlite.h.in a65fd6667df5b8a8abc287edebe6b4b82c10cce1
F src/sqlite.h.in eeb3617be89c7004b8a2936d5a46e5138fe02ab9
F src/sqlite3ext.h a93f59cdee3638dc0c9c086f80df743a4e68c3cb
F src/sqliteInt.h b006a4d887af1ce273683cc4874a506254068dbd
F src/sqliteLimit.h ee4430f88f69bf63527967bb35ca52af7b0ccb1e
@ -157,7 +157,7 @@ F src/test_config.c e7db7a46833d0df98ae6c9a11f70dada1bcca249
F src/test_devsym.c fd8884c2269fb7e0db2c52d21ec59d31a33790ba
F src/test_hexio.c 1a1cd8324d57585ea86b922f609fa1fbaaf9662d
F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
F src/test_malloc.c 7ba7e0c283d22c8b079acc4f73d0a034e9779b26
F src/test_malloc.c 0bc9d27c09efe0be63d0de5fb6e38a4253cd5551
F src/test_md5.c c107c96637123239c3518b5fbe97a79130f4d32e
F src/test_onefile.c 54282b6796d55d7acc489be83b89b8715e7d3756
F src/test_schema.c 12c9de7661d6294eec2d57afbb52e2af1128084f
@ -614,7 +614,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P 9b6ab9faad39dd20d761efa68f137c596fbcd7a5
R 404d6f349ee958f04a4a292b728a9be9
P 72411043e60d5358d5a7adf566d662d65d3b3336
R 869aa95ac306ab28b66d2cbeb9340567
U drh
Z 6f7c0fc62c348da44e13ada5666fe319
Z b39878f0b1c59992e9b7955387e6c156

@ -1 +1 @@
72411043e60d5358d5a7adf566d662d65d3b3336
413ddade6a13f993cddc57389d1107d82fa19972

@ -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);
}

@ -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_
@ -4748,6 +4748,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.

@ -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;