From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29331 invoked by alias); 27 Jul 2017 08:50:45 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 29240 invoked by uid 89); 27 Jul 2017 08:50:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy= X-HELO: einhorn-mail.in-berlin.de Received: from einhorn-mail.in-berlin.de (HELO einhorn-mail.in-berlin.de) (217.197.80.20) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Jul 2017 08:50:40 +0000 X-Envelope-From: doko@ubuntu.com Received: from [192.168.178.30] (ip5f5bd694.dynamic.kabel-deutschland.de [95.91.214.148]) (authenticated bits=0) by einhorn.in-berlin.de (8.14.4/8.14.4/Debian-8+deb8u2) with ESMTP id v6R8oGe5007193 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Jul 2017 10:50:16 +0200 Subject: Re: [PATCH 1/2] Introduce testsuite support to run Python tests To: Pierre-Marie de Rodat , gcc-patches@gcc.gnu.org References: <20170726160040.6516-1-derodat@adacore.com> <20170726160040.6516-2-derodat@adacore.com> From: Matthias Klose Message-ID: <28e5006d-92e6-d6dc-992d-690db28daa85@ubuntu.com> Date: Thu, 27 Jul 2017 08:50:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170726160040.6516-2-derodat@adacore.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-07/txt/msg01784.txt.bz2 you are unconditionally hard coding python as the interpreter, which on most distributions points to 2.7. Please check python3 as well and make that the preferred interpreter if available. python 2.7 is now EOL'd for 2020. Matthias On 26.07.2017 18:00, Pierre-Marie de Rodat wrote: > gcc/testsuite/ > > * lib/gcc-python.exp: New test library. > * python/testutils.py: New Python helper. > --- > gcc/testsuite/lib/gcc-python.exp | 95 +++++++++++++++++++++++++++++++++++++++ > gcc/testsuite/python/testutils.py | 45 +++++++++++++++++++ > 2 files changed, 140 insertions(+) > create mode 100644 gcc/testsuite/lib/gcc-python.exp > create mode 100644 gcc/testsuite/python/testutils.py > > diff --git a/gcc/testsuite/lib/gcc-python.exp b/gcc/testsuite/lib/gcc-python.exp > new file mode 100644 > index 00000000000..30cf74a87ac > --- /dev/null > +++ b/gcc/testsuite/lib/gcc-python.exp > @@ -0,0 +1,95 @@ > +# Copyright (C) 2017 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 GCC; see the file COPYING3. If not see > +# . > + > +# Helpers to run a Python interpreter > + > +load_lib "remote.exp" > + > +# Return whether a working Python interpreter is available. > + > +proc check-python-available { args } { > + set result [local_exec "python -c print(\"Hello\")" "" "" 300] > + > + set status [lindex $result 0] > + set output [string trim [lindex $result 1]] > + > + if { $status != 0 || $output != "Hello" } { > + return 0 > + } else { > + return 1 > + } > +} > + > +# Run the SCRIPT_PY Python script. Add one PASSing (FAILing) test per output > +# line that starts with "PASS: " ("FAIL: "). Also fail for any other output > +# line and for non-zero exit status code. > +# > +# The Python script can access Python modules and packages in the > +# $srcdir/python directory. > + > +proc python-test { script_py } { > + global srcdir > + > + set testname testname-for-summary > + > + # This assumes that we are three frames down from dg-test, and that > + # it still stores the filename of the testcase in a local variable "name". > + # A cleaner solution would require a new DejaGnu release. > + upvar 2 prog src_file > + > + set asm_file "[file rootname [file tail $src_file]].o" > + set script_py_path "[file dirname $src_file]/$script_py" > + > + set old_pythonpath [getenv "PYTHONPATH"] > + set support_dir "$srcdir/python" > + if { $old_pythonpath == "" } { > + setenv "PYTHONPATH" $support_dir > + } else { > + setenv "PYTHONPATH" "$support_dir:$PYTHONPATH" > + } > + > + set commandline "python $script_py_path $asm_file" > + set timeout 300 > + > + verbose -log "Executing: $commandline (timeout = $timeout)" 2 > + set result [local_exec $commandline "" "" $timeout] > + > + set status [lindex $result 0] > + set output [lindex $result 1] > + > + if { $status != 0 } { > + fail [concat "$testname: $script_py stopped with non-zero status" \ > + " code ($status)"] > + } > + > + foreach line [split $output "\n"] { > + if { $line == "" } { > + continue > + } > + if { [regexp "^PASS: (.*)" $line dummy message] } { > + pass "$testname/$script_py: $message" > + continue > + } > + if { [regexp "^FAIL: (.*)" $line dummy message] } { > + fail "$testname/$script_py: $message" > + continue > + } > + > + fail "$testname/$script_py: spurious output: $line" > + } > + > + setenv "PYTHONPATH" $old_pythonpath > +} > diff --git a/gcc/testsuite/python/testutils.py b/gcc/testsuite/python/testutils.py > new file mode 100644 > index 00000000000..503105ad9d0 > --- /dev/null > +++ b/gcc/testsuite/python/testutils.py > @@ -0,0 +1,45 @@ > +# Copyright (C) 2017 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 GCC; see the file COPYING3. If not see > +# . > + > +# Helpers to drive a testcase > + > +def print_pass(message): > + """Emit a PASS message. > + > + :param str message: Message to emit. > + """ > + print('PASS: {}'.format(message)) > + > + > +def print_fail(message): > + """Emit a FAIL message. > + > + :param str message: Message to emit. > + """ > + print('FAIL: {}'.format(message)) > + > + > +def check(predicate, message): > + """ > + If `predicate` is True, emit a PASS message, otherwise emit a FAIL one. > + > + :param bool predicate: Whether the test should pass. > + :param str message: Message to emit. > + """ > + if predicate: > + print_pass(message) > + else: > + print_fail(message) >