]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Improve the os_test.c module. (CVS 1657)
authordanielk1977 <danielk1977@noemail.net>
Tue, 22 Jun 2004 12:18:32 +0000 (12:18 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Tue, 22 Jun 2004 12:18:32 +0000 (12:18 +0000)
FossilOrigin-Name: ecdb93d3c92e34f7d85aa2fd703880669397b216

main.mk
manifest
manifest.uuid
src/build.c
src/os_test.c
src/os_test.h
src/pager.c
src/test1.c

diff --git a/main.mk b/main.mk
index 7b9c22e58c0e8976a687664abf2562cf1e61ad3d..cf234635c9fdf9cc575cefbda2261a15d1ee17f4 100644 (file)
--- a/main.mk
+++ b/main.mk
@@ -359,7 +359,7 @@ testfixture$(EXE):  $(TOP)/src/tclsqlite.c libsqlite3.a $(TESTSRC)
                libsqlite3.a $(LIBTCL) $(THREADLIB)
 
 testfixturex:  $(TOP)/src/tclsqlite.c libsqlite3.a $(TESTSRC)
-       $(TCCX) $(TCL_FLAGS) -DOS_TEST=1 -DTCLSH=1 -DSQLITE_TEST=1 -o testfixture$(EXE) \
+       $(TCCX) $(TCL_FLAGS) -DOS_TEST=1 -DTCLSH=1 -DSQLITE_TEST=1 -o testfixturex \
                $(TESTSRC) $(TOP)/src/tclsqlite.c \
                libsqlite3.a $(LIBTCL) $(THREADLIB)
 
index c2dfdd500767b37aa7a0e3e18b9142eb15a193c7..2ebba38ebaf5bdcc3192b63cb3d3cc4253e9dd89 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Patch\saround\scompilers\sthat\sdo\snot\ssupport\s"long\slong\sint".\s(CVS\s1656)
-D 2004-06-22T12:13:55
+C Improve\sthe\sos_test.c\smodule.\s(CVS\s1657)
+D 2004-06-22T12:18:32
 F Makefile.in 0a3d7aaefa50717bd550b0cf568a51072c4c103c
 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -17,7 +17,7 @@ F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
 F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
 F ltmain.sh f6b283068efa69f06eb8aa1fe4bddfdbdeb35826
-F main.mk 0692293db19dc8206d88abe9c24e11fa22a2ab95
+F main.mk e0dcbccbec3295c7b59d6d5578cf48304b99c887
 F mkdll.sh 68d34a961a1fdfa15ef27fc4f4740be583112124
 F publish.sh 5bc5e493fa1773a3c0d9712182de0f5abd494903
 F spec.template a38492f1c1dd349fc24cb0565e08afc53045304b
@@ -28,7 +28,7 @@ F src/attach.c 05102e2e8ac43ce639d07b47a99c7772a62420e6
 F src/auth.c 60db23b98bb94c8b0178180faaf49dc116674217
 F src/btree.c 0cf8a52a57a7eb13d50719114ee1fa353e89d7d3
 F src/btree.h 32f96abef464cf8765b23ca669acfe90d191fcc5
-F src/build.c ee7548a4dfc446d4312c217d74badbd2898a7eef
+F src/build.c baed8f54ea9fb785cb798dc6600b07697b8595d4
 F src/date.c b3e8b2bef1e3f2ce24e5b057203036defb18c3f1
 F src/delete.c e81545e546f6bc87d7508a93a09ca70695265af3
 F src/encode.c a876af473d1d636faa3dca51c7571f2e007eea37
@@ -44,13 +44,13 @@ F src/os.h 2f5ea879b784bc82aac8022a3e8fe00b73c83d67
 F src/os_common.h ba1b7306e16e2091718f2c48db0fe6c1d7a31bb8
 F src/os_mac.c 3d31e26be1411acfb7961033098631b4f3486fdf
 F src/os_mac.h 51d2445f47e182ed32d3bd6937f81070c6fd9bd4
-F src/os_test.c 616d6845ef7015c31d283ece85e8a7700f7986c7
-F src/os_test.h 6665b2ace17a76ecee68bc463343340d3cd5c1cc
+F src/os_test.c 0c6490723681649c11852adf701f00e09a981d1e
+F src/os_test.h c47bad966c6f6f9bb4448abfc03c18884bc0ca9f
 F src/os_unix.c 39e73ed02fc992a6bfc52200ea26704633412cc0
 F src/os_unix.h 00c1f82b526ab2fb7ee5ddd555ea4ed68363c93a
 F src/os_win.c 84549f6cc815237533c5d0eb3697352b03478d96
 F src/os_win.h babd4e912967c6b09088cfe38a45e8005a07ba44
-F src/pager.c d9d3f577319ebac6670d3f44eca46060b78ee6b2
+F src/pager.c 5fac95a8fef916a4c5915ccc3b8dc72312681880
 F src/pager.h bc58d32a9dee464f7268fb68652c130a4216e438
 F src/parse.y 097438674976355a10cf177bd97326c548820b86
 F src/pragma.c 0750e1c360647dbe0a991f16133b0fe5e42e5039
@@ -62,7 +62,7 @@ F src/sqlite.h.in 1f400a561fca3b1df73677d2d97046425d47cae4
 F src/sqliteInt.h dd796b6abc6d50505fe33c54f0143d7000681a41
 F src/table.c af14284fa36c8d41f6829e3f2819dce07d3e2de2
 F src/tclsqlite.c 8d093146332b2f0cbf2a8ebe8597d481619308a3
-F src/test1.c ee426e026ad9223483e7a84bb68849fc6e9f542e
+F src/test1.c 9a9d9069c1c390c8be81038f77aed976bb58844c
 F src/test2.c dafd8bd314a554bf376c6d3a8c83fd69219f5a40
 F src/test3.c 7247090d15a5a43823079b6fd8dad1ed3cccdedf
 F src/test4.c a921a69821fd30209589228e64f94e9f715b6fe2
@@ -227,7 +227,7 @@ F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075
 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
 F www/version3.tcl af528563442e3039928f9018327a18157e53a44f
 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
-P d16b863849d1aa887fe403e25153b1e9df6b837e
-R 85dc3ae43867f14feba3557419001a96
-U drh
-Z bbfe7d28a769302b653c6e45868a429e
+P d98b1502e2947d24ab9f4a5d2e5b9a95dde92faf
+R 6110d7f21fe73b602543dea11b1b80ca
+U danielk1977
+Z 5ef671e5847eb9235ebe6c8ce5485e34
index c801fc4453d7eed267a237dcdb0f13d80e53feda..e26fd9c9f20a29da43da2081aacb40fb04b96634 100644 (file)
@@ -1 +1 @@
-d98b1502e2947d24ab9f4a5d2e5b9a95dde92faf
\ No newline at end of file
+ecdb93d3c92e34f7d85aa2fd703880669397b216
\ No newline at end of file
index b1ff5016d3de1d77e3af26807723a5ef0988fc10..4a6ece04eb41bf5381106f1c6a50d3f34b6547ac 100644 (file)
@@ -23,7 +23,7 @@
 **     ROLLBACK
 **     PRAGMA
 **
-** $Id: build.c,v 1.230 2004/06/21 18:14:46 drh Exp $
+** $Id: build.c,v 1.231 2004/06/22 12:18:32 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -965,16 +965,16 @@ CollSeq *sqlite3FindCollSeq(
 ** If the collation sequence
 */
 static void callCollNeeded(sqlite *db, const char *zName, int nName){
-  char const *zExternal = 0;
   assert( !db->xCollNeeded || !db->xCollNeeded16 );
   if( nName<0 ) nName = strlen(zName);
   if( db->xCollNeeded ){
-    zExternal = sqliteStrNDup(zName, nName);
+    char *zExternal = sqliteStrNDup(zName, nName);
     if( !zExternal ) return;
     db->xCollNeeded(db->pCollNeededArg, db, (int)db->enc, zExternal);
     sqliteFree(zExternal);
   }
   if( db->xCollNeeded16 ){
+    char const *zExternal;
     sqlite3_value *pTmp = sqlite3GetTransientValue(db);
     sqlite3ValueSetStr(pTmp, -1, zName, SQLITE_UTF8, SQLITE_STATIC);
     zExternal = sqlite3ValueText(pTmp, SQLITE_UTF16NATIVE);
index b6fd755f109b7254c6b0e9deb3db9f06db01e174..fb2e915939235959714428668e0068200ae8272f 100644 (file)
@@ -95,27 +95,52 @@ static int crashseed(){
   return i;
 }
 
+static OsTestFile *pAllFiles = 0;
+
 /*
 ** Initialise the os_test.c specific fields of pFile.
 */
-static void initFile(OsFile *pFile){
+static void initFile(OsFile *id){
+  OsTestFile *pFile = (OsTestFile *)sqliteMalloc(sizeof(OsTestFile));
   pFile->nMaxWrite = 0; 
   pFile->nBlk = 0; 
   pFile->apBlk = 0; 
+  *id = pFile;
+  pFile->pNext = pAllFiles;
+  pAllFiles = pFile;
+}
+
+/*
+** Undo the work done by initFile. Delete the OsTestFile structure
+** and unlink the structure from the pAllFiles list.
+*/
+static void closeFile(OsFile *id){
+  OsTestFile *pFile = *id;
+  if( pFile==pAllFiles ){
+    pAllFiles = pFile->pNext;
+  }else{
+    OsTestFile *p;
+    for(p=pAllFiles; p->pNext!=pFile; p=p->pNext ){
+      assert( p );
+    }
+    p->pNext = pFile->pNext;
+  }
+  sqliteFree(pFile);
+  *id = 0;
 }
 
 /*
 ** Return the current seek offset from the start of the file. This
 ** is unix-only code.
 */
-static off_t osTell(OsFile *pFile){
+static off_t osTell(OsTestFile *pFile){
   return lseek(pFile->fd.h, 0, SEEK_CUR);
 }
 
 /*
 ** Load block 'blk' into the cache of pFile.
 */
-static int cacheBlock(OsFile *pFile, int blk){
+static int cacheBlock(OsTestFile *pFile, int blk){
   if( blk>=pFile->nBlk ){
     int n = ((pFile->nBlk * 2) + 100 + blk);
     pFile->apBlk = (u8 **)sqliteRealloc(pFile->apBlk, n * sizeof(u8*));
@@ -153,7 +178,7 @@ static int cacheBlock(OsFile *pFile, int blk){
 ** Write the cache of pFile to disk. If crash is non-zero, randomly
 ** skip blocks when writing. The cache is deleted before returning.
 */
-static int writeCache2(OsFile *pFile, int crash){
+static int writeCache2(OsTestFile *pFile, int crash){
   int i;
   int nMax = pFile->nMaxWrite;
   off_t offset;
@@ -197,13 +222,17 @@ static int writeCache2(OsFile *pFile, int crash){
 /*
 ** Write the cache to disk.
 */
-static int writeCache(OsFile *pFile){
-  if( crashseed() ){
-    /* FIX ME: writeCache2() should be called on all open files
-    ** here. */
-    writeCache2(pFile, 1);
+static int writeCache(OsTestFile *pFile){
+  int cs = crashseed();
+  if( cs==1 ){
+    /* FIX ME: writeCache2() should be called on all open files here. */
+    OsTestFile *pFile;
+    for(pFile=pAllFiles; pFile; pFile=pFile->pNext){
+      writeCache2(pFile, 1);
+    }
     exit(-1);
   }else{
+    if( cs>0 ) sqlite3SetCrashseed(cs-1);
     return writeCache2(pFile, 0);
   }
 }
@@ -212,9 +241,12 @@ static int writeCache(OsFile *pFile){
 ** Close the file.
 */
 int sqlite3OsClose(OsFile *id){
-  if( !id->fd.isOpen ) return SQLITE_OK;
-  writeCache(id);
-  sqlite3RealClose(&id->fd);
+  if( !(*id) ) return SQLITE_OK;
+  if( (*id)->fd.isOpen ){
+    writeCache(*id);
+    sqlite3RealClose(&(*id)->fd);
+  }
+  closeFile(id);
   return SQLITE_OK;
 }
 
@@ -225,8 +257,9 @@ int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
   int i;
   u8 *zCsr;
   int rc = SQLITE_OK;
+  OsTestFile *pFile = *id;
 
-  offset = osTell(id);
+  offset = osTell(pFile);
   end = offset+amt;
   blk = (offset/BLOCKSIZE);
 
@@ -244,13 +277,13 @@ int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
       len = len - (BLOCK_OFFSET(i+1)-end);
     }
 
-    if( i<id->nBlk && id->apBlk[i]){
-      u8 *pBlk = id->apBlk[i];
+    if( i<pFile->nBlk && pFile->apBlk[i]){
+      u8 *pBlk = pFile->apBlk[i];
       memcpy(zCsr, &pBlk[off], len);
     }else{
-      rc = sqlite3RealSeek(&id->fd, BLOCK_OFFSET(i) + off);
+      rc = sqlite3RealSeek(&pFile->fd, BLOCK_OFFSET(i) + off);
       if( rc!=SQLITE_OK ) return rc;
-      rc = sqlite3RealRead(&id->fd, zCsr, len);
+      rc = sqlite3RealRead(&pFile->fd, zCsr, len);
       if( rc!=SQLITE_OK ) return rc;
     }
 
@@ -258,7 +291,7 @@ int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
   }
   assert( zCsr==&((u8 *)pBuf)[amt] );
 
-  rc = sqlite3RealSeek(&id->fd, end);
+  rc = sqlite3RealSeek(&pFile->fd, end);
   return rc;
 }
 
@@ -269,8 +302,9 @@ int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
   int i;
   const u8 *zCsr;
   int rc = SQLITE_OK;
+  OsTestFile *pFile = *id;
 
-  offset = osTell(id);
+  offset = osTell(pFile);
   end = offset+amt;
   blk = (offset/BLOCKSIZE);
 
@@ -281,11 +315,11 @@ int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
     int len = 0;
 
     /* Make sure the block is in the cache */
-    rc = cacheBlock(id, i);
+    rc = cacheBlock(pFile, i);
     if( rc!=SQLITE_OK ) return rc;
 
     /* Write into the cache */
-    pBlk = id->apBlk[i];
+    pBlk = pFile->apBlk[i];
     assert( pBlk );
 
     if( BLOCK_OFFSET(i) < offset ){
@@ -298,12 +332,12 @@ int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
     memcpy(&pBlk[off], zCsr, len);
     zCsr += len;
   }
-  if( id->nMaxWrite<end ){
-    id->nMaxWrite = end;
+  if( pFile->nMaxWrite<end ){
+    pFile->nMaxWrite = end;
   }
   assert( zCsr==&((u8 *)pBuf)[amt] );
 
-  rc = sqlite3RealSeek(&id->fd, end);
+  rc = sqlite3RealSeek(&pFile->fd, end);
   return rc;
 }
 
@@ -312,9 +346,9 @@ int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
 ** real sync() function.
 */
 int sqlite3OsSync(OsFile *id){
-  int rc = writeCache(id);
+  int rc = writeCache(*id);
   if( rc!=SQLITE_OK ) return rc;
-  rc = sqlite3RealSync(&id->fd);
+  rc = sqlite3RealSync(&(*id)->fd);
   return rc;
 }
 
@@ -324,8 +358,8 @@ int sqlite3OsSync(OsFile *id){
 ** is written to disk.
 */
 int sqlite3OsTruncate(OsFile *id, off_t nByte){
-  id->nMaxWrite = nByte;
-  return sqlite3RealTruncate(&id->fd, nByte);
+  (*id)->nMaxWrite = nByte;
+  return sqlite3RealTruncate(&(*id)->fd, nByte);
 }
 
 /*
@@ -333,9 +367,9 @@ int sqlite3OsTruncate(OsFile *id, off_t nByte){
 ** the file, then return this size instead of the on-disk size.
 */
 int sqlite3OsFileSize(OsFile *id, off_t *pSize){
-  int rc = sqlite3RealFileSize(&id->fd, pSize);
-  if( rc==SQLITE_OK && pSize && *pSize<id->nMaxWrite ){
-    *pSize = id->nMaxWrite;
+  int rc = sqlite3RealFileSize(&(*id)->fd, pSize);
+  if( rc==SQLITE_OK && pSize && *pSize<(*id)->nMaxWrite ){
+    *pSize = (*id)->nMaxWrite;
   }
   return rc;
 }
@@ -347,15 +381,15 @@ int sqlite3OsFileSize(OsFile *id, off_t *pSize){
 */
 int sqlite3OsOpenReadWrite(const char *zFilename, OsFile *id, int *pReadonly){
   initFile(id);
-  return sqlite3RealOpenReadWrite(zFilename, &id->fd, pReadonly);
+  return sqlite3RealOpenReadWrite(zFilename, &(*id)->fd, pReadonly);
 }
 int sqlite3OsOpenExclusive(const char *zFilename, OsFile *id, int delFlag){
   initFile(id);
-  return sqlite3RealOpenExclusive(zFilename, &id->fd, delFlag);
+  return sqlite3RealOpenExclusive(zFilename, &(*id)->fd, delFlag);
 }
 int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){
   initFile(id);
-  return sqlite3RealOpenReadOnly(zFilename, &id->fd);
+  return sqlite3RealOpenReadOnly(zFilename, &(*id)->fd);
 }
 
 /*
@@ -363,22 +397,22 @@ int sqlite3OsOpenReadOnly(const char *zFilename, OsFile *id){
 ** backend.
 */
 int sqlite3OsSeek(OsFile *id, off_t offset){
-  return sqlite3RealSeek(&id->fd, offset);
+  return sqlite3RealSeek(&(*id)->fd, offset);
 }
 int sqlite3OsCheckReservedLock(OsFile *id){
-  return sqlite3RealCheckReservedLock(&id->fd);
+  return sqlite3RealCheckReservedLock(&(*id)->fd);
 }
 int sqlite3OsLock(OsFile *id, int locktype){
-  return sqlite3RealLock(&id->fd, locktype);
+  return sqlite3RealLock(&(*id)->fd, locktype);
 }
 int sqlite3OsUnlock(OsFile *id, int locktype){
-  return sqlite3RealUnlock(&id->fd, locktype);
+  return sqlite3RealUnlock(&(*id)->fd, locktype);
 }
 int sqlite3OsFileModTime(OsFile *id, double *prNow){
-  return sqlite3RealFileModTime(&id->fd, prNow);
+  return sqlite3RealFileModTime(&(*id)->fd, prNow);
 }
 int sqlite3OsOpenDirectory(const char *zDirname, OsFile *id){
-  return sqlite3RealOpenDirectory(zDirname, &id->fd);
+  return sqlite3RealOpenDirectory(zDirname, &(*id)->fd);
 }
 
 #endif /* OS_TEST */
index bf913eb5cca374c2619905c4014645897e98d2ed..a32cc3f256fb75254267cb0ee4319a79f143f4c6 100644 (file)
 /* Include sqliteInt.h now to get the type u8. */
 #include "sqliteInt.h"
 
-typedef struct OsFile OsFile;
-struct OsFile {
+typedef struct OsTestFile* OsFile;
+typedef struct OsTestFile OsTestFile;
+struct OsTestFile {
   u8 **apBlk;       /* Array of blocks that have been written to. */
   int nBlk;         /* Size of apBlock. */
   int nMaxWrite;    /* Largest offset written to. */
   OsRealFile fd;
+  OsTestFile *pNext;
 };
 
 void sqlite3SetCrashseed(int seed);
index fb80b7d2d6eae35a50a8304af679e54ad9516394..4f73e7629bbd417ef5ae48245b2434e87193dcfc 100644 (file)
@@ -18,7 +18,7 @@
 ** file simultaneously, or one process from reading the database while
 ** another is writing.
 **
-** @(#) $Id: pager.c,v 1.134 2004/06/22 11:29:02 danielk1977 Exp $
+** @(#) $Id: pager.c,v 1.135 2004/06/22 12:18:32 danielk1977 Exp $
 */
 #include "os.h"         /* Must be first to enable large file support */
 #include "sqliteInt.h"
@@ -2786,7 +2786,7 @@ sync_exit:
 */
 int sqlite3pager_lockstate(Pager *pPager){
 #ifdef OS_TEST
-  return pPager->fd.fd.locktype;
+  return pPager->fd->fd.locktype;
 #else
   return pPager->fd.locktype;
 #endif
index ec695751203d4e1cb24bdbcdfa98d6d0cedc41c7..4ba6c092d92cbb2dc878420cedbd2a2fc04e435a 100644 (file)
@@ -13,7 +13,7 @@
 ** is not included in the SQLite library.  It is used for automated
 ** testing of the SQLite library.
 **
-** $Id: test1.c,v 1.80 2004/06/19 08:18:23 danielk1977 Exp $
+** $Id: test1.c,v 1.81 2004/06/22 12:18:32 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "tcl.h"
@@ -984,6 +984,27 @@ bad_args:
   return TCL_ERROR;
 }
 
+static int sqlite3_crashseed(
+  void * clientData,
+  Tcl_Interp *interp,
+  int objc,
+  Tcl_Obj *CONST objv[]
+){
+#ifdef OS_TEST
+  int seed;
+  if( objc!=2 ) goto bad_args;
+  if( Tcl_GetIntFromObj(interp, objv[2], &seed) ) return TCL_ERROR;
+  sqlite3SetCrashseed(seed);
+#endif
+  return TCL_OK;
+
+bad_args:
+  Tcl_AppendResult(interp, "wrong # args: should be \"",
+      Tcl_GetStringFromObj(objv[0], 0), "<seed>", 0);
+  return TCL_ERROR;
+}
+
+
 /*
 ** Usage:    breakpoint
 **
@@ -1995,6 +2016,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
      { "sqlite3OsLock",         test_sqlite3OsLock, 0 },
      { "sqlite3OsUnlock",       test_sqlite3OsUnlock, 0 },
      { "add_test_collate",      test_collate, 0         },
+     { "sqlite3_crashseed",     sqlite3_crashseed, 0         },
 
   };
   int i;