/ Check-in [ed8b2525]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:ed8b2525006ae7f8cacd01b291760513fdbdff57
User & Date: drh 2008-07-10 18:13:42
Context
2008-07-10
20:41
Fix a bug in the mutex-testing logic introduced by check-in (5389). (CVS 5390) check-in: 8fc462b6 user: drh tags: trunk
18:13
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) check-in: ed8b2525 user: drh tags: trunk
17:59
Fix a crash in flattenSubquery(). (CVS 5388) check-in: 9c8b97ef user: danielk1977 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/main.c.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250





251
252
253
254
255
256
257
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** 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 $
*/
#include "sqliteInt.h"
#include <ctype.h>

#ifdef SQLITE_ENABLE_FTS3
# include "fts3.h"
#endif
................................................................................

    case SQLITE_CONFIG_HEAP: {
      /* Designate a buffer for heap memory space */
      sqlite3Config.pHeap = va_arg(ap, void*);
      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
      ** 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;
      break;
    }
#endif






    default: {
      rc = SQLITE_ERROR;
      break;
    }
  }
  va_end(ap);







|







 







|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.475 2008/07/10 18:13:42 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

#ifdef SQLITE_ENABLE_FTS3
# include "fts3.h"
#endif
................................................................................

    case SQLITE_CONFIG_HEAP: {
      /* Designate a buffer for heap memory space */
      sqlite3Config.pHeap = va_arg(ap, void*);
      sqlite3Config.nHeap = va_arg(ap, int);
      sqlite3Config.mnReq = va_arg(ap, int);

      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_MEMSYS3
        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;
    }

    default: {
      rc = SQLITE_ERROR;
      break;
    }
  }
  va_end(ap);

Changes to src/mem2.c.

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
...
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
** to obtain the memory it needs while adding lots of additional debugging
** information to each allocation in order to help detect and fix memory
** leaks and memory usage errors.
**
** 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 $
*/
#include "sqliteInt.h"

/*
** This version of the memory allocator is used only if the
** SQLITE_MEMDEBUG macro is defined
*/
................................................................................
  return SQLITE_OK;
}

/*
** Deinitialize the memory allocation subsystem.
*/
static void sqlite3MemShutdown(void *NotUsed){
  sqlite3_mutex_free(mem.mutex);
  mem.mutex = 0;
}

/*
** Round up a request size to the next valid allocation size.
*/
static int sqlite3MemRoundup(int n){







|







 







<







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
...
170
171
172
173
174
175
176

177
178
179
180
181
182
183
** to obtain the memory it needs while adding lots of additional debugging
** information to each allocation in order to help detect and fix memory
** leaks and memory usage errors.
**
** This file contains implementations of the low-level memory allocation
** routines specified in the sqlite3_mem_methods object.
**
** $Id: mem2.c,v 1.34 2008/07/10 18:13:42 drh Exp $
*/
#include "sqliteInt.h"

/*
** This version of the memory allocator is used only if the
** SQLITE_MEMDEBUG macro is defined
*/
................................................................................
  return SQLITE_OK;
}

/*
** Deinitialize the memory allocation subsystem.
*/
static void sqlite3MemShutdown(void *NotUsed){

  mem.mutex = 0;
}

/*
** Round up a request size to the next valid allocation size.
*/
static int sqlite3MemRoundup(int n){

Changes to src/sqlite.h.in.

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
....
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115

1116
1117
1118
1119
1120
1121
1122
....
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
** on how SQLite interfaces are suppose to operate.
**
** The name of this file under configuration management is "sqlite.h.in".
** The makefile makes some minor changes to this file (such as inserting
** 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 $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
#include <stdarg.h>     /* Needed for the definition of va_list */

/*
** Make sure we can call this stuff from C++.
................................................................................
** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd>
**
** <dt>SQLITE_CONFIG_HEAP</dt>
** <dd>This option specifies a static memory buffer that SQLite will use
** 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>

**
** <dt>SQLITE_CONFIG_MUTEX</dt>
** <dd>This option takes a single argument which is a pointer to an
** instance of the [sqlite3_mutex_methods] structure.  The argument specifies
** alternative low-level mutex routines to be used in place
** the mutex routines built into SQLite.</dd>
**
................................................................................
** <dd>This option takes a single argument which is a pointer to an
** instance of the [sqlite3_mutex_methods] structure.  The
** [sqlite3_mutex_methods]
** structure is filled with the currently defined mutex routines.
** 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 */
#define SQLITE_CONFIG_SERIALIZED    3  /* nil */
#define SQLITE_CONFIG_MALLOC        4  /* sqlite3_mem_methods* */
#define SQLITE_CONFIG_GETMALLOC     5  /* sqlite3_mem_methods* */
#define SQLITE_CONFIG_SCRATCH       6  /* void*, int sz, int N */
#define SQLITE_CONFIG_PAGECACHE     7  /* void*, int sz, int N */
#define SQLITE_CONFIG_HEAP          8  /* void*, int nByte, int min */
#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}
**
** The sqlite3_extended_result_codes() routine enables or disables the
** [extended result codes] feature of SQLite. The extended result
** codes are disabled by default for historical compatibility considerations.







|







 







|
|
|
|
|
|
>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<












|
<







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
....
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
....
1125
1126
1127
1128
1129
1130
1131

















1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144

1145
1146
1147
1148
1149
1150
1151
** on how SQLite interfaces are suppose to operate.
**
** The name of this file under configuration management is "sqlite.h.in".
** The makefile makes some minor changes to this file (such as inserting
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
**
** @(#) $Id: sqlite.h.in,v 1.367 2008/07/10 18:13:42 drh Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
#include <stdarg.h>     /* Needed for the definition of va_list */

/*
** Make sure we can call this stuff from C++.
................................................................................
** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd>
**
** <dt>SQLITE_CONFIG_HEAP</dt>
** <dd>This option specifies a static memory buffer that SQLite will use
** 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.  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
** instance of the [sqlite3_mutex_methods] structure.  The argument specifies
** alternative low-level mutex routines to be used in place
** the mutex routines built into SQLite.</dd>
**
................................................................................
** <dd>This option takes a single argument which is a pointer to an
** instance of the [sqlite3_mutex_methods] structure.  The
** [sqlite3_mutex_methods]
** structure is filled with the currently defined mutex routines.
** 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>

















*/
#define SQLITE_CONFIG_SINGLETHREAD  1  /* nil */
#define SQLITE_CONFIG_MULTITHREAD   2  /* nil */
#define SQLITE_CONFIG_SERIALIZED    3  /* nil */
#define SQLITE_CONFIG_MALLOC        4  /* sqlite3_mem_methods* */
#define SQLITE_CONFIG_GETMALLOC     5  /* sqlite3_mem_methods* */
#define SQLITE_CONFIG_SCRATCH       6  /* void*, int sz, int N */
#define SQLITE_CONFIG_PAGECACHE     7  /* void*, int sz, int N */
#define SQLITE_CONFIG_HEAP          8  /* void*, int nByte, int min */
#define SQLITE_CONFIG_MEMSTATUS     9  /* boolean */
#define SQLITE_CONFIG_MUTEX        10  /* sqlite3_mutex_methods* */
#define SQLITE_CONFIG_GETMUTEX     11  /* sqlite3_mutex_methods* */



/*
** CAPI3REF: Enable Or Disable Extended Result Codes {F12200}
**
** The sqlite3_extended_result_codes() routine enables or disables the
** [extended result codes] feature of SQLite. The extended result
** codes are disabled by default for historical compatibility considerations.

Changes to src/test_malloc.c.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
231
232
233
234
235
236
237




238
239
240
241
242
243
244
...
925
926
927
928
929
930
931






















932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
....
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126

1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
**    May you share freely, never taking more than you give.
**
*************************************************************************
**
** 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 $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>

................................................................................
** Transform pointers to text and back again
*/
static void pointerToText(void *p, char *z){
  static const char zHex[] = "0123456789abcdef";
  int i, k;
  unsigned int u;
  sqlite3_uint64 n;




  if( sizeof(n)==sizeof(p) ){
    memcpy(&n, &p, sizeof(p));
  }else if( sizeof(u)==sizeof(p) ){
    memcpy(&u, &p, sizeof(u));
    n = u;
  }else{
    assert( 0 );
................................................................................
  }
  pResult = Tcl_NewObj();
  Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(rc));
  Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(N));
  Tcl_SetObjResult(interp, pResult);
  return TCL_OK;
}























/*
** Usage:
**
**   sqlite3_config_heap ?-memsys3? NBYTE NMINALLOC
*/
static int test_config_heap(
  void * clientData, 
  Tcl_Interp *interp,
  int objc,
  Tcl_Obj *CONST objv[]
){
  static char zBuf[1048576];
  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");
    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);
  }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);
  return TCL_OK;
}

/*
................................................................................
*/
int Sqlitetest_malloc_Init(Tcl_Interp *interp){
  static struct {
     char *zName;
     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_config_heap",        test_config_heap              ,0 },

     { "sqlite3_dump_memsys3",       test_dump_memsys3             ,3 },
     { "sqlite3_dump_memsys5",       test_dump_memsys3             ,5 }
  };
  int i;
  for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
    ClientData c = (ClientData)aObjCmd[i].clientData;
    Tcl_CreateObjCommand(interp, aObjCmd[i].zName, aObjCmd[i].xProc, c, 0);
  }
  return TCL_OK;
}
#endif







|







 







>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




|











<




<
<
<
<
<

|






<
<
|





<
<
<







 







|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

>











9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
...
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973

974
975
976
977





978
979
980
981
982
983
984
985


986
987
988
989
990
991



992
993
994
995
996
997
998
....
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
**    May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code used to implement test interfaces to the
** memory allocation subsystem.
**
** $Id: test_malloc.c,v 1.36 2008/07/10 18:13:42 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>

................................................................................
** Transform pointers to text and back again
*/
static void pointerToText(void *p, char *z){
  static const char zHex[] = "0123456789abcdef";
  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) ){
    memcpy(&u, &p, sizeof(u));
    n = u;
  }else{
    assert( 0 );
................................................................................
  }
  pResult = Tcl_NewObj();
  Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(rc));
  Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(N));
  Tcl_SetObjResult(interp, pResult);
  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 NBYTE NMINALLOC
*/
static int test_config_heap(
  void * clientData, 
  Tcl_Interp *interp,
  int objc,
  Tcl_Obj *CONST objv[]
){
  static char zBuf[1048576];
  int nByte;         /* Size of buffer to pass to sqlite3_config() */
  int nMinAlloc;     /* Size of minimum allocation */
  int rc;            /* Return code of sqlite3_config() */


  Tcl_Obj * CONST *aArg = &objv[1];
  int nArg = objc-1;






  if( nArg!=2 ){
    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 ){


    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);



  }

  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
  return TCL_OK;
}

/*
................................................................................
*/
int Sqlitetest_malloc_Init(Tcl_Interp *interp){
  static struct {
     char *zName;
     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_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 }
  };
  int i;
  for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
    ClientData c = (ClientData)aObjCmd[i].clientData;
    Tcl_CreateObjCommand(interp, aObjCmd[i].zName, aObjCmd[i].xProc, c, 0);
  }
  return TCL_OK;
}
#endif

Changes to src/test_mutex.c.

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
..
29
30
31
32
33
34
35

36
37
38
39
40
41
42
...
116
117
118
119
120
121
122

123
124
125
126
127
128
129
...
214
215
216
217
218
219
220

221
222
223
224
225
226
227
...
304
305
306
307
308
309
310








311
312
313
314
315
316
317
...
330
331
332
333
334
335
336

337
338


339

340
341
342
343
344
345
346
347
...
360
361
362
363
364
365
366


367
368
**
**    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.
**
*************************************************************************
** 
** $Id: test_mutex.c,v 1.7 2008/07/10 17:52:49 danielk1977 Exp $
*/

#include "tcl.h"
#include "sqlite3.h"
#include <stdlib.h>
#include <assert.h>
#include <string.h>
................................................................................
  int eType;
};

/* State variables */
static struct test_mutex_globals {
  int isInstalled;              /* True if installed */
  int disableInit;              /* True to cause sqlite3_initalize() 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 */
  sqlite3_mutex aStatic[6];     /* The six static mutexes */
} g;

/* Return true if the countable mutex is currently held */
................................................................................

/*
** Try to enter a mutex.  Return true on success.
*/
static int counterMutexTry(sqlite3_mutex *p){
  assert( g.isInit );
  g.aCounter[p->eType]++;

  return g.m.xMutexTry(p->pReal);
}

/* Leave a mutex
*/
static void counterMutexLeave(sqlite3_mutex *p){
  assert( g.isInit );
................................................................................

  if( isInstall ){
    assert( g.m.xMutexAlloc==0 );
    rc = sqlite3_config(SQLITE_CONFIG_GETMUTEX, &g.m);
    if( rc==SQLITE_OK ){
      sqlite3_config(SQLITE_CONFIG_MUTEX, &counter_methods);
    }

  }else{
    assert( g.m.xMutexAlloc );
    rc = sqlite3_config(SQLITE_CONFIG_MUTEX, &g.m);
    memset(&g.m, 0, sizeof(sqlite3_mutex_methods));
  }

  if( rc==SQLITE_OK ){
................................................................................
  sqlite3_snprintf(sizeof(zBuf), zBuf, "%p", p);
  Tcl_AppendResult(interp, zBuf, (char*)0);
  return TCL_OK;
}

/*
** sqlite3_config OPTION








*/
static int test_config(
  void * clientData,
  Tcl_Interp *interp,
  int objc,
  Tcl_Obj *CONST objv[]
){
................................................................................

  if( objc!=2 ){
    Tcl_WrongNumArgs(interp, 1, objv, "");
    return TCL_ERROR;
  }

  if( Tcl_GetIndexFromObjStruct(interp, objv[1], aOpt, s, "flag", 0, &i) ){

    return TCL_ERROR;
  }




  rc = sqlite3_config(aOpt[i].iValue);
  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
  return TCL_OK;
}

int Sqlitetest_mutex_Init(Tcl_Interp *interp){
  static struct {
    char *zName;
................................................................................
  for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
    Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
  }
  memset(&g, 0, sizeof(g));

  Tcl_LinkVar(interp, "disable_mutex_init", 
              (char*)&g.disableInit, TCL_LINK_INT);


  return SQLITE_OK;
}







|







 







>







 







>







 







>







 







>
>
>
>
>
>
>
>







 







>
|
|
>
>
|
>
|







 







>
>


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
..
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
...
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
...
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
...
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
...
375
376
377
378
379
380
381
382
383
384
385
**
**    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.
**
*************************************************************************
** 
** $Id: test_mutex.c,v 1.8 2008/07/10 18:13:42 drh Exp $
*/

#include "tcl.h"
#include "sqlite3.h"
#include <stdlib.h>
#include <assert.h>
#include <string.h>
................................................................................
  int eType;
};

/* State variables */
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 */
  sqlite3_mutex aStatic[6];     /* The six static mutexes */
} g;

/* Return true if the countable mutex is currently held */
................................................................................

/*
** Try to enter a mutex.  Return true on success.
*/
static int counterMutexTry(sqlite3_mutex *p){
  assert( g.isInit );
  g.aCounter[p->eType]++;
  if( g.disableTry ) return 0;
  return g.m.xMutexTry(p->pReal);
}

/* Leave a mutex
*/
static void counterMutexLeave(sqlite3_mutex *p){
  assert( g.isInit );
................................................................................

  if( isInstall ){
    assert( g.m.xMutexAlloc==0 );
    rc = sqlite3_config(SQLITE_CONFIG_GETMUTEX, &g.m);
    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);
    memset(&g.m, 0, sizeof(sqlite3_mutex_methods));
  }

  if( rc==SQLITE_OK ){
................................................................................
  sqlite3_snprintf(sizeof(zBuf), zBuf, "%p", p);
  Tcl_AppendResult(interp, zBuf, (char*)0);
  return TCL_OK;
}

/*
** 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,
  Tcl_Interp *interp,
  int objc,
  Tcl_Obj *CONST objv[]
){
................................................................................

  if( objc!=2 ){
    Tcl_WrongNumArgs(interp, 1, objv, "");
    return TCL_ERROR;
  }

  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(i);
  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
  return TCL_OK;
}

int Sqlitetest_mutex_Init(Tcl_Interp *interp){
  static struct {
    char *zName;
................................................................................
  for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
    Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
  }
  memset(&g, 0, sizeof(g));

  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;
}

Added test/memsubsys2.test.



























































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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

Changes to test/mutex2.test.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
80
81
82
83
84
85
86










87
#    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}
................................................................................
} {}

# Restore the system to a functional state
#
install_mutex_counters 0
set disable_mutex_init 0
autoinstall_test_functions










finish_test







|







 







>
>
>
>
>
>
>
>
>
>

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#    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.4 2008/07/10 18:13:43 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# deinitialize
#
catch {db close}
................................................................................
} {}

# Restore the system to a functional state
#
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

Changes to test/permutations.test.

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
..
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64




65
66
67
68
69
70
71
...
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
...
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
...
348
349
350
351
352
353
354
355
356
357
358


359
360
361
362
363
364
365
366
367
368
369
370
...
374
375
376
377
378
379
380
381
382
383
384


385
386
387
388
389
390
391
...
397
398
399
400
401
402
403
404

405
406
407
408
409
410
411
...
415
416
417
418
419
420
421















422
423
424
425
426
427
428
...
460
461
462
463
464
465
466
467
#
#    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.
#
#***********************************************************************
#
# $Id: permutations.test,v 1.10 2008/07/10 17:52:49 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Argument processing.
#
set ::testmode [lindex $argv 0]
................................................................................
  set ::testmode [list persistent_journal no_journal autovacuum_ioerr]
  set ISQUICK 1
}
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
  }
}
if {$::testmode eq "targets"} { 
  puts ""
  puts -nonewline "veryquick            "
  puts "Same as persistent_journal and no_journal"
  puts -nonewline "quick                "
  puts "Same as persistent_journal, no_journal and autovacuum_ioerr"
  puts -nonewline "all                  "
  puts "Everything except autovacuum_crash"
}

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




}
set ALLTESTS [list]
foreach filename [glob $testdir/*.test] {
  set filename [file tail $filename]
  if {[lsearch $EXCLUDE $filename] < 0} { lappend ALLTESTS $filename }
}

................................................................................
run_tests "memsubsys1" -description {
  Tests using pre-allocated page and scratch blocks
} -initialize {
  sqlite3_shutdown
  sqlite3_config_pagecache 4096 24
  sqlite3_config_scratch 25000 1
  sqlite3_initialize
} -exclude {
  memsubsys1.test
} -shutdown {
  catch {db close}
  sqlite3_shutdown
  sqlite3_config_pagecache 0 0
  sqlite3_config_scratch 0 0
  sqlite3_initialize
}
................................................................................
run_tests "memsubsys2" -description {
  Tests using small pre-allocated page and scratch blocks
} -initialize {
  sqlite3_shutdown
  sqlite3_config_pagecache 512 5
  sqlite3_config_scratch 1000 1
  sqlite3_initialize
} -exclude {
  memsubsys1.test
} -shutdown {
  catch {db close}
  sqlite3_shutdown
  sqlite3_config_pagecache 0 0
  sqlite3_config_scratch 0 0
  sqlite3_initialize
}
................................................................................
  pragma auto_vacuum = 1
} -include ioerr.test

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


  } -initialize {
    catch {db close}
    sqlite3_reset_auto_extension
    sqlite3_shutdown
    sqlite3_config_heap -memsys3 1000000 0
    install_malloc_faultsim 1 
    sqlite3_initialize
    autoinstall_test_functions
  } -shutdown {
    catch {db close}
    sqlite3_reset_auto_extension
    sqlite3_shutdown
................................................................................
  }
}

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


  } -initialize {
    catch {db close}
    sqlite3_reset_auto_extension
    sqlite3_shutdown
    sqlite3_config_heap 1000000 64
    install_malloc_faultsim 1 
    sqlite3_initialize
................................................................................
    sqlite3_config_heap 0 0
    install_malloc_faultsim 1 
    sqlite3_initialize
  }

  run_tests "memsys5-2" -description {
    Run tests using the allocator in mem5.c in a different configuration.
  } -include { select1.test 

  } -initialize {
    catch {db close}
    sqlite3_reset_auto_extension
    sqlite3_shutdown
    sqlite3_config_heap 250000 16
    install_malloc_faultsim 1 
    sqlite3_initialize
................................................................................
    sqlite3_reset_auto_extension
    sqlite3_shutdown
    sqlite3_config_heap 0 0
    install_malloc_faultsim 1 
    sqlite3_initialize
  }
}
















# run_tests "crash_safe_append" -description {
#   Run crash.test with persistent journals on a SAFE_APPEND file-system.
# } -initialize {
#   rename crashsql sa_crashsql
#   proc crashsql {args} {
#     set options [lrange $args 0 [expr {[llength $args]-2}]]
................................................................................

# Restore the [do_test] command.
#
rename do_test ""
rename really_do_test do_test

finish_test








|







 







|













|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>







 







<
<







 







<
<







 







|
|
|
|
>
>




|







 







|
|
|
|
>
>







 







|
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
..
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
...
142
143
144
145
146
147
148


149
150
151
152
153
154
155
...
160
161
162
163
164
165
166


167
168
169
170
171
172
173
...
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
...
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
...
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
...
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
...
480
481
482
483
484
485
486

#
#    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.
#
#***********************************************************************
#
# $Id: permutations.test,v 1.11 2008/07/10 18:13:43 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Argument processing.
#
set ::testmode [lindex $argv 0]
................................................................................
  set ::testmode [list persistent_journal no_journal autovacuum_ioerr]
  set ISQUICK 1
}
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 no_mutex_try
  }
}
if {$::testmode eq "targets"} { 
  puts ""
  puts -nonewline "veryquick            "
  puts "Same as persistent_journal and no_journal"
  puts -nonewline "quick                "
  puts "Same as persistent_journal, no_journal and autovacuum_ioerr"
  puts -nonewline "all                  "
  puts "Everything except autovacuum_crash"
}

set EXCLUDE {
  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] {
  set filename [file tail $filename]
  if {[lsearch $EXCLUDE $filename] < 0} { lappend ALLTESTS $filename }
}

................................................................................
run_tests "memsubsys1" -description {
  Tests using pre-allocated page and scratch blocks
} -initialize {
  sqlite3_shutdown
  sqlite3_config_pagecache 4096 24
  sqlite3_config_scratch 25000 1
  sqlite3_initialize


} -shutdown {
  catch {db close}
  sqlite3_shutdown
  sqlite3_config_pagecache 0 0
  sqlite3_config_scratch 0 0
  sqlite3_initialize
}
................................................................................
run_tests "memsubsys2" -description {
  Tests using small pre-allocated page and scratch blocks
} -initialize {
  sqlite3_shutdown
  sqlite3_config_pagecache 512 5
  sqlite3_config_scratch 1000 1
  sqlite3_initialize


} -shutdown {
  catch {db close}
  sqlite3_shutdown
  sqlite3_config_pagecache 0 0
  sqlite3_config_scratch 0 0
  sqlite3_initialize
}
................................................................................
  pragma auto_vacuum = 1
} -include ioerr.test

ifcapable mem3 {
  run_tests "memsys3" -description {
    Run tests using the allocator in mem3.c.
  } -exclude {
    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 1000000 0
    install_malloc_faultsim 1 
    sqlite3_initialize
    autoinstall_test_functions
  } -shutdown {
    catch {db close}
    sqlite3_reset_auto_extension
    sqlite3_shutdown
................................................................................
  }
}

ifcapable mem5 {
  run_tests "memsys5" -description {
    Run tests using the allocator in mem5.c.
  } -exclude {
    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 1000000 64
    install_malloc_faultsim 1 
    sqlite3_initialize
................................................................................
    sqlite3_config_heap 0 0
    install_malloc_faultsim 1 
    sqlite3_initialize
  }

  run_tests "memsys5-2" -description {
    Run tests using the allocator in mem5.c in a different configuration.
  } -include {
    select1.test 
  } -initialize {
    catch {db close}
    sqlite3_reset_auto_extension
    sqlite3_shutdown
    sqlite3_config_heap 250000 16
    install_malloc_faultsim 1 
    sqlite3_initialize
................................................................................
    sqlite3_reset_auto_extension
    sqlite3_shutdown
    sqlite3_config_heap 0 0
    install_malloc_faultsim 1 
    sqlite3_initialize
  }
}

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 {
#   rename crashsql sa_crashsql
#   proc crashsql {args} {
#     set options [lrange $args 0 [expr {[llength $args]-2}]]
................................................................................

# Restore the [do_test] command.
#
rename do_test ""
rename really_do_test do_test

finish_test