1# 2007 April 30 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# This file contains additional out-of-memory checks (see malloc.tcl). 12# 13# $Id: mallocA.test,v 1.8 2008/02/18 22:24:58 drh Exp $ 14 15set testdir [file dirname $argv0] 16source $testdir/tester.tcl 17source $testdir/malloc_common.tcl 18set testprefix mallocA 19 20# Only run these tests if memory debugging is turned on. 21# 22if {!$MEMDEBUG} { 23 puts "Skipping mallocA tests: not compiled with -DSQLITE_MEMDEBUG..." 24 finish_test 25 return 26} 27 28 29# Construct a test database 30# 31forcedelete test.db.bu 32db eval { 33 CREATE TABLE t1(a COLLATE NOCASE,b,c); 34 INSERT INTO t1 VALUES(1,2,3); 35 INSERT INTO t1 VALUES(1,2,4); 36 INSERT INTO t1 VALUES(2,3,4); 37 CREATE INDEX t1i1 ON t1(a); 38 CREATE INDEX t1i2 ON t1(b,c); 39 CREATE TABLE t2(x,y,z); 40} 41db close 42copy_file test.db test.db.bu 43 44do_malloc_test mallocA-1 -testdb test.db.bu -sqlbody { 45 ANALYZE 46} 47do_malloc_test mallocA-1.1 -testdb test.db.bu -sqlbody { 48 ANALYZE t1 49} 50do_malloc_test mallocA-1.2 -testdb test.db.bu -sqlbody { 51 ANALYZE main 52} 53do_malloc_test mallocA-1.3 -testdb test.db.bu -sqlbody { 54 ANALYZE main.t1 55} 56 57ifcapable reindex { 58 do_malloc_test mallocA-2 -testdb test.db.bu -sqlbody { 59 REINDEX; 60 } 61 do_malloc_test mallocA-3 -testdb test.db.bu -sqlbody { 62 REINDEX t1; 63 } 64 do_malloc_test mallocA-4 -testdb test.db.bu -sqlbody { 65 REINDEX main.t1; 66 } 67 do_malloc_test mallocA-5 -testdb test.db.bu -sqlbody { 68 REINDEX nocase; 69 } 70} 71 72reset_db 73sqlite3_db_config_lookaside db 0 0 0 74do_execsql_test 6-prep { 75 CREATE TABLE t1(a, b); 76 CREATE INDEX i1 ON t1(a, b); 77 INSERT INTO t1 VALUES('abc', 'w'); -- rowid=1 78 INSERT INTO t1 VALUES('abc', 'x'); -- rowid=2 79 INSERT INTO t1 VALUES('abc', 'y'); -- rowid=3 80 INSERT INTO t1 VALUES('abc', 'z'); -- rowid=4 81 82 INSERT INTO t1 VALUES('def', 'w'); -- rowid=5 83 INSERT INTO t1 VALUES('def', 'x'); -- rowid=6 84 INSERT INTO t1 VALUES('def', 'y'); -- rowid=7 85 INSERT INTO t1 VALUES('def', 'z'); -- rowid=8 86 87 ANALYZE; 88} 89 90do_faultsim_test 6.1 -faults oom* -body { 91 execsql { SELECT rowid FROM t1 WHERE a='abc' AND b='x' } 92} -test { 93 faultsim_test_result [list 0 2] 94} 95do_faultsim_test 6.2 -faults oom* -body { 96 execsql { SELECT rowid FROM t1 WHERE a='abc' AND b<'y' } 97} -test { 98 faultsim_test_result [list 0 {1 2}] 99} 100ifcapable stat3 { 101 do_test 6.3-prep { 102 execsql { 103 PRAGMA writable_schema = 1; 104 CREATE TABLE sqlite_stat4 AS 105 SELECT tbl, idx, neq, nlt, ndlt, sqlite_record(sample) AS sample 106 FROM sqlite_stat3; 107 } 108 } {} 109 do_faultsim_test 6.3 -faults oom* -body { 110 execsql { 111 ANALYZE sqlite_master; 112 SELECT rowid FROM t1 WHERE a='abc' AND b<'y'; 113 } 114 } -test { 115 faultsim_test_result [list 0 {1 2}] 116 } 117} 118 119# Ensure that no file descriptors were leaked. 120do_test malloc-99.X { 121 catch {db close} 122 set sqlite_open_file_count 123} {0} 124 125forcedelete test.db.bu 126finish_test 127