twister: testplan: move calls to json loading/filter into class

Move all code related to instance filtering and loading into the class
instead of having it in the main script. Simplify option passing.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2022-06-11 17:24:28 -04:00
commit 396b8574eb
2 changed files with 20 additions and 73 deletions

View file

@ -18,7 +18,6 @@ import colorama
import json
import collections
from typing import List
from winreg import QueryValue
from collections import OrderedDict
from itertools import islice
@ -190,8 +189,7 @@ class TestPlan:
self.instances = dict()
self.warnings = 0
# hardcoded for now
self.duts = []
self.hwm = env.hwm
# used during creating shorter build paths
self.link_dir_counter = 0
self.modules = []
@ -242,7 +240,6 @@ class TestPlan:
subset = int(subset)
self.generate_subset(subset, sets)
def load(self):
if self.options.report_suffix:
@ -256,32 +253,20 @@ class TestPlan:
elif self.options.load_tests:
self.load_from_file(self.options.load_tests)
self.selected_platforms = set(p.platform.name for p in self.instances.values())
elif self.test_only:
elif self.options.test_only:
# Get list of connected hardware and filter tests to only be run on connected hardware
# in cases where no platform was specified when running the tests.
# If the platform does not exist in the hardware map, just skip it.
connected_list = []
if not self.options.platform:
for connected in hwm.duts:
for connected in self.hwm.duts:
if connected['connected']:
connected_list.append(connected['platform'])
self.load_from_file(last_run, filter_platform=connected_list)
self.selected_platforms = set(p.platform.name for p in self.instances.values())
else:
self.apply_filters(
enable_slow=options.enable_slow,
platform=options.platform,
exclude_platform=options.exclude_platform,
arch=options.arch,
tag=options.tag,
exclude_tag=options.exclude_tag,
force_toolchain=options.force_toolchain,
all=options.all,
emulation_only=options.emulation_only,
runnable=(options.device_testing or options.filter == 'runnable'),
force_platform=options.force_platform
)
self.apply_filters()
def generate_subset(self, subset, sets):
# Test instances are sorted depending on the context. For CI runs
@ -942,18 +927,17 @@ class TestPlan:
def apply_filters(self, **kwargs):
toolchain = self.env.toolchain
platform_filter = kwargs.get('platform')
exclude_platform = kwargs.get('exclude_platform', [])
platform_filter = self.options.platform
exclude_platform = self.options.exclude_platform
testsuite_filter = self.run_individual_testsuite
arch_filter = kwargs.get('arch')
tag_filter = kwargs.get('tag')
exclude_tag = kwargs.get('exclude_tag')
all_filter = kwargs.get('all')
runnable = kwargs.get('runnable')
force_toolchain = kwargs.get('force_toolchain')
force_platform = kwargs.get('force_platform')
emu_filter = kwargs.get('emulation_only')
arch_filter = self.options.arch
tag_filter = self.options.tag
exclude_tag = self.options.exclude_tag
all_filter = self.options.all
runnable = (self.options.device_testing or self.options.filter == 'runnable')
force_toolchain = self.options.force_toolchain
force_platform = self.options.force_platform
emu_filter = self.options.emulation_only
logger.debug("platform filter: " + str(platform_filter))
logger.debug(" arch_filter: " + str(arch_filter))
@ -1029,8 +1013,8 @@ class TestPlan:
tfilter,
self.options.fixture
)
if runnable and self.duts:
for h in self.duts:
if runnable and self.hwm.duts:
for h in self.hwm.duts:
if h.platform == plat.name:
if ts.harness_config.get('fixture') in h.fixtures:
instance.run = True

View file

@ -916,9 +916,10 @@ def main():
return
env = TwisterEnv(options)
env.hwm = hwm
env.discover()
tplan = TestPlan(options.board_root, options.testsuite_root, env, options.outdir)
tplan = TestPlan(options.board_root, options.testsuite_root, hwm, env, options.outdir)
try:
tplan.discover()
except RuntimeError as e:
@ -928,7 +929,6 @@ def main():
if options.device_testing:
if options.hardware_map:
hwm.load(options.hardware_map)
tplan.duts = hwm.duts
if not options.platform:
options.platform = []
for d in hwm.duts:
@ -950,7 +950,6 @@ def main():
options.pre_script,
True)
tplan.duts = hwm.duts
else:
logger.error("""When --device-testing is used with
--device-serial or --device-serial-pty,
@ -958,7 +957,7 @@ def main():
# the fixtures given by twister command explicitly should be assigned to each DUT
if options.fixture:
for d in tplan.duts:
for d in tplan.hwm.duts:
d.fixtures.extend(options.fixture)
if tplan.load_errors:
@ -967,43 +966,8 @@ def main():
if tplan.report() == 0:
return
if options.report_suffix:
last_run = os.path.join(options.outdir, "twister_{}.json".format(options.report_suffix))
else:
last_run = os.path.join(options.outdir, "twister.json")
if options.only_failed:
tplan.load_from_file(last_run)
tplan.selected_platforms = set(p.platform.name for p in tplan.instances.values())
elif options.load_tests:
tplan.load_from_file(options.load_tests)
tplan.selected_platforms = set(p.platform.name for p in tplan.instances.values())
elif options.test_only:
# Get list of connected hardware and filter tests to only be run on connected hardware
# in cases where no platform was specified when running the tests.
# If the platform does not exist in the hardware map, just skip it.
connected_list = []
if not options.platform:
for connected in hwm.duts:
if connected['connected']:
connected_list.append(connected['platform'])
tplan.load_from_file(last_run, filter_platform=connected_list)
tplan.selected_platforms = set(p.platform.name for p in tplan.instances.values())
else:
tplan.apply_filters(
enable_slow=options.enable_slow,
platform=options.platform,
exclude_platform=options.exclude_platform,
arch=options.arch,
tag=options.tag,
exclude_tag=options.exclude_tag,
force_toolchain=options.force_toolchain,
all=options.all,
emulation_only=options.emulation_only,
runnable=(options.device_testing or options.filter == 'runnable'),
force_platform=options.force_platform
)
tplan.load()
if options.list_tests and options.platform:
tplan.report_platform_tests(options.platform)
@ -1052,7 +1016,6 @@ def main():
tplan.create_build_dir_links()
runner = TwisterRunner(tplan.instances, tplan.testsuites, env)
runner.duts = tplan.duts
runner.run()
# figure out which report to use for size comparison