aboutsummaryrefslogtreecommitdiff
path: root/src/lib/kadm5/unit-test/config/unix.exp
blob: a78515f915bc8e0b8a87cdb407f76e54b9558473 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
set prompt "% "
set stty_init {-onlcr -opost intr \^C kill \^U}
set kadmin_local $KADMIN_LOCAL

# Backward compatibility until we're using expect 5 everywhere
if {[info exists exp_version_4]} {
	global wait_error_index wait_errno_index wait_status_index
	set wait_error_index 0
	set wait_errno_index 1
	set wait_status_index 1
} else {
	set wait_error_index 2
	set wait_errno_index 3
	set wait_status_index 3
}

# Hack around Solaris 9 kernel race condition that causes last output
# from a pty to get dropped.
if { $PRIOCNTL_HACK } {
    catch {exec priocntl -s -c FX -m 30 -p 30 -i pid [getpid]}
    rename spawn oldspawn
    proc spawn { args } {
	upvar 1 spawn_id spawn_id
	set newargs {}
	set inflags 1
	set eatnext 0
	foreach arg $args {
	    if { $arg == "-ignore" \
		     || $arg == "-open" \
		     || $arg == "-leaveopen" } {
		lappend newargs $arg
		set eatnext 1
		continue
	    }
	    if [string match "-*" $arg] {
		lappend newargs $arg
		continue
	    }
	    if { $eatnext } {
		set eatnext 0
		lappend newargs $arg
		continue
	    }
	    if { $inflags } {
		set inflags 0
		set newargs [concat $newargs {priocntl -e -c FX -p 0}]
	    }
	    lappend newargs $arg
	}
	set pid [eval oldspawn $newargs]
	return $pid
    }
}

# Variables for keeping track of api process state
set api_pid "0"

proc api_exit {} {
	global spawn_id
        global api_pid

#	puts stdout "Starting api_exit (spawn_id $spawn_id)."
	catch {close} errMsg
        catch {wait} errMsg
#       puts stdout "Finishing api_exit for $api_pid."
        set api_pid "0"
}

proc api_isrunning {pid} {
        global api_pid
    
#        puts stdout "testing $pid, api_pid is $api_pid"
        if {$pid == $api_pid} {
	    return 1;
	} else {
	    return 0;
	}
}

proc api_version {} {
}

proc api_start {} {
	global API 
	global env
	global spawn_id
	global prompt
        global api_pid

	set pid [spawn $API]
	expect {
		-re "$prompt$" {}
		eof { error "EOF starting API" }
		timeout { error "Timeout starting API" }
	}
	if {! [info exists env(TCLUTIL)]} {
		error "TCLUTIL environment variable isn't set"
	}
	# tcl 8.4 for some reason screws up autodetection of output
	# EOL translation.  Work around it for now.
	send "if { \[info commands fconfigure\] ne \"\" } { fconfigure stdout -translation lf }\n"
	expect {
		-re "$prompt$" {}
		eof { error "EOF starting API" }
		timeout { error "Timeout starting API" }
	}
	send "source $env(TCLUTIL)\n"
	expect {
		-re "$prompt$" {}
		eof { error "EOF starting API" }
		timeout { error "Timeout starting API" }
	}
	send "set current_struct_version \[expr \$OVSEC_KADM_STRUCT_VERSION &~ \$OVSEC_KADM_STRUCT_VERSION_MASK\]\n"
	expect {
		-re "$prompt$" {}
		eof { error "EOF setting API varibles"}
		timeout { error "timeout setting API varibles"}
	}
	send "set current_api_version \[expr \$OVSEC_KADM_API_VERSION_1 &~ \$OVSEC_KADM_API_VERSION_MASK\]\n"
	expect {
		-re "$prompt$" {}
		eof { error "EOF setting API varibles"}
		timeout { error "timeout setting API varibles"}
	}
	send "set bad_struct_version_mask \[expr 0x65432100 | \$current_struct_version\]\n"
	expect {
		-re "$prompt$" {}
		eof { error "EOF setting API varibles"}
		timeout { error "timeout setting API varibles"}
	}
	send "set bad_api_version_mask \[expr 0x65432100 | \$current_api_version\]\n"
	expect {
		-re "$prompt$" {}
		eof { error "EOF setting API varibles"}
		timeout { error "timeout setting API varibles"}
	}
	send "set no_api_version_mask \$current_api_version\n"
	expect {
		-re "$prompt$" {}
		eof { error "EOF setting API varibles"}
		timeout { error "timeout setting API varibles"}
	}
	send "set no_struct_version_mask \$current_struct_version\n"
	expect {
		-re "$prompt$" {}
		eof { error "EOF setting API varibles"}
		timeout { error "timeout setting API varibles"}
	}
	send "set old_api_version \[expr \$OVSEC_KADM_API_VERSION_MASK | 0x00\]\n"
	expect {
		-re "$prompt$" {}
		eof { error "EOF setting API varibles"}
		timeout { error "timeout setting API varibles"}
	}
	send "set old_struct_version \[expr \$OVSEC_KADM_STRUCT_VERSION_MASK | 0x00\]\n"
	expect {
		-re "$prompt$" {}
		eof { error "EOF setting API varibles"}
		timeout { error "timeout setting API varibles"}
	}
	send "set new_api_version \[expr \$OVSEC_KADM_API_VERSION_MASK | 0xca\]\n"
	expect {
		-re "$prompt$" {}
		eof { error "EOF setting API varibles"}
		timeout { error "timeout setting API varibles"}
	}
	send "set new_struct_version \[expr \$OVSEC_KADM_STRUCT_VERSION_MASK | 0xca\]\n"
	expect {
		-re "$prompt$" {}
		eof { error "EOF setting API varibles"}
		timeout { error "timeout setting API varibles"}
	}

	set api_pid $pid
#	puts stdout "Finishing api_start (spawn_id $spawn_id, pid $api_pid)."
	return $pid
}
api_start