Update the .help screen in the CLI. Make sure the temporary files for
[sqlite.git] / test / mmap2.test
blob1f8346b915eac5b29d5d4a51d27bf9d793ec2bc0
1 # 2013 March 20
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # This file tests the effect of the mmap() or mremap() system calls 
13 # returning an error on the library. 
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.
20 set testdir [file dirname $argv0]
21 source $testdir/tester.tcl
22 set testprefix mmap2
24 if {$::tcl_platform(platform)!="unix" || [test_syscall defaultvfs] != "unix"} {
25   finish_test
26   return
28 ifcapable !mmap {
29   finish_test
30   return
33 db close
34 sqlite3_shutdown
35 test_sqlite3_log xLog
36 proc xLog {error_code msg} {
37   if {[string match os_unix.c* $msg]} {
38     lappend ::log $msg 
39   }
42 foreach syscall {mmap mremap} {
43   test_syscall uninstall 
44   if {[catch {test_syscall install $syscall}]} continue
46   for {set i 1} {$i < 20} {incr i} {
47     reset_db
48     execsql { PRAGMA mmap_size = 8000000 }
50     test_syscall fault $i 1
51     test_syscall errno $syscall ENOMEM
52     set ::log ""
54     do_execsql_test 1.$syscall.$i.1 {
55       CREATE TABLE t1(a, b, UNIQUE(a, b));
56       INSERT INTO t1 VALUES(randomblob(1000), randomblob(1000));
57       INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
58       INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
59       INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
60       INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
61       INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
62       INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1;
63     }
65     set nFail [test_syscall fault 0 0]
67     do_execsql_test 1.$syscall.$i.2 {
68       SELECT count(*) FROM t1;
69       PRAGMA integrity_check;
70     } {64 ok}
72     do_test 1.$syscall.$i.3 {
73       expr {$nFail==0 || $nFail==1}
74     } {1}
76     do_test 1.$syscall.$i.4.nFail=$nFail {
77       regexp ".*${syscall}.*" $::log
78     } [expr $nFail>0]
79   }
82 db close
83 test_syscall uninstall 
84 sqlite3_shutdown
85 test_sqlite3_log 
86 sqlite3_initialize
87 finish_test