14ff7bc45Sdan# 2013 March 20 24ff7bc45Sdan# 34ff7bc45Sdan# The author disclaims copyright to this source code. In place of 44ff7bc45Sdan# a legal notice, here is a blessing: 54ff7bc45Sdan# 64ff7bc45Sdan# May you do good and not evil. 74ff7bc45Sdan# May you find forgiveness for yourself and forgive others. 84ff7bc45Sdan# May you share freely, never taking more than you give. 94ff7bc45Sdan# 104ff7bc45Sdan#*********************************************************************** 114ff7bc45Sdan# 124ff7bc45Sdan# This file tests the effect of the mmap() or mremap() system calls 134ff7bc45Sdan# returning an error on the library. 144ff7bc45Sdan# 154ff7bc45Sdan# If either mmap() or mremap() fails, SQLite should log an error 164ff7bc45Sdan# message, then continue accessing the database using read() and 174ff7bc45Sdan# write() exclusively. 184ff7bc45Sdan# 194ff7bc45Sdan 204ff7bc45Sdanset testdir [file dirname $argv0] 214ff7bc45Sdansource $testdir/tester.tcl 224ff7bc45Sdanset testprefix mmap2 234ff7bc45Sdan 24a478b3faSdrhif {$::tcl_platform(platform)!="unix" || [test_syscall defaultvfs] != "unix"} { 254ff7bc45Sdan finish_test 264ff7bc45Sdan return 274ff7bc45Sdan} 28188d4884Sdrhifcapable !mmap { 29188d4884Sdrh finish_test 30188d4884Sdrh return 31188d4884Sdrh} 324ff7bc45Sdan 334ff7bc45Sdandb close 344ff7bc45Sdansqlite3_shutdown 354ff7bc45Sdantest_sqlite3_log xLog 364ff7bc45Sdanproc xLog {error_code msg} { 374ff7bc45Sdan if {[string match os_unix.c* $msg]} { 384ff7bc45Sdan lappend ::log $msg 394ff7bc45Sdan } 404ff7bc45Sdan} 414ff7bc45Sdan 424ff7bc45Sdanforeach syscall {mmap mremap} { 434ff7bc45Sdan test_syscall uninstall 444ff7bc45Sdan if {[catch {test_syscall install $syscall}]} continue 454ff7bc45Sdan 464ff7bc45Sdan for {set i 1} {$i < 20} {incr i} { 474ff7bc45Sdan reset_db 48*cf8489feSdan execsql { PRAGMA mmap_size = 8000000 } 494ff7bc45Sdan 504ff7bc45Sdan test_syscall fault $i 1 514ff7bc45Sdan test_syscall errno $syscall ENOMEM 524ff7bc45Sdan set ::log "" 534ff7bc45Sdan 544ff7bc45Sdan do_execsql_test 1.$syscall.$i.1 { 554ff7bc45Sdan CREATE TABLE t1(a, b, UNIQUE(a, b)); 564ff7bc45Sdan INSERT INTO t1 VALUES(randomblob(1000), randomblob(1000)); 574ff7bc45Sdan INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; 584ff7bc45Sdan INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; 594ff7bc45Sdan INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; 604ff7bc45Sdan INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; 614ff7bc45Sdan INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; 624ff7bc45Sdan INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; 634ff7bc45Sdan } 644ff7bc45Sdan 654ff7bc45Sdan set nFail [test_syscall fault 0 0] 664ff7bc45Sdan 674ff7bc45Sdan do_execsql_test 1.$syscall.$i.2 { 684ff7bc45Sdan SELECT count(*) FROM t1; 694ff7bc45Sdan PRAGMA integrity_check; 704ff7bc45Sdan } {64 ok} 714ff7bc45Sdan 724ff7bc45Sdan do_test 1.$syscall.$i.3 { 734ff7bc45Sdan expr {$nFail==0 || $nFail==1} 744ff7bc45Sdan } {1} 754ff7bc45Sdan 764ff7bc45Sdan do_test 1.$syscall.$i.4.nFail=$nFail { 774ff7bc45Sdan regexp ".*${syscall}.*" $::log 784ff7bc45Sdan } [expr $nFail>0] 794ff7bc45Sdan } 804ff7bc45Sdan} 814ff7bc45Sdan 8281d1765aSdandb close 834ff7bc45Sdantest_syscall uninstall 8481d1765aSdansqlite3_shutdown 8581d1765aSdantest_sqlite3_log 8681d1765aSdansqlite3_initialize 874ff7bc45Sdanfinish_test 88