ff337fe11c468e0d3a9dadceee24d7eb0ad7f099
[binutils-gdb.git] / gdb / testsuite / gdb.base / testenv.exp
1 # Copyright 2011-2012 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 # This file was written by Pierre Muller <muller@ics.u-strasbg.fr>
17 #
18 # Check if environment variables are correctly passed to inferiors
19 #
20
21 if $tracelevel then {
22 strace $tracelevel
23 }
24
25 # There's no support for passing environment variables in the remote protocol.
26 if { [is_remote target] } {
27 return 0
28 }
29
30 set testfile "testenv"
31 set srcfile ${testfile}.c
32 set binfile ${testfile}
33
34 # Compile binary
35 # and start with a fresh gdb
36
37 if { [prepare_for_testing ${testfile}.exp ${binfile} ${srcfile}] } {
38 return -1
39 }
40
41 # make sure $pc is sane, in case we're talking to a board.
42 if { ![runto_main] } {
43 gdb_suppress_tests;
44 }
45
46 set bp_line [gdb_get_line_number "set breakpoint here"]
47 gdb_breakpoint $bp_line
48
49 #
50 # Test gdb set/unset environment commands.
51 # Executable lists and counts all environment variables
52 # starting with TEST_GDB.
53
54
55 # First test with no TEST_GDB_VAR
56 gdb_test "continue" \
57 ".*Program found 0 variables starting with TEST_GDB.*" \
58 "Test no TEST_GDB var"
59
60 gdb_test_no_output "set env TEST_GDB_VAR1 test1" \
61 "Set TEST_GDB_VAR1"
62
63 runto_main
64 gdb_breakpoint $bp_line
65
66 # Second test with one TEST_GDB_VAR
67 gdb_test "continue" \
68 ".*Program found 1 variables starting with TEST_GDB.*" \
69 "Test with one TEST_GDB var"
70
71 gdb_test_no_output "set env TEST_GDB_VAR2 test2" \
72 "Set TEST_GDB_VAR2"
73
74 runto_main
75 gdb_breakpoint $bp_line
76
77 # Third test with two TEST_GDB_VAR
78 gdb_test "continue" \
79 ".*Program found 2 variables starting with TEST_GDB.*" \
80 "Test with two TEST_GDB var"
81
82 gdb_test_no_output "unset env TEST_GDB_VAR1" \
83 "Unset TEST_GDB_VAR1"
84
85 runto_main
86 gdb_breakpoint $bp_line
87
88 # Fourth test with one TEST_GDB_VAR left, after one was removed
89 # with unset command.
90 gdb_test "continue" \
91 ".*Program found 1 variables starting with TEST_GDB.*" \
92 "Test with one TEST_GDB var, after unset"
93
94 gdb_exit
95
96 set env(TEST_GDB_GLOBAL) "Global environment value"
97
98 clean_restart $binfile
99
100 # make sure $pc is sane, in case we're talking to a board.
101 if { ![runto_main] } {
102 gdb_suppress_tests;
103 }
104
105 set bp_line [gdb_get_line_number "set breakpoint here"]
106 gdb_breakpoint $bp_line
107
108 gdb_test "show env" ".*TEST_GDB_GLOBAL=.*" "Test passing TEST_GDB_GLOBAL to GDB"
109 # First test with only inherited TEST_GDB_GLOBAL
110 gdb_test "continue" \
111 ".*TEST_GDB_GLOBAL=Global environment value.*Program found 1 variables starting with TEST_GDB.*" \
112 "Test with TEST_GDB_GLOBAL"
113
114 gdb_test_no_output "unset env TEST_GDB_GLOBAL" \
115 "Unset TEST_GDB_GLOBAL"
116
117 runto_main
118 gdb_breakpoint $bp_line
119
120 # Second test with one TEST_GDB_VAR
121 gdb_test "continue" \
122 ".*Program found 0 variables starting with TEST_GDB.*" \
123 "Test with TEST_GDB_GLOBAL unset"
124
125 gdb_exit
126
127 # Clear environment in case we're doing multiple runs
128 unset env(TEST_GDB_GLOBAL)
129