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 $testfile.exp $testfile \
30 [list $srcfile $srcfile2] {debug nowarnings}]} {
31 untested $testfile.exp
35 if ![runto_main] then { fail "environment command tests suppressed" }
37 # (No, this is not really related to the environment commands. But it's
38 # a convenient place to verify that this command works.)
40 send_gdb "info program\n"
42 -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 $"\
46 timeout {fail "(timeout) info program"}
49 # We don't really care where this step lands, so long as it gets
50 # the inferior pushed off the breakpoint it's currently on...
54 -re ".*$gdb_prompt $"\
55 {pass "step before info program"}
56 timeout {fail "(timeout) step before info program"}
58 send_gdb "info program\n"
60 -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 $"\
61 {pass "info program after step"}
63 {fail "info program after step"}
64 timeout {fail "(timeout) info program after step"}
67 if ![runto_main] then { fail "environment command tests suppressed" }
74 -re ".*$gdb_prompt $"\
75 {pass "delete breakpoint before info program"}
76 timeout {fail "(timeout) delete breakpoint before info program"}
80 {fail "delete breakpoint before info program"}
81 timeout {fail "(timeout) delete breakpoint before info program"}
83 send_gdb "info program\n"
85 -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 $"\
86 {pass "info program after deleted breakpoint"}
88 {fail "info program after deleted breakpoint"}
89 timeout {fail "(timeout) info program after deleted breakpoint"}
92 # Verify that we can show all currently-set environment variables.
93 # (It's a bit hacky, but nonetheless probably safe to check for at
94 # least the SHELL variable.)
96 # need to increase timeout because of very long output
97 set oldtimeout $timeout
98 set timeout [expr "$timeout + 300"]
100 send_gdb "show environment\n"
102 -re ".*SHELL=(\[a-zA-Z0-9\]*).*$gdb_prompt $"\
103 {pass "show environment"}
105 {fail "show environment"}
106 timeout {fail "(timeout) show environment"}
108 set timeout $oldtimeout
110 # Verify that we can unset a specific environment variable.
112 send_gdb "unset environment EDITOR\n"
115 {pass "issue unset environment"}
116 timeout {fail "(timeout) issue unset environment"}
118 send_gdb "show environment EDITOR\n"
120 -re "Environment variable \"EDITOR\" not defined.\r\n$gdb_prompt $"\
121 {pass "unset environment"}
123 {fail "unset environment"}
124 timeout {fail "(timeout) unset environment"}
127 # Verify that we can unset all environment variables.
129 send_gdb "unset environment\n"
131 -re "Delete all environment variables.*y or n. $"\
135 {pass "unset entire environment"}
136 timeout {fail "(timeout) unset entire environment"}
140 {fail "unset entire environment"}
141 timeout {fail "(timeout) unset entire environment"}
144 # Verify that we can set a specific environment variable.
146 send_gdb "set environment EDITOR emacs\n"
149 {pass "issue set environment"}
150 timeout {fail "(timeout) issue set environment"}
152 send_gdb "show environment EDITOR\n"
154 -re "EDITOR = emacs\r\n$gdb_prompt $"\
155 {pass "set environment"}
157 {fail "set environment"}
158 timeout {fail "(timeout) set environment"}
161 # Verify that GDB responds gracefully to a request to set environment,
162 # with no variable name.
164 send_gdb "set environment\n"
166 -re "Argument required .environment variable and value..*$gdb_prompt $"\
167 {pass "set environment without variable disallowed"}
169 {fail "set environment without variable disallowed"}
170 timeout {fail "(timeout) set environment without variable disallowed"}
173 # I'm not sure just what GDB has in mind in explicitly checking
174 # for this variant, but since GDB handles it, test it.
176 send_gdb "set environment =\n"
178 -re "Argument required .environment variable to set..*$gdb_prompt $"\
179 {pass "set environment equals without variable disallowed"}
181 {fail "set environment equals without variable disallowed"}
182 timeout {fail "(timeout) set environment equals without variable disallowed"}
185 # Setting an environment variable without a value sets it to a NULL
188 send_gdb "set environment EDITOR\n"
190 -re "Setting environment variable \"EDITOR\" to null value..*$gdb_prompt $"\
191 {pass "issue set environment without variable value"}
193 {fail "issue set environment without variable value"}
194 timeout {fail "(timeout) issue set environment without variable value"}
196 send_gdb "show environment EDITOR\n"
198 -re "EDITOR = \r\n$gdb_prompt $"\
199 {pass "set environment without variable value"}
201 {fail "set environment without variable value"}
202 timeout {fail "(timeout) set environment without variable value"}
205 # Verify that GDB responds gracefully to an attempt to show a
206 # non-existent environment variable. (We hope this variable is
209 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
211 -re "Environment variable \"FOOBARBAZGRUNGESPAZBALL\" not defined..*$gdb_prompt $"\
212 {pass "show non-existent environment variable disallowed"}
214 {fail "show non-existent environment variable disallowed"}
215 timeout {fail "(timeout) show non-existent environment variable disallowed"}
218 # Verify that GDB can set an environment variable hitherto undefined.
220 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t\n"
223 {pass "issue set environment for previously undefined variable"}
224 timeout {fail "(timeout) issue set environment for previously undefined variable"}
226 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
228 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
229 {pass "set environment for previously undefined variable"}
231 {fail "set environment for previously undefined variable"}
232 timeout {fail "(timeout) set environment for previously undefined variable"}
235 # Verify that GDB can also set an environment variable using the "="
238 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = t\n"
241 {pass "issue set environment with equals"}
242 timeout {fail "(timeout) issue set environment with equals"}
244 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
246 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
247 {pass "set environment with equals"}
249 {fail "set environment with equals"}
250 timeout {fail "(timeout) set environment with equals"}
253 # Verify that GDB can set an environment variable to a value that has
254 # an embedded (trailing, in this case) equals.
256 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t=\n"
259 {pass "issue set environment with trailing equals"}
260 timeout {fail "(timeout) issue set environment with trailing equals"}
262 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
264 -re "FOOBARBAZGRUNGESPAZBALL = t=\r\n$gdb_prompt $"\
265 {pass "set environment with trailing equals"}
267 {fail "set environment with trailing equals"}
268 timeout {fail "(timeout) set environment with trailing equals"}
271 # Verify that GDB can set an environment variable to a value preceded
272 # by whitespace, and that such whitespace is ignored (not included
275 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = foo\n"
278 {pass "issue set environment with preceding whitespace"}
279 timeout {fail "(timeout) issue set environment with preceding whitespace"}
281 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
283 -re "FOOBARBAZGRUNGESPAZBALL = foo\r\n$gdb_prompt $"\
284 {pass "set environment with preceding whitespace"}
286 {fail "set environment with preceding whitespace"}
287 timeout {fail "(timeout) set environment with preceding whitespace"}
290 # Verify that GDB can manipulate the distinguished PATH variable.
292 send_gdb "path /tmp/FOOBARBAZGRUNGESPAZBALL\n"
294 -re ".*Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
298 timeout {fail "(timeout) issue path"}
300 send_gdb "show paths\n"
302 -re "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
306 timeout {fail "(timeout) show paths"}