History

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 #

Tony Jones committed 7 years ago

Commit 8f2f3501 parent 6ab3bc21 file · +19 −13Browse files

Unified · Split

tools/perf/tests/attr.py+19−13
@@ -1,6 +1,8 @@
1#! /usr/bin/python1#! /usr/bin/python
2# SPDX-License-Identifier: GPL-2.02# SPDX-License-Identifier: GPL-2.0
3 3
4from __future__ import print_function
5
4import os6import os
5import sys7import sys
6import glob8import glob
@@ -8,7 +10,11 @@ import optparse · 1 unmodified line
8import tempfile10import tempfile
9import logging11import logging
10import shutil12import shutil
11import ConfigParser13
14try:
15 import configparser
16except ImportError:
17 import ConfigParser as configparser
12 18
13def data_equal(a, b):19def data_equal(a, b):
14 # Allow multiple values in assignment separated by '|'20 # Allow multiple values in assignment separated by '|'
@@ -100,20 +106,20 @@ class Event(dict): · 85 unmodified lines
100 def equal(self, other):106 def equal(self, other):
101 for t in Event.terms:107 for t in Event.terms:
102 log.debug(" [%s] %s %s" % (t, self[t], other[t]));108 log.debug(" [%s] %s %s" % (t, self[t], other[t]));
103 if not self.has_key(t) or not other.has_key(t):109 if t not in self or t not in other:
104 return False110 return False
105 if not data_equal(self[t], other[t]):111 if not data_equal(self[t], other[t]):
106 return False112 return False
107 return True113 return True
108 114
109 def optional(self):115 def optional(self):
110 if self.has_key('optional') and self['optional'] == '1':116 if 'optional' in self and self['optional'] == '1':
111 return True117 return True
112 return False118 return False
113 119
114 def diff(self, other):120 def diff(self, other):
115 for t in Event.terms:121 for t in Event.terms:
116 if not self.has_key(t) or not other.has_key(t):122 if t not in self or t not in other:
117 continue123 continue
118 if not data_equal(self[t], other[t]):124 if not data_equal(self[t], other[t]):
119 log.warning("expected %s=%s, got %s" % (t, self[t], other[t]))125 log.warning("expected %s=%s, got %s" % (t, self[t], other[t]))
@@ -134,7 +140,7 @@ class Event(dict): · 14 unmodified lines
134# - expected values assignments140# - expected values assignments
135class Test(object):141class Test(object):
136 def __init__(self, path, options):142 def __init__(self, path, options):
137 parser = ConfigParser.SafeConfigParser()143 parser = configparser.SafeConfigParser()
138 parser.read(path)144 parser.read(path)
139 145
140 log.warning("running '%s'" % path)146 log.warning("running '%s'" % path)
@@ -193,7 +199,7 @@ class Test(object): · 52 unmodified lines
193 return True199 return True
194 200
195 def load_events(self, path, events):201 def load_events(self, path, events):
196 parser_event = ConfigParser.SafeConfigParser()202 parser_event = configparser.SafeConfigParser()
197 parser_event.read(path)203 parser_event.read(path)
198 204
199 # The event record section header contains 'event' word,205 # The event record section header contains 'event' word,
@@ -207,7 +213,7 @@ class Test(object): · 7 unmodified lines
207 # Read parent event if there's any213 # Read parent event if there's any
208 if (':' in section):214 if (':' in section):
209 base = section[section.index(':') + 1:]215 base = section[section.index(':') + 1:]
210 parser_base = ConfigParser.SafeConfigParser()216 parser_base = configparser.SafeConfigParser()
211 parser_base.read(self.test_dir + '/' + base)217 parser_base.read(self.test_dir + '/' + base)
212 base_items = parser_base.items('event')218 base_items = parser_base.items('event')
213 219
@@ -322,9 +328,9 @@ def run_tests(options): · 108 unmodified lines
322 for f in glob.glob(options.test_dir + '/' + options.test):328 for f in glob.glob(options.test_dir + '/' + options.test):
323 try:329 try:
324 Test(f, options).run()330 Test(f, options).run()
325 except Unsup, obj:331 except Unsup as obj:
326 log.warning("unsupp %s" % obj.getMsg())332 log.warning("unsupp %s" % obj.getMsg())
327 except Notest, obj:333 except Notest as obj:
328 log.warning("skipped %s" % obj.getMsg())334 log.warning("skipped %s" % obj.getMsg())
329 335
330def setup_log(verbose):336def setup_log(verbose):
@@ -363,7 +369,7 @@ def main(): · 32 unmodified lines
363 parser.add_option("-p", "--perf",369 parser.add_option("-p", "--perf",
364 action="store", type="string", dest="perf")370 action="store", type="string", dest="perf")
365 parser.add_option("-v", "--verbose",371 parser.add_option("-v", "--verbose",
366 action="count", dest="verbose")372 default=0, action="count", dest="verbose")
367 373
368 options, args = parser.parse_args()374 options, args = parser.parse_args()
369 if args:375 if args:
@@ -373,7 +379,7 @@ def main(): · 3 unmodified lines
373 setup_log(options.verbose)379 setup_log(options.verbose)
374 380
375 if not options.test_dir:381 if not options.test_dir:
376 print 'FAILED no -d option specified'382 print('FAILED no -d option specified')
377 sys.exit(-1)383 sys.exit(-1)
378 384
379 if not options.test:385 if not options.test:
@@ -382,8 +388,8 @@ def main(): · 2 unmodified lines
382 try:388 try:
383 run_tests(options)389 run_tests(options)
384 390
385 except Fail, obj:391 except Fail as obj:
386 print "FAILED %s" % obj.getMsg();392 print("FAILED %s" % obj.getMsg())
387 sys.exit(-1)393 sys.exit(-1)
388 394
389 sys.exit(0)395 sys.exit(0)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t