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 fts5fault3 18 19# If SQLITE_ENABLE_FTS3 is defined, omit this file. 20ifcapable !fts5 { 21 finish_test 22 return 23} 24 25#------------------------------------------------------------------------- 26# An OOM while resuming a partially completed segment merge. 27# 28db func rnddoc fts5_rnddoc 29do_test 1.0 { 30 expr srand(0) 31 execsql { 32 CREATE VIRTUAL TABLE xx USING fts5(x); 33 INSERT INTO xx(xx, rank) VALUES('pgsz', 32); 34 INSERT INTO xx(xx, rank) VALUES('automerge', 16); 35 } 36 for {set i 0} {$i < 10} {incr i} { 37 execsql { 38 BEGIN; 39 INSERT INTO xx(x) VALUES(rnddoc(20)); 40 INSERT INTO xx(x) VALUES(rnddoc(20)); 41 INSERT INTO xx(x) VALUES(rnddoc(20)); 42 COMMIT 43 } 44 } 45 46 execsql { 47 INSERT INTO xx(xx, rank) VALUES('automerge', 2); 48 INSERT INTO xx(xx, rank) VALUES('merge', 50); 49 } 50} {} 51faultsim_save_and_close 52 53do_faultsim_test 1 -faults oom-* -prep { 54 faultsim_restore_and_reopen 55} -body { 56 execsql { INSERT INTO xx(xx, rank) VALUES('merge', 1) } 57} -test { 58 faultsim_test_result [list 0 {}] 59} 60 61#------------------------------------------------------------------------- 62# An OOM while flushing an unusually large term to disk. 63# 64reset_db 65do_execsql_test 2.0 { 66 CREATE VIRTUAL TABLE xx USING fts5(x); 67 INSERT INTO xx(xx, rank) VALUES('pgsz', 32); 68} 69faultsim_save_and_close 70 71set doc "a long term abcdefghijklmnopqrstuvwxyz " 72append doc "and then abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz " 73append doc [string repeat "abcdefghijklmnopqrstuvwxyz" 10] 74 75do_faultsim_test 2 -faults oom-* -prep { 76 faultsim_restore_and_reopen 77} -body { 78 execsql { INSERT INTO xx(x) VALUES ($::doc) } 79} -test { 80 faultsim_test_result [list 0 {}] 81} 82 83#------------------------------------------------------------------------- 84# An OOM while flushing an unusually large term to disk. 85# 86reset_db 87do_execsql_test 3.0 { 88 CREATE VIRTUAL TABLE xx USING fts5(x); 89} 90faultsim_save_and_close 91 92set doc [fts5_rnddoc 1000] 93do_faultsim_test 3.1 -faults oom-* -prep { 94 faultsim_restore_and_reopen 95} -body { 96 execsql { INSERT INTO xx(x) VALUES ($::doc) } 97} -test { 98 faultsim_test_result [list 0 {}] 99} 100 101set doc [string repeat "abc " 100] 102do_faultsim_test 3.2 -faults oom-* -prep { 103 faultsim_restore_and_reopen 104} -body { 105 execsql { INSERT INTO xx(x) VALUES ($::doc) } 106} -test { 107 faultsim_test_result [list 0 {}] 108} 109 110 111 112finish_test 113