]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add test cases for errors in mmap() or mremap() is os_unix.c.
authordan <dan@noemail.net>
Tue, 2 Apr 2013 12:04:09 +0000 (12:04 +0000)
committerdan <dan@noemail.net>
Tue, 2 Apr 2013 12:04:09 +0000 (12:04 +0000)
FossilOrigin-Name: 3098a3c1e7305033904a496ef534cb312a876fab

manifest
manifest.uuid
src/os_unix.c
src/test_syscall.c
test/mmap2.test [new file with mode: 0644]
test/speed1p.test

index edce1feec8b26f322681b22545f6dea212b1c49c..645d467c467379734155d6099acf3327ab05ad5b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Proposed\stemplate\spreprocessor\smagic\sfor\sactivating\smmap\sonly\son\splatforms\nwhere\swe\sknow\sit\sworks.
-D 2013-04-02T10:29:13.935
+C Add\stest\scases\sfor\serrors\sin\smmap()\sor\smremap()\sis\sos_unix.c.
+D 2013-04-02T12:04:09.729
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in df3e48659d80e1b7765785d8d66c86b320f72cc7
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -160,7 +160,7 @@ F src/notify.c 976dd0f6171d4588e89e874fcc765e92914b6d30
 F src/os.c 809d0707cec693e1b9b376ab229271ad74c3d35d
 F src/os.h ae08bcc5f6ec6b339f4a2adf3931bb88cc14c3e4
 F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
-F src/os_unix.c d136eca0cff2f8a5ac2f45867d5e5153d60e377c
+F src/os_unix.c 42684a59b06b912b3ab80a8ad9f4295c0572a1f4
 F src/os_win.c a2f41c9dfb9b065285ba94d4a40a31ca2e2b6ea3
 F src/pager.c 46fa7d8b29e7fb8baa6111690d900c9111a5a397
 F src/pager.h 5cb78b8e1adfd5451e600be7719f5a99d87ac3b1
@@ -226,7 +226,7 @@ F src/test_spellfix.c 56dfa6d583ac34f61af0834d7b58d674e7e18e13
 F src/test_sqllog.c bc50e5afeb7fb50e77b4594e42302df9d05446aa
 F src/test_stat.c d1569c7a4839f13e80187e2c26b2ab4da2d03935
 F src/test_superlock.c 2b97936ca127d13962c3605dbc9a4ef269c424cd
-F src/test_syscall.c fe018f95049d4f24e036d1d649516b60689b4e57
+F src/test_syscall.c 7e8293e4e6971b0f44c7f7f37b1315a8cc9f6018
 F src/test_tclvar.c f4dc67d5f780707210d6bb0eb6016a431c04c7fa
 F src/test_thread.c e286f2173563f2a1747c24bcda6b9d030bf4f4e4
 F src/test_vfs.c fb16b2d9938cf0c1afc5a423b55b952fcc024275
@@ -631,6 +631,7 @@ F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
 F test/misc7.test dd82ec9250b89178b96cd28b2aca70639d21e5b3
 F test/misuse.test ba4fb5d1a6101d1c171ea38b3c613d0661c83054
 F test/mmap1.test 9fb71daaca72f66fcc7a3b3a37fc3db99988b57a
+F test/mmap2.test bb0c97cdac0db06a5acdc6836eef9866815481b1
 F test/multiplex.test e08cc7177bd6d85990ee1d71100bb6c684c02256
 F test/multiplex2.test 580ca5817c7edbe4cc68fa150609c9473393003a
 F test/multiplex3.test d228f59eac91839a977eac19f21d053f03e4d101
@@ -731,7 +732,7 @@ F test/softheap1.test c16709a16ad79fa43b32929b2e623d1d117ccf53
 F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5
 F test/speed1.test f2974a91d79f58507ada01864c0e323093065452
 F test/speed1p.explain d841e650a04728b39e6740296b852dccdca9b2cb
-F test/speed1p.test c4a469f29f135f4d76c55b1f2a52f36e209466cc
+F test/speed1p.test b180e98609c7677382cf618c0ec9b69f789033a8
 F test/speed2.test 53177056baf6556dcbdcf032bbdfc41c1aa74ded
 F test/speed3.test d32043614c08c53eafdc80f33191d5bd9b920523
 F test/speed4.test abc0ad3399dcf9703abed2fff8705e4f8e416715
@@ -1040,7 +1041,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
-P 793ba4e996426522eeaa86589a9e974fa1fc1522
-R 2b5ee6ceec98b53d533d4ea410a1bfc7
-U drh
-Z ead310385cbe70188969099b54288940
+P d96272f031102514b02bd839aac9e37618872200
+R 323dfbce5d7140c5ce46f22a5112dcc8
+U dan
+Z 3d1807f4fa3a8cf06a6141b170b215ce
index 6c51e2ad5aaa272dd5d2f47d29cabc62ce50e52c..dfa80de2b57106302f1e77041e3d442b49e4bce7 100644 (file)
@@ -1 +1 @@
-d96272f031102514b02bd839aac9e37618872200
\ No newline at end of file
+3098a3c1e7305033904a496ef534cb312a876fab
\ No newline at end of file
index e92c7cc4a47658e8f59e517f766820b07b2cfd30..07c919c9831e7dad437fe1b4ccf786920cbef6ea 100644 (file)
@@ -4560,6 +4560,7 @@ static void unixRemapfile(
   unixFile *pFd,                  /* File descriptor object */
   i64 nNew                        /* Required mapping size */
 ){
+  const char *zErr = "mmap";
   int h = pFd->h;                      /* File descriptor open on db file */
   u8 *pOrig = (u8 *)pFd->pMapRegion;   /* Pointer to current file mapping */
   i64 nOrig = pFd->mmapOrigsize;       /* Size of pOrig region in bytes */
@@ -4571,6 +4572,7 @@ static void unixRemapfile(
   assert( nNew<=pFd->mmapLimit );
   assert( nNew>0 );
   assert( pFd->mmapOrigsize>=pFd->mmapSize );
+  assert( MAP_FAILED!=0 );
 
   if( (pFd->ctrlFlags & UNIXFILE_RDONLY)==0 ) flags |= PROT_WRITE;
 
@@ -4586,12 +4588,13 @@ static void unixRemapfile(
 
 #if HAVE_MREMAP
     pNew = osMremap(pOrig, nReuse, nNew, MREMAP_MAYMOVE);
+    zErr = "mremap";
 #else
     pNew = osMmap(pReq, nNew-nReuse, flags, MAP_SHARED, h, nReuse);
     if( pNew!=MAP_FAILED ){
       if( pNew!=pReq ){
         osMunmap(pNew, nNew - nReuse);
-        pNew = MAP_FAILED;
+        pNew = 0;
       }else{
         pNew = pOrig;
       }
@@ -4602,7 +4605,6 @@ static void unixRemapfile(
     ** mapping and set pNew to NULL so that the code below will create a
     ** new mapping from scratch.  */
     if( pNew==MAP_FAILED ){
-      pNew = 0;
       osMunmap(pOrig, nReuse);
     }
   }
@@ -4610,18 +4612,18 @@ static void unixRemapfile(
   /* If pNew is still NULL, try to create an entirely new mapping. */
   if( pNew==0 ){
     pNew = osMmap(0, nNew, flags, MAP_SHARED, h, 0);
-    if( pNew==MAP_FAILED ){
-      pNew = 0;
-      nNew = 0;
-      unixLogError(SQLITE_OK, "mmap", pFd->zPath);
-
-      /* If the mmap() above failed, assume that all subsequent mmap() calls
-      ** will probably fail too. Fall back to using xRead/xWrite exclusively
-      ** in this case.  */
-      pFd->mmapLimit = 0;
-    }
   }
 
+  if( pNew==MAP_FAILED ){
+    pNew = 0;
+    nNew = 0;
+    unixLogError(SQLITE_OK, zErr, pFd->zPath);
+
+    /* If the mmap() above failed, assume that all subsequent mmap() calls
+    ** will probably fail too. Fall back to using xRead/xWrite exclusively
+    ** in this case.  */
+    pFd->mmapLimit = 0;
+  }
   pFd->pMapRegion = (void *)pNew;
   pFd->mmapSize = pFd->mmapOrigsize = nNew;
 }
index 0b053fc599c2f850b33bcde7dd0fd038562dcae5..3d117fb2abebabeac90d072b64c22ee93124932a 100644 (file)
@@ -108,7 +108,7 @@ static int ts_pwrite64(int fd, const void *aBuf, size_t nBuf, off_t off);
 static int ts_fchmod(int fd, mode_t mode);
 static int ts_fallocate(int fd, off_t off, off_t len);
 static void *ts_mmap(void *, size_t, int, int, int, off_t);
-
+static void *ts_mremap(void*, size_t, size_t, int, ...);
 
 struct TestSyscallArray {
   const char *zName;
@@ -134,6 +134,7 @@ struct TestSyscallArray {
   /* 14 */ { "fchmod",    (sqlite3_syscall_ptr)ts_fchmod,    0, 0, 0 },
   /* 15 */ { "fallocate", (sqlite3_syscall_ptr)ts_fallocate, 0, 0, 0 },
   /* 16 */ { "mmap",      (sqlite3_syscall_ptr)ts_mmap,      0, 0, 0 },
+  /* 17 */ { "mremap",    (sqlite3_syscall_ptr)ts_mremap,    0, 0, 0 },
            { 0, 0, 0, 0, 0 }
 };
 
@@ -156,6 +157,7 @@ struct TestSyscallArray {
 #define orig_fchmod    ((int(*)(int,mode_t))aSyscall[14].xOrig)
 #define orig_fallocate ((int(*)(int,off_t,off_t))aSyscall[15].xOrig)
 #define orig_mmap      ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[16].xOrig)
+#define orig_mremap    ((void*(*)(void*,size_t,size_t,int,...))aSyscall[17].xOrig)
 
 /*
 ** This function is called exactly once from within each invocation of a
@@ -395,6 +397,17 @@ static void *ts_mmap(
   return orig_mmap(pAddr, nByte, prot, flags, fd, iOff);
 }
 
+static void *ts_mremap(void *a, size_t b, size_t c, int d, ...){
+  va_list ap;
+  void *pArg;
+  if( tsIsFailErrno("mremap") ){
+    return MAP_FAILED;
+  }
+  va_start(ap, d);
+  pArg = va_arg(ap, void *);
+  return orig_mremap(a, b, c, d, pArg);
+}
+
 static int test_syscall_install(
   void * clientData,
   Tcl_Interp *interp,
diff --git a/test/mmap2.test b/test/mmap2.test
new file mode 100644 (file)
index 0000000..d43ea97
--- /dev/null
@@ -0,0 +1,79 @@
+# 2013 March 20
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+# This file tests the effect of the mmap() or mremap() system calls 
+# returning an error on the library. 
+#
+# If either mmap() or mremap() fails, SQLite should log an error 
+# message, then continue accessing the database using read() and 
+# write() exclusively.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix mmap2
+
+if {[test_syscall defaultvfs] != "unix"} {
+  finish_test
+  return
+}
+
+db close
+sqlite3_shutdown
+test_sqlite3_log xLog
+proc xLog {error_code msg} {
+  if {[string match os_unix.c* $msg]} {
+    lappend ::log $msg 
+  }
+}
+
+foreach syscall {mmap mremap} {
+  test_syscall uninstall 
+  if {[catch {test_syscall install $syscall}]} continue
+
+  for {set i 1} {$i < 20} {incr i} {
+    reset_db
+
+    test_syscall fault $i 1
+    test_syscall errno $syscall ENOMEM
+    set ::log ""
+
+    do_execsql_test 1.$syscall.$i.1 {
+      CREATE TABLE t1(a, b, UNIQUE(a, b));
+      INSERT INTO t1 VALUES(randomblob(1000), randomblob(1000));
+      INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+      INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+      INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+      INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+      INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+      INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
+    }
+
+    set nFail [test_syscall fault 0 0]
+
+    do_execsql_test 1.$syscall.$i.2 {
+      SELECT count(*) FROM t1;
+      PRAGMA integrity_check;
+    } {64 ok}
+
+    do_test 1.$syscall.$i.3 {
+      expr {$nFail==0 || $nFail==1}
+    } {1}
+
+    do_test 1.$syscall.$i.4.nFail=$nFail {
+      regexp ".*${syscall}.*" $::log
+    } [expr $nFail>0]
+  }
+}
+
+test_syscall uninstall 
+finish_test
+
index 915f1653541ec8628c6927ef7d75e1a6e595edbc..6bf7b10e1fa87142bd11bce2f8c59597f3105782 100644 (file)
@@ -24,6 +24,8 @@ set testdir [file dirname $argv0]
 source $testdir/tester.tcl
 speed_trial_init speed1
 
+sqlite3_memdebug_vfs_oom_test 0
+
 # Set a uniform random seed
 expr srand(0)
 
@@ -78,7 +80,6 @@ do_test speed1p-1.0 {
   }
 } {i2a i2b t1 t2}
 
-
 # 50000 INSERTs on an unindexed table
 #
 set list {}