/ Check-in [413ddade]
Login

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

Overview
Comment:Add the sqlite3_test_control() API. Use it to control the fault injector. (CVS 4758)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:413ddade6a13f993cddc57389d1107d82fa19972
User & Date: drh 2008-01-31 14:43:24
Context
2008-01-31
14:54
Fix assertion fault in sqllimits1.test encountered when auto_vacuum is enabled. Correct the sqllimit1 tests to account for extra pages inserted by auto_vacuum. (CVS 4759) check-in: 9b207d1a user: drh tags: trunk
14:43
Add the sqlite3_test_control() API. Use it to control the fault injector. (CVS 4758) check-in: 413ddade user: drh tags: trunk
13:35
Version number to 3.5.5. Include FTS3 in the amalgamation by default (but disabled unless compiled with -DSQLITE_ENABLE_FTS3). Fix a memory allocation problem. (CVS 4757) check-in: 72411043 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.415 2008/01/31 13:35:49 drh Exp $
           17  +** $Id: main.c,v 1.416 2008/01/31 14:43:24 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   
................................................................................
  1466   1466         }
  1467   1467         sqlite3BtreeLeave(pBtree);
  1468   1468       }
  1469   1469     }
  1470   1470     sqlite3_mutex_leave(db->mutex);
  1471   1471     return rc;   
  1472   1472   }
         1473  +
         1474  +/*
         1475  +** Interface to the testing logic.
         1476  +*/
         1477  +int sqlite3_test_control(int op, ...){
         1478  +  va_list ap;
         1479  +  int rc = 0;
         1480  +  va_start(ap, op);
         1481  +  switch( op ){
         1482  +#ifndef SQLITE_OMIT_FAULTINJECTOR
         1483  +    case SQLITE_TESTCTRL_FAULT_CONFIG: {
         1484  +      int id = va_arg(ap, int);
         1485  +      int nDelay = va_arg(ap, int);
         1486  +      int nRepeat = va_arg(ap, int);
         1487  +      sqlite3FaultConfig(id, nDelay, nRepeat);
         1488  +      break;
         1489  +    }
         1490  +    case SQLITE_TESTCTRL_FAULT_FAILURES: {
         1491  +      int id = va_arg(ap, int);
         1492  +      rc = sqlite3FaultFailures(id);
         1493  +      break;
         1494  +    }
         1495  +    case SQLITE_TESTCTRL_FAULT_BENIGN_FAILURES: {
         1496  +      int id = va_arg(ap, int);
         1497  +      rc = sqlite3FaultBenignFailures(id);
         1498  +      break;
         1499  +    }
         1500  +    case SQLITE_TESTCTRL_FAULT_PENDING: {
         1501  +      int id = va_arg(ap, int);
         1502  +      rc = sqlite3FaultPending(id);
         1503  +      break;
         1504  +    }
         1505  +#endif /* SQLITE_OMIT_FAULTINJECTOR */
         1506  +  }
         1507  +  va_end(ap);
         1508  +}

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.280 2008/01/31 12:26:50 drh Exp $
           33  +** @(#) $Id: sqlite.h.in,v 1.281 2008/01/31 14:43:24 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++.
................................................................................
  4743   4743   ** also return SQLITE_ERROR.  {U11309} There is no way to distinguish between
  4744   4744   ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
  4745   4745   ** xFileControl method. {END}
  4746   4746   **
  4747   4747   ** See also: [SQLITE_FCNTL_LOCKSTATE]
  4748   4748   */
  4749   4749   int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
         4750  +
         4751  +/*
         4752  +** CAPI3REF: Testing Interface {F11400}
         4753  +**
         4754  +** The sqlite3_test_control() interface is used to read out internal
         4755  +** state of SQLite and to inject faults into SQLite for testing
         4756  +** purposes.  The first parameter a operation code that determines
         4757  +** the number, meaning, and operation of all subsequent parameters.
         4758  +**
         4759  +** This interface is not for use by applications.  It exists solely
         4760  +** for verifying the correct operation of the SQLite library.  Depending
         4761  +** on how the SQLite library is compiled, this interface might not exist.
         4762  +**
         4763  +** The details of the operation codes, their meanings, the parameters
         4764  +** they take, and what they do are all subject to change without notice.
         4765  +** Unlike most of the SQLite API, this function is not guaranteed to
         4766  +** operate consistently from one release to the next.
         4767  +*/
         4768  +int sqlite3_test_control(int op, ...);
         4769  +
         4770  +/*
         4771  +** CAPI3REF: Testing Interface Operation Codes {F11410}
         4772  +**
         4773  +** These constants are the valid operation code parameters used
         4774  +** as the first argument to [sqlite3_test_control()].
         4775  +**
         4776  +** These parameters and their meansing are subject to change
         4777  +** without notice.  These values are for testing purposes only.
         4778  +** Applications should not use any of these parameters or the
         4779  +** [sqlite3_test_control()] interface.
         4780  +*/
         4781  +#define SQLITE_TESTCTRL_FAULT_CONFIG             1
         4782  +#define SQLITE_TESTCTRL_FAULT_FAILURES           2
         4783  +#define SQLITE_TESTCTRL_FAULT_BENIGN_FAILURES    3
         4784  +#define SQLITE_TESTCTRL_FAULT_PENDING            4
         4785  +
         4786  +
         4787  +
         4788  +
  4750   4789   
  4751   4790   /*
  4752   4791   ** Undo the hack that converts floating point types to integer for
  4753   4792   ** builds on processors without floating point support.
  4754   4793   */
  4755   4794   #ifdef SQLITE_OMIT_FLOATING_POINT
  4756   4795   # undef double
  4757   4796   #endif
  4758   4797   
  4759   4798   #ifdef __cplusplus
  4760   4799   }  /* End of the 'extern "C"' block */
  4761   4800   #endif
  4762   4801   #endif

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.10 2008/01/22 21:30:53 drh Exp $
           16  +** $Id: test_malloc.c,v 1.11 2008/01/31 14:43:24 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   
................................................................................
   406    406   
   407    407       if( zErr ){
   408    408         Tcl_AppendResult(interp, zErr, zOption, 0);
   409    409         return TCL_ERROR;
   410    410       }
   411    411     }
   412    412     
   413         -  nBenign = sqlite3FaultBenignFailures(SQLITE_FAULTINJECTOR_MALLOC);
   414         -  nFail = sqlite3FaultFailures(SQLITE_FAULTINJECTOR_MALLOC);
   415         -  sqlite3FaultConfig(SQLITE_FAULTINJECTOR_MALLOC, iFail, nRepeat);
          413  +  nBenign = sqlite3_test_control(SQLITE_TESTCTRL_FAULT_BENIGN_FAILURES,
          414  +                                 SQLITE_FAULTINJECTOR_MALLOC);
          415  +  nFail = sqlite3_test_control(SQLITE_TESTCTRL_FAULT_FAILURES,
          416  +                               SQLITE_FAULTINJECTOR_MALLOC);
          417  +  sqlite3_test_control(SQLITE_TESTCTRL_FAULT_CONFIG,
          418  +                       SQLITE_FAULTINJECTOR_MALLOC, iFail, nRepeat);
   416    419     if( pBenignCnt ){
   417    420       Tcl_ObjSetVar2(interp, pBenignCnt, 0, Tcl_NewIntObj(nBenign), 0);
   418    421     }
   419    422     Tcl_SetObjResult(interp, Tcl_NewIntObj(nFail));
   420    423     return TCL_OK;
   421    424   }
   422    425   
................................................................................
   436    439     if( objc!=1 ){
   437    440       Tcl_WrongNumArgs(interp, 1, objv, "");
   438    441       return TCL_ERROR;
   439    442     }
   440    443   
   441    444   #ifdef SQLITE_MEMDEBUG
   442    445     {
   443         -    Tcl_SetObjResult(interp, 
   444         -       Tcl_NewIntObj(sqlite3FaultPending(SQLITE_FAULTINJECTOR_MALLOC))
   445         -    );
          446  +    int nPending = sqlite3_test_control(SQLITE_TESTCTRL_FAULT_PENDING,
          447  +                                        SQLITE_FAULTINJECTOR_MALLOC);
          448  +    Tcl_SetObjResult(interp, Tcl_NewIntObj(nPending));
   446    449     }
   447    450   #endif
   448    451     return TCL_OK;
   449    452   }
   450    453   
   451    454   
   452    455   /*