1f8848ae35e7637f75def977d39801df05348fcd
[platform/upstream/gdb.git] / gdb / testsuite / gdb.base / environ.exp
1 # Copyright 1997-2015 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 3 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, see <http://www.gnu.org/licenses/>.  */
15
16 #
17 # test running programs
18 #
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 standard_testfile break.c break1.c
28
29 if {[prepare_for_testing $testfile.exp $testfile \
30          [list $srcfile $srcfile2] {debug nowarnings}]} {
31     untested $testfile.exp
32     return -1
33 }
34
35 if ![runto_main] then { fail "environment command tests suppressed" }
36
37 # (No, this is not really related to the environment commands.  But it's
38 # a convenient place to verify that this command works.)
39 #
40 send_gdb "info program\n"
41 gdb_expect {
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 $"\
43           {pass "info program"}
44   -re "$gdb_prompt $"\
45           {fail "info program"}
46   timeout {fail "(timeout) info program"}
47 }
48
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...
51 #
52 send_gdb "next\n"
53 gdb_expect {
54   -re ".*$gdb_prompt $"\
55           {pass "step before info program"}
56   timeout {fail "(timeout) step before info program"}
57 }
58 send_gdb "info program\n"
59 gdb_expect {
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"}
62   -re "$gdb_prompt $"\
63           {fail "info program after step"}
64   timeout {fail "(timeout) info program after step"}
65 }
66
67 if ![runto_main] then { fail "environment command tests suppressed" }
68
69 send_gdb "delete\n"
70 gdb_expect {
71   -re ".*y or n. $"\
72           {send_gdb "y\n"
73            gdb_expect {
74              -re ".*$gdb_prompt $"\
75                      {pass "delete breakpoint before info program"}
76              timeout {fail "(timeout) delete breakpoint before info program"}
77            }
78           }
79   -re "$gdb_prompt $"\
80           {fail "delete breakpoint before info program"}
81   timeout {fail "(timeout) delete breakpoint before info program"}
82 }
83 send_gdb "info program\n"
84 gdb_expect {
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"}
87   -re "$gdb_prompt $"\
88           {fail "info program after deleted breakpoint"}
89   timeout {fail "(timeout) info program after deleted breakpoint"}
90 }
91
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.)
95 #
96 # need to increase timeout because of very long output
97 set oldtimeout $timeout
98 set timeout [expr "$timeout + 300"]
99
100 send_gdb "show environment\n"
101 gdb_expect {
102   -re ".*SHELL=(\[a-zA-Z0-9\]*).*$gdb_prompt $"\
103           {pass "show environment"}
104   -re "$gdb_prompt $"\
105           {fail "show environment"}
106   timeout {fail "(timeout) show environment"}
107 }
108 set timeout $oldtimeout
109
110 # Verify that we can unset a specific environment variable.
111 #
112 send_gdb "unset environment EDITOR\n"
113 gdb_expect {
114   -re "$gdb_prompt $"\
115           {pass "issue unset environment"}
116   timeout {fail "(timeout) issue unset environment"}
117 }
118 send_gdb "show environment EDITOR\n"
119 gdb_expect {
120   -re "Environment variable \"EDITOR\" not defined.\r\n$gdb_prompt $"\
121           {pass "unset environment"}
122   -re "$gdb_prompt $"\
123           {fail "unset environment"}
124   timeout {fail "(timeout) unset environment"}
125 }
126
127 # Verify that we can unset all environment variables.
128 #
129 send_gdb "unset environment\n"
130 gdb_expect {
131   -re "Delete all environment variables.*y or n. $"\
132           {send_gdb "y\n"
133            gdb_expect {
134              -re "$gdb_prompt $"\
135                      {pass "unset entire environment"}
136              timeout {fail "(timeout) unset entire environment"}
137            }
138           }
139   -re "$gdb_prompt $"\
140           {fail "unset entire environment"}
141   timeout {fail "(timeout) unset entire environment"}
142 }
143
144 # Verify that we can set a specific environment variable.
145 #
146 send_gdb "set environment EDITOR emacs\n"
147 gdb_expect {
148   -re "$gdb_prompt $"\
149           {pass "issue set environment"}
150   timeout {fail "(timeout) issue set environment"}
151 }
152 send_gdb "show environment EDITOR\n"
153 gdb_expect {
154   -re "EDITOR = emacs\r\n$gdb_prompt $"\
155           {pass "set environment"}
156   -re "$gdb_prompt $"\
157           {fail "set environment"}
158   timeout {fail "(timeout) set environment"}
159 }
160
161 # Verify that GDB responds gracefully to a request to set environment,
162 # with no variable name.
163 #
164 send_gdb "set environment\n"
165 gdb_expect {
166   -re "Argument required .environment variable and value..*$gdb_prompt $"\
167           {pass "set environment without variable disallowed"}
168   -re "$gdb_prompt $"\
169           {fail "set environment without variable disallowed"}
170   timeout {fail "(timeout) set environment without variable disallowed"}
171 }
172
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.
175 #
176 send_gdb "set environment =\n"
177 gdb_expect {
178   -re "Argument required .environment variable to set..*$gdb_prompt $"\
179           {pass "set environment equals without variable disallowed"}
180   -re "$gdb_prompt $"\
181           {fail "set environment equals without variable disallowed"}
182   timeout {fail "(timeout) set environment equals without variable disallowed"}
183 }
184
185 # Setting an environment variable without a value sets it to a NULL
186 # value.
187 #
188 send_gdb "set environment EDITOR\n"
189 gdb_expect {
190   -re "Setting environment variable \"EDITOR\" to null value..*$gdb_prompt $"\
191           {pass "issue set environment without variable value"}
192   -re "$gdb_prompt $"\
193           {fail "issue set environment without variable value"}
194   timeout {fail "(timeout) issue set environment without variable value"}
195 }
196 send_gdb "show environment EDITOR\n"
197 gdb_expect {
198   -re "EDITOR = \r\n$gdb_prompt $"\
199           {pass "set environment without variable value"}
200   -re "$gdb_prompt $"\
201           {fail "set environment without variable value"}
202   timeout {fail "(timeout) set environment without variable value"}
203 }
204
205 # Verify that GDB responds gracefully to an attempt to show a
206 # non-existent environment variable.  (We hope this variable is
207 # undefined!)
208 #
209 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
210 gdb_expect {
211   -re "Environment variable \"FOOBARBAZGRUNGESPAZBALL\" not defined..*$gdb_prompt $"\
212           {pass "show non-existent environment variable disallowed"}
213   -re "$gdb_prompt $"\
214           {fail "show non-existent environment variable disallowed"}
215   timeout {fail "(timeout) show non-existent environment variable disallowed"}
216 }
217
218 # Verify that GDB can set an environment variable hitherto undefined.
219 #
220 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t\n"
221 gdb_expect {
222   -re "$gdb_prompt $"\
223           {pass "issue set environment for previously undefined variable"}
224   timeout {fail "(timeout) issue set environment for previously undefined variable"}
225 }
226 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
227 gdb_expect {
228   -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
229           {pass "set environment for previously undefined variable"}
230   -re "$gdb_prompt $"\
231           {fail "set environment for previously undefined variable"}
232   timeout {fail "(timeout) set environment for previously undefined variable"}
233 }
234
235 # Verify that GDB can also set an environment variable using the "="
236 # syntax.
237 #
238 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = t\n"
239 gdb_expect {
240   -re "$gdb_prompt $"\
241           {pass "issue set environment with equals"}
242   timeout {fail "(timeout) issue set environment with equals"}
243 }
244 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
245 gdb_expect {
246   -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
247           {pass "set environment with equals"}
248   -re "$gdb_prompt $"\
249           {fail "set environment with equals"}
250   timeout {fail "(timeout) set environment with equals"}
251 }
252
253 # Verify that GDB can set an environment variable to a value that has
254 # an embedded (trailing, in this case) equals.
255 #
256 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t=\n"
257 gdb_expect {
258   -re "$gdb_prompt $"\
259           {pass "issue set environment with trailing equals"}
260   timeout {fail "(timeout) issue set environment with trailing equals"}
261 }
262 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
263 gdb_expect {
264   -re "FOOBARBAZGRUNGESPAZBALL = t=\r\n$gdb_prompt $"\
265           {pass "set environment with trailing equals"}
266   -re "$gdb_prompt $"\
267           {fail "set environment with trailing equals"}
268   timeout {fail "(timeout) set environment with trailing equals"}
269 }
270
271 # Verify that GDB can set an environment variable to a value preceded
272 # by whitespace, and that such whitespace is ignored (not included
273 # in the set value).
274 #
275 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL =     foo\n"
276 gdb_expect {
277   -re "$gdb_prompt $"\
278           {pass "issue set environment with preceding whitespace"}
279   timeout {fail "(timeout) issue set environment with preceding whitespace"}
280 }
281 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
282 gdb_expect {
283   -re "FOOBARBAZGRUNGESPAZBALL = foo\r\n$gdb_prompt $"\
284           {pass "set environment with preceding whitespace"}
285   -re "$gdb_prompt $"\
286           {fail "set environment with preceding whitespace"}
287   timeout {fail "(timeout) set environment with preceding whitespace"}
288 }
289
290 # Verify that GDB can manipulate the distinguished PATH variable.
291 #
292 send_gdb "path /tmp/FOOBARBAZGRUNGESPAZBALL\n"
293 gdb_expect {
294   -re ".*Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
295           {pass "issue path"}
296   -re "$gdb_prompt $"\
297           {fail "issue path"}
298   timeout {fail "(timeout) issue path"}
299 }
300 send_gdb "show paths\n"
301 gdb_expect {
302   -re "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
303           {pass "show paths"}
304   -re "$gdb_prompt $"\
305           {fail "show paths"}
306   timeout {fail "(timeout) show paths"}
307 }
308
309 gdb_exit
310 return 0