mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Move error simulation code from the sqlite3_os_init() functions into a wrapper.
FossilOrigin-Name: 67ad21abf88abb7a3e2eacddcaf1ab5d54149807
This commit is contained in:
26
manifest
26
manifest
@@ -1,5 +1,5 @@
|
|||||||
C More\sdocumentation\sand\scomment\supdates\sfor\ssqlite3_initialize/shutdown\sinterface\schanges\sto\shandle\sfailures.
|
C Move\serror\ssimulation\scode\sfrom\sthe\ssqlite3_os_init()\sfunctions\sinto\sa\swrapper.
|
||||||
D 2009-08-17T15:31:23
|
D 2009-08-17T15:52:26
|
||||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||||
F Makefile.in 0f7761c5d1c62ae7a841e3393ffaff1fa0f5c00a
|
F Makefile.in 0f7761c5d1c62ae7a841e3393ffaff1fa0f5c00a
|
||||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||||
@@ -126,7 +126,7 @@ F src/journal.c e00df0c0da8413ab6e1bb7d7cab5665d4a9000d0
|
|||||||
F src/legacy.c 303b4ffcf1ae652fcf5ef635846c563c254564f6
|
F src/legacy.c 303b4ffcf1ae652fcf5ef635846c563c254564f6
|
||||||
F src/lempar.c 0c4d1ab0a5ef2b0381eb81a732c54f68f27a574d
|
F src/lempar.c 0c4d1ab0a5ef2b0381eb81a732c54f68f27a574d
|
||||||
F src/loadext.c 0e88a335665db0b2fb4cece3e49dcb65d832635a
|
F src/loadext.c 0e88a335665db0b2fb4cece3e49dcb65d832635a
|
||||||
F src/main.c cb283c9e98d50cb14b01d6b736c4336f7bf07189
|
F src/main.c 1e87aa66fd43d4a11c9aa4ed1407d0894b359a52
|
||||||
F src/malloc.c ae9fef00398ead775630cad97e228d527178eb3a
|
F src/malloc.c ae9fef00398ead775630cad97e228d527178eb3a
|
||||||
F src/mem0.c f2f84062d1f35814d6535c9f9e33de3bfb3b132c
|
F src/mem0.c f2f84062d1f35814d6535c9f9e33de3bfb3b132c
|
||||||
F src/mem1.c e6d5c23941288df8191b8a98c28e3f57771e2270
|
F src/mem1.c e6d5c23941288df8191b8a98c28e3f57771e2270
|
||||||
@@ -141,12 +141,12 @@ F src/mutex_os2.c 6b5a74f812082a8483c3df05b47bbaac2424b9a0
|
|||||||
F src/mutex_unix.c aff26c77f698b552becfedfa677ad1036c42d790
|
F src/mutex_unix.c aff26c77f698b552becfedfa677ad1036c42d790
|
||||||
F src/mutex_w32.c b2c1481ee93b0ac7a8fa5346570fd173b6763fdb
|
F src/mutex_w32.c b2c1481ee93b0ac7a8fa5346570fd173b6763fdb
|
||||||
F src/notify.c 0127121816d8a861deb0dfd111b495346bf233db
|
F src/notify.c 0127121816d8a861deb0dfd111b495346bf233db
|
||||||
F src/os.c 5029ae6c88d1869ad9034008a9531658d53438e4
|
F src/os.c 3855c23ceb2006795b29c78915ebf36717b06aad
|
||||||
F src/os.h fa3f4aa0119ff721a2da4b47ffd74406ac864c05
|
F src/os.h 00a1334a4eecee7f7bef79ac606b88d325119f21
|
||||||
F src/os_common.h 8c61457df58f1a4bd5f5adc3e90e01b37bf7afbc
|
F src/os_common.h 8c61457df58f1a4bd5f5adc3e90e01b37bf7afbc
|
||||||
F src/os_os2.c bed77dc26e3a95ce4a204936b9a1ca6fe612fcc5
|
F src/os_os2.c bed77dc26e3a95ce4a204936b9a1ca6fe612fcc5
|
||||||
F src/os_unix.c aea2a5c1c07c47767b0961b670dc647aa4aefc4e
|
F src/os_unix.c 6895098a9e7bd5630fab59060da6397bebcf2ff9
|
||||||
F src/os_win.c a3e93d1b44a818ce9422e2e588984df1cb7e4819
|
F src/os_win.c 58bb163f327e79726dd119344d908e4d98483c3f
|
||||||
F src/pager.c a47be286477ed6c7b9a342dd53d4e4043f29d8c2
|
F src/pager.c a47be286477ed6c7b9a342dd53d4e4043f29d8c2
|
||||||
F src/pager.h 11852d044c86cf5a9d6e34171fb0c4fcf1f6265f
|
F src/pager.h 11852d044c86cf5a9d6e34171fb0c4fcf1f6265f
|
||||||
F src/parse.y 6c42631e72a3d14cde2bee85e79409066066d3df
|
F src/parse.y 6c42631e72a3d14cde2bee85e79409066066d3df
|
||||||
@@ -185,7 +185,7 @@ F src/test_config.c 63d1b08809ca182ee75429573111b44735861c64
|
|||||||
F src/test_devsym.c 9f4bc2551e267ce7aeda195f3897d0f30c5228f4
|
F src/test_devsym.c 9f4bc2551e267ce7aeda195f3897d0f30c5228f4
|
||||||
F src/test_func.c 26ac62d8ed7a9f45a1e05baffb1c1e55fe2a06f2
|
F src/test_func.c 26ac62d8ed7a9f45a1e05baffb1c1e55fe2a06f2
|
||||||
F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f
|
F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f
|
||||||
F src/test_init.c ff7c0e055fb786f5b048df83b6dfb1624851a88b
|
F src/test_init.c f6a5dfaf2fb52d697eec1c825a641e5893c339d2
|
||||||
F src/test_journal.c dab49b7c47b53242f039c9563b18cafb67ebfe03
|
F src/test_journal.c dab49b7c47b53242f039c9563b18cafb67ebfe03
|
||||||
F src/test_loadext.c 97dc8800e46a46ed002c2968572656f37e9c0dd9
|
F src/test_loadext.c 97dc8800e46a46ed002c2968572656f37e9c0dd9
|
||||||
F src/test_malloc.c d054506b095d711e4e5575558dd576a2cbf035a2
|
F src/test_malloc.c d054506b095d711e4e5575558dd576a2cbf035a2
|
||||||
@@ -409,7 +409,7 @@ F test/index.test cbf301cdb2da43e4eac636c3400c2439af1834ad
|
|||||||
F test/index2.test ee83c6b5e3173a3d7137140d945d9a5d4fdfb9d6
|
F test/index2.test ee83c6b5e3173a3d7137140d945d9a5d4fdfb9d6
|
||||||
F test/index3.test 727d55dceb9a4ec36675057bb5becfc265e28ca6
|
F test/index3.test 727d55dceb9a4ec36675057bb5becfc265e28ca6
|
||||||
F test/indexedby.test 946ca2628a521f4ced0520421a0788345abaf3dc
|
F test/indexedby.test 946ca2628a521f4ced0520421a0788345abaf3dc
|
||||||
F test/init.test 5768d2cfeb25df627d42de675ab6201a65c167fe
|
F test/init.test 3f9e97948cf2335c08a5e3edc3df3a26cdaa76f2
|
||||||
F test/insert.test aef273dd1cee84cc92407469e6bd1b3cdcb76908
|
F test/insert.test aef273dd1cee84cc92407469e6bd1b3cdcb76908
|
||||||
F test/insert2.test 4f3a04d168c728ed5ec2c88842e772606c7ce435
|
F test/insert2.test 4f3a04d168c728ed5ec2c88842e772606c7ce435
|
||||||
F test/insert3.test 1b7db95a03ad9c5013fdf7d6722b6cd66ee55e30
|
F test/insert3.test 1b7db95a03ad9c5013fdf7d6722b6cd66ee55e30
|
||||||
@@ -746,7 +746,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
|||||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||||
F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746
|
F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746
|
||||||
P 904a371c6c9d3f20332b37767b06161fa0a78113
|
P 32509bc7339cd6a46cea4c243e3418546860cb2d
|
||||||
R a9ed6e4e5323f07f7cab487d83cce5a4
|
R ee9f9682e4e218a87239394324f62b18
|
||||||
U shane
|
U dan
|
||||||
Z f4248855d1755b89d2ad5c1a3e7e2a1a
|
Z 435403f17ee49c9f5cf99c3836460b04
|
||||||
|
@@ -1 +1 @@
|
|||||||
32509bc7339cd6a46cea4c243e3418546860cb2d
|
67ad21abf88abb7a3e2eacddcaf1ab5d54149807
|
@@ -167,7 +167,7 @@ int sqlite3_initialize(void){
|
|||||||
}
|
}
|
||||||
if( rc==SQLITE_OK ){
|
if( rc==SQLITE_OK ){
|
||||||
sqlite3GlobalConfig.isPCacheInit = 1;
|
sqlite3GlobalConfig.isPCacheInit = 1;
|
||||||
rc = sqlite3_os_init();
|
rc = sqlite3OsInit();
|
||||||
}
|
}
|
||||||
if( rc==SQLITE_OK ){
|
if( rc==SQLITE_OK ){
|
||||||
sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage,
|
sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage,
|
||||||
|
11
src/os.c
11
src/os.c
@@ -190,6 +190,17 @@ int sqlite3OsCloseFree(sqlite3_file *pFile){
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** This function is a wrapper around the OS specific implementation of
|
||||||
|
** sqlite3_os_init(). The purpose of the wrapper is to provide the
|
||||||
|
** ability to simulate a malloc failure, so that the handling of an
|
||||||
|
** error in sqlite3_os_init() by the upper layers can be tested.
|
||||||
|
*/
|
||||||
|
int sqlite3OsInit(void){
|
||||||
|
DO_OS_MALLOC_TEST(0);
|
||||||
|
return sqlite3_os_init();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** The list of all registered VFS implementations.
|
** The list of all registered VFS implementations.
|
||||||
*/
|
*/
|
||||||
|
5
src/os.h
5
src/os.h
@@ -224,6 +224,11 @@
|
|||||||
#define SHARED_FIRST (PENDING_BYTE+2)
|
#define SHARED_FIRST (PENDING_BYTE+2)
|
||||||
#define SHARED_SIZE 510
|
#define SHARED_SIZE 510
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Wrapper around OS specific sqlite3_os_init() function.
|
||||||
|
*/
|
||||||
|
int sqlite3OsInit(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Functions for accessing sqlite3_file methods
|
** Functions for accessing sqlite3_file methods
|
||||||
*/
|
*/
|
||||||
|
@@ -5126,13 +5126,6 @@ int sqlite3_os_init(void){
|
|||||||
};
|
};
|
||||||
unsigned int i; /* Loop counter */
|
unsigned int i; /* Loop counter */
|
||||||
|
|
||||||
#ifdef SQLITE_TEST
|
|
||||||
/* This block is used by test code only to simulate the effect on sqlite
|
|
||||||
** of returning an error from within the sqlite3_os_init() function. */
|
|
||||||
int sqlite3TestFailOsInit(void);
|
|
||||||
if( sqlite3TestFailOsInit() ){ return SQLITE_ERROR; }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Register all VFSes defined in the aVfs[] array */
|
/* Register all VFSes defined in the aVfs[] array */
|
||||||
for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
|
for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
|
||||||
sqlite3_vfs_register(&aVfs[i], i==0);
|
sqlite3_vfs_register(&aVfs[i], i==0);
|
||||||
|
@@ -1883,13 +1883,6 @@ int sqlite3_os_init(void){
|
|||||||
winGetLastError /* xGetLastError */
|
winGetLastError /* xGetLastError */
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef SQLITE_TEST
|
|
||||||
/* This block is used by test code only to simulate the effect on sqlite
|
|
||||||
** of returning an error from within the sqlite3_os_init() function. */
|
|
||||||
int sqlite3TestFailOsInit(void);
|
|
||||||
if( sqlite3TestFailOsInit() ){ return SQLITE_ERROR; }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
sqlite3_vfs_register(&winVfs, 1);
|
sqlite3_vfs_register(&winVfs, 1);
|
||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,6 @@ static struct Wrapped {
|
|||||||
int mutex_fail; /* True to fail mutex subsystem inialization */
|
int mutex_fail; /* True to fail mutex subsystem inialization */
|
||||||
int pcache_init; /* True if pcache subsystem is initalized */
|
int pcache_init; /* True if pcache subsystem is initalized */
|
||||||
int pcache_fail; /* True to fail pcache subsystem inialization */
|
int pcache_fail; /* True to fail pcache subsystem inialization */
|
||||||
int osinit_fail; /* True to fail OS subsystem inialization */
|
|
||||||
} wrapped;
|
} wrapped;
|
||||||
|
|
||||||
static int wrMemInit(void *pAppData){
|
static int wrMemInit(void *pAppData){
|
||||||
@@ -196,8 +195,6 @@ static int init_wrapper_install(
|
|||||||
wrapped.mutex_fail = 1;
|
wrapped.mutex_fail = 1;
|
||||||
}else if( strcmp(z, "pcache")==0 ){
|
}else if( strcmp(z, "pcache")==0 ){
|
||||||
wrapped.pcache_fail = 1;
|
wrapped.pcache_fail = 1;
|
||||||
}else if( strcmp(z, "os")==0 ){
|
|
||||||
wrapped.osinit_fail = 1;
|
|
||||||
}else{
|
}else{
|
||||||
Tcl_AppendResult(interp, "Unknown argument: \"", z, "\"");
|
Tcl_AppendResult(interp, "Unknown argument: \"", z, "\"");
|
||||||
return TCL_ERROR;
|
return TCL_ERROR;
|
||||||
@@ -239,7 +236,6 @@ static int init_wrapper_clear(
|
|||||||
wrapped.mem_fail = 0;
|
wrapped.mem_fail = 0;
|
||||||
wrapped.mutex_fail = 0;
|
wrapped.mutex_fail = 0;
|
||||||
wrapped.pcache_fail = 0;
|
wrapped.pcache_fail = 0;
|
||||||
wrapped.osinit_fail = 0;
|
|
||||||
return TCL_OK;
|
return TCL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,18 +262,11 @@ static int init_wrapper_query(
|
|||||||
if( wrapped.pcache_init ){
|
if( wrapped.pcache_init ){
|
||||||
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj("pcache", -1));
|
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj("pcache", -1));
|
||||||
}
|
}
|
||||||
if( sqlite3GlobalConfig.isInit ){
|
|
||||||
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj("os", -1));
|
|
||||||
}
|
|
||||||
|
|
||||||
Tcl_SetObjResult(interp, pRet);
|
Tcl_SetObjResult(interp, pRet);
|
||||||
return TCL_OK;
|
return TCL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sqlite3TestFailOsInit(void){
|
|
||||||
return (wrapped.mem.xMalloc && wrapped.osinit_fail);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Sqlitetest_init_Init(Tcl_Interp *interp){
|
int Sqlitetest_init_Init(Tcl_Interp *interp){
|
||||||
static struct {
|
static struct {
|
||||||
char *zName;
|
char *zName;
|
||||||
|
@@ -9,6 +9,11 @@
|
|||||||
#
|
#
|
||||||
#***********************************************************************
|
#***********************************************************************
|
||||||
#
|
#
|
||||||
|
# This file implements regression tests for SQLite library. The
|
||||||
|
# focus of this file is testing the effects of a failure in
|
||||||
|
# sqlite3_initialize().
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
set testdir [file dirname $argv0]
|
set testdir [file dirname $argv0]
|
||||||
source $testdir/tester.tcl
|
source $testdir/tester.tcl
|
||||||
@@ -16,11 +21,10 @@ source $testdir/tester.tcl
|
|||||||
db close
|
db close
|
||||||
|
|
||||||
foreach {t failed rc started} {
|
foreach {t failed rc started} {
|
||||||
1.1 {} SQLITE_OK {mutex mem pcache os}
|
1.1 {} SQLITE_OK {mutex mem pcache}
|
||||||
1.2 {mutex} SQLITE_ERROR {}
|
1.2 {mutex} SQLITE_ERROR {}
|
||||||
1.3 {mem} SQLITE_ERROR {mutex}
|
1.3 {mem} SQLITE_ERROR {mutex}
|
||||||
1.4 {pcache} SQLITE_ERROR {mutex mem}
|
1.4 {pcache} SQLITE_ERROR {mutex mem}
|
||||||
1.5 {os} SQLITE_ERROR {mutex mem pcache}
|
|
||||||
} {
|
} {
|
||||||
do_test init-$t.1 {
|
do_test init-$t.1 {
|
||||||
eval init_wrapper_install $failed
|
eval init_wrapper_install $failed
|
||||||
@@ -45,12 +49,31 @@ foreach {t failed rc started} {
|
|||||||
} SQLITE_OK
|
} SQLITE_OK
|
||||||
do_test init-$t.7 {
|
do_test init-$t.7 {
|
||||||
init_wrapper_query
|
init_wrapper_query
|
||||||
} {mutex mem pcache os}
|
} {mutex mem pcache}
|
||||||
do_test init-$t.8 {
|
do_test init-$t.8 {
|
||||||
init_wrapper_uninstall
|
init_wrapper_uninstall
|
||||||
} {}
|
} {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
source $testdir/malloc_common.tcl
|
||||||
|
if {$MEMDEBUG} {
|
||||||
|
do_malloc_test init-2 -tclprep {
|
||||||
|
db close
|
||||||
|
init_wrapper_install
|
||||||
|
} -tclbody {
|
||||||
|
set rc [sqlite3_initialize]
|
||||||
|
if {[string match "SQLITE*NOMEM" $rc]} {error "out of memory"}
|
||||||
|
} -cleanup {
|
||||||
|
set zRepeat "transient"
|
||||||
|
if {$::iRepeat} {set zRepeat "persistent"}
|
||||||
|
do_test init-2.$zRepeat.$::n.x {
|
||||||
|
init_wrapper_clear
|
||||||
|
sqlite3_initialize
|
||||||
|
} SQLITE_OK
|
||||||
|
init_wrapper_uninstall
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
autoinstall_test_functions
|
autoinstall_test_functions
|
||||||
finish_test
|
finish_test
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user