blob: 248b5bad082faec8a06dd67e703579df05ef31bc [file] [log] [blame]
dan789efdb2013-07-06 17:57:39 +00001# 2013-05-23
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
13set testdir [file dirname $argv0]
14source $testdir/tester.tcl
15source $testdir/malloc_common.tcl
16ifcapable !mmap {
17 finish_test
18 return
19}
20set testprefix mmapfault
21
22set a_string_counter 1
23proc a_string {n} {
24 global a_string_counter
25 incr a_string_counter
26 string range [string repeat "${a_string_counter}." $n] 1 $n
27}
28db func a_string a_string
29
30do_test 1-pre {
31 execsql {
32 CREATE TABLE t1(a UNIQUE, b UNIQUE);
33 INSERT INTO t1 VALUES(a_string(200), a_string(300));
34 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
35 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
36 }
37 faultsim_save_and_close
38} {}
39
40
41do_faultsim_test 1 -prep {
42 faultsim_restore_and_reopen
43 db func a_string a_string
44 breakpoint
45 execsql {
46 PRAGMA mmap_size = 1000000;
47 PRAGMA cache_size = 5;
48 BEGIN;
49 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
50 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
51 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
52 INSERT INTO t1 SELECT a_string(200), a_string(300) FROM t1;
53 }
54} -body {
55 execsql { INSERT INTO t1 VALUES(a_string(200), a_string(300)) }
56} -test {
57 faultsim_test_result {0 {}}
58
59 if {[sqlite3_get_autocommit db]} {
60 sqlite3 db2 test.db
61 set nRow [db2 one {SELECT count(*) FROM t1}]
62 if {$nRow!=4} { error "Database content appears incorrect (1)" }
63 db2 close
64 }
65
66 execsql { INSERT INTO t1 VALUES(a_string(201), a_string(301)) }
67 set nRow [db one {SELECT count(*) FROM t1}]
68 if {$nRow!=5 && $nRow!=66 && $nRow!=65} {
69 error "Database content appears incorrect (2) ($nRow)"
70 }
71
72 catch { execsql COMMIT }
73}
74
75
76
77finish_test