From patchwork Mon Apr 22 12:12:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= X-Patchwork-Id: 88861 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EB12B384AB54 for ; Mon, 22 Apr 2024 12:14:44 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail0.khirnov.net (mail0.khirnov.net [IPv6:2001:67c:1138:4304::3]) by sourceware.org (Postfix) with ESMTPS id 65F373858D35 for ; Mon, 22 Apr 2024 12:14:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 65F373858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=khirnov.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=khirnov.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 65F373858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:1138:4304::3 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713788063; cv=none; b=Nex9A3XghFi8fSwSnrr2KsvgTdTxEH1riPFSgMD1rkm1XClGsEAtMrzkWKgVlaK4w3/E9EbgJAW9x/1QJN3B94IYSPhVDsaFYMKIHqvkftcIqoBcqmWnTMTtGKZxBTs6l0jWXjO3dWtOguIksQY6Ah1IojLyAdFdAPtegGX2YeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713788063; c=relaxed/simple; bh=aDKkudb+UzugRySCmrFaJMRBnSesvZmX8aVlKUG+WrU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gW9V1tET4tgY8H3zYvnD26iqlJUcHtfOhYfFwGOqrUge74/7MAg2rFerWeA9xIY9SGwQsek3hRZXy3DKnrrVbNhaK2WANA4xyHbikM6DkStDRB6WjC84qeTbZYLWCeywL0pdg90gjtJzMRsCRR5aAyqo0c1oZPNkS1KPxAgwTtU= ARC-Authentication-Results: i=1; server2.sourceware.org Authentication-Results: mail0.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=QiwAqkhQ; dkim-atps=neutral Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9A99B240DAC; Mon, 22 Apr 2024 14:14:17 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id jsb_gkdL_fgO; Mon, 22 Apr 2024 14:14:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1713788054; bh=aDKkudb+UzugRySCmrFaJMRBnSesvZmX8aVlKUG+WrU=; h=From:To:Cc:Subject:Date:From; b=QiwAqkhQMceeoveUA6tcuHroGFkjw7+IOCzPmgFBF1ZymDOkzbEb5OGqk59IsLiHN iBkBeeodGawNRFuKZVtoSurz4brTmRWv3siUmDWX9ZfHN9zVOtnHV6JO0NZbKOwasM W9cB6WeGfIXWUruwBd369Zma9G65755cBBtNpp3WqMcEGjPjEfHrd+FXGH4Ik0JIwP aCQNDodmSp7dg1HXN+gcCfJEc/qRyWok40p7uTF81W9NHpScuJDljOdglJK1PgPd52 DHiibnh4u2bKKVIeR6xacaN4W4yiSboHNJJcTDCcuhSaLQpKaAtN2nF6TNc6M0HtdB EjwZ8XvcuZs/g== Received: from fedora.khirnov.net (ip-244-183.pel.cz [IPv6:2002:b061:f0a:201::d5e2:f4b7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "sasshka SMTP cert", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id EB0EB2404E5; Mon, 22 Apr 2024 14:14:13 +0200 (CEST) Received: from fedora.redhat.com (localhost [IPv6:::1]) by fedora.khirnov.net (Postfix) with ESMTP id 47A36864C93; Mon, 22 Apr 2024 14:14:11 +0200 (CEST) From: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= To: gdb-patches@sourceware.org Cc: ahajkova@redhat.com Subject: [PATCH v2] Add a test for the gcore script Date: Mon, 22 Apr 2024 14:12:07 +0200 Message-ID: <20240422121409.1520569-1-ahajkova@khirnov.net> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org From: Alexandra Hájková 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. Modify the gcore script to make it possible to pass the --data-directory to it. This prevents a lot of these warnings: Python Exception : module 'gdb' has no attribute '_handle_missing_debuginfo' Tested by using make check-all-boards. Co-Authored-By: Jan Kratochvil --- v2: - added a -d option to the gcore script to make it possbile to pass the --data-directory to it - changed the gcorebg.c to use pipe intead of sleep - added more comments - added has_gcore_script proc to the lib/gdb.exp gdb/gcore.in | 9 ++- gdb/testsuite/gdb.base/gcorebg.c | 85 +++++++++++++++++++++++++++++ gdb/testsuite/gdb.base/gcorebg.exp | 88 ++++++++++++++++++++++++++++++ gdb/testsuite/lib/gdb.exp | 17 ++++++ 4 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.base/gcorebg.c create mode 100644 gdb/testsuite/gdb.base/gcorebg.exp diff --git a/gdb/gcore.in b/gdb/gcore.in index 982c854eb70..291b807bed9 100644 --- a/gdb/gcore.in +++ b/gdb/gcore.in @@ -27,7 +27,9 @@ prefix=core # to ensure gdb dumps all mappings (OS dependent). dump_all_cmds=() -while getopts :ao: opt; do +DATA_DIRECTORY_OPT="" + +while getopts :ao:d: opt; do case "$opt" in a) case "$OSTYPE" in @@ -40,8 +42,12 @@ while getopts :ao: opt; do o) prefix=$OPTARG ;; + d) + DATA_DIRECTORY_OPT="--data-directory $OPTARG" + ;; *) echo "usage: @GCORE_TRANSFORM_NAME@ [-a] [-o prefix] pid1 [pid2...pidN]" + echo "DATA_DIRECTORY_OPT: $DATA_DIRECTORY_OPT" exit 2 ;; esac @@ -98,6 +104,7 @@ do # `. */ + +#include +#include +#include +#include +#include +#include +#include + +/* Expects 4 arguments: + + 1. Either 'standard' or 'detached', where 'standard' tests + a general gcore script spawn with its controlling terminal available + and 'detached' tests gcore script spawn without its controlling + terminal available. + 2. Path to the gcore script + 3. Path to the data-directory to pass to the gcore script + 4. The core file output name + +*/ + +int +main (int argc, char **argv) +{ + pid_t pid = 0; + pid_t ppid; + char buf[1024*2 + 500]; + int gotint, res; + int fd[2]; + + assert (argc == 5); + + if (pipe(fd) == -1) + { + perror ("pipe err\n"); + exit (1); + } + pid = fork (); + + switch (pid) + { + case 0: + close (fd[0]); + if (strcmp (argv[1], "detached") == 0) + setpgrp (); + ppid = getppid (); + gotint = snprintf (buf, sizeof (buf), "sh %s -d %s -o %s %d", + argv[2], argv[3], argv[4], (int) ppid); + assert (gotint < sizeof (buf)); + res = system (buf); + assert (res != -1); + close(fd[1]); + break; + + case -1: + close (fd[0]); + close (fd[1]); + perror ("fork err\n"); + exit (1); + break; + + default: + close (fd[1]); + res = read (fd[0], buf, 1); + assert (res == 0); + close (fd[0]); + break; + } + + return 0; +} diff --git a/gdb/testsuite/gdb.base/gcorebg.exp b/gdb/testsuite/gdb.base/gcorebg.exp new file mode 100644 index 00000000000..6269988133c --- /dev/null +++ b/gdb/testsuite/gdb.base/gcorebg.exp @@ -0,0 +1,88 @@ +# 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}] == -1 } { + return -1 +} + +# Cleanup. + +proc core_clean {} { + global corefile + + foreach file [glob -nocomplain [join [list $corefile *] ""]] { + verbose "Delete file $file" 1 + remote_file target delete $file + } +} +core_clean + +# Generate the core file. +proc test_body { detached } { + global binfile + global GCORE + global corefile + global GDB_DATA_DIRECTORY + + with_test_prefix "detached = $detached" { + # We can't use gdb_test_multiple here because GDB is not started. + set res [remote_spawn target "$binfile $detached $GCORE $GDB_DATA_DIRECTORY $corefile"] + if { $res < 0 || $res == "" } { + fail "Spawning gcore" + return 1 + } + pass "Spawned gcore" + + set saw_corefile_created false + set testname "Spawned gcore finished" + remote_expect target 20 { + timeout { + fail "$testname (timeout)" + remote_exec target "kill -9 -[exp_pid -i $res]" + return + } + -re "Saved corefile \[^\r\n\]+\r\n" { + set saw_corefile_created true + exp_continue + } + eof { + gdb_assert { $saw_corefile_created } $testname + } + } + + gdb_assert {1 == [llength [glob -nocomplain [join [list $corefile *] ""]]]} "Core file generated by gcore" + core_clean + } +} + +# First a general gcore script spawn with its controlling terminal available. + +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 ddee928d510..e8c38869cee 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -158,6 +158,23 @@ load_lib gdb-utils.exp load_lib memory.exp load_lib check-test-names.exp +# The path to the GCORE script to test. +global GCORE +if ![info exists GCORE] { + set GCORE [findfile $base_dir/../../gdb/gcore] +} else { + set GCORE "" +} +verbose "using GCORE = $GCORE" 2 + +proc has_gcore_script {} { + if {[info exists ::GCORE]} { + return 1 + } else { + return 0 + } +} + # The path to the GDB binary to test. global GDB