Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1408912imu; Sat, 26 Jan 2019 02:10:21 -0800 (PST) X-Google-Smtp-Source: ALg8bN5gSgctmtUt4ZgNOscOB8aEcXfDSoNUipxtxDPp4bQ0+RQZV7dElfo/B07BXrhp6bdDY51f X-Received: by 2002:a62:5486:: with SMTP id i128mr14057836pfb.215.1548497421890; Sat, 26 Jan 2019 02:10:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548497421; cv=none; d=google.com; s=arc-20160816; b=zwjt5e+6lA3UTyx3YzX/fPFDThNN8YCp9N/hkBE/isG15e5YxoG3/JA4xq3FihN5vD C8r+2U3/AvvajiGxLX6WBe7GU81pF5ZsicJU+hYBBeieOkS92JBz9xTm5/u5xNACb/rk k5lDkyrf9OcJs99OyBlcU6gIQMBId2q36P2SpcFGXnUyU3i48il+d19gaWz7oIPQDxb9 BlvRuqvQJyOzW9smVvR/H7Fgd37ua0Te3Tac6bjnKZkfUaAH71+T1EO/uSOBWqdFiwng g3Z8H4DT93/41Yi1Lh5yARYRQT68Mv8hzlNaGt5h6lwx1jP4tt7nU39Qg/Drui+qIJn9 eSVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=Ne+S+V96GkEl6BjEMaBrFB7XrNKSVE1qqWifg9bbgjM=; b=0NzY1mvYQVmIb6oMtQTxrAWwcscU6YKAmJo4GWCG4hyfAxkppshujScyz8aQ6HCTlL XkQ2dASOIS+Y9LTK/49OJA8+pJ6OhFVhsk1DrR7+uuTmBVk2bWr2iUB6rzAtj+et8hCV v7hHuSROVSNtBXGGpcqbkEpzL4ylHUwRm1A4PohihnlzLE8/3PPieli6lcAtWqXdrR30 5KTJmPUaatykWSwib3bpAQLHpZf7zbXGW6m/bnlX+P7BMU0ArthpUJ48RjSQroJeIkDz sQBqs86S06iuQ8Owk86qWRjfYObxd3ZHrz+QDtW2O95MNXlA4i2T4Qh1RoFt99Oi1cdD WkQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l7si3725560plg.390.2019.01.26.02.10.07; Sat, 26 Jan 2019 02:10:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729556AbfAZKJt (ORCPT + 99 others); Sat, 26 Jan 2019 05:09:49 -0500 Received: from terminus.zytor.com ([198.137.202.136]:59273 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726143AbfAZKJt (ORCPT ); Sat, 26 Jan 2019 05:09:49 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x0QA9dG3513709 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sat, 26 Jan 2019 02:09:39 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x0QA9cCw513706; Sat, 26 Jan 2019 02:09:38 -0800 Date: Sat, 26 Jan 2019 02:09:38 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Tony Jones Message-ID: Cc: s1seetee@linux.vnet.ibm.com, acme@redhat.com, hpa@zytor.com, ravi.bangoria@linux.ibm.com, linux-kernel@vger.kernel.org, mingo@kernel.org, tonyj@suse.de, corbet@lwn.net, tglx@linutronix.de, jolsa@kernel.org Reply-To: jolsa@kernel.org, tglx@linutronix.de, corbet@lwn.net, tonyj@suse.de, linux-kernel@vger.kernel.org, mingo@kernel.org, ravi.bangoria@linux.ibm.com, hpa@zytor.com, acme@redhat.com, s1seetee@linux.vnet.ibm.com In-Reply-To: <20190124005229.16146-7-tonyj@suse.de> References: <20190124005229.16146-7-tonyj@suse.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf script python: Add Python3 support to tests/attr.py Git-Commit-ID: 35ea7e4bbb89ecd32057f5f6a2a8feb0d7224e51 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-0.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_24_48 autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 35ea7e4bbb89ecd32057f5f6a2a8feb0d7224e51 Gitweb: https://git.kernel.org/tip/35ea7e4bbb89ecd32057f5f6a2a8feb0d7224e51 Author: Tony Jones AuthorDate: Wed, 23 Jan 2019 16:52:29 -0800 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 25 Jan 2019 15:12:10 +0100 perf script python: Add Python3 support to tests/attr.py Support both Python 2 and Python 3 in tests/attr.py The use of "except as" syntax implies the minimum supported Python2 version is now v2.6 Committer testing: $ make -C tools/perf PYTHON3=python install-bin Before: # perf test attr 16: Setup struct perf_event_attr : FAILED! 48: Synthesize attr update : Ok [root@quaco ~]# perf test -v attr 16: Setup struct perf_event_attr : --- start --- test child forked, pid 3121 File "/home/acme/libexec/perf-core/tests/attr.py", line 324 except Unsup, obj: ^ SyntaxError: invalid syntax test child finished with -1 ---- end ---- Setup struct perf_event_attr: FAILED! 48: Synthesize attr update : --- start --- test child forked, pid 3124 test child finished with 0 ---- end ---- Synthesize attr update: Ok # After: # perf test attr 16: Setup struct perf_event_attr : Ok 48: Synthesize attr update : Ok # Signed-off-by: Tony Jones Acked-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: Jonathan Corbet Cc: Ravi Bangoria Cc: Seeteena Thoufeek Link: http://lkml.kernel.org/r/20190124005229.16146-7-tonyj@suse.de Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/attr.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/tools/perf/tests/attr.py b/tools/perf/tests/attr.py index 3e07eee33b10..cb39ac46bc73 100644 --- a/tools/perf/tests/attr.py +++ b/tools/perf/tests/attr.py @@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 +from __future__ import print_function + import os import sys import glob @@ -7,7 +9,11 @@ import optparse import tempfile import logging import shutil -import ConfigParser + +try: + import configparser +except ImportError: + import ConfigParser as configparser def data_equal(a, b): # Allow multiple values in assignment separated by '|' @@ -99,20 +105,20 @@ class Event(dict): def equal(self, other): for t in Event.terms: log.debug(" [%s] %s %s" % (t, self[t], other[t])); - if not self.has_key(t) or not other.has_key(t): + if t not in self or t not in other: return False if not data_equal(self[t], other[t]): return False return True def optional(self): - if self.has_key('optional') and self['optional'] == '1': + if 'optional' in self and self['optional'] == '1': return True return False def diff(self, other): for t in Event.terms: - if not self.has_key(t) or not other.has_key(t): + if t not in self or t not in other: continue if not data_equal(self[t], other[t]): log.warning("expected %s=%s, got %s" % (t, self[t], other[t])) @@ -133,7 +139,7 @@ class Event(dict): # - expected values assignments class Test(object): def __init__(self, path, options): - parser = ConfigParser.SafeConfigParser() + parser = configparser.SafeConfigParser() parser.read(path) log.warning("running '%s'" % path) @@ -192,7 +198,7 @@ class Test(object): return True def load_events(self, path, events): - parser_event = ConfigParser.SafeConfigParser() + parser_event = configparser.SafeConfigParser() parser_event.read(path) # The event record section header contains 'event' word, @@ -206,7 +212,7 @@ class Test(object): # Read parent event if there's any if (':' in section): base = section[section.index(':') + 1:] - parser_base = ConfigParser.SafeConfigParser() + parser_base = configparser.SafeConfigParser() parser_base.read(self.test_dir + '/' + base) base_items = parser_base.items('event') @@ -321,9 +327,9 @@ def run_tests(options): for f in glob.glob(options.test_dir + '/' + options.test): try: Test(f, options).run() - except Unsup, obj: + except Unsup as obj: log.warning("unsupp %s" % obj.getMsg()) - except Notest, obj: + except Notest as obj: log.warning("skipped %s" % obj.getMsg()) def setup_log(verbose): @@ -362,7 +368,7 @@ def main(): parser.add_option("-p", "--perf", action="store", type="string", dest="perf") parser.add_option("-v", "--verbose", - action="count", dest="verbose") + default=0, action="count", dest="verbose") options, args = parser.parse_args() if args: @@ -372,7 +378,7 @@ def main(): setup_log(options.verbose) if not options.test_dir: - print 'FAILED no -d option specified' + print('FAILED no -d option specified') sys.exit(-1) if not options.test: @@ -381,8 +387,8 @@ def main(): try: run_tests(options) - except Fail, obj: - print "FAILED %s" % obj.getMsg(); + except Fail as obj: + print("FAILED %s" % obj.getMsg()) sys.exit(-1) sys.exit(0)