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