1# 2008 Feb 19 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# The focus of this file is testing that the r-tree correctly handles 13# out-of-memory conditions. 14# 15 16if {![info exists testdir]} { 17 set testdir [file join [file dirname $argv0] .. .. test] 18} 19source $testdir/tester.tcl 20source $testdir/malloc_common.tcl 21 22ifcapable !rtree { 23 finish_test 24 return 25} 26 27# Only run these tests if memory debugging is turned on. 28# 29source $testdir/malloc_common.tcl 30if {!$MEMDEBUG} { 31 puts "Skipping malloc tests: not compiled with -DSQLITE_MEMDEBUG..." 32 finish_test 33 return 34} 35 36if 1 { 37 38do_faultsim_test rtree3-1 -faults oom* -prep { 39 faultsim_delete_and_reopen 40} -body { 41 execsql { 42 BEGIN TRANSACTION; 43 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2); 44 INSERT INTO rt VALUES(NULL, 3, 5, 7, 9); 45 INSERT INTO rt VALUES(NULL, 13, 15, 17, 19); 46 DELETE FROM rt WHERE ii = 1; 47 SELECT * FROM rt; 48 SELECT ii FROM rt WHERE ii = 2; 49 COMMIT; 50 } 51} 52 53do_test rtree3-2.prep { 54 faultsim_delete_and_reopen 55 execsql { 56 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2); 57 INSERT INTO rt VALUES(NULL, 3, 5, 7, 9); 58 } 59 faultsim_save_and_close 60} {} 61do_faultsim_test rtree3-2 -faults oom* -prep { 62 faultsim_restore_and_reopen 63} -body { 64 execsql { DROP TABLE rt } 65} 66 67do_malloc_test rtree3-3.prep { 68 faultsim_delete_and_reopen 69 execsql { 70 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2); 71 INSERT INTO rt VALUES(NULL, 3, 5, 7, 9); 72 } 73 faultsim_save_and_close 74} {} 75 76do_faultsim_test rtree3-3a -faults oom* -prep { 77 faultsim_restore_and_reopen 78} -body { 79 db eval BEGIN 80 for {set ii 0} {$ii < 100} {incr ii} { 81 set f [expr rand()] 82 db eval {INSERT INTO rt VALUES(NULL, $f*10.0, $f*10.0, $f*15.0, $f*15.0)} 83 } 84 db eval COMMIT 85} 86faultsim_save_and_close 87 88do_faultsim_test rtree3-3b -faults oom* -prep { 89 faultsim_restore_and_reopen 90} -body { 91 db eval BEGIN 92 for {set ii 0} {$ii < 100} {incr ii} { 93 set f [expr rand()] 94 db eval { DELETE FROM rt WHERE x1<($f*10.0) AND x1>($f*10.5) } 95 } 96 db eval COMMIT 97} 98 99} 100 101do_test rtree3-4.prep { 102 faultsim_delete_and_reopen 103 execsql { 104 BEGIN; 105 PRAGMA page_size = 512; 106 CREATE VIRTUAL TABLE rt USING rtree(ii, x1, x2, y1, y2); 107 } 108 for {set i 0} {$i < 1500} {incr i} { 109 execsql { INSERT INTO rt VALUES($i, $i, $i+1, $i, $i+1) } 110 } 111 execsql { COMMIT } 112 faultsim_save_and_close 113} {} 114 115do_faultsim_test rtree3-4 -faults oom-transient -prep { 116 faultsim_restore_and_reopen 117} -body { 118 db eval { SELECT count(*) FROM rt } 119} -test { 120 faultsim_test_result {0 1500} 121} 122 123finish_test 124