From: Alan Hayward <Alan.Hayward@arm.com>
To: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Cc: nd <nd@arm.com>, Alan Hayward <Alan.Hayward@arm.com>
Subject: [PATCH 8/9] testsuite: Add script to quickly re-run tests
Date: Tue, 14 May 2019 15:13:00 -0000 [thread overview]
Message-ID: <20190514151238.8765-9-alan.hayward@arm.com> (raw)
In-Reply-To: <20190514151238.8765-1-alan.hayward@arm.com>
Using the .cmd and .in files created by a test it is fairly simple
to manually re-run a test. For gdbserver tests, the .replay log
can also be used.
Document the process required to do this.
In addition create a script to automate the process.
2019-05-14 Alan Hayward <alan.hayward@arm.com>
* README (Re-running Tests Outside The Testsuite): New section.
* lib/gdbserver-support.exp (gdbserver_run): Mark kill as optional.
* replaytest: New test.
---
gdb/testsuite/README | 23 ++++
gdb/testsuite/lib/gdbserver-support.exp | 2 +-
gdb/testsuite/replaytest | 147 ++++++++++++++++++++++++
3 files changed, 171 insertions(+), 1 deletion(-)
create mode 100755 gdb/testsuite/replaytest
diff --git a/gdb/testsuite/README b/gdb/testsuite/README
index 98fc8d1b852..b5fbb456bee 100644
--- a/gdb/testsuite/README
+++ b/gdb/testsuite/README
@@ -95,6 +95,29 @@ example:
The script will output its analysis report to the standard output.
+Re-running Tests Outside The Testsuite
+**************************************
+
+When running a test, the arguments used to run GDB are saved to gdb.cmd
+and any commands sent to GDB are saved to gdb.in. As well as being a
+reference of the commands run, they can be used to manually re-run a test
+by giving the .in file as a batch file to a GDB launched with the arguments
+in the .cmd file. For many tests you can use just the .in file:
+ $ gdb -x gdb.in
+
+Tests that run GDB multiple times will append .1, .2, .3 etc to the end
+of each .cmd and .in file.
+
+For tests requiring gdbserver, this can by executing the contents of
+gdbserver.cmd. Alternatively, the gdbserver.replay file (created when
+running the test with GDBSERVER_DEBUG="replay") can be used with the
+gdbreplay test.
+
+This process can be automated with the "replaytest" script.
+For example:
+ $ replaytest gdb testsuite/outputs/gdb.base/store
+For more details see the documentation in the script.
+
Running the Performance Tests
*****************************
diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp
index 2ccc717ef60..ade99c0ea16 100644
--- a/gdb/testsuite/lib/gdbserver-support.exp
+++ b/gdb/testsuite/lib/gdbserver-support.exp
@@ -484,7 +484,7 @@ proc gdbserver_run { child_args } {
# Kill anything running before we try to start gdbserver, in case
# we are sharing a serial connection.
global gdb_prompt
- send_gdb "kill\n"
+ send_gdb "kill\n" optional
gdb_expect 120 {
-re "Kill the program being debugged. .y or n. $" {
send_gdb "y\n"
diff --git a/gdb/testsuite/replaytest b/gdb/testsuite/replaytest
new file mode 100755
index 00000000000..4c11d9735f3
--- /dev/null
+++ b/gdb/testsuite/replaytest
@@ -0,0 +1,147 @@
+#!/bin/bash
+
+# Copyright (C) 2019 Free Software Foundation, Inc.
+#
+# This file is part of GDB.
+#
+# 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 script uses GDB to replay previously run tests using the .in and
+# .cmd files from the output directory of a test.
+#
+# For example:
+# $ replaytest gdb testsuite/outputs/gdb.base/store
+#
+#
+# For tests that have been runing using gdbserver (for example with
+# board file native-gdbserver), the test script should be run in two
+# terminals, using gdbserver and gdb modes.
+#
+# For example, in two different terminals:
+# $ replaytest -b gdbserver testsuite/outputs/gdb.base/store
+# $ replaytest -b gdb testsuite/outputs/gdb.base/store
+#
+# Alternatively, instead of running gdbserver, the gdbreplay tool can
+# be used instead. This uses the .replay file which is created when the
+# test is run with GDBSERVER_DEBUG="replay". gdbreplay must be in your
+# $PATH.
+#
+#
+# Tests that run GDB (and gdbserver) multiple times will create .1, .2
+# .3 etc files for each instance of GDB. You can run a specified
+# instance using the -i flag
+#
+# For example:
+# $ replaytest -b -i 23 gdb testsuite/outputs/gdb.base/infcall-nested-structs
+#
+# Note that to successfully run to the end of the test, the .in file must be
+# free from the answers to any interactive gdb prompts (for example the y from
+# a y/n question) or any command that causes gdb to report an error.
+#
+#
+# Usage: replaytest [-b] [-i instance] [-e] {gdb|gdbserver|replay} test_output_dir
+#
+# -b : Run GDB in batch mode (ie: exit GDB at the end of the test).
+# -i : Run the given instance of the test. Defaults to 0.
+# -e : Don't run the test, just echo the command line instead.
+#
+# test_output_dir : Directory containing all the test output files.
+#
+
+usage()
+{
+ echo "$0 [-b] [-i instance] [-e] {gdb|gdbserver|replay} test_output_dir"
+ exit 2
+}
+
+# Check file $1 exists, using test operator $2 (defaults to -e).
+check_exists()
+{
+ if [ ! ${2:-"-e"} "${1}" ]; then echo Error: Cannot find $1; exit 2; fi
+}
+
+# Run the given command in $1...n
+execute()
+{
+ if [ -n "$ECHO" ]
+ then
+ echo $@
+ else
+ # Pipe the command we want to run to a file then execute the file. This
+ # ensures spaces within quoatation marks args get interpreted correctly.
+ OUTFILE=$(mktemp)
+ echo $@ > ${OUTFILE}
+ bash ${OUTFILE}
+ rm ${OUTFILE}
+ fi
+}
+
+# Parse command line
+while getopts bi:e line
+do
+ case $line in
+ b) EXTRA_GDBCMD="${EXTRA_GDBCMD} --batch";;
+ i) INSTANCE=".$OPTARG";;
+ e) ECHO=1;;
+ *) usage;;
+ esac
+done
+shift $(($OPTIND - 1))
+if [[ $# -ne 2 ]]; then usage; fi;
+MODE=$1
+TESTDIR=$2
+check_exists ${TESTDIR} -d
+
+
+case $MODE in
+
+"gdb")
+ # Run the .in file through GDB by appending it to the end of the .cmd contents.
+ CMDFILE=${TESTDIR}/gdb.cmd${INSTANCE}
+ INFILE=${TESTDIR}/gdb.in${INSTANCE}
+ check_exists ${CMDFILE}
+ check_exists ${INFILE}
+ execute "$(cat $CMDFILE) ${EXTRA_GDBCMD} -x ${INFILE}"
+ ;;
+
+"gdbserver")
+ # Run gdbserver using the .cmd file.
+ GDBSERVER_CMDFILE=${TESTDIR}/gdbserver.cmd${INSTANCE}
+ check_exists ${GDBSERVER_CMDFILE}
+ execute $(cat $GDBSERVER_CMDFILE)
+ ;;
+
+"replay")
+ GDBSERVER_REPLAYFILE=${TESTDIR}/gdbserver.replay${INSTANCE}
+ check_exists ${GDBSERVER_REPLAYFILE}
+
+ # Extract the connection from the .cmd file.
+ GDBSERVER_CMDFILE=${TESTDIR}/gdbserver.cmd${INSTANCE}
+ check_exists ${GDBSERVER_CMDFILE}
+ GDBSERVER_HOST=$(grep -o '[^ ]*:[^ ]*' ${GDBSERVER_CMDFILE})
+
+ # Run the .replay file through gdbreplay.
+ execute gdbreplay ${GDBSERVER_REPLAYFILE} ${GDBSERVER_HOST}
+ ;;
+
+*)
+ echo "Unknown mode $MODE"
+ usage
+ ;;
+
+esac
+
+
+
--
2.20.1 (Apple Git-117)
next prev parent reply other threads:[~2019-05-14 15:13 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-14 15:12 [PATCH 0/9] Create gdb.debug, gdb.cmd and gdb.in files when running the testsuite Alan Hayward
2019-05-14 15:12 ` [PATCH 1/9] Change file close behavior for tee_file Alan Hayward
2019-05-16 18:57 ` Tom Tromey
2019-05-14 15:12 ` [PATCH 3/9] testsuite: Add option to capture GDB debug Alan Hayward
2019-05-16 19:16 ` Tom Tromey
2019-05-14 15:13 ` [PATCH 9/9] testsuite: Remove TRANSCRIPT support Alan Hayward
2019-05-16 19:38 ` Tom Tromey
2019-05-14 15:13 ` [PATCH 2/9] Add debug redirect option Alan Hayward
2019-05-16 19:12 ` Tom Tromey
2019-05-17 13:21 ` Alan Hayward
2019-05-18 18:11 ` Tom Tromey
2019-05-14 15:13 ` Alan Hayward [this message]
2019-05-14 15:13 ` [PATCH 5/9] testsuite: Record all gdb input to gdb.in Alan Hayward
2019-05-16 19:25 ` Tom Tromey
2019-05-17 15:35 ` Alan Hayward
2019-05-14 15:13 ` [PATCH 4/9] testsuite: Disable some tests when logging Alan Hayward
2019-05-16 19:19 ` Tom Tromey
2019-05-17 14:36 ` Alan Hayward
2019-05-14 15:13 ` [PATCH 7/9] testsuite: Add replay logging to GDBSERVER_DEBUG Alan Hayward
2019-05-16 19:34 ` Tom Tromey
2019-05-14 15:13 ` [PATCH 6/9] testsuite: Create .cmd files for gdb and gdbserver Alan Hayward
2019-05-16 19:28 ` Tom Tromey
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=20190514151238.8765-9-alan.hayward@arm.com \
--to=alan.hayward@arm.com \
--cc=gdb-patches@sourceware.org \
--cc=nd@arm.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).