1# 2014 June 17 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# This file is focused on OOM errors. 13# 14 15source [file join [file dirname [info script]] fts5_common.tcl] 16source $testdir/malloc_common.tcl 17set testprefix fts5fault2 18 19# If SQLITE_ENABLE_FTS5 is not defined, omit this file. 20ifcapable !fts5 { 21 finish_test 22 return 23} 24 25set doc [string trim [string repeat "x y z " 200]] 26do_execsql_test 1.0 { 27 CREATE TABLE t1(a INTEGER PRIMARY KEY, x); 28 CREATE VIRTUAL TABLE x1 USING fts5(x, content='t1', content_rowid='a'); 29 INSERT INTO x1(x1, rank) VALUES('pgsz', 32); 30 WITH input(a,b) AS ( 31 SELECT 1, $doc UNION ALL 32 SELECT a+1, ($doc || CASE WHEN (a+1)%100 THEN '' ELSE ' xyz' END) 33 FROM input WHERE a < 1000 34 ) 35 INSERT INTO t1 SELECT * FROM input; 36 37 INSERT INTO x1(x1) VALUES('rebuild'); 38} 39 40do_faultsim_test 1.1 -faults oom-* -prep { 41} -body { 42 execsql { SELECT rowid FROM x1 WHERE x1 MATCH 'z AND xyz' } 43} -test { 44 faultsim_test_result {0 {100 200 300 400 500 600 700 800 900 1000}} 45} 46 47do_faultsim_test 1.2 -faults oom-* -prep { 48} -body { 49 execsql { SELECT rowid FROM x1 WHERE x1 MATCH 'z + xyz' ORDER BY 1 DESC} 50} -test { 51 faultsim_test_result {0 {1000 900 800 700 600 500 400 300 200 100}} 52} 53 54#------------------------------------------------------------------------- 55# OOM within a query that accesses the in-memory hash table. 56# 57reset_db 58do_execsql_test 2.0 { 59 CREATE VIRTUAL TABLE "a b c" USING fts5(a, b, c); 60 INSERT INTO "a b c" VALUES('one two', 'x x x', 'three four'); 61 INSERT INTO "a b c" VALUES('nine ten', 'y y y', 'two two'); 62} 63 64do_faultsim_test 2.1 -faults oom-trans* -prep { 65 execsql { 66 BEGIN; 67 INSERT INTO "a b c" VALUES('one one', 'z z z', 'nine ten'); 68 } 69} -body { 70 execsql { SELECT rowid FROM "a b c" WHERE "a b c" MATCH 'one' } 71} -test { 72 faultsim_test_result {0 {1 3}} 73 catchsql { ROLLBACK } 74} 75 76#------------------------------------------------------------------------- 77# OOM within an 'optimize' operation that writes multiple pages to disk. 78# 79reset_db 80do_execsql_test 3.0 { 81 CREATE VIRTUAL TABLE zzz USING fts5(z); 82 INSERT INTO zzz(zzz, rank) VALUES('pgsz', 32); 83 INSERT INTO zzz VALUES('a b c d'); 84 INSERT INTO zzz SELECT 'c d e f' FROM zzz; 85 INSERT INTO zzz SELECT 'e f g h' FROM zzz; 86 INSERT INTO zzz SELECT 'i j k l' FROM zzz; 87 INSERT INTO zzz SELECT 'l k m n' FROM zzz; 88 INSERT INTO zzz SELECT 'o p q r' FROM zzz; 89} 90faultsim_save_and_close 91 92do_faultsim_test 3.1 -faults oom-trans* -prep { 93 faultsim_restore_and_reopen 94 execsql { SELECT rowid FROM zzz } 95} -body { 96 execsql { INSERT INTO zzz(zzz) VALUES('optimize') } 97} -test { 98 faultsim_test_result {0 {}} 99} 100 101#------------------------------------------------------------------------- 102# OOM within an 'integrity-check' operation. 103# 104reset_db 105db func rnddoc fts5_rnddoc 106do_execsql_test 4.0 { 107 CREATE VIRTUAL TABLE zzz USING fts5(z); 108 INSERT INTO zzz(zzz, rank) VALUES('pgsz', 32); 109 WITH ii(i) AS (SELECT 1 UNION SELECT i+1 FROM ii WHERE i<10) 110 INSERT INTO zzz SELECT rnddoc(10) || ' xccc' FROM ii; 111} 112 113do_faultsim_test 4.1 -faults oom-trans* -prep { 114} -body { 115 execsql { INSERT INTO zzz(zzz) VALUES('integrity-check') } 116} -test { 117 faultsim_test_result {0 {}} 118} 119 120#------------------------------------------------------------------------- 121# OOM while parsing a tokenize=option 122# 123reset_db 124faultsim_save_and_close 125do_faultsim_test 5.0 -faults oom-* -prep { 126 faultsim_restore_and_reopen 127} -body { 128 execsql { 129 CREATE VIRTUAL TABLE uio USING fts5(a, b, 130 tokenize="porter 'ascii'", 131 content="another table", 132 content_rowid="somecolumn" 133 ); 134 } 135} -test { 136 faultsim_test_result {0 {}} 137} 138 139finish_test 140