From: "Pierre Muller" <pierre.muller@ics-cnrs.unistra.fr>
To: "'Tom Tromey'" <tromey@redhat.com>
Cc: <gdb-patches@sourceware.org>
Subject: [RFA-v3] testsuite: Add a test for passing of environment variables to inferior
Date: Tue, 04 Oct 2011 21:35:00 -0000 [thread overview]
Message-ID: <000c01cc82dd$72ba3150$582e93f0$@muller@ics-cnrs.unistra.fr> (raw)
In-Reply-To: <m3ipo4oeft.fsf@fleche.redhat.com>
> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Tom Tromey
> Envoyé : mardi 4 octobre 2011 19:27
> À : Pierre Muller
> Cc : gdb-patches@sourceware.org
> Objet : Re: [RFA-v2] testsuite: Add a test for passing of environment
> variables to inferior
>
> >>>>> "Pierre" == Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>
writes:
>
> Pierre> 2011-10-04 Pierre Muller <muller@ics.u-strasbg.fr>
>
> Pierre> Add tests for passing of environment variables to inferior.
> Pierre> * gdb.base/testenv.c: New test source.
> Pierre> * gdb.base/testenv.exp: New expect test.
>
> Thanks for doing this.
>
> Pierre> +#ifdef PROTOTYPES
> Pierre> +int main (int argc, char **argv, char **envp)
>
> You don't need to handle the no PROTOTYPES case any more.
Removed
> Pierre> +if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile}
> executable {debug}] != "" } {
> Pierre> + untested testenv.exp
> Pierre> + return -1
> Pierre> +}
> Pierre> +
> Pierre> +# Start with a fresh gdb
> Pierre> +
> Pierre> +gdb_exit
> Pierre> +gdb_start
> Pierre> +gdb_reinitialize_dir $srcdir/$subdir
> Pierre> +gdb_load ${binfile}
>
> You can use prepare_for_testing instead.
Used instead.
> Pierre> +runto main
>
> There's a special runto_main proc for this.
>
> Pierre> +gdb_exit
> Pierre> +
> Pierre> +set env(TEST_GDB_GLOBAL) "Global environment value"
> Pierre> +
> Pierre> +gdb_start
> Pierre> +gdb_reinitialize_dir $srcdir/$subdir
> Pierre> +gdb_load ${binfile}
>
> You can use clean_restart here.
Also changed.
Thanks for all your comments,
here is an updated patch
that takes all your suggestions into account.
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 21:32:05 -0000
@@ -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 <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>
+
+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. */
+}
+
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 21:32:05 -0000
@@ -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 <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 ${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
next prev parent reply other threads:[~2011-10-04 21:35 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-04 12:36 [RFA] " Pierre Muller
2011-10-04 13:45 ` Corinna Vinschen
2011-10-04 14:43 ` Eli Zaretskii
2011-10-04 14:48 ` Pierre Muller
2011-10-04 14:50 ` Pierre Muller
2011-10-04 15:13 ` Corinna Vinschen
2011-10-04 16:09 ` [RFA-v2] " Pierre Muller
2011-10-04 16:11 ` [RFA] " Pierre Muller
2011-10-05 11:40 ` Corinna Vinschen
2011-10-05 12:08 ` Pierre Muller
2011-10-05 12:52 ` Corinna Vinschen
2011-10-06 14:51 ` Christopher Faylor
2011-10-06 15:03 ` Corinna Vinschen
2011-10-07 12:26 ` Christopher Faylor
2011-10-07 13:53 ` Corinna Vinschen
[not found] ` <12954.5351061553$1317744599@news.gmane.org>
2011-10-04 17:27 ` [RFA-v2] " Tom Tromey
2011-10-04 21:35 ` Pierre Muller [this message]
[not found] ` <29288.743020925$1317764135@news.gmane.org>
2011-10-05 13:53 ` [RFA-v3] " Tom Tromey
2011-10-05 14:25 ` Pierre Muller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='000c01cc82dd$72ba3150$582e93f0$@muller@ics-cnrs.unistra.fr' \
--to=pierre.muller@ics-cnrs.unistra.fr \
--cc=gdb-patches@sourceware.org \
--cc=tromey@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox