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 #***********************************************************************
12 # The focus of this file is testing that the r-tree correctly handles
13 # out-of-memory conditions.
16 if {![info exists testdir]} {
17 set testdir [file join [file dirname [info script]] .. .. test]
19 source $testdir/tester.tcl
20 source $testdir/malloc_common.tcl
28 # rtree3-1: Test OOM in simple CREATE TABLE, INSERT, DELETE and SELECT
29 # commands on an almost empty table.
31 # rtree3-2: Test OOM in a DROP TABLE command.
33 # rtree3-3a: Test OOM during a transaction to insert 100 pseudo-random rows.
35 # rtree3-3b: Test OOM during a transaction deleting all entries in the
36 # database constructed in [rtree3-3a] in pseudo-random order.
38 # rtree3-4a: OOM during "SELECT count(*) FROM ..." on a big table.
40 # rtree3-4b: OOM while deleting rows from a big table.
42 # rtree3-5: Test OOM while inserting rows into a big table.
44 # rtree3-6: Test OOM while deleting all rows of a table, one at a time.
46 # rtree3-7: OOM during an ALTER TABLE RENAME TABLE command.
48 # rtree3-8: Test OOM while registering the r-tree module with sqlite.
51 do_faultsim_test rtree3-1 -faults oom* -prep {
52 faultsim_delete_and_reopen
56 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
57 INSERT INTO rt VALUES(NULL, 3, 5, 7, 9);
58 INSERT INTO rt VALUES(NULL, 13, 15, 17, 19);
59 DELETE FROM rt WHERE ii = 1;
61 SELECT ii FROM rt WHERE ii = 2;
66 do_test rtree3-2.prep {
67 faultsim_delete_and_reopen
69 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
70 INSERT INTO rt VALUES(NULL, 3, 5, 7, 9);
72 faultsim_save_and_close
74 do_faultsim_test rtree3-2 -faults oom* -prep {
75 faultsim_restore_and_reopen
77 execsql { DROP TABLE rt }
80 do_malloc_test rtree3-3.prep {
81 faultsim_delete_and_reopen
83 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
84 INSERT INTO rt VALUES(NULL, 3, 5, 7, 9);
86 faultsim_save_and_close
89 do_faultsim_test rtree3-3a -faults oom* -prep {
90 faultsim_restore_and_reopen
93 for {set ii 0} {$ii < 100} {incr ii} {
95 db eval {INSERT INTO rt VALUES(NULL, $f*10.0, $f*10.0, $f*15.0, $f*15.0)}
99 faultsim_save_and_close
101 do_faultsim_test rtree3-3b -faults oom* -prep {
102 faultsim_restore_and_reopen
105 for {set ii 0} {$ii < 100} {incr ii} {
107 db eval { DELETE FROM rt WHERE x1<($f*10.0) AND x1>($f*10.5) }
112 do_test rtree3-4.prep {
113 faultsim_delete_and_reopen
116 PRAGMA page_size = 512;
117 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
119 for {set i 0} {$i < 1500} {incr i} {
120 execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) }
123 faultsim_save_and_close
126 do_faultsim_test rtree3-4a -faults oom-* -prep {
127 faultsim_restore_and_reopen
129 db eval { SELECT count(*) FROM rt }
131 faultsim_test_result {0 1500}
134 do_faultsim_test rtree3-4b -faults oom-transient -prep {
135 faultsim_restore_and_reopen
137 db eval { DELETE FROM rt WHERE ii BETWEEN 1 AND 100 }
139 faultsim_test_result {0 {}}
142 do_test rtree3-5.prep {
143 faultsim_delete_and_reopen
146 PRAGMA page_size = 512;
147 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
149 for {set i 0} {$i < 100} {incr i} {
150 execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) }
153 faultsim_save_and_close
155 do_faultsim_test rtree3-5 -faults oom-* -prep {
156 faultsim_restore_and_reopen
158 for {set i 100} {$i < 110} {incr i} {
159 execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) }
162 faultsim_test_result {0 {}}
165 do_test rtree3-6.prep {
166 faultsim_delete_and_reopen
169 PRAGMA page_size = 512;
170 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
172 for {set i 0} {$i < 50} {incr i} {
173 execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) }
176 faultsim_save_and_close
178 do_faultsim_test rtree3-6 -faults oom-* -prep {
179 faultsim_restore_and_reopen
182 for {set i 0} {$i < 50} {incr i} {
183 execsql { DELETE FROM rt WHERE ii=$i }
187 faultsim_test_result {0 {}}
190 do_test rtree3-7.prep {
191 faultsim_delete_and_reopen
192 execsql { CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2) }
193 faultsim_save_and_close
195 do_faultsim_test rtree3-7 -faults oom-* -prep {
196 faultsim_restore_and_reopen
198 execsql { ALTER TABLE rt RENAME TO rt2 }
200 faultsim_test_result {0 {}}
203 do_faultsim_test rtree3-8 -faults oom-* -prep {
209 do_faultsim_test rtree3-9 -faults oom-* -prep {
212 set rc [register_cube_geom db]
213 if {$rc != "SQLITE_OK"} { error $rc }
215 faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
218 do_test rtree3-10.prep {
219 faultsim_delete_and_reopen
221 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2, z1, z2);
222 INSERT INTO rt VALUES(1, 10, 10, 10, 11, 11, 11);
223 INSERT INTO rt VALUES(2, 5, 6, 6, 7, 7, 8);
225 faultsim_save_and_close
227 do_faultsim_test rtree3-10 -faults oom-* -prep {
228 faultsim_restore_and_reopen
229 register_cube_geom db
230 execsql { SELECT * FROM rt }
232 execsql { SELECT ii FROM rt WHERE ii MATCH cube(4.5, 5.5, 6.5, 1, 1, 1) }
234 faultsim_test_result {0 2}