hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/tools/perf/tests/attr.py
....@@ -1,5 +1,6 @@
1
-#! /usr/bin/python
21 # SPDX-License-Identifier: GPL-2.0
2
+
3
+from __future__ import print_function
34
45 import os
56 import sys
....@@ -8,7 +9,11 @@
89 import tempfile
910 import logging
1011 import shutil
11
-import ConfigParser
12
+
13
+try:
14
+ import configparser
15
+except ImportError:
16
+ import ConfigParser as configparser
1217
1318 def data_equal(a, b):
1419 # Allow multiple values in assignment separated by '|'
....@@ -100,20 +105,20 @@
100105 def equal(self, other):
101106 for t in Event.terms:
102107 log.debug(" [%s] %s %s" % (t, self[t], other[t]));
103
- if not self.has_key(t) or not other.has_key(t):
108
+ if t not in self or t not in other:
104109 return False
105110 if not data_equal(self[t], other[t]):
106111 return False
107112 return True
108113
109114 def optional(self):
110
- if self.has_key('optional') and self['optional'] == '1':
115
+ if 'optional' in self and self['optional'] == '1':
111116 return True
112117 return False
113118
114119 def diff(self, other):
115120 for t in Event.terms:
116
- if not self.has_key(t) or not other.has_key(t):
121
+ if t not in self or t not in other:
117122 continue
118123 if not data_equal(self[t], other[t]):
119124 log.warning("expected %s=%s, got %s" % (t, self[t], other[t]))
....@@ -134,7 +139,7 @@
134139 # - expected values assignments
135140 class Test(object):
136141 def __init__(self, path, options):
137
- parser = ConfigParser.SafeConfigParser()
142
+ parser = configparser.SafeConfigParser()
138143 parser.read(path)
139144
140145 log.warning("running '%s'" % path)
....@@ -193,7 +198,7 @@
193198 return True
194199
195200 def load_events(self, path, events):
196
- parser_event = ConfigParser.SafeConfigParser()
201
+ parser_event = configparser.SafeConfigParser()
197202 parser_event.read(path)
198203
199204 # The event record section header contains 'event' word,
....@@ -207,7 +212,7 @@
207212 # Read parent event if there's any
208213 if (':' in section):
209214 base = section[section.index(':') + 1:]
210
- parser_base = ConfigParser.SafeConfigParser()
215
+ parser_base = configparser.SafeConfigParser()
211216 parser_base.read(self.test_dir + '/' + base)
212217 base_items = parser_base.items('event')
213218
....@@ -322,9 +327,9 @@
322327 for f in glob.glob(options.test_dir + '/' + options.test):
323328 try:
324329 Test(f, options).run()
325
- except Unsup, obj:
330
+ except Unsup as obj:
326331 log.warning("unsupp %s" % obj.getMsg())
327
- except Notest, obj:
332
+ except Notest as obj:
328333 log.warning("skipped %s" % obj.getMsg())
329334
330335 def setup_log(verbose):
....@@ -363,7 +368,7 @@
363368 parser.add_option("-p", "--perf",
364369 action="store", type="string", dest="perf")
365370 parser.add_option("-v", "--verbose",
366
- action="count", dest="verbose")
371
+ default=0, action="count", dest="verbose")
367372
368373 options, args = parser.parse_args()
369374 if args:
....@@ -373,7 +378,7 @@
373378 setup_log(options.verbose)
374379
375380 if not options.test_dir:
376
- print 'FAILED no -d option specified'
381
+ print('FAILED no -d option specified')
377382 sys.exit(-1)
378383
379384 if not options.test:
....@@ -382,8 +387,8 @@
382387 try:
383388 run_tests(options)
384389
385
- except Fail, obj:
386
- print "FAILED %s" % obj.getMsg();
390
+ except Fail as obj:
391
+ print("FAILED %s" % obj.getMsg())
387392 sys.exit(-1)
388393
389394 sys.exit(0)