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 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # Specifically, it tests the effects of fault injection on the sorter
14 # module (code in vdbesort.c).
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
19 set testprefix sortfault
22 sqlite3_config_pmasz 10
28 PRAGMA cache_size = 5;
31 foreach {tn mmap_limit nWorker tmpstore threadsmode fakeheap lookaside} {
32 1 0 0 file multithread false false
33 2 100000 0 file multithread false false
34 3 100000 1 file multithread false false
35 4 2000000 0 file singlethread false true
37 if {$sqlite_options(threadsafe)} { set threadsmode singlethread }
39 db eval "PRAGMA threads=$nWorker"
40 sqlite3_config $threadsmode
42 sqlite3_config_lookaside 100 500
44 sqlite3_config_lookaside 0 0
47 sorter_test_fakeheap $fakeheap
49 set str [string repeat a 1000]
52 do_faultsim_test 1.$tn -prep {
54 sqlite3_test_control SQLITE_TESTCTRL_SORTER_MMAP db $::mmap_limit
55 execsql { PRAGMA cache_size = 5 }
61 SELECT x+1, $::str FROM r
64 SELECT count(x), length(y) FROM r GROUP BY (x%5)
67 faultsim_test_result {0 {40 1000 40 1000 40 1000 40 1000 40 1000}}
70 do_faultsim_test 2.$tn -faults oom* -prep {
72 sqlite3_test_control SQLITE_TESTCTRL_SORTER_MMAP db $::mmap_limit
73 add_test_utf16bin_collate db
74 execsql { PRAGMA cache_size = 5 }
80 SELECT x-1, $::str FROM r
83 SELECT count(x), length(y) FROM r GROUP BY y COLLATE utf16bin, (x%5)
86 faultsim_test_result {0 {20 1000 20 1000 20 1000 20 1000 20 1000}}
89 if {$mmap_limit > 1000000} {
90 set str2 [string repeat $str 10]
92 sqlite3_memdebug_vfs_oom_test 0
94 sqlite3_test_control SQLITE_TESTCTRL_SORTER_MMAP db $::mmap_limit
95 execsql { PRAGMA cache_size = 5 }
97 do_faultsim_test 3.$tn -faults oom-trans* -body {
102 SELECT x-1, $::str2 FROM r
105 SELECT count(x), length(y) FROM r GROUP BY y, (x%5)
108 faultsim_test_result {0 {60 10000 60 10000 60 10000 60 10000 60 10000}}
111 sqlite3_memdebug_vfs_oom_test 1
117 set t(0) singlethread
120 sqlite3_config $t($sqlite_options(threadsafe))
121 sqlite3_config_lookaside 100 500
124 #-------------------------------------------------------------------------
127 do_execsql_test 4.0 {
128 CREATE TABLE t1(a, b, c);
129 INSERT INTO t1 VALUES(1, 2, 3);
132 for {set i 0} {$i < 256} {incr i} {
134 INSERT INTO t1 SELECT
135 ((a<<3) + b) & 2147483647,
136 ((b<<3) + c) & 2147483647,
137 ((c<<3) + a) & 2147483647
138 FROM t1 ORDER BY rowid DESC LIMIT 1;
143 faultsim_save_and_close
145 do_faultsim_test 4.2 -faults oom* -prep {
146 faultsim_restore_and_reopen
148 execsql { CREATE UNIQUE INDEX i1 ON t1(a,b,c) }
150 faultsim_test_result {0 {}}
153 #-------------------------------------------------------------------------
156 set a [string repeat a 500]
157 set b [string repeat b 500]
158 set c [string repeat c 500]
159 do_execsql_test 5.0 {
160 CREATE TABLE t1(a, b, c);
161 INSERT INTO t1 VALUES($a, $b, $c);
162 INSERT INTO t1 VALUES($c, $b, $a);
165 do_faultsim_test 5.1 -faults oom* -body {
166 execsql { SELECT * FROM t1 ORDER BY a }
168 faultsim_test_result [list 0 [list $::a $::b $::c $::c $::b $::a]]