Skip to content

Commit

Permalink
saniytcheck: fixed pylint issues
Browse files Browse the repository at this point in the history
Fixed a few pylint issues, including space and indent reported by
flake8.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
  • Loading branch information
nashif committed Dec 4, 2019
1 parent 0268d2a commit 8f1b47c
Showing 1 changed file with 26 additions and 33 deletions.
59 changes: 26 additions & 33 deletions scripts/sanitycheck
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,8 @@ if not ZEPHYR_BASE:

sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts", "dts"))
import edtlib

import logging


hw_map_local = threading.Lock()
report_lock = threading.Lock()

Expand Down Expand Up @@ -247,6 +245,7 @@ else:
COLOR_GREEN = ""
COLOR_YELLOW = ""


class CMakeCacheEntry:
'''Represents a CMake cache entry.
Expand Down Expand Up @@ -402,17 +401,20 @@ class CMakeCache:
def __iter__(self):
return iter(self._entries.values())


class SanityCheckException(Exception):
pass


class SanityRuntimeError(SanityCheckException):
pass


class ConfigurationError(SanityCheckException):
def __init__(self, cfile, message):
SanityCheckException.__init__(self, cfile + ": " + message)


class BuildError(SanityCheckException):
pass

Expand All @@ -423,6 +425,7 @@ class ExecutionError(SanityCheckException):

log_file = None


# Debug Functions
def info(what, show_time=True):
if options.timestamps and show_time:
Expand Down Expand Up @@ -454,6 +457,7 @@ def verbose(what):
if VERBOSE >= 2:
info(what)


class HarnessImporter:

def __init__(self, name):
Expand All @@ -466,6 +470,7 @@ class HarnessImporter:

self.instance = my_class()


class Handler:
def __init__(self, instance, type_str="build"):
"""Constructor
Expand Down Expand Up @@ -516,6 +521,7 @@ class Handler:
for instance in harness.recording:
cw.writerow(instance)


class BinaryHandler(Handler):
def __init__(self, instance, type_str):
"""Constructor
Expand Down Expand Up @@ -632,6 +638,7 @@ class BinaryHandler(Handler):

self.record(harness)


class DeviceHandler(Handler):

def __init__(self, instance, type_str):
Expand Down Expand Up @@ -837,6 +844,7 @@ class DeviceHandler(Handler):

self.record(harness)


class QEMUHandler(Handler):
"""Spawns a thread to monitor QEMU output from pipes
Expand Down Expand Up @@ -1005,6 +1013,7 @@ class QEMUHandler(Handler):
def get_fifo(self):
return self.fifo_fn


class SizeCalculator:

alloc_sections = [
Expand Down Expand Up @@ -1246,6 +1255,7 @@ testcase_valid_keys = {"tags": {"type": "set", "required": False},
"harness_config": {"type": "map", "default": {}}
}


class SanityConfigParser:
"""Class to read test case files with semantic checking
"""
Expand Down Expand Up @@ -1446,15 +1456,14 @@ class Platform:
if not os.environ.get(env, None):
self.env_satisfied = False


def __repr__(self):
return "<%s on %s>" % (self.name, self.arch)


class TestCase(object):
"""Class representing a test application
"""


def __init__(self):
"""TestCase constructor.
Expand Down Expand Up @@ -1516,7 +1525,7 @@ class TestCase(object):
# This is in ZEPHYR_BASE, so include path in name for uniqueness
# FIXME: We should not depend on path of test for unique names.
relative_tc_root = os.path.relpath(canonical_testcase_root,
start=canonical_zephyr_base)
start=canonical_zephyr_base)
else:
relative_tc_root = ""

Expand Down Expand Up @@ -1610,7 +1619,6 @@ class TestCase(object):
if not results:
self.cases.append(self.id)


def __str__(self):
return self.name

Expand Down Expand Up @@ -1832,11 +1840,11 @@ class CMake():

def run_cmake(self, args=[]):

verbose("Running cmake on %s for %s" %(self.source_dir, self.platform.name))
verbose("Running cmake on %s for %s" % (self.source_dir,
self.platform.name))
ldflags = "-Wl,--fatal-warnings"

ldflags="-Wl,--fatal-warnings"

#fixme: add additional cflags based on options
# fixme: add additional cflags based on options
cmake_args = [
'-B{}'.format(self.build_dir),
'-S{}'.format(self.source_dir),
Expand Down Expand Up @@ -1878,7 +1886,6 @@ class CMake():
self.instance.reason = "Cmake build failure"
results = {"returncode": p.returncode}


if out:
with open(os.path.join(self.build_dir, self.log), "a") as log:
log_msg = out.decode(sys.getdefaultencoding())
Expand Down Expand Up @@ -2018,7 +2025,6 @@ class ProjectBuilder(FilterBuilder):
else:
pipeline.put({"op": "build", "test": self.instance})


elif op == "build":
verbose("build test: %s" %self.instance.name)
results = self.build()
Expand Down Expand Up @@ -2158,6 +2164,7 @@ class ProjectBuilder(FilterBuilder):

pipeline = queue.LifoQueue()


class BoundedExecutor(concurrent.futures.ThreadPoolExecutor):
"""BoundedExecutor behaves as a ThreadPoolExecutor which will block on
calls to submit() once the limit given as "bound" work items are queued for
Expand All @@ -2167,14 +2174,14 @@ class BoundedExecutor(concurrent.futures.ThreadPoolExecutor):
"""
def __init__(self, bound, max_workers, **kwargs):
super().__init__(max_workers)
#self.executor = ThreadPoolExecutor(max_workers=max_workers)
# self.executor = ThreadPoolExecutor(max_workers=max_workers)
self.semaphore = BoundedSemaphore(bound + max_workers)

def submit(self, fn, *args, **kwargs):
self.semaphore.acquire()
try:
future = super().submit(fn, *args, **kwargs)
except:
except Exception:
self.semaphore.release()
raise
else:
Expand All @@ -2194,7 +2201,7 @@ class TestSuite:

self.roots = testcase_roots
if not isinstance(board_root_list, list):
self.board_roots= [board_root_list]
self.board_roots = [board_root_list]
else:
self.board_roots = board_root_list

Expand All @@ -2208,9 +2215,9 @@ class TestSuite:
self.load_errors = 0
self.instances = dict()

self.total_tests = 0 # number of test instances
self.total_cases = 0 # number of test cases
self.total_done = 0 # tests completed
self.total_tests = 0 # number of test instances
self.total_cases = 0 # number of test cases
self.total_done = 0 # tests completed
self.total_failed = 0
self.total_skipped = 0

Expand All @@ -2237,13 +2244,11 @@ class TestSuite:
self.total_tests = len(self.instances)
self.total_cases = len(self.testcases)


def compare_metrics(self, filename):
# name, datatype, lower results better
interesting_metrics = [("ram_size", int, True),
("rom_size", int, True)]


if not os.path.exists(filename):
info("Cannot compare metrics, %s not found" % filename)
return []
Expand Down Expand Up @@ -2373,8 +2378,6 @@ class TestSuite:
if log_file:
log_file.close()



def add_configurations(self):

for board_root in self.board_roots:
Expand Down Expand Up @@ -2424,7 +2427,6 @@ class TestSuite:

return toolchain


def add_testcases(self):
for root in self.roots:
root = os.path.abspath(root)
Expand Down Expand Up @@ -2499,7 +2501,6 @@ class TestSuite:

return True


def get_platform(self, name):
selected_platform = None
for platform in self.platforms:
Expand Down Expand Up @@ -2557,7 +2558,6 @@ class TestSuite:
instance_list.append(instance)
self.add_instances(instance_list)


def apply_filters(self):

toolchain = self.get_toolchain()
Expand Down Expand Up @@ -2805,7 +2805,6 @@ class TestSuite:
instance.metrics["handler_time"] = instance.handler.duration if instance.handler else 0
instance.metrics["unrecognized"] = []


def discard_report(self, filename):

try:
Expand All @@ -2826,7 +2825,6 @@ class TestSuite:
"reason": reason}
cw.writerow(rowdict)


def target_report(self, outdir):
run = "Sanitycheck"
eleTestsuite = None
Expand Down Expand Up @@ -2908,7 +2906,6 @@ class TestSuite:
with open(os.path.join(outdir, platform + ".xml"), 'wb') as f:
f.write(result)


def xunit_report(self, filename):
fails = 0
passes = 0
Expand Down Expand Up @@ -2994,7 +2991,6 @@ class TestSuite:
with open(filename, 'wb') as report:
report.write(result)


def csv_report(self, filename):
with open(filename, "wt") as csvfile:
fieldnames = ["test", "arch", "platform", "passed", "status",
Expand Down Expand Up @@ -3686,7 +3682,7 @@ class HardwareMap:
s_dev['serial'] = d.device
s_dev['product'] = d.product
s_dev['runner'] = 'unknown'
for runner in self.runner_mapping.keys():
for runner,_ in self.runner_mapping.items():
products = self.runner_mapping.get(runner)
if d.product in products:
s_dev['runner'] = runner
Expand Down Expand Up @@ -3739,9 +3735,6 @@ class HardwareMap:
with open(hwm_file, 'w') as yaml_file:
yaml.dump(self.detected, yaml_file, default_flow_style=False)

return



run_individual_tests = None
options = None
Expand Down

0 comments on commit 8f1b47c

Please sign in to comment.