From patchwork Thu Apr 18 15:23:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Vrany X-Patchwork-Id: 32333 Received: (qmail 24976 invoked by alias); 18 Apr 2019 15:24:34 -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 24910 invoked by uid 89); 18 Apr 2019 15:24:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.1 spammy=world X-HELO: relay.fit.cvut.cz Received: from relay.fit.cvut.cz (HELO relay.fit.cvut.cz) (147.32.232.237) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 18 Apr 2019 15:24:29 +0000 Received: from imap.fit.cvut.cz (imap.fit.cvut.cz [147.32.232.238]) by relay.fit.cvut.cz (8.15.2/8.15.2) with ESMTPS id x3IFOJCN093725 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 18 Apr 2019 17:24:21 +0200 (CEST) (envelope-from jan.vrany@fit.cvut.cz) Received: from localhost (02d97c6d.bb.sky.com [2.217.124.109] (may be forged)) (authenticated bits=0 as user vranyj1) by imap.fit.cvut.cz (8.15.2/8.15.2) with ESMTPSA id x3IFOJvZ060413 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Thu, 18 Apr 2019 17:24:19 +0200 (CEST) (envelope-from jan.vrany@fit.cvut.cz) From: Jan Vrany To: gdb-patches@sourceware.org Cc: Jan Vrany Subject: [RFC 7/8] mi/python: Add tests for python-defined MI commands Date: Thu, 18 Apr 2019 16:23:36 +0100 Message-Id: <20190418152337.6376-8-jan.vrany@fit.cvut.cz> In-Reply-To: <20190418152337.6376-1-jan.vrany@fit.cvut.cz> References: <20190418152337.6376-1-jan.vrany@fit.cvut.cz> MIME-Version: 1.0 gdb/testsuite/Changelog: * gdb.python/py-mi-cmd.exp: New file. * gdb.python/py-mi-cmd-1.py: New file. --- gdb/testsuite/ChangeLog | 5 ++ gdb/testsuite/gdb.python/py-mi-cmd-1.py | 27 +++++++++ gdb/testsuite/gdb.python/py-mi-cmd.exp | 77 +++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 gdb/testsuite/gdb.python/py-mi-cmd-1.py create mode 100644 gdb/testsuite/gdb.python/py-mi-cmd.exp diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index d46422635b..a71b3f25db 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-12-10 Jan Vrany + + * gdb.python/py-mi-cmd.exp: New file. + * gdb.python/py-mi-cmd-1.py: New file. + 2019-04-15 Leszek Swirski * gdb.arch/amd64-eval.cc: New file. diff --git a/gdb/testsuite/gdb.python/py-mi-cmd-1.py b/gdb/testsuite/gdb.python/py-mi-cmd-1.py new file mode 100644 index 0000000000..2e73c022a3 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-mi-cmd-1.py @@ -0,0 +1,27 @@ +import gdb + +class pycmd(gdb.MICommand): + def invoke(self, argv): + if argv[0] == 'int': + return 42 + elif argv[0] == 'str': + return "Hello world!" + elif argv[0] == 'ary': + return [ 'Hello', 42 ] + elif argv[0] == "dct": + return { 'hello' : 'world', 'times' : 42} + elif argv[0] == 'tpl': + return ( 42 , 'Hello' ) + elif argv[0] == 'itr': + return iter([1,2,3]) + elif argv[0] == 'nn1': + return None + elif argv[0] == 'nn2': + return [ None ] + elif argv[0] == 'exp': + raise gdb.GdbError() + else: + raise gdb.GdbError("Invalid parameter: %s" % argv[0]) + +pycmd('-pycmd') + diff --git a/gdb/testsuite/gdb.python/py-mi-cmd.exp b/gdb/testsuite/gdb.python/py-mi-cmd.exp new file mode 100644 index 0000000000..17afb6c83e --- /dev/null +++ b/gdb/testsuite/gdb.python/py-mi-cmd.exp @@ -0,0 +1,77 @@ +# Copyright (C) 2018 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 . + +# Tests whether -var-info-path-expression fails as documented when +# invoked on a dynamic varobj. + +load_lib mi-support.exp +set MIFLAGS "-i=mi2" + +gdb_exit +if {[mi_gdb_start]} { + continue +} + +mi_gdb_test "set python print-stack full" \ + ".*\\^done" \ + "set python print-stack full" + +standard_testfile +# +# Start here +# +mi_gdb_test "source ${srcdir}/${subdir}/${testfile}-1.py" \ + ".*\\^done" \ + "load python file" + + +mi_gdb_test "-pycmd int" \ + "\\^done,result=\"42\"" \ + "-pycmd int" + +mi_gdb_test "-pycmd str" \ + "\\^done,result=\"Hello world!\"" \ + "-pycmd str" + +mi_gdb_test "-pycmd ary" \ + "\\^done,result=\\\[\"Hello\",\"42\"\\\]" \ + "-pycmd ary" + +mi_gdb_test "-pycmd dct" \ + "\\^done,result={hello=\"world\",times=\"42\"}" \ + "-pycmd dct" + +mi_gdb_test "-pycmd tpl" \ + "\\^done,result=\\\[\"42\",\"Hello\"\\\]" \ + "-pycmd tpl" + +mi_gdb_test "-pycmd itr" \ + "\\^done,result=\\\[\"1\",\"2\",\"3\"\\\]" \ + "-pycmd itr" + +mi_gdb_test "-pycmd nn1" \ + "\\^done" \ + "-pycmd nn1" + +mi_gdb_test "-pycmd nn2" \ + "\\^done,result=\\\[\"None\"\\\]" \ + "-pycmd nn2" + +mi_gdb_test "-pycmd bogus" \ + "\\^error,msg=\"Invalid parameter: bogus\"" \ + "-pycmd bogus" + +mi_gdb_test "-pycmd exp" \ + "\\^error,msg=\"Failed to execute command\"" \ + "-pycmd exp"