/ Check-in [0288fa5d]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Enhanced disk-full tests. (CVS 2682)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0288fa5d25886f6fbef0be782f12285d62bebd68
User & Date: drh 2005-09-09 10:46:19
Context
2005-09-10
15:28
Use of the CROSS keyword in a join prevents table reordering. Ticket #1414. (CVS 2683) check-in: 415b8b24 user: drh tags: trunk
2005-09-09
10:46
Enhanced disk-full tests. (CVS 2682) check-in: 0288fa5d user: drh tags: trunk
10:17
Detect errors returned by SetFilePointer on windows. (CVS 2681) check-in: bc8c33f9 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_common.h.

    78     78   ** If we compile with the SQLITE_TEST macro set, then the following block
    79     79   ** of code will give us the ability to simulate a disk I/O error.  This
    80     80   ** is used for testing the I/O recovery logic.
    81     81   */
    82     82   #ifdef SQLITE_TEST
    83     83   int sqlite3_io_error_pending = 0;
    84     84   int sqlite3_diskfull_pending = 0;
           85  +int sqlite3_diskfull = 0;
    85     86   #define SimulateIOError(A)  \
    86     87      if( sqlite3_io_error_pending ) \
    87     88        if( sqlite3_io_error_pending-- == 1 ){ local_ioerr(); return A; }
    88     89   static void local_ioerr(){
    89     90     sqlite3_io_error_pending = 0;  /* Really just a place to set a breakpoint */
    90     91   }
    91     92   #define SimulateDiskfullError \
    92         -   if( sqlite3_diskfull_pending ) \
    93         -     if( sqlite3_diskfull_pending-- == 1 ){ local_ioerr(); return SQLITE_FULL; }
           93  +   if( sqlite3_diskfull_pending ){ \
           94  +     if( sqlite3_diskfull_pending == 1 ){ \
           95  +       local_ioerr(); \
           96  +       sqlite3_diskfull = 1; \
           97  +       return SQLITE_FULL; \
           98  +     }else{ \
           99  +       sqlite3_diskfull_pending--; \
          100  +     } \
          101  +   }
    94    102   #else
    95    103   #define SimulateIOError(A)
    96    104   #define SimulateDiskfullError
    97    105   #endif
    98    106   
    99    107   /*
   100    108   ** When testing, keep a count of the number of open files.

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.31 2005/08/11 02:10:19 drh Exp $
           16  +** $Id: test2.c,v 1.32 2005/09/09 10:46:19 drh Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "os.h"
    20     20   #include "pager.h"
    21     21   #include "tcl.h"
    22     22   #include <stdlib.h>
    23     23   #include <string.h>
................................................................................
   557    557   
   558    558   /*
   559    559   ** Register commands with the TCL interpreter.
   560    560   */
   561    561   int Sqlitetest2_Init(Tcl_Interp *interp){
   562    562     extern int sqlite3_io_error_pending;
   563    563     extern int sqlite3_diskfull_pending;
          564  +  extern int sqlite3_diskfull;
   564    565     static struct {
   565    566       char *zName;
   566    567       Tcl_CmdProc *xProc;
   567    568     } aCmd[] = {
   568    569       { "pager_open",              (Tcl_CmdProc*)pager_open          },
   569    570       { "pager_close",             (Tcl_CmdProc*)pager_close         },
   570    571       { "pager_commit",            (Tcl_CmdProc*)pager_commit        },
................................................................................
   589    590     for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
   590    591       Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
   591    592     }
   592    593     Tcl_LinkVar(interp, "sqlite_io_error_pending",
   593    594        (char*)&sqlite3_io_error_pending, TCL_LINK_INT);
   594    595     Tcl_LinkVar(interp, "sqlite_diskfull_pending",
   595    596        (char*)&sqlite3_diskfull_pending, TCL_LINK_INT);
          597  +  Tcl_LinkVar(interp, "sqlite_diskfull",
          598  +     (char*)&sqlite3_diskfull, TCL_LINK_INT);
   596    599     Tcl_LinkVar(interp, "pager_pagesize",
   597    600        (char*)&test_pagesize, TCL_LINK_INT);
   598    601     return TCL_OK;
   599    602   }

Changes to test/diskfull.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing for correct handling of disk full
    13     13   # errors.
    14     14   # 
    15         -# $Id: diskfull.test,v 1.2 2005/08/11 02:10:19 drh Exp $
           15  +# $Id: diskfull.test,v 1.3 2005/09/09 10:46:19 drh Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   do_test diskfull-1.1 {
    21     21     execsql {
    22     22       CREATE TABLE t1(x);
    23     23       INSERT INTO t1 VALUES(randstr(1000,1000));
    24     24       INSERT INTO t1 SELECT * FROM t1;
           25  +    INSERT INTO t1 SELECT * FROM t1;
           26  +    INSERT INTO t1 SELECT * FROM t1;
           27  +    INSERT INTO t1 SELECT * FROM t1;
           28  +    CREATE INDEX t1i1 ON t1(x);
           29  +    CREATE TABLE t2 AS SELECT x AS a, x AS b FROM t1;
           30  +    CREATE INDEX t2i1 ON t2(b);
    25     31     }
    26     32   } {}
    27         -do_test diskfull-1.2 {
           33  +set sqlite_diskfull_pending 0
           34  +integrity_check diskfull-1.2
           35  +do_test diskfull-1.3 {
    28     36     set sqlite_diskfull_pending 1
    29     37     catchsql {
    30     38       INSERT INTO t1 SELECT * FROM t1;
    31     39     }
    32     40   } {1 {database or disk is full}}
    33         -do_test diskfull-1.3 {
           41  +set sqlite_diskfull_pending 0
           42  +integrity_check diskfull-1.4
           43  +do_test diskfull-1.5 {
    34     44     set sqlite_diskfull_pending 1
    35     45     catchsql {
    36     46       DELETE FROM t1;
    37     47     }
    38     48   } {1 {database or disk is full}}
           49  +set sqlite_diskfull_pending 0
           50  +integrity_check diskfull-1.6
           51  +
           52  +set go 1
           53  +set i 0
           54  +while {$go} {
           55  +  incr i
           56  +  do_test diskfull-2.$i.1 {
           57  +    set sqlite_diskfull_pending $i
           58  +    set sqlite_diskfull 0
           59  +    set r [catchsql {VACUUM}]
           60  +    if {!$sqlite_diskfull} {
           61  +      set r {1 {database or disk is full}}
           62  +      set go 0
           63  +    }
           64  +    if {$r=="1 {disk I/O error}"} {
           65  +      set r {1 {database or disk is full}}
           66  +    }
           67  +    set r
           68  +  } {1 {database or disk is full}}
           69  +  set sqlite_diskfull_pending 0
           70  +  db close
           71  +  sqlite3 db test.db
           72  +  integrity_check diskfull-2.$i.2
           73  +}
    39     74   
    40     75   finish_test