1 # Copyright 2011-2013 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] } {
26 set testfile "testenv"
27 set srcfile ${testfile}.c
28 set binfile ${testfile}
31 # and start with a fresh gdb
33 if { [prepare_for_testing ${testfile}.exp ${binfile} ${srcfile}] } {
37 # make sure $pc is sane, in case we're talking to a board.
38 if { ![runto_main] } {
42 set bp_line [gdb_get_line_number "set breakpoint here"]
43 gdb_breakpoint $bp_line
46 # Test gdb set/unset environment commands.
47 # Executable lists and counts all environment variables
48 # starting with TEST_GDB.
51 # First test with no TEST_GDB_VAR
53 ".*Program found 0 variables starting with TEST_GDB.*" \
54 "Test no TEST_GDB var"
56 gdb_test_no_output "set env TEST_GDB_VAR1 test1" \
60 gdb_breakpoint $bp_line
62 # Second test with one TEST_GDB_VAR
64 ".*Program found 1 variables starting with TEST_GDB.*" \
65 "Test with one TEST_GDB var"
67 gdb_test_no_output "set env TEST_GDB_VAR2 test2" \
71 gdb_breakpoint $bp_line
73 # Third test with two TEST_GDB_VAR
75 ".*Program found 2 variables starting with TEST_GDB.*" \
76 "Test with two TEST_GDB var"
78 gdb_test_no_output "unset env TEST_GDB_VAR1" \
82 gdb_breakpoint $bp_line
84 # Fourth test with one TEST_GDB_VAR left, after one was removed
87 ".*Program found 1 variables starting with TEST_GDB.*" \
88 "Test with one TEST_GDB var, after unset"
92 set env(TEST_GDB_GLOBAL) "Global environment value"
94 clean_restart $binfile
96 # make sure $pc is sane, in case we're talking to a board.
97 if { ![runto_main] } {
101 set bp_line [gdb_get_line_number "set breakpoint here"]
102 gdb_breakpoint $bp_line
104 gdb_test "show env" ".*TEST_GDB_GLOBAL=.*" "Test passing TEST_GDB_GLOBAL to GDB"
105 # First test with only inherited TEST_GDB_GLOBAL
106 gdb_test "continue" \
107 ".*TEST_GDB_GLOBAL=Global environment value.*Program found 1 variables starting with TEST_GDB.*" \
108 "Test with TEST_GDB_GLOBAL"
110 gdb_test_no_output "unset env TEST_GDB_GLOBAL" \
111 "Unset TEST_GDB_GLOBAL"
114 gdb_breakpoint $bp_line
116 # Second test with one TEST_GDB_VAR
117 gdb_test "continue" \
118 ".*Program found 0 variables starting with TEST_GDB.*" \
119 "Test with TEST_GDB_GLOBAL unset"
123 # Clear environment in case we're doing multiple runs
124 unset env(TEST_GDB_GLOBAL)