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. The
12 # focus of this file is testing OOM error handling within the built-in
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
19 set testprefix instrfault
21 # Use big NEEDLE and HAYSTACK strings. Strings so large they cannot
22 # use lookaside buffers.
24 set ::NEEDLE [string repeat "abcdefghijklmnopqrstuvwxyz" 10]
25 set ::HAYSTACK "[string repeat 123 10]$NEEDLE[string repeat 456 10]"
32 sqlite3_db_config_lookaside db 0 0 0
34 execsql "PRAGMA encoding = $enc"
35 do_execsql_test 1.$enc.1 {
36 CREATE TABLE t1(n, h);
37 INSERT INTO t1 VALUES($::NEEDLE, $::HAYSTACK);
40 do_faultsim_test 1.$enc.1 -faults oom-t* -prep {
41 execsql { SELECT instr(h, n) FROM t1 }
43 execsql { SELECT instr(h, n) FROM t1 }
45 faultsim_test_result {0 31}
48 do_faultsim_test 1.$enc.2 -faults oom-t* -prep {
49 execsql { SELECT instr($::HAYSTACK, $::NEEDLE) FROM t1 }
51 execsql { SELECT instr($::HAYSTACK, $::NEEDLE) FROM t1 }
53 faultsim_test_result {0 31}
56 do_faultsim_test 1.$enc.3 -faults oom-t* -prep {
57 set ::stmt [sqlite3_prepare_v2 db "SELECT instr(?, ?)" -1 dummy]
58 sqlite3_bind_text $::stmt 1 $::HAYSTACK [string length $::HAYSTACK]
59 sqlite3_bind_text $::stmt 2 $::NEEDLE [string length $::NEEDLE]
61 set rc [sqlite3_step $::stmt]
62 if {$rc=="SQLITE_NOMEM"} { error "out of memory" }
63 sqlite3_column_int $::stmt 0
65 faultsim_test_result {0 31}
66 sqlite3_finalize $::stmt
69 do_faultsim_test 1.$enc.4 -faults oom-t* -prep {
70 set ::stmt [sqlite3_prepare_v2 db "SELECT instr(?, ?)" -1 dummy]
71 sqlite3_bind_blob $::stmt 1 $::HAYSTACK [string length $::HAYSTACK]
72 sqlite3_bind_text $::stmt 2 $::NEEDLE [string length $::NEEDLE]
74 set rc [sqlite3_step $::stmt]
75 if {$rc=="SQLITE_NOMEM"} { error "out of memory" }
76 sqlite3_column_int $::stmt 0
78 faultsim_test_result {0 31}
79 sqlite3_finalize $::stmt
82 do_execsql_test 1.$enc.5.0 {
83 CREATE TABLE h1(a, b);
84 INSERT INTO h1 VALUES('abcdefg%200hijkl', randomblob(200));
85 INSERT INTO h1 SELECT b, a FROM h1;
87 do_faultsim_test 1.$enc.5 -faults oom-t* -body {
88 execsql { SELECT rowid FROM h1 WHERE instr(a,b) }