From: tip-bot for Tony Jones <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: ravi.bangoria@linux.ibm.com, hpa@zytor.com,
s1seetee@linux.vnet.ibm.com, tonyj@suse.de, corbet@lwn.net,
linux-kernel@vger.kernel.org, mingo@kernel.org, jolsa@kernel.org,
acme@redhat.com, tglx@linutronix.de
Subject: [tip:perf/urgent] perf script python: Add Python3 support to tests/attr.py
Date: Sat, 9 Feb 2019 04:24:20 -0800 [thread overview]
Message-ID: <tip-8f2f350cbdb2c2fbff654cb778139144b48a59ba@git.kernel.org> (raw)
In-Reply-To: <20190124005229.16146-7-tonyj@suse.de>
Commit-ID: 8f2f350cbdb2c2fbff654cb778139144b48a59ba
Gitweb: https://git.kernel.org/tip/8f2f350cbdb2c2fbff654cb778139144b48a59ba
Author: Tony Jones <tonyj@suse.de>
AuthorDate: Wed, 23 Jan 2019 16:52:29 -0800
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 5 Feb 2019 10:31:08 -0300
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 <tonyj@suse.de>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Cc: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/20190124005229.16146-7-tonyj@suse.de
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
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 44090a9a19f3..e952127e4fb0 100644
--- a/tools/perf/tests/attr.py
+++ b/tools/perf/tests/attr.py
@@ -1,6 +1,8 @@
#! /usr/bin/python
# SPDX-License-Identifier: GPL-2.0
+from __future__ import print_function
+
import os
import sys
import glob
@@ -8,7 +10,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 '|'
@@ -100,20 +106,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]))
@@ -134,7 +140,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)
@@ -193,7 +199,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,
@@ -207,7 +213,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')
@@ -322,9 +328,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):
@@ -363,7 +369,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:
@@ -373,7 +379,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:
@@ -382,8 +388,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)
next prev parent reply other threads:[~2019-02-09 12:24 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-24 0:52 [PATCH 0/6] Fix issues with Python3 scripting Tony Jones
2019-01-24 0:52 ` [PATCH 1/6] perf script python: Add trace_context extension module to sys,modules Tony Jones
2019-01-26 10:06 ` [tip:perf/core] perf script python: Add trace_context extension module to sys.modules tip-bot for Tony Jones
2019-01-24 0:52 ` [PATCH 2/6] perf script python: Use PyBytes for attr in trace-event-python Tony Jones
2019-01-26 10:07 ` [tip:perf/core] " tip-bot for Tony Jones
2019-01-24 0:52 ` [PATCH 3/6] perf script python: remove explicit shebang from setup.py Tony Jones
2019-01-26 10:07 ` [tip:perf/core] perf script python: Remove " tip-bot for Tony Jones
2019-01-24 0:52 ` [PATCH 4/6] perf script python: remove explicit shebang from tests/attr.c Tony Jones
2019-01-26 10:08 ` [tip:perf/core] perf script python: Remove " tip-bot for Tony Jones
2019-01-24 0:52 ` [PATCH 5/6] perf script python: remove explicit shebang from Python scripts Tony Jones
2019-01-26 10:09 ` [tip:perf/core] perf script python: Remove " tip-bot for Tony Jones
2019-01-24 0:52 ` [PATCH 6/6] perf script python: add Python3 support to tests/attr.py Tony Jones
2019-01-26 10:09 ` [tip:perf/core] perf script python: Add " tip-bot for Tony Jones
2019-02-09 12:24 ` tip-bot for Tony Jones [this message]
2019-01-24 10:39 ` [PATCH 0/6] Fix issues with Python3 scripting Jiri Olsa
2019-01-24 13:26 ` Arnaldo Carvalho de Melo
2019-01-25 12:31 ` Arnaldo Carvalho de Melo
2019-01-25 13:57 ` Arnaldo Carvalho de Melo
2019-01-25 18:09 ` Tony Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-8f2f350cbdb2c2fbff654cb778139144b48a59ba@git.kernel.org \
--to=tipbot@zytor.com \
--cc=acme@redhat.com \
--cc=corbet@lwn.net \
--cc=hpa@zytor.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=ravi.bangoria@linux.ibm.com \
--cc=s1seetee@linux.vnet.ibm.com \
--cc=tglx@linutronix.de \
--cc=tonyj@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.