twister: move cleanup and classification of code
Move code out of the main script and use global options. Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
396b8574eb
commit
f7d501447d
4 changed files with 39 additions and 40 deletions
|
@ -13,7 +13,6 @@ import yaml
|
||||||
import scl
|
import scl
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import expr_parser
|
|
||||||
|
|
||||||
from twister.enviornment import ZEPHYR_BASE
|
from twister.enviornment import ZEPHYR_BASE
|
||||||
|
|
||||||
|
@ -139,9 +138,23 @@ class HardwareMap:
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, env=None):
|
||||||
self.detected = []
|
self.detected = []
|
||||||
self.duts = []
|
self.duts = []
|
||||||
|
self.options = env.options
|
||||||
|
|
||||||
|
def discover(self):
|
||||||
|
if self.options.generate_hardware_map:
|
||||||
|
self.scan(persistent=self.options.persistent_hardware_map)
|
||||||
|
self.save(self.options.generate_hardware_map)
|
||||||
|
return 0
|
||||||
|
if not self.options.device_testing and self.options.hardware_map:
|
||||||
|
self.load(self.options.hardware_map)
|
||||||
|
logger.info("Available devices:")
|
||||||
|
table = []
|
||||||
|
self.dump(connected_only=True)
|
||||||
|
return 0
|
||||||
|
return 1
|
||||||
|
|
||||||
def add_device(self, serial, platform, pre_script, is_pty, baud=None):
|
def add_device(self, serial, platform, pre_script, is_pty, baud=None):
|
||||||
device = DUT(platform=platform, connected=True, pre_script=pre_script, serial_baud=baud)
|
device = DUT(platform=platform, connected=True, pre_script=pre_script, serial_baud=baud)
|
||||||
|
|
|
@ -389,10 +389,6 @@ class ProjectBuilder(FilterBuilder):
|
||||||
self.env = env
|
self.env = env
|
||||||
self.duts = None
|
self.duts = None
|
||||||
|
|
||||||
self.extra_args = kwargs.get('extra_args', [])
|
|
||||||
self.verbose = kwargs.get('verbose', None)
|
|
||||||
self.suite_name_check = kwargs.get('suite_name_check', True)
|
|
||||||
self.seed = kwargs.get('seed', 0)
|
|
||||||
if self.options.ninja:
|
if self.options.ninja:
|
||||||
self.generator_cmd = "ninja"
|
self.generator_cmd = "ninja"
|
||||||
self.generator = "Ninja"
|
self.generator = "Ninja"
|
||||||
|
@ -597,7 +593,7 @@ class ProjectBuilder(FilterBuilder):
|
||||||
results.error += 1
|
results.error += 1
|
||||||
else:
|
else:
|
||||||
results.failed += 1
|
results.failed += 1
|
||||||
if self.verbose:
|
if self.options.verbose:
|
||||||
status = Fore.RED + "FAILED " + Fore.RESET + instance.reason
|
status = Fore.RED + "FAILED " + Fore.RESET + instance.reason
|
||||||
else:
|
else:
|
||||||
print("")
|
print("")
|
||||||
|
@ -608,7 +604,7 @@ class ProjectBuilder(FilterBuilder):
|
||||||
Fore.RED,
|
Fore.RED,
|
||||||
Fore.RESET,
|
Fore.RESET,
|
||||||
instance.reason))
|
instance.reason))
|
||||||
if not self.verbose:
|
if not self.options.verbose:
|
||||||
self.log_info_file(self.options.inline_logs)
|
self.log_info_file(self.options.inline_logs)
|
||||||
elif instance.status in ["skipped", "filtered"]:
|
elif instance.status in ["skipped", "filtered"]:
|
||||||
status = Fore.YELLOW + "SKIPPED" + Fore.RESET
|
status = Fore.YELLOW + "SKIPPED" + Fore.RESET
|
||||||
|
@ -624,8 +620,8 @@ class ProjectBuilder(FilterBuilder):
|
||||||
logger.debug(f"Unknown status = {instance.status}")
|
logger.debug(f"Unknown status = {instance.status}")
|
||||||
status = Fore.YELLOW + "UNKNOWN" + Fore.RESET
|
status = Fore.YELLOW + "UNKNOWN" + Fore.RESET
|
||||||
|
|
||||||
if self.verbose:
|
if self.options.verbose:
|
||||||
if self.cmake_only:
|
if self.options.cmake_only:
|
||||||
more_info = "cmake"
|
more_info = "cmake"
|
||||||
elif instance.status in ["skipped", "filtered"]:
|
elif instance.status in ["skipped", "filtered"]:
|
||||||
more_info = instance.reason
|
more_info = instance.reason
|
||||||
|
@ -641,7 +637,7 @@ class ProjectBuilder(FilterBuilder):
|
||||||
if ( instance.status in ["error", "failed", "timeout", "flash_error"]
|
if ( instance.status in ["error", "failed", "timeout", "flash_error"]
|
||||||
and hasattr(self.instance.handler, 'seed')
|
and hasattr(self.instance.handler, 'seed')
|
||||||
and self.instance.handler.seed is not None ):
|
and self.instance.handler.seed is not None ):
|
||||||
more_info += "/seed: " + str(self.seed)
|
more_info += "/seed: " + str(self.options.seed)
|
||||||
|
|
||||||
logger.info("{:>{}}/{} {:<25} {:<50} {} ({})".format(
|
logger.info("{:>{}}/{} {:<25} {:<50} {} ({})".format(
|
||||||
results.done + results.skipped_filter, total_tests_width, total_to_do , instance.platform.name,
|
results.done + results.skipped_filter, total_tests_width, total_to_do , instance.platform.name,
|
||||||
|
@ -674,7 +670,7 @@ class ProjectBuilder(FilterBuilder):
|
||||||
|
|
||||||
instance = self.instance
|
instance = self.instance
|
||||||
args = self.testsuite.extra_args[:]
|
args = self.testsuite.extra_args[:]
|
||||||
args += self.extra_args
|
args += self.options.extra_args
|
||||||
|
|
||||||
if instance.handler:
|
if instance.handler:
|
||||||
args += instance.handler.args
|
args += instance.handler.args
|
||||||
|
@ -719,11 +715,11 @@ class ProjectBuilder(FilterBuilder):
|
||||||
if instance.handler.type_str == "device":
|
if instance.handler.type_str == "device":
|
||||||
instance.handler.duts = self.duts
|
instance.handler.duts = self.duts
|
||||||
|
|
||||||
if(self.seed is not None and instance.platform.name.startswith("native_posix")):
|
if(self.options.seed is not None and instance.platform.name.startswith("native_posix")):
|
||||||
self.parse_generated()
|
self.parse_generated()
|
||||||
if('CONFIG_FAKE_ENTROPY_NATIVE_POSIX' in self.defconfig and
|
if('CONFIG_FAKE_ENTROPY_NATIVE_POSIX' in self.defconfig and
|
||||||
self.defconfig['CONFIG_FAKE_ENTROPY_NATIVE_POSIX'] == 'y'):
|
self.defconfig['CONFIG_FAKE_ENTROPY_NATIVE_POSIX'] == 'y'):
|
||||||
instance.handler.seed = self.seed
|
instance.handler.seed = self.options.seed
|
||||||
|
|
||||||
instance.handler.handle()
|
instance.handler.handle()
|
||||||
|
|
||||||
|
|
|
@ -223,6 +223,9 @@ class TestPlan:
|
||||||
self.find_subtests()
|
self.find_subtests()
|
||||||
self.add_configurations()
|
self.add_configurations()
|
||||||
|
|
||||||
|
if self.load_errors:
|
||||||
|
raise TwisterRuntimeError("Errors while loading configurations")
|
||||||
|
|
||||||
# handle quarantine
|
# handle quarantine
|
||||||
ql = self.options.quarantine_list
|
ql = self.options.quarantine_list
|
||||||
if ql:
|
if ql:
|
||||||
|
@ -238,6 +241,11 @@ class TestPlan:
|
||||||
if self.options.subset:
|
if self.options.subset:
|
||||||
subset, sets = self.options.subset.split("/")
|
subset, sets = self.options.subset.split("/")
|
||||||
subset = int(subset)
|
subset = int(subset)
|
||||||
|
if int(subset) > 0 and int(sets) >= int(subset):
|
||||||
|
logger.info("Running only a subset: %s/%s" % (subset, sets))
|
||||||
|
else:
|
||||||
|
logger.error("You have provided a wrong subset value: %s." % self.options.subset)
|
||||||
|
return
|
||||||
self.generate_subset(subset, sets)
|
self.generate_subset(subset, sets)
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
|
|
|
@ -894,32 +894,17 @@ def main():
|
||||||
size_report(SizeCalculator(fn, []))
|
size_report(SizeCalculator(fn, []))
|
||||||
return
|
return
|
||||||
|
|
||||||
hwm = HardwareMap()
|
|
||||||
if options.generate_hardware_map:
|
|
||||||
hwm.scan(persistent=options.persistent_hardware_map)
|
|
||||||
hwm.save(options.generate_hardware_map)
|
|
||||||
return
|
|
||||||
|
|
||||||
if not options.device_testing and options.hardware_map:
|
|
||||||
hwm.load(options.hardware_map)
|
|
||||||
logger.info("Available devices:")
|
|
||||||
table = []
|
|
||||||
hwm.dump(connected_only=True)
|
|
||||||
return
|
|
||||||
|
|
||||||
if options.subset:
|
|
||||||
subset, sets = options.subset.split("/")
|
|
||||||
if int(subset) > 0 and int(sets) >= int(subset):
|
|
||||||
logger.info("Running only a subset: %s/%s" % (subset, sets))
|
|
||||||
else:
|
|
||||||
logger.error("You have provided a wrong subset value: %s." % options.subset)
|
|
||||||
return
|
|
||||||
|
|
||||||
env = TwisterEnv(options)
|
env = TwisterEnv(options)
|
||||||
env.hwm = hwm
|
|
||||||
env.discover()
|
env.discover()
|
||||||
|
|
||||||
tplan = TestPlan(options.board_root, options.testsuite_root, hwm, env, options.outdir)
|
hwm = HardwareMap(env)
|
||||||
|
env.hwm = hwm
|
||||||
|
ret = hwm.discover()
|
||||||
|
if ret == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
tplan = TestPlan(options.board_root, options.testsuite_root, env, options.outdir)
|
||||||
try:
|
try:
|
||||||
tplan.discover()
|
tplan.discover()
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
|
@ -960,13 +945,9 @@ def main():
|
||||||
for d in tplan.hwm.duts:
|
for d in tplan.hwm.duts:
|
||||||
d.fixtures.extend(options.fixture)
|
d.fixtures.extend(options.fixture)
|
||||||
|
|
||||||
if tplan.load_errors:
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if tplan.report() == 0:
|
if tplan.report() == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
tplan.load()
|
tplan.load()
|
||||||
|
|
||||||
if options.list_tests and options.platform:
|
if options.list_tests and options.platform:
|
||||||
|
@ -1016,6 +997,7 @@ def main():
|
||||||
tplan.create_build_dir_links()
|
tplan.create_build_dir_links()
|
||||||
|
|
||||||
runner = TwisterRunner(tplan.instances, tplan.testsuites, env)
|
runner = TwisterRunner(tplan.instances, tplan.testsuites, env)
|
||||||
|
runner.duts = hwm.duts
|
||||||
runner.run()
|
runner.run()
|
||||||
|
|
||||||
# figure out which report to use for size comparison
|
# figure out which report to use for size comparison
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue