/ Check-in [2498d3ea]
Login

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

Overview
Comment:Add a completely new testing system for the Bitvec object. The new testing system uses sqlite3_test_control() instead of unpublished APIs. Now provides 100% condition/decision coverage. Obscure bugs in Bitvec found and fixed as a result of the enhanced coverage. (CVS 4902)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:2498d3ea36ecab6d9c0f04ef1c49d76a7a215a4f
User & Date: drh 2008-03-21 16:45:47
Context
2008-03-21
17:13
Make sure the text result of an aggregate function has the correct encoding. Ticket #3009. (CVS 4903) check-in: 13e388ce user: drh tags: trunk
16:45
Add a completely new testing system for the Bitvec object. The new testing system uses sqlite3_test_control() instead of unpublished APIs. Now provides 100% condition/decision coverage. Obscure bugs in Bitvec found and fixed as a result of the enhanced coverage. (CVS 4902) check-in: 2498d3ea user: drh tags: trunk
14:22
Add some more logging to the malloc system used when SQLITE_MEMDEBUG is defined. (CVS 4901) check-in: 79738f58 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/bitvec.c.

    28     28   ** Clear operations are exceedingly rare.  There are usually between
    29     29   ** 5 and 500 set operations per Bitvec object, though the number of sets can
    30     30   ** sometimes grow into tens of thousands or larger.  The size of the
    31     31   ** Bitvec object is the number of pages in the database file at the
    32     32   ** start of a transaction, and is thus usually less than a few thousand,
    33     33   ** but can be as large as 2 billion for a really big database.
    34     34   **
    35         -** @(#) $Id: bitvec.c,v 1.2 2008/03/14 13:02:08 mlcreech Exp $
           35  +** @(#) $Id: bitvec.c,v 1.3 2008/03/21 16:45:47 drh Exp $
    36     36   */
    37     37   #include "sqliteInt.h"
    38     38   
    39     39   #define BITVEC_SZ        512
    40     40   /* Round the union size down to the nearest pointer boundary, since that's how 
    41     41   ** it will be aligned within the Bitvec struct. */
    42         -#define BITVEC_USIZE     (((BITVEC_SZ-12)/sizeof(Bitvec *))*sizeof(Bitvec *))
           42  +#define BITVEC_USIZE     (((BITVEC_SZ-12)/sizeof(Bitvec*))*sizeof(Bitvec*))
    43     43   #define BITVEC_NCHAR     BITVEC_USIZE
    44     44   #define BITVEC_NBIT      (BITVEC_NCHAR*8)
    45     45   #define BITVEC_NINT      (BITVEC_USIZE/4)
    46     46   #define BITVEC_MXHASH    (BITVEC_NINT/2)
    47     47   #define BITVEC_NPTR      (BITVEC_USIZE/sizeof(Bitvec *))
    48     48   
    49     49   #define BITVEC_HASH(X)   (((X)*37)%BITVEC_NINT)
................................................................................
    97     97   
    98     98   /*
    99     99   ** Check to see if the i-th bit is set.  Return true or false.
   100    100   ** If p is NULL (if the bitmap has not been created) or if
   101    101   ** i is out of range, then return false.
   102    102   */
   103    103   int sqlite3BitvecTest(Bitvec *p, u32 i){
   104         -  assert( i>0 );
   105    104     if( p==0 ) return 0;
   106         -  if( i>p->iSize ) return 0;
          105  +  if( i>p->iSize || i==0 ) return 0;
   107    106     if( p->iSize<=BITVEC_NBIT ){
   108    107       i--;
   109    108       return (p->u.aBitmap[i/8] & (1<<(i&7)))!=0;
   110    109     }
   111    110     if( p->iDivisor>0 ){
   112    111       u32 bin = (i-1)/p->iDivisor;
   113    112       i = (i-1)%p->iDivisor + 1;
................................................................................
   126    125   /*
   127    126   ** Set the i-th bit.  Return 0 on success and an error code if
   128    127   ** anything goes wrong.
   129    128   */
   130    129   int sqlite3BitvecSet(Bitvec *p, u32 i){
   131    130     u32 h;
   132    131     assert( p!=0 );
          132  +  assert( i>0 );
   133    133     if( p->iSize<=BITVEC_NBIT ){
   134    134       i--;
   135    135       p->u.aBitmap[i/8] |= 1 << (i&7);
   136    136       return SQLITE_OK;
   137    137     }
   138    138     if( p->iDivisor ){
   139    139       u32 bin = (i-1)/p->iDivisor;
................................................................................
   155    155     p->nSet++;
   156    156     if( p->nSet>=BITVEC_MXHASH ){
   157    157       int j, rc;
   158    158       u32 aiValues[BITVEC_NINT];
   159    159       memcpy(aiValues, p->u.aHash, sizeof(aiValues));
   160    160       memset(p->u.apSub, 0, sizeof(p->u.apSub[0])*BITVEC_NPTR);
   161    161       p->iDivisor = (p->iSize + BITVEC_NPTR - 1)/BITVEC_NPTR;
   162         -    sqlite3BitvecSet(p, i);
   163         -    for(rc=j=0; j<BITVEC_NINT; j++){
          162  +    rc = sqlite3BitvecSet(p, i);
          163  +    for(j=0; j<BITVEC_NINT; j++){
   164    164         if( aiValues[j] ) rc |= sqlite3BitvecSet(p, aiValues[j]);
   165    165       }
   166    166       return rc;
   167    167     }
   168    168     p->u.aHash[h] = i;
   169    169     return SQLITE_OK;
   170    170   }
................................................................................
   171    171   
   172    172   /*
   173    173   ** Clear the i-th bit.  Return 0 on success and an error code if
   174    174   ** anything goes wrong.
   175    175   */
   176    176   void sqlite3BitvecClear(Bitvec *p, u32 i){
   177    177     assert( p!=0 );
          178  +  assert( i>0 );
   178    179     if( p->iSize<=BITVEC_NBIT ){
   179    180       i--;
   180    181       p->u.aBitmap[i/8] &= ~(1 << (i&7));
   181    182     }else if( p->iDivisor ){
   182    183       u32 bin = (i-1)/p->iDivisor;
   183    184       i = (i-1)%p->iDivisor + 1;
   184    185       if( p->u.apSub[bin] ){
................................................................................
   187    188     }else{
   188    189       int j;
   189    190       u32 aiValues[BITVEC_NINT];
   190    191       memcpy(aiValues, p->u.aHash, sizeof(aiValues));
   191    192       memset(p->u.aHash, 0, sizeof(p->u.aHash[0])*BITVEC_NINT);
   192    193       p->nSet = 0;
   193    194       for(j=0; j<BITVEC_NINT; j++){
   194         -      if( aiValues[j] && aiValues[j]!=i ) sqlite3BitvecSet(p, aiValues[j]);
          195  +      if( aiValues[j] && aiValues[j]!=i ){
          196  +        sqlite3BitvecSet(p, aiValues[j]);
          197  +      }
   195    198       }
   196    199     }
   197    200   }
   198    201   
   199    202   /*
   200    203   ** Destroy a bitmap object.  Reclaim all memory used.
   201    204   */
................................................................................
   205    208       int i;
   206    209       for(i=0; i<BITVEC_NPTR; i++){
   207    210         sqlite3BitvecDestroy(p->u.apSub[i]);
   208    211       }
   209    212     }
   210    213     sqlite3_free(p);
   211    214   }
          215  +
          216  +#ifndef SQLITE_OMIT_BUILTIN_TEST
          217  +/*
          218  +** Let V[] be an array of unsigned characters sufficient to hold
          219  +** up to N bits.  Let I be an integer between 0 and N.  0<=I<N.
          220  +** Then the following macros can be used to set, clear, or test
          221  +** individual bits within V.
          222  +*/
          223  +#define SETBIT(V,I)      V[I>>3] |= (1<<(I&7))
          224  +#define CLEARBIT(V,I)    V[I>>3] &= ~(1<<(I&7))
          225  +#define TESTBIT(V,I)     (V[I>>3]&(1<<(I&7)))!=0
          226  +
          227  +/*
          228  +** This routine runs an extensive test of the Bitvec code.
          229  +**
          230  +** The input is an array of integers that acts as a program
          231  +** to test the Bitvec.  The integers are opcodes followed
          232  +** by 0, 1, or 3 operands, depending on the opcode.  Another
          233  +** opcode follows immediately after the last operand.
          234  +**
          235  +** There are 6 opcodes numbered from 0 through 5.  0 is the
          236  +** "halt" opcode and causes the test to end.
          237  +**
          238  +**    0          Halt and return the number of errors
          239  +**    1 N S X    Set N bits beginning with S and incrementing by X
          240  +**    2 N S X    Clear N bits beginning with S and incrementing by X
          241  +**    3 N        Set N randomly chosen bits
          242  +**    4 N        Clear N randomly chosen bits
          243  +**    5 N S X    Set N bits from S increment X in array only, not in bitvec
          244  +**
          245  +** The opcodes 1 through 4 perform set and clear operations are performed
          246  +** on both a Bitvec object and on a linear array of bits obtained from malloc.
          247  +** Opcode 5 works on the linear array only, not on the Bitvec.
          248  +** Opcode 5 is used to deliberately induce a fault in order to
          249  +** confirm that error detection works.
          250  +**
          251  +** At the conclusion of the test the linear array is compared
          252  +** against the Bitvec object.  If there are any differences,
          253  +** an error is returned.  If they are the same, zero is returned.
          254  +**
          255  +** If a memory allocation error occurs, return -1.
          256  +*/
          257  +int sqlite3BitvecBuiltinTest(int sz, int *aOp){
          258  +  Bitvec *pBitvec = 0;
          259  +  unsigned char *pV = 0;
          260  +  int rc = -1;
          261  +  int i, nx, pc, op;
          262  +
          263  +  /* Allocate the Bitvec to be tested and a linear array of
          264  +  ** bits to act as the reference */
          265  +  pBitvec = sqlite3BitvecCreate( sz );
          266  +  pV = sqlite3_malloc( (sz+7)/8 + 1 );
          267  +  if( pBitvec==0 || pV==0 ) goto bitvec_end;
          268  +  memset(pV, 0, (sz+7)/8 + 1);
          269  +
          270  +  /* Run the program */
          271  +  pc = 0;
          272  +  while( (op = aOp[pc])!=0 ){
          273  +    switch( op ){
          274  +      case 1:
          275  +      case 2:
          276  +      case 5: {
          277  +        nx = 4;
          278  +        i = aOp[pc+2] - 1;
          279  +        aOp[pc+2] += aOp[pc+3];
          280  +        break;
          281  +      }
          282  +      case 3:
          283  +      case 4: 
          284  +      default: {
          285  +        nx = 2;
          286  +        sqlite3_randomness(sizeof(i), &i);
          287  +        break;
          288  +      }
          289  +    }
          290  +    if( (--aOp[pc+1]) > 0 ) nx = 0;
          291  +    pc += nx;
          292  +    i = (i & 0x7fffffff)%sz;
          293  +    if( (op & 1)!=0 ){
          294  +      SETBIT(pV, (i+1));
          295  +      if( op!=5 ){
          296  +        if( sqlite3BitvecSet(pBitvec, i+1) ) goto bitvec_end;
          297  +      }
          298  +    }else{
          299  +      CLEARBIT(pV, (i+1));
          300  +      sqlite3BitvecClear(pBitvec, i+1);
          301  +    }
          302  +  }
          303  +
          304  +  /* Test to make sure the linear array exactly matches the
          305  +  ** Bitvec object.  Start with the assumption that they do
          306  +  ** match (rc==0).  Change rc to non-zero if a discrepancy
          307  +  ** is found.
          308  +  */
          309  +  rc = sqlite3BitvecTest(0,0) + sqlite3BitvecTest(pBitvec, sz+1)
          310  +          + sqlite3BitvecTest(pBitvec, 0);
          311  +  for(i=1; i<=sz; i++){
          312  +    if(  (TESTBIT(pV,i))!=sqlite3BitvecTest(pBitvec,i) ){
          313  +      rc = i;
          314  +      break;
          315  +    }
          316  +  }
          317  +
          318  +  /* Free allocated structure */
          319  +bitvec_end:
          320  +  sqlite3_free(pV);
          321  +  sqlite3BitvecDestroy(pBitvec);
          322  +  return rc;
          323  +}
          324  +#endif /* SQLITE_OMIT_BUILTIN_TEST */

Changes to src/fault.c.

    15     15   ** Subsystems within SQLite can call sqlite3FaultStep() to see if
    16     16   ** they should simulate a fault.  sqlite3FaultStep() normally returns
    17     17   ** zero but will return non-zero if a fault should be simulated.
    18     18   ** Fault injectors can be used, for example, to simulate memory
    19     19   ** allocation failures or I/O errors.
    20     20   **
    21     21   ** The fault injector is omitted from the code if SQLite is
    22         -** compiled with -DSQLITE_OMIT_TESTLOGIC=1.  There is a very
           22  +** compiled with -DSQLITE_OMIT_BUILTIN_TEST=1.  There is a very
    23     23   ** small performance hit for leaving the fault injector in the code.
    24     24   ** Commerical products will probably want to omit the fault injector
    25     25   ** from production builds.  But safety-critical systems who work
    26     26   ** under the motto "fly what you test and test what you fly" may
    27     27   ** choose to leave the fault injector enabled even in production.
    28     28   */
    29     29   #include "sqliteInt.h"
    30     30   
    31         -#ifndef SQLITE_OMIT_TESTLOGIC
           31  +#ifndef SQLITE_OMIT_BUILTIN_TEST
    32     32   
    33     33   /*
    34     34   ** There can be various kinds of faults.  For example, there can be
    35     35   ** a memory allocation failure.  Or an I/O failure.  For each different
    36     36   ** fault type, there is a separate FaultInjector structure to keep track
    37     37   ** of the status of that fault.
    38     38   */
................................................................................
   140    140     aFault[id].nRepeat--;
   141    141     if( aFault[id].nRepeat<=0 ){
   142    142       aFault[id].enable = 0;
   143    143     }
   144    144     return 1;  
   145    145   }
   146    146   
   147         -#endif /* SQLITE_OMIT_TESTLOGIC */
          147  +#endif /* SQLITE_OMIT_BUILTIN_TEST */

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.428 2008/03/20 18:00:49 drh Exp $
           17  +** $Id: main.c,v 1.429 2008/03/21 16:45:47 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include <ctype.h>
    21     21   #ifdef SQLITE_ENABLE_FTS3
    22     22   # include "fts3.h"
    23     23   #endif
    24     24   
................................................................................
  1570   1570   }
  1571   1571   
  1572   1572   /*
  1573   1573   ** Interface to the testing logic.
  1574   1574   */
  1575   1575   int sqlite3_test_control(int op, ...){
  1576   1576     int rc = 0;
  1577         -#ifndef SQLITE_OMIT_TESTLOGIC
         1577  +#ifndef SQLITE_OMIT_BUILTIN_TEST
  1578   1578     va_list ap;
  1579   1579     va_start(ap, op);
  1580   1580     switch( op ){
  1581   1581       /*
  1582   1582       ** sqlite3_test_control(FAULT_CONFIG, fault_id, nDelay, nRepeat)
  1583   1583       **
  1584   1584       ** Configure a fault injector.  The specific fault injector is
................................................................................
  1654   1654       ** to sqlite3_randomness() will reseed the PRNG using a single call
  1655   1655       ** to the xRandomness method of the default VFS.
  1656   1656       */
  1657   1657       case SQLITE_TESTCTRL_PRNG_RESET: {
  1658   1658         sqlite3PrngResetState();
  1659   1659         break;
  1660   1660       }
         1661  +
         1662  +    /*
         1663  +    **  sqlite3_test_control(BITVEC_TEST, size, program)
         1664  +    **
         1665  +    ** Run a test against a Bitvec object of size.  The program argument
         1666  +    ** is an array of integers that defines the test.  Return -1 on a
         1667  +    ** memory allocation error, 0 on success, or non-zero for an error.
         1668  +    ** See the sqlite3BitvecBuiltinTest() for additional information.
         1669  +    */
         1670  +    case SQLITE_TESTCTRL_BITVEC_TEST: {
         1671  +      int sz = va_arg(ap, int);
         1672  +      int *aProg = va_arg(ap, int*);
         1673  +      rc = sqlite3BitvecBuiltinTest(sz, aProg);
         1674  +      break;
         1675  +    }
  1661   1676     }
  1662   1677     va_end(ap);
  1663         -#endif /* SQLITE_OMIT_TESTLOGIC */
         1678  +#endif /* SQLITE_OMIT_BUILTIN_TEST */
  1664   1679     return rc;
  1665   1680   }

Changes to src/random.c.

    11     11   *************************************************************************
    12     12   ** This file contains code to implement a pseudo-random number
    13     13   ** generator (PRNG) for SQLite.
    14     14   **
    15     15   ** Random numbers are used by some of the database backends in order
    16     16   ** to generate random integer keys for tables or random filenames.
    17     17   **
    18         -** $Id: random.c,v 1.22 2008/03/19 14:15:35 drh Exp $
           18  +** $Id: random.c,v 1.23 2008/03/21 16:45:47 drh Exp $
    19     19   */
    20     20   #include "sqliteInt.h"
    21     21   
    22     22   
    23     23   /* All threads share a single random number generator.
    24     24   ** This structure is the current state of the generator.
    25     25   */
................................................................................
    99     99     sqlite3_mutex_enter(mutex);
   100    100     while( N-- ){
   101    101       *(zBuf++) = randomByte();
   102    102     }
   103    103     sqlite3_mutex_leave(mutex);
   104    104   }
   105    105   
   106         -#ifndef SQLITE_OMIT_TESTLOGIC
          106  +#ifndef SQLITE_OMIT_BUILTIN_TEST
   107    107   /*
   108    108   ** For testing purposes, we sometimes want to preserve the state of
   109    109   ** PRNG and restore the PRNG to its saved state at a later time.
   110    110   ** The sqlite3_test_control() interface calls these routines to
   111    111   ** control the PRNG.
   112    112   */
   113    113   static struct sqlite3PrngType sqlite3SavedPrng;
................................................................................
   116    116   }
   117    117   void sqlite3PrngRestoreState(void){
   118    118     memcpy(&sqlite3Prng, &sqlite3SavedPrng, sizeof(sqlite3Prng));
   119    119   }
   120    120   void sqlite3PrngResetState(void){
   121    121     sqlite3Prng.isInit = 0;
   122    122   }
   123         -#endif /* SQLITE_OMIT_TESTLOGIC */
          123  +#endif /* SQLITE_OMIT_BUILTIN_TEST */

Changes to src/sqlite.h.in.

    26     26   ** on how SQLite interfaces are suppose to operate.
    27     27   **
    28     28   ** The name of this file under configuration management is "sqlite.h.in".
    29     29   ** The makefile makes some minor changes to this file (such as inserting
    30     30   ** the version number) and changes its name to "sqlite3.h" as
    31     31   ** part of the build process.
    32     32   **
    33         -** @(#) $Id: sqlite.h.in,v 1.298 2008/03/20 18:00:49 drh Exp $
           33  +** @(#) $Id: sqlite.h.in,v 1.299 2008/03/21 16:45:47 drh Exp $
    34     34   */
    35     35   #ifndef _SQLITE3_H_
    36     36   #define _SQLITE3_H_
    37     37   #include <stdarg.h>     /* Needed for the definition of va_list */
    38     38   
    39     39   /*
    40     40   ** Make sure we can call this stuff from C++.
................................................................................
  5606   5606   #define SQLITE_TESTCTRL_FAULT_CONFIG             1
  5607   5607   #define SQLITE_TESTCTRL_FAULT_FAILURES           2
  5608   5608   #define SQLITE_TESTCTRL_FAULT_BENIGN_FAILURES    3
  5609   5609   #define SQLITE_TESTCTRL_FAULT_PENDING            4
  5610   5610   #define SQLITE_TESTCTRL_PRNG_SAVE                5
  5611   5611   #define SQLITE_TESTCTRL_PRNG_RESTORE             6
  5612   5612   #define SQLITE_TESTCTRL_PRNG_RESET               7
         5613  +#define SQLITE_TESTCTRL_BITVEC_TEST              8
  5613   5614   
  5614   5615   
  5615   5616   /*
  5616   5617   ** Undo the hack that converts floating point types to integer for
  5617   5618   ** builds on processors without floating point support.
  5618   5619   */
  5619   5620   #ifdef SQLITE_OMIT_FLOATING_POINT

Changes to src/sqliteInt.h.

     7      7   **    May you do good and not evil.
     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   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.678 2008/03/20 16:30:18 drh Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.679 2008/03/21 16:45:47 drh Exp $
    15     15   */
    16     16   #ifndef _SQLITEINT_H_
    17     17   #define _SQLITEINT_H_
    18     18   
    19     19   /*
    20     20   ** Include the configuration header output by 'configure' if it was run
    21     21   ** (otherwise we get an empty default).
................................................................................
  1786   1786   void sqlite3EndTable(Parse*,Token*,Token*,Select*);
  1787   1787   
  1788   1788   Bitvec *sqlite3BitvecCreate(u32);
  1789   1789   int sqlite3BitvecTest(Bitvec*, u32);
  1790   1790   int sqlite3BitvecSet(Bitvec*, u32);
  1791   1791   void sqlite3BitvecClear(Bitvec*, u32);
  1792   1792   void sqlite3BitvecDestroy(Bitvec*);
         1793  +int sqlite3BitvecBuiltinTest(int,int*);
  1793   1794   
  1794   1795   void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int);
  1795   1796   
  1796   1797   #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
  1797   1798     int sqlite3ViewGetColumnNames(Parse*,Table*);
  1798   1799   #else
  1799   1800   # define sqlite3ViewGetColumnNames(A,B) 0
................................................................................
  2080   2081   #define SQLITE_FAULTINJECTOR_COUNT      1
  2081   2082   
  2082   2083   /*
  2083   2084   ** The interface to the fault injector subsystem.  If the fault injector
  2084   2085   ** mechanism is disabled at compile-time then set up macros so that no
  2085   2086   ** unnecessary code is generated.
  2086   2087   */
  2087         -#ifndef SQLITE_OMIT_TESTLOGIC
         2088  +#ifndef SQLITE_OMIT_BUILTIN_TEST
  2088   2089     void sqlite3FaultConfig(int,int,int);
  2089   2090     int sqlite3FaultFailures(int);
  2090   2091     int sqlite3FaultBenignFailures(int);
  2091   2092     int sqlite3FaultPending(int);
  2092   2093     void sqlite3FaultBenign(int,int);
  2093   2094     int sqlite3FaultStep(int);
  2094   2095   #else

Changes to src/test2.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing the pager.c module in SQLite.  This code
    13     13   ** is not included in the SQLite library.  It is used for automated
    14     14   ** testing of the SQLite library.
    15     15   **
    16         -** $Id: test2.c,v 1.56 2008/03/20 11:04:21 danielk1977 Exp $
           16  +** $Id: test2.c,v 1.57 2008/03/21 16:45:48 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  +#include <ctype.h>
    22     23   
    23     24   /*
    24     25   ** Interpret an SQLite error number
    25     26   */
    26     27   static char *errorName(int rc){
    27     28     char *zName;
    28     29     switch( rc ){
................................................................................
   556    557     if( rc ){
   557    558       Tcl_AppendResult(interp, "write failed: ", errorName(rc), 0);
   558    559       return TCL_ERROR;
   559    560     }
   560    561     return TCL_OK;
   561    562   }
   562    563   #endif
          564  +
   563    565   
   564    566   /*
   565         -**   sqlite3BitvecCreate SIZE
   566         -**   sqlite3BitvecTest POINTER N
   567         -**   sqlite3BitvecSet POINTER N
   568         -**   sqlite3BitvecClear POINTER N
   569         -**   sqlite3BitvecDestroy POINTER
          567  +** sqlite3BitvecBuiltinTest SIZE PROGRAM
          568  +**
          569  +** Invoke the SQLITE_TESTCTRL_BITVEC_TEST operator on test_control.
          570  +** See comments on sqlite3BitvecBuiltinTest() for additional information.
   570    571   */
   571         -static int testBitvecCreate(
          572  +static int testBitvecBuiltinTest(
   572    573     void *NotUsed,
   573    574     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   574    575     int argc,              /* Number of arguments */
   575    576     const char **argv      /* Text of each argument */
   576    577   ){
   577         -  int size;
   578         -  Bitvec *p;
   579         -  char zBuf[100];
   580         -  if( argc!=2 ){
   581         -    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " N\"", 
   582         -           (void*)0);
          578  +  int sz, rc;
          579  +  int nProg = 0;
          580  +  int aProg[100];
          581  +  const char *z;
          582  +  if( argc!=3 ){
          583  +    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
          584  +                     " SIZE PROGRAM\"", (void*)0);
          585  +  }
          586  +  if( Tcl_GetInt(interp, argv[1], &sz) ) return TCL_ERROR;
          587  +  z = argv[2];
          588  +  while( nProg<99 && *z ){
          589  +    while( *z && !isdigit(*z) ){ z++; }
          590  +    if( *z==0 ) break;
          591  +    aProg[nProg++] = atoi(z);
          592  +    while( isdigit(*z) ){ z++; }
   583    593     }
   584         -  if( Tcl_GetInt(interp, argv[1], &size) ) return TCL_ERROR;
   585         -  p = sqlite3BitvecCreate(size);
   586         -  sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",p);
   587         -  Tcl_AppendResult(interp, zBuf, 0);
   588         -  return TCL_OK;
   589         -}  
   590         -static int testBitvecTest(
   591         -  void *NotUsed,
   592         -  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   593         -  int argc,              /* Number of arguments */
   594         -  const char **argv      /* Text of each argument */
   595         -){
   596         -  int N;
   597         -  Bitvec *p;
   598         -  char zBuf[100];
   599         -  if( argc!=3 ){
   600         -    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " PTR N\"", 
   601         -           (void*)0);
   602         -  }
   603         -  p = (Bitvec*)sqlite3TextToPtr(argv[1]);
   604         -  if( Tcl_GetInt(interp, argv[2], &N) ) return TCL_ERROR;
   605         -  sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",sqlite3BitvecTest(p,N));
   606         -  Tcl_AppendResult(interp, zBuf, 0);
          594  +  aProg[nProg] = 0;
          595  +  rc = sqlite3_test_control(SQLITE_TESTCTRL_BITVEC_TEST, sz, aProg);
          596  +  Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
   607    597     return TCL_OK;
   608    598   }  
   609         -static int testBitvecSet(
   610         -  void *NotUsed,
   611         -  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   612         -  int argc,              /* Number of arguments */
   613         -  const char **argv      /* Text of each argument */
   614         -){
   615         -  int N;
   616         -  Bitvec *p;
   617         -  char zBuf[100];
   618         -  if( argc!=3 ){
   619         -    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " PTR N\"", 
   620         -           (void*)0);
   621         -  }
   622         -  p = (Bitvec*)sqlite3TextToPtr(argv[1]);
   623         -  if( Tcl_GetInt(interp, argv[2], &N) ) return TCL_ERROR;
   624         -  sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",sqlite3BitvecSet(p,N));
   625         -  Tcl_AppendResult(interp, zBuf, 0);
   626         -  return TCL_OK;
   627         -}  
   628         -static int testBitvecClear(
   629         -  void *NotUsed,
   630         -  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   631         -  int argc,              /* Number of arguments */
   632         -  const char **argv      /* Text of each argument */
   633         -){
   634         -  int N;
   635         -  Bitvec *p;
   636         -  if( argc!=3 ){
   637         -    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " PTR N\"", 
   638         -           (void*)0);
   639         -  }
   640         -  p = (Bitvec*)sqlite3TextToPtr(argv[1]);
   641         -  if( Tcl_GetInt(interp, argv[2], &N) ) return TCL_ERROR;
   642         -  sqlite3BitvecClear(p,N);
   643         -  return TCL_OK;
   644         -}  
   645         -static int testBitvecDestroy(
   646         -  void *NotUsed,
   647         -  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   648         -  int argc,              /* Number of arguments */
   649         -  const char **argv      /* Text of each argument */
   650         -){
   651         -  Bitvec *p;
   652         -  if( argc!=2 ){
   653         -    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " PTR\"", 
   654         -           (void*)0);
   655         -  }
   656         -  p = (Bitvec*)sqlite3TextToPtr(argv[1]);
   657         -  sqlite3BitvecDestroy(p);
   658         -  return TCL_OK;
   659         -}  
   660         -       
   661    599   
   662    600   /*
   663    601   ** Register commands with the TCL interpreter.
   664    602   */
   665    603   int Sqlitetest2_Init(Tcl_Interp *interp){
   666    604     extern int sqlite3_io_error_persist;
   667    605     extern int sqlite3_io_error_pending;
................................................................................
   689    627       { "page_read",               (Tcl_CmdProc*)page_read           },
   690    628       { "page_write",              (Tcl_CmdProc*)page_write          },
   691    629       { "page_number",             (Tcl_CmdProc*)page_number         },
   692    630       { "pager_truncate",          (Tcl_CmdProc*)pager_truncate      },
   693    631   #ifndef SQLITE_OMIT_DISKIO
   694    632       { "fake_big_file",           (Tcl_CmdProc*)fake_big_file       },
   695    633   #endif
   696         -    { "sqlite3BitvecCreate",     (Tcl_CmdProc*)testBitvecCreate    },
   697         -    { "sqlite3BitvecTest",       (Tcl_CmdProc*)testBitvecTest      },
   698         -    { "sqlite3BitvecSet",        (Tcl_CmdProc*)testBitvecSet       },
   699         -    { "sqlite3BitvecClear",      (Tcl_CmdProc*)testBitvecClear     },
   700         -    { "sqlite3BitvecDestroy",    (Tcl_CmdProc*)testBitvecDestroy   },
          634  +    { "sqlite3BitvecBuiltinTest",(Tcl_CmdProc*)testBitvecBuiltinTest},
   701    635     };
   702    636     int i;
   703    637     for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
   704    638       Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
   705    639     }
   706    640     Tcl_LinkVar(interp, "sqlite_io_error_pending",
   707    641        (char*)&sqlite3_io_error_pending, TCL_LINK_INT);

Changes to src/test_config.c.

    12     12   ** 
    13     13   ** This file contains code used for testing the SQLite system.
    14     14   ** None of the code in this file goes into a deliverable build.
    15     15   ** 
    16     16   ** The focus of this file is providing the TCL testing layer
    17     17   ** access to compile-time constants.
    18     18   **
    19         -** $Id: test_config.c,v 1.22 2008/03/20 14:03:29 drh Exp $
           19  +** $Id: test_config.c,v 1.23 2008/03/21 16:45:48 drh Exp $
    20     20   */
    21     21   
    22     22   #include "sqliteLimit.h"
    23     23   
    24     24   #include "sqliteInt.h"
    25     25   #include "tcl.h"
    26     26   #include <stdlib.h>
................................................................................
   130    130   #endif
   131    131   
   132    132   #ifdef SQLITE_OMIT_BETWEEN_OPTIMIZATION
   133    133     Tcl_SetVar2(interp, "sqlite_options", "between_opt", "0", TCL_GLOBAL_ONLY);
   134    134   #else
   135    135     Tcl_SetVar2(interp, "sqlite_options", "between_opt", "1", TCL_GLOBAL_ONLY);
   136    136   #endif
          137  +
          138  +#ifdef SQLITE_OMIT_BUILTIN_TEST
          139  +  Tcl_SetVar2(interp, "sqlite_options", "builtin_test", "0", TCL_GLOBAL_ONLY);
          140  +#else
          141  +  Tcl_SetVar2(interp, "sqlite_options", "builtin_test", "1", TCL_GLOBAL_ONLY);
          142  +#endif
   137    143   
   138    144   #ifdef SQLITE_OMIT_BLOB_LITERAL
   139    145     Tcl_SetVar2(interp, "sqlite_options", "bloblit", "0", TCL_GLOBAL_ONLY);
   140    146   #else
   141    147     Tcl_SetVar2(interp, "sqlite_options", "bloblit", "1", TCL_GLOBAL_ONLY);
   142    148   #endif
   143    149   
................................................................................
   352    358   
   353    359   #ifdef SQLITE_OMIT_TCL_VARIABLE
   354    360     Tcl_SetVar2(interp, "sqlite_options", "tclvar", "0", TCL_GLOBAL_ONLY);
   355    361   #else
   356    362     Tcl_SetVar2(interp, "sqlite_options", "tclvar", "1", TCL_GLOBAL_ONLY);
   357    363   #endif
   358    364   
   359         -#ifdef SQLITE_OMIT_TESTLOGIC
   360         -  Tcl_SetVar2(interp, "sqlite_options", "testlogic", "0", TCL_GLOBAL_ONLY);
   361         -#else
   362         -  Tcl_SetVar2(interp, "sqlite_options", "testlogic", "1", TCL_GLOBAL_ONLY);
   363         -#endif
   364         -
   365    365     rc = sqlite3_threadsafe();
   366    366   #if SQLITE_THREADSAFE
   367    367     Tcl_SetVar2(interp, "sqlite_options", "threadsafe", "1", TCL_GLOBAL_ONLY);
   368    368     assert( rc );
   369    369   #else
   370    370     Tcl_SetVar2(interp, "sqlite_options", "threadsafe", "0", TCL_GLOBAL_ONLY);
   371    371     assert( !rc );

Changes to test/bitvec.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   #
    12     12   # Unit testing of the Bitvec object.
    13     13   #
    14         -# $Id: bitvec.test,v 1.1 2008/02/18 14:47:34 drh Exp $
           14  +# $Id: bitvec.test,v 1.2 2008/03/21 16:45:48 drh Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20         -#ifcapable !subquery {
    21         -#  finish_test
    22         -#  return
    23         -#}
           20  +# The built-in test logic must be operational in order for
           21  +# this test to work.
           22  +ifcapable !builtin_test {
           23  +  finish_test
           24  +  return
           25  +}
    24     26   
           27  +# Test that sqlite3BitvecBuiltinTest correctly reports errors
           28  +# that are deliberately introduced.
           29  +#
           30  +do_test bitvec-1.0.1 {
           31  +  sqlite3BitvecBuiltinTest 400 {5 1 1 1 0}
           32  +} 1
           33  +do_test bitvec-1.0.2 {
           34  +  sqlite3BitvecBuiltinTest 400 {5 1 234 1 0}
           35  +} 234
           36  +
           37  +# Run test cases that set every bit in vectors of various sizes.
           38  +# for larger cases, this should cycle the bit vector representation
           39  +# from hashing into subbitmaps.  The subbitmaps should start as
           40  +# hashes then change to either subbitmaps or linear maps, depending
           41  +# on their size.
           42  +#
    25     43   do_test bitvec-1.1 {
    26         -  set PTR [sqlite3BitvecCreate 4000]
    27         -  for {set i 1} {$i<=4000} {incr i} {
    28         -    if {$i%1000==999} continue
    29         -    sqlite3BitvecSet $PTR $i
    30         -  }
    31         -  set r {}
    32         -  for {set i 1} {$i<=4000} {incr i} {
    33         -    if {![sqlite3BitvecTest $PTR $i]} {lappend r $i}
    34         -  }
    35         -  sqlite3BitvecDestroy $PTR
    36         -  set r
    37         -} {999 1999 2999 3999}
           44  +  sqlite3BitvecBuiltinTest 400 {1 400 1 1 0}
           45  +} 0
    38     46   do_test bitvec-1.2 {
    39         -  set PTR [sqlite3BitvecCreate 4001]
    40         -  for {set i 1} {$i<=4001} {incr i} {
    41         -    if {$i%1000==999} continue
    42         -    sqlite3BitvecSet $PTR $i
    43         -  }
    44         -  set r {}
    45         -  for {set i 1} {$i<=4001} {incr i} {
    46         -    if {![sqlite3BitvecTest $PTR $i]} {lappend r $i}
    47         -  }
    48         -  sqlite3BitvecDestroy $PTR
    49         -  set r
    50         -} {999 1999 2999 3999}
           47  +  sqlite3BitvecBuiltinTest 4000 {1 4000 1 1 0}
           48  +} 0
    51     49   do_test bitvec-1.3 {
    52         -  set PTR [sqlite3BitvecCreate 40000]
    53         -  for {set i 1} {$i<=40000} {incr i} {
    54         -    if {$i%10000==9999} continue
    55         -    sqlite3BitvecSet $PTR $i
    56         -  }
    57         -  set r {}
    58         -  for {set i 1} {$i<=40000} {incr i} {
    59         -    if {![sqlite3BitvecTest $PTR $i]} {lappend r $i}
    60         -  }
    61         -  sqlite3BitvecDestroy $PTR
    62         -  set r
    63         -} {9999 19999 29999 39999}
           50  +  sqlite3BitvecBuiltinTest 40000 {1 40000 1 1 0}
           51  +} 0
    64     52   do_test bitvec-1.4 {
    65         -  set PTR [sqlite3BitvecCreate 2000000000]
    66         -  for {set i 1000000} {$i<=1001000} {incr i} {
    67         -    if {$i%1000==789} continue
    68         -    sqlite3BitvecSet $PTR $i
    69         -  }
    70         -  set r {}
    71         -  for {set i 1000000} {$i<=1001000} {incr i} {
    72         -    if {![sqlite3BitvecTest $PTR $i]} {lappend r $i}
    73         -  }
    74         -  sqlite3BitvecDestroy $PTR
    75         -  set r
    76         -} {1000789}
           53  +  sqlite3BitvecBuiltinTest 400000 {1 400000 1 1 0}
           54  +} 0
           55  +
           56  +# By specifying a larger increments, we spread the load around.
           57  +#
           58  +do_test bitvec-1.5 {
           59  +  sqlite3BitvecBuiltinTest 400 {1 400 1 7 0}
           60  +} 0
           61  +do_test bitvec-1.6 {
           62  +  sqlite3BitvecBuiltinTest 4000 {1 4000 1 7 0}
           63  +} 0
           64  +do_test bitvec-1.7 {
           65  +  sqlite3BitvecBuiltinTest 40000 {1 40000 1 7 0}
           66  +} 0
           67  +do_test bitvec-1.8 {
           68  +  sqlite3BitvecBuiltinTest 400000 {1 400000 1 7 0}
           69  +} 0
           70  +
           71  +# First fill up the bitmap with ones,  then go through and
           72  +# clear all the bits.  This will stress the clearing mechanism.
           73  +#
           74  +do_test bitvec-1.9 {
           75  +  sqlite3BitvecBuiltinTest 400 {1 400 1 1 2 400 1 1 0}
           76  +} 0
           77  +do_test bitvec-1.10 {
           78  +  sqlite3BitvecBuiltinTest 4000 {1 4000 1 1 2 4000 1 1 0}
           79  +} 0
           80  +do_test bitvec-1.11 {
           81  +  sqlite3BitvecBuiltinTest 40000 {1 40000 1 1 2 40000 1 1 0}
           82  +} 0
           83  +do_test bitvec-1.12 {
           84  +  sqlite3BitvecBuiltinTest 400000 {1 400000 1 1 2 400000 1 1 0}
           85  +} 0
           86  +
           87  +do_test bitvec-1.13 {
           88  +  sqlite3BitvecBuiltinTest 400 {1 400 1 1 2 400 1 7 0}
           89  +} 0
           90  +do_test bitvec-1.15 {
           91  +  sqlite3BitvecBuiltinTest 4000 {1 4000 1 1 2 4000 1 7 0}
           92  +} 0
           93  +do_test bitvec-1.16 {
           94  +  sqlite3BitvecBuiltinTest 40000 {1 40000 1 1 2 40000 1 77 0}
           95  +} 0
           96  +do_test bitvec-1.17 {
           97  +  sqlite3BitvecBuiltinTest 400000 {1 400000 1 1 2 400000 1 777 0}
           98  +} 0
           99  +
          100  +do_test bitvec-1.18 {
          101  +  sqlite3BitvecBuiltinTest 400000 {1 5000 100000 1 2 400000 1 37 0}
          102  +} 0
    77    103   
    78         -do_test bitvec-2.1 {
    79         -  set PTR [sqlite3BitvecCreate 4000]
    80         -  for {set i 1} {$i<=4000} {incr i 2} {
    81         -    sqlite3BitvecSet $PTR $i
    82         -  }
    83         -  for {set i 1} {$i<=4000} {incr i} {
    84         -    sqlite3BitvecClear $PTR $i
    85         -  }
    86         -  set r {}
    87         -  for {set i 1} {$i<=4000} {incr i} {
    88         -    if {[sqlite3BitvecTest $PTR $i]} {lappend r $i}
    89         -  }
    90         -  sqlite3BitvecDestroy $PTR
    91         -  set r
    92         -} {}
    93         -do_test bitvec-2.2 {
    94         -  set PTR [sqlite3BitvecCreate 4001]
    95         -  for {set i 1} {$i<=101} {incr i 2} {
    96         -    sqlite3BitvecSet $PTR $i
          104  +# Attempt to induce hash collisions.  
          105  +#
          106  +unset -nocomplain start
          107  +unset -nocomplain incr
          108  +foreach start {1 2 3 4 5 6 7 8} {
          109  +  foreach incr {124 125} {
          110  +    do_test bitvec-1.20.$start.$incr {
          111  +      set prog [list 1 60 $::start $::incr 2 5000 1 1 0]
          112  +      sqlite3BitvecBuiltinTest 5000 $prog
          113  +    } 0
    97    114     }
    98         -  for {set i 1} {$i<=99} {incr i} {
    99         -    sqlite3BitvecClear $PTR $i
   100         -  }
   101         -  set r {}
   102         -  for {set i 1} {$i<=4000} {incr i} {
   103         -    if {[sqlite3BitvecTest $PTR $i]} {lappend r $i}
   104         -  }
   105         -  sqlite3BitvecDestroy $PTR
   106         -  set r
   107         -} {101}
          115  +}
          116  +
          117  +do_test bitvec-1.30.big_and_slow {
          118  +  sqlite3BitvecBuiltinTest 17000000 {1 17000000 1 1 2 17000000 1 1 0}
          119  +} 0
          120  +
          121  +
          122  +# Test setting and clearing a random subset of bits.
          123  +#
          124  +do_test bitvec-2.1 {
          125  +  sqlite3BitvecBuiltinTest 4000 {3 2000 4 2000 0}
          126  +} 0
          127  +do_test bitvec-2.2 {
          128  +  sqlite3BitvecBuiltinTest 4000 {3 1000 4 1000 3 1000 4 1000 3 1000 4 1000
          129  +                                 3 1000 4 1000 3 1000 4 1000 3 1000 4 1000 0}
          130  +} 0
   108    131   do_test bitvec-2.3 {
   109         -  set PTR [sqlite3BitvecCreate 4001]
   110         -  for {set i 1} {$i<=101} {incr i} {
   111         -    sqlite3BitvecSet $PTR $i
   112         -  }
   113         -  for {set i 1} {$i<=99} {incr i} {
   114         -    sqlite3BitvecClear $PTR $i
   115         -  }
   116         -  set r {}
   117         -  for {set i 1} {$i<=4000} {incr i} {
   118         -    if {[sqlite3BitvecTest $PTR $i]} {lappend r $i}
   119         -  }
   120         -  sqlite3BitvecDestroy $PTR
   121         -  set r
   122         -} {100 101}
          132  +  sqlite3BitvecBuiltinTest 400000 {3 10 0}
          133  +} 0
   123    134   do_test bitvec-2.4 {
   124         -  set PTR [sqlite3BitvecCreate 5000]
   125         -  for {set i 1} {$i<=5000} {incr i} {
   126         -    sqlite3BitvecSet $PTR $i
   127         -    if {$i%1000!=456} {sqlite3BitvecClear $PTR $i}
   128         -  }
   129         -  set r {}
   130         -  for {set i 1} {$i<=5000} {incr i} {
   131         -    if {[sqlite3BitvecTest $PTR $i]} {lappend r $i}
   132         -  }
   133         -  sqlite3BitvecDestroy $PTR
   134         -  set r
   135         -} {456 1456 2456 3456 4456}
          135  +  sqlite3BitvecBuiltinTest 4000 {3 10 2 4000 1 1 0}
          136  +} 0
          137  +do_test bitvec-2.5 {
          138  +  sqlite3BitvecBuiltinTest 5000 {3 20 2 5000 1 1 0}
          139  +} 0
          140  +do_test bitvec-2.6 {
          141  +  sqlite3BitvecBuiltinTest 50000 {3 60 2 50000 1 1 0}
          142  +} 0
   136    143   
   137         -do_test bitvec-3.1 {
   138         -  set PTR [sqlite3BitvecCreate 2000000000]
   139         -  for {set i 2000000} {$i<=3000000} {incr i 100000} {
   140         -    for {set j $i} {$j<=$i+50} {incr j} {
   141         -      sqlite3BitvecSet $PTR $i
   142         -    }
   143         -    for {set j $i} {$j<=$i+50} {incr j} {
   144         -      sqlite3BitvecClear $PTR $i
          144  +# This procedure runs sqlite3BitvecBuiltinTest with argments "n" and
          145  +# "program".  But it also causes a malloc error to occur after the
          146  +# "failcnt"-th malloc.  The result should be "0" if no malloc failure
          147  +# occurs or "-1" if there is a malloc failure.
          148  +#
          149  +proc bitvec_malloc_test {label failcnt n program} {
          150  +  do_test $label [subst {
          151  +    sqlite3_memdebug_fail $failcnt
          152  +    set x \[sqlite3BitvecBuiltinTest $n [list $program]\]
          153  +    set nFail \[sqlite3_memdebug_fail -1\]
          154  +    if {\$nFail==0} {
          155  +      set ::go 0
          156  +      set x -1
   145    157       }
   146         -  }
   147         -  set r {}
   148         -  for {set i 2000000} {$i<=3000000} {incr i} {
   149         -    if {[sqlite3BitvecTest $PTR $i]} {lappend r $i}
   150         -  }
   151         -  sqlite3BitvecDestroy $PTR
   152         -  set r
   153         -} {}
   154         -do_test bitvec-3.2 {
   155         -  set PTR [sqlite3BitvecCreate 200000]
   156         -  for {set i 1000} {$i<=190000} {incr i 10000} {
   157         -    for {set j $i} {$j<=$i+50} {incr j} {
   158         -      sqlite3BitvecSet $PTR $i
   159         -    }
   160         -    for {set j $i} {$j<=$i+50} {incr j} {
   161         -      sqlite3BitvecClear $PTR $i
   162         -    }
          158  +    set x
          159  +  }] -1
          160  +}
          161  +
          162  +# Make sure malloc failures are handled sanily.
          163  +#
          164  +unset -nocomplain n
          165  +unset -nocomplain go
          166  +set go 1
          167  +save_prng_state
          168  +for {set n 0} {$go} {incr n} {
          169  +  restore_prng_state
          170  +  bitvec_malloc_test bitvec-3.1.$n $n 5000 {
          171  +      3 60 2 5000 1 1 3 60 2 5000 1 1 3 60 2 5000 1 1 0
   163    172     }
   164         -  set r {}
   165         -  for {set i 1} {$i<=200000} {incr i} {
   166         -    if {[sqlite3BitvecTest $PTR $i]} {lappend r $i}
          173  +}
          174  +set go 1
          175  +for {set n 0} {$go} {incr n} {
          176  +  restore_prng_state
          177  +  bitvec_malloc_test bitvec-3.2.$n $n 5000 {
          178  +      3 600 2 5000 1 1 3 600 2 5000 1 1 3 600 2 5000 1 1 0
   167    179     }
   168         -  sqlite3BitvecDestroy $PTR
   169         -  set r
   170         -} {}
   171         -do_test bitvec-3.3 {
   172         -  set PTR [sqlite3BitvecCreate 200000]
   173         -  for {set i 1000} {$i<=190000} {incr i 10000} {
   174         -    for {set j $i} {$j<=$i+500} {incr j} {
   175         -      sqlite3BitvecSet $PTR $i
   176         -    }
   177         -    for {set j $i} {$j<=$i+500} {incr j} {
   178         -      sqlite3BitvecClear $PTR $i
   179         -    }
   180         -  }
   181         -  set r {}
   182         -  for {set i 1} {$i<=200000} {incr i} {
   183         -    if {[sqlite3BitvecTest $PTR $i]} {lappend r $i}
   184         -  }
   185         -  sqlite3BitvecDestroy $PTR
   186         -  set r
   187         -} {}
   188         -do_test bitvec-3.4 {
   189         -  set PTR [sqlite3BitvecCreate 2000]
   190         -  for {set i 10} {$i<=1900} {incr i 100} {
   191         -    for {set j $i} {$j<=$i+50} {incr j} {
   192         -      sqlite3BitvecSet $PTR $i
   193         -    }
   194         -    for {set j $i} {$j<=$i+50} {incr j} {
   195         -      sqlite3BitvecClear $PTR $i
   196         -    }
   197         -  }
   198         -  set r {}
   199         -  for {set i 1} {$i<=2000} {incr i} {
   200         -    if {[sqlite3BitvecTest $PTR $i]} {lappend r $i}
   201         -  }
   202         -  sqlite3BitvecDestroy $PTR
   203         -  set r
   204         -} {}
          180  +}
          181  +set go 1
          182  +for {set n 1} {$go} {incr n} {
          183  +  bitvec_malloc_test bitvec-3.3.$n $n 50000 {1 50000 1 1 0}
          184  +}
          185  +
          186  +finish_test
          187  +return
          188  +
   205    189   
   206    190   
   207    191   finish_test

Changes to test/malloc_common.tcl.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   #
    12     12   # This file contains common code used by many different malloc tests
    13     13   # within the test suite.
    14     14   #
    15         -# $Id: malloc_common.tcl,v 1.15 2008/03/19 14:15:35 drh Exp $
           15  +# $Id: malloc_common.tcl,v 1.16 2008/03/21 16:45:48 drh Exp $
    16     16   
    17     17   # If we did not compile with malloc testing enabled, then do nothing.
    18     18   #
    19         -ifcapable testlogic {
           19  +ifcapable builtin_test {
    20     20     set MEMDEBUG 1
    21     21   } else {
    22     22     set MEMDEBUG 0
    23     23     return 0
    24     24   }
    25     25   
    26     26   # Usage: do_malloc_test <test number> <options...>