Update years in copyright notice for the GDB files.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / environ.exp
CommitLineData
28e7fd62 1# Copyright 1997-2013 Free Software Foundation, Inc.
c906108c
SS
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c906108c 6# (at your option) any later version.
e22f8b7c 7#
c906108c
SS
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
e22f8b7c 12#
c906108c 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 15
c906108c
SS
16#
17# test running programs
18#
c906108c
SS
19
20# This test exists solely to exercise the "environment" commands for
21# code-coverage on HP-UX.
22#
23if ![istarget "hppa*-*-hpux*"] then {
24 return
25}
26
27set testfile "break"
28set srcfile ${testfile}.c
eb4bbda8 29set srcfile1 ${testfile}1.c
c906108c
SS
30set binfile ${objdir}/${subdir}/${testfile}
31
fc91c6c2 32if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
b60f0898
JB
33 untested environ.exp
34 return -1
eb4bbda8
MC
35}
36
fc91c6c2 37if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
b60f0898
JB
38 untested environ.exp
39 return -1
eb4bbda8 40}
c906108c 41
fc91c6c2 42if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
b60f0898
JB
43 untested environ.exp
44 return -1
c906108c
SS
45}
46
47gdb_exit
48gdb_start
49gdb_reinitialize_dir $srcdir/$subdir
50gdb_load ${binfile}
51
52if ![runto_main] then { fail "environment command tests suppressed" }
53
54# (No, this is not really related to the environment commands. But it's
55# a convenient place to verify that this command works.)
56#
57send_gdb "info program\n"
58gdb_expect {
59 -re ".*Using the running image of child process \[0-9\]*.\r\nProgram stopped at 0x\[0-9a-fA-F\]*.\r\nIt stopped at breakpoint 1..*$gdb_prompt $"\
60 {pass "info program"}
61 -re "$gdb_prompt $"\
62 {fail "info program"}
63 timeout {fail "(timeout) info program"}
64}
65
66# We don't really care where this step lands, so long as it gets
67# the inferior pushed off the breakpoint it's currently on...
68#
69send_gdb "next\n"
70gdb_expect {
71 -re ".*$gdb_prompt $"\
72 {pass "step before info program"}
73 timeout {fail "(timeout) step before info program"}
74}
75send_gdb "info program\n"
76gdb_expect {
77 -re ".*Using the running image of child process \[0-9\]*.\r\nProgram stopped at 0x\[0-9a-fA-F\]*.\r\nIt stopped after being stepped..*$gdb_prompt $"\
78 {pass "info program after step"}
79 -re "$gdb_prompt $"\
80 {fail "info program after step"}
81 timeout {fail "(timeout) info program after step"}
82}
83
84if ![runto_main] then { fail "environment command tests suppressed" }
85
86send_gdb "delete\n"
87gdb_expect {
88 -re ".*y or n. $"\
89 {send_gdb "y\n"
90 gdb_expect {
91 -re ".*$gdb_prompt $"\
92 {pass "delete breakpoint before info program"}
93 timeout {fail "(timeout) delete breakpoint before info program"}
94 }
95 }
96 -re "$gdb_prompt $"\
97 {fail "delete breakpoint before info program"}
98 timeout {fail "(timeout) delete breakpoint before info program"}
99}
100send_gdb "info program\n"
101gdb_expect {
102 -re ".*Using the running image of child process \[0-9\]*.\r\nProgram stopped at 0x\[0-9a-fA-F\]*.\r\nIt stopped at a breakpoint that has since been deleted..*$gdb_prompt $"\
103 {pass "info program after deleted breakpoint"}
104 -re "$gdb_prompt $"\
105 {fail "info program after deleted breakpoint"}
106 timeout {fail "(timeout) info program after deleted breakpoint"}
107}
108
109# Verify that we can show all currently-set environment variables.
110# (It's a bit hacky, but nonetheless probably safe to check for at
111# least the SHELL variable.)
112#
113# need to increase timeout because of very long output
114set oldtimeout $timeout
115set timeout [expr "$timeout + 300"]
116
117send_gdb "show environment\n"
118gdb_expect {
119 -re ".*SHELL=(\[a-zA-Z0-9\]*).*$gdb_prompt $"\
120 {pass "show environment"}
121 -re "$gdb_prompt $"\
122 {fail "show environment"}
123 timeout {fail "(timeout) show environment"}
124}
125set timeout $oldtimeout
126
127# Verify that we can unset a specific environment variable.
128#
129send_gdb "unset environment EDITOR\n"
130gdb_expect {
131 -re "$gdb_prompt $"\
132 {pass "issue unset environment"}
133 timeout {fail "(timeout) issue unset environment"}
134}
135send_gdb "show environment EDITOR\n"
136gdb_expect {
137 -re "Environment variable \"EDITOR\" not defined.\r\n$gdb_prompt $"\
138 {pass "unset environment"}
139 -re "$gdb_prompt $"\
140 {fail "unset environment"}
141 timeout {fail "(timeout) unset environment"}
142}
143
144# Verify that we can unset all environment variables.
145#
146send_gdb "unset environment\n"
147gdb_expect {
148 -re "Delete all environment variables.*y or n. $"\
149 {send_gdb "y\n"
150 gdb_expect {
151 -re "$gdb_prompt $"\
152 {pass "unset entire environment"}
153 timeout {fail "(timeout) unset entire environment"}
154 }
155 }
156 -re "$gdb_prompt $"\
157 {fail "unset entire environment"}
158 timeout {fail "(timeout) unset entire environment"}
159}
160
161# Verify that we can set a specific environment variable.
162#
163send_gdb "set environment EDITOR emacs\n"
164gdb_expect {
165 -re "$gdb_prompt $"\
166 {pass "issue set environment"}
167 timeout {fail "(timeout) issue set environment"}
168}
169send_gdb "show environment EDITOR\n"
170gdb_expect {
171 -re "EDITOR = emacs\r\n$gdb_prompt $"\
172 {pass "set environment"}
173 -re "$gdb_prompt $"\
174 {fail "set environment"}
175 timeout {fail "(timeout) set environment"}
176}
177
178# Verify that GDB responds gracefully to a request to set environment,
179# with no variable name.
180#
181send_gdb "set environment\n"
182gdb_expect {
183 -re "Argument required .environment variable and value..*$gdb_prompt $"\
184 {pass "set environment without variable disallowed"}
185 -re "$gdb_prompt $"\
186 {fail "set environment without variable disallowed"}
187 timeout {fail "(timeout) set environment without variable disallowed"}
188}
189
190# I'm not sure just what GDB has in mind in explicitly checking
191# for this variant, but since GDB handles it, test it.
192#
193send_gdb "set environment =\n"
194gdb_expect {
195 -re "Argument required .environment variable to set..*$gdb_prompt $"\
196 {pass "set environment equals without variable disallowed"}
197 -re "$gdb_prompt $"\
198 {fail "set environment equals without variable disallowed"}
199 timeout {fail "(timeout) set environment equals without variable disallowed"}
200}
201
202# Setting an environment variable without a value sets it to a NULL
203# value.
204#
205send_gdb "set environment EDITOR\n"
206gdb_expect {
207 -re "Setting environment variable \"EDITOR\" to null value..*$gdb_prompt $"\
208 {pass "issue set environment without variable value"}
209 -re "$gdb_prompt $"\
210 {fail "issue set environment without variable value"}
211 timeout {fail "(timeout) issue set environment without variable value"}
212}
213send_gdb "show environment EDITOR\n"
214gdb_expect {
215 -re "EDITOR = \r\n$gdb_prompt $"\
216 {pass "set environment without variable value"}
217 -re "$gdb_prompt $"\
218 {fail "set environment without variable value"}
219 timeout {fail "(timeout) set environment without variable value"}
220}
221
222# Verify that GDB responds gracefully to an attempt to show a
223# non-existent environment variable. (We hope this variable is
224# undefined!)
225#
226send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
227gdb_expect {
228 -re "Environment variable \"FOOBARBAZGRUNGESPAZBALL\" not defined..*$gdb_prompt $"\
229 {pass "show non-existent environment variable disallowed"}
230 -re "$gdb_prompt $"\
231 {fail "show non-existent environment variable disallowed"}
232 timeout {fail "(timeout) show non-existent environment variable disallowed"}
233}
234
235# Verify that GDB can set an environment variable hitherto undefined.
236#
237send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t\n"
238gdb_expect {
239 -re "$gdb_prompt $"\
240 {pass "issue set environment for previously undefined variable"}
241 timeout {fail "(timeout) issue set environment for previously undefined variable"}
242}
243send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
244gdb_expect {
245 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
246 {pass "set environment for previously undefined variable"}
247 -re "$gdb_prompt $"\
248 {fail "set environment for previously undefined variable"}
249 timeout {fail "(timeout) set environment for previously undefined variable"}
250}
251
252# Verify that GDB can also set an environment variable using the "="
253# syntax.
254#
255send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = t\n"
256gdb_expect {
257 -re "$gdb_prompt $"\
258 {pass "issue set environment with equals"}
259 timeout {fail "(timeout) issue set environment with equals"}
260}
261send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
262gdb_expect {
263 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
264 {pass "set environment with equals"}
265 -re "$gdb_prompt $"\
266 {fail "set environment with equals"}
267 timeout {fail "(timeout) set environment with equals"}
268}
269
270# Verify that GDB can set an environment variable to a value that has
271# an embedded (trailing, in this case) equals.
272#
273send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t=\n"
274gdb_expect {
275 -re "$gdb_prompt $"\
276 {pass "issue set environment with trailing equals"}
277 timeout {fail "(timeout) issue set environment with trailing equals"}
278}
279send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
280gdb_expect {
281 -re "FOOBARBAZGRUNGESPAZBALL = t=\r\n$gdb_prompt $"\
282 {pass "set environment with trailing equals"}
283 -re "$gdb_prompt $"\
284 {fail "set environment with trailing equals"}
285 timeout {fail "(timeout) set environment with trailing equals"}
286}
287
288# Verify that GDB can set an environment variable to a value preceded
289# by whitespace, and that such whitespace is ignored (not included
290# in the set value).
291#
292send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = foo\n"
293gdb_expect {
294 -re "$gdb_prompt $"\
295 {pass "issue set environment with preceding whitespace"}
296 timeout {fail "(timeout) issue set environment with preceding whitespace"}
297}
298send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
299gdb_expect {
300 -re "FOOBARBAZGRUNGESPAZBALL = foo\r\n$gdb_prompt $"\
301 {pass "set environment with preceding whitespace"}
302 -re "$gdb_prompt $"\
303 {fail "set environment with preceding whitespace"}
304 timeout {fail "(timeout) set environment with preceding whitespace"}
305}
306
307# Verify that GDB can manipulate the distinguished PATH variable.
308#
309send_gdb "path /tmp/FOOBARBAZGRUNGESPAZBALL\n"
310gdb_expect {
311 -re ".*Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
312 {pass "issue path"}
313 -re "$gdb_prompt $"\
314 {fail "issue path"}
315 timeout {fail "(timeout) issue path"}
316}
317send_gdb "show paths\n"
318gdb_expect {
319 -re "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
320 {pass "show paths"}
321 -re "$gdb_prompt $"\
322 {fail "show paths"}
323 timeout {fail "(timeout) show paths"}
324}
325
326gdb_exit
327return 0
This page took 1.522526 seconds and 4 git commands to generate.