/ Check-in [6a6b94302a]
Login

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

Overview
Comment:Test cases for sqlite3_db_config() and sqlite3_db_status(). (CVS 5518)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6a6b94302acdfe6404b04bff1cc8d16c1ef69df9
User & Date: drh 2008-08-01 16:31:14
Context
2008-08-01
17:37
Test that virtual table methods xBestIndex, xOpen, xFilter, xNext, xColumn, xRowid, xUpdate, xSync and xBegin can all return error messages using the sqlite3_vtab.zErrMsg variable. (CVS 5519) check-in: 007359b770 user: danielk1977 tags: trunk
16:31
Test cases for sqlite3_db_config() and sqlite3_db_status(). (CVS 5518) check-in: 6a6b94302a user: drh tags: trunk
15:06
Add a permutation test case for running all OOM tests with lookaside disabled. (CVS 5517) check-in: 3f70e03ae8 user: drh 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
...
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340




341
342
343
344
345
346
347
**
*************************************************************************
** 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.483 2008/07/28 19:34:53 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

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

/*
** Configuration settings for an individual database connection
*/
int sqlite3_db_config(sqlite3 *db, int op, ...){
  va_list ap;
  int rc = SQLITE_OK;
  va_start(ap, op);
  switch( op ){
    case SQLITE_CONFIG_LOOKASIDE: {
      int sz = va_arg(ap, int);
      int cnt = va_arg(ap, int);
      rc = setupLookaside(db, sz, cnt);
      break;




    }
  }
  va_end(ap);
  return rc;
}

/*







|







 







|







>
>
>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
**
*************************************************************************
** 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.484 2008/08/01 16:31:14 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

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

/*
** Configuration settings for an individual database connection
*/
int sqlite3_db_config(sqlite3 *db, int op, ...){
  va_list ap;
  int rc;
  va_start(ap, op);
  switch( op ){
    case SQLITE_CONFIG_LOOKASIDE: {
      int sz = va_arg(ap, int);
      int cnt = va_arg(ap, int);
      rc = setupLookaside(db, sz, cnt);
      break;
    }
    default: {
      rc = SQLITE_ERROR;
      break;
    }
  }
  va_end(ap);
  return rc;
}

/*

Changes to src/malloc.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
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
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
**
** Memory allocation functions used throughout sqlite.
**
** $Id: malloc.c,v 1.32 2008/07/31 17:16:05 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
#include <ctype.h>

/*
** This routine runs when the memory allocator sees that the
................................................................................
  if( sqlite3Config.m.xMalloc==0 ){
    sqlite3MemSetDefault();
  }
  memset(&mem0, 0, sizeof(mem0));
  if( sqlite3Config.bCoreMutex ){
    mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
  }
  if( sqlite3Config.pScratch && sqlite3Config.szScratch>=3000
      && sqlite3Config.nScratch>0 ){
    int i;
    sqlite3Config.szScratch -= 4;
    mem0.aScratchFree = (u32*)&((char*)sqlite3Config.pScratch)
                  [sqlite3Config.szScratch*sqlite3Config.nScratch];
    for(i=0; i<sqlite3Config.nScratch; i++){ mem0.aScratchFree[i] = i; }
    mem0.nScratchFree = sqlite3Config.nScratch;
  }else{
    sqlite3Config.pScratch = 0;
    sqlite3Config.szScratch = 0;
  }
  if( sqlite3Config.pPage && sqlite3Config.szPage>=512
      && sqlite3Config.nPage>1 ){
    int i;
    int overhead;
    int sz = sqlite3Config.szPage;
    int n = sqlite3Config.nPage;
    overhead = (4*n + sz - 1)/sz;
    sqlite3Config.nPage -= overhead;
    mem0.aPageFree = (u32*)&((char*)sqlite3Config.pPage)







|







 







|
|











|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
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
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
**
** Memory allocation functions used throughout sqlite.
**
** $Id: malloc.c,v 1.33 2008/08/01 16:31:14 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
#include <ctype.h>

/*
** This routine runs when the memory allocator sees that the
................................................................................
  if( sqlite3Config.m.xMalloc==0 ){
    sqlite3MemSetDefault();
  }
  memset(&mem0, 0, sizeof(mem0));
  if( sqlite3Config.bCoreMutex ){
    mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
  }
  if( sqlite3Config.pScratch && sqlite3Config.szScratch>=100
      && sqlite3Config.nScratch>=0 ){
    int i;
    sqlite3Config.szScratch -= 4;
    mem0.aScratchFree = (u32*)&((char*)sqlite3Config.pScratch)
                  [sqlite3Config.szScratch*sqlite3Config.nScratch];
    for(i=0; i<sqlite3Config.nScratch; i++){ mem0.aScratchFree[i] = i; }
    mem0.nScratchFree = sqlite3Config.nScratch;
  }else{
    sqlite3Config.pScratch = 0;
    sqlite3Config.szScratch = 0;
  }
  if( sqlite3Config.pPage && sqlite3Config.szPage>=512
      && sqlite3Config.nPage>=1 ){
    int i;
    int overhead;
    int sz = sqlite3Config.szPage;
    int n = sqlite3Config.nPage;
    overhead = (4*n + sz - 1)/sz;
    sqlite3Config.nPage -= overhead;
    mem0.aPageFree = (u32*)&((char*)sqlite3Config.pPage)

Changes to src/status.c.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
99
100
101
102
103
104
105



106
107
108
**    May you share freely, never taking more than you give.
**
*************************************************************************
**
** This module implements the sqlite3_status() interface and related
** functionality.
**
** $Id: status.c,v 1.5 2008/07/28 19:34:54 drh Exp $
*/
#include "sqliteInt.h"

/*
** Variables in which to record status information.
*/
static struct {
................................................................................
      *pCurrent = db->lookaside.nOut;
      *pHighwater = db->lookaside.mxOut;
      if( resetFlag ){
        db->lookaside.mxOut = db->lookaside.nOut;
      }
      break;
    }



  }
  return SQLITE_OK;
}







|







 







>
>
>



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
99
100
101
102
103
104
105
106
107
108
109
110
111
**    May you share freely, never taking more than you give.
**
*************************************************************************
**
** This module implements the sqlite3_status() interface and related
** functionality.
**
** $Id: status.c,v 1.6 2008/08/01 16:31:14 drh Exp $
*/
#include "sqliteInt.h"

/*
** Variables in which to record status information.
*/
static struct {
................................................................................
      *pCurrent = db->lookaside.nOut;
      *pHighwater = db->lookaside.mxOut;
      if( resetFlag ){
        db->lookaside.mxOut = db->lookaside.nOut;
      }
      break;
    }
    default: {
      return SQLITE_ERROR;
    }
  }
  return SQLITE_OK;
}

Changes to src/test_malloc.c.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
....
1067
1068
1069
1070
1071
1072
1073






































1074
1075
1076
1077
1078
1079
1080
....
1267
1268
1269
1270
1271
1272
1273

1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
**    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.44 2008/07/31 17:16:05 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>

................................................................................
  if( Tcl_GetIntFromObj(interp, objv[1], &sz) ) return TCL_ERROR;
  if( Tcl_GetIntFromObj(interp, objv[2], &N) ) return TCL_ERROR;
  free(buf);
  if( sz<0 ){
    buf = 0;
    rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, 0, 0, 0);
  }else{
    buf = malloc( sz*N );
    rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, buf, sz, N);
  }
  pResult = Tcl_NewObj();
  Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(rc));
  Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(N));
  Tcl_SetObjResult(interp, pResult);
  return TCL_OK;
................................................................................
    szBuf = nByte;
    rc = sqlite3_config(SQLITE_CONFIG_HEAP, zBuf, nByte, nMinAlloc);
  }

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







































/*
** Usage:    
**
**   sqlite3_dump_memsys3  FILENAME
**   sqlite3_dump_memsys5  FILENAME
**
................................................................................
     { "sqlite3_status",             test_status                   ,0 },
     { "sqlite3_db_status",          test_db_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_config_chunkalloc",  test_config_chunkalloc        ,0 },
     { "sqlite3_config_lookaside",   test_config_lookaside         ,0 },

     { "sqlite3_db_config_lookaside",test_db_config_lookaside      ,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
...
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
....
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
....
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
**    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.45 2008/08/01 16:31:14 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>

................................................................................
  if( Tcl_GetIntFromObj(interp, objv[1], &sz) ) return TCL_ERROR;
  if( Tcl_GetIntFromObj(interp, objv[2], &N) ) return TCL_ERROR;
  free(buf);
  if( sz<0 ){
    buf = 0;
    rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, 0, 0, 0);
  }else{
    buf = malloc( sz*N + 1 );
    rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, buf, sz, N);
  }
  pResult = Tcl_NewObj();
  Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(rc));
  Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(N));
  Tcl_SetObjResult(interp, pResult);
  return TCL_OK;
................................................................................
    szBuf = nByte;
    rc = sqlite3_config(SQLITE_CONFIG_HEAP, zBuf, nByte, nMinAlloc);
  }

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

/*
** tclcmd:     sqlite3_config_error  [DB]
**
** Invoke sqlite3_config() or sqlite3_db_config() with invalid
** opcodes and verify that they return errors.
*/
static int test_config_error(
  void * clientData, 
  Tcl_Interp *interp,
  int objc,
  Tcl_Obj *CONST objv[]
){
  sqlite3 *db;
  int getDbPointer(Tcl_Interp*, const char*, sqlite3**);

  if( objc!=2 && objc!=1 ){
    Tcl_WrongNumArgs(interp, 1, objv, "[DB]");
    return TCL_ERROR;
  }
  if( objc==2 ){
    if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
    if( sqlite3_db_config(db, 99999)!=SQLITE_ERROR ){
      Tcl_AppendResult(interp, 
            "sqlite3_db_config(db, 99999) does not return SQLITE_ERROR",
            (char*)0);
      return TCL_ERROR;
    }
  }else{
    if( sqlite3_config(99999)!=SQLITE_ERROR ){
      Tcl_AppendResult(interp, 
          "sqlite3_config(99999) does not return SQLITE_ERROR",
          (char*)0);
      return TCL_ERROR;
    }
  }
  return TCL_OK;
}

/*
** Usage:    
**
**   sqlite3_dump_memsys3  FILENAME
**   sqlite3_dump_memsys5  FILENAME
**
................................................................................
     { "sqlite3_status",             test_status                   ,0 },
     { "sqlite3_db_status",          test_db_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_config_chunkalloc",  test_config_chunkalloc        ,0 },
     { "sqlite3_config_lookaside",   test_config_lookaside         ,0 },
     { "sqlite3_config_error",       test_config_error             ,0 },
     { "sqlite3_db_config_lookaside",test_db_config_lookaside      ,0 },
     { "sqlite3_dump_memsys3",       test_dump_memsys3             ,3 },
     { "sqlite3_dump_memsys5",       test_dump_memsys3             ,5 }
  };
  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

Added test/lookaside.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
# 2008 August 01
#
# 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.
#
#***********************************************************************
#
# Tests for the lookaside memory allocator.
#
# $Id: lookaside.test,v 1.1 2008/08/01 16:31:14 drh Exp $

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

# Make sure sqlite3_db_config() and sqlite3_db_status are working.
#
do_test lookaside-1.1 {
  catch {sqlite3_config_error db}
} {0}
do_test lookaside-1.2 {
  sqlite3_db_config_lookaside db 20 20
} {0}
do_test lookaside-1.3 {
  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
} {0 0 0}
do_test lookaside-1.4 {
  db eval {CREATE TABLE t1(x);}
  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
} {0 7 20}
do_test lookaside-1.5 {
  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 1
} {0 7 20}
do_test lookaside-1.6 {
  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
} {0 7 7}
do_test lookaside-1.7 {
  db cache flush
  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
} {0 0 7}
do_test lookaside-1.8 {
  db cache flush
  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 1
} {0 0 7}
do_test lookaside-1.9 {
  db cache flush
  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
} {0 0 0}

do_test lookaside-2.1 {
  sqlite3_db_config_lookaside db 100 1000
} {0}
do_test lookaside-2.2 {
  db eval {CREATE TABLE t2(x);}
  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
} {0 10 48}
do_test lookaside-2.3 {
  sqlite3_db_config_lookaside db 50 50
} {5}  ;# SQLITE_BUSY
do_test lookaside-2.4 {
  db cache flush
  sqlite3_db_config_lookaside db 50 50
} {0}  ;# SQLITE_OK

# sqlite3_db_status() with an invalid verb returns an error.
#
do_test lookaside-3.1 {
  sqlite3_db_status db 99999 0
} {1 0 0}

# Test that an invalid verb on sqlite3_config() is detected and
# reported as an error.
#
do_test lookaside-4.1 {
  db close
  sqlite3_shutdown
  catch sqlite3_config_error
} {0}
sqlite3_initialize