1# Copyright 2011-2017 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. 22if { [is_remote target] } { 23 return 0 24} 25 26standard_testfile .c 27 28# Compile binary 29# and start with a fresh gdb 30 31if { [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. 36if { ![runto_main] } { 37 gdb_suppress_tests 38} 39 40set bp_line [gdb_get_line_number "set breakpoint here"] 41gdb_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 50gdb_test "continue" \ 51 ".*Program found 0 variables starting with TEST_GDB.*" \ 52 "test no TEST_GDB var" 53 54gdb_test_no_output "set env TEST_GDB_VAR1 test1" \ 55 "set TEST_GDB_VAR1" 56 57runto_main 58gdb_breakpoint $bp_line 59 60# Second test with one TEST_GDB_VAR 61gdb_test "continue" \ 62 ".*Program found 1 variables starting with TEST_GDB.*" \ 63 "test with one TEST_GDB var" 64 65gdb_test_no_output "set env TEST_GDB_VAR2 test2" \ 66 "set TEST_GDB_VAR2" 67 68runto_main 69gdb_breakpoint $bp_line 70 71# Third test with two TEST_GDB_VAR 72gdb_test "continue" \ 73 ".*Program found 2 variables starting with TEST_GDB.*" \ 74 "test with two TEST_GDB var" 75 76gdb_test_no_output "unset env TEST_GDB_VAR1" \ 77 "unset TEST_GDB_VAR1" 78 79runto_main 80gdb_breakpoint $bp_line 81 82# Fourth test with one TEST_GDB_VAR left, after one was removed 83# with unset command. 84gdb_test "continue" \ 85 ".*Program found 1 variables starting with TEST_GDB.*" \ 86 "test with one TEST_GDB var, after unset" 87 88gdb_exit 89 90set env(TEST_GDB_GLOBAL) "Global environment value" 91 92clean_restart $binfile 93 94# make sure $pc is sane, in case we're talking to a board. 95if { ![runto_main] } { 96 gdb_suppress_tests 97} 98 99set bp_line [gdb_get_line_number "set breakpoint here"] 100gdb_breakpoint $bp_line 101 102gdb_test "show env" ".*TEST_GDB_GLOBAL=.*" "test passing TEST_GDB_GLOBAL to GDB" 103# First test with only inherited TEST_GDB_GLOBAL 104gdb_test "continue" \ 105 ".*TEST_GDB_GLOBAL=Global environment value.*Program found 1 variables starting with TEST_GDB.*" \ 106 "test with TEST_GDB_GLOBAL" 107 108gdb_test_no_output "unset env TEST_GDB_GLOBAL" \ 109 "unset TEST_GDB_GLOBAL" 110 111runto_main 112gdb_breakpoint $bp_line 113 114# Second test with one TEST_GDB_VAR 115gdb_test "continue" \ 116 ".*Program found 0 variables starting with TEST_GDB.*" \ 117 "test with TEST_GDB_GLOBAL unset" 118 119gdb_exit 120 121# Clear environment in case we're doing multiple runs 122unset env(TEST_GDB_GLOBAL) 123 124