1
# See the file LICENSE for redistribution information.
3
# Copyright (c) 1999-2002
4
# Sleepycat Software. All rights reserved.
9
# TEST Test of DB_LOG_DIR and env name resolution.
10
# TEST With an environment path specified using -home, and then again
11
# TEST with it specified by the environment variable DB_HOME:
12
# TEST 1) Make sure that the set_lg_dir option is respected
13
# TEST a) as a relative pathname.
14
# TEST b) as an absolute pathname.
15
# TEST 2) Make sure that the DB_LOG_DIR db_config argument is respected,
16
# TEST again as relative and absolute pathnames.
17
# TEST 3) Make sure that if -both- db_config and a file are present,
18
# TEST only the file is respected (see doc/env/naming.html).
20
# env002 is essentially just a small driver that runs
21
# env002_body--formerly the entire test--twice; once, it
22
# supplies a "home" argument to use with environment opens,
23
# and the second time it sets DB_HOME instead.
24
# Note that env002_body itself calls env002_run_test to run
25
# the body of the actual test and check for the presence
26
# of logs. The nesting, I hope, makes this test's structure simpler.
31
puts "Env002: set_lg_dir test."
33
puts "\tEnv002: Running with -home argument to berkdb_env."
34
env002_body "-home $testdir"
36
puts "\tEnv002: Running with environment variable DB_HOME set."
37
set env(DB_HOME) $testdir
38
env002_body "-use_environ"
42
puts "\tEnv002: Running with both DB_HOME and -home set."
43
# Should respect -only- -home, so we give it a bogus
44
# environment variable setting.
45
set env(DB_HOME) $testdir/bogus_home
46
env002_body "-use_environ -home $testdir"
51
proc env002_body { home_arg } {
55
set logdir "logs_in_here"
57
file mkdir $testdir/$logdir
59
# Set up full path to $logdir for when we test absolute paths.
65
env002_make_config $logdir
67
# Run the meat of the test.
68
env002_run_test a 1 "relative path, config file" $home_arg \
73
file mkdir $fulllogdir
74
env002_make_config $fulllogdir
77
env002_run_test a 2 "absolute path, config file" $home_arg \
82
# Now we try without a config file, but instead with db_config
84
file mkdir $testdir/$logdir
85
env002_run_test b 1 "relative path, db_config" "$home_arg \
86
-log_dir $logdir -data_dir ." \
92
file mkdir $fulllogdir
93
env002_run_test b 2 "absolute path, db_config" "$home_arg \
94
-log_dir $fulllogdir -data_dir ." \
99
# Now, set db_config -and- have a # DB_CONFIG file, and make
100
# sure only the latter is honored.
102
file mkdir $testdir/$logdir
103
env002_make_config $logdir
105
# note that we supply a -nonexistent- log dir to db_config
106
env002_run_test c 1 "relative path, both db_config and file" \
107
"$home_arg -log_dir $testdir/bogus \
108
-data_dir ." $testdir/$logdir
111
file mkdir $fulllogdir
112
env002_make_config $fulllogdir
114
# note that we supply a -nonexistent- log dir to db_config
115
env002_run_test c 2 "relative path, both db_config and file" \
116
"$home_arg -log_dir $fulllogdir/bogus \
117
-data_dir ." $fulllogdir
120
proc env002_run_test { major minor msg env_args log_path} {
122
set testfile "env002.db"
124
puts "\t\tEnv002.$major.$minor: $msg"
126
# Create an environment, with logging, and scribble some
127
# stuff in a [btree] database in it.
128
# puts [concat {berkdb_env -create -log -private} $env_args]
129
set dbenv [eval {berkdb_env -create -log -private} $env_args]
130
error_check_good env_open [is_valid_env $dbenv] TRUE
131
set db [berkdb_open -env $dbenv -create -btree -mode 0644 $testfile]
132
error_check_good db_open [is_valid_db $db] TRUE
137
error_check_good db_put \
138
[$db put $key [chop_data btree $data]] 0
140
error_check_good db_close [$db close] 0
141
error_check_good env_close [$dbenv close] 0
143
# Now make sure the log file is where we want it to be.
144
error_check_good db_exists [file exists $testdir/$testfile] 1
145
error_check_good log_exists \
146
[file exists $log_path/log.0000000001] 1
149
proc env002_make_config { logdir } {
152
set cid [open $testdir/DB_CONFIG w]
153
puts $cid "set_data_dir ."
154
puts $cid "set_lg_dir $logdir"