drh | cf1be45 | 2007-05-12 12:08:51 +0000 | [diff] [blame] | 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 | # |
drh | eee4c8c | 2008-02-18 22:24:57 +0000 | [diff] [blame] | 13 | # $Id: mallocA.test,v 1.8 2008/02/18 22:24:58 drh Exp $ |
drh | cf1be45 | 2007-05-12 12:08:51 +0000 | [diff] [blame] | 14 | |
| 15 | set testdir [file dirname $argv0] |
| 16 | source $testdir/tester.tcl |
drh | eee4c8c | 2008-02-18 22:24:57 +0000 | [diff] [blame] | 17 | source $testdir/malloc_common.tcl |
dan | af2583c | 2013-08-15 18:43:21 +0000 | [diff] [blame] | 18 | set testprefix mallocA |
drh | cf1be45 | 2007-05-12 12:08:51 +0000 | [diff] [blame] | 19 | |
| 20 | # Only run these tests if memory debugging is turned on. |
| 21 | # |
drh | eee4c8c | 2008-02-18 22:24:57 +0000 | [diff] [blame] | 22 | if {!$MEMDEBUG} { |
drh | 5a3032b | 2007-09-03 16:12:09 +0000 | [diff] [blame] | 23 | puts "Skipping mallocA tests: not compiled with -DSQLITE_MEMDEBUG..." |
drh | cf1be45 | 2007-05-12 12:08:51 +0000 | [diff] [blame] | 24 | finish_test |
| 25 | return |
| 26 | } |
| 27 | |
drh | cf1be45 | 2007-05-12 12:08:51 +0000 | [diff] [blame] | 28 | |
| 29 | # Construct a test database |
| 30 | # |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 31 | forcedelete test.db.bu |
drh | cf1be45 | 2007-05-12 12:08:51 +0000 | [diff] [blame] | 32 | db eval { |
drh | 84f3112 | 2007-05-12 15:00:14 +0000 | [diff] [blame] | 33 | CREATE TABLE t1(a COLLATE NOCASE,b,c); |
drh | cf1be45 | 2007-05-12 12:08:51 +0000 | [diff] [blame] | 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 | } |
| 41 | db close |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 42 | copy_file test.db test.db.bu |
drh | cf1be45 | 2007-05-12 12:08:51 +0000 | [diff] [blame] | 43 | |
danielk1977 | a1644fd | 2007-08-29 12:31:25 +0000 | [diff] [blame] | 44 | do_malloc_test mallocA-1 -testdb test.db.bu -sqlbody { |
drh | cf1be45 | 2007-05-12 12:08:51 +0000 | [diff] [blame] | 45 | ANALYZE |
| 46 | } |
danielk1977 | b8b4bfa | 2007-11-15 13:10:22 +0000 | [diff] [blame] | 47 | do_malloc_test mallocA-1.1 -testdb test.db.bu -sqlbody { |
| 48 | ANALYZE t1 |
| 49 | } |
| 50 | do_malloc_test mallocA-1.2 -testdb test.db.bu -sqlbody { |
| 51 | ANALYZE main |
| 52 | } |
| 53 | do_malloc_test mallocA-1.3 -testdb test.db.bu -sqlbody { |
| 54 | ANALYZE main.t1 |
| 55 | } |
dan | af2583c | 2013-08-15 18:43:21 +0000 | [diff] [blame] | 56 | |
danielk1977 | 4152e67 | 2007-09-12 17:01:45 +0000 | [diff] [blame] | 57 | ifcapable 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 | } |
drh | 84f3112 | 2007-05-12 15:00:14 +0000 | [diff] [blame] | 70 | } |
drh | cf1be45 | 2007-05-12 12:08:51 +0000 | [diff] [blame] | 71 | |
dan | af2583c | 2013-08-15 18:43:21 +0000 | [diff] [blame] | 72 | reset_db |
| 73 | sqlite3_db_config_lookaside db 0 0 0 |
| 74 | do_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 | |
| 90 | do_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 | } |
| 95 | do_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 | } |
dan | af0d8bc | 2013-09-04 16:38:42 +0000 | [diff] [blame] | 100 | ifcapable 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 | } |
dan | af2583c | 2013-08-15 18:43:21 +0000 | [diff] [blame] | 118 | |
drh | cf1be45 | 2007-05-12 12:08:51 +0000 | [diff] [blame] | 119 | # Ensure that no file descriptors were leaked. |
| 120 | do_test malloc-99.X { |
| 121 | catch {db close} |
| 122 | set sqlite_open_file_count |
| 123 | } {0} |
| 124 | |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 125 | forcedelete test.db.bu |
drh | cf1be45 | 2007-05-12 12:08:51 +0000 | [diff] [blame] | 126 | finish_test |