1 # Copyright 2011-2015 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/>.
16 # This file was written by Pierre Muller <muller@ics.u-strasbg.fr>
18 # Check if environment variables are correctly passed to inferiors
21 # There's no support for passing environment variables in the remote protocol.
22 if { [is_remote target] } {
29 # and start with a fresh gdb
31 if { [prepare_for_testing ${testfile}.exp ${binfile} ${srcfile}] } {
35 # make sure $pc is sane, in case we're talking to a board.
36 if { ![runto_main] } {
40 set bp_line [gdb_get_line_number "set breakpoint here"]
41 gdb_breakpoint $bp_line
44 # Test gdb set/unset environment commands.
45 # Executable lists and counts all environment variables
46 # starting with TEST_GDB.
49 # First test with no TEST_GDB_VAR
51 ".*Program found 0 variables starting with TEST_GDB.*" \
52 "Test no TEST_GDB var"
54 gdb_test_no_output "set env TEST_GDB_VAR1 test1" \
58 gdb_breakpoint $bp_line
60 # Second test with one TEST_GDB_VAR
62 ".*Program found 1 variables starting with TEST_GDB.*" \
63 "Test with one TEST_GDB var"
65 gdb_test_no_output "set env TEST_GDB_VAR2 test2" \
69 gdb_breakpoint $bp_line
71 # Third test with two TEST_GDB_VAR
73 ".*Program found 2 variables starting with TEST_GDB.*" \
74 "Test with two TEST_GDB var"
76 gdb_test_no_output "unset env TEST_GDB_VAR1" \
80 gdb_breakpoint $bp_line
82 # Fourth test with one TEST_GDB_VAR left, after one was removed
85 ".*Program found 1 variables starting with TEST_GDB.*" \
86 "Test with one TEST_GDB var, after unset"
90 set env(TEST_GDB_GLOBAL) "Global environment value"
92 clean_restart $binfile
94 # make sure $pc is sane, in case we're talking to a board.
95 if { ![runto_main] } {
99 set bp_line [gdb_get_line_number "set breakpoint here"]
100 gdb_breakpoint $bp_line
102 gdb_test "show env" ".*TEST_GDB_GLOBAL=.*" "Test passing TEST_GDB_GLOBAL to GDB"
103 # First test with only inherited TEST_GDB_GLOBAL
104 gdb_test "continue" \
105 ".*TEST_GDB_GLOBAL=Global environment value.*Program found 1 variables starting with TEST_GDB.*" \
106 "Test with TEST_GDB_GLOBAL"
108 gdb_test_no_output "unset env TEST_GDB_GLOBAL" \
109 "Unset TEST_GDB_GLOBAL"
112 gdb_breakpoint $bp_line
114 # Second test with one TEST_GDB_VAR
115 gdb_test "continue" \
116 ".*Program found 0 variables starting with TEST_GDB.*" \
117 "Test with TEST_GDB_GLOBAL unset"
121 # Clear environment in case we're doing multiple runs
122 unset env(TEST_GDB_GLOBAL)