]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/testenv.exp
850fd8acd30c1cfa1100ad91dd72962255a34c77
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / testenv.exp
1 # Copyright 2011-2016 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 standard_testfile .c
27
28 # Compile binary
29 # and start with a fresh gdb
30
31 if { [prepare_for_testing "failed to prepare" ${binfile} ${srcfile}] } {
32 return -1
33 }
34
35 # make sure $pc is sane, in case we're talking to a board.
36 if { ![runto_main] } {
37 gdb_suppress_tests
38 }
39
40 set bp_line [gdb_get_line_number "set breakpoint here"]
41 gdb_breakpoint $bp_line
42
43 #
44 # Test gdb set/unset environment commands.
45 # Executable lists and counts all environment variables
46 # starting with TEST_GDB.
47
48
49 # First test with no TEST_GDB_VAR
50 gdb_test "continue" \
51 ".*Program found 0 variables starting with TEST_GDB.*" \
52 "test no TEST_GDB var"
53
54 gdb_test_no_output "set env TEST_GDB_VAR1 test1" \
55 "set TEST_GDB_VAR1"
56
57 runto_main
58 gdb_breakpoint $bp_line
59
60 # Second test with one TEST_GDB_VAR
61 gdb_test "continue" \
62 ".*Program found 1 variables starting with TEST_GDB.*" \
63 "test with one TEST_GDB var"
64
65 gdb_test_no_output "set env TEST_GDB_VAR2 test2" \
66 "set TEST_GDB_VAR2"
67
68 runto_main
69 gdb_breakpoint $bp_line
70
71 # Third test with two TEST_GDB_VAR
72 gdb_test "continue" \
73 ".*Program found 2 variables starting with TEST_GDB.*" \
74 "test with two TEST_GDB var"
75
76 gdb_test_no_output "unset env TEST_GDB_VAR1" \
77 "unset TEST_GDB_VAR1"
78
79 runto_main
80 gdb_breakpoint $bp_line
81
82 # Fourth test with one TEST_GDB_VAR left, after one was removed
83 # with unset command.
84 gdb_test "continue" \
85 ".*Program found 1 variables starting with TEST_GDB.*" \
86 "test with one TEST_GDB var, after unset"
87
88 gdb_exit
89
90 set env(TEST_GDB_GLOBAL) "Global environment value"
91
92 clean_restart $binfile
93
94 # make sure $pc is sane, in case we're talking to a board.
95 if { ![runto_main] } {
96 gdb_suppress_tests
97 }
98
99 set bp_line [gdb_get_line_number "set breakpoint here"]
100 gdb_breakpoint $bp_line
101
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"
107
108 gdb_test_no_output "unset env TEST_GDB_GLOBAL" \
109 "unset TEST_GDB_GLOBAL"
110
111 runto_main
112 gdb_breakpoint $bp_line
113
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"
118
119 gdb_exit
120
121 # Clear environment in case we're doing multiple runs
122 unset env(TEST_GDB_GLOBAL)
123