From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25646 invoked by alias); 24 Aug 2011 15:12:02 -0000 Received: (qmail 25435 invoked by uid 22791); 24 Aug 2011 15:11:57 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,TW_BJ,TW_RG,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-yx0-f169.google.com (HELO mail-yx0-f169.google.com) (209.85.213.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 24 Aug 2011 15:11:22 +0000 Received: by yxn35 with SMTP id 35so998297yxn.0 for ; Wed, 24 Aug 2011 08:11:21 -0700 (PDT) Received: by 10.90.19.10 with SMTP id 10mr4994819ags.133.1314198681641; Wed, 24 Aug 2011 08:11:21 -0700 (PDT) Received: from localhost.localdomain (c-98-232-221-4.hsd1.or.comcast.net [98.232.221.4]) by mx.google.com with ESMTPS id d7sm968071anb.40.2011.08.24.08.11.20 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 24 Aug 2011 08:11:21 -0700 (PDT) From: matt rice To: gdb-patches@sourceware.org Cc: matt rice Subject: [PATCH 7/7] [python] API for macros: Add tests. Date: Wed, 24 Aug 2011 15:12:00 -0000 Message-Id: <1314198654-9008-8-git-send-email-ratmice@gmail.com> In-Reply-To: <1314198654-9008-1-git-send-email-ratmice@gmail.com> References: <1314198654-9008-1-git-send-email-ratmice@gmail.com> X-IsSubscribed: yes 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 X-SW-Source: 2011-08/txt/msg00445.txt.bz2 2011-08-23 Matt Rice PR python/10807 * gdb.python/py-macro.exp: Ditto. * gdb.python/py-macro.c: New file. --- gdb/testsuite/gdb.python/py-macro.c | 87 +++++++++ gdb/testsuite/gdb.python/py-macro.exp | 338 +++++++++++++++++++++++++++++++++ 2 files changed, 425 insertions(+), 0 deletions(-) create mode 100644 gdb/testsuite/gdb.python/py-macro.c create mode 100644 gdb/testsuite/gdb.python/py-macro.exp diff --git a/gdb/testsuite/gdb.python/py-macro.c b/gdb/testsuite/gdb.python/py-macro.c new file mode 100644 index 0000000..3397eb5 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-macro.c @@ -0,0 +1,87 @@ +/* Copyright (C) 2011 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 . */ + +#ifdef DEF_MACROS + + #ifdef ONE + #ifdef FOO + #undef FOO + #endif + + #define FOO "hello" + #else + #undef FOO + #endif + + + #ifdef TWO + #ifdef FOO + #undef FOO + #endif + #define FOO " " + #endif + + #ifdef THREE + #ifdef FOO + #undef FOO + #endif + #define FOO(a,b) + #endif + + #ifdef FOUR + #ifdef FOO + #undef FOO + #endif + #define FOO(a) foo = a + #endif +#else + +int main (int argc, const char **argv) +{ + char *foo; + + #define DEF_MACROS + #define ONE + #include "py-macro.c" + foo = FOO; + + #define TWO + #include "py-macro.c" + foo = FOO; + + #define THREE + #include "py-macro.c" + foo = "world"FOO(0,1); + + #undef THREE + #include "py-macro.c" + foo = FOO; + + #undef TWO + #include "py-macro.c" + foo = FOO; + + #undef ONE + #include "py-macro.c" + foo = (char *)0; + + #define FOUR + #include "py-macro.c" + FOO ("the end."); + + return 0; +} +#endif + diff --git a/gdb/testsuite/gdb.python/py-macro.exp b/gdb/testsuite/gdb.python/py-macro.exp new file mode 100644 index 0000000..203e1b4 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-macro.exp @@ -0,0 +1,338 @@ +# Copyright (C) 2011 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 mechanism +# exposing macros to Python. + +if $tracelevel then { + strace $tracelevel +} + +load_lib gdb-python.exp + +gdb_start +# Skip all tests if Python scripting is not enabled. +if { [skip_python_tests] } { continue } + +set testfile "py-macro" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} +get_compiler_info ${binfile} +if [test_compiler_info gcc*] { + lappend options additional_flags=-g3 +} else { + untested ${testfile}.exp + return -1 +} + +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} $options] } { + untested ${testfile}.exp + return -1 +} + +# Start with a fresh gdb. +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + + +gdb_py_test_multiple "setup macro test objects" \ + "python" "" \ + "def find_objfile():" "" \ + " for objfile in gdb.objfiles():" "" \ + " if objfile.filename == \"$binfile\":" "" \ + " print objfile.filename" "" \ + " return objfile" "" \ + "def here_macro(name):" "" \ + " return gdb.decode_line(\"*\$pc\")\[1\]\[0\].macro_named(name)" "" \ + "macros = list()" "" \ + "end" "" + +gdb_test "python objfile = find_objfile()" "$binfile" "found objfile" +gdb_test "python print objfile.symtabs()" \ + "\\\[\\\]" "symtabs is empty" + +if ![runto_main] { + untested ${testfile}.exp + return -1 +} + +gdb_py_test_silent_cmd "python m = objfile.symtabs()\[0\].macros()" "get all macros" 1 + +gdb_py_test_silent_cmd "python include_guard = here_macro(\"DEF_MACROS\")" \ + "get guard macro #1" \ + 1 + +gdb_test "python print include_guard.is_valid()" \ + "True" \ + "guard is valid" + +gdb_test "python print include_guard.name() == \"DEF_MACROS\"" \ + "True" \ + "guard name" + +gdb_test "python print include_guard.is_function_like() == False" \ + "True" \ + "guard isnt function like" + +gdb_test "python print include_guard.argv() == None" \ + "True" \ + "guard has no args" + +gdb_test "python print 'foo' + include_guard.definition() + 'bar'" \ + "foobar" \ + "guard definition is empty" + +gdb_test "python print include_guard.include_trail()\[0\]\[0\]" \ + "$srcfile.*" \ + "guard trail has srcfile" + +# +gdb_test "python print include_guard" \ +"" \ +"guard string rep" + +gdb_py_test_silent_cmd "python macros.append(include_guard)" \ + "add to macros list" \ + 0 + +gdb_py_test_silent_cmd "python foo = here_macro(\"FOO\")" \ + "get FOO macro #1" \ + 1 + +gdb_test "python print foo.is_valid()" \ + "True" \ + "FOO macro #1 is valid" + +gdb_test "python print foo.name()" \ + "FOO" \ + "FOO macro #1 name" + +gdb_test "python print foo.is_function_like()" \ + "False" \ + "FOO macro #1 isnt function like" + +gdb_test "python print foo.argv()" \ + "None" \ + "FOO macro #1 has no args" + +gdb_test "python print foo.definition()" \ + "\"hello\"" \ + "FOO macro #1 definition is \"hello\"" + +gdb_test "python print include_guard.include_trail()\[0\]\[0\]" \ + "$srcfile.*" \ + "FOO macro #1 has srcfile" + +gdb_test "python print foo" \ +"" \ +"FOO macro #1 string rep" + +gdb_py_test_silent_cmd "python macros.append(foo)" \ + "add to macros list" \ + 0 + +gdb_test "next" "" "" +gdb_py_test_silent_cmd "python foo = here_macro(\"FOO\")" \ + "get FOO macro #2" \ + 1 + +gdb_test "python print foo.is_valid()" \ + "True" \ + "FOO macro #2 is valid" + +gdb_test "python print foo.name()" \ + "FOO" \ + "FOO macro #2 name" + +gdb_test "python print foo.is_function_like()" \ + "False" \ + "FOO macro #2 isnt function like" + +gdb_test "python print foo.argv()" \ + "None" \ + "FOO macro #2 has no args" + +gdb_test "python print foo.definition()" \ + "\" \"" \ + "FOO macro #2 definition is \" \"" + +gdb_test "python print foo.include_trail()\[0\]\[0\]" \ + "$srcfile.*" \ + "FOO macro #2 has srcfile" + +gdb_test "python print foo" \ +"" \ +"FOO macro #2 string rep" + +gdb_py_test_silent_cmd "python macros.append(foo)" \ + "add to macros list" \ + 0 + +gdb_test "next" "" "" +gdb_py_test_silent_cmd "python foo = here_macro(\"FOO\")" \ + "get FOO macro #3" \ + 1 +gdb_test "python print foo.is_valid()" \ + "True" \ + "FOO macro #3 is valid" + +gdb_test "python print foo.name()" \ + "FOO" \ + "FOO macro #3 name" + +gdb_test "python print foo.is_function_like()" \ + "True" \ + "FOO macro #3 is function like" + +gdb_test "python print foo.argv()" \ + "\\\['a', 'b'\\\]" \ + "FOO macro #3 has args" + +gdb_test "python print 'foo' + foo.definition() + 'bar'" \ + "foobar" \ + "FOO macro #3 definition is empty" + +gdb_test "python print include_guard.include_trail()\[0\]\[0\]" \ + "$srcfile.*" \ + "FOO macro #3 has srcfile" + +gdb_test "python print foo" \ +"" \ +"FOO macro #3 string rep" + +gdb_py_test_silent_cmd "python macros.append(foo)" \ + "add to macros list" \ + 0 +gdb_test "next" "" "" +gdb_test "next" "" "" +gdb_test "next" "" "" +gdb_py_test_silent_cmd "python foo = here_macro(\"FOO\")" \ + "get FOO macro #4" \ + 1 +gdb_test "python print foo" \ + "None" \ + "there is no Foo macro #4" + +gdb_test "next" "" "" +gdb_py_test_silent_cmd "python foo = here_macro(\"FOO\")" \ + "get FOO macro #5" \ + 1 + +gdb_test "python print foo.is_valid()" \ + "True" \ + "FOO macro #5 is valid" + +gdb_test "python print foo.name()" \ + "" \ + "FOO macro #5 name" + +gdb_test "python print foo.is_function_like()" \ + "True" \ + "FOO macro #5 is function like" + +gdb_test "python print foo.argv()" \ + "\\\['a'\\\]" \ + "FOO macro #5 has args" + +gdb_test "python print foo.definition()" \ + "foo = a" \ + "FOO macro #5 definition ok" + +gdb_test "python print include_guard.include_trail()\[0\]\[0\]" \ + "$srcfile.*" \ + "FOO macro #5 has srcfile" + +gdb_test "python print foo" \ +"" \ +"FOO macro #5 string rep" +gdb_py_test_silent_cmd "python macros.append(foo)" \ + "add to macros list" \ + 0 + +# this could find some ref count bugs if they were to happen for a singleton. +gdb_py_test_multiple "run macros a couple of times" \ + "python" "" \ + "c = 0" "" \ + "while c > 3:" "" \ + " c = c + 1" "" \ + " for macro in objfile.symtabs()\[0\].macros():" "" \ + " macro.name()" "" \ + " macro.is_function_like()" "" \ + " macro.argv()" "" \ + " macro.include_path()" "" \ + " macro.definition()" "" \ + " str(macro)" "" \ + " hash(macro)" "" \ + "end" "" + +gdb_py_test_multiple "find selected macros in the big list of macros" \ + "python" "" \ + "set1 = set(objfile.symtabs()\[0\].macros())" "" \ + "set2 = set(macros)" "" \ + "intersect = (set1 & set2)" "" \ + "set3 = set(filter(lambda(x): x.name() == \"FOO\", objfile.symtabs()\[0\].macros()))" "" \ + "intersect2 = (set3 & set2)" "" \ + "print \"set2\", map(lambda(x): x.name(), set2)" "" \ + "print \"set3\", map(lambda(x): x.name(), set3)" "" \ + "print \"intersect\", map(lambda(x): x.name(), intersect)" "" \ + "print \"intersect2\", map(lambda(x): x.name(), intersect2)" "" \ + "print \"set2 - intersect\", map(lambda(x): x.name(), set2 - intersect)" "" \ + "print \"intersect - set2\", map(lambda(x): x.name(), intersect - set2)" "" \ + "print \"set2 - intersect2\", map(lambda(x): x.name(), set2 - intersect2)" "" \ + "print \"intersect2 - set2\", map(lambda(x): x.name(), intersect2 - set2)" "" \ + "end" "" + +gdb_test "python print len(set2)" "5" "macro set length 5" +gdb_test "python print len(set1) > len(set2)" "True" "all macros is longer." +gdb_test "python print set1 >= set2" "True" "macro set2 is a subset" +gdb_test "python print len(intersect - set2), len(set2 - intersect)" \ + "0 0" \ + "macro set intersection equality" +gdb_test "python print len(intersect2 - set2)" \ + "0" \ + "macro set intersection equality 2" +gdb_test "python print len(set2 - intersect2), (set2 - intersect2).pop()" \ + "1 " \ + "macro set intersection 3" + +gdb_unload +# test is_valid() +gdb_test "python print include_guard.is_valid()" "False" \ + "guard macro is invalid after unload" + +gdb_test "python print foo.is_valid()" "False" \ + "foo macro is invalid after unload" + +# test individual method's to make sure they throw exceptions. +gdb_test "python print foo.argv()" "Macro is invalid.*" \ + "foo argv method is invalid after unload" + +gdb_test "python print foo.definition()" "Macro is invalid.*" \ + "foo definition method is invalid after unload" + +gdb_test "python print foo.include_trail()" "Macro is invalid.*" \ + "foo include_trail method is invalid after unload" + +gdb_test "python print foo.is_function_like()" "Macro is invalid.*" \ + "foo is_function_like method is invalid after unload" + +gdb_test "python print foo.name()" "Macro is invalid.*" \ + "foo name method is invalid after unload" + +gdb_test "python print str(foo)" "Macro is invalid.*" \ + "str(foo) method is invalid after unload" + -- 1.7.4.4