From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8579 invoked by alias); 4 Oct 2011 21:35:27 -0000 Received: (qmail 8170 invoked by uid 22791); 4 Oct 2011 21:35:25 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,MSGID_MULTIPLE_AT X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.158) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 04 Oct 2011 21:35:02 +0000 Received: from md2.u-strasbg.fr (md2.u-strasbg.fr [IPv6:2001:660:2402::187]) by mailhost.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id p94LYpYd027551 ; Tue, 4 Oct 2011 23:34:51 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms4.u-strasbg.fr [130.79.204.13]) by md2.u-strasbg.fr (8.14.4/jtpda-5.5pre1) with ESMTP id p94LYo1e006229 ; Tue, 4 Oct 2011 23:34:50 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from E6510Muller (lec67-4-82-230-53-140.fbx.proxad.net [82.230.53.140]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.4/jtpda-5.5pre1) with ESMTP id p94LYmKl043694 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) ; Tue, 4 Oct 2011 23:34:49 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: "'Tom Tromey'" Cc: References: <006301cc8292$367539b0$a35fad10$@muller@ics-cnrs.unistra.fr> <20111004134506.GB24369@calimero.vinschen.de> <000901cc82a4$dfba7cd0$9f2f7670$@muller@ics-cnrs.unistra.fr> <20111004151236.GC15757@calimero.vinschen.de> <12954.5351061553$1317744599@news.gmane.org> In-Reply-To: Subject: [RFA-v3] testsuite: Add a test for passing of environment variables to inferior Date: Tue, 04 Oct 2011 21:35:00 -0000 Message-ID: <000c01cc82dd$72ba3150$582e93f0$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-10/txt/msg00119.txt.bz2 > -----Message d'origine----- > De=A0: gdb-patches-owner@sourceware.org [mailto:gdb-patches- > owner@sourceware.org] De la part de Tom Tromey > Envoy=E9=A0: mardi 4 octobre 2011 19:27 > =C0=A0: Pierre Muller > Cc=A0: gdb-patches@sourceware.org > Objet=A0: Re: [RFA-v2] testsuite: Add a test for passing of environment > variables to inferior >=20 > >>>>> "Pierre" =3D=3D Pierre Muller writes: >=20 > Pierre> 2011-10-04 Pierre Muller >=20 > 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. >=20 > Thanks for doing this. >=20 > Pierre> +#ifdef PROTOTYPES > Pierre> +int main (int argc, char **argv, char **envp) >=20 > You don't need to handle the no PROTOTYPES case any more. Removed=20 > Pierre> +if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} > executable {debug}] !=3D "" } { > 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} >=20 > You can use prepare_for_testing instead. Used instead.=20 > Pierre> +runto main >=20 > There's a special runto_main proc for this. >=20 > 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} >=20 > 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 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 . */ + +/* + 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 =3D 0; + for (i =3D 0; envp[i]; i++) + { + if (strncmp ("TEST_GDB", envp[i], 8) =3D=3D 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 . + +# 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=3D.*" "Test passing TEST_GDB_GLOBAL= to GDB" +# First test with only inherited TEST_GDB_GLOBAL +gdb_test "continue" \ + ".*TEST_GDB_GLOBAL=3DGlobal 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