blob: 33830a6943813f44563bbdd236247a9b6caeee41 [file] [log] [blame]
dan4ff7bc42013-04-02 12:04:09 +00001# 2013 March 20
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#
12# This file tests the effect of the mmap() or mremap() system calls
13# returning an error on the library.
14#
15# If either mmap() or mremap() fails, SQLite should log an error
16# message, then continue accessing the database using read() and
17# write() exclusively.
18#
19
20set testdir [file dirname $argv0]
21source $testdir/tester.tcl
22set testprefix mmap2
23
drha478b3f2013-04-04 00:40:17 +000024if {$::tcl_platform(platform)!="unix" || [test_syscall defaultvfs] != "unix"} {
dan4ff7bc42013-04-02 12:04:09 +000025 finish_test
26 return
27}
28
29db close
30sqlite3_shutdown
31test_sqlite3_log xLog
32proc xLog {error_code msg} {
33 if {[string match os_unix.c* $msg]} {
34 lappend ::log $msg
35 }
36}
37
38foreach syscall {mmap mremap} {
39 test_syscall uninstall
40 if {[catch {test_syscall install $syscall}]} continue
41
42 for {set i 1} {$i < 20} {incr i} {
43 reset_db
44
45 test_syscall fault $i 1
46 test_syscall errno $syscall ENOMEM
47 set ::log ""
48
49 do_execsql_test 1.$syscall.$i.1 {
50 CREATE TABLE t1(a, b, UNIQUE(a, b));
51 INSERT INTO t1 VALUES(randomblob(1000), randomblob(1000));
52 INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
53 INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
54 INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
55 INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
56 INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
57 INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
58 }
59
60 set nFail [test_syscall fault 0 0]
61
62 do_execsql_test 1.$syscall.$i.2 {
63 SELECT count(*) FROM t1;
64 PRAGMA integrity_check;
65 } {64 ok}
66
67 do_test 1.$syscall.$i.3 {
68 expr {$nFail==0 || $nFail==1}
69 } {1}
70
71 do_test 1.$syscall.$i.4.nFail=$nFail {
72 regexp ".*${syscall}.*" $::log
73 } [expr $nFail>0]
74 }
75}
76
dan81d17652013-04-02 20:19:22 +000077db close
dan4ff7bc42013-04-02 12:04:09 +000078test_syscall uninstall
dan81d17652013-04-02 20:19:22 +000079sqlite3_shutdown
80test_sqlite3_log
81sqlite3_initialize
dan4ff7bc42013-04-02 12:04:09 +000082finish_test