| 1 |
# 2015 September 3 |
| 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 |
|
| 15 |
source [file join [file dirname [info script]] fts5_common.tcl] |
| 16 |
source $testdir/malloc_common.tcl |
| 17 |
set testprefix fts5fault7 |
| 18 |
|
| 19 |
# If SQLITE_ENABLE_FTS3 is defined, omit this file. |
| 20 |
ifcapable !fts5 { |
| 21 |
finish_test |
| 22 |
return |
| 23 |
} |
| 24 |
|
| 25 |
if 1 { |
| 26 |
|
| 27 |
#------------------------------------------------------------------------- |
| 28 |
# Test fault-injection on a query that uses xColumnSize() on columnsize=0 |
| 29 |
# table. |
| 30 |
# |
| 31 |
do_execsql_test 1.0 { |
| 32 |
CREATE VIRTUAL TABLE t1 USING fts5(x, columnsize=0); |
| 33 |
INSERT INTO t1 VALUES('a b c d e f g'); |
| 34 |
INSERT INTO t1 VALUES('a b c d'); |
| 35 |
INSERT INTO t1 VALUES('a b c d e f g h i j'); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
fts5_aux_test_functions db |
| 40 |
do_faultsim_test 1 -faults oom* -body { |
| 41 |
execsql { SELECT fts5_test_columnsize(t1) FROM t1 WHERE t1 MATCH 'b' } |
| 42 |
} -test { |
| 43 |
faultsim_test_result {0 {7 4 10}} {1 SQLITE_NOMEM} |
| 44 |
} |
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
#------------------------------------------------------------------------- |
| 49 |
# Test fault-injection when a segment is promoted. |
| 50 |
# |
| 51 |
do_execsql_test 1.0 { |
| 52 |
CREATE VIRTUAL TABLE t2 USING fts5(a); |
| 53 |
INSERT INTO t2(t2, rank) VALUES('automerge', 0); |
| 54 |
INSERT INTO t2(t2, rank) VALUES('crisismerge', 4); |
| 55 |
INSERT INTO t2(t2, rank) VALUES('pgsz', 40); |
| 56 |
|
| 57 |
INSERT INTO t2 VALUES('a b c'); |
| 58 |
INSERT INTO t2 VALUES('d e f'); |
| 59 |
INSERT INTO t2 VALUES('f e d'); |
| 60 |
INSERT INTO t2 VALUES('c b a'); |
| 61 |
|
| 62 |
INSERT INTO t2 VALUES('a b c'); |
| 63 |
INSERT INTO t2 VALUES('d e f'); |
| 64 |
INSERT INTO t2 VALUES('f e d'); |
| 65 |
INSERT INTO t2 VALUES('c b a'); |
| 66 |
} {} |
| 67 |
|
| 68 |
faultsim_save_and_close |
| 69 |
do_faultsim_test 1 -faults oom-t* -prep { |
| 70 |
faultsim_restore_and_reopen |
| 71 |
db eval { |
| 72 |
BEGIN; |
| 73 |
INSERT INTO t2 VALUES('c d c g g f'); |
| 74 |
INSERT INTO t2 VALUES('c d g b f d'); |
| 75 |
INSERT INTO t2 VALUES('c c f d e d'); |
| 76 |
INSERT INTO t2 VALUES('e a f c e f'); |
| 77 |
INSERT INTO t2 VALUES('c g f b b d'); |
| 78 |
INSERT INTO t2 VALUES('d a g a b b'); |
| 79 |
INSERT INTO t2 VALUES('e f a b c e'); |
| 80 |
INSERT INTO t2 VALUES('e c a g c d'); |
| 81 |
INSERT INTO t2 VALUES('g b d d e b'); |
| 82 |
INSERT INTO t2 VALUES('e a d a e d'); |
| 83 |
} |
| 84 |
} -body { |
| 85 |
db eval COMMIT |
| 86 |
} -test { |
| 87 |
faultsim_test_result {0 {}} |
| 88 |
} |
| 89 |
|
| 90 |
#------------------------------------------------------------------------- |
| 91 |
# Test fault-injection when a segment is promoted. |
| 92 |
# |
| 93 |
reset_db |
| 94 |
do_execsql_test 2.0 { |
| 95 |
CREATE VIRTUAL TABLE xy USING fts5(x); |
| 96 |
INSERT INTO xy(rowid, x) VALUES(1, '1 2 3'); |
| 97 |
INSERT INTO xy(rowid, x) VALUES(2, '2 3 4'); |
| 98 |
INSERT INTO xy(rowid, x) VALUES(3, '3 4 5'); |
| 99 |
} |
| 100 |
faultsim_save_and_close |
| 101 |
|
| 102 |
do_faultsim_test 2.1 -faults oom-* -prep { |
| 103 |
faultsim_restore_and_reopen |
| 104 |
} -body { |
| 105 |
db eval { UPDATE OR REPLACE xy SET rowid=3 WHERE rowid = 2 } |
| 106 |
} -test { |
| 107 |
faultsim_test_result {0 {}} |
| 108 |
} |
| 109 |
|
| 110 |
# Test fault-injection when an empty expression is parsed. |
| 111 |
# |
| 112 |
do_faultsim_test 2.2 -faults oom-* -body { |
| 113 |
db eval { SELECT * FROM xy('""') } |
| 114 |
} -test { |
| 115 |
faultsim_test_result {0 {}} |
| 116 |
} |
| 117 |
|
| 118 |
finish_test |