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