summaryrefslogtreecommitdiff
path: root/test/mmap2.test
diff options
context:
space:
mode:
authorHans-Christoph Steiner <hans@eds.org>2013-08-13 15:43:01 -0400
committerHans-Christoph Steiner <hans@eds.org>2013-08-13 15:43:01 -0400
commit4228998fd796fa2f9e84fb73632e0a07cc7cd188 (patch)
tree15b2336f351468fedd0c39e9de4ad905a686f3b0 /test/mmap2.test
parentbdee7cf7d974b2f70d5934786c5666006e7360be (diff)
parent08119c361d1181b3e8f1abb429236e488a664753 (diff)
Merge tag 'upstream/2.2.1'
Upstream version 2.2.1 # gpg: Signature made Tue 13 Aug 2013 03:42:56 PM EDT using RSA key ID 374BBE81 # gpg: Good signature from "Hans-Christoph Steiner <hans@at.or.at>" # gpg: aka "[jpeg image of size 5408]" # gpg: aka "Hans-Christoph Steiner <hs420@nyu.edu>" # gpg: aka "Hans-Christoph Steiner <hans@eds.org>" # gpg: aka "Hans-Christoph Steiner <hans@guardianproject.info>" # gpg: aka "Hans-Christoph Steiner <hansi@nyu.edu>" # gpg: aka "Hans-Christoph Steiner <hans@guardianproject.info>"
Diffstat (limited to 'test/mmap2.test')
-rw-r--r--test/mmap2.test87
1 files changed, 87 insertions, 0 deletions
diff --git a/test/mmap2.test b/test/mmap2.test
new file mode 100644
index 0000000..1f8346b
--- /dev/null
+++ b/test/mmap2.test
@@ -0,0 +1,87 @@
+# 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 {$::tcl_platform(platform)!="unix" || [test_syscall defaultvfs] != "unix"} {
+ finish_test
+ return
+}
+ifcapable !mmap {
+ 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
+ execsql { PRAGMA mmap_size = 8000000 }
+
+ 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]
+ }
+}
+
+db close
+test_syscall uninstall
+sqlite3_shutdown
+test_sqlite3_log
+sqlite3_initialize
+finish_test