From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13013 invoked by alias); 30 Aug 2013 14:40:45 -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 12998 invoked by uid 89); 30 Aug 2013 14:40:44 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 30 Aug 2013 14:40:44 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RDNS_NONE,TO_NO_BRKTS_NORDNS autolearn=no version=3.3.2 X-HELO: mga02.intel.com Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 30 Aug 2013 07:40:31 -0700 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 30 Aug 2013 07:40:24 -0700 Received: from ulliclel004.iul.intel.com (ulliclel004.iul.intel.com [172.28.50.125]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id r7UEeO7p004962; Fri, 30 Aug 2013 15:40:24 +0100 Received: from ulliclel004.iul.intel.com (ulliclel004.iul.intel.com [127.0.0.1]) by ulliclel004.iul.intel.com (8.13.8/8.12.8/MailSET/client) with ESMTP id r7UEeMrn015569; Fri, 30 Aug 2013 16:40:22 +0200 Received: (from sagovic@localhost) by ulliclel004.iul.intel.com (8.13.8/8.13.1/Submit) id r7UEeGCM015568; Fri, 30 Aug 2013 16:40:16 +0200 From: Sanimir Agovic To: gdb-patches@sourceware.org Cc: pmuldoon@redhat.com Subject: [PATCH 2/2] test: ensure certain types exposed to python are not instancable Date: Fri, 30 Aug 2013 14:40:00 -0000 Message-Id: <1377873604-15519-3-git-send-email-sanimir.agovic@intel.com> In-Reply-To: <1377873604-15519-1-git-send-email-sanimir.agovic@intel.com> References: <1377873604-15519-1-git-send-email-sanimir.agovic@intel.com> X-SW-Source: 2013-08/txt/msg00917.txt.bz2 The proc gdb_py_test_exception executes a piece of python code and expects an exception of type EXCEPTION to be raised by the code with an optional MESSAGE for fine grained filtering. # Example ... gdb_py_test_exception "gdb.Frame()" "TypeError" "cannot create 'gdb.Frame' instances" # ... w/o exception message gdb_py_test_exception "gdb.Frame()" "TypeError" # ... any exception gdb_py_test_exception "gdb.Frame()" 2013-08-30 Sanimir Agovic testsuite/ * lib/gdb-python.exp: Add proc gdb_py_test_exception. * gdb.python/py-arch.exp: Call gdb_py_test_exception gdb.Arhitecture. * gdb.python/py-block.exp: Call gdb_py_test_exception gdb.Block. * gdb.python/py-frame.exp: Call gdb_py_test_exception gdb.Frame. * gdb.python/py-inferior.exp: Call gdb_py_test_exception gdb.Inferior. * gdb.python/py-infthread.exp: Call gdb_py_test_exception gdb.Infthread. * gdb.python/py-progspace.exp: Use proc gdb_py_test_exception gdb.Progspace. * gdb.python/py-symtab.exp: Call gdb_py_test_exception gdb.Symtab and gdb_py_test_exception gdb.Symtab_and_line * gdb.python/py-type.exp: Call gdb_py_test_exception gdb.Type. Change-Id: I8dfb4b42b43dbc1e3bdcb85b56bb202c84eec608 --- gdb/testsuite/gdb.python/py-arch.exp | 2 ++ gdb/testsuite/gdb.python/py-block.exp | 2 ++ gdb/testsuite/gdb.python/py-frame.exp | 2 ++ gdb/testsuite/gdb.python/py-inferior.exp | 2 ++ gdb/testsuite/gdb.python/py-infthread.exp | 2 ++ gdb/testsuite/gdb.python/py-progspace.exp | 4 ++++ gdb/testsuite/gdb.python/py-symtab.exp | 3 +++ gdb/testsuite/gdb.python/py-type.exp | 2 ++ gdb/testsuite/lib/gdb-python.exp | 14 ++++++++++++++ 9 files changed, 33 insertions(+), 0 deletions(-) diff --git a/gdb/testsuite/gdb.python/py-arch.exp b/gdb/testsuite/gdb.python/py-arch.exp index 7413b44..9d4c2da 100644 --- a/gdb/testsuite/gdb.python/py-arch.exp +++ b/gdb/testsuite/gdb.python/py-arch.exp @@ -52,3 +52,5 @@ gdb_test "python print (\"length\" in insn)" "True" "test key length" # Negative test gdb_test "python arch.disassemble(0, 0)" ".*gdb\.MemoryError.*" \ "test exception" + +gdb_py_test_exception "gdb.Architecture()" "TypeError" diff --git a/gdb/testsuite/gdb.python/py-block.exp b/gdb/testsuite/gdb.python/py-block.exp index 138ca3d..d6923ca 100644 --- a/gdb/testsuite/gdb.python/py-block.exp +++ b/gdb/testsuite/gdb.python/py-block.exp @@ -85,3 +85,5 @@ gdb_test "python print (block.is_valid())" "False" \ "Check block validity" gdb_test "python print (block_iter.is_valid())" "False" \ "Check block validity" + +gdb_py_test_exception "gdb.Block()" "TypeError" diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp index 63e4afb..8136b18 100644 --- a/gdb/testsuite/gdb.python/py-frame.exp +++ b/gdb/testsuite/gdb.python/py-frame.exp @@ -94,3 +94,5 @@ gdb_test "python print ('result = %s' % f0.read_var ('variable_which_surely_does gdb_test "python print ('result = %s' % f0.read_var ('a'))" " = 1" "test Frame.read_var - success" gdb_test "python print ('result = %s' % (gdb.selected_frame () == f1))" " = True" "test gdb.selected_frame" + +gdb_py_test_exception "gdb.Frame()" "TypeError" diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index 4c1dba7..b86115b 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -231,3 +231,5 @@ gdb_test "inferior 3" ".*" "Switch to third inferior" gdb_test "py print (gdb.selected_inferior().num)" "3" "Third inferior selected" gdb_test "inferior 1" ".*" "Switch to first inferior" gdb_test_no_output "remove-inferiors 3" "Remove second inferior" + +gdb_py_test_exception "gdb.Inferior()" "TypeError" diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp index a26cdc1..0240a41 100644 --- a/gdb/testsuite/gdb.python/py-infthread.exp +++ b/gdb/testsuite/gdb.python/py-infthread.exp @@ -65,3 +65,5 @@ gdb_test "python print ('result = %s' % t0.is_exited ())" " = False" "test Infer gdb_test "python print ('result = %s' % t0.is_valid ())" " = True" "test InferiorThread.is_valid" gdb_test_no_output "kill inferior 1" "kill inferior 1" gdb_test "python print ('result = %s' % t0.is_valid ())" " = False" "test InferiorThread.is_valid" + +gdb_py_test_exception "gdb.InferiorThread()" "TypeError" diff --git a/gdb/testsuite/gdb.python/py-progspace.exp b/gdb/testsuite/gdb.python/py-progspace.exp index d101680..6e28adc 100644 --- a/gdb/testsuite/gdb.python/py-progspace.exp +++ b/gdb/testsuite/gdb.python/py-progspace.exp @@ -16,6 +16,8 @@ # This file is part of the GDB testsuite. It tests the program space # support in Python. +load_lib gdb-python.exp + standard_testfile if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} { @@ -39,3 +41,5 @@ gdb_load ${binfile} gdb_test "python print (gdb.current_progspace().filename)" "py-progspace" \ "current progspace filename (py-progspace)" + +gdb_py_test_exception "gdb.Progspace()" "TypeError" diff --git a/gdb/testsuite/gdb.python/py-symtab.exp b/gdb/testsuite/gdb.python/py-symtab.exp index f5279b1..b60eecc 100644 --- a/gdb/testsuite/gdb.python/py-symtab.exp +++ b/gdb/testsuite/gdb.python/py-symtab.exp @@ -76,3 +76,6 @@ gdb_test "python print (symtab.is_valid())" "False" "Test symtab.is_valid()" gdb_test_no_output "python sal = None" "Test sal destructor" gdb_test_no_output "python symtab = None" "Test symtab destructor" + +gdb_py_test_exception "gdb.Symtab()" "TypeError" +gdb_py_test_exception "gdb.Symtab_and_line()" "TypeError" diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp index f6b1d96..0da0940 100644 --- a/gdb/testsuite/gdb.python/py-type.exp +++ b/gdb/testsuite/gdb.python/py-type.exp @@ -254,3 +254,5 @@ with_test_prefix "lang_cpp" { test_template test_enums } + +gdb_py_test_exception "gdb.InferiorThread()" "TypeError" diff --git a/gdb/testsuite/lib/gdb-python.exp b/gdb/testsuite/lib/gdb-python.exp index 26ebf8f..1d6f229 100644 --- a/gdb/testsuite/lib/gdb-python.exp +++ b/gdb/testsuite/lib/gdb-python.exp @@ -45,3 +45,17 @@ proc gdb_py_test_multiple { name args } { } return 0 } + +# Usage: gdb_py_test_exception STMT {EXCEPTION} {MESSAGE} +# Executes python code named STMT which is expected to throw EXCEPTION +# with MESSAGE. + +proc gdb_py_test_exception { stmt {exception "Exception"} {message .*} } { + gdb_py_test_multiple "$stmt throws $exception" \ + "python" "" \ + "try:" "" \ + " $stmt" "" \ + "except $exception as e:" "" \ + " print \"$exception\",e.message" "" \ + "end" "$exception $message" +} -- 1.7.1.1