From patchwork Sat Jan 21 04:52:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 18979 Received: (qmail 90335 invoked by alias); 21 Jan 2017 04:52:57 -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 90319 invoked by uid 89); 21 Jan 2017 04:52:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL, BAYES_00, SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=568, break-here, breakhere, HCc:D*ca X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 21 Jan 2017 04:52:46 +0000 X-ASG-Debug-ID: 1484974363-0c856e65d512b1740001-fS2M51 Received: from smtp.electronicbox.net (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id Q7wVpy1tHTSKnVr3 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 20 Jan 2017 23:52:44 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (cable-11.246.173-162.electronicbox.net [173.246.11.162]) by smtp.electronicbox.net (Postfix) with ESMTP id D9D1E440E7C; Fri, 20 Jan 2017 23:52:43 -0500 (EST) From: Simon Marchi X-Barracuda-Effective-Source-IP: cable-11.246.173-162.electronicbox.net[173.246.11.162] X-Barracuda-Apparent-Source-IP: 173.246.11.162 X-Barracuda-RBL-IP: 173.246.11.162 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] Change method of loading .py files in Python tests Date: Fri, 20 Jan 2017 23:52:43 -0500 X-ASG-Orig-Subj: [PATCH] Change method of loading .py files in Python tests Message-Id: <20170121045243.1435-1-simon.marchi@polymtl.ca> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1484974364 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 11848 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 2.00 X-Barracuda-Spam-Status: No, SCORE=2.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_RULE7568M, BSF_SC0_MISMATCH_TO, BSF_SC0_MV0713, BSF_SC0_MV0713_2 X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.35962 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 BSF_SC0_MISMATCH_TO Envelope rcpt doesn't match header 0.50 BSF_RULE7568M Custom Rule 7568M 1.00 BSF_SC0_MV0713_2 BSF_SC0_MV0713_2 0.50 BSF_SC0_MV0713 Custom rule MV0713 X-IsSubscribed: yes With my debug build of Python (--with-pydebug), many tests fails because of the same issue. Python scripts are loaded by the tests using this pattern: (gdb) python exec (open ('file.py').read ()) This causes Python to output this warning: __main__:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='file.py' mode='r' encoding='ANSI_X3.4-1968'> and the test to fail because of that extra output. Instead of using the open + read + exec trick which leaks the file and causes the warning, why not just source the files? (gdb) source file.py This patch changes this, and standardizes the test names of the tests I touched to "load python file" (some of them were empty, others were overly complicated). gdb/testsuite/ChangeLog: * gdb.python/py-bad-printers.exp: Load python file using "source". * gdb.python/py-events.exp: Likewise. * gdb.python/py-evsignal.exp: Likewise. * gdb.python/py-evthreads.exp: Likewise. * gdb.python/py-frame-args.exp: Likewise. * gdb.python/py-framefilter-invalidarg.exp: Likewise. * gdb.python/py-framefilter-mi.exp: Likewise. * gdb.python/py-framefilter.exp: Likewise. * gdb.python/py-mi.exp: Likewise. * gdb.python/py-pp-maint.exp: Likewise. * gdb.python/py-pp-registration.exp: Likewise. * gdb.python/py-prettyprint.exp: Likewise. (run_lang_tests): Likewise. * gdb.python/py-typeprint.exp: Likewise. --- gdb/testsuite/gdb.python/py-bad-printers.exp | 3 +-- gdb/testsuite/gdb.python/py-events.exp | 2 +- gdb/testsuite/gdb.python/py-evsignal.exp | 2 +- gdb/testsuite/gdb.python/py-evthreads.exp | 2 +- gdb/testsuite/gdb.python/py-frame-args.exp | 3 +-- gdb/testsuite/gdb.python/py-framefilter-invalidarg.exp | 3 +-- gdb/testsuite/gdb.python/py-framefilter-mi.exp | 3 +-- gdb/testsuite/gdb.python/py-framefilter.exp | 6 ++---- gdb/testsuite/gdb.python/py-mi.exp | 2 +- gdb/testsuite/gdb.python/py-pp-maint.exp | 2 +- gdb/testsuite/gdb.python/py-pp-registration.exp | 3 +-- gdb/testsuite/gdb.python/py-prettyprint.exp | 6 ++---- gdb/testsuite/gdb.python/py-typeprint.exp | 3 +-- 13 files changed, 15 insertions(+), 25 deletions(-) diff --git a/gdb/testsuite/gdb.python/py-bad-printers.exp b/gdb/testsuite/gdb.python/py-bad-printers.exp index ecc259edac..0e39763791 100644 --- a/gdb/testsuite/gdb.python/py-bad-printers.exp +++ b/gdb/testsuite/gdb.python/py-bad-printers.exp @@ -35,8 +35,7 @@ if ![runto_main ] then { set remote_python_file [gdb_remote_download host \ ${srcdir}/${subdir}/${testfile}.py] -gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \ - "load python file" +gdb_test_no_output "source ${remote_python_file}" "load python file" gdb_breakpoint [gdb_get_line_number "break here"] gdb_continue_to_breakpoint "break here" ".* break here .*" diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp index 12936f3609..16ea110737 100644 --- a/gdb/testsuite/gdb.python/py-events.exp +++ b/gdb/testsuite/gdb.python/py-events.exp @@ -43,7 +43,7 @@ clean_restart ${testfile} if { [skip_python_tests] } { continue } -gdb_test_no_output "python exec (open ('${pyfile}').read ())" "" +gdb_test_no_output "source ${pyfile}" "load python file" gdb_test "test-objfile-events" "Object file events registered." diff --git a/gdb/testsuite/gdb.python/py-evsignal.exp b/gdb/testsuite/gdb.python/py-evsignal.exp index 65a558ca5f..8a39f4eacb 100644 --- a/gdb/testsuite/gdb.python/py-evsignal.exp +++ b/gdb/testsuite/gdb.python/py-evsignal.exp @@ -31,7 +31,7 @@ clean_restart $testfile if { [skip_python_tests] } { continue } -gdb_test_no_output "python exec (open ('${pyfile}').read ())" "" +gdb_test_no_output "source ${pyfile}" "load python file" gdb_test "test-events" "Event testers registered." gdb_test_no_output "set non-stop on" diff --git a/gdb/testsuite/gdb.python/py-evthreads.exp b/gdb/testsuite/gdb.python/py-evthreads.exp index 1ebab40318..64b2af5fef 100644 --- a/gdb/testsuite/gdb.python/py-evthreads.exp +++ b/gdb/testsuite/gdb.python/py-evthreads.exp @@ -36,7 +36,7 @@ clean_restart $testfile if { [skip_python_tests] } { continue } -gdb_test_no_output "python exec (open ('${pyfile}').read ())" "" +gdb_test_no_output "source ${pyfile}" "load python file" gdb_test "test-events" "Event testers registered." gdb_test_no_output "set non-stop on" diff --git a/gdb/testsuite/gdb.python/py-frame-args.exp b/gdb/testsuite/gdb.python/py-frame-args.exp index 91f200f4f3..08f2171633 100644 --- a/gdb/testsuite/gdb.python/py-frame-args.exp +++ b/gdb/testsuite/gdb.python/py-frame-args.exp @@ -29,8 +29,7 @@ if ![runto_main] { set remote_python_file [gdb_remote_download host \ ${srcdir}/${subdir}/${testfile}.py] -gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \ - "python exec (open ('[file tail ${remote_python_file}]').read ())" +gdb_test_no_output "source ${remote_python_file}" "load python file" gdb_breakpoint [gdb_get_line_number "break-here"] gdb_continue_to_breakpoint "break-here" ".* break-here .*" diff --git a/gdb/testsuite/gdb.python/py-framefilter-invalidarg.exp b/gdb/testsuite/gdb.python/py-framefilter-invalidarg.exp index bf9d0767ad..881ebe4ed8 100644 --- a/gdb/testsuite/gdb.python/py-framefilter-invalidarg.exp +++ b/gdb/testsuite/gdb.python/py-framefilter-invalidarg.exp @@ -61,7 +61,6 @@ gdb_test_no_output "set python print-stack full" \ # Load global frame-filters set remote_python_file [gdb_remote_download host \ ${srcdir}/${subdir}/${testfile}.py] -gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \ - "load python file" +gdb_test_no_output "source ${remote_python_file}" "load python file" gdb_test "bt" " in niam \\(argc=, argv=0x\[0-9a-f\]+\\) at py-framefilter-invalidarg.c:\[0-9\]+" "bt full with filters" diff --git a/gdb/testsuite/gdb.python/py-framefilter-mi.exp b/gdb/testsuite/gdb.python/py-framefilter-mi.exp index eef7a1ea8e..91e07dd10a 100644 --- a/gdb/testsuite/gdb.python/py-framefilter-mi.exp +++ b/gdb/testsuite/gdb.python/py-framefilter-mi.exp @@ -46,8 +46,7 @@ mi_runto main set remote_python_file [gdb_remote_download host ${srcdir}/${subdir}/${pyfile}] -mi_gdb_test "python exec (open ('${remote_python_file}').read ())" ".*\\^done." \ - "Load python file" +mi_gdb_test "source ${remote_python_file}" ".*\\^done." "load python file" # Multiple blocks test mi_continue_to_line [gdb_get_line_number {Inner test breakpoint} ${srcfile}] \ diff --git a/gdb/testsuite/gdb.python/py-framefilter.exp b/gdb/testsuite/gdb.python/py-framefilter.exp index 76184c0ce0..bad4d7cc19 100644 --- a/gdb/testsuite/gdb.python/py-framefilter.exp +++ b/gdb/testsuite/gdb.python/py-framefilter.exp @@ -63,8 +63,7 @@ gdb_test_no_output "set python print-stack full" \ # Load global frame-filters set remote_python_file [gdb_remote_download host \ ${srcdir}/${subdir}/${testfile}.py] -gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \ - "load python file" +gdb_test_no_output "source ${remote_python_file}" "load python file" gdb_breakpoint [gdb_get_line_number "Backtrace end breakpoint"] gdb_breakpoint [gdb_get_line_number "Inner test breakpoint"] @@ -253,8 +252,7 @@ gdb_test_no_output "set python print-stack full" \ # Load global frame-filters set remote_python_file [gdb_remote_download host \ ${srcdir}/${subdir}/${testfile}.py] -gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \ - "load python file for no debuginfo tests" +gdb_test_no_output "source ${remote_python_file}" "load python file for no debuginfo tests" # Disable Reverse gdb_test_no_output "disable frame-filter global Reverse" \ diff --git a/gdb/testsuite/gdb.python/py-mi.exp b/gdb/testsuite/gdb.python/py-mi.exp index 920e9d678e..736dc7a0d6 100644 --- a/gdb/testsuite/gdb.python/py-mi.exp +++ b/gdb/testsuite/gdb.python/py-mi.exp @@ -44,7 +44,7 @@ mi_runto main set remote_python_file [gdb_remote_download host ${srcdir}/${subdir}/${pyfile}] -mi_gdb_test "python exec (open ('${remote_python_file}').read ())" "" +mi_gdb_test "source ${remote_python_file}" "load python file" mi_continue_to_line [gdb_get_line_number {MI breakpoint here} ${srcfile}] \ "step to breakpoint" diff --git a/gdb/testsuite/gdb.python/py-pp-maint.exp b/gdb/testsuite/gdb.python/py-pp-maint.exp index ba0d0f04fe..6ca0ee6b56 100644 --- a/gdb/testsuite/gdb.python/py-pp-maint.exp +++ b/gdb/testsuite/gdb.python/py-pp-maint.exp @@ -43,7 +43,7 @@ gdb_test "continue" ".*Breakpoint.*" set python_file ${srcdir}/${subdir}/${testfile}.py -gdb_test_no_output "python exec (open ('${python_file}').read ())" "" +gdb_test_no_output "source ${python_file}" "load python file" gdb_test "info pretty-printer" \ {.*function_lookup_test.*pp-test.*struct ss.*} diff --git a/gdb/testsuite/gdb.python/py-pp-registration.exp b/gdb/testsuite/gdb.python/py-pp-registration.exp index def44160ac..0bd6d871db 100644 --- a/gdb/testsuite/gdb.python/py-pp-registration.exp +++ b/gdb/testsuite/gdb.python/py-pp-registration.exp @@ -46,8 +46,7 @@ proc prepare_test { } { return 0 } - gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \ - "read file" + gdb_test_no_output "source ${remote_python_file}" "read file" gdb_test_no_output "py progspace = gdb.current_progspace()" gdb_test_no_output "py my_pretty_printer1 = build_pretty_printer1()" diff --git a/gdb/testsuite/gdb.python/py-prettyprint.exp b/gdb/testsuite/gdb.python/py-prettyprint.exp index 2ba2a8f6ce..b0a9e32df6 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint.exp +++ b/gdb/testsuite/gdb.python/py-prettyprint.exp @@ -56,8 +56,7 @@ proc run_lang_tests {exefile lang} { set remote_python_file [gdb_remote_download host \ ${srcdir}/${subdir}/${testfile}.py] - gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \ - "python exec (open ('[file tail ${remote_python_file}]').read ())" + gdb_test_no_output "source ${remote_python_file}" "load python file" gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>" gdb_test "print ssa\[1\]" " = a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>" @@ -137,8 +136,7 @@ if ![runto_main ] then { set remote_python_file [gdb_remote_download host \ ${srcdir}/${subdir}/${testfile}.py] -gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \ - "python exec (open ('[file tail ${remote_python_file}]').read ())" +gdb_test_no_output "source ${remote_python_file}" "load python file" gdb_breakpoint [gdb_get_line_number "eval-break"] gdb_continue_to_breakpoint "eval-break" ".* eval-break .*" diff --git a/gdb/testsuite/gdb.python/py-typeprint.exp b/gdb/testsuite/gdb.python/py-typeprint.exp index 73db732c3d..28e505331f 100644 --- a/gdb/testsuite/gdb.python/py-typeprint.exp +++ b/gdb/testsuite/gdb.python/py-typeprint.exp @@ -29,8 +29,7 @@ if { [skip_python_tests] } { continue } set remote_python_file [gdb_remote_download host \ ${srcdir}/${subdir}/${testfile}.py] -gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" \ - "python exec (open ('[file tail ${remote_python_file}]').read ())" +gdb_test_no_output "source ${remote_python_file}" "load python file" cp_test_ptype_class s "basic test" "class" "templ" { { field public "T x;" }