Skip to content

Commit 38385ed

Browse files
teburdnashif
authored andcommitted
twister: Platform key for test suites
Adds an option to inform twister a testsuite should only be built and run for platforms with unique sets of attributes. This enables for example keying on unique (arch, simulation) platforms to run the test suite on. The most common usage may be test suites configured to run once per (arch, simulation) pair as being enough. Additional information about platforms may enable running a test once per hardware IP block or once per soc family or soc avoiding duplicated effort in building and running tests when once suffices. Signed-off-by: Tom Burdick <[email protected]>
1 parent b36a31f commit 38385ed

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

doc/develop/test/twister.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,25 @@ harness: <string>
388388
Usually pertains to external dependency domains but can be anything such as
389389
console, sensor, net, keyboard, Bluetooth or pytest.
390390

391+
platform_key: <list of platform attributes>
392+
Often a test needs to only be built and run once to qualify as passing.
393+
Imagine a library of code that depends on the platform architecture where
394+
passing the test on a single platform for each arch is enough to qualify the
395+
tests and code as passing. The platform_key attribute enables doing just
396+
that.
397+
398+
For example to key on (arch, simulation) to ensure a test is run once
399+
per arch and simulation (as would be most common)::
400+
401+
platform_key:
402+
- arch
403+
- simulation
404+
405+
Adding platform (board) attributes to include things such as soc name,
406+
soc family, and perhaps sets of IP blocks implementing each peripheral
407+
interface would enable other interesting uses. For example, this could enable
408+
building and running SPI tests once for eacn unique IP block.
409+
391410
harness_config: <harness configuration options>
392411
Extra harness configuration options to be used to select a board and/or
393412
for handling generic Console with regex matching. Config can announce

scripts/pylib/twister/twisterlib/config_parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class TwisterConfigParser:
3333
"platform_type": {"type": "list", "default": []},
3434
"platform_exclude": {"type": "set"},
3535
"platform_allow": {"type": "set"},
36+
"platform_key": {"type": "list", "default": []},
3637
"toolchain_exclude": {"type": "set"},
3738
"toolchain_allow": {"type": "set"},
3839
"filter": {"type": "str"},

scripts/pylib/twister/twisterlib/environment.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,9 @@ def parse_arguments(args):
361361
help="Upon test failure, print relevant log data to stdout "
362362
"instead of just a path to it.")
363363

364+
parser.add_argument("--ignore-platform-key", action="store_true",
365+
help="Do not filter based on platform key")
366+
364367
parser.add_argument(
365368
"-j", "--jobs", type=int,
366369
help="Number of jobs for building, defaults to number of CPU threads, "

scripts/pylib/twister/twisterlib/testplan.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ def apply_filters(self, **kwargs):
570570
runnable = (self.options.device_testing or self.options.filter == 'runnable')
571571
force_toolchain = self.options.force_toolchain
572572
force_platform = self.options.force_platform
573+
ignore_platform_key = self.options.ignore_platform_key
573574
emu_filter = self.options.emulation_only
574575

575576
logger.debug("platform filter: " + str(platform_filter))
@@ -616,6 +617,8 @@ def apply_filters(self, **kwargs):
616617

617618
logger.info("Building initial testsuite list...")
618619

620+
keyed_tests = {}
621+
619622
for ts_name, ts in self.testsuites.items():
620623

621624
if ts.build_on_all and not platform_filter:
@@ -642,6 +645,7 @@ def apply_filters(self, **kwargs):
642645
platform_scope = list(filter(lambda item: item.name in ts.platform_allow, \
643646
self.platforms))
644647

648+
645649
# list of instances per testsuite, aka configurations.
646650
instance_list = []
647651
for plat in platform_scope:
@@ -746,6 +750,31 @@ def apply_filters(self, **kwargs):
746750
if plat.only_tags and not set(plat.only_tags) & ts.tags:
747751
instance.add_filter("Excluded tags per platform (only_tags)", Filters.PLATFORM)
748752

753+
# platform_key is a list of unique platform attributes that form a unique key a test
754+
# will match against to determine if it should be scheduled to run. A key containing a
755+
# field name that the platform does not have will filter the platform.
756+
#
757+
# A simple example is keying on arch and simulation to run a test once per unique (arch, simulation) platform.
758+
if not ignore_platform_key and hasattr(ts, 'platform_key') and len(ts.platform_key) > 0:
759+
# form a key by sorting the key fields first, then fetching the key fields from plat if they exist
760+
# if a field does not exist the test is still scheduled on that platform as its undeterminable.
761+
key_fields = sorted(set(ts.platform_key))
762+
key = [getattr(plat, key_field) for key_field in key_fields]
763+
has_all_fields = True
764+
for key_field in key_fields:
765+
if key_field is None:
766+
has_all_fields = False
767+
if has_all_fields:
768+
key.append(ts.name)
769+
key = tuple(key)
770+
keyed_test = keyed_tests.get(key)
771+
if keyed_test is not None:
772+
instance.add_filter(f"Excluded test already covered by platform_key {key} given fields {key_fields}", Filters.TESTSUITE)
773+
else:
774+
keyed_tests[key] = {'plat': plat, 'ts': ts}
775+
else:
776+
instance.add_filter(f"Excluded platform missing key fields demanded by test {key_fields}", Filters.PLATFORM)
777+
749778
test_configuration = ".".join([instance.platform.name,
750779
instance.testsuite.id])
751780
# skip quarantined tests

scripts/schemas/twister/testsuite-schema.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ mapping:
115115
required: false
116116
sequence:
117117
- type: str
118+
"platform_key":
119+
required: false
120+
type: seq
121+
matching: "all"
122+
sequence:
123+
- type: str
118124
"tags":
119125
type: str
120126
required: false
@@ -272,6 +278,12 @@ mapping:
272278
required: false
273279
sequence:
274280
- type: str
281+
"platform_key":
282+
required: false
283+
type: seq
284+
matching: "all"
285+
sequence:
286+
- type: str
275287
"tags":
276288
type: str
277289
required: false

0 commit comments

Comments
 (0)