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
26 set ::TMPDBERROR [list 1 \
27 {unable to open a temporary database file for storing temporary tables}
32 # rtree3-1: Test OOM in simple CREATE TABLE, INSERT, DELETE and SELECT
33 # commands on an almost empty table.
35 # rtree3-2: Test OOM in a DROP TABLE command.
37 # rtree3-3a: Test OOM during a transaction to insert 100 pseudo-random rows.
39 # rtree3-3b: Test OOM during a transaction deleting all entries in the
40 # database constructed in [rtree3-3a] in pseudo-random order.
42 # rtree3-4a: OOM during "SELECT count(*) FROM ..." on a big table.
44 # rtree3-4b: OOM while deleting rows from a big table.
46 # rtree3-5: Test OOM while inserting rows into a big table.
48 # rtree3-6: Test OOM while deleting all rows of a table, one at a time.
50 # rtree3-7: OOM during an ALTER TABLE RENAME TABLE command.
52 # rtree3-8: Test OOM while registering the r-tree module with sqlite.
54 # rtree3-11: OOM following a constraint failure
56 do_faultsim_test rtree3-1 -faults oom* -prep {
57 faultsim_delete_and_reopen
61 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
62 INSERT INTO rt VALUES(NULL, 3, 5, 7, 9);
63 INSERT INTO rt VALUES(NULL, 13, 15, 17, 19);
64 DELETE FROM rt WHERE ii = 1;
66 SELECT ii FROM rt WHERE ii = 2;
71 do_test rtree3-2.prep {
72 faultsim_delete_and_reopen
74 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
75 INSERT INTO rt VALUES(NULL, 3, 5, 7, 9);
77 faultsim_save_and_close
79 do_faultsim_test rtree3-2 -faults oom* -prep {
80 faultsim_restore_and_reopen
82 execsql { DROP TABLE rt }
85 do_malloc_test rtree3-3.prep {
86 faultsim_delete_and_reopen
88 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2, +a1, +a2);
89 INSERT INTO rt VALUES(NULL, 3, 5, 7, 9);
91 faultsim_save_and_close
94 do_faultsim_test rtree3-3a -faults oom* -prep {
95 faultsim_restore_and_reopen
98 for {set ii 0} {$ii < 100} {incr ii} {
100 db eval {INSERT INTO rt VALUES(NULL, $f*10.0, $f*10.0, $f*15.0, $f*15.0)}
104 faultsim_save_and_close
106 do_faultsim_test rtree3-3b -faults oom* -prep {
107 faultsim_restore_and_reopen
110 for {set ii 0} {$ii < 100} {incr ii} {
112 db eval { DELETE FROM rt WHERE x1<($f*10.0) AND x1>($f*10.5) }
117 do_test rtree3-4.prep {
118 faultsim_delete_and_reopen
121 PRAGMA page_size = 512;
122 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
124 for {set i 0} {$i < 1500} {incr i} {
125 execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) }
128 faultsim_save_and_close
131 do_faultsim_test rtree3-4a -faults oom-* -prep {
132 faultsim_restore_and_reopen
134 db eval { SELECT count(*) FROM rt }
136 faultsim_test_result {0 1500}
139 do_faultsim_test rtree3-4b -faults oom-transient -prep {
140 faultsim_restore_and_reopen
142 db eval { DELETE FROM rt WHERE ii BETWEEN 1 AND 100 }
144 faultsim_test_result {0 {}}
147 do_test rtree3-5.prep {
148 faultsim_delete_and_reopen
151 PRAGMA page_size = 512;
152 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
154 for {set i 0} {$i < 100} {incr i} {
155 execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) }
158 faultsim_save_and_close
160 do_faultsim_test rtree3-5 -faults oom-* -prep {
161 faultsim_restore_and_reopen
163 for {set i 100} {$i < 110} {incr i} {
164 execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) }
167 faultsim_test_result {0 {}}
170 do_test rtree3-6.prep {
171 faultsim_delete_and_reopen
174 PRAGMA page_size = 512;
175 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
177 for {set i 0} {$i < 50} {incr i} {
178 execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) }
181 faultsim_save_and_close
183 do_faultsim_test rtree3-6 -faults oom-* -prep {
184 faultsim_restore_and_reopen
187 for {set i 0} {$i < 50} {incr i} {
188 execsql { DELETE FROM rt WHERE ii=$i }
192 faultsim_test_result {0 {}}
195 do_test rtree3-7.prep {
196 faultsim_delete_and_reopen
197 execsql { CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2) }
198 faultsim_save_and_close
200 do_faultsim_test rtree3-7 -faults oom-* -prep {
201 faultsim_restore_and_reopen
203 execsql { ALTER TABLE rt RENAME TO rt2 }
205 faultsim_test_result {0 {}} $::TMPDBERROR
208 do_faultsim_test rtree3-8 -faults oom-* -prep {
214 do_faultsim_test rtree3-9 -faults oom-* -prep {
217 set rc [register_cube_geom db]
218 if {$rc != "SQLITE_OK"} { error $rc }
220 faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
223 do_test rtree3-10.prep {
224 faultsim_delete_and_reopen
226 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2, z1, z2);
227 INSERT INTO rt VALUES(1, 10, 10, 10, 11, 11, 11);
228 INSERT INTO rt VALUES(2, 5, 6, 6, 7, 7, 8);
230 faultsim_save_and_close
232 do_faultsim_test rtree3-10 -faults oom-* -prep {
233 faultsim_restore_and_reopen
234 register_cube_geom db
235 execsql { SELECT * FROM rt }
237 execsql { SELECT ii FROM rt WHERE ii MATCH cube(4.5, 5.5, 6.5, 1, 1, 1) }
239 faultsim_test_result {0 2}
243 do_test rtree3-11.prep {
244 faultsim_delete_and_reopen
246 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2);
247 INSERT INTO rt VALUES(1, 2, 3, 4, 5);
249 faultsim_save_and_close
251 do_faultsim_test rtree3-10.1 -faults oom-* -prep {
252 faultsim_restore_and_reopen
253 execsql { SELECT * FROM rt }
255 execsql { INSERT INTO rt VALUES(1, 2, 3, 4, 5) }
257 faultsim_test_result {1 {UNIQUE constraint failed: rt.ii}} \
258 {1 {constraint failed}}
260 do_faultsim_test rtree3-10.2 -faults oom-* -prep {
261 faultsim_restore_and_reopen
262 execsql { SELECT * FROM rt }
264 execsql { INSERT INTO rt VALUES(2, 2, 3, 5, 4) }
266 faultsim_test_result {1 {rtree constraint failed: rt.(y1<=y2)}} \
267 {1 {constraint failed}}