sanitycheck: get rid of global VERBOSE

Do not declare VERBOSE as global, instead pass verbosity as argument.
Also get rid of options as global and fix coverage class to not use
global option variable.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2020-03-29 19:02:51 -04:00
commit f6462a3a8c
2 changed files with 28 additions and 30 deletions

View file

@ -64,13 +64,9 @@ sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/"))
from sanity_chk import scl from sanity_chk import scl
from sanity_chk import expr_parser from sanity_chk import expr_parser
VERBOSE = 0
logger = logging.getLogger('sanitycheck') logger = logging.getLogger('sanitycheck')
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
options = None
pipeline = queue.LifoQueue() pipeline = queue.LifoQueue()
class CMakeCacheEntry: class CMakeCacheEntry:
@ -1807,6 +1803,7 @@ class ProjectBuilder(FilterBuilder):
self.west_runner = kwargs.get('west_runner', None) self.west_runner = kwargs.get('west_runner', None)
self.generator = kwargs.get('generator', None) self.generator = kwargs.get('generator', None)
self.generator_cmd = kwargs.get('generator_cmd', None) self.generator_cmd = kwargs.get('generator_cmd', None)
self.verbose = kwargs.get('verbose', None)
@staticmethod @staticmethod
def log_info(filename, inline_logs): def log_info(filename, inline_logs):
@ -1977,7 +1974,7 @@ class ProjectBuilder(FilterBuilder):
if instance.status in ["failed", "timeout"]: if instance.status in ["failed", "timeout"]:
self.suite.total_failed += 1 self.suite.total_failed += 1
if VERBOSE: if self.verbose:
status = Fore.RED + "FAILED " + Fore.RESET + instance.reason status = Fore.RED + "FAILED " + Fore.RESET + instance.reason
else: else:
print("") print("")
@ -1988,7 +1985,7 @@ class ProjectBuilder(FilterBuilder):
Fore.RED, Fore.RED,
Fore.RESET, Fore.RESET,
instance.reason)) instance.reason))
if not VERBOSE: if not self.verbose:
self.log_info_file(self.inline_logs) self.log_info_file(self.inline_logs)
elif instance.status == "skipped": elif instance.status == "skipped":
self.suite.total_skipped += 1 self.suite.total_skipped += 1
@ -1996,7 +1993,7 @@ class ProjectBuilder(FilterBuilder):
else: else:
status = Fore.GREEN + "PASSED" + Fore.RESET status = Fore.GREEN + "PASSED" + Fore.RESET
if VERBOSE: if self.verbose:
if self.cmake_only: if self.cmake_only:
more_info = "cmake" more_info = "cmake"
elif instance.status == "skipped": elif instance.status == "skipped":
@ -2746,7 +2743,8 @@ class TestSuite:
west_flash=self.west_flash, west_flash=self.west_flash,
west_runner=self.west_runner, west_runner=self.west_runner,
generator=self.generator, generator=self.generator,
generator_cmd=self.generator_cmd generator_cmd=self.generator_cmd,
verbose=self.verbose
) )
future_to_test[executor.submit(pb.process, message)] = test.name future_to_test[executor.submit(pb.process, message)] = test.name
@ -3011,20 +3009,25 @@ class CoverageTool:
""" """
def __init__(self): def __init__(self):
self.gcov_tool = options.gcov_tool self.gcov_tool = None
self.base_dir = None
@staticmethod @staticmethod
def factory(tool): def factory(tool):
if tool == 'lcov': if tool == 'lcov':
return Lcov() t = Lcov()
if tool == 'gcovr': elif tool == 'gcovr':
return Gcovr() t = Lcov()
logger.error("Unsupported coverage tool specified: {}".format(tool)) else:
logger.error("Unsupported coverage tool specified: {}".format(tool))
return None
t.gcov_tool = tool
return t
@staticmethod @staticmethod
def retrieve_gcov_data(intput_file): def retrieve_gcov_data(intput_file):
if VERBOSE: logger.debug("Working on %s" % intput_file)
logger.debug("Working on %s" % intput_file)
extracted_coverage_info = {} extracted_coverage_info = {}
capture_data = False capture_data = False
capture_complete = False capture_complete = False
@ -3057,8 +3060,7 @@ class CoverageTool:
@staticmethod @staticmethod
def create_gcda_files(extracted_coverage_info): def create_gcda_files(extracted_coverage_info):
if VERBOSE: logger.debug("Generating gcda files")
logger.debug("Generating gcda files")
for filename, hexdump_val in extracted_coverage_info.items(): for filename, hexdump_val in extracted_coverage_info.items():
# if kobject_hash is given for coverage gcovr fails # if kobject_hash is given for coverage gcovr fails
# hence skipping it problem only in gcovr v4.1 # hence skipping it problem only in gcovr v4.1
@ -3113,14 +3115,14 @@ class Lcov(CoverageTool):
# We want to remove tests/* and tests/ztest/test/* but save tests/ztest # We want to remove tests/* and tests/ztest/test/* but save tests/ztest
subprocess.call(["lcov", "--gcov-tool", self.gcov_tool, "--extract", subprocess.call(["lcov", "--gcov-tool", self.gcov_tool, "--extract",
coveragefile, coveragefile,
os.path.join(ZEPHYR_BASE, "tests", "ztest", "*"), os.path.join(self.base_dir, "tests", "ztest", "*"),
"--output-file", ztestfile, "--output-file", ztestfile,
"--rc", "lcov_branch_coverage=1"], stdout=coveragelog) "--rc", "lcov_branch_coverage=1"], stdout=coveragelog)
if os.path.exists(ztestfile) and os.path.getsize(ztestfile) > 0: if os.path.exists(ztestfile) and os.path.getsize(ztestfile) > 0:
subprocess.call(["lcov", "--gcov-tool", self.gcov_tool, "--remove", subprocess.call(["lcov", "--gcov-tool", self.gcov_tool, "--remove",
ztestfile, ztestfile,
os.path.join(ZEPHYR_BASE, "tests/ztest/test/*"), os.path.join(self.base_dir, "tests/ztest/test/*"),
"--output-file", ztestfile, "--output-file", ztestfile,
"--rc", "lcov_branch_coverage=1"], "--rc", "lcov_branch_coverage=1"],
stdout=coveragelog) stdout=coveragelog)
@ -3168,12 +3170,12 @@ class Gcovr(CoverageTool):
excludes = Gcovr._interleave_list("-e", self.ignores) excludes = Gcovr._interleave_list("-e", self.ignores)
# We want to remove tests/* and tests/ztest/test/* but save tests/ztest # We want to remove tests/* and tests/ztest/test/* but save tests/ztest
subprocess.call(["gcovr", "-r", ZEPHYR_BASE, "--gcov-executable", subprocess.call(["gcovr", "-r", self.base_dir, "--gcov-executable",
self.gcov_tool, "-e", "tests/*"] + excludes + self.gcov_tool, "-e", "tests/*"] + excludes +
["--json", "-o", coveragefile, outdir], ["--json", "-o", coveragefile, outdir],
stdout=coveragelog) stdout=coveragelog)
subprocess.call(["gcovr", "-r", ZEPHYR_BASE, "--gcov-executable", subprocess.call(["gcovr", "-r", self.base_dir, "--gcov-executable",
self.gcov_tool, "-f", "tests/ztest", "-e", self.gcov_tool, "-f", "tests/ztest", "-e",
"tests/ztest/test/*", "--json", "-o", ztestfile, "tests/ztest/test/*", "--json", "-o", ztestfile,
outdir], stdout=coveragelog) outdir], stdout=coveragelog)
@ -3188,7 +3190,7 @@ class Gcovr(CoverageTool):
tracefiles = self._interleave_list("--add-tracefile", files) tracefiles = self._interleave_list("--add-tracefile", files)
return subprocess.call(["gcovr", "-r", ZEPHYR_BASE, "--html", return subprocess.call(["gcovr", "-r", self.base_dir, "--html",
"--html-details"] + tracefiles + "--html-details"] + tracefiles +
["-o", os.path.join(subdir, "index.html")], ["-o", os.path.join(subdir, "index.html")],
stdout=coveragelog) stdout=coveragelog)

View file

@ -195,13 +195,9 @@ sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/sanity_chk"))
from sanitylib import HardwareMap, TestSuite, SizeCalculator, CoverageTool from sanitylib import HardwareMap, TestSuite, SizeCalculator, CoverageTool
VERBOSE = 0
logger = logging.getLogger('sanitycheck') logger = logging.getLogger('sanitycheck')
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
options = None
def size_report(sc): def size_report(sc):
logger.info(sc.filename) logger.info(sc.filename)
logger.info("SECTION NAME VMA LMA SIZE HEX SZ TYPE") logger.info("SECTION NAME VMA LMA SIZE HEX SZ TYPE")
@ -635,8 +631,6 @@ structure in the main Zephyr tree: boards/<arch>/<board_name>/""")
def main(): def main():
start_time = time.time() start_time = time.time()
global VERBOSE
global options
options = parse_arguments() options = parse_arguments()
@ -669,7 +663,7 @@ def main():
# create console handler with a higher log level # create console handler with a higher log level
ch = logging.StreamHandler() ch = logging.StreamHandler()
VERBOSE += options.verbose VERBOSE = options.verbose
if VERBOSE > 1: if VERBOSE > 1:
ch.setLevel(logging.DEBUG) ch.setLevel(logging.DEBUG)
else: else:
@ -757,6 +751,7 @@ def main():
suite.extra_args = options.extra_args suite.extra_args = options.extra_args
suite.west_flash = options.west_flash suite.west_flash = options.west_flash
suite.west_runner = options.west_runner suite.west_runner = options.west_runner
suite.verbose = VERBOSE
if options.ninja: if options.ninja:
suite.generator_cmd = "ninja" suite.generator_cmd = "ninja"
@ -1018,7 +1013,7 @@ def main():
suite.summary(options.disable_unrecognized_section_test) suite.summary(options.disable_unrecognized_section_test)
if options.coverage: if options.coverage:
if options.gcov_tool is None: if not options.gcov_tools:
use_system_gcov = False use_system_gcov = False
for plat in options.coverage_platform: for plat in options.coverage_platform:
@ -1034,6 +1029,7 @@ def main():
logger.info("Generating coverage files...") logger.info("Generating coverage files...")
coverage_tool = CoverageTool.factory(options.coverage_tool) coverage_tool = CoverageTool.factory(options.coverage_tool)
coverage_tool.base_dir = ZEPHYR_BASE
coverage_tool.add_ignore_file('generated') coverage_tool.add_ignore_file('generated')
coverage_tool.add_ignore_directory('tests') coverage_tool.add_ignore_directory('tests')
coverage_tool.add_ignore_directory('samples') coverage_tool.add_ignore_directory('samples')