1 # Copyright 1997-2016 Free Software Foundation, Inc.
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 3 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 # test running programs
20 # This test exists solely to exercise the "environment" commands for
21 # code-coverage on HP-UX.
23 if ![istarget "hppa*-*-hpux*"] then {
27 standard_testfile break.c break1.c
29 if {[prepare_for_testing "failed to prepare" $testfile \
30 [list $srcfile $srcfile2] {debug nowarnings}]} {
34 if ![runto_main] then { fail "environment command tests suppressed" }
36 # (No, this is not really related to the environment commands. But it's
37 # a convenient place to verify that this command works.)
39 send_gdb "info program\n"
41 -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 $"\
45 timeout {fail "(timeout) info program"}
48 # We don't really care where this step lands, so long as it gets
49 # the inferior pushed off the breakpoint it's currently on...
53 -re ".*$gdb_prompt $"\
54 {pass "step before info program"}
55 timeout {fail "(timeout) step before info program"}
57 send_gdb "info program\n"
59 -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 $"\
60 {pass "info program after step"}
62 {fail "info program after step"}
63 timeout {fail "(timeout) info program after step"}
66 if ![runto_main] then { fail "environment command tests suppressed" }
73 -re ".*$gdb_prompt $"\
74 {pass "delete breakpoint before info program"}
75 timeout {fail "(timeout) delete breakpoint before info program"}
79 {fail "delete breakpoint before info program"}
80 timeout {fail "(timeout) delete breakpoint before info program"}
82 send_gdb "info program\n"
84 -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 $"\
85 {pass "info program after deleted breakpoint"}
87 {fail "info program after deleted breakpoint"}
88 timeout {fail "(timeout) info program after deleted breakpoint"}
91 # Verify that we can show all currently-set environment variables.
92 # (It's a bit hacky, but nonetheless probably safe to check for at
93 # least the SHELL variable.)
95 # need to increase timeout because of very long output
96 set oldtimeout $timeout
97 set timeout [expr "$timeout + 300"]
99 send_gdb "show environment\n"
101 -re ".*SHELL=(\[a-zA-Z0-9\]*).*$gdb_prompt $"\
102 {pass "show environment"}
104 {fail "show environment"}
105 timeout {fail "(timeout) show environment"}
107 set timeout $oldtimeout
109 # Verify that we can unset a specific environment variable.
111 send_gdb "unset environment EDITOR\n"
114 {pass "issue unset environment"}
115 timeout {fail "(timeout) issue unset environment"}
117 send_gdb "show environment EDITOR\n"
119 -re "Environment variable \"EDITOR\" not defined.\r\n$gdb_prompt $"\
120 {pass "unset environment"}
122 {fail "unset environment"}
123 timeout {fail "(timeout) unset environment"}
126 # Verify that we can unset all environment variables.
128 send_gdb "unset environment\n"
130 -re "Delete all environment variables.*y or n. $"\
134 {pass "unset entire environment"}
135 timeout {fail "(timeout) unset entire environment"}
139 {fail "unset entire environment"}
140 timeout {fail "(timeout) unset entire environment"}
143 # Verify that we can set a specific environment variable.
145 send_gdb "set environment EDITOR emacs\n"
148 {pass "issue set environment"}
149 timeout {fail "(timeout) issue set environment"}
151 send_gdb "show environment EDITOR\n"
153 -re "EDITOR = emacs\r\n$gdb_prompt $"\
154 {pass "set environment"}
156 {fail "set environment"}
157 timeout {fail "(timeout) set environment"}
160 # Verify that GDB responds gracefully to a request to set environment,
161 # with no variable name.
163 send_gdb "set environment\n"
165 -re "Argument required .environment variable and value..*$gdb_prompt $"\
166 {pass "set environment without variable disallowed"}
168 {fail "set environment without variable disallowed"}
169 timeout {fail "(timeout) set environment without variable disallowed"}
172 # I'm not sure just what GDB has in mind in explicitly checking
173 # for this variant, but since GDB handles it, test it.
175 send_gdb "set environment =\n"
177 -re "Argument required .environment variable to set..*$gdb_prompt $"\
178 {pass "set environment equals without variable disallowed"}
180 {fail "set environment equals without variable disallowed"}
181 timeout {fail "(timeout) set environment equals without variable disallowed"}
184 # Setting an environment variable without a value sets it to a NULL
187 send_gdb "set environment EDITOR\n"
189 -re "Setting environment variable \"EDITOR\" to null value..*$gdb_prompt $"\
190 {pass "issue set environment without variable value"}
192 {fail "issue set environment without variable value"}
193 timeout {fail "(timeout) issue set environment without variable value"}
195 send_gdb "show environment EDITOR\n"
197 -re "EDITOR = \r\n$gdb_prompt $"\
198 {pass "set environment without variable value"}
200 {fail "set environment without variable value"}
201 timeout {fail "(timeout) set environment without variable value"}
204 # Verify that GDB responds gracefully to an attempt to show a
205 # non-existent environment variable. (We hope this variable is
208 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
210 -re "Environment variable \"FOOBARBAZGRUNGESPAZBALL\" not defined..*$gdb_prompt $"\
211 {pass "show non-existent environment variable disallowed"}
213 {fail "show non-existent environment variable disallowed"}
214 timeout {fail "(timeout) show non-existent environment variable disallowed"}
217 # Verify that GDB can set an environment variable hitherto undefined.
219 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t\n"
222 {pass "issue set environment for previously undefined variable"}
223 timeout {fail "(timeout) issue set environment for previously undefined variable"}
225 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
227 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
228 {pass "set environment for previously undefined variable"}
230 {fail "set environment for previously undefined variable"}
231 timeout {fail "(timeout) set environment for previously undefined variable"}
234 # Verify that GDB can also set an environment variable using the "="
237 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = t\n"
240 {pass "issue set environment with equals"}
241 timeout {fail "(timeout) issue set environment with equals"}
243 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
245 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
246 {pass "set environment with equals"}
248 {fail "set environment with equals"}
249 timeout {fail "(timeout) set environment with equals"}
252 # Verify that GDB can set an environment variable to a value that has
253 # an embedded (trailing, in this case) equals.
255 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t=\n"
258 {pass "issue set environment with trailing equals"}
259 timeout {fail "(timeout) issue set environment with trailing equals"}
261 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
263 -re "FOOBARBAZGRUNGESPAZBALL = t=\r\n$gdb_prompt $"\
264 {pass "set environment with trailing equals"}
266 {fail "set environment with trailing equals"}
267 timeout {fail "(timeout) set environment with trailing equals"}
270 # Verify that GDB can set an environment variable to a value preceded
271 # by whitespace, and that such whitespace is ignored (not included
274 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = foo\n"
277 {pass "issue set environment with preceding whitespace"}
278 timeout {fail "(timeout) issue set environment with preceding whitespace"}
280 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
282 -re "FOOBARBAZGRUNGESPAZBALL = foo\r\n$gdb_prompt $"\
283 {pass "set environment with preceding whitespace"}
285 {fail "set environment with preceding whitespace"}
286 timeout {fail "(timeout) set environment with preceding whitespace"}
289 # Verify that GDB can manipulate the distinguished PATH variable.
291 send_gdb "path /tmp/FOOBARBAZGRUNGESPAZBALL\n"
293 -re ".*Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
297 timeout {fail "(timeout) issue path"}
299 send_gdb "show paths\n"
301 -re "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
305 timeout {fail "(timeout) show paths"}