/ Check-in [26b2e1ae]
Login

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

Overview
Comment:Additional coverage testing. (CVS 3823)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 26b2e1aede3f776134b2d6e941d17a907843e650
User & Date: drh 2007-04-06 18:23:18
Context
2007-04-06
21:42
Changes to test scripts to support alternative configurations. (CVS 3824) check-in: 3471a226 user: drh tags: trunk
18:23
Additional coverage testing. (CVS 3823) check-in: 26b2e1ae user: drh tags: trunk
15:02
Binary file I/O infrastructure added and used to increase test coverage for detection of corrupt database files. (CVS 3822) check-in: 479b3d96 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

   915    915   ** *id unchanged.
   916    916   */
   917    917   static int unixOpenDirectory(
   918    918     OsFile *id,
   919    919     const char *zDirname
   920    920   ){
   921    921     unixFile *pFile = (unixFile*)id;
   922         -  if( pFile==0 ){
   923         -    /* Do not open the directory if the corresponding file is not already
   924         -    ** open. */
   925         -    return SQLITE_CANTOPEN;
   926         -  }
          922  +  assert( pFile!=0 );
   927    923     SET_THREADID(pFile);
   928    924     assert( pFile->dirfd<0 );
   929    925     pFile->dirfd = open(zDirname, O_RDONLY|O_BINARY, 0);
   930    926     if( pFile->dirfd<0 ){
   931    927       return SQLITE_CANTOPEN; 
   932    928     }
   933    929     OSTRACE3("OPENDIR %-3d %s\n", pFile->dirfd, zDirname);
................................................................................
   996    992   */
   997    993   static int seekAndRead(unixFile *id, void *pBuf, int cnt){
   998    994     int got;
   999    995     i64 newOffset;
  1000    996     TIMER_START;
  1001    997   #if defined(USE_PREAD)
  1002    998     got = pread(id->h, pBuf, cnt, id->offset);
          999  +  SimulateIOError( got = -1 );
  1003   1000   #elif defined(USE_PREAD64)
  1004   1001     got = pread64(id->h, pBuf, cnt, id->offset);
         1002  +  SimulateIOError( got = -1 );
  1005   1003   #else
  1006   1004     newOffset = lseek(id->h, id->offset, SEEK_SET);
         1005  +  SimulateIOError( newOffset-- );
  1007   1006     if( newOffset!=id->offset ){
  1008   1007       return -1;
  1009   1008     }
  1010   1009     got = read(id->h, pBuf, cnt);
  1011   1010   #endif
  1012   1011     TIMER_END;
  1013   1012     OSTRACE5("READ    %-3d %5d %7lld %d\n", id->h, got, id->offset, TIMER_ELAPSED);
................................................................................
  1022   1021   ** bytes were read successfully and SQLITE_IOERR if anything goes
  1023   1022   ** wrong.
  1024   1023   */
  1025   1024   static int unixRead(OsFile *id, void *pBuf, int amt){
  1026   1025     int got;
  1027   1026     assert( id );
  1028   1027     got = seekAndRead((unixFile*)id, pBuf, amt);
  1029         -  SimulateIOError( got = -1 );
  1030   1028     if( got==amt ){
  1031   1029       return SQLITE_OK;
  1032   1030     }else if( got<0 ){
  1033   1031       return SQLITE_IOERR_READ;
  1034   1032     }else{
  1035   1033       memset(&((char*)pBuf)[got], 0, amt-got);
  1036   1034       return SQLITE_IOERR_SHORT_READ;

Changes to src/pager.c.

    14     14   ** The pager is used to access a database disk file.  It implements
    15     15   ** atomic commit and rollback through the use of a journal file that
    16     16   ** is separate from the database file.  The pager also implements file
    17     17   ** locking to prevent two processes from writing the same database
    18     18   ** file simultaneously, or one process from reading the database while
    19     19   ** another is writing.
    20     20   **
    21         -** @(#) $Id: pager.c,v 1.323 2007/04/05 17:15:53 danielk1977 Exp $
           21  +** @(#) $Id: pager.c,v 1.324 2007/04/06 18:23:18 drh Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   #include "os.h"
    26     26   #include "pager.h"
    27     27   #include <assert.h>
    28     28   #include <string.h>
................................................................................
  2504   2504   **
  2505   2505   ** If the current size of the database file is 0 but a journal file
  2506   2506   ** exists, that is probably an old journal left over from a prior
  2507   2507   ** database with the same name.  Just delete the journal.
  2508   2508   */
  2509   2509   static int hasHotJournal(Pager *pPager){
  2510   2510     if( !pPager->useJournal ) return 0;
  2511         -  if( !sqlite3OsFileExists(pPager->zJournal) ) return 0;
  2512         -  if( sqlite3OsCheckReservedLock(pPager->fd) ) return 0;
         2511  +  if( !sqlite3OsFileExists(pPager->zJournal) ){
         2512  +    return 0;
         2513  +  }
         2514  +  if( sqlite3OsCheckReservedLock(pPager->fd) ){
         2515  +    return 0;
         2516  +  }
  2513   2517     if( sqlite3PagerPagecount(pPager)==0 ){
  2514   2518       sqlite3OsDelete(pPager->zJournal);
  2515   2519       return 0;
  2516   2520     }else{
  2517   2521       return 1;
  2518   2522     }
  2519   2523   }

Added test/lock4.test.

            1  +# 2007 April 6
            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  +# This file implements regression tests for SQLite library.  The
           12  +# focus of this script is database locks.
           13  +#
           14  +# $Id: lock4.test,v 1.3 2007/04/06 18:23:19 drh Exp $
           15  +
           16  +
           17  +set testdir [file dirname $argv0]
           18  +source $testdir/tester.tcl
           19  +
           20  +# Initialize the test.db database so that it is non-empty
           21  +#
           22  +do_test lock4-1.1 {
           23  +  db eval {CREATE TABLE t1(x)}
           24  +  file delete -force test2.db test2.db-journal
           25  +  sqlite3 db2 test2.db
           26  +  db2 eval {CREATE TABLE t2(x)}
           27  +  db2 close
           28  +  list [file size test.db] [file size test2.db]
           29  +} {2048 2048}
           30  +
           31  +# Create a script to drive a separate process that will
           32  +#
           33  +#     1.  Create a second database test2.db
           34  +#     2.  Get an exclusive lock on test2.db
           35  +#     3.  Add an entry to test.db in table t1, waiting as necessary.
           36  +#     4.  Commit the change to test2.db.
           37  +#
           38  +# Meanwhile, this process will:
           39  +# 
           40  +#     A.  Get an exclusive lock on test.db
           41  +#     B.  Attempt to read from test2.db but get an SQLITE_BUSY error.
           42  +#     C.  Commit the changes to test.db thus alloing the other process
           43  +#         to continue.
           44  +#
           45  +do_test lock4-1.2 {
           46  +  set out [open test2-script.tcl w]
           47  +  puts $out "set sqlite_pending_byte [set sqlite_pending_byte]"
           48  +  puts $out {
           49  +     sqlite3 db2 test2.db
           50  +     db2 eval {
           51  +        BEGIN;
           52  +        INSERT INTO t2 VALUES(2);
           53  +     }
           54  +     sqlite3 db test.db
           55  +     db timeout 1000000
           56  +     db eval {
           57  +        INSERT INTO t1 VALUES(2);
           58  +     }
           59  +     db2 eval COMMIT
           60  +     exit
           61  +  }
           62  +  close $out
           63  +  db eval {
           64  +     BEGIN;
           65  +     INSERT INTO t1 VALUES(1);
           66  +  }
           67  +  exec [info nameofexec] ./test2-script.tcl &
           68  +  while {![file exists test2.db-journal]} {
           69  +    after 10
           70  +  }
           71  +  sqlite3 db2 test2.db
           72  +  catchsql {
           73  +    INSERT INTO t2 VALUES(1)
           74  +  } db2
           75  +} {1 {database is locked}}
           76  +do_test lock4-1.3 {
           77  +  db eval {
           78  +     COMMIT;
           79  +  }
           80  +  while {[file exists test2.db-journal]} {
           81  +    after 10
           82  +  }
           83  +  db2 eval {
           84  +     SELECT * FROM t2
           85  +  }
           86  +} {2}
           87  +
           88  +    
           89  +do_test lock4-999.1 {
           90  +  rename db2 {}
           91  +} {}
           92  +
           93  +finish_test

Changes to tool/lempar.c.

   206    206   /* For tracing reduce actions, the names of all rules are required.
   207    207   */
   208    208   static const char *const yyRuleName[] = {
   209    209   %%
   210    210   };
   211    211   #endif /* NDEBUG */
   212    212   
   213         -/*
   214         -** This function returns the symbolic name associated with a token
   215         -** value.
   216         -*/
   217         -const char *ParseTokenName(int tokenType){
   218         -#ifndef NDEBUG
   219         -  if( tokenType>0 && tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){
   220         -    return yyTokenName[tokenType];
   221         -  }else{
   222         -    return "Unknown";
   223         -  }
   224         -#else
   225         -  return "";
   226         -#endif
   227         -}
   228    213   
   229    214   #if YYSTACKDEPTH<=0
   230    215   /*
   231    216   ** Try to increase the size of the parser stack.
   232    217   */
   233    218   static void yyGrowStack(yyParser *p){
   234    219     int newSize;