AryaWu/sqlite
0
1# 2016 February 042#3# The author disclaims copyright to this source code. In place of4# 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# 19set testdir [file dirname $argv0]20source $testdir/tester.tcl21ifcapable !mmap {22 finish_test23 return24}25source $testdir/lock_common.tcl26set testprefix mmap427 28# Return a Tcl script that registers a user-defined scalar function 29# named rblob() with database handle $dbname. The function returns a30# sequence of pseudo-random blobs based on seed value $seed.31#32proc register_rblob_code {dbname seed} {33 return [subst -nocommands {34 set ::rcnt $seed35 proc rblob {n} {36 set ::rcnt [expr (([set ::rcnt] << 3) + [set ::rcnt] + 456) & 0xFFFFFFFF]37 set str [format %.8x [expr [set ::rcnt] ^ 0xbdf20da3]]38 string range [string repeat [set str] [expr [set n]/4]] 1 [set n]39 }40 $dbname func rblob rblob41 }]42}43 44#-------------------------------------------------------------------------45# Test various mmap_size settings.46#47foreach {tn1 mmap1 mmap2} {48 1 6144 16777349 2 18432 14039950 3 43008 40130251 4 92160 25389952 5 190464 253 6 387072 75243154 7 780288 29114355 8 1566720 59430656 9 3139584 82913757 10 6285312 79396358 11 12576768 101559059} {60 do_multiclient_test tn {61 sql1 {62 CREATE TABLE t1(a PRIMARY KEY);63 CREATE TABLE t2(x);64 INSERT INTO t2 VALUES('');65 }66 67 code1 [register_rblob_code db 0]68 code2 [register_rblob_code db2 444]69 70 sql1 "PRAGMA mmap_size = $mmap1"71 sql2 "PRAGMA mmap_size = $mmap2"72 73 do_test $tn1.$tn {74 for {set i 1} {$i <= 100} {incr i} {75 if {$i % 2} {76 set c1 sql177 set c2 sql278 } else {79 set c1 sql280 set c2 sql181 }82 83 $c1 {84 INSERT INTO t1 VALUES( rblob(5000) );85 UPDATE t2 SET x = (SELECT md5sum(a) FROM t1);86 }87 88 set res [$c2 {89 SELECT count(*) FROM t1;90 SELECT x == (SELECT md5sum(a) FROM t1) FROM t2;91 PRAGMA integrity_check;92 }]93 if {$res != [list $i 1 ok]} {94 do_test $tn1.$tn.$i {95 set ::res96 } [list $i 1 ok]97 }98 }99 set res 1100 } {1}101 }102}103 104finish_test105 