From patchwork Sun Jul 21 23:54:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 33759 Received: (qmail 107099 invoked by alias); 21 Jul 2019 23:54:49 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 107031 invoked by uid 89); 21 Jul 2019 23:54:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 21 Jul 2019 23:54:46 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DBB1F30C1324 for ; Sun, 21 Jul 2019 23:54:45 +0000 (UTC) Received: from f30-1.lan (ovpn-117-224.phx2.redhat.com [10.3.117.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id B21075DC1A; Sun, 21 Jul 2019 23:54:45 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Cc: Kevin Buettner Subject: [PATCH 3/3] Tests for Python -P commandline support Date: Sun, 21 Jul 2019 16:54:27 -0700 Message-Id: <20190721235427.21893-4-kevinb@redhat.com> In-Reply-To: <20190721235427.21893-1-kevinb@redhat.com> References: <20190721235427.21893-1-kevinb@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes gdb/testsuite/ChangeLog: * gdb.python/py-script.c: New file. * gdb.python/py-script.exp: New file. * gdb.python/py-script.py: New file. --- gdb/testsuite/gdb.python/py-script.c | 27 ++++++++++++++ gdb/testsuite/gdb.python/py-script.exp | 51 ++++++++++++++++++++++++++ gdb/testsuite/gdb.python/py-script.py | 25 +++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 gdb/testsuite/gdb.python/py-script.c create mode 100644 gdb/testsuite/gdb.python/py-script.exp create mode 100644 gdb/testsuite/gdb.python/py-script.py diff --git a/gdb/testsuite/gdb.python/py-script.c b/gdb/testsuite/gdb.python/py-script.c new file mode 100644 index 0000000000..bff3a5edf5 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-script.c @@ -0,0 +1,27 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2019 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 program is intended to be started outside of gdb, and then + attached to by gdb. It loops for a while, but not forever. */ + +#include + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.python/py-script.exp b/gdb/testsuite/gdb.python/py-script.exp new file mode 100644 index 0000000000..fc5b87cb34 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-script.exp @@ -0,0 +1,51 @@ +# Copyright (C) 2019 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 is part of the GDB testsuite. It tests the loading +# and execution of scripts specified on the GDB command line. + +load_lib gdb-python.exp + +standard_testfile + +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { + return -1 +} + +set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py] +save_vars { GDBFLAGS } { + append GDBFLAGS " -P $pyfile" + clean_restart ${binfile} +} + +if ![runto_main] then { + perror "couldn't run to breakpoint" + continue +} + +# Skip all tests if Python scripting is not enabled. +if { [skip_python_tests] } { continue } + +gdb_test "python print(gdb.script_var1)" "script var 1" +gdb_test "python print(gdb.script_var2)" "script var 2" + +save_vars { GDBFLAGS } { + append GDBFLAGS " -P $pyfile first_arg second_arg third_arg" + clean_restart ${binfile} +} + +gdb_test "python print(gdb.script_args\[0\])" "first_arg" +gdb_test "python print(gdb.script_args\[1\])" "second_arg" +gdb_test "python print(gdb.script_args\[2\])" "third_arg" diff --git a/gdb/testsuite/gdb.python/py-script.py b/gdb/testsuite/gdb.python/py-script.py new file mode 100644 index 0000000000..4bbd5ba593 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-script.py @@ -0,0 +1,25 @@ +# Copyright (C) 2019 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 is part of the GDB testsuite. It tests the loading +# and execution of a Python script specified on the GDB command line. + +import gdb +import sys + +gdb.script_var1 = "script var 1" +gdb.script_var2 = "script var 2" + +gdb.script_args = list(sys.argv)