From 7fea69231b71b2bae46c2a8f9bb77d6739c3e1b4 Mon Sep 17 00:00:00 2001 From: Pierre Muller Date: Wed, 5 Oct 2011 14:23:37 +0000 Subject: [PATCH] Add tests for passing of environment variables to inferior. * gdb.base/testenv.c: New test source. * gdb.base/testenv.exp: New expect test. --- gdb/testsuite/ChangeLog | 6 ++ gdb/testsuite/gdb.base/testenv.c | 47 +++++++++++ gdb/testsuite/gdb.base/testenv.exp | 121 +++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+) create mode 100755 gdb/testsuite/gdb.base/testenv.c create mode 100644 gdb/testsuite/gdb.base/testenv.exp diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 68aa02a4c8..8f9efd1e4e 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2011-10-05 Pierre Muller + + Add tests for passing of environment variables to inferior. + * gdb.base/testenv.c: New test source. + * gdb.base/testenv.exp: New expect test. + 2011-10-04 Paul Koning * gdb.python/py-value.c (main): Break before return. diff --git a/gdb/testsuite/gdb.base/testenv.c b/gdb/testsuite/gdb.base/testenv.c new file mode 100755 index 0000000000..83f7e9c540 --- /dev/null +++ b/gdb/testsuite/gdb.base/testenv.c @@ -0,0 +1,47 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2011 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 . */ + +/* + This source is used to check that GDB correctly + passes on environment variables down to inferior. + One of the tests checks that 'unset' variables also are removed from + inferior environment list. */ + +#include + +int main (int argc, char **argv, char **envp) + +{ + int i, j; +#ifdef usestubs + set_debug_traps(); + breakpoint(); +#endif + + j = 0; + for (i = 0; envp[i]; i++) + { + if (strncmp ("TEST_GDB", envp[i], 8) == 0) + { + printf ("%s\n", envp[i]); + j++; + } + } + printf ("Program found %d variables starting with TEST_GDB\n", j); + return 0; /* set breakpoint here. */ +} + diff --git a/gdb/testsuite/gdb.base/testenv.exp b/gdb/testsuite/gdb.base/testenv.exp new file mode 100644 index 0000000000..ad39f1451d --- /dev/null +++ b/gdb/testsuite/gdb.base/testenv.exp @@ -0,0 +1,121 @@ +# Copyright 2011 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 . + +# This file was written by Pierre Muller +# +# Check if environment variables are correctly passed to inferiors +# + +if $tracelevel then { + strace $tracelevel +} + + +set testfile "testenv" +set srcfile ${testfile}.c +set binfile ${testfile} + +# Compile binary +# and start with a fresh gdb + +if { [prepare_for_testing ${testfile}.exp ${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