1 # Copyright 2011-2012 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
25 # There's no support for passing environment variables in the remote protocol.
26 if { [is_remote target] } {
30 set testfile "testenv"
31 set srcfile ${testfile}.c
32 set binfile ${testfile}
35 # and start with a fresh gdb
37 if { [prepare_for_testing ${testfile}.exp ${binfile} ${srcfile}] } {
41 # make sure $pc is sane, in case we're talking to a board.
42 if { ![runto_main] } {
46 set bp_line [gdb_get_line_number "set breakpoint here"]
47 gdb_breakpoint $bp_line
50 # Test gdb set/unset environment commands.
51 # Executable lists and counts all environment variables
52 # starting with TEST_GDB.
55 # First test with no TEST_GDB_VAR
57 ".*Program found 0 variables starting with TEST_GDB.*" \
58 "Test no TEST_GDB var"
60 gdb_test_no_output "set env TEST_GDB_VAR1 test1" \
64 gdb_breakpoint $bp_line
66 # Second test with one TEST_GDB_VAR
68 ".*Program found 1 variables starting with TEST_GDB.*" \
69 "Test with one TEST_GDB var"
71 gdb_test_no_output "set env TEST_GDB_VAR2 test2" \
75 gdb_breakpoint $bp_line
77 # Third test with two TEST_GDB_VAR
79 ".*Program found 2 variables starting with TEST_GDB.*" \
80 "Test with two TEST_GDB var"
82 gdb_test_no_output "unset env TEST_GDB_VAR1" \
86 gdb_breakpoint $bp_line
88 # Fourth test with one TEST_GDB_VAR left, after one was removed
91 ".*Program found 1 variables starting with TEST_GDB.*" \
92 "Test with one TEST_GDB var, after unset"
96 set env(TEST_GDB_GLOBAL) "Global environment value"
98 clean_restart $binfile
100 # make sure $pc is sane, in case we're talking to a board.
101 if { ![runto_main] } {
105 set bp_line [gdb_get_line_number "set breakpoint here"]
106 gdb_breakpoint $bp_line
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"
114 gdb_test_no_output "unset env TEST_GDB_GLOBAL" \
115 "Unset TEST_GDB_GLOBAL"
118 gdb_breakpoint $bp_line
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"
127 # Clear environment in case we're doing multiple runs
128 unset env(TEST_GDB_GLOBAL)