blob: 6cc0786d28c54c201bfda2b26810bdb5a9431560 [file] [log] [blame]
drh09419b42011-11-16 19:29:17 +00001# 2011 November 16
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# This file contains test cases for sqlite3_db_release_memory and
13# the PRAGMA shrink_memory statement.
14#
15
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
19unset -nocomplain baseline
20do_test shrink-1.1 {
21 db eval {
dan5d8341a2012-01-12 16:41:30 +000022 PRAGMA cache_size = 2000;
drh09419b42011-11-16 19:29:17 +000023 CREATE TABLE t1(x,y);
24 INSERT INTO t1 VALUES(randomblob(1000000),1);
25 }
26 set ::baseline sqlite3_memory_used
drh8dd7a6a2015-03-06 04:37:26 +000027 # EVIDENCE-OF: R-58814-63508 The sqlite3_db_release_memory(D) interface
28 # attempts to free as much heap memory as possible from database
29 # connection D.
drh09419b42011-11-16 19:29:17 +000030 sqlite3_db_release_memory db
31 expr {$::baseline > [sqlite3_memory_used]+500000}
32} {1}
33do_test shrink-1.2 {
34 set baseline [sqlite3_memory_used]
35 db eval {
36 UPDATE t1 SET y=y+1;
37 }
38 expr {$::baseline+500000 < [sqlite3_memory_used]}
39} {1}
40do_test shrink-1.3 {
41 set baseline [sqlite3_memory_used]
42 db eval {PRAGMA shrink_memory}
43 expr {$::baseline > [sqlite3_memory_used]+500000}
44} {1}
45
46finish_test