aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/testenv.exp
blob: 850fd8acd30c1cfa1100ad91dd72962255a34c77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Copyright 2011-2016 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This file was written by Pierre Muller <muller@ics.u-strasbg.fr>
#
# Check if environment variables are correctly passed to inferiors
#

# There's no support for passing environment variables in the remote protocol.
if { [is_remote target] } {
    return 0
}

standard_testfile .c

# Compile binary
# and start with a fresh gdb

if { [prepare_for_testing "failed to prepare" ${binfile} ${srcfile}] } {
     return -1
}

# make sure $pc is sane, in case we're talking to a board.
if { ![runto_main] } {
    gdb_suppress_tests
}

set bp_line [gdb_get_line_number "set breakpoint here"]
gdb_breakpoint  $bp_line

#
# Test gdb set/unset environment commands.
# Executable lists and counts all environment variables
# starting with TEST_GDB.


# First test with no TEST_GDB_VAR
gdb_test "continue" \
  ".*Program found 0 variables starting with TEST_GDB.*" \
  "test no TEST_GDB var"

gdb_test_no_output "set env TEST_GDB_VAR1 test1" \
  "set TEST_GDB_VAR1"

runto_main
gdb_breakpoint  $bp_line

# Second test with one TEST_GDB_VAR
gdb_test "continue" \
  ".*Program found 1 variables starting with TEST_GDB.*" \
  "test with one TEST_GDB var"

gdb_test_no_output "set env TEST_GDB_VAR2 test2" \
  "set TEST_GDB_VAR2"

runto_main
gdb_breakpoint  $bp_line

# Third test with two TEST_GDB_VAR
gdb_test "continue"  \
  ".*Program found 2 variables starting with TEST_GDB.*" \
  "test with two TEST_GDB var"

gdb_test_no_output "unset env TEST_GDB_VAR1" \
  "unset TEST_GDB_VAR1"

runto_main
gdb_breakpoint  $bp_line

# Fourth test with one TEST_GDB_VAR left, after one was removed
# with unset command.
gdb_test "continue"  \
  ".*Program found 1 variables starting with TEST_GDB.*" \
  "test with one TEST_GDB var, after unset"

gdb_exit

set env(TEST_GDB_GLOBAL) "Global environment value"

clean_restart $binfile

# make sure $pc is sane, in case we're talking to a board.
if { ![runto_main] } {
    gdb_suppress_tests
}

set bp_line [gdb_get_line_number "set breakpoint here"]
gdb_breakpoint  $bp_line

gdb_test "show env" ".*TEST_GDB_GLOBAL=.*" "test passing TEST_GDB_GLOBAL to GDB"
# First test with only inherited TEST_GDB_GLOBAL
gdb_test "continue" \
  ".*TEST_GDB_GLOBAL=Global environment value.*Program found 1 variables starting with TEST_GDB.*" \
  "test with TEST_GDB_GLOBAL"

gdb_test_no_output "unset env TEST_GDB_GLOBAL" \
  "unset TEST_GDB_GLOBAL"

runto_main
gdb_breakpoint  $bp_line

# Second test with one TEST_GDB_VAR
gdb_test "continue" \
  ".*Program found 0 variables starting with TEST_GDB.*" \
  "test with TEST_GDB_GLOBAL unset"

gdb_exit

# Clear environment in case we're doing multiple runs
unset env(TEST_GDB_GLOBAL)