OLD | NEW |
1 # 2008 June 18 | 1 # 2008 June 18 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
11 # | 11 # |
12 # This file contains tests of the memory allocation subsystem | 12 # This file contains tests of the memory allocation subsystem |
13 # | 13 # |
14 # $Id: memsubsys1.test,v 1.17 2009/07/18 14:36:24 danielk1977 Exp $ | |
15 | 14 |
16 set testdir [file dirname $argv0] | 15 set testdir [file dirname $argv0] |
17 source $testdir/tester.tcl | 16 source $testdir/tester.tcl |
18 sqlite3_reset_auto_extension | 17 sqlite3_reset_auto_extension |
19 | 18 |
| 19 # This test assumes that no page-cache or scratch buffers are installed |
| 20 # by default when a new database connection is opened. As a result, it |
| 21 # will not work with the "memsubsys1" permutation. |
| 22 # |
| 23 if {[permutation] == "memsubsys1"} { |
| 24 finish_test |
| 25 return |
| 26 } |
| 27 |
20 # This procedure constructs a new database in test.db. It fills | 28 # This procedure constructs a new database in test.db. It fills |
21 # this database with many small records (enough to force multiple | 29 # this database with many small records (enough to force multiple |
22 # rebalance operations in the btree-layer and to require a large | 30 # rebalance operations in the btree-layer and to require a large |
23 # page cache), verifies correct results, then returns. | 31 # page cache), verifies correct results, then returns. |
24 # | 32 # |
25 proc build_test_db {testname pragmas} { | 33 proc build_test_db {testname pragmas} { |
26 catch {db close} | 34 catch {db close} |
27 file delete -force test.db test.db-journal | 35 file delete -force test.db test.db-journal |
28 sqlite3 db test.db | 36 sqlite3 db test.db |
29 sqlite3_db_config_lookaside db 0 0 0 | 37 sqlite3_db_config_lookaside db 0 0 0 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 89 |
82 # Test 2: Activate PAGECACHE with 20 pages | 90 # Test 2: Activate PAGECACHE with 20 pages |
83 # | 91 # |
84 db close | 92 db close |
85 sqlite3_shutdown | 93 sqlite3_shutdown |
86 sqlite3_config_pagecache [expr 1024+$xtra_size] 20 | 94 sqlite3_config_pagecache [expr 1024+$xtra_size] 20 |
87 sqlite3_initialize | 95 sqlite3_initialize |
88 reset_highwater_marks | 96 reset_highwater_marks |
89 build_test_db memsubsys1-2 {PRAGMA page_size=1024} | 97 build_test_db memsubsys1-2 {PRAGMA page_size=1024} |
90 #show_memstats | 98 #show_memstats |
| 99 set MEMORY_MANAGEMENT $sqlite_options(memorymanage) |
91 do_test memsubsys1-2.3 { | 100 do_test memsubsys1-2.3 { |
92 set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2] | 101 set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2] |
93 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] | 102 } [expr ($TEMP_STORE>1 || $MEMORY_MANAGEMENT==0)*1024] |
94 expr { | |
95 ($pg_used*1024 + $pg_ovfl) < $max_pagecache && | |
96 ($pg_used*(1024+$xtra_size) + $pg_ovfl) >= $max_pagecache | |
97 } | |
98 } 1 | |
99 do_test memsubsys1-2.4 { | 103 do_test memsubsys1-2.4 { |
100 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] | 104 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] |
101 } 19 | 105 } 20 |
102 do_test memsubsys1-2.5 { | 106 do_test memsubsys1-2.5 { |
103 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] | 107 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] |
104 } 0 | 108 } 0 |
105 | 109 |
106 # Test 3: Activate PAGECACHE with 20 pages but use the wrong page size | 110 # Test 3: Activate PAGECACHE with 20 pages but use the wrong page size |
107 # so that PAGECACHE is not used. | 111 # so that PAGECACHE is not used. |
108 # | 112 # |
109 db close | 113 db close |
110 sqlite3_shutdown | 114 sqlite3_shutdown |
111 sqlite3_config_pagecache [expr 512+$xtra_size] 20 | 115 sqlite3_config_pagecache [expr 512+$xtra_size] 20 |
(...skipping 15 matching lines...) Expand all Loading... |
127 sqlite3_config_pagecache [expr 2048+$xtra_size] 20 | 131 sqlite3_config_pagecache [expr 2048+$xtra_size] 20 |
128 sqlite3_initialize | 132 sqlite3_initialize |
129 reset_highwater_marks | 133 reset_highwater_marks |
130 build_test_db memsubsys1-3.2 {PRAGMA page_size=2048} | 134 build_test_db memsubsys1-3.2 {PRAGMA page_size=2048} |
131 #show_memstats | 135 #show_memstats |
132 do_test memsubsys1-3.2.3 { | 136 do_test memsubsys1-3.2.3 { |
133 db eval {PRAGMA page_size} | 137 db eval {PRAGMA page_size} |
134 } 2048 | 138 } 2048 |
135 do_test memsubsys1-3.2.4 { | 139 do_test memsubsys1-3.2.4 { |
136 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] | 140 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] |
137 } 19 | 141 } 20 |
138 do_test memsubsys1-3.2.5 { | 142 do_test memsubsys1-3.2.5 { |
139 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] | 143 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] |
140 } 0 | 144 } 0 |
141 | 145 |
142 # Test 4: Activate both PAGECACHE and SCRATCH. | 146 # Test 4: Activate both PAGECACHE and SCRATCH. |
143 # | 147 # |
144 db close | 148 db close |
145 sqlite3_shutdown | 149 sqlite3_shutdown |
146 sqlite3_config_pagecache [expr 1024+$xtra_size] 50 | 150 sqlite3_config_pagecache [expr 1024+$xtra_size] 50 |
147 sqlite3_config_scratch 6000 2 | 151 sqlite3_config_scratch 6000 2 |
148 sqlite3_initialize | 152 sqlite3_initialize |
149 reset_highwater_marks | 153 reset_highwater_marks |
150 build_test_db memsubsys1-4 {PRAGMA page_size=1024} | 154 build_test_db memsubsys1-4 {PRAGMA page_size=1024} |
151 #show_memstats | 155 #show_memstats |
152 do_test memsubsys1-4.3 { | 156 do_test memsubsys1-4.3 { |
153 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] | 157 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] |
154 } 49 | 158 expr {$pg_used>=45 && $pg_used<=50} |
| 159 } 1 |
155 do_test memsubsys1-4.4 { | 160 do_test memsubsys1-4.4 { |
156 set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2] | 161 set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2] |
157 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] | 162 } 0 |
158 expr { | |
159 ($pg_used*1024 + $pg_ovfl) < $max_pagecache && | |
160 ($pg_used*(1024+$xtra_size) + $pg_ovfl) >= $max_pagecache | |
161 } | |
162 } 1 | |
163 do_test memsubsys1-4.5 { | 163 do_test memsubsys1-4.5 { |
164 set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2] | 164 set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2] |
165 expr {$maxreq<7000} | 165 expr {$maxreq<7000} |
166 } 1 | 166 } 1 |
167 do_test memsubsys1-4.6 { | 167 do_test memsubsys1-4.6 { |
168 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] | 168 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] |
169 } 1 | 169 } 1 |
170 | 170 |
171 # Test 5: Activate both PAGECACHE and SCRATCH. But make the page size | 171 # Test 5: Activate both PAGECACHE and SCRATCH. But make the page size |
172 # such that the SCRATCH allocations are too small. | 172 # such that the SCRATCH allocations are too small. |
173 # | 173 # |
174 db close | 174 db close |
175 sqlite3_shutdown | 175 sqlite3_shutdown |
176 sqlite3_config_pagecache [expr 4096+$xtra_size] 24 | 176 sqlite3_config_pagecache [expr 4096+$xtra_size] 24 |
177 sqlite3_config_scratch 6000 2 | 177 sqlite3_config_scratch 6000 2 |
178 sqlite3_initialize | 178 sqlite3_initialize |
179 reset_highwater_marks | 179 reset_highwater_marks |
180 build_test_db memsubsys1-5 {PRAGMA page_size=4096} | 180 build_test_db memsubsys1-5 {PRAGMA page_size=4096} |
181 #show_memstats | 181 #show_memstats |
182 do_test memsubsys1-5.3 { | 182 do_test memsubsys1-5.3 { |
183 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] | 183 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] |
184 } 23 | 184 } 24 |
185 do_test memsubsys1-5.4 { | 185 do_test memsubsys1-5.4 { |
186 set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2] | 186 set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2] |
187 expr {$maxreq>4096} | 187 expr {$maxreq>4096} |
188 } 1 | 188 } 1 |
189 do_test memsubsys1-5.5 { | 189 do_test memsubsys1-5.5 { |
190 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] | 190 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] |
191 } 0 | 191 } 0 |
192 do_test memsubsys1-5.6 { | 192 do_test memsubsys1-5.6 { |
193 set s_ovfl [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0] 2] | 193 set s_ovfl [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0] 2] |
194 expr {$s_ovfl>6000} | 194 expr {$s_ovfl>6000} |
195 } 1 | 195 } 1 |
196 | 196 |
197 # Test 6: Activate both PAGECACHE and SCRATCH with a 4k page size. | 197 # Test 6: Activate both PAGECACHE and SCRATCH with a 4k page size. |
198 # Make it so that SCRATCH is large enough | 198 # Make it so that SCRATCH is large enough |
199 # | 199 # |
200 db close | 200 db close |
201 sqlite3_shutdown | 201 sqlite3_shutdown |
202 sqlite3_config_pagecache [expr 4096+$xtra_size] 24 | 202 sqlite3_config_pagecache [expr 4096+$xtra_size] 24 |
203 sqlite3_config_scratch 25300 1 | 203 sqlite3_config_scratch 25300 1 |
204 sqlite3_initialize | 204 sqlite3_initialize |
205 reset_highwater_marks | 205 reset_highwater_marks |
206 build_test_db memsubsys1-6 {PRAGMA page_size=4096} | 206 build_test_db memsubsys1-6 {PRAGMA page_size=4096} |
207 #show_memstats | 207 #show_memstats |
208 do_test memsubsys1-6.3 { | 208 do_test memsubsys1-6.3 { |
209 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] | 209 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2] |
210 } 23 | 210 } 24 |
211 do_test memsubsys1-6.4 { | 211 #do_test memsubsys1-6.4 { |
212 set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2] | 212 # set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2] |
213 expr {$maxreq>4096 && $maxreq<=(4096+$xtra_size)} | 213 # expr {$maxreq>4096 && $maxreq<=(4096+$xtra_size)} |
214 } 1 | 214 #} 1 |
215 do_test memsubsys1-6.5 { | 215 do_test memsubsys1-6.5 { |
216 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] | 216 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2] |
217 } 1 | 217 } 1 |
218 do_test memsubsys1-6.6 { | 218 do_test memsubsys1-6.6 { |
219 set s_ovfl [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0] 2] | 219 set s_ovfl [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0] 2] |
220 } 0 | 220 } 0 |
221 | 221 |
222 # Test 7: Activate both PAGECACHE and SCRATCH with a 4k page size. | 222 # Test 7: Activate both PAGECACHE and SCRATCH with a 4k page size. |
223 # Set cache_size small so that no PAGECACHE overflow occurs. Verify | 223 # Set cache_size small so that no PAGECACHE overflow occurs. Verify |
224 # that maximum allocation size is small. | 224 # that maximum allocation size is small. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 300 |
301 db close | 301 db close |
302 sqlite3_shutdown | 302 sqlite3_shutdown |
303 sqlite3_config_memstatus 1 | 303 sqlite3_config_memstatus 1 |
304 sqlite3_config_pagecache 0 0 | 304 sqlite3_config_pagecache 0 0 |
305 sqlite3_config_scratch 0 0 | 305 sqlite3_config_scratch 0 0 |
306 sqlite3_config_lookaside 100 500 | 306 sqlite3_config_lookaside 100 500 |
307 sqlite3_initialize | 307 sqlite3_initialize |
308 autoinstall_test_functions | 308 autoinstall_test_functions |
309 finish_test | 309 finish_test |
OLD | NEW |