This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] testsuite: Add a test for passing of environment variables to inferior


  Following Eli's comment that it was not clear
what I wanted to achieve, I wrote a new test.

  Manually checking CVS GDB for mingw, Eli's patch
gives the correct output.
  But Stock Cygwin GDB currently passes none of these
TEST_GDB_XXX variables to inferior.
  Even the patch that I sent earlier is not correct:
it still fails for the last test,
once TEST_GDB_VAR1 has been set into GDB environment list,
it doesn't get removed on the last start of the inferior...

  Corinna, I think this is the reason why I wanted to restore
the original environment layout (to avoid leaving unset
variables around.)

  Anyhow, one more test in the testsuite to test
an unchecked feature is always a good thing, no?

  
Pierre

testsuite/ChangeLog entry:

2011-10-04  Pierre Muller  <muller@ics.u-strasbg.fr>

	Add tests for passing of environment variables to inferior.
	* gdb.base/testenv.c: New test source.
	* gdb.base/testenv.exp: New expect test.



Index: gdb.base/testenv.c
===================================================================
RCS file: gdb.base/testenv.c
diff -N gdb.base/testenv.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gdb.base/testenv.c	4 Oct 2011 12:27:05 -0000
@@ -0,0 +1,53 @@
+/* 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 <http://www.gnu.org/licenses/>.
*/
+
+/*
+    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 <stdio.h>
+
+#ifdef PROTOTYPES
+int main (int argc, char **argv, char **envp)
+#else
+main (argc, argv, envp)
+     int argc;
+     char **argv;
+     char **envp;
+#endif
+{
+    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.  */
+}
+
Index: gdb.base/testenv.exp
===================================================================
RCS file: gdb.base/testenv.exp
diff -N gdb.base/testenv.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gdb.base/testenv.exp	4 Oct 2011 12:27:05 -0000
@@ -0,0 +1,94 @@
+# 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 <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
+#
+
+if $tracelevel then {
+	strace $tracelevel
+}
+
+
+set testfile "testenv"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable
{debug}] != "" } {
+     untested testenv.exp
+     return -1
+}
+
+# Start with a fresh gdb
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${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
+
+#
+# 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]