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

Unified Diff: third_party/sqlite/src/test/malloc5.test

Issue 1610963002: Import SQLite 3.10.2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/sqlite/src/test/malloc.test ('k') | third_party/sqlite/src/test/mallocK.test » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/sqlite/src/test/malloc5.test
diff --git a/third_party/sqlite/src/test/malloc5.test b/third_party/sqlite/src/test/malloc5.test
index 6abedf79e1c438c1302955074884b144c83c3c8b..8f0db04c2a5a2e9d973be4f1820c3708918e34d1 100644
--- a/third_party/sqlite/src/test/malloc5.test
+++ b/third_party/sqlite/src/test/malloc5.test
@@ -39,8 +39,11 @@ ifcapable !memorymanage {
return
}
+test_set_config_pagecache 0 100
+
sqlite3_soft_heap_limit 0
sqlite3 db test.db
+db eval {PRAGMA cache_size=1}
do_test malloc5-1.1 {
# Simplest possible test. Call sqlite3_release_memory when there is exactly
@@ -61,15 +64,31 @@ do_test malloc5-1.2 {
# not the case before version 3.6.2).
#
sqlite3 db2 test.db
- execsql { SELECT * FROM sqlite_master } db2
+ execsql {PRAGMA cache_size=2; SELECT * FROM sqlite_master } db2
} {}
do_test malloc5-1.3 {
# Call [sqlite3_release_memory] when there is exactly one unused page
# in the cache belonging to db2.
#
set ::pgalloc [sqlite3_release_memory]
- expr $::pgalloc > 0
-} {1}
+} {0}
+
+# The sizes of memory allocations from system malloc() might vary,
+# depending on the memory allocator algorithms used. The following
+# routine is designed to support answers that fall within a range
+# of values while also supplying easy-to-understand "expected" values
+# when errors occur.
+#
+proc value_in_range {target x args} {
+ set v [lindex $args 0]
+ if {$v!=""} {
+ if {$v<$target*$x} {return $v}
+ if {$v>$target/$x} {return $v}
+ }
+ return "number between [expr {int($target*$x)}] and [expr {int($target/$x)}]"
+}
+set mrange 0.98 ;# plus or minus 2%
+
do_test malloc5-1.4 {
# Commit the transaction and open a new one. Read 1 page into the cache.
@@ -81,16 +100,16 @@ do_test malloc5-1.4 {
BEGIN;
SELECT * FROM abc;
}
- sqlite3_release_memory
-} $::pgalloc
+ value_in_range $::pgalloc $::mrange [sqlite3_release_memory]
+} [value_in_range $::pgalloc $::mrange]
do_test malloc5-1.5 {
# Conclude the transaction opened in the previous [do_test] block. This
# causes another page (page 1) to become eligible for recycling.
#
execsql { COMMIT }
- sqlite3_release_memory
-} $::pgalloc
+ value_in_range $::pgalloc $::mrange [sqlite3_release_memory]
+} [value_in_range $::pgalloc $::mrange]
do_test malloc5-1.6 {
# Manipulate the cache so that it contains two unused pages. One requires
@@ -101,8 +120,8 @@ do_test malloc5-1.6 {
SELECT * FROM abc;
CREATE TABLE def(d, e, f);
}
- sqlite3_release_memory 500
-} $::pgalloc
+ value_in_range $::pgalloc $::mrange [sqlite3_release_memory 500]
+} [value_in_range $::pgalloc $::mrange]
do_test malloc5-1.7 {
# Database should not be locked this time.
@@ -172,8 +191,8 @@ do_test malloc5-3.1 {
BEGIN;
SELECT * FROM def;
} db2
- sqlite3_release_memory
-} [expr $::pgalloc * 2]
+ value_in_range [expr $::pgalloc*2] 0.99 [sqlite3_release_memory]
+} [value_in_range [expr $::pgalloc * 2] 0.99]
do_test malloc5-3.2 {
concat \
[execsql {SELECT * FROM abc; COMMIT}] \
@@ -214,6 +233,7 @@ do_test malloc5-4.1 {
expr $nMaxBytes > 1000000
} {1}
do_test malloc5-4.2 {
+ db eval {PRAGMA cache_size=1}
db cache flush
sqlite3_release_memory
sqlite3_soft_heap_limit 100000
@@ -285,7 +305,7 @@ do_test malloc5-6.1.1 {
sqlite3 db test.db
execsql {
PRAGMA page_size=1024;
- PRAGMA default_cache_size=10;
+ PRAGMA default_cache_size=2;
}
execsql {
PRAGMA temp_store = memory;
@@ -308,24 +328,25 @@ do_test malloc5-6.1.1 {
}
forcecopy test.db test2.db
sqlite3 db2 test2.db
+ db2 eval {PRAGMA cache_size=2}
list \
[expr ([file size test.db]/1024)>20] [expr ([file size test2.db]/1024)>20]
} {1 1}
do_test malloc5-6.1.2 {
list [execsql {PRAGMA cache_size}] [execsql {PRAGMA cache_size} db2]
-} {10 10}
+} {2 2}
do_test malloc5-6.2.1 {
execsql {SELECT * FROM abc} db2
execsql {SELECT * FROM abc} db
expr [nPage db] + [nPage db2]
-} {20}
+} {4}
do_test malloc5-6.2.2 {
# If we now try to reclaim some memory, it should come from the db2 cache.
sqlite3_release_memory 3000
expr [nPage db] + [nPage db2]
-} {17}
+} {4}
do_test malloc5-6.2.3 {
# Access the db2 cache again, so that all the db2 pages have been used
# more recently than all the db pages. Then try to reclaim 3000 bytes.
@@ -333,7 +354,7 @@ do_test malloc5-6.2.3 {
execsql { SELECT * FROM abc } db2
sqlite3_release_memory 3000
expr [nPage db] + [nPage db2]
-} {17}
+} {4}
do_test malloc5-6.3.1 {
# Now open a transaction and update 2 pages in the db2 cache. Then
@@ -350,19 +371,19 @@ do_test malloc5-6.3.1 {
} db2
execsql { SELECT * FROM abc } db
expr [nPage db] + [nPage db2]
-} {20}
+} {4}
do_test malloc5-6.3.2 {
# Try to release 7700 bytes. This should release all the
# non-dirty pages held by db2.
sqlite3_release_memory [expr 7*1132]
list [nPage db] [nPage db2]
-} {10 3}
+} {1 3}
do_test malloc5-6.3.3 {
# Try to release another 1000 bytes. This should come fromt the db
# cache, since all three pages held by db2 are either in-use or diry.
sqlite3_release_memory 1000
list [nPage db] [nPage db2]
-} {9 3}
+} {1 3}
do_test malloc5-6.3.4 {
# Now release 9900 more (about 9 pages worth). This should expunge
# the rest of the db cache. But the db2 cache remains intact, because
@@ -373,23 +394,24 @@ do_test malloc5-6.3.4 {
sqlite3_release_memory 9900
}
list [nPage db] [nPage db2]
-} {0 3}
+} {1 3}
do_test malloc5-6.3.5 {
# But if we are really insistent, SQLite will consent to call sync()
# if there is no other option. UPDATE: As of 3.6.2, SQLite will not
# call sync() in this scenario. So no further memory can be reclaimed.
sqlite3_release_memory 1000
list [nPage db] [nPage db2]
-} {0 3}
+} {1 3}
do_test malloc5-6.3.6 {
# The referenced page (page 1 of the db2 cache) will not be freed no
# matter how much memory we ask for:
sqlite3_release_memory 31459
list [nPage db] [nPage db2]
-} {0 3}
+} {1 3}
db2 close
sqlite3_soft_heap_limit $::soft_limit
+test_restore_config_pagecache
finish_test
catch {db close}
« no previous file with comments | « third_party/sqlite/src/test/malloc.test ('k') | third_party/sqlite/src/test/mallocK.test » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698