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

Enhancements to the testing logic for malloc and mutex. Only permit one

of MEMSYS3/5 to be compiled-in at a time.  Omit the SQLITE_CONFIG_MEMSYS3/5
configuration options. (CVS 5389)

FossilOrigin-Name: ed8b2525006ae7f8cacd01b291760513fdbdff57
This commit is contained in:
drh
2008-07-10 18:13:42 +00:00
parent 80b3c54851
commit 8a42cbd3f0
10 changed files with 334 additions and 127 deletions

View File

@@ -1,5 +1,5 @@
C Fix\sa\scrash\sin\sflattenSubquery().\s(CVS\s5388)
D 2008-07-10T17:59:12
C Enhancements\sto\sthe\stesting\slogic\sfor\smalloc\sand\smutex.\s\sOnly\spermit\sone\nof\sMEMSYS3/5\sto\sbe\scompiled-in\sat\sa\stime.\s\sOmit\sthe\sSQLITE_CONFIG_MEMSYS3/5\nconfiguration\soptions.\s(CVS\s5389)
D 2008-07-10T18:13:42
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in a03f7cb4f7ad50bc53a788c6c544430e81f95de4
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -114,11 +114,11 @@ F src/insert.c e8efc17d037346e4a4a6949e72aab850befe3d5d
F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e
F src/legacy.c 3626c71fb70912abec9a4312beba753a9ce800df
F src/loadext.c ae0eed9fa96d74172d2a90ee63b5bc36d284295c
F src/main.c 85517c4d61ed24f2d0230335aedd6270a69f59dd
F src/main.c ff7d9e39d014cc36246c334f6076e44e20db45ca
F src/malloc.c 226a532e9e371d1bb3de2553bdd1f9b600ef099c
F src/md5.c 008216bbb5d34c6fbab5357aa68575ad8a31516a
F src/mem1.c 8340fa5f969e9f9b9bdeb54106457a2003456d2b
F src/mem2.c 23f9538f35fbcd5665afe7056a56be0c7ed65aa7
F src/mem2.c 0fc5bd6581c80f3ebd9d0cdf0f3f9c08826397ba
F src/mem3.c abaf65e3fa911b8acdbb67a50a54ec149af55736
F src/mem4.c 6703adb1717b26d9d70a1c2586b4b7b7ffee7909
F src/mem5.c 6c711af220f2c1566724dc439a34a98f94ab01a0
@@ -142,7 +142,7 @@ F src/printf.c 8e5d410220cf8650f502caf71f0de979a3f9031e
F src/random.c 5c754319d38abdd6acd74601ee0105504adc508a
F src/select.c fcf51df1818a448edebf55b032d89771ba4536ef
F src/shell.c 484e7297e066f22830f9c15d7abbcdd2acb097b0
F src/sqlite.h.in 2fcdb1c1ee337d8371eb43a0c29294562b76ee23
F src/sqlite.h.in 8d25645bc8aee60e3089d05f3dbb8f66d1af0cd5
F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e
F src/sqliteInt.h ca0dc923bcc51bef0064f34628bd6daeb0d68d38
F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
@@ -166,9 +166,9 @@ F src/test_devsym.c 6012cb8e3acf812513511025a4fa5d626e0ba19b
F src/test_func.c ade4f0117cc96c5a05682e1ef38b84320a866ad9
F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f
F src/test_loadext.c df8ab3a6481ddebbdf0d28ebac5d9e0790f7860f
F src/test_malloc.c e9e1500f85c50964adc34892045410c08aaf67ff
F src/test_malloc.c 4f07302a0077f2c1730baa7aeb359e4f51960aa7
F src/test_md5.c 28209a4e2068711b5443c33104fe41f21d160071
F src/test_mutex.c 195d88dfc206d98ef6af3700c294c66a822e6378
F src/test_mutex.c 893cdb8a1d8015e0103c0fa48e2aaca2d40d4dc7
F src/test_onefile.c 243157b10275251c5dc2d6619aee2ff9ae22379c
F src/test_osinst.c 867f1317bd135f942a63eab5a78da40fc70d1493
F src/test_schema.c 4b4bf7bb329326458c491b0e6facd4c8c4c5b479
@@ -403,6 +403,7 @@ F test/manydb.test 8de36b8d33aab5ef295b11d9e95310aeded31af8
F test/memdb.test a67bda4ff90a38f2b19f6c7f95aa7289e051d893
F test/memleak.test d2d2a1ff7105d32dc3fdf691458cf6cba58c7217
F test/memsubsys1.test 209156a07aaf99d095ef2e3a3a0acd5d55c978f6
F test/memsubsys2.test c05b541f9c2a1234a9dc2ff2233b3a9544fa5139
F test/minmax.test 722d80816f7e096bf2c04f4111f1a6c1ba65453d
F test/minmax2.test 33504c01a03bd99226144e4b03f7631a274d66e0
F test/minmax3.test 05110398e065875b3d9315892889d3c87fccfe2b
@@ -415,7 +416,7 @@ F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
F test/misc7.test 68198e6a699f0e8e8e7641d597a9e77c87c961d6
F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33
F test/mutex1.test b0017a45203e92ddab9e27cc3d6bd5c8637925ac
F test/mutex2.test a006d753714ea7e00b90b6f9c061bdde5be16435
F test/mutex2.test 64a627f58c95bce467f4bce41e788b64268e3309
F test/nan.test 14c41572ff52dbc740b1c3303dd313a90dc6084c
F test/notnull.test 44d600f916b770def8b095a9962dbe3be5a70d82
F test/null.test a8b09b8ed87852742343b33441a9240022108993
@@ -425,7 +426,7 @@ F test/pager2.test c025f91b75fe65e85febda64d9416428b8a5cab5
F test/pager3.test 2323bf27fd5bd887b580247e5bce500ceee994b4
F test/pageropt.test 6df72c441db0a037b7ec6990d16311c24fbea77b
F test/pagesize.test e0a8b3fe80f8b8e808d94a00734c7a18c76c407e
F test/permutations.test 1a2047d4cded4f9c0a81fd16aa5ee47f9c3928de
F test/permutations.test bf962d39b77fd87555455d16bb1208d32a732c6d
F test/pragma.test e1984ed47f699a4a817008dab4111be31ee8b935
F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47
F test/printf.test 262a5acd3158f788e9bdf7f18d718f3af32ff6ef
@@ -600,7 +601,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P 7e58b78712420b3bd4320192a58d89eb71eecc9c
R 0939dee77d063e7cffac53f1e1ad55a1
U danielk1977
Z a0db231c1a42fdb08eeec046ea7b2e61
P 9c8b97ef593c17740640a01a7338164d7fbe070e
R 2fd49240ed9bef71f7d65c695010f7c4
U drh
Z ab81163c7db604825f9001df3cff3c52

View File

@@ -1 +1 @@
9c8b97ef593c17740640a01a7338164d7fbe070e
ed8b2525006ae7f8cacd01b291760513fdbdff57

View File

@@ -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.474 2008/07/10 17:52:49 danielk1977 Exp $
** $Id: main.c,v 1.475 2008/07/10 18:13:42 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -228,26 +228,31 @@ int sqlite3_config(int op, ...){
sqlite3Config.nHeap = va_arg(ap, int);
sqlite3Config.mnReq = va_arg(ap, int);
/* Fall through to install the mem5.c/mem3.c methods. If neither
** ENABLE_MEMSYS3 nor ENABLE_MEMSYS5 is defined, fall through to
if( sqlite3Config.pHeap==0 ){
/* If the heap pointer is NULL, then restore the malloc implementation
** back to NULL pointers too. This will cause the malloc to go
** back to its default implementation when sqlite3_initialize() is
** run.
*/
memset(&sqlite3Config.m, 0, sizeof(sqlite3Config.m));
}else{
/* The heap pointer is not NULL, then install one of the
** mem5.c/mem3.c methods. If neither ENABLE_MEMSYS3 nor
** ENABLE_MEMSYS5 is defined, return an error.
** the default case and return an error.
*/
}
#ifdef SQLITE_ENABLE_MEMSYS5
case SQLITE_CONFIG_MEMSYS5: {
sqlite3_mem_methods *p = sqlite3MemGetMemsys5();
sqlite3Config.m = *p;
break;
}
#endif
#ifdef SQLITE_ENABLE_MEMSYS3
case SQLITE_CONFIG_MEMSYS3: {
sqlite3_mem_methods *p = sqlite3MemGetMemsys3();
sqlite3Config.m = *p;
sqlite3Config.m = sqlite3MemGetMemsys3();
#endif
#ifdef SQLITE_ENABLE_MEMSYS5
sqlite3Config.m = sqlite3MemGetMemsys5();
#endif
#if !defined(SQLITE_ENABLE_MEMSYS3) && !defined(SQLITE_ENABLE_MEMSYS5)
rc = SQLITE_ERROR;
#endif
}
break;
}
#endif
default: {
rc = SQLITE_ERROR;

View File

@@ -19,7 +19,7 @@
** This file contains implementations of the low-level memory allocation
** routines specified in the sqlite3_mem_methods object.
**
** $Id: mem2.c,v 1.33 2008/06/19 01:03:18 drh Exp $
** $Id: mem2.c,v 1.34 2008/07/10 18:13:42 drh Exp $
*/
#include "sqliteInt.h"
@@ -174,7 +174,6 @@ static int sqlite3MemInit(void *NotUsed){
** Deinitialize the memory allocation subsystem.
*/
static void sqlite3MemShutdown(void *NotUsed){
sqlite3_mutex_free(mem.mutex);
mem.mutex = 0;
}

View File

@@ -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.366 2008/07/10 17:52:49 danielk1977 Exp $
** @(#) $Id: sqlite.h.in,v 1.367 2008/07/10 18:13:42 drh Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
@@ -1107,12 +1107,13 @@ struct sqlite3_mem_methods {
** for all of its dynamic memory allocation needs beyond those provided
** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
** There are three arguments: A pointer to the memory, the number of
** bytes in the memory buffer, and the minimum allocation size. When
** this configuration option is used, SQLite never calls the system
** malloc() implementation but instead uses the supplied memory buffer
** to satisfy all [sqlite3_malloc()] requests. This option is only
** available if either or both of SQLITE_ENABLE_MEMSYS3 and
** SQLITE_ENABLE_MEMSYS5 are defined during compilation.</dd>
** bytes in the memory buffer, and the minimum allocation size. If
** the first pointer (the memory pointer) is NULL, then SQLite reverts
** to using its default memory allocator (the system malloc() implementation),
** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. If the
** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
** allocator is engaged to handle all of SQLites memory allocation needs.</dd>
**
** <dt>SQLITE_CONFIG_MUTEX</dt>
** <dd>This option takes a single argument which is a pointer to an
@@ -1128,23 +1129,6 @@ struct sqlite3_mem_methods {
** This option can be used to overload the default mutex allocation
** routines with a wrapper used to track mutex usage for performance
** profiling or testing, for example.</dd>
**
** <dt>SQLITE_CONFIG_MEMSYS3</dt>
** <dd>This option is only available if SQLite is compiled with the
** SQLITE_ENABLE_MEMSYS3 symbol defined. It selects one of two memory
** allocation systems that use the block of memory supplied to sqlite
** using the SQLITE_CONFIG_HEAP option.
** </dd>
**
** <dt>SQLITE_CONFIG_MEMSYS5</dt>
** <dd>This option is only available if SQLite is compiled with the
** SQLITE_ENABLE_MEMSYS5 symbol defined. It selects one of two memory
** allocation systems that use the block of memory supplied to sqlite
** using the SQLITE_CONFIG_HEAP option. The memory allocation system
** selected by this option, "memsys5", is also installed by default
** when the SQLITE_CONFIG_HEAP option is set, so it is not usually
** necessary to use this option directly.
** </dd>
*/
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
@@ -1157,8 +1141,7 @@ struct sqlite3_mem_methods {
#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
#define SQLITE_CONFIG_MEMSYS3 12 /* nil */
#define SQLITE_CONFIG_MEMSYS5 13 /* nil */
/*
** CAPI3REF: Enable Or Disable Extended Result Codes {F12200}

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.35 2008/07/09 16:51:51 drh Exp $
** $Id: test_malloc.c,v 1.36 2008/07/10 18:13:42 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -235,6 +235,10 @@ static void pointerToText(void *p, char *z){
int i, k;
unsigned int u;
sqlite3_uint64 n;
if( p==0 ){
strcpy(z, "0");
return;
}
if( sizeof(n)==sizeof(p) ){
memcpy(&n, &p, sizeof(p));
}else if( sizeof(u)==sizeof(p) ){
@@ -930,10 +934,32 @@ static int test_config_pagecache(
return TCL_OK;
}
/*
** Usage: sqlite3_config_memstatus BOOLEAN
**
** Enable or disable memory status reporting using SQLITE_CONFIG_MEMSTATUS.
*/
static int test_config_memstatus(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
int enable, rc;
if( objc!=2 ){
Tcl_WrongNumArgs(interp, 1, objv, "BOOLEAN");
return TCL_ERROR;
}
if( Tcl_GetBooleanFromObj(interp, objv[1], &enable) ) return TCL_ERROR;
rc = sqlite3_config(SQLITE_CONFIG_MEMSTATUS, enable);
Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
return TCL_OK;
}
/*
** Usage:
**
** sqlite3_config_heap ?-memsys3? NBYTE NMINALLOC
** sqlite3_config_heap NBYTE NMINALLOC
*/
static int test_config_heap(
void * clientData,
@@ -945,35 +971,24 @@ static int test_config_heap(
int nByte; /* Size of buffer to pass to sqlite3_config() */
int nMinAlloc; /* Size of minimum allocation */
int rc; /* Return code of sqlite3_config() */
int isMemsys3 = 0; /* True if the -memsys3 switch is present */
Tcl_Obj * CONST *aArg = &objv[1];
int nArg = objc-1;
if( nArg>0 && 0==strcmp("-memsys3", Tcl_GetString(aArg[0])) ){
nArg--;
aArg++;
isMemsys3 = 1;
}
if( nArg!=2 ){
Tcl_WrongNumArgs(interp, 1, objv, "?-memsys3? NBYTE NMINALLOC");
Tcl_WrongNumArgs(interp, 1, objv, "NBYTE NMINALLOC");
return TCL_ERROR;
}
if( Tcl_GetIntFromObj(interp, aArg[0], &nByte) ) return TCL_ERROR;
if( Tcl_GetIntFromObj(interp, aArg[1], &nMinAlloc) ) return TCL_ERROR;
if( nByte==0 ){
sqlite3_mem_methods m;
memset(&m, 0, sizeof(sqlite3_mem_methods));
rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &m);
rc = sqlite3_config(SQLITE_CONFIG_HEAP, (void*)0, 0, 0);
}else{
if( nByte>sizeof(zBuf) ){
nByte = sizeof(zBuf);
}
rc = sqlite3_config(SQLITE_CONFIG_HEAP, zBuf, nByte, nMinAlloc);
if( isMemsys3 && rc==SQLITE_OK ){
rc = sqlite3_config(SQLITE_CONFIG_MEMSYS3);
}
}
Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
@@ -1105,25 +1120,26 @@ int Sqlitetest_malloc_Init(Tcl_Interp *interp){
Tcl_ObjCmdProc *xProc;
int clientData;
} aObjCmd[] = {
{ "sqlite3_malloc", test_malloc ,0. },
{ "sqlite3_realloc", test_realloc ,0. },
{ "sqlite3_free", test_free ,0. },
{ "memset", test_memset ,0. },
{ "memget", test_memget ,0. },
{ "sqlite3_memory_used", test_memory_used ,0. },
{ "sqlite3_memory_highwater", test_memory_highwater ,0. },
{ "sqlite3_memdebug_backtrace", test_memdebug_backtrace ,0. },
{ "sqlite3_memdebug_dump", test_memdebug_dump ,0. },
{ "sqlite3_memdebug_fail", test_memdebug_fail ,0. },
{ "sqlite3_memdebug_pending", test_memdebug_pending ,0. },
{ "sqlite3_memdebug_settitle", test_memdebug_settitle ,0. },
{ "sqlite3_memdebug_malloc_count", test_memdebug_malloc_count ,0. },
{ "sqlite3_memdebug_log", test_memdebug_log ,0. },
{ "sqlite3_config_scratch", test_config_scratch ,0. },
{ "sqlite3_config_pagecache", test_config_pagecache ,0. },
{ "sqlite3_status", test_status ,0. },
{ "install_malloc_faultsim", test_install_malloc_faultsim ,0. },
{ "sqlite3_malloc", test_malloc ,0 },
{ "sqlite3_realloc", test_realloc ,0 },
{ "sqlite3_free", test_free ,0 },
{ "memset", test_memset ,0 },
{ "memget", test_memget ,0 },
{ "sqlite3_memory_used", test_memory_used ,0 },
{ "sqlite3_memory_highwater", test_memory_highwater ,0 },
{ "sqlite3_memdebug_backtrace", test_memdebug_backtrace ,0 },
{ "sqlite3_memdebug_dump", test_memdebug_dump ,0 },
{ "sqlite3_memdebug_fail", test_memdebug_fail ,0 },
{ "sqlite3_memdebug_pending", test_memdebug_pending ,0 },
{ "sqlite3_memdebug_settitle", test_memdebug_settitle ,0 },
{ "sqlite3_memdebug_malloc_count", test_memdebug_malloc_count ,0 },
{ "sqlite3_memdebug_log", test_memdebug_log ,0 },
{ "sqlite3_config_scratch", test_config_scratch ,0 },
{ "sqlite3_config_pagecache", test_config_pagecache ,0 },
{ "sqlite3_status", test_status ,0 },
{ "install_malloc_faultsim", test_install_malloc_faultsim ,0 },
{ "sqlite3_config_heap", test_config_heap ,0 },
{ "sqlite3_config_memstatus", test_config_memstatus ,0 },
{ "sqlite3_dump_memsys3", test_dump_memsys3 ,3 },
{ "sqlite3_dump_memsys5", test_dump_memsys3 ,5 }
};

View File

@@ -10,7 +10,7 @@
**
*************************************************************************
**
** $Id: test_mutex.c,v 1.7 2008/07/10 17:52:49 danielk1977 Exp $
** $Id: test_mutex.c,v 1.8 2008/07/10 18:13:42 drh Exp $
*/
#include "tcl.h"
@@ -33,6 +33,7 @@ struct sqlite3_mutex {
static struct test_mutex_globals {
int isInstalled; /* True if installed */
int disableInit; /* True to cause sqlite3_initalize() to fail */
int disableTry; /* True to force sqlite3_mutex_try() to fail */
int isInit; /* True if initialized */
sqlite3_mutex_methods m; /* Interface to "real" mutex system */
int aCounter[8]; /* Number of grabs of each type of mutex */
@@ -120,6 +121,7 @@ static void counterMutexEnter(sqlite3_mutex *p){
static int counterMutexTry(sqlite3_mutex *p){
assert( g.isInit );
g.aCounter[p->eType]++;
if( g.disableTry ) return 0;
return g.m.xMutexTry(p->pReal);
}
@@ -218,6 +220,7 @@ static int test_install_mutex_counters(
if( rc==SQLITE_OK ){
sqlite3_config(SQLITE_CONFIG_MUTEX, &counter_methods);
}
g.disableTry = 0;
}else{
assert( g.m.xMutexAlloc );
rc = sqlite3_config(SQLITE_CONFIG_MUTEX, &g.m);
@@ -308,6 +311,14 @@ static int test_alloc_mutex(
/*
** sqlite3_config OPTION
**
** OPTION can be either one of the keywords:
**
** SQLITE_CONFIG_SINGLETHREAD
** SQLITE_CONFIG_MULTITHREAD
** SQLITE_CONFIG_SERIALIZED
**
** Or OPTION can be an raw integer.
*/
static int test_config(
void * clientData,
@@ -334,10 +345,14 @@ static int test_config(
}
if( Tcl_GetIndexFromObjStruct(interp, objv[1], aOpt, s, "flag", 0, &i) ){
if( Tcl_GetIntFromObj(interp, objv[1], &i) ){
return TCL_ERROR;
}
}else{
i = aOpt[i].iValue;
}
rc = sqlite3_config(aOpt[i].iValue);
rc = sqlite3_config(i);
Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
return TCL_OK;
}
@@ -364,5 +379,7 @@ int Sqlitetest_mutex_Init(Tcl_Interp *interp){
Tcl_LinkVar(interp, "disable_mutex_init",
(char*)&g.disableInit, TCL_LINK_INT);
Tcl_LinkVar(interp, "disable_mutex_try",
(char*)&g.disableTry, TCL_LINK_INT);
return SQLITE_OK;
}

157
test/memsubsys2.test Normal file
View File

@@ -0,0 +1,157 @@
# 2008 June 18
#
# 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.
#
#***********************************************************************
#
# This file contains tests of the memory allocation subsystem.
#
# $Id: memsubsys2.test,v 1.1 2008/07/10 18:13:43 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
sqlite3_reset_auto_extension
# This procedure constructs a new database in test.db. It fills
# this database with many small records (enough to force multiple
# rebalance operations in the btree-layer and to require a large
# page cache), verifies correct results, then returns.
#
proc build_test_db {testname pragmas} {
catch {db close}
file delete -force test.db test.db-journal
sqlite3 db test.db
db eval $pragmas
db eval {
CREATE TABLE t1(x, y);
CREATE TABLE t2(a, b);
CREATE INDEX i1 ON t1(x,y);
INSERT INTO t1 VALUES(1, 100);
INSERT INTO t1 VALUES(2, 200);
}
for {set i 2} {$i<5000} {incr i $i} {
db eval {INSERT INTO t2 SELECT * FROM t1}
db eval {INSERT INTO t1 SELECT a+$i, a+b*100 FROM t2}
db eval {DELETE FROM t2}
}
do_test $testname.1 {
db eval {SELECT count(*) FROM t1}
} 8192
integrity_check $testname.2
}
# Test 1: Verify that calling sqlite3_malloc(0) returns a NULL
# pointer.
#
set highwater [sqlite3_memory_highwater 0]
do_test memsubsys2-1.1 {
sqlite3_malloc 0
} {0}
do_test memsubsys2-1.2 {
sqlite3_memory_highwater 0
} $highwater
# Test 2: Verify that the highwater mark increases after a large
# allocation.
#
sqlite3_memory_highwater 1
set highwater [sqlite3_memory_highwater 0]
do_test memsubsys2-2.1 {
sqlite3_free [set x [sqlite3_malloc 100000]]
expr {$x!="0"}
} {1}
do_test memsubsys2-2.2 {
expr {[sqlite3_memory_highwater 0]>=[sqlite3_memory_used]+$highwater}
} {1}
# Test 3: Verify that turning of memstatus disables the statistics
# tracking.
#
db close
sqlite3_shutdown
sqlite3_config_memstatus 0
sqlite3_initialize
set highwater [sqlite3_memory_highwater 0]
do_test memsubsys2-3.1 {
set highwater
} {0}
do_test memsubsys2-3.2 {
sqlite3_malloc 0
} {0}
do_test memsubsys2-3.3 {
sqlite3_memory_highwater 0
} {0}
do_test memsubsys2-3.4 {
sqlite3_memory_used
} {0}
do_test memsubsys2-3.5 {
set ::allocation [sqlite3_malloc 100000]
expr {$::allocation!="0"}
} {1}
do_test memsubsys2-3.6 {
sqlite3_memory_highwater 0
} {0}
do_test memsubsys2-3.7 {
sqlite3_memory_used
} {0}
do_test memsubsys2-3.8 {
sqlite3_free $::allocation
} {}
do_test memsubsys2-3.9 {
sqlite3_free 0
} {}
# Test 4: Verify that turning on memstatus reenables the statistics
# tracking.
#
sqlite3_shutdown
sqlite3_config_memstatus 1
sqlite3_initialize
set highwater [sqlite3_memory_highwater 0]
do_test memsubsys2-4.1 {
set highwater
} {0}
do_test memsubsys2-4.2 {
sqlite3_malloc 0
} {0}
do_test memsubsys2-4.3 {
sqlite3_memory_highwater 0
} {0}
do_test memsubsys2-4.4 {
sqlite3_memory_used
} {0}
do_test memsubsys2-4.5 {
set ::allocation [sqlite3_malloc 100000]
expr {$::allocation!="0"}
} {1}
do_test memsubsys2-4.6 {
expr {[sqlite3_memory_highwater 0]>=100000}
} {1}
do_test memsubsys2-4.7 {
expr {[sqlite3_memory_used]>=100000}
} {1}
do_test memsubsys2-4.8 {
sqlite3_free $::allocation
} {}
do_test memsubsys2-4.9 {
sqlite3_free 0
} {}
do_test memsubsys2-4.10 {
expr {[sqlite3_memory_highwater 0]>=100000}
} {1}
do_test memsubsys2-4.11 {
sqlite3_memory_used
} {0}
autoinstall_test_functions
finish_test

View File

@@ -11,7 +11,7 @@
#
# Test scripts for deliberate failures of mutex routines.
#
# $Id: mutex2.test,v 1.3 2008/07/08 02:12:37 drh Exp $
# $Id: mutex2.test,v 1.4 2008/07/10 18:13:43 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -84,4 +84,14 @@ do_test mutex2-2.10 {
install_mutex_counters 0
set disable_mutex_init 0
autoinstall_test_functions
# Mutex allocation works now.
#
do_test mutex2-3.1 {
set ptr [alloc_dealloc_mutex]
expr {$ptr!=0}
} {1}
finish_test

View File

@@ -9,7 +9,7 @@
#
#***********************************************************************
#
# $Id: permutations.test,v 1.10 2008/07/10 17:52:49 danielk1977 Exp $
# $Id: permutations.test,v 1.11 2008/07/10 18:13:43 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -35,7 +35,7 @@ if {$::testmode eq "all"} {
set ::testmode {
memsubsys1 memsubsys2 singlethread multithread onefile utf16 exclusive
persistent_journal persistent_journal_error no_journal no_journal_error
autovacuum_ioerr
autovacuum_ioerr no_mutex_try
}
}
if {$::testmode eq "targets"} {
@@ -49,19 +49,23 @@ if {$::testmode eq "targets"} {
}
set EXCLUDE {
all.test async.test async2.test corrupt.test
crash.test crash2.test crash3.test crash4.test
crash6.test crash7.test exclusive3.test fts3.test
fuzz.test fuzz_malloc.test in2.test jrnlmode3.test
loadext.test mallocAll.test malloc.test malloc2.test
malloc3.test malloc4.test memleak.test misc7.test
misuse.test mutex2.test onefile.test quick.test
soak.test speed1.test speed1p.test speed2.test
speed3.test speed4.test speed4p.test sqllimits1.test
thread001.test thread002.test btree8.test utf16.test
shared_err.test vtab_err.test veryquick.test incrvacuum_ioerr.test
autovacuum_crash.test permutations.test
autovacuum_ioerr.test jrnlmode2.test jrnlmode4.test
all.test in2.test onefile.test
async2.test incrvacuum_ioerr.test permutations.test
async.test jrnlmode2.test quick.test
autovacuum_crash.test jrnlmode3.test shared_err.test
autovacuum_ioerr.test jrnlmode4.test soak.test
btree8.test loadext.test speed1p.test
corrupt.test malloc2.test speed1.test
crash2.test malloc3.test speed2.test
crash3.test malloc4.test speed3.test
crash4.test mallocAll.test speed4p.test
crash6.test malloc.test speed4.test
crash7.test memleak.test sqllimits1.test
crash.test memsubsys1.test thread001.test
exclusive3.test memsubsys2.test thread002.test
fts3.test misc7.test utf16.test
fuzz_malloc.test misuse.test veryquick.test
fuzz.test mutex2.test vtab_err.test
}
set ALLTESTS [list]
foreach filename [glob $testdir/*.test] {
@@ -142,8 +146,6 @@ run_tests "memsubsys1" -description {
sqlite3_config_pagecache 4096 24
sqlite3_config_scratch 25000 1
sqlite3_initialize
} -exclude {
memsubsys1.test
} -shutdown {
catch {db close}
sqlite3_shutdown
@@ -162,8 +164,6 @@ run_tests "memsubsys2" -description {
sqlite3_config_pagecache 512 5
sqlite3_config_scratch 1000 1
sqlite3_initialize
} -exclude {
memsubsys1.test
} -shutdown {
catch {db close}
sqlite3_shutdown
@@ -352,15 +352,17 @@ ifcapable mem3 {
run_tests "memsys3" -description {
Run tests using the allocator in mem3.c.
} -exclude {
incrblob2.test manydb.test autovacuum.test bigrow.test
collate5.test delete3.test index2.test ioerr.test join3.test
pagesize.test bitvec.test capi3.test memsubsys1.test limit.test
memdb.test capi3c.test
autovacuum.test delete3.test manydb.test
bigrow.test incrblob2.test memdb.test
bitvec.test index2.test memsubsys1.test
capi3c.test ioerr.test memsubsys2.test
capi3.test join3.test pagesize.test
collate5.test limit.test
} -initialize {
catch {db close}
sqlite3_reset_auto_extension
sqlite3_shutdown
sqlite3_config_heap -memsys3 1000000 0
sqlite3_config_heap 1000000 0
install_malloc_faultsim 1
sqlite3_initialize
autoinstall_test_functions
@@ -378,10 +380,12 @@ ifcapable mem5 {
run_tests "memsys5" -description {
Run tests using the allocator in mem5.c.
} -exclude {
incrblob2.test manydb.test autovacuum.test bigrow.test
collate5.test delete3.test index2.test ioerr.test join3.test
pagesize.test bitvec.test capi3.test memsubsys1.test limit.test
memdb.test capi3c.test func.test
autovacuum.test delete3.test manydb.test
bigrow.test incrblob2.test memdb.test
bitvec.test index2.test memsubsys1.test
capi3c.test ioerr.test memsubsys2.test
capi3.test join3.test pagesize.test
collate5.test limit.test
} -initialize {
catch {db close}
sqlite3_reset_auto_extension
@@ -401,7 +405,8 @@ ifcapable mem5 {
run_tests "memsys5-2" -description {
Run tests using the allocator in mem5.c in a different configuration.
} -include { select1.test
} -include {
select1.test
} -initialize {
catch {db close}
sqlite3_reset_auto_extension
@@ -420,6 +425,21 @@ ifcapable mem5 {
}
}
ifcapable threadsafe {
run_tests "no_mutex_try" -description {
The sqlite3_mutex_try() interface always fails
} -initialize {
catch {db close}
sqlite3_shutdown
install_mutex_counters 1
set ::disable_mutex_try 1
} -shutdown {
catch {db close}
sqlite3_shutdown
install_mutex_counters 0
}
}
# run_tests "crash_safe_append" -description {
# Run crash.test with persistent journals on a SAFE_APPEND file-system.
# } -initialize {
@@ -464,4 +484,3 @@ rename do_test ""
rename really_do_test do_test
finish_test