/ Check-in [6a6b9430]
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: 007359b7 user: danielk1977 tags: trunk
16:31
Test cases for sqlite3_db_config() and sqlite3_db_status(). (CVS 5518) check-in: 6a6b9430 user: drh tags: trunk
15:06
Add a permutation test case for running all OOM tests with lookaside disabled. (CVS 5517) check-in: 3f70e03a user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Main file for the SQLite library.  The routines in this file
    13     13   ** implement the programmer interface to the library.  Routines in
    14     14   ** other files are for internal use by SQLite and should not be
    15     15   ** accessed by users of the library.
    16     16   **
    17         -** $Id: main.c,v 1.483 2008/07/28 19:34:53 drh Exp $
           17  +** $Id: main.c,v 1.484 2008/08/01 16:31:14 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include <ctype.h>
    21     21   
    22     22   #ifdef SQLITE_ENABLE_FTS3
    23     23   # include "fts3.h"
    24     24   #endif
................................................................................
   326    326   }
   327    327   
   328    328   /*
   329    329   ** Configuration settings for an individual database connection
   330    330   */
   331    331   int sqlite3_db_config(sqlite3 *db, int op, ...){
   332    332     va_list ap;
   333         -  int rc = SQLITE_OK;
          333  +  int rc;
   334    334     va_start(ap, op);
   335    335     switch( op ){
   336    336       case SQLITE_CONFIG_LOOKASIDE: {
   337    337         int sz = va_arg(ap, int);
   338    338         int cnt = va_arg(ap, int);
   339    339         rc = setupLookaside(db, sz, cnt);
   340    340         break;
          341  +    }
          342  +    default: {
          343  +      rc = SQLITE_ERROR;
          344  +      break;
   341    345       }
   342    346     }
   343    347     va_end(ap);
   344    348     return rc;
   345    349   }
   346    350   
   347    351   /*

Changes to src/malloc.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   **
    13     13   ** Memory allocation functions used throughout sqlite.
    14     14   **
    15         -** $Id: malloc.c,v 1.32 2008/07/31 17:16:05 drh Exp $
           15  +** $Id: malloc.c,v 1.33 2008/08/01 16:31:14 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <stdarg.h>
    19     19   #include <ctype.h>
    20     20   
    21     21   /*
    22     22   ** This routine runs when the memory allocator sees that the
................................................................................
   108    108     if( sqlite3Config.m.xMalloc==0 ){
   109    109       sqlite3MemSetDefault();
   110    110     }
   111    111     memset(&mem0, 0, sizeof(mem0));
   112    112     if( sqlite3Config.bCoreMutex ){
   113    113       mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
   114    114     }
   115         -  if( sqlite3Config.pScratch && sqlite3Config.szScratch>=3000
   116         -      && sqlite3Config.nScratch>0 ){
          115  +  if( sqlite3Config.pScratch && sqlite3Config.szScratch>=100
          116  +      && sqlite3Config.nScratch>=0 ){
   117    117       int i;
   118    118       sqlite3Config.szScratch -= 4;
   119    119       mem0.aScratchFree = (u32*)&((char*)sqlite3Config.pScratch)
   120    120                     [sqlite3Config.szScratch*sqlite3Config.nScratch];
   121    121       for(i=0; i<sqlite3Config.nScratch; i++){ mem0.aScratchFree[i] = i; }
   122    122       mem0.nScratchFree = sqlite3Config.nScratch;
   123    123     }else{
   124    124       sqlite3Config.pScratch = 0;
   125    125       sqlite3Config.szScratch = 0;
   126    126     }
   127    127     if( sqlite3Config.pPage && sqlite3Config.szPage>=512
   128         -      && sqlite3Config.nPage>1 ){
          128  +      && sqlite3Config.nPage>=1 ){
   129    129       int i;
   130    130       int overhead;
   131    131       int sz = sqlite3Config.szPage;
   132    132       int n = sqlite3Config.nPage;
   133    133       overhead = (4*n + sz - 1)/sz;
   134    134       sqlite3Config.nPage -= overhead;
   135    135       mem0.aPageFree = (u32*)&((char*)sqlite3Config.pPage)

Changes to src/status.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   **
    13     13   ** This module implements the sqlite3_status() interface and related
    14     14   ** functionality.
    15     15   **
    16         -** $Id: status.c,v 1.5 2008/07/28 19:34:54 drh Exp $
           16  +** $Id: status.c,v 1.6 2008/08/01 16:31:14 drh Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   
    20     20   /*
    21     21   ** Variables in which to record status information.
    22     22   */
    23     23   static struct {
................................................................................
    99     99         *pCurrent = db->lookaside.nOut;
   100    100         *pHighwater = db->lookaside.mxOut;
   101    101         if( resetFlag ){
   102    102           db->lookaside.mxOut = db->lookaside.nOut;
   103    103         }
   104    104         break;
   105    105       }
          106  +    default: {
          107  +      return SQLITE_ERROR;
          108  +    }
   106    109     }
   107    110     return SQLITE_OK;
   108    111   }

Changes to src/test_malloc.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   **
    13     13   ** This file contains code used to implement test interfaces to the
    14     14   ** memory allocation subsystem.
    15     15   **
    16         -** $Id: test_malloc.c,v 1.44 2008/07/31 17:16:05 drh Exp $
           16  +** $Id: test_malloc.c,v 1.45 2008/08/01 16:31:14 drh Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "tcl.h"
    20     20   #include <stdlib.h>
    21     21   #include <string.h>
    22     22   #include <assert.h>
    23     23   
................................................................................
   882    882     if( Tcl_GetIntFromObj(interp, objv[1], &sz) ) return TCL_ERROR;
   883    883     if( Tcl_GetIntFromObj(interp, objv[2], &N) ) return TCL_ERROR;
   884    884     free(buf);
   885    885     if( sz<0 ){
   886    886       buf = 0;
   887    887       rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, 0, 0, 0);
   888    888     }else{
   889         -    buf = malloc( sz*N );
          889  +    buf = malloc( sz*N + 1 );
   890    890       rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, buf, sz, N);
   891    891     }
   892    892     pResult = Tcl_NewObj();
   893    893     Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(rc));
   894    894     Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(N));
   895    895     Tcl_SetObjResult(interp, pResult);
   896    896     return TCL_OK;
................................................................................
  1067   1067       szBuf = nByte;
  1068   1068       rc = sqlite3_config(SQLITE_CONFIG_HEAP, zBuf, nByte, nMinAlloc);
  1069   1069     }
  1070   1070   
  1071   1071     Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
  1072   1072     return TCL_OK;
  1073   1073   }
         1074  +
         1075  +/*
         1076  +** tclcmd:     sqlite3_config_error  [DB]
         1077  +**
         1078  +** Invoke sqlite3_config() or sqlite3_db_config() with invalid
         1079  +** opcodes and verify that they return errors.
         1080  +*/
         1081  +static int test_config_error(
         1082  +  void * clientData, 
         1083  +  Tcl_Interp *interp,
         1084  +  int objc,
         1085  +  Tcl_Obj *CONST objv[]
         1086  +){
         1087  +  sqlite3 *db;
         1088  +  int getDbPointer(Tcl_Interp*, const char*, sqlite3**);
         1089  +
         1090  +  if( objc!=2 && objc!=1 ){
         1091  +    Tcl_WrongNumArgs(interp, 1, objv, "[DB]");
         1092  +    return TCL_ERROR;
         1093  +  }
         1094  +  if( objc==2 ){
         1095  +    if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
         1096  +    if( sqlite3_db_config(db, 99999)!=SQLITE_ERROR ){
         1097  +      Tcl_AppendResult(interp, 
         1098  +            "sqlite3_db_config(db, 99999) does not return SQLITE_ERROR",
         1099  +            (char*)0);
         1100  +      return TCL_ERROR;
         1101  +    }
         1102  +  }else{
         1103  +    if( sqlite3_config(99999)!=SQLITE_ERROR ){
         1104  +      Tcl_AppendResult(interp, 
         1105  +          "sqlite3_config(99999) does not return SQLITE_ERROR",
         1106  +          (char*)0);
         1107  +      return TCL_ERROR;
         1108  +    }
         1109  +  }
         1110  +  return TCL_OK;
         1111  +}
  1074   1112   
  1075   1113   /*
  1076   1114   ** Usage:    
  1077   1115   **
  1078   1116   **   sqlite3_dump_memsys3  FILENAME
  1079   1117   **   sqlite3_dump_memsys5  FILENAME
  1080   1118   **
................................................................................
  1267   1305        { "sqlite3_status",             test_status                   ,0 },
  1268   1306        { "sqlite3_db_status",          test_db_status                ,0 },
  1269   1307        { "install_malloc_faultsim",    test_install_malloc_faultsim  ,0 },
  1270   1308        { "sqlite3_config_heap",        test_config_heap              ,0 },
  1271   1309        { "sqlite3_config_memstatus",   test_config_memstatus         ,0 },
  1272   1310        { "sqlite3_config_chunkalloc",  test_config_chunkalloc        ,0 },
  1273   1311        { "sqlite3_config_lookaside",   test_config_lookaside         ,0 },
         1312  +     { "sqlite3_config_error",       test_config_error             ,0 },
  1274   1313        { "sqlite3_db_config_lookaside",test_db_config_lookaside      ,0 },
  1275   1314        { "sqlite3_dump_memsys3",       test_dump_memsys3             ,3 },
  1276   1315        { "sqlite3_dump_memsys5",       test_dump_memsys3             ,5 }
  1277   1316     };
  1278   1317     int i;
  1279   1318     for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
  1280   1319       ClientData c = (ClientData)aObjCmd[i].clientData;
  1281   1320       Tcl_CreateObjCommand(interp, aObjCmd[i].zName, aObjCmd[i].xProc, c, 0);
  1282   1321     }
  1283   1322     return TCL_OK;
  1284   1323   }
  1285   1324   #endif

Added test/lookaside.test.

            1  +# 2008 August 01
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +# Tests for the lookaside memory allocator.
           13  +#
           14  +# $Id: lookaside.test,v 1.1 2008/08/01 16:31:14 drh Exp $
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +
           19  +# Make sure sqlite3_db_config() and sqlite3_db_status are working.
           20  +#
           21  +do_test lookaside-1.1 {
           22  +  catch {sqlite3_config_error db}
           23  +} {0}
           24  +do_test lookaside-1.2 {
           25  +  sqlite3_db_config_lookaside db 20 20
           26  +} {0}
           27  +do_test lookaside-1.3 {
           28  +  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
           29  +} {0 0 0}
           30  +do_test lookaside-1.4 {
           31  +  db eval {CREATE TABLE t1(x);}
           32  +  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
           33  +} {0 7 20}
           34  +do_test lookaside-1.5 {
           35  +  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 1
           36  +} {0 7 20}
           37  +do_test lookaside-1.6 {
           38  +  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
           39  +} {0 7 7}
           40  +do_test lookaside-1.7 {
           41  +  db cache flush
           42  +  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
           43  +} {0 0 7}
           44  +do_test lookaside-1.8 {
           45  +  db cache flush
           46  +  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 1
           47  +} {0 0 7}
           48  +do_test lookaside-1.9 {
           49  +  db cache flush
           50  +  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
           51  +} {0 0 0}
           52  +
           53  +do_test lookaside-2.1 {
           54  +  sqlite3_db_config_lookaside db 100 1000
           55  +} {0}
           56  +do_test lookaside-2.2 {
           57  +  db eval {CREATE TABLE t2(x);}
           58  +  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
           59  +} {0 10 48}
           60  +do_test lookaside-2.3 {
           61  +  sqlite3_db_config_lookaside db 50 50
           62  +} {5}  ;# SQLITE_BUSY
           63  +do_test lookaside-2.4 {
           64  +  db cache flush
           65  +  sqlite3_db_config_lookaside db 50 50
           66  +} {0}  ;# SQLITE_OK
           67  +
           68  +# sqlite3_db_status() with an invalid verb returns an error.
           69  +#
           70  +do_test lookaside-3.1 {
           71  +  sqlite3_db_status db 99999 0
           72  +} {1 0 0}
           73  +
           74  +# Test that an invalid verb on sqlite3_config() is detected and
           75  +# reported as an error.
           76  +#
           77  +do_test lookaside-4.1 {
           78  +  db close
           79  +  sqlite3_shutdown
           80  +  catch sqlite3_config_error
           81  +} {0}
           82  +sqlite3_initialize