Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: third_party/sqlite/sqlite-src-3170000/test/memsubsys1.test

Issue 2747283002: [sql] Import reference version of SQLite 3.17.. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # 2008 June 18
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 tests of the memory allocation subsystem
13 #
14
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 sqlite3_reset_auto_extension
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
28 test_set_config_pagecache 0 0
29
30 # This procedure constructs a new database in test.db. It fills
31 # this database with many small records (enough to force multiple
32 # rebalance operations in the btree-layer and to require a large
33 # page cache), verifies correct results, then returns.
34 #
35 proc build_test_db {testname pragmas} {
36 catch {db close}
37 forcedelete test.db test.db-journal
38 sqlite3 db test.db
39 sqlite3_db_config_lookaside db 0 0 0
40 db eval $pragmas
41 db eval {
42 CREATE TABLE t1(x, y);
43 CREATE TABLE t2(a, b);
44 CREATE INDEX i1 ON t1(x,y);
45 INSERT INTO t1 VALUES(1, 100);
46 INSERT INTO t1 VALUES(2, 200);
47 }
48 for {set i 2} {$i<5000} {incr i $i} {
49 db eval {INSERT INTO t2 SELECT * FROM t1}
50 db eval {INSERT INTO t1 SELECT a+$i, a+b*100 FROM t2}
51 db eval {DELETE FROM t2}
52 }
53 do_test $testname.1 {
54 db eval {SELECT count(*) FROM t1}
55 } 8192
56 integrity_check $testname.2
57 }
58
59 # Reset all of the highwater marks.
60 #
61 proc reset_highwater_marks {} {
62 sqlite3_status SQLITE_STATUS_MEMORY_USED 1
63 sqlite3_status SQLITE_STATUS_MALLOC_SIZE 1
64 sqlite3_status SQLITE_STATUS_PAGECACHE_USED 1
65 sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 1
66 sqlite3_status SQLITE_STATUS_PAGECACHE_SIZE 1
67 sqlite3_status SQLITE_STATUS_SCRATCH_USED 1
68 sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 1
69 sqlite3_status SQLITE_STATUS_SCRATCH_SIZE 1
70 sqlite3_status SQLITE_STATUS_PARSER_STACK 1
71 }
72
73 set xtra_size 290
74
75 # Test 1: Both PAGECACHE and SCRATCH are shut down.
76 #
77 db close
78 sqlite3_shutdown
79 sqlite3_config_lookaside 0 0
80 sqlite3_config_pagecache 0 0
81 sqlite3_initialize
82 reset_highwater_marks
83 build_test_db memsubsys1-1 {PRAGMA page_size=1024}
84 do_test memsubsys1-1.3 {
85 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
86 } 0
87 do_test memsubsys1-1.4 {
88 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
89 } 0
90 set max_pagecache [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2]
91 #show_memstats
92
93 # Test 2: Activate PAGECACHE with 20 pages
94 #
95 db close
96 sqlite3_shutdown
97 sqlite3_config_pagecache [expr 1024+$xtra_size] 20
98 sqlite3_initialize
99 reset_highwater_marks
100 build_test_db memsubsys1-2 {PRAGMA page_size=1024; PRAGMA mmap_size=0}
101 #show_memstats
102 set MEMORY_MANAGEMENT $sqlite_options(memorymanage)
103 ifcapable pagecache_overflow_stats {
104 ifcapable !malloc_usable_size {
105 do_test memsubsys1-2.3 {
106 set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2]
107 } [expr ($TEMP_STORE>1 || $MEMORY_MANAGEMENT==0)*1024]
108 }
109 }
110 do_test memsubsys1-2.4 {
111 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
112 } 20
113 do_test memsubsys1-2.5 {
114 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
115 } 0
116
117 # Test 3: Activate PAGECACHE with 20 pages but use the wrong page size
118 # so that PAGECACHE is not used.
119 #
120 db close
121 sqlite3_shutdown
122 sqlite3_config_pagecache [expr 512+$xtra_size] 20
123 sqlite3_config singlethread
124 sqlite3_initialize
125 reset_highwater_marks
126 build_test_db memsubsys1-3.1 {PRAGMA page_size=1024}
127 do_test memsubsys1-3.1.3 {
128 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
129 } 0
130 do_test memsubsys1-3.1.4 {
131 set overflow [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2]
132 # Note: The measured PAGECACHE_OVERFLOW is amount malloc() returns, not what
133 # was requested. System malloc() implementations might (arbitrarily) return
134 # slightly different oversize buffers, which can result in slightly different
135 # PAGECACHE_OVERFLOW sizes between consecutive runs. So we cannot do an
136 # exact comparison. Simply verify that the amount is within 5%.
137 expr {$overflow>=$max_pagecache*0.95 && $overflow<=$max_pagecache*1.05}
138 } 1
139 do_test memsubsys1-3.1.5 {
140 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
141 } 0
142 db close
143 sqlite3_shutdown
144 sqlite3_config_pagecache [expr 2048+$xtra_size] 20
145 sqlite3_initialize
146 reset_highwater_marks
147 build_test_db memsubsys1-3.2 {PRAGMA page_size=2048}
148 #show_memstats
149 do_test memsubsys1-3.2.3 {
150 db eval {PRAGMA page_size}
151 } 2048
152 do_test memsubsys1-3.2.4 {
153 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
154 } 20
155 do_test memsubsys1-3.2.5 {
156 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
157 } 0
158
159 # Test 4: Activate both PAGECACHE and SCRATCH.
160 #
161 db close
162 sqlite3_shutdown
163 sqlite3_config_pagecache [expr 1024+$xtra_size] 50
164 sqlite3_config_scratch 6000 2
165 sqlite3_initialize
166 reset_highwater_marks
167 build_test_db memsubsys1-4 {PRAGMA page_size=1024}
168 #show_memstats
169 do_test memsubsys1-4.3 {
170 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
171 expr {$pg_used>=45 && $pg_used<=50}
172 } 1
173 do_test memsubsys1-4.4 {
174 set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2]
175 } 0
176 do_test memsubsys1-4.5 {
177 set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2]
178 expr {$maxreq<7000}
179 } 1
180 do_test memsubsys1-4.6 {
181 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
182 } 1
183
184 # Test 5: Activate both PAGECACHE and SCRATCH. But make the page size is
185 # such that the SCRATCH allocations are too small.
186 #
187 db close
188 sqlite3_shutdown
189 sqlite3_config_pagecache [expr 4096+$xtra_size] 24
190 sqlite3_config_scratch 4000 2
191 sqlite3_initialize
192 reset_highwater_marks
193 build_test_db memsubsys1-5 {PRAGMA page_size=4096}
194 #show_memstats
195 do_test memsubsys1-5.3 {
196 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
197 } {/^2[34]$/}
198 do_test memsubsys1-5.4 {
199 set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2]
200 expr {$maxreq>4096}
201 } 1
202 do_test memsubsys1-5.5 {
203 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
204 } 0
205 do_test memsubsys1-5.6 {
206 set s_ovfl [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0] 2]
207 expr {$s_ovfl>6000}
208 } 1
209
210 # Test 6: Activate both PAGECACHE and SCRATCH with a 4k page size.
211 # Make it so that SCRATCH is large enough
212 #
213 db close
214 sqlite3_shutdown
215 sqlite3_config_pagecache [expr 4096+$xtra_size] 24
216 sqlite3_config_scratch 25300 1
217 sqlite3_initialize
218 reset_highwater_marks
219 build_test_db memsubsys1-6 {PRAGMA page_size=4096}
220 #show_memstats
221 do_test memsubsys1-6.3 {
222 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
223 } {/^2[34]$/}
224 #do_test memsubsys1-6.4 {
225 # set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2]
226 # expr {$maxreq>4096 && $maxreq<=(4096+$xtra_size)}
227 #} 1
228 do_test memsubsys1-6.5 {
229 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
230 } 1
231 do_test memsubsys1-6.6 {
232 set s_ovfl [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0] 2]
233 } 0
234
235 # Test 7: Activate both PAGECACHE and SCRATCH with a 4k page size.
236 # Set cache_size small so that no PAGECACHE overflow occurs. Verify
237 # that maximum allocation size is small.
238 #
239 db close
240 sqlite3_shutdown
241 sqlite3_config_pagecache [expr 4096+$xtra_size] 24
242 sqlite3_config_scratch 25300 1
243 sqlite3_initialize
244 reset_highwater_marks
245 build_test_db memsubsys1-7 {
246 PRAGMA page_size=4096;
247 PRAGMA cache_size=10;
248 PRAGMA temp_store=memory;
249 }
250 #show_memstats
251 do_test memsubsys1-7.3 {
252 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
253 expr {$pg_used<24}
254 } 1
255 do_test memsubsys1-7.4 {
256 set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2]
257 } 0
258 do_test memsubsys1-7.5 {
259 set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2]
260 expr {$maxreq<(4100 + 8200*[nonzero_reserved_bytes])}
261 } 1
262 do_test memsubsys1-7.6 {
263 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
264 } 1
265 do_test memsubsys1-7.7 {
266 set s_ovfl [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0] 2]
267 } 0
268
269 # Test 8: Disable PAGECACHE. Make available SCRATCH zero. Verify that
270 # the SCRATCH overflow logic works.
271 #
272 db close
273 sqlite3_shutdown
274 sqlite3_config_pagecache 0 0
275 sqlite3_config_scratch 25000 0
276 sqlite3_initialize
277 reset_highwater_marks
278 do_test memsubsys1-8.1 {
279 set pg_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
280 } 0
281 do_test memsubsys1-8.2 {
282 set s_ovfl [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0] 2]
283 } 0
284 do_test memsubsys1-8.3 {
285 sqlite3 db :memory:
286 db eval {
287 CREATE TABLE t1(x);
288 INSERT INTO t1 VALUES(zeroblob(400));
289 INSERT INTO t1 VALUES(zeroblob(400));
290 INSERT INTO t1 SELECT * FROM t1;
291 INSERT INTO t1 SELECT * FROM t1;
292 INSERT INTO t1 SELECT * FROM t1;
293 }
294 expr {[lindex [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0] 2]>0}
295 } 1
296 db close
297 sqlite3_shutdown
298 sqlite3_config_memstatus 0
299 sqlite3_initialize
300 do_test memsubsys1-8.4 {
301 sqlite3 db :memory:
302 db eval {
303 CREATE TABLE t1(x);
304 INSERT INTO t1 VALUES(zeroblob(400));
305 INSERT INTO t1 VALUES(zeroblob(400));
306 INSERT INTO t1 SELECT * FROM t1;
307 INSERT INTO t1 SELECT * FROM t1;
308 INSERT INTO t1 SELECT * FROM t1;
309 SELECT rowid FROM t1;
310 }
311 } {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16}
312
313
314 db close
315 sqlite3_shutdown
316 sqlite3_config_memstatus 1
317 sqlite3_config_scratch 0 0
318 sqlite3_config_lookaside 100 500
319 sqlite3_config serialized
320 sqlite3_initialize
321 autoinstall_test_functions
322
323 test_restore_config_pagecache
324 finish_test
OLDNEW
« no previous file with comments | « third_party/sqlite/sqlite-src-3170000/test/memleak.test ('k') | third_party/sqlite/sqlite-src-3170000/test/memsubsys2.test » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698