Skip to content

Commit da1066f

Browse files
PerMacnashif
authored andcommitted
twister: Add sysbuild boolean to platform definitions
More complex platforms require sysbuild to use always, even for such "simple" samples like hello_world. Such platforms can have `sysbuild: true` entry in their board_name.yaml used by twister. Using such entry will tell twister, that sysbuild must always be used on a given platform. Twister is aligned to have information about need of sysbuild at instance (platform + suite) level (was only at suite level before). Instance.sysbuild is true whenever a test suite or a platform requires sysbuild. Twister pytest unit tests are aligned with changes. Signed-off-by: Maciej Perkowski <[email protected]>
1 parent e902a08 commit da1066f

File tree

9 files changed

+24
-15
lines changed

9 files changed

+24
-15
lines changed

scripts/pylib/twister/twisterlib/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def _final_handle_actions(self, harness, handler_time):
153153
self.instance.record(harness.recording)
154154

155155
def get_default_domain_build_dir(self):
156-
if self.instance.testsuite.sysbuild:
156+
if self.instance.sysbuild:
157157
# Load domain yaml to get default domain build directory
158158
# Note: for targets using QEMU, we assume that the target will
159159
# have added any additional images to the run target manually

scripts/pylib/twister/twisterlib/platform.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def __init__(self):
2424

2525
self.name = ""
2626
self.normalized_name = ""
27+
# if sysbuild to be used by default on a given platform
28+
self.sysbuild = False
2729
self.twister = True
2830
# if no RAM size is specified by the board, take a default of 128K
2931
self.ram = 128
@@ -56,6 +58,7 @@ def load(self, platform_file):
5658

5759
self.name = data['identifier']
5860
self.normalized_name = self.name.replace("/", "_")
61+
self.sysbuild = data.get("sysbuild", False)
5962
self.twister = data.get("twister", True)
6063
# if no RAM size is specified by the board, take a default of 128K
6164
self.ram = data.get("ram", 128)

scripts/pylib/twister/twisterlib/runner.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def run_cmake(self, args="", filter_stages=[]):
335335
gen_defines_args = ""
336336

337337
warning_command = 'CONFIG_COMPILER_WARNINGS_AS_ERRORS'
338-
if self.testsuite.sysbuild:
338+
if self.instance.sysbuild:
339339
warning_command = 'SB_' + warning_command
340340

341341
logger.debug("Running cmake on %s for %s" % (self.source_dir, self.platform.name))
@@ -357,7 +357,7 @@ def run_cmake(self, args="", filter_stages=[]):
357357
f'-P{canonical_zephyr_base}/cmake/package_helper.cmake',
358358
]
359359

360-
if self.testsuite.sysbuild and not filter_stages:
360+
if self.instance.sysbuild and not filter_stages:
361361
logger.debug("Building %s using sysbuild" % (self.source_dir))
362362
source_args = [
363363
f'-S{canonical_zephyr_base}/share/sysbuild',
@@ -445,7 +445,7 @@ def parse_generated(self, filter_stages=[]):
445445
if self.platform.name == "unit_testing":
446446
return {}
447447

448-
if self.testsuite.sysbuild and not filter_stages:
448+
if self.instance.sysbuild and not filter_stages:
449449
# Load domain yaml to get default domain build directory
450450
domain_path = os.path.join(self.build_dir, "domains.yaml")
451451
domains = Domains.from_file(domain_path)
@@ -498,7 +498,7 @@ def parse_generated(self, filter_stages=[]):
498498
filter_data.update(self.defconfig)
499499
filter_data.update(self.cmake_cache)
500500

501-
if self.testsuite.sysbuild and self.env.options.device_testing:
501+
if self.instance.sysbuild and self.env.options.device_testing:
502502
# Verify that twister's arguments support sysbuild.
503503
# Twister sysbuild flashing currently only works with west, so
504504
# --west-flash must be passed.
@@ -806,7 +806,7 @@ def cleanup_device_testing_artifacts(self):
806806
files_to_keep = self._get_binaries()
807807
files_to_keep.append(os.path.join('zephyr', 'runners.yaml'))
808808

809-
if self.testsuite.sysbuild:
809+
if self.instance.sysbuild:
810810
files_to_keep.append('domains.yaml')
811811
for domain in self.instance.domains.get_domains():
812812
files_to_keep += self._get_artifact_allow_list_for_domain(domain.name)
@@ -846,7 +846,7 @@ def _get_binaries(self) -> List[str]:
846846
# Get binaries for a single-domain build
847847
binaries += self._get_binaries_from_runners()
848848
# Get binaries in the case of a multiple-domain build
849-
if self.testsuite.sysbuild:
849+
if self.instance.sysbuild:
850850
for domain in self.instance.domains.get_domains():
851851
binaries += self._get_binaries_from_runners(domain.name)
852852

scripts/pylib/twister/twisterlib/testinstance.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def __init__(self, testsuite, platform, outdir):
6767
self.build_dir = os.path.join(outdir, platform.normalized_name, source_dir_rel, testsuite.name)
6868
self.run_id = self._get_run_id()
6969
self.domains = None
70+
# Instance need to use sysbuild if a given suite or a platform requires it
71+
self.sysbuild = testsuite.sysbuild or platform.sysbuild
7072

7173
self.run = False
7274
self.testcases: list[TestCase] = []
@@ -335,7 +337,7 @@ def calculate_sizes(self, from_buildlog: bool = False, generate_warning: bool =
335337

336338
def get_elf_file(self) -> str:
337339

338-
if self.testsuite.sysbuild:
340+
if self.sysbuild:
339341
build_dir = self.domains.get_default_domain().build_dir
340342
else:
341343
build_dir = self.build_dir

scripts/schemas/twister/platform-schema.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ mapping:
6666
type: seq
6767
seq:
6868
- type: str
69+
"sysbuild":
70+
type: bool
6971
"env":
7072
type: seq
7173
seq:

scripts/tests/twister/pytest_integration/test_harness_pytest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def testinstance() -> TestInstance:
1919
testsuite = TestSuite('.', 'samples/hello', 'unit.test')
2020
testsuite.harness_config = {}
2121
testsuite.ignore_faults = False
22+
testsuite.sysbuild = False
2223
platform = Platform()
2324

2425
testinstance = TestInstance(testsuite, platform, 'outdir')

scripts/tests/twister/test_handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def test_binaryhandler_create_command(
445445
handler.seed = seed
446446
handler.extra_test_args = extra_args
447447
handler.build_dir = 'build_dir'
448-
handler.instance.testsuite.sysbuild = False
448+
handler.instance.sysbuild = False
449449
handler.platform = SimpleNamespace()
450450
handler.platform.resc = "file.resc"
451451
handler.platform.uart = "uart"
@@ -1469,7 +1469,7 @@ def test_qemuhandler_get_default_domain_build_dir(
14691469
from_file_mock = mock.Mock(return_value=domains_mock)
14701470

14711471
handler = QEMUHandler(mocked_instance, 'build')
1472-
handler.instance.testsuite.sysbuild = self_sysbuild
1472+
handler.instance.sysbuild = self_sysbuild
14731473
handler.build_dir = self_build_dir
14741474

14751475
with mock.patch('domains.Domains.from_file', from_file_mock):

scripts/tests/twister/test_runner.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def mocked_instance(tmp_path):
4242
testsuite.source_dir: str = ''
4343
instance.testsuite = testsuite
4444
platform = mock.Mock()
45+
platform.sysbuild = False
4546
platform.binaries: List[str] = []
4647
instance.platform = platform
4748
build_dir = tmp_path / 'build_dir'
@@ -131,15 +132,15 @@ def test_if_default_binaries_are_taken_properly(project_builder: ProjectBuilder)
131132
os.path.join('zephyr', 'zephyr.elf'),
132133
os.path.join('zephyr', 'zephyr.exe'),
133134
]
134-
project_builder.testsuite.sysbuild = False
135+
project_builder.instance.sysbuild = False
135136
binaries = project_builder._get_binaries()
136137
assert sorted(binaries) == sorted(default_binaries)
137138

138139

139140
def test_if_binaries_from_platform_are_taken_properly(project_builder: ProjectBuilder):
140141
platform_binaries = ['spi_image.bin']
141142
project_builder.platform.binaries = platform_binaries
142-
project_builder.testsuite.sysbuild = False
143+
project_builder.instance.sysbuild = False
143144
platform_binaries_expected = [os.path.join('zephyr', bin) for bin in platform_binaries]
144145
binaries = project_builder._get_binaries()
145146
assert sorted(binaries) == sorted(platform_binaries_expected)
@@ -698,7 +699,6 @@ def mock_pickle(datafile):
698699
return mock.Mock()
699700

700701
testsuite_mock = mock.Mock()
701-
testsuite_mock.sysbuild = 'sysbuild' if sysbuild else None
702702
testsuite_mock.name = 'dummy.testsuite.name'
703703
testsuite_mock.filter = testsuite_filter
704704
platform_mock = mock.Mock()
@@ -710,6 +710,7 @@ def mock_pickle(datafile):
710710
fb = FilterBuilder(testsuite_mock, platform_mock, source_dir, build_dir,
711711
mocked_jobserver)
712712
instance_mock = mock.Mock()
713+
instance_mock.sysbuild = 'sysbuild' if sysbuild else None
713714
fb.instance = instance_mock
714715
fb.env = mock.Mock()
715716
fb.env.options = mock.Mock()
@@ -1675,7 +1676,7 @@ def test_projectbuilder_cleanup_device_testing_artifacts(
16751676
bins = [os.path.join('zephyr', 'file.bin')]
16761677

16771678
instance_mock = mock.Mock()
1678-
instance_mock.testsuite.sysbuild = False
1679+
instance_mock.sysbuild = False
16791680
build_dir = os.path.join('build', 'dir')
16801681
instance_mock.build_dir = build_dir
16811682
env_mock = mock.Mock()

scripts/tests/twister/test_testinstance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ def test_testinstance_get_elf_file(caplog, tmp_path, testinstance, sysbuild, exp
597597
sysbuild_elf2 = zephyr_dir / 'dummy2.elf'
598598
sysbuild_elf2.write_bytes(b'0')
599599

600-
testinstance.testsuite.sysbuild = sysbuild
600+
testinstance.sysbuild = sysbuild
601601
testinstance.domains = mock.Mock(
602602
get_default_domain=mock.Mock(
603603
return_value=mock.Mock(

0 commit comments

Comments
 (0)