Commit | Line | Data |
---|---|---|
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 | # | |
23 | if ![istarget "hppa*-*-hpux*"] then { | |
24 | return | |
25 | } | |
26 | ||
27 | set testfile "break" | |
28 | set srcfile ${testfile}.c | |
eb4bbda8 | 29 | set srcfile1 ${testfile}1.c |
c906108c SS |
30 | set binfile ${objdir}/${subdir}/${testfile} |
31 | ||
fc91c6c2 | 32 | if { [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 | 37 | if { [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 | 42 | if { [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 | ||
47 | gdb_exit | |
48 | gdb_start | |
49 | gdb_reinitialize_dir $srcdir/$subdir | |
50 | gdb_load ${binfile} | |
51 | ||
52 | if ![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 | # | |
57 | send_gdb "info program\n" | |
58 | gdb_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 | # | |
69 | send_gdb "next\n" | |
70 | gdb_expect { | |
71 | -re ".*$gdb_prompt $"\ | |
72 | {pass "step before info program"} | |
73 | timeout {fail "(timeout) step before info program"} | |
74 | } | |
75 | send_gdb "info program\n" | |
76 | gdb_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 | ||
84 | if ![runto_main] then { fail "environment command tests suppressed" } | |
85 | ||
86 | send_gdb "delete\n" | |
87 | gdb_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 | } | |
100 | send_gdb "info program\n" | |
101 | gdb_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 | |
114 | set oldtimeout $timeout | |
115 | set timeout [expr "$timeout + 300"] | |
116 | ||
117 | send_gdb "show environment\n" | |
118 | gdb_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 | } | |
125 | set timeout $oldtimeout | |
126 | ||
127 | # Verify that we can unset a specific environment variable. | |
128 | # | |
129 | send_gdb "unset environment EDITOR\n" | |
130 | gdb_expect { | |
131 | -re "$gdb_prompt $"\ | |
132 | {pass "issue unset environment"} | |
133 | timeout {fail "(timeout) issue unset environment"} | |
134 | } | |
135 | send_gdb "show environment EDITOR\n" | |
136 | gdb_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 | # | |
146 | send_gdb "unset environment\n" | |
147 | gdb_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 | # | |
163 | send_gdb "set environment EDITOR emacs\n" | |
164 | gdb_expect { | |
165 | -re "$gdb_prompt $"\ | |
166 | {pass "issue set environment"} | |
167 | timeout {fail "(timeout) issue set environment"} | |
168 | } | |
169 | send_gdb "show environment EDITOR\n" | |
170 | gdb_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 | # | |
181 | send_gdb "set environment\n" | |
182 | gdb_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 | # | |
193 | send_gdb "set environment =\n" | |
194 | gdb_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 | # | |
205 | send_gdb "set environment EDITOR\n" | |
206 | gdb_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 | } | |
213 | send_gdb "show environment EDITOR\n" | |
214 | gdb_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 | # | |
226 | send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n" | |
227 | gdb_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 | # | |
237 | send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t\n" | |
238 | gdb_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 | } | |
243 | send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n" | |
244 | gdb_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 | # | |
255 | send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = t\n" | |
256 | gdb_expect { | |
257 | -re "$gdb_prompt $"\ | |
258 | {pass "issue set environment with equals"} | |
259 | timeout {fail "(timeout) issue set environment with equals"} | |
260 | } | |
261 | send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n" | |
262 | gdb_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 | # | |
273 | send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t=\n" | |
274 | gdb_expect { | |
275 | -re "$gdb_prompt $"\ | |
276 | {pass "issue set environment with trailing equals"} | |
277 | timeout {fail "(timeout) issue set environment with trailing equals"} | |
278 | } | |
279 | send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n" | |
280 | gdb_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 | # | |
292 | send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = foo\n" | |
293 | gdb_expect { | |
294 | -re "$gdb_prompt $"\ | |
295 | {pass "issue set environment with preceding whitespace"} | |
296 | timeout {fail "(timeout) issue set environment with preceding whitespace"} | |
297 | } | |
298 | send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n" | |
299 | gdb_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 | # | |
309 | send_gdb "path /tmp/FOOBARBAZGRUNGESPAZBALL\n" | |
310 | gdb_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 | } | |
317 | send_gdb "show paths\n" | |
318 | gdb_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 | ||
326 | gdb_exit | |
327 | return 0 |