blob: 61e88a61e721be812905257fc809ec5cbd19d862 [file] [log] [blame]
drhcf1be452007-05-12 12:08:51 +00001# 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#
drheee4c8c2008-02-18 22:24:57 +000013# $Id: mallocA.test,v 1.8 2008/02/18 22:24:58 drh Exp $
drhcf1be452007-05-12 12:08:51 +000014
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
drheee4c8c2008-02-18 22:24:57 +000017source $testdir/malloc_common.tcl
danaf2583c2013-08-15 18:43:21 +000018set testprefix mallocA
drhcf1be452007-05-12 12:08:51 +000019
20# Only run these tests if memory debugging is turned on.
21#
drheee4c8c2008-02-18 22:24:57 +000022if {!$MEMDEBUG} {
drh5a3032b2007-09-03 16:12:09 +000023 puts "Skipping mallocA tests: not compiled with -DSQLITE_MEMDEBUG..."
drhcf1be452007-05-12 12:08:51 +000024 finish_test
25 return
26}
27
drhcf1be452007-05-12 12:08:51 +000028
29# Construct a test database
30#
mistachkinfda06be2011-08-02 00:57:34 +000031forcedelete test.db.bu
drhcf1be452007-05-12 12:08:51 +000032db eval {
drh84f31122007-05-12 15:00:14 +000033 CREATE TABLE t1(a COLLATE NOCASE,b,c);
drhcf1be452007-05-12 12:08:51 +000034 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
mistachkinfda06be2011-08-02 00:57:34 +000042copy_file test.db test.db.bu
drhcf1be452007-05-12 12:08:51 +000043
danielk1977a1644fd2007-08-29 12:31:25 +000044do_malloc_test mallocA-1 -testdb test.db.bu -sqlbody {
drhcf1be452007-05-12 12:08:51 +000045 ANALYZE
46}
danielk1977b8b4bfa2007-11-15 13:10:22 +000047do_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}
danaf2583c2013-08-15 18:43:21 +000056
danielk19774152e672007-09-12 17:01:45 +000057ifcapable 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 }
drh84f31122007-05-12 15:00:14 +000070}
drhcf1be452007-05-12 12:08:51 +000071
danaf2583c2013-08-15 18:43:21 +000072reset_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}
danaf0d8bc2013-09-04 16:38:42 +0000100ifcapable 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}
danaf2583c2013-08-15 18:43:21 +0000118
drhcf1be452007-05-12 12:08:51 +0000119# 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
mistachkinfda06be2011-08-02 00:57:34 +0000125forcedelete test.db.bu
drhcf1be452007-05-12 12:08:51 +0000126finish_test