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

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

Issue 2846743003: [sql] Remove SQLite 3.10.2 reference directory. (Closed)
Patch Set: Created 3 years, 7 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 !malloc_usable_size {
104 do_test memsubsys1-2.3 {
105 set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2]
106 } [expr ($TEMP_STORE>1 || $MEMORY_MANAGEMENT==0)*1024]
107 }
108 do_test memsubsys1-2.4 {
109 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
110 } 20
111 do_test memsubsys1-2.5 {
112 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
113 } 0
114
115 # Test 3: Activate PAGECACHE with 20 pages but use the wrong page size
116 # so that PAGECACHE is not used.
117 #
118 db close
119 sqlite3_shutdown
120 sqlite3_config_pagecache [expr 512+$xtra_size] 20
121 sqlite3_config singlethread
122 sqlite3_initialize
123 reset_highwater_marks
124 build_test_db memsubsys1-3.1 {PRAGMA page_size=1024}
125 do_test memsubsys1-3.1.3 {
126 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
127 } 0
128 do_test memsubsys1-3.1.4 {
129 set overflow [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2]
130 # Note: The measured PAGECACHE_OVERFLOW is amount malloc() returns, not what
131 # was requested. System malloc() implementations might (arbitrarily) return
132 # slightly different oversize buffers, which can result in slightly different
133 # PAGECACHE_OVERFLOW sizes between consecutive runs. So we cannot do an
134 # exact comparison. Simply verify that the amount is within 5%.
135 expr {$overflow>=$max_pagecache*0.95 && $overflow<=$max_pagecache*1.05}
136 } 1
137 do_test memsubsys1-3.1.5 {
138 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
139 } 0
140 db close
141 sqlite3_shutdown
142 sqlite3_config_pagecache [expr 2048+$xtra_size] 20
143 sqlite3_initialize
144 reset_highwater_marks
145 build_test_db memsubsys1-3.2 {PRAGMA page_size=2048}
146 #show_memstats
147 do_test memsubsys1-3.2.3 {
148 db eval {PRAGMA page_size}
149 } 2048
150 do_test memsubsys1-3.2.4 {
151 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
152 } 20
153 do_test memsubsys1-3.2.5 {
154 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
155 } 0
156
157 # Test 4: Activate both PAGECACHE and SCRATCH.
158 #
159 db close
160 sqlite3_shutdown
161 sqlite3_config_pagecache [expr 1024+$xtra_size] 50
162 sqlite3_config_scratch 6000 2
163 sqlite3_initialize
164 reset_highwater_marks
165 build_test_db memsubsys1-4 {PRAGMA page_size=1024}
166 #show_memstats
167 do_test memsubsys1-4.3 {
168 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
169 expr {$pg_used>=45 && $pg_used<=50}
170 } 1
171 do_test memsubsys1-4.4 {
172 set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2]
173 } 0
174 do_test memsubsys1-4.5 {
175 set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2]
176 expr {$maxreq<7000}
177 } 1
178 do_test memsubsys1-4.6 {
179 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
180 } 1
181
182 # Test 5: Activate both PAGECACHE and SCRATCH. But make the page size is
183 # such that the SCRATCH allocations are too small.
184 #
185 db close
186 sqlite3_shutdown
187 sqlite3_config_pagecache [expr 4096+$xtra_size] 24
188 sqlite3_config_scratch 4000 2
189 sqlite3_initialize
190 reset_highwater_marks
191 build_test_db memsubsys1-5 {PRAGMA page_size=4096}
192 #show_memstats
193 do_test memsubsys1-5.3 {
194 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
195 } {/^2[34]$/}
196 do_test memsubsys1-5.4 {
197 set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2]
198 expr {$maxreq>4096}
199 } 1
200 do_test memsubsys1-5.5 {
201 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
202 } 0
203 do_test memsubsys1-5.6 {
204 set s_ovfl [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0] 2]
205 expr {$s_ovfl>6000}
206 } 1
207
208 # Test 6: Activate both PAGECACHE and SCRATCH with a 4k page size.
209 # Make it so that SCRATCH is large enough
210 #
211 db close
212 sqlite3_shutdown
213 sqlite3_config_pagecache [expr 4096+$xtra_size] 24
214 sqlite3_config_scratch 25300 1
215 sqlite3_initialize
216 reset_highwater_marks
217 build_test_db memsubsys1-6 {PRAGMA page_size=4096}
218 #show_memstats
219 do_test memsubsys1-6.3 {
220 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
221 } {/^2[34]$/}
222 #do_test memsubsys1-6.4 {
223 # set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2]
224 # expr {$maxreq>4096 && $maxreq<=(4096+$xtra_size)}
225 #} 1
226 do_test memsubsys1-6.5 {
227 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
228 } 1
229 do_test memsubsys1-6.6 {
230 set s_ovfl [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0] 2]
231 } 0
232
233 # Test 7: Activate both PAGECACHE and SCRATCH with a 4k page size.
234 # Set cache_size small so that no PAGECACHE overflow occurs. Verify
235 # that maximum allocation size is small.
236 #
237 db close
238 sqlite3_shutdown
239 sqlite3_config_pagecache [expr 4096+$xtra_size] 24
240 sqlite3_config_scratch 25300 1
241 sqlite3_initialize
242 reset_highwater_marks
243 build_test_db memsubsys1-7 {
244 PRAGMA page_size=4096;
245 PRAGMA cache_size=10;
246 PRAGMA temp_store=memory;
247 }
248 #show_memstats
249 do_test memsubsys1-7.3 {
250 set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
251 expr {$pg_used<24}
252 } 1
253 do_test memsubsys1-7.4 {
254 set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2]
255 } 0
256 do_test memsubsys1-7.5 {
257 set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2]
258 expr {$maxreq<4100}
259 } 1
260 do_test memsubsys1-7.6 {
261 set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
262 } 1
263 do_test memsubsys1-7.7 {
264 set s_ovfl [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0] 2]
265 } 0
266
267 # Test 8: Disable PAGECACHE. Make available SCRATCH zero. Verify that
268 # the SCRATCH overflow logic works.
269 #
270 db close
271 sqlite3_shutdown
272 sqlite3_config_pagecache 0 0
273 sqlite3_config_scratch 25000 0
274 sqlite3_initialize
275 reset_highwater_marks
276 do_test memsubsys1-8.1 {
277 set pg_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
278 } 0
279 do_test memsubsys1-8.2 {
280 set s_ovfl [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0] 2]
281 } 0
282 do_test memsubsys1-8.3 {
283 sqlite3 db :memory:
284 db eval {
285 CREATE TABLE t1(x);
286 INSERT INTO t1 VALUES(zeroblob(400));
287 INSERT INTO t1 VALUES(zeroblob(400));
288 INSERT INTO t1 SELECT * FROM t1;
289 INSERT INTO t1 SELECT * FROM t1;
290 INSERT INTO t1 SELECT * FROM t1;
291 }
292 expr {[lindex [sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 0] 2]>0}
293 } 1
294 db close
295 sqlite3_shutdown
296 sqlite3_config_memstatus 0
297 sqlite3_initialize
298 do_test memsubsys1-8.4 {
299 sqlite3 db :memory:
300 db eval {
301 CREATE TABLE t1(x);
302 INSERT INTO t1 VALUES(zeroblob(400));
303 INSERT INTO t1 VALUES(zeroblob(400));
304 INSERT INTO t1 SELECT * FROM t1;
305 INSERT INTO t1 SELECT * FROM t1;
306 INSERT INTO t1 SELECT * FROM t1;
307 SELECT rowid FROM t1;
308 }
309 } {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16}
310
311
312 db close
313 sqlite3_shutdown
314 sqlite3_config_memstatus 1
315 sqlite3_config_scratch 0 0
316 sqlite3_config_lookaside 100 500
317 sqlite3_config serialized
318 sqlite3_initialize
319 autoinstall_test_functions
320
321 test_restore_config_pagecache
322 finish_test
OLDNEW
« no previous file with comments | « third_party/sqlite/sqlite-src-3100200/test/memleak.test ('k') | third_party/sqlite/sqlite-src-3100200/test/memsubsys2.test » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698