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

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

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

Powered by Google App Engine
This is Rietveld 408576698