From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id AC7E43858C39 for ; Wed, 20 Mar 2024 13:28:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AC7E43858C39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AC7E43858C39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710941336; cv=none; b=sJTDzzR6UpgkcuSc6gfapA+9yLAvUhl/aIYA1o4b9tZ4cnfkr3OW9ySu3s9VGVKXvHWH2tQ9RLZc09D0CI57tiX/MUeu6iKjqlaaaRWLV5E7Pa/hVTnbfU2jYc4QsPyOw8PbTyADLhhetbi7lIVQOwmMeShB60dMqMRgH5vsjjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710941336; c=relaxed/simple; bh=uLSgxS1uM3HkU2M4/m+BqgBO9KyIt2MbKMCuS9UIrTI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=R/eotqOHHUHHhH3/w8A2FaHXBs+7oRYQ1I83H3oWIpNv+biIGD5dX1/n75i8F0g5WU4RCJLq49lYgR1plKKMA/JWh7cwkk1dqDYFm7Zjr8EzXmrDiOltqTe1tSwMnV/4pEI1GSgYEPmz2dxpp/DT3auh70Q3SFH3nnx1kwx8eH4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710941333; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2b9Dnki4u8BhkwBtuztuFI8UR9ADi4X9ypqN2O3pLlc=; b=LVFbqu3QYwFyZ/XwFNH+1Gucs5Ln/yoj49975irxI8T1IMr8lXA5tR+ErSbCCCpyxbuhlS vJoyXYpbVJNBYHeon2c9UQGlNYbxHqFN9es173S1QKXHgaU4CSigKPPUb+6j5dvUqmeGuW PzhDPYu37cr6UQNgDg0X6+s9iCY5g4c= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-498-ITvUglwoOJSVNcIqoLeeQg-1; Wed, 20 Mar 2024 09:28:51 -0400 X-MC-Unique: ITvUglwoOJSVNcIqoLeeQg-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2d4b150c9a0so34127141fa.0 for ; Wed, 20 Mar 2024 06:28:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710941329; x=1711546129; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:to:from:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=gQRgLMyP+7REwBNqcfU27tHhYSFX0EYK5V/ALa6jZ7I=; b=dyAnl/bziZGAYs6iH5yX7r1c2b+52aB+HiYdcbERJl6tlEIX5ljjptATkNRiipthCh uO9R2XO0AZMU3KjeK3AMH9yBB/vWzswSnMOpmGFV+LwQwx/cMEpH391gbAe5wzlZZyhg OJwYdwAWWGOxrv6APLvjZ/r8Ct0Q93/7kt9rcqbK1X6NDPB73uqRKH6LAkDMniKXIzUz eqPZO9A+SRqtWOMAY1fC+yUw0ISp5baj42PIkdVnlY8rnY6ZTbP8YNDYxO72pAFXGRl/ sAHnWf1q+BIPNn7+jJyVcYEjRwzcZvhv4kKVy9JXgNqinlmcnqFfjSKR1pbD7ZlJHPgP p5BQ== X-Forwarded-Encrypted: i=1; AJvYcCXsHCPgZ30mTbYTCJc0IV4r+GoykZNZAxh49DJA2816nS0lM/68AlTzTib+VZtVwoneQoBV2/CrOKjtd/ABpCucY/cWmw1VjY521g== X-Gm-Message-State: AOJu0Yx6JfDsT/3k4mV9WhAmC5yOFWgfRDbdVrxEMFVeBliHzIvfg1US xJAcIFk/fVCMCqe8ZLBh2NO7Ff92Nuf9ANvPaxsRrl853rVlnCiFuV13IX065k78mDFBzX59mY9 Xh4pTKl03tCa0mdFcrG1whXVJtzW6lFinWf6Sb6NBUFBshzNv1qSX+K7Jni4= X-Received: by 2002:a2e:8556:0:b0:2d4:49d1:38e with SMTP id u22-20020a2e8556000000b002d449d1038emr10319398ljj.28.1710941329556; Wed, 20 Mar 2024 06:28:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7SeM00jXiZMnkgorB2AuPy/D+VWjZ4LwVupHQfRAklbni1nQHktJfLLKqh4X4XQFbvdNosQ== X-Received: by 2002:a2e:8556:0:b0:2d4:49d1:38e with SMTP id u22-20020a2e8556000000b002d449d1038emr10319387ljj.28.1710941328995; Wed, 20 Mar 2024 06:28:48 -0700 (PDT) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id q23-20020a17090622d700b00a46a781ae94sm5055183eja.156.2024.03.20.06.28.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 06:28:48 -0700 (PDT) From: Andrew Burgess To: Alexandra =?utf-8?B?SMOhamtvdsOh?= , gdb-patches@sourceware.org Subject: Re: [PATCH v2] Add a test for the gcore script In-Reply-To: <20240221150402.1375797-1-ahajkova@redhat.com> References: <20240221150402.1375797-1-ahajkova@redhat.com> Date: Wed, 20 Mar 2024 13:28:47 +0000 Message-ID: <87msqtt4kw.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Alexandra H=C3=A1jkov=C3=A1 writes: > It also tests the gcore script being run without its accessible > terminal. > > This test was written by Jan Kratochvil a long time ago. I modernized > the test making it use various procs from lib/gdb.exp, reoirganising it > and added some comments. > > Tested by using make check-all-boards. > > Co-Authored-By: Jan Kratochvil > --- > v2: - cosmetics > - Added Jan Kratochvil as the Co-Author > - added asserts > - added more comments > - removed unnecessary code > > gdb/testsuite/gdb.base/gcorebg.c | 68 +++++++++++++++++++++++++ > gdb/testsuite/gdb.base/gcorebg.exp | 81 ++++++++++++++++++++++++++++++ > gdb/testsuite/lib/gdb.exp | 17 +++++++ > 3 files changed, 166 insertions(+) > create mode 100644 gdb/testsuite/gdb.base/gcorebg.c > create mode 100644 gdb/testsuite/gdb.base/gcorebg.exp > > diff --git a/gdb/testsuite/gdb.base/gcorebg.c b/gdb/testsuite/gdb.base/gc= orebg.c > new file mode 100644 > index 00000000000..0d5168c63ad > --- /dev/null > +++ b/gdb/testsuite/gdb.base/gcorebg.c > @@ -0,0 +1,68 @@ > +/* Copyright 2007-2024 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 .= */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +int > +main (int argc, char **argv) > +{ > + pid_t pid =3D 0; > + pid_t ppid; > + char buf[1024*2 + 500]; > + int gotint, res; > + > + if (argc !=3D 4) > + { > + fprintf (stderr, "Syntax: %s {standard|detached} <= core output file>\n", > +=09 argv[0]); > + exit (1); > + } > + > + pid =3D fork (); > + > + switch (pid) > + { > + case 0: > +=09if (strcmp (argv[1], "detached") =3D=3D 0) > +=09 setpgrp (); > +=09ppid =3D getppid (); > +=09gotint =3D snprintf (buf, sizeof (buf), "sh %s -o %s %d", argv[2], ar= gv[3], (int) ppid); > +=09assert (gotint < sizeof (buf)); > +=09res =3D system (buf); > +=09assert (res !=3D -1); > +=09fprintf (stderr, "Killing parent PID %d\n", ppid); > +=09kill (ppid, SIGTERM); > +=09break; > + > + case -1: > +=09perror ("fork err\n"); > +=09exit (1); > +=09break; > + > + default: > +=09fprintf (stderr, "Sleeping as PID %d\n", getpid ()); > +=09/* Wait here until the child is done with gcore-ing us. If things go= right, > +=09 the child kills us with SIGTERM before this sleep returns. */ > +=09sleep (60); > + } > + > + return 0; > +} > diff --git a/gdb/testsuite/gdb.base/gcorebg.exp b/gdb/testsuite/gdb.base/= gcorebg.exp > new file mode 100644 > index 00000000000..bcfbe994c9e > --- /dev/null > +++ b/gdb/testsuite/gdb.base/gcorebg.exp > @@ -0,0 +1,81 @@ > +# Copyright 2007-2024 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 is a test for the gcore script (not the gcore command form > +# inside GDB). It also tests the gcore script being run without its > +# accessible terminal. > + > +standard_testfile > +require {!is_remote host} > +require {!is_remote target} > +require has_gcore_script > + > +set corefile [standard_output_file ${testfile}.core] > + > +if {[build_executable "failed to build" $testfile ${srcfile}] =3D=3D -1 = } { > + return -1 > +} > + > +# Cleanup. > + > +proc core_clean {} { > + global corefile > + > + foreach file [glob -nocomplain [join [list $corefile *] ""]] { > +=09verbose "Delete file $file" 1 > +=09remote_file target delete $file > + } > +} > +core_clean > + > +# Generate the core file. > +proc test_body { detached } { > + global binfile > + global GCORE > + global corefile > + > + with_test_prefix "detached =3D $detached" { > +=09# We can't use gdb_test_multiple here because GDB is not started. > +=09set res [remote_spawn target "$binfile $detached $GCORE $corefile"] > +=09if { $res < 0 || $res =3D=3D "" } { > +=09 fail "Spawning gcore" > +=09 return 1 > +=09} > +=09pass "Spawned gcore" > + > +=09remote_expect target 20 { > +=09 timeout { > +=09=09fail "Spawned gcore finished (timeout)" > +=09=09remote_exec target "kill -9 -[exp_pid -i $res]" > +=09=09return 1 > +=09 } > +=09 "Saved corefile .*\r\nKilling parent PID " { > +=09=09pass "Spawned gcore finished" > +=09 } > +=09} > + > +=09gdb_assert {1 =3D=3D [llength [glob -nocomplain [join [list $corefile= *] ""]]]} "Core file generated by gcore" > +=09core_clean > + } > +} > + > +# First a general gcore script spawn with its controlling terminal avail= able. > + > +test_body standard > + > +# And now gcore script spawn without its controlling terminal available. > +# It is spawned through `gcorebg.c' using setpgrp (). > + > +test_body detached > diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp > index 9a906f0f349..7943fcbbe74 100644 > --- a/gdb/testsuite/lib/gdb.exp > +++ b/gdb/testsuite/lib/gdb.exp > @@ -146,6 +146,23 @@ load_lib gdb-utils.exp > load_lib memory.exp > load_lib check-test-names.exp > =20 > +# The path to the GCORE script to test. > +global GCORE > +if ![info exists GCORE] { > + set GCORE [findfile $base_dir/../../gcore] This isn't going to find the gcore script in the build tree. For that you would need: set GCORE [findfile $base_dir/../../gdb/gcore] instead what you have will just result in GCORE being set to 'gcore', so we'll end up testing with whatever version of gcore happens to be installed on the machine, which is likely not what we want (be default). > +} else { > + set GCORE "" > +} Setting this means that we can't do: make check-gdb TESTS=3D"..." RUNTESTFLAGS=3D"GCORE=3D/path/to/gcore" So I think this should be dropped. > +verbose "using GCORE =3D $GCORE" 2 > + > +proc has_gcore_script {} { This proc should have a comment before it. However, if you fix the above and start testing the local gcore script, then you're going to spot a slightly bigger issue. When you run gcore it will correctly find the locally built gdb executable, but it doesn't pass the --data-directory option, so we end up with a bunch of errors from starting GDB. Now this doesn't actually cause any FAILs from your test, but I think we need to consider how to address this. I don't have a specific plan in mind, but I do have a couple of ideas. We could add a --data-directory=3D.... line to the built gcore script file, like: "$binary_path/gdb" + if { $::GCORE !=3D "" } { > +=09return 1 > + } else { > +=09return 0 > + } > +} > + > # The path to the GDB binary to test. > global GDB > =20 > --=20 > 2.43.0