blob: ff91d2af2655930cf0dfc9835ece52dcc45c015b [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# Construct a test database
29#
mistachkinfda06be2011-08-02 00:57:34 +000030forcedelete test.db.bu
drhcf1be452007-05-12 12:08:51 +000031db eval {
drh84f31122007-05-12 15:00:14 +000032 CREATE TABLE t1(a COLLATE NOCASE,b,c);
drhcf1be452007-05-12 12:08:51 +000033 INSERT INTO t1 VALUES(1,2,3);
34 INSERT INTO t1 VALUES(1,2,4);
35 INSERT INTO t1 VALUES(2,3,4);
36 CREATE INDEX t1i1 ON t1(a);
37 CREATE INDEX t1i2 ON t1(b,c);
38 CREATE TABLE t2(x,y,z);
39}
40db close
mistachkinfda06be2011-08-02 00:57:34 +000041copy_file test.db test.db.bu
drhcf1be452007-05-12 12:08:51 +000042
danielk1977a1644fd2007-08-29 12:31:25 +000043do_malloc_test mallocA-1 -testdb test.db.bu -sqlbody {
drhcf1be452007-05-12 12:08:51 +000044 ANALYZE
45}
danielk1977b8b4bfa2007-11-15 13:10:22 +000046do_malloc_test mallocA-1.1 -testdb test.db.bu -sqlbody {
47 ANALYZE t1
48}
49do_malloc_test mallocA-1.2 -testdb test.db.bu -sqlbody {
50 ANALYZE main
51}
52do_malloc_test mallocA-1.3 -testdb test.db.bu -sqlbody {
53 ANALYZE main.t1
54}
danaf2583c2013-08-15 18:43:21 +000055
danielk19774152e672007-09-12 17:01:45 +000056ifcapable reindex {
57 do_malloc_test mallocA-2 -testdb test.db.bu -sqlbody {
58 REINDEX;
59 }
60 do_malloc_test mallocA-3 -testdb test.db.bu -sqlbody {
61 REINDEX t1;
62 }
63 do_malloc_test mallocA-4 -testdb test.db.bu -sqlbody {
64 REINDEX main.t1;
65 }
66 do_malloc_test mallocA-5 -testdb test.db.bu -sqlbody {
67 REINDEX nocase;
68 }
drh84f31122007-05-12 15:00:14 +000069}
drhcf1be452007-05-12 12:08:51 +000070
danaf2583c2013-08-15 18:43:21 +000071reset_db
72sqlite3_db_config_lookaside db 0 0 0
73do_execsql_test 6-prep {
74 CREATE TABLE t1(a, b);
75 CREATE INDEX i1 ON t1(a, b);
76 INSERT INTO t1 VALUES('abc', 'w'); -- rowid=1
77 INSERT INTO t1 VALUES('abc', 'x'); -- rowid=2
78 INSERT INTO t1 VALUES('abc', 'y'); -- rowid=3
79 INSERT INTO t1 VALUES('abc', 'z'); -- rowid=4
80
81 INSERT INTO t1 VALUES('def', 'w'); -- rowid=5
82 INSERT INTO t1 VALUES('def', 'x'); -- rowid=6
83 INSERT INTO t1 VALUES('def', 'y'); -- rowid=7
84 INSERT INTO t1 VALUES('def', 'z'); -- rowid=8
85
86 ANALYZE;
87}
88
89do_faultsim_test 6.1 -faults oom* -body {
90 execsql { SELECT rowid FROM t1 WHERE a='abc' AND b='x' }
91} -test {
92 faultsim_test_result [list 0 2]
93}
94do_faultsim_test 6.2 -faults oom* -body {
95 execsql { SELECT rowid FROM t1 WHERE a='abc' AND b<'y' }
96} -test {
97 faultsim_test_result [list 0 {1 2}]
98}
99
dandd95d302014-04-02 15:15:25 +0000100do_execsql_test 7.0 {
101 PRAGMA cache_size = 5;
102}
103do_faultsim_test 7 -faults oom-trans* -prep {
dandd95d302014-04-02 15:15:25 +0000104} -body {
105 execsql {
106 WITH r(x,y) AS (
107 SELECT 1, randomblob(100)
108 UNION ALL
109 SELECT x+1, randomblob(100) FROM r
110 LIMIT 1000
111 )
112 SELECT count(x), length(y) FROM r GROUP BY (x%5)
113 }
114} -test {
115 set res [list 200 100 200 100 200 100 200 100 200 100]
116 faultsim_test_result [list 0 $res]
117}
118
119
drhcf1be452007-05-12 12:08:51 +0000120# Ensure that no file descriptors were leaked.
121do_test malloc-99.X {
122 catch {db close}
123 set sqlite_open_file_count
124} {0}
125
mistachkinfda06be2011-08-02 00:57:34 +0000126forcedelete test.db.bu
drhcf1be452007-05-12 12:08:51 +0000127finish_test