Skip to content

Commit

Permalink
Add an OOM fault injection test for the new code on this branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielk-1977 committed Jun 28, 2014
1 parent 8108a33 commit 1d91d5e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/vdbeaux.c
Original file line number Diff line number Diff line change
Expand Up @@ -3589,6 +3589,7 @@ int sqlite3VdbeRecordCompare(
** value. */
assert( CORRUPT_DB
|| pPKey2->default_rc==vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)
|| pKeyInfo->db->mallocFailed
);
return pPKey2->default_rc;
}
Expand Down Expand Up @@ -3754,6 +3755,7 @@ static int vdbeRecordCompareString(
|| (res<0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)<0)
|| (res>0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)>0)
|| CORRUPT_DB
|| pPKey2->pKeyInfo->db->mallocFailed
);
return res;
}
Expand Down
66 changes: 66 additions & 0 deletions test/mallocK.test
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/malloc_common.tcl
set testprefix mallocK

set sql {SELECT * FROM t1, t2 WHERE (a=1 OR a=2)}
for {set x 1} {$x<5} {incr x} {
Expand Down Expand Up @@ -68,5 +69,70 @@ ifcapable vtab {
}
}

#-------------------------------------------------------------------------
# Test that OOM errors are correctly handled by the code that uses stat4
# data to estimate the number of rows visited by a skip-scan range query.
#
add_alignment_test_collations db
do_execsql_test 6.0 {
CREATE TABLE t3(a TEXT, b TEXT COLLATE utf16_aligned, c);
INSERT INTO t3 VALUES('one', '.....', 0);
INSERT INTO t3 VALUES('one', '....x', 1);
INSERT INTO t3 VALUES('one', '...x.', 2);
INSERT INTO t3 VALUES('one', '...xx', 3);
INSERT INTO t3 VALUES('one', '..x..', 4);
INSERT INTO t3 VALUES('one', '..x.x', 5);
INSERT INTO t3 VALUES('one', '..xx.', 6);
INSERT INTO t3 VALUES('one', '..xxx', 7);
INSERT INTO t3 VALUES('one', '.x...', 8);
INSERT INTO t3 VALUES('one', '.x..x', 9);
INSERT INTO t3 VALUES('one', '.x.x.', 10);
INSERT INTO t3 VALUES('one', '.x.xx', 11);
INSERT INTO t3 VALUES('one', '.xx..', 12);
INSERT INTO t3 VALUES('one', '.xx.x', 13);
INSERT INTO t3 VALUES('one', '.xxx.', 14);
INSERT INTO t3 VALUES('one', '.xxxx', 15);

INSERT INTO t3 VALUES('two', 'x....', 16);
INSERT INTO t3 VALUES('two', 'x...x', 17);
INSERT INTO t3 VALUES('two', 'x..x.', 18);
INSERT INTO t3 VALUES('two', 'x..xx', 19);
INSERT INTO t3 VALUES('two', 'x.x..', 20);
INSERT INTO t3 VALUES('two', 'x.x.x', 21);
INSERT INTO t3 VALUES('two', 'x.xx.', 22);
INSERT INTO t3 VALUES('two', 'x.xxx', 23);
INSERT INTO t3 VALUES('two', 'xx...', 24);
INSERT INTO t3 VALUES('two', 'xx..x', 25);
INSERT INTO t3 VALUES('two', 'xx.x.', 26);
INSERT INTO t3 VALUES('two', 'xx.xx', 27);
INSERT INTO t3 VALUES('two', 'xxx..', 28);
INSERT INTO t3 VALUES('two', 'xxx.x', 29);
INSERT INTO t3 VALUES('two', 'xxxx.', 30);
INSERT INTO t3 VALUES('two', 'xxxxx', 31);

INSERT INTO t3 SELECT * FROM t3;

CREATE INDEX i3 ON t3(a, b);
ANALYZE;

SELECT 'x' > '.';
} {1}

ifcapable stat4 {
do_eqp_test 6.1 {
SELECT DISTINCT c FROM t3 WHERE b BETWEEN '.xx..' AND '.xxxx';
} {
0 0 0 {SEARCH TABLE t3 USING INDEX i3 (ANY(a) AND b>? AND b<?)}
0 0 0 {USE TEMP B-TREE FOR DISTINCT}
}
}

do_faultsim_test 6 -faults oom* -body {
db cache flush
db eval { SELECT DISTINCT c FROM t3 WHERE b BETWEEN '.xx..' AND '.xxxx' }
} -test {
faultsim_test_result {0 {12 13 14 15}}
}

finish_test

0 comments on commit 1d91d5e

Please sign in to comment.