From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 73923 invoked by alias); 18 Jun 2019 20:11:33 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 73915 invoked by uid 89); 18 Jun 2019 20:11:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=1132, forget X-HELO: mail-wr1-f68.google.com Received: from mail-wr1-f68.google.com (HELO mail-wr1-f68.google.com) (209.85.221.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Jun 2019 20:11:31 +0000 Received: by mail-wr1-f68.google.com with SMTP id k11so888763wrl.1 for ; Tue, 18 Jun 2019 13:11:30 -0700 (PDT) Return-Path: Received: from ?IPv6:2001:8a0:f913:f700:56ee:75ff:fe8d:232b? ([2001:8a0:f913:f700:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id g5sm17112136wrp.29.2019.06.18.13.11.28 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jun 2019 13:11:28 -0700 (PDT) Subject: Re: [PATCH v3 5/5] mi/python: Add tests for python-defined MI commands To: Jan Vrany , gdb-patches@sourceware.org References: <20190128124101.26243-1-jan.vrany@fit.cvut.cz> <20190530134850.3236-6-jan.vrany@fit.cvut.cz> From: Pedro Alves Message-ID: <63d633a0-8deb-bbed-83ef-44ba536c024e@redhat.com> Date: Tue, 18 Jun 2019 20:11:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20190530134850.3236-6-jan.vrany@fit.cvut.cz> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2019-06/txt/msg00357.txt.bz2 On 5/30/19 2:48 PM, Jan Vrany wrote: > gdb/testsuite/Changelog: > > * gdb.python/py-mi-cmd.exp: New file. > * gdb.python/py-mi-cmd.py: New file. > --- > gdb/testsuite/ChangeLog | 5 + > gdb/testsuite/gdb.python/py-mi-cmd.exp | 132 +++++++++++++++++++++++++ > gdb/testsuite/gdb.python/py-mi-cmd.py | 54 ++++++++++ > 3 files changed, 191 insertions(+) > create mode 100644 gdb/testsuite/gdb.python/py-mi-cmd.exp > create mode 100644 gdb/testsuite/gdb.python/py-mi-cmd.py > > diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog > index ba657cc615..26d14996f4 100644 > --- a/gdb/testsuite/ChangeLog > +++ b/gdb/testsuite/ChangeLog > @@ -1,3 +1,8 @@ > +2019-05-03 Jan Vrany > + > + * gdb.python/py-mi-cmd.exp: New file. > + * gdb.python/py-mi-cmd.py: New file. > + > 2019-05-24 Tom de Vries > > * gdb.dwarf2/gdb-add-index.exp: New file. > 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..ba8670d5ea > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-mi-cmd.exp > @@ -0,0 +1,132 @@ > +# Copyright (C) 2018 Free Software Foundation, Inc. Don't forget to update the copyright years. > +# 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 . > + > +# Test custom MI commands implemented in Python. > + > +load_lib gdb-python.exp > +load_lib mi-support.exp > +set MIFLAGS "-i=mi2" > + > +gdb_exit > +if {[mi_gdb_start]} { > + continue > +} > + > +if {[lsearch -exact [mi_get_features] python] < 0} { > + unsupported "python support is disabled" > + return -1 > +} > + > +standard_testfile > +# > +# Start here > +# > + Empty line after standard_testfile. > + > +mi_gdb_test "set python print-stack full" \ > + ".*\\^done" \ > + "set python print-stack full" > + > +mi_gdb_test "source ${srcdir}/${subdir}/${testfile}.py" \ > + ".*\\^done" \ > + "load python file" > + > +mi_gdb_test "python pycmd1('-pycmd')" \ > + ".*\\^done" \ > + "Define -pycmd MI command" Lowercase "define". > + > + > +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 bk1" \ > + "\\^error,msg=\"Non-string object used as key: Bad Kay.\"" \ Is "Kay" a typo or on purpose? Also, escape the "." (throughout). > + "-pycmd bk1" > + > +mi_gdb_test "-pycmd bk2" \ > + "\\^error,msg=\"Non-string object used as key: 1.\"" \ > + "-pycmd bk2" > + > +mi_gdb_test "-pycmd bk3" \ > + "\\^error,msg=\"Non-string object used as key: __repr__ returned non-string .*" \ > + "-pycmd bk3" > + > +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=\"-pycmd: Invalid parameter: bogus\"" \ > + "-pycmd bogus" > + > +mi_gdb_test "-pycmd exp" \ > + "\\^error,msg=\"-pycmd: failed to execute command\"" \ > + "-pycmd exp" > + > +mi_gdb_test "python pycmd2('-pycmd')" \ > + ".*\\^done" \ > + "Redefine -pycmd MI command from CLI command" lowercase "Redefine". > + > +mi_gdb_test "-pycmd str" \ > + "\\^done,result=\"Ciao!\"" \ > + "-pycmd str" > + > +mi_gdb_test "-pycmd int" \ > + "\\^error,msg=\"-pycmd: Invalid parameter: int\"" \ > + "-pycmd int" > + > +mi_gdb_test "-pycmd red" \ > + "\\^error,msg=\"-pycmd: Command redefined but we failing anyway\"" \ "but we're failing anyway" ? > + "Redefine -pycmd MI command from Python MI command" Ditto re. lowercase. > + > +mi_gdb_test "-pycmd int" \ > + "\\^done,result=\"42\"" \ > + "-pycmd int" You have duplicated test names. See: https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Make_sure_test_messages_are_unique > + > +mi_gdb_test "python pycmd1('')" \ > + ".*\\^error,msg=\"MI command name is empty.\"" \ > + "empty MI command name" > + > +mi_gdb_test "python pycmd1('-')" \ > + ".*\\^error,msg=\"MI command name does not start with '-' followed by at least one letter or digit.\"" \ > + "invalid MI command name" > + > +mi_gdb_test "python pycmd1('-bad-character-@')" \ > + ".*\\^error,msg=\"MI command name contains invalid character: @.\"" \ > + "invalid character in MI command name" > diff --git a/gdb/testsuite/gdb.python/py-mi-cmd.py b/gdb/testsuite/gdb.python/py-mi-cmd.py > new file mode 100644 > index 0000000000..24aa475095 > --- /dev/null > +++ b/gdb/testsuite/gdb.python/py-mi-cmd.py > @@ -0,0 +1,54 @@ > +import gdb > + Missing copyright header. > +class BadKey: > + def __repr__(self): > + return "Bad Kay" > + > +class ReallyBadKey: > + def __repr__(self): > + return BadKey() > + > + > +class pycmd1(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] == "bk1": > + return { BadKey() : 'world' } > + elif argv[0] == "bk2": > + return { 1 : 'world' } > + elif argv[0] == "bk3": > + return { ReallyBadKey() : 'world' } > + 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] == 'red': > + pycmd2('-pycmd') > + return None > + elif argv[0] == 'exp': > + raise gdb.GdbError() > + else: > + raise gdb.GdbError("Invalid parameter: %s" % argv[0]) > + > + > +class pycmd2(gdb.MICommand): > + def invoke(self, argv): > + if argv[0] == 'str': > + return "Ciao!" > + elif argv[0] == 'red': > + pycmd1('-pycmd') > + raise gdb.GdbError("Command redefined but we failing anyway") > + else: > + raise gdb.GdbError("Invalid parameter: %s" % argv[0]) > + > Thanks, Pedro Alves