1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

Add an alternative application-defined pcache implementation and add test

cases to permutations.test to invoke it.  Added the SQLITE_CONFIG_GETPCACHE
method to sqlite3_config(). (CVS 5920)

FossilOrigin-Name: 16f1e6ec2ad92f68c0079a0c2b5ca08a3b4af816
This commit is contained in:
drh
2008-11-19 01:20:26 +00:00
parent 4c6517848f
commit b232c23297
9 changed files with 606 additions and 19 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.50 2008/11/10 18:05:36 shane Exp $
** $Id: test_malloc.c,v 1.51 2008/11/19 01:20:26 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -945,6 +945,42 @@ static int test_config_pagecache(
return TCL_OK;
}
/*
** Usage: sqlite3_config_alt_pcache INSTALL_FLAG DISCARD_CHANCE PRNG_SEED
**
** Set up the alternative test page cache. Install if INSTALL_FLAG is
** true and uninstall (reverting to the default page cache) if INSTALL_FLAG
** is false. DISCARD_CHANGE is an integer between 0 and 100 inclusive
** which determines the chance of discarding a page when unpinned. 100
** is certainty. 0 is never. PRNG_SEED is the pseudo-random number generator
** seed.
*/
static int test_alt_pcache(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
int installFlag;
int discardChance;
int prngSeed;
extern void installTestPCache(int,unsigned,unsigned);
if( objc!=4 ){
Tcl_WrongNumArgs(interp, 1, objv, "INSTALLFLAG DISCARDCHANCE PRNGSEEED");
return TCL_ERROR;
}
if( Tcl_GetIntFromObj(interp, objv[1], &installFlag) ) return TCL_ERROR;
if( Tcl_GetIntFromObj(interp, objv[2], &discardChance) ) return TCL_ERROR;
if( Tcl_GetIntFromObj(interp, objv[3], &prngSeed) ) return TCL_ERROR;
if( discardChance<0 || discardChance>100 ){
Tcl_AppendResult(interp, "discard-chance should be between 0 and 100",
(char*)0);
return TCL_ERROR;
}
installTestPCache(installFlag, (unsigned)discardChance, (unsigned)prngSeed);
return TCL_OK;
}
/*
** Usage: sqlite3_config_memstatus BOOLEAN
**
@@ -1312,6 +1348,7 @@ int Sqlitetest_malloc_Init(Tcl_Interp *interp){
{ "sqlite3_memdebug_log", test_memdebug_log ,0 },
{ "sqlite3_config_scratch", test_config_scratch ,0 },
{ "sqlite3_config_pagecache", test_config_pagecache ,0 },
{ "sqlite3_config_alt_pcache", test_alt_pcache ,0 },
{ "sqlite3_status", test_status ,0 },
{ "sqlite3_db_status", test_db_status ,0 },
{ "install_malloc_faultsim", test_install_malloc_faultsim ,0 },
@@ -1321,7 +1358,7 @@ int Sqlitetest_malloc_Init(Tcl_Interp *interp){
{ "sqlite3_config_error", test_config_error ,0 },
{ "sqlite3_db_config_lookaside",test_db_config_lookaside ,0 },
{ "sqlite3_dump_memsys3", test_dump_memsys3 ,3 },
{ "sqlite3_dump_memsys5", test_dump_memsys3 ,5 }
{ "sqlite3_dump_memsys5", test_dump_memsys3 ,5 },
};
int i;
for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){