summaryrefslogtreecommitdiff
path: root/db-4.8.30/test/memp004.tcl
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2016-12-17 21:28:53 -0800
committerJesse Morgan <jesse@jesterpm.net>2016-12-17 21:28:53 -0800
commit54df2afaa61c6a03cbb4a33c9b90fa572b6d07b8 (patch)
tree18147b92b969d25ffbe61935fb63035cac820dd0 /db-4.8.30/test/memp004.tcl
Berkeley DB 4.8 with rust build script for linux.
Diffstat (limited to 'db-4.8.30/test/memp004.tcl')
-rw-r--r--db-4.8.30/test/memp004.tcl82
1 files changed, 82 insertions, 0 deletions
diff --git a/db-4.8.30/test/memp004.tcl b/db-4.8.30/test/memp004.tcl
new file mode 100644
index 0000000..d8e16cb
--- /dev/null
+++ b/db-4.8.30/test/memp004.tcl
@@ -0,0 +1,82 @@
+# See the file LICENSE for redistribution information.
+#
+# Copyright (c) 1996-2009 Oracle. All rights reserved.
+#
+# $Id$
+#
+
+# TEST memp004
+# TEST Test that small read-only databases are mapped into memory.
+proc memp004 { } {
+ global is_qnx_test
+ source ./include.tcl
+
+ puts "Memp004: Test of memory-mapped read-only databases"
+
+ if { $is_qnx_test } {
+ puts "Memp004: skipping for QNX"
+ return
+ }
+
+ env_cleanup $testdir
+ set testfile memp004.db
+
+ # Create an environment.
+ puts "memp004.a: Create an environment and database"
+ set dbenv [eval {berkdb_env -create -home $testdir -private}]
+ error_check_good dbenv [is_valid_env $dbenv] TRUE
+ set db [berkdb_open -env $dbenv -create -mode 0644 -btree $testfile]
+ error_check_good dbopen/$testfile/RW [is_valid_db $db] TRUE
+
+ # Put each key/data pair.
+ set did [open $dict]
+ set keys ""
+ set count 0
+ while { [gets $did str] != -1 && $count < 1000 } {
+ lappend keys $str
+
+ set ret [eval {$db put} {$str $str}]
+ error_check_good put $ret 0
+
+ incr count
+ }
+ close $did
+ error_check_good close [$db close] 0
+
+ # Discard the environment.
+ error_check_good close [$dbenv close] 0
+
+ puts "memp004.b: Re-create the environment and open database read-only"
+ set dbenv [eval {berkdb_env -create -home $testdir}]
+ error_check_good dbenv [is_valid_env $dbenv] TRUE
+ set db [berkdb_open -env $dbenv -rdonly $testfile]
+ error_check_good dbopen/$testfile/RO [is_substr $db db] 1
+
+ # Read a couple of keys.
+ set c [eval {$db cursor}]
+ for { set i 0 } { $i < 500 } { incr i } {
+ set ret [$c get -next]
+ }
+
+ puts "memp004.c: Check mpool statistics"
+ set tmp [memp004_stat $dbenv "Pages mapped into address space"]
+ error_check_good "mmap check: $tmp >= 500" [expr $tmp >= 500] 1
+
+ error_check_good db_close [$db close] 0
+ reset_env $dbenv
+}
+
+# memp004_stat --
+# Return the current mpool statistics.
+proc memp004_stat { env s } {
+ set stat [$env mpool_stat]
+ foreach statpair $stat {
+ set statmsg [lindex $statpair 0]
+ set statval [lindex $statpair 1]
+ if {[is_substr $statmsg $s] != 0} {
+ return $statval
+ }
+ }
+ puts "FAIL: memp004: stat string $s not found"
+ return 0
+}