Skip to content

Commit

Permalink
Merge pull request #1810 from sypark9646/style/pylint-style
Browse files Browse the repository at this point in the history
Update tests/runtest.py to match the pylint code style.
Simply run pylint with the filename would show the warnings.
And also it's possible to check only a specific warning like below:

  $ pylint --disable R,C,W,E --enable W0612 tests/runtest.py

Fixed: #1497 

Signed-off-by: Namhyung Kim <[email protected]>
  • Loading branch information
namhyung authored Sep 6, 2023
2 parents 955b9e9 + 34a062c commit e5f6cde
Showing 1 changed file with 19 additions and 29 deletions.
48 changes: 19 additions & 29 deletions tests/runtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ def is_32bit(filename):
# e_ident[] indexes
EI_CLASS = 4

# EI_CLASS
ELFCLASSNONE = 0
# EI_CLASS: ELFCLASSNONE, ELFCLASS32, ELFCLASS64, ELFCLASSNUM
ELFCLASS32 = 1
ELFCLASS64 = 2
ELFCLASSNUM = 3

try:
with open(filename, 'rb') as f:
Expand All @@ -32,7 +29,7 @@ def is_32bit(filename):

if ei_class == ELFCLASS32:
return True
except:
except Exception:
pass

return False
Expand All @@ -59,11 +56,11 @@ def get_elf_machine(filename):

# read e_machine
e_machine = f.read(2)[0]
if type(e_machine) is str:
if isinstance(e_machine, str):
e_machine = ord(e_machine)

return machine[e_machine]
except:
except Exception:
pass

return None
Expand Down Expand Up @@ -144,7 +141,7 @@ def gen_port(self, start = 40000, end = 50000):
s.bind(("localhost", port))
self.port = port
return
except OSError as e:
except OSError:
pass
raise Exception("No available port found")

Expand All @@ -156,7 +153,7 @@ def test_feature(self):
for i in range(3, len(s) - 1):
self.feature.add(s[i])
return True
except:
except Exception:
return False

def convert_abs_path(self, build_cmd):
Expand Down Expand Up @@ -185,7 +182,7 @@ def build_it(self, build_cmd):
except OSError as e:
self.pr_debug(e.strerror)
return TestBase.TEST_BUILD_FAIL
except:
except Exception:
return TestBase.TEST_BUILD_FAIL

def build(self, name, cflags='', ldflags=''):
Expand All @@ -199,11 +196,9 @@ def build(self, name, cflags='', ldflags=''):

build_cflags = ' '.join(TestBase.default_cflags + [self.cflags, cflags, \
os.getenv(lang['flags'], '')])
build_ldflags = ' '.join([self.ldflags, ldflags, \
os.getenv('LDFLAGS', '')])
build_ldflags = ' '.join([self.ldflags, ldflags, os.getenv('LDFLAGS', '')])

build_cmd = '%s -o %s %s %s %s' % \
(lang['cc'], prog, build_cflags, src, build_ldflags)
build_cmd = '%s -o %s %s %s %s' % (lang['cc'], prog, build_cflags, src, build_ldflags)

self.pr_debug("build command: %s" % build_cmd)
return self.build_it(build_cmd)
Expand All @@ -213,8 +208,7 @@ def build_notrace_lib(self, dstname, srcname, cflags='', ldflags =''):

build_cflags = ' '.join(TestBase.default_cflags + [self.cflags, cflags, \
os.getenv(lang['flags'], '')])
build_ldflags = ' '.join([self.ldflags, ldflags, \
os.getenv('LDFLAGS', '')])
build_ldflags = ' '.join([self.ldflags, ldflags, os.getenv('LDFLAGS', '')])

lib_cflags = build_cflags + ' -shared -fPIC'

Expand All @@ -230,17 +224,15 @@ def build_libabc(self, cflags='', ldflags=''):

build_cflags = ' '.join(TestBase.default_cflags + [self.cflags, cflags, \
os.getenv(lang['flags'], '')])
build_ldflags = ' '.join([self.ldflags, ldflags, \
os.getenv('LDFLAGS', '')])
build_ldflags = ' '.join([self.ldflags, ldflags, os.getenv('LDFLAGS', '')])

lib_cflags = build_cflags + ' -shared -fPIC'

if '-fpatchable-function-entry' in cflags:
self.p_libs.append('libabc_test_lib.so')

# build libabc_test_lib.so library
build_cmd = '%s -o libabc_test_lib.so %s s-lib.c %s' % \
(lang['cc'], lib_cflags, build_ldflags)
build_cmd = '%s -o libabc_test_lib.so %s s-lib.c %s' % (lang['cc'], lib_cflags, build_ldflags)

self.pr_debug("build command for library: %s" % build_cmd)
return self.build_it(build_cmd)
Expand All @@ -250,8 +242,7 @@ def build_libfoo(self, name, cflags='', ldflags=''):

build_cflags = ' '.join(TestBase.default_cflags + [self.cflags, cflags, \
os.getenv(lang['flags'], '')])
build_ldflags = ' '.join([self.ldflags, ldflags, \
os.getenv('LDFLAGS', '')])
build_ldflags = ' '.join([self.ldflags, ldflags, os.getenv('LDFLAGS', '')])

lib_cflags = build_cflags + ' -shared -fPIC'

Expand Down Expand Up @@ -338,7 +329,7 @@ def task_sort(self, output, ignore_children=False):
m = pid_patt.match(ln)
try:
pid = int(m.group(1))
except:
except Exception:
continue

func = ln.split('|', 1)[-1]
Expand All @@ -358,7 +349,7 @@ def task_sort(self, output, ignore_children=False):
for p in pid_list:
result += '\n'.join(pids[p]['result']) + '\n'
result = result.strip()
except:
except Exception:
pass # this leads to a failure with 'NG'
return result

Expand Down Expand Up @@ -393,7 +384,7 @@ def report_sort(self, output, ignored):
try:
if line[-1].startswith('__'):
continue
except:
except Exception:
pass
result.append('%s %s' % (line[-2], line[-1]))

Expand Down Expand Up @@ -430,7 +421,6 @@ def graph_sort(self, output, ignored):
def dump_sort(self, output, ignored):
""" This function post-processes output of the test to be compared .
It ignores blank and comment (#) lines and remaining functions. """
mode = 1
result = []

# A (raw) dump result consists of following data
Expand Down Expand Up @@ -470,7 +460,7 @@ def chrome_sort(self, output, ignored):
result = []
try:
o = json.loads(output)
except:
except Exception:
return ''
for ln in o['traceEvents']:
if ln['name'].startswith('__'):
Expand Down Expand Up @@ -545,7 +535,7 @@ def check_perf_paranoid(self):

if v >= 3:
return False
except:
except Exception:
pass

return True
Expand Down Expand Up @@ -698,7 +688,7 @@ def timeout_handler(sig, frame):
dif = "%s: diff result of %s %s\n" % (name, compiler, cflags)
try:
p = sp.Popen(['colordiff', '-U1', 'expect', 'result'], stdout=sp.PIPE)
except:
except Exception:
p = sp.Popen(['diff', '-U1', 'expect', 'result'], stdout=sp.PIPE)
dif += p.communicate()[0].decode(errors='ignore')
os.remove('expect')
Expand Down

0 comments on commit e5f6cde

Please sign in to comment.