1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Add the fault injector module in fault.c. Use it as a basis for memory

allocation failure testing. (CVS 4742)

FossilOrigin-Name: 1a335e180183b414fcc3510ce28b98b21cd134a6
This commit is contained in:
drh
2008-01-22 21:30:53 +00:00
parent 02cd2b80c1
commit 643167ff21
20 changed files with 264 additions and 247 deletions

View File

@@ -13,7 +13,7 @@
** This file contains code used to implement test interfaces to the
** memory allocation subsystem.
**
** $Id: test_malloc.c,v 1.9 2007/10/19 17:47:25 drh Exp $
** $Id: test_malloc.c,v 1.10 2008/01/22 21:30:53 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -349,12 +349,12 @@ static int test_memdebug_dump(
**
** where options are:
**
** -repeat <boolean>
** -repeat <count>
** -benigncnt <varname>
**
** Arrange for a simulated malloc() failure after COUNTER successes.
** If REPEAT is 1 then all subsequent malloc()s fail. If REPEAT is
** 0 then only a single failure occurs.
** If a repeat count is specified, the fault is repeated that many
** times.
**
** Each call to this routine overrides the prior counter value.
** This routine returns the number of simulated failures that have
@@ -370,9 +370,9 @@ static int test_memdebug_fail(
){
int ii;
int iFail;
int iRepeat = -1;
int nRepeat = 1;
Tcl_Obj *pBenignCnt = 0;
int nBenign;
int nFail = 0;
if( objc<2 ){
@@ -390,7 +390,7 @@ static int test_memdebug_fail(
if( ii==(objc-1) ){
zErr = "option requires an argument: ";
}else{
if( Tcl_GetIntFromObj(interp, objv[ii+1], &iRepeat) ){
if( Tcl_GetIntFromObj(interp, objv[ii+1], &nRepeat) ){
return TCL_ERROR;
}
}
@@ -410,16 +410,12 @@ static int test_memdebug_fail(
}
}
#ifdef SQLITE_MEMDEBUG
{
extern int sqlite3_memdebug_fail(int,int,int*);
int iBenignCnt;
nFail = sqlite3_memdebug_fail(iFail, iRepeat, &iBenignCnt);
if( pBenignCnt ){
Tcl_ObjSetVar2(interp, pBenignCnt, 0, Tcl_NewIntObj(iBenignCnt), 0);
}
nBenign = sqlite3FaultBenignFailures(SQLITE_FAULTINJECTOR_MALLOC);
nFail = sqlite3FaultFailures(SQLITE_FAULTINJECTOR_MALLOC);
sqlite3FaultConfig(SQLITE_FAULTINJECTOR_MALLOC, iFail, nRepeat);
if( pBenignCnt ){
Tcl_ObjSetVar2(interp, pBenignCnt, 0, Tcl_NewIntObj(nBenign), 0);
}
#endif
Tcl_SetObjResult(interp, Tcl_NewIntObj(nFail));
return TCL_OK;
}
@@ -444,8 +440,9 @@ static int test_memdebug_pending(
#ifdef SQLITE_MEMDEBUG
{
extern int sqlite3_memdebug_pending();
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_memdebug_pending()));
Tcl_SetObjResult(interp,
Tcl_NewIntObj(sqlite3FaultPending(SQLITE_FAULTINJECTOR_MALLOC))
);
}
#endif
return TCL_OK;