Imported Upstream version 7.5
[platform/upstream/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 # There's no support for passing environment variables in the remote protocol.
22 if { [is_remote target] } {
23     return 0
24 }
25
26 set testfile "testenv"
27 set srcfile ${testfile}.c
28 set binfile ${testfile}
29
30 # Compile binary
31 # and start with a fresh gdb
32
33 if { [prepare_for_testing ${testfile}.exp ${binfile} ${srcfile}] } {
34      return -1
35 }
36
37 # make sure $pc is sane, in case we're talking to a board.
38 if { ![runto_main] } {
39     gdb_suppress_tests;
40 }
41
42 set bp_line [gdb_get_line_number "set breakpoint here"]
43 gdb_breakpoint  $bp_line
44
45 #
46 # Test gdb set/unset environment commands.
47 # Executable lists and counts all environment variables
48 # starting with TEST_GDB.
49
50
51 # First test with no TEST_GDB_VAR
52 gdb_test "continue" \
53   ".*Program found 0 variables starting with TEST_GDB.*" \
54   "Test no TEST_GDB var"
55
56 gdb_test_no_output "set env TEST_GDB_VAR1 test1" \
57   "Set TEST_GDB_VAR1"
58
59 runto_main
60 gdb_breakpoint  $bp_line
61
62 # Second test with one TEST_GDB_VAR
63 gdb_test "continue" \
64   ".*Program found 1 variables starting with TEST_GDB.*" \
65   "Test with one TEST_GDB var"
66
67 gdb_test_no_output "set env TEST_GDB_VAR2 test2" \
68   "Set TEST_GDB_VAR2"
69
70 runto_main
71 gdb_breakpoint  $bp_line
72
73 # Third test with two TEST_GDB_VAR
74 gdb_test "continue"  \
75   ".*Program found 2 variables starting with TEST_GDB.*" \
76   "Test with two TEST_GDB var"
77
78 gdb_test_no_output "unset env TEST_GDB_VAR1" \
79   "Unset TEST_GDB_VAR1"
80
81 runto_main
82 gdb_breakpoint  $bp_line
83
84 # Fourth test with one TEST_GDB_VAR left, after one was removed
85 # with unset command.
86 gdb_test "continue"  \
87   ".*Program found 1 variables starting with TEST_GDB.*" \
88   "Test with one TEST_GDB var, after unset"
89
90 gdb_exit
91
92 set env(TEST_GDB_GLOBAL) "Global environment value"
93
94 clean_restart $binfile
95
96 # make sure $pc is sane, in case we're talking to a board.
97 if { ![runto_main] } {
98     gdb_suppress_tests;
99 }
100
101 set bp_line [gdb_get_line_number "set breakpoint here"]
102 gdb_breakpoint  $bp_line
103
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"
109
110 gdb_test_no_output "unset env TEST_GDB_GLOBAL" \
111   "Unset TEST_GDB_GLOBAL"
112
113 runto_main
114 gdb_breakpoint  $bp_line
115
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"
120
121 gdb_exit
122
123 # Clear environment in case we're doing multiple runs
124 unset env(TEST_GDB_GLOBAL)
125