1# Sel the file LICENSE for redistribution information.
2#
3# Copyright (c) 1999,2008 Oracle.  All rights reserved.
4#
5# $Id: rpc002.tcl,v 12.10 2008/01/08 20:58:53 bostic Exp $
6#
7# TEST	rpc002
8# TEST	Test invalid RPC functions and make sure we error them correctly
9# TEST	Test server home directory error cases
10proc rpc002 { } {
11	global __debug_on
12	global __debug_print
13	global errorInfo
14	global rpc_svc
15	source ./include.tcl
16
17	set testfile "rpc002.db"
18	set home [file tail $rpc_testdir]
19	#
20	# First start the server.
21	#
22	puts "Rpc002: Error and Unsupported interface test"
23	puts "Rpc002: Using $rpc_svc"
24	set dpid [rpc_server_start]
25	puts "\tRpc002.a: Started server, pid $dpid"
26
27	#
28	# Wrap the whole test in a catch statement so we can still
29	# kill the rpc server even if the test fails.
30	#
31	set status [catch {
32		tclsleep 2
33		remote_cleanup $rpc_server $rpc_testdir $testdir
34
35		puts "\tRpc002.b: Unsupported env options"
36		#
37		# Test each "pre-open" option for env's.  These need to be
38		# tested on the 'berkdb_env' line.
39		#
40		set rlist {
41		{ "-data_dir $rpc_testdir"	"Rpc002.b0"}
42		{ "-log_buffer 512"		"Rpc002.b1"}
43		{ "-log_dir $rpc_testdir"	"Rpc002.b2"}
44		{ "-log_max 100"		"Rpc002.b3"}
45		{ "-lock_conflict {3 {0 0 0 0 0 1 0 1 1}}"	"Rpc002.b4"}
46		{ "-lock_detect default"	"Rpc002.b5"}
47		{ "-lock_max_locks 100"		"Rpc002.b6"}
48		{ "-lock_max_objects 100"	"Rpc002.b6"}
49		{ "-lock_max_lockers 100"	"Rpc002.b6"}
50		{ "-mpool_mmap_size 100"	"Rpc002.b7"}
51		{ "-shm_key 100"		"Rpc002.b9"}
52		{ "-tmp_dir $rpc_testdir"	"Rpc002.b10"}
53		{ "-txn_max 100"		"Rpc002.b11"}
54		{ "-txn_timestamp 100"		"Rpc002.b12"}
55		{ "-verbose {recovery on}"		"Rpc002.b13"}
56		}
57
58		set e "berkdb_env_noerr -create -mode 0644 -home $home \
59		    -server $rpc_server -client_timeout 10000 -txn"
60
61		foreach pair $rlist {
62			set cmd [lindex $pair 0]
63			set msg [lindex $pair 1]
64			puts "\t$msg: $cmd"
65
66			set stat [catch {eval $e $cmd} ret]
67			error_check_good $cmd $stat 1
68			error_check_good $cmd.err [is_substr $errorInfo \
69			    "Interface not supported by Berkeley DB RPC"] 1
70		}
71
72		#
73		# Open an env with all the subsystems (-txn implies all
74		# the rest)
75		#
76		puts "\tRpc002.c: Unsupported env related interfaces"
77		set env [eval {berkdb_env_noerr -create -mode 0644 -home $home \
78		    -server $rpc_server -client_timeout 10000 -txn}]
79		error_check_good envopen [is_valid_env $env] TRUE
80		set dbcmd "berkdb_open_noerr -create -btree -mode 0644 \
81		    -env $env $testfile"
82		set db [eval $dbcmd]
83		error_check_good dbopen [is_valid_db $db] TRUE
84
85		#
86		# Test each "post-open" option relating to envs, txns, locks,
87		# logs and mpools.
88		#
89		set rlist {
90		{ " lock_detect default"	"Rpc002.c0"}
91		{ " lock_get read 1 $env"	"Rpc002.c1"}
92		{ " lock_id"			"Rpc002.c2"}
93		{ " lock_stat"			"Rpc002.c3"}
94		{ " lock_vec 1 {get $env read}"	"Rpc002.c4"}
95		{ " log_archive"		"Rpc002.c5"}
96		{ " log_file {0 0}"		"Rpc002.c6"}
97		{ " log_flush"			"Rpc002.c7"}
98		{ " log_cursor"			"Rpc002.c8"}
99		{ " log_stat"			"Rpc002.c9"}
100		{ " mpool -create -pagesize 512"	"Rpc002.c10"}
101		{ " mpool_stat"			"Rpc002.c11"}
102		{ " mpool_sync {0 0}"		"Rpc002.c12"}
103		{ " mpool_trickle 50"		"Rpc002.c13"}
104		{ " txn_checkpoint -min 1"	"Rpc002.c14"}
105		{ " txn_stat"			"Rpc002.c15"}
106		}
107
108		foreach pair $rlist {
109			set cmd [lindex $pair 0]
110			set msg [lindex $pair 1]
111			puts "\t$msg: $cmd"
112
113			set stat [catch {eval $env $cmd} ret]
114			error_check_good $cmd $stat 1
115			error_check_good $cmd.err [is_substr $errorInfo \
116			    "Interface not supported by Berkeley DB RPC"] 1
117		}
118		error_check_good dbclose [$db close] 0
119
120		#
121		# The database operations that aren't supported are few
122		# because mostly they are the ones Tcl doesn't support
123		# either so we have no way to get at them.  Test what we can.
124		#
125		puts "\tRpc002.d: Unsupported database related interfaces"
126		#
127		# NOTE: the type of database doesn't matter, just use btree.
128		#
129		puts "\tRpc002.d0: -cachesize"
130		set dbcmd "berkdb_open_noerr -create -btree -mode 0644 \
131		    -env $env -cachesize {0 65536 0} $testfile"
132		set stat [catch {eval $dbcmd} ret]
133		error_check_good dbopen_cache $stat 1
134		error_check_good dbopen_cache_err [is_substr $errorInfo \
135		    "Interface not supported by Berkeley DB RPC"] 1
136
137		puts "\tRpc002.d1: Try to upgrade a database"
138		set stat [catch {eval {berkdb upgrade -env} $env $testfile} ret]
139		error_check_good dbupgrade $stat 1
140		error_check_good dbupgrade_err [is_substr $errorInfo \
141		    "Interface not supported by Berkeley DB RPC"] 1
142		error_check_good envclose [$env close] 0
143
144		puts "\tRpc002.e: Open env with unsupported home dir"
145		set stat [catch {eval {berkdb_env_noerr -create -mode 0644 \
146		    -home XXX -server $rpc_server -client_timeout 10000 \
147		    -txn}} ret]
148		error_check_good env2open $stat 1
149		error_check_good envfail [is_substr $ret "Home unrecognized"] 1
150
151		puts "\tRpc002.f: Open env with a NULL home dir"
152		set stat [catch {eval {berkdb_env_noerr -create -mode 0644 \
153		    -server $rpc_server -client_timeout 10000 -txn}} ret]
154		error_check_good env2open $stat 1
155		error_check_good envfail [is_substr $ret "Home unrecognized"] 1
156	} res]
157	if { $status != 0 } {
158		puts $res
159	}
160	tclkill $dpid
161}
162