AryaWu/sqlite
0
1# 2014 March 25.2#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# This file implements regression tests for SQLite library. 12#13# Specifically, it tests the effects of fault injection on the sorter14# module (code in vdbesort.c).15#16 17set testdir [file dirname $argv0]18source $testdir/tester.tcl19set testprefix sortfault20db close21sqlite3_shutdown22sqlite3_config_pmasz 1023sqlite3_initialize24sqlite3 db test.db25 26 27do_execsql_test 1.0 {28 PRAGMA cache_size = 5;29}30 31foreach {tn mmap_limit nWorker tmpstore threadsmode fakeheap lookaside} {32 1 0 0 file multithread false false33 2 100000 0 file multithread false false34 3 100000 1 file multithread false false35 4 2000000 0 file singlethread false true36} {37 if {$sqlite_options(threadsafe)} { set threadsmode singlethread }38 39 db eval "PRAGMA threads=$nWorker"40 sqlite3_config $threadsmode41 if { $lookaside } {42 sqlite3_config_lookaside 100 50043 } else {44 sqlite3_config_lookaside 0 045 }46 sqlite3_initialize47 sorter_test_fakeheap $fakeheap48 49 set str [string repeat a 1000]50 puts $threadsmode51 52 do_faultsim_test 1.$tn -prep {53 sqlite3 db test.db54 sqlite3_test_control SQLITE_TESTCTRL_SORTER_MMAP db $::mmap_limit55 execsql { PRAGMA cache_size = 5 }56 } -body {57 execsql { 58 WITH r(x,y) AS (59 SELECT 1, $::str60 UNION ALL61 SELECT x+1, $::str FROM r62 LIMIT 20063 )64 SELECT count(x), length(y) FROM r GROUP BY (x%5)65 }66 } -test {67 faultsim_test_result {0 {40 1000 40 1000 40 1000 40 1000 40 1000}}68 }69 70 do_faultsim_test 2.$tn -faults oom* -prep {71 sqlite3 db test.db72 sqlite3_test_control SQLITE_TESTCTRL_SORTER_MMAP db $::mmap_limit73 add_test_utf16bin_collate db74 execsql { PRAGMA cache_size = 5 }75 } -body {76 execsql { 77 WITH r(x,y) AS (78 SELECT 100, $::str79 UNION ALL80 SELECT x-1, $::str FROM r81 LIMIT 10082 )83 SELECT count(x), length(y) FROM r GROUP BY y COLLATE utf16bin, (x%5)84 }85 } -test {86 faultsim_test_result {0 {20 1000 20 1000 20 1000 20 1000 20 1000}}87 }88 89 if {$mmap_limit > 1000000} {90 set str2 [string repeat $str 10]91 92 sqlite3_memdebug_vfs_oom_test 093 sqlite3 db test.db94 sqlite3_test_control SQLITE_TESTCTRL_SORTER_MMAP db $::mmap_limit95 execsql { PRAGMA cache_size = 5 }96 97 do_faultsim_test 3.$tn -faults oom-trans* -body {98 execsql { 99 WITH r(x,y) AS (100 SELECT 300, $::str2101 UNION ALL102 SELECT x-1, $::str2 FROM r103 LIMIT 300104 )105 SELECT count(x), length(y) FROM r GROUP BY y, (x%5)106 }107 } -test {108 faultsim_test_result {0 {60 10000 60 10000 60 10000 60 10000 60 10000}}109 }110 111 sqlite3_memdebug_vfs_oom_test 1112 }113}114 115catch { db close }116sqlite3_shutdown117set t(0) singlethread118set t(1) multithread119set t(2) serialized120sqlite3_config $t($sqlite_options(threadsafe))121sqlite3_config_lookaside 100 500122sqlite3_initialize123 124#-------------------------------------------------------------------------125#126reset_db127do_execsql_test 4.0 { 128 CREATE TABLE t1(a, b, c); 129 INSERT INTO t1 VALUES(1, 2, 3);130}131do_test 4.1 { 132 for {set i 0} {$i < 256} {incr i} {133 execsql { 134 INSERT INTO t1 SELECT135 ((a<<3) + b) & 2147483647,136 ((b<<3) + c) & 2147483647,137 ((c<<3) + a) & 2147483647138 FROM t1 ORDER BY rowid DESC LIMIT 1;139 }140 }141} {}142 143faultsim_save_and_close144 145do_faultsim_test 4.2 -faults oom* -prep {146 faultsim_restore_and_reopen147} -body {148 execsql { CREATE UNIQUE INDEX i1 ON t1(a,b,c) }149} -test {150 faultsim_test_result {0 {}}151}152 153#-------------------------------------------------------------------------154#155reset_db156set a [string repeat a 500]157set b [string repeat b 500]158set c [string repeat c 500]159do_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); 163}164 165do_faultsim_test 5.1 -faults oom* -body {166 execsql { SELECT * FROM t1 ORDER BY a }167} -test {168 faultsim_test_result [list 0 [list $::a $::b $::c $::c $::b $::a]]169}170 171finish_test172 