1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 1999,2008 Oracle.  All rights reserved.
4#
5# $Id: sdb015.tcl,v 12.10 2008/01/08 20:58:53 bostic Exp $
6#
7# TEST	sdb015
8# TEST	Tests basic in-memory named database functionality
9# TEST		Small keys, small data
10# TEST		Put/get per key
11# TEST
12# TEST	Use the first 10,000 entries from the dictionary.
13# TEST	Insert each with self as key and data; retrieve each.
14# TEST	After all are entered, retrieve all; compare output to original.
15# TEST	Close file, reopen, do retrieve and re-verify.
16# TEST	Then repeat using an environment.
17proc sdb015 { method {nentries 1000} args } {
18	global passwd
19	global has_crypto
20
21	if { [is_queueext $method] == 1 } {
22		puts "Subdb015: skipping for method $method"
23		return
24	}
25
26	# Skip test if given an env - this test needs its own.
27	set eindex [lsearch -exact $args "-env"]
28	if { $eindex != -1 } {
29		incr eindex
30		set env [lindex $args $eindex]
31		puts "Subdb015 skipping for env $env"
32		return
33	}
34
35	# In-memory dbs never go to disk, so we can't do checksumming.
36	# If the test module sent in the -chksum arg, get rid of it.
37	set chkindex [lsearch -exact $args "-chksum"]
38	if { $chkindex != -1 } {
39		set args [lreplace $args $chkindex $chkindex]
40	}
41
42	set largs $args
43	subdb015_main $method $nentries $largs
44
45	# Skip remainder of test if release does not support encryption.
46	if { $has_crypto == 0 } {
47		return
48	}
49
50	append largs " -encryptaes $passwd "
51	subdb015_main $method $nentries $largs
52}
53
54proc subdb015_main { method nentries largs } {
55	source ./include.tcl
56	global encrypt
57
58	set largs [convert_args $method $largs]
59	set omethod [convert_method $method]
60
61	env_cleanup $testdir
62
63	# Run convert_encrypt so that old_encrypt will be reset to
64	# the proper value and cleanup will work.
65	convert_encrypt $largs
66	set encargs ""
67	set largs [split_encargs $largs encargs]
68
69	set env [eval {berkdb_env -create -cachesize {0 10000000 0} \
70	    -mode 0644} -home $testdir $encargs]
71	error_check_good env_open [is_valid_env $env] TRUE
72
73	puts "Subdb015: $method ($largs) basic in-memory named db tests."
74	subdb015_body $method $omethod $nentries $largs $env
75	error_check_good env_close [$env close] 0
76}
77
78proc subdb015_body { method omethod nentries largs env } {
79	global encrypt
80	global passwd
81	source ./include.tcl
82
83	# Create the database and open the dictionary
84	set subdb subdb0
85	set db [eval {berkdb_open -create -mode 0644} $largs \
86	    {-env $env $omethod "" $subdb}]
87	error_check_good dbopen [is_valid_db $db] TRUE
88
89	set did [open $dict]
90	set pflags ""
91	set gflags ""
92	set count 0
93
94	puts "\tSubdb015.a: put/get loop"
95	# Here is the loop where we put and get each key/data pair
96	while { [gets $did str] != -1 && $count < $nentries } {
97		if { [is_record_based $method] == 1 } {
98			global kvals
99
100			set key [expr $count + 1]
101			set kvals($key) [pad_data $method $str]
102		} else {
103			set key $str
104		}
105		set ret [eval \
106		    {$db put} $pflags {$key [chop_data $method $str]}]
107		error_check_good put $ret 0
108
109		set ret [eval {$db get} $gflags {$key}]
110		error_check_good \
111		    get $ret [list [list $key [pad_data $method $str]]]
112		incr count
113	}
114	close $did
115	error_check_good db_close [$db close] 0
116}
117
118