aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2008-07-08 02:12:37 +0000
committerdrh <drh@noemail.net>2008-07-08 02:12:37 +0000
commitc8d75674d6dff8ade0e423a6a56888394bb6fddb (patch)
tree07bfebd30752692d0e44b1cd6533dc33adec921f
parentfb45d8c563db372c9a9cf67c5a58d2e3bf67152a (diff)
downloadsqlite-c8d75674d6dff8ade0e423a6a56888394bb6fddb.tar.gz
sqlite-c8d75674d6dff8ade0e423a6a56888394bb6fddb.zip
Add tests to verify correct behavior when mutex initialization fails. (CVS 5359)
FossilOrigin-Name: 65875005ac8bc7988d7d7d8e8b999857449568fd
-rw-r--r--manifest21
-rw-r--r--manifest.uuid2
-rw-r--r--src/test1.c26
-rw-r--r--src/test_autoext.c11
-rw-r--r--src/test_mutex.c27
-rw-r--r--test/date.test11
-rw-r--r--test/mutex1.test9
-rw-r--r--test/mutex2.test87
8 files changed, 166 insertions, 28 deletions
diff --git a/manifest b/manifest
index 708031cd7..317483bab 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Testing\scoverage\senhancements.\s(CVS\s5358)
-D 2008-07-08T00:06:50
+C Add\stests\sto\sverify\scorrect\sbehavior\swhen\smutex\sinitialization\sfails.\s(CVS\s5359)
+D 2008-07-08T02:12:37
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 325dfac0a0dd1cb4d975f1ace6453157892e6042
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -149,7 +149,7 @@ F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
F src/status.c 6cb10377992505bd69f1ca1d75c1240a65f25a58
F src/table.c 1fa8f8113ac9cbc09ae4801c6d2a7f0af82c5822
F src/tclsqlite.c 4dd9ee4cb44846ad9bcc4d0da8088c1e7d4b33d9
-F src/test1.c 92fcc114c60ea9c1c41437db43cfc5a920e7402a
+F src/test1.c 6baa867e394e55b5dbb0a2e605ba52a20fb671ce
F src/test2.c c46d146019ab6e37474e66b3c789e5237d9ea7b7
F src/test3.c 01ff03164cf6a2bededa3b44ecd481603e2644fc
F src/test4.c ff4ecde3cafc71337b04e8cb7da5bb88e85d70e7
@@ -159,7 +159,7 @@ F src/test7.c 19474b1802858cd2017493c907f70ac2d57ab092
F src/test8.c 3b85c05b15ccfc6844093791e83d5c8a1e0354ca
F src/test9.c 4615ef08750245a2d96aaa7cbe2fb4aff2b57acc
F src/test_async.c da9f58f49faccd3a26ba89f58de125862351b6e2
-F src/test_autoext.c 5e892ab84aece3f0428920bf46923f16ac83962a
+F src/test_autoext.c f53b0cdf7bf5f08100009572a5d65cdb540bd0ad
F src/test_btree.c c1308ba0b88ab577fa56c9e493a09829dfcded9c
F src/test_config.c e893a7195e975f133c4481d679089531c2970c73
F src/test_devsym.c 6012cb8e3acf812513511025a4fa5d626e0ba19b
@@ -168,7 +168,7 @@ F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f
F src/test_loadext.c df8ab3a6481ddebbdf0d28ebac5d9e0790f7860f
F src/test_malloc.c 62296810d3ee914fc3e05f2a8a69d8f8f42c32e1
F src/test_md5.c 28209a4e2068711b5443c33104fe41f21d160071
-F src/test_mutex.c 0a515271d8ee480b7929b8b2ba20a7bc2224ae9f
+F src/test_mutex.c 64c88ef9fed47c896fe470af03bffcd0f6f058f2
F src/test_onefile.c 243157b10275251c5dc2d6619aee2ff9ae22379c
F src/test_osinst.c 867f1317bd135f942a63eab5a78da40fc70d1493
F src/test_schema.c 4b4bf7bb329326458c491b0e6facd4c8c4c5b479
@@ -258,7 +258,7 @@ F test/crash7.test e20a7b9ee1d16eaef7c94a4cb7ed2191b4d05970
F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
F test/createtab.test 199cf68f44e5d9e87a0b8afc7130fdeb4def3272
F test/cse.test 4b8a49decaefccb835ecc67249277be491713f6c
-F test/date.test 1413c8a73d281f09afb8ac444c57958f5fbed3fc
+F test/date.test 4ea54e26feea7c24dfc7fad1b2b87da21ff12380
F test/default.test 252298e42a680146b1dd64f563b95bdf088d94fb
F test/delete.test f171c1011395a8dd63169438fe1d8cc625eb7442
F test/delete2.test c06be3806ba804bc8c6f134476816080280b40e3
@@ -414,7 +414,8 @@ F test/misc5.test 0b68dcb630d44af2dbcdca94dd2b17c8d580f6fa
F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
F test/misc7.test 26e0d948a413bca61ed031159907a03d64647409
F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33
-F test/mutex1.test 1c98e4d236444c6a1a912b9c48b4004eeba0d9a6
+F test/mutex1.test 77719e9da234ba23f50e89e9fb19be8c116ad27a
+F test/mutex2.test a006d753714ea7e00b90b6f9c061bdde5be16435
F test/nan.test 14c41572ff52dbc740b1c3303dd313a90dc6084c
F test/notnull.test 44d600f916b770def8b095a9962dbe3be5a70d82
F test/null.test a8b09b8ed87852742343b33441a9240022108993
@@ -599,7 +600,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 28f8b6bfcc3e169f8a54a6681395f2c85bf99cab
-R 45fa0fc8c38b488b294ddeb46f1ccc23
+P fe80aa58a4ac12db5a92d25d28165f5159f04533
+R f30d395fe0e995ac76915a06c1dd7771
U drh
-Z 80facad624be60e0509d94f9ed839a1b
+Z 4be64c0a5d2f09e2efc62714a2157dfd
diff --git a/manifest.uuid b/manifest.uuid
index f3d5af5d0..d12291df6 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-fe80aa58a4ac12db5a92d25d28165f5159f04533 \ No newline at end of file
+65875005ac8bc7988d7d7d8e8b999857449568fd \ No newline at end of file
diff --git a/src/test1.c b/src/test1.c
index 1baa8073f..2b98179fe 100644
--- a/src/test1.c
+++ b/src/test1.c
@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
-** $Id: test1.c,v 1.311 2008/07/07 17:53:08 drh Exp $
+** $Id: test1.c,v 1.312 2008/07/08 02:12:37 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -4426,6 +4426,29 @@ static int vfs_unlink_test(
}
/*
+** tclcmd: vfs_initfail_test
+**
+** This TCL command attempts to vfs_find and vfs_register when the
+** sqlite3_initialize() interface is failing. All calls should fail.
+*/
+static int vfs_initfail_test(
+ ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
+ Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
+ int objc, /* Number of arguments */
+ Tcl_Obj *CONST objv[] /* Command arguments */
+){
+ sqlite3_vfs one;
+ one.zName = "__one";
+
+ if( sqlite3_vfs_find(0) ) return TCL_ERROR;
+ sqlite3_vfs_register(&one, 0);
+ if( sqlite3_vfs_find(0) ) return TCL_ERROR;
+ sqlite3_vfs_register(&one, 1);
+ if( sqlite3_vfs_find(0) ) return TCL_ERROR;
+ return TCL_OK;
+}
+
+/*
** Saved VFSes
*/
static sqlite3_vfs *apVfs[20];
@@ -4778,6 +4801,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "sqlite3_global_recover", test_global_recover, 0 },
{ "working_64bit_int", working_64bit_int, 0 },
{ "vfs_unlink_test", vfs_unlink_test, 0 },
+ { "vfs_initfail_test", vfs_initfail_test, 0 },
{ "vfs_unregister_all", vfs_unregister_all, 0 },
{ "vfs_reregister_all", vfs_reregister_all, 0 },
{ "file_control_test", file_control_test, 0 },
diff --git a/src/test_autoext.c b/src/test_autoext.c
index 6c5b98370..11f541360 100644
--- a/src/test_autoext.c
+++ b/src/test_autoext.c
@@ -11,7 +11,7 @@
*************************************************************************
** Test extension for testing the sqlite3_auto_extension() function.
**
-** $Id: test_autoext.c,v 1.4 2008/03/19 23:52:35 mlcreech Exp $
+** $Id: test_autoext.c,v 1.5 2008/07/08 02:12:37 drh Exp $
*/
#include "tcl.h"
#include "sqlite3ext.h"
@@ -95,7 +95,8 @@ static int autoExtSqrObjCmd(
int objc,
Tcl_Obj *CONST objv[]
){
- sqlite3_auto_extension((void*)sqr_init);
+ int rc = sqlite3_auto_extension((void*)sqr_init);
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
return SQLITE_OK;
}
@@ -110,7 +111,8 @@ static int autoExtCubeObjCmd(
int objc,
Tcl_Obj *CONST objv[]
){
- sqlite3_auto_extension((void*)cube_init);
+ int rc = sqlite3_auto_extension((void*)cube_init);
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
return SQLITE_OK;
}
@@ -125,7 +127,8 @@ static int autoExtBrokenObjCmd(
int objc,
Tcl_Obj *CONST objv[]
){
- sqlite3_auto_extension((void*)broken_init);
+ int rc = sqlite3_auto_extension((void*)broken_init);
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
return SQLITE_OK;
}
diff --git a/src/test_mutex.c b/src/test_mutex.c
index c2df5563a..817de93ac 100644
--- a/src/test_mutex.c
+++ b/src/test_mutex.c
@@ -10,7 +10,7 @@
**
*************************************************************************
**
-** $Id: test_mutex.c,v 1.5 2008/07/08 00:06:50 drh Exp $
+** $Id: test_mutex.c,v 1.6 2008/07/08 02:12:37 drh Exp $
*/
#include "tcl.h"
@@ -65,7 +65,6 @@ static int counterMutexInit(void){
** Uninitialize the mutex subsystem
*/
static int counterMutexEnd(void){
- assert( g.isInit );
g.isInit = 0;
return g.m.xMutexEnd();
}
@@ -83,7 +82,7 @@ static sqlite3_mutex *counterMutexAlloc(int eType){
pReal = g.m.xMutexAlloc(eType);
if( !pReal ) return 0;
- if( eType==0 || eType==1 ){
+ if( eType==SQLITE_MUTEX_FAST || eType==SQLITE_MUTEX_RECURSIVE ){
pRet = (sqlite3_mutex *)malloc(sizeof(sqlite3_mutex));
}else{
pRet = &g.aStatic[eType-2];
@@ -100,7 +99,7 @@ static sqlite3_mutex *counterMutexAlloc(int eType){
static void counterMutexFree(sqlite3_mutex *p){
assert( g.isInit );
g.m.xMutexFree(p->pReal);
- if( p->eType==0 || p->eType==1 ){
+ if( p->eType==SQLITE_MUTEX_FAST || p->eType==SQLITE_MUTEX_RECURSIVE ){
free(p);
}
}
@@ -288,6 +287,25 @@ static int test_clear_mutex_counters(
}
/*
+** Create and free a mutex. Return the mutex pointer. The pointer
+** will be invalid since the mutex has already been freed. The
+** return pointer just checks to see if the mutex really was allocated.
+*/
+static int test_alloc_mutex(
+ void * clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ sqlite3_mutex *p = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
+ char zBuf[100];
+ sqlite3_mutex_free(p);
+ sqlite3_snprintf(sizeof(zBuf), zBuf, "%p", p);
+ Tcl_AppendResult(interp, zBuf, (char*)0);
+ return TCL_OK;
+}
+
+/*
** sqlite3_config OPTION
*/
static int test_config(
@@ -332,6 +350,7 @@ int Sqlitetest_mutex_Init(Tcl_Interp *interp){
{ "sqlite3_initialize", (Tcl_ObjCmdProc*)test_initialize },
{ "sqlite3_config", (Tcl_ObjCmdProc*)test_config },
+ { "alloc_dealloc_mutex", (Tcl_ObjCmdProc*)test_alloc_mutex },
{ "install_mutex_counters", (Tcl_ObjCmdProc*)test_install_mutex_counters },
{ "read_mutex_counters", (Tcl_ObjCmdProc*)test_read_mutex_counters },
{ "clear_mutex_counters", (Tcl_ObjCmdProc*)test_clear_mutex_counters },
diff --git a/test/date.test b/test/date.test
index 9b3c47821..466fb6516 100644
--- a/test/date.test
+++ b/test/date.test
@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing date and time functions.
#
-# $Id: date.test,v 1.30 2008/06/12 18:05:40 drh Exp $
+# $Id: date.test,v 1.31 2008/07/08 02:12:37 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -57,6 +57,7 @@ datetest 1.20 {julianday('2000-01-01 12:00:00.01')} 2451545.00000012
datetest 1.21 {julianday('2000-01-01 12:00:00.001')} 2451545.00000001
datetest 1.22 {julianday('2000-01-01 12:00:00.')} NULL
datetest 1.23 julianday(12345.6) 12345.6
+datetest 1.23b julianday('12345.6') 12345.6
datetest 1.24 {julianday('2001-01-01 12:00:00 bogus')} NULL
datetest 1.25 {julianday('2001-01-01 bogus')} NULL
datetest 1.26 {julianday('2001-01-01 12:60:00')} NULL
@@ -69,6 +70,7 @@ datetest 2.1b datetime(0,'unixepoc') NULL
datetest 2.1c datetime(0,'unixepochx') NULL
datetest 2.1d datetime('2003-10-22','unixepoch') NULL
datetest 2.2 datetime(946684800,'unixepoch') {2000-01-01 00:00:00}
+datetest 2.2b datetime('946684800','unixepoch') {2000-01-01 00:00:00}
datetest 2.3 {date('2003-10-22','weekday 0')} 2003-10-26
datetest 2.4 {date('2003-10-22','weekday 1')} 2003-10-27
datetest 2.4a {date('2003-10-22','weekday 1')} 2003-10-27
@@ -167,9 +169,10 @@ datetest 3.11.19 {strftime('%W %j',2454109.04140974)} {02 008}
datetest 3.11.20 {strftime('%W %j',2454109.04140975)} {02 008}
datetest 3.11.21 {strftime('%W %j',2454109.04140976)} {02 008}
datetest 3.11.22 {strftime('%W %j',2454109.04140977)} {02 008}
-datetest 3.11.22 {strftime('%W %j',2454109.04140978)} {02 008}
-datetest 3.11.22 {strftime('%W %j',2454109.04140979)} {02 008}
-datetest 3.11.22 {strftime('%W %j',2454109.04140980)} {02 008}
+datetest 3.11.23 {strftime('%W %j',2454109.04140978)} {02 008}
+datetest 3.11.24 {strftime('%W %j',2454109.04140979)} {02 008}
+datetest 3.11.25 {strftime('%W %j',2454109.04140980)} {02 008}
+datetest 3.11.99 {strftime('%W %j','2454109.04140970')} {02 008}
datetest 3.12 {strftime('%Y','2003-10-31 12:34:56.432')} 2003
datetest 3.13 {strftime('%%','2003-10-31 12:34:56.432')} %
datetest 3.14 {strftime('%_','2003-10-31 12:34:56.432')} NULL
diff --git a/test/mutex1.test b/test/mutex1.test
index ad71b8f47..38c4a3ef3 100644
--- a/test/mutex1.test
+++ b/test/mutex1.test
@@ -9,7 +9,7 @@
#
#***********************************************************************
#
-# $Id: mutex1.test,v 1.6 2008/06/28 11:23:00 danielk1977 Exp $
+# $Id: mutex1.test,v 1.7 2008/07/08 02:12:37 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -86,7 +86,7 @@ do_test mutex1-1.9 {
# * Multi-threaded mode,
# * Single-threaded mode.
#
-
+set enable_shared_cache [sqlite3_enable_shared_cache 1]
ifcapable threadsafe {
foreach {mode mutexes} {
singlethread {}
@@ -96,9 +96,9 @@ ifcapable threadsafe {
ifcapable memorymanage {
if {$mode ne "singlethread"} {
lappend mutexes static_lru static_lru2 static_mem2
- set mutexes [lsort $mutexes]
}
}
+
do_test mutex1.2.$mode.1 {
catch {db close}
sqlite3_shutdown
@@ -125,9 +125,10 @@ ifcapable threadsafe {
}
}
lsort $res
- } $mutexes
+ } [lsort $mutexes]
}
}
+sqlite3_enable_shared_cache $enable_shared_cache
do_test mutex1-X {
catch {db close}
diff --git a/test/mutex2.test b/test/mutex2.test
new file mode 100644
index 000000000..6a0dbd002
--- /dev/null
+++ b/test/mutex2.test
@@ -0,0 +1,87 @@
+# 2008 July 7
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+# Test scripts for deliberate failures of mutex routines.
+#
+# $Id: mutex2.test,v 1.3 2008/07/08 02:12:37 drh Exp $
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# deinitialize
+#
+catch {db close}
+sqlite3_reset_auto_extension
+sqlite3_shutdown
+install_mutex_counters 1
+
+# Fix the mutex subsystem so that it will not initialize. In other words,
+# make it so that sqlite3_initialize() always fails.
+#
+do_test mutex2-1.1 {
+ set ::disable_mutex_init 10
+ sqlite3_initialize
+} {SQLITE_IOERR}
+do_test mutex2-1.1 {
+ set ::disable_mutex_init 7
+ sqlite3_initialize
+} {SQLITE_NOMEM}
+
+proc utf16 {str} {
+ set r [encoding convertto unicode $str]
+ append r "\x00\x00"
+ return $r
+}
+
+# Now that sqlite3_initialize() is failing, try to run various APIs that
+# require that SQLite be initialized. Verify that they fail.
+#
+do_test mutex2-2.1 {
+ set ::disable_mutex_init 7
+ set rc [catch {sqlite db test.db} msg]
+ lappend rc $msg
+} {1 {out of memory}}
+ifcapable utf16 {
+ do_test mutex2-2.2 {
+ set db2 [sqlite3_open16 [utf16 test.db] {}]
+ } {0}
+ do_test mutex2-2.3 {
+ sqlite3_complete16 [utf16 {SELECT * FROM t1;}]
+ } {7}
+}
+do_test mutex2-2.4 {
+ sqlite3_mprintf_int {This is a test %d,%d,%d} 1 2 3
+} {This is a test 1,2,3}
+do_test mutex2-2.5 {
+ sqlite3_auto_extension_sqr
+} {7}
+do_test mutex2-2.6 {
+ sqlite3_reset_auto_extension
+} {}
+do_test mutex2-2.7 {
+ sqlite3_malloc 10000
+} {00000000}
+do_test mutex2-2.8 {
+ sqlite3_realloc 0 10000
+} {00000000}
+do_test mutex2-2.9 {
+ alloc_dealloc_mutex
+} {0}
+do_test mutex2-2.10 {
+ vfs_initfail_test
+} {}
+
+# Restore the system to a functional state
+#
+install_mutex_counters 0
+set disable_mutex_init 0
+autoinstall_test_functions
+finish_test