diff options
Diffstat (limited to 'tools/perf/tests/attr.py')
| -rw-r--r-- | tools/perf/tests/attr.py | 32 |
1 files 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 @@ | |||
| 1 | #! /usr/bin/python | 1 | #! /usr/bin/python |
| 2 | # SPDX-License-Identifier: GPL-2.0 | 2 | # SPDX-License-Identifier: GPL-2.0 |
| 3 | 3 | ||
| 4 | from __future__ import print_function | ||
| 5 | |||
| 4 | import os | 6 | import os |
| 5 | import sys | 7 | import sys |
| 6 | import glob | 8 | import glob |
| @@ -8,7 +10,11 @@ import optparse | |||
| 8 | import tempfile | 10 | import tempfile |
| 9 | import logging | 11 | import logging |
| 10 | import shutil | 12 | import shutil |
| 11 | import ConfigParser | 13 | |
| 14 | try: | ||
| 15 | import configparser | ||
| 16 | except ImportError: | ||
| 17 | import ConfigParser as configparser | ||
| 12 | 18 | ||
| 13 | def data_equal(a, b): | 19 | def 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): | |||
| 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 False | 110 | return False |
| 105 | if not data_equal(self[t], other[t]): | 111 | if not data_equal(self[t], other[t]): |
| 106 | return False | 112 | return False |
| 107 | return True | 113 | 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 True | 117 | return True |
| 112 | return False | 118 | 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 | continue | 123 | 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): | |||
| 134 | # - expected values assignments | 140 | # - expected values assignments |
| 135 | class Test(object): | 141 | class 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): | |||
| 193 | return True | 199 | 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): | |||
| 207 | # Read parent event if there's any | 213 | # 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): | |||
| 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 | ||
| 330 | def setup_log(verbose): | 336 | def setup_log(verbose): |
| @@ -363,7 +369,7 @@ def main(): | |||
| 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(): | |||
| 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(): | |||
| 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) |
