From 3c17162be6a4630f58658a2c066fd0e72a7ac9fd Mon Sep 17 00:00:00 2001 From: Maciej Perkowski Date: Wed, 5 Jun 2024 12:52:40 +0200 Subject: [PATCH 1/2] 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 --- scripts/pylib/twister/twisterlib/handlers.py | 2 +- scripts/pylib/twister/twisterlib/platform.py | 3 +++ scripts/pylib/twister/twisterlib/runner.py | 12 ++++++------ scripts/pylib/twister/twisterlib/testinstance.py | 4 +++- scripts/schemas/twister/platform-schema.yaml | 2 ++ .../pytest_integration/test_harness_pytest.py | 1 + scripts/tests/twister/test_handlers.py | 4 ++-- scripts/tests/twister/test_runner.py | 9 +++++---- scripts/tests/twister/test_testinstance.py | 2 +- 9 files changed, 24 insertions(+), 15 deletions(-) diff --git a/scripts/pylib/twister/twisterlib/handlers.py b/scripts/pylib/twister/twisterlib/handlers.py index 8655dc0d54fccd..f8324252450026 100755 --- a/scripts/pylib/twister/twisterlib/handlers.py +++ b/scripts/pylib/twister/twisterlib/handlers.py @@ -153,7 +153,7 @@ def _final_handle_actions(self, harness, handler_time): self.instance.record(harness.recording) def get_default_domain_build_dir(self): - if self.instance.testsuite.sysbuild: + if self.instance.sysbuild: # Load domain yaml to get default domain build directory # Note: for targets using QEMU, we assume that the target will # have added any additional images to the run target manually diff --git a/scripts/pylib/twister/twisterlib/platform.py b/scripts/pylib/twister/twisterlib/platform.py index 44672c36a77cfd..6429907928f96c 100644 --- a/scripts/pylib/twister/twisterlib/platform.py +++ b/scripts/pylib/twister/twisterlib/platform.py @@ -24,6 +24,8 @@ def __init__(self): self.name = "" self.normalized_name = "" + # if sysbuild to be used by default on a given platform + self.sysbuild = False self.twister = True # if no RAM size is specified by the board, take a default of 128K self.ram = 128 @@ -56,6 +58,7 @@ def load(self, platform_file): self.name = data['identifier'] self.normalized_name = self.name.replace("/", "_") + self.sysbuild = data.get("sysbuild", False) self.twister = data.get("twister", True) # if no RAM size is specified by the board, take a default of 128K self.ram = data.get("ram", 128) diff --git a/scripts/pylib/twister/twisterlib/runner.py b/scripts/pylib/twister/twisterlib/runner.py index 6f723ca477c52d..567f125cd8caf0 100644 --- a/scripts/pylib/twister/twisterlib/runner.py +++ b/scripts/pylib/twister/twisterlib/runner.py @@ -335,7 +335,7 @@ def run_cmake(self, args="", filter_stages=[]): gen_defines_args = "" warning_command = 'CONFIG_COMPILER_WARNINGS_AS_ERRORS' - if self.testsuite.sysbuild: + if self.instance.sysbuild: warning_command = 'SB_' + warning_command 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=[]): f'-P{canonical_zephyr_base}/cmake/package_helper.cmake', ] - if self.testsuite.sysbuild and not filter_stages: + if self.instance.sysbuild and not filter_stages: logger.debug("Building %s using sysbuild" % (self.source_dir)) source_args = [ f'-S{canonical_zephyr_base}/share/sysbuild', @@ -445,7 +445,7 @@ def parse_generated(self, filter_stages=[]): if self.platform.name == "unit_testing": return {} - if self.testsuite.sysbuild and not filter_stages: + if self.instance.sysbuild and not filter_stages: # Load domain yaml to get default domain build directory domain_path = os.path.join(self.build_dir, "domains.yaml") domains = Domains.from_file(domain_path) @@ -498,7 +498,7 @@ def parse_generated(self, filter_stages=[]): filter_data.update(self.defconfig) filter_data.update(self.cmake_cache) - if self.testsuite.sysbuild and self.env.options.device_testing: + if self.instance.sysbuild and self.env.options.device_testing: # Verify that twister's arguments support sysbuild. # Twister sysbuild flashing currently only works with west, so # --west-flash must be passed. @@ -806,7 +806,7 @@ def cleanup_device_testing_artifacts(self): files_to_keep = self._get_binaries() files_to_keep.append(os.path.join('zephyr', 'runners.yaml')) - if self.testsuite.sysbuild: + if self.instance.sysbuild: files_to_keep.append('domains.yaml') for domain in self.instance.domains.get_domains(): files_to_keep += self._get_artifact_allow_list_for_domain(domain.name) @@ -846,7 +846,7 @@ def _get_binaries(self) -> List[str]: # Get binaries for a single-domain build binaries += self._get_binaries_from_runners() # Get binaries in the case of a multiple-domain build - if self.testsuite.sysbuild: + if self.instance.sysbuild: for domain in self.instance.domains.get_domains(): binaries += self._get_binaries_from_runners(domain.name) diff --git a/scripts/pylib/twister/twisterlib/testinstance.py b/scripts/pylib/twister/twisterlib/testinstance.py index b7a46fd5008ac4..3540b3e58f2010 100644 --- a/scripts/pylib/twister/twisterlib/testinstance.py +++ b/scripts/pylib/twister/twisterlib/testinstance.py @@ -67,6 +67,8 @@ def __init__(self, testsuite, platform, outdir): self.build_dir = os.path.join(outdir, platform.normalized_name, source_dir_rel, testsuite.name) self.run_id = self._get_run_id() self.domains = None + # Instance need to use sysbuild if a given suite or a platform requires it + self.sysbuild = testsuite.sysbuild or platform.sysbuild self.run = False self.testcases: list[TestCase] = [] @@ -335,7 +337,7 @@ def calculate_sizes(self, from_buildlog: bool = False, generate_warning: bool = def get_elf_file(self) -> str: - if self.testsuite.sysbuild: + if self.sysbuild: build_dir = self.domains.get_default_domain().build_dir else: build_dir = self.build_dir diff --git a/scripts/schemas/twister/platform-schema.yaml b/scripts/schemas/twister/platform-schema.yaml index dd9dfe10dafead..c651f83c3e3641 100644 --- a/scripts/schemas/twister/platform-schema.yaml +++ b/scripts/schemas/twister/platform-schema.yaml @@ -66,6 +66,8 @@ mapping: type: seq seq: - type: str + "sysbuild": + type: bool "env": type: seq seq: diff --git a/scripts/tests/twister/pytest_integration/test_harness_pytest.py b/scripts/tests/twister/pytest_integration/test_harness_pytest.py index 898f7e5ababdeb..86628d40ce80cd 100644 --- a/scripts/tests/twister/pytest_integration/test_harness_pytest.py +++ b/scripts/tests/twister/pytest_integration/test_harness_pytest.py @@ -19,6 +19,7 @@ def testinstance() -> TestInstance: testsuite = TestSuite('.', 'samples/hello', 'unit.test') testsuite.harness_config = {} testsuite.ignore_faults = False + testsuite.sysbuild = False platform = Platform() testinstance = TestInstance(testsuite, platform, 'outdir') diff --git a/scripts/tests/twister/test_handlers.py b/scripts/tests/twister/test_handlers.py index 79825c4784639b..9ae333389fa06b 100644 --- a/scripts/tests/twister/test_handlers.py +++ b/scripts/tests/twister/test_handlers.py @@ -445,7 +445,7 @@ def test_binaryhandler_create_command( handler.seed = seed handler.extra_test_args = extra_args handler.build_dir = 'build_dir' - handler.instance.testsuite.sysbuild = False + handler.instance.sysbuild = False handler.platform = SimpleNamespace() handler.platform.resc = "file.resc" handler.platform.uart = "uart" @@ -1469,7 +1469,7 @@ def test_qemuhandler_get_default_domain_build_dir( from_file_mock = mock.Mock(return_value=domains_mock) handler = QEMUHandler(mocked_instance, 'build') - handler.instance.testsuite.sysbuild = self_sysbuild + handler.instance.sysbuild = self_sysbuild handler.build_dir = self_build_dir with mock.patch('domains.Domains.from_file', from_file_mock): diff --git a/scripts/tests/twister/test_runner.py b/scripts/tests/twister/test_runner.py index 88ed43a87fef8b..e1e12242108ef7 100644 --- a/scripts/tests/twister/test_runner.py +++ b/scripts/tests/twister/test_runner.py @@ -42,6 +42,7 @@ def mocked_instance(tmp_path): testsuite.source_dir: str = '' instance.testsuite = testsuite platform = mock.Mock() + platform.sysbuild = False platform.binaries: List[str] = [] instance.platform = platform build_dir = tmp_path / 'build_dir' @@ -131,7 +132,7 @@ def test_if_default_binaries_are_taken_properly(project_builder: ProjectBuilder) os.path.join('zephyr', 'zephyr.elf'), os.path.join('zephyr', 'zephyr.exe'), ] - project_builder.testsuite.sysbuild = False + project_builder.instance.sysbuild = False binaries = project_builder._get_binaries() assert sorted(binaries) == sorted(default_binaries) @@ -139,7 +140,7 @@ def test_if_default_binaries_are_taken_properly(project_builder: ProjectBuilder) def test_if_binaries_from_platform_are_taken_properly(project_builder: ProjectBuilder): platform_binaries = ['spi_image.bin'] project_builder.platform.binaries = platform_binaries - project_builder.testsuite.sysbuild = False + project_builder.instance.sysbuild = False platform_binaries_expected = [os.path.join('zephyr', bin) for bin in platform_binaries] binaries = project_builder._get_binaries() assert sorted(binaries) == sorted(platform_binaries_expected) @@ -698,7 +699,6 @@ def mock_pickle(datafile): return mock.Mock() testsuite_mock = mock.Mock() - testsuite_mock.sysbuild = 'sysbuild' if sysbuild else None testsuite_mock.name = 'dummy.testsuite.name' testsuite_mock.filter = testsuite_filter platform_mock = mock.Mock() @@ -710,6 +710,7 @@ def mock_pickle(datafile): fb = FilterBuilder(testsuite_mock, platform_mock, source_dir, build_dir, mocked_jobserver) instance_mock = mock.Mock() + instance_mock.sysbuild = 'sysbuild' if sysbuild else None fb.instance = instance_mock fb.env = mock.Mock() fb.env.options = mock.Mock() @@ -1675,7 +1676,7 @@ def test_projectbuilder_cleanup_device_testing_artifacts( bins = [os.path.join('zephyr', 'file.bin')] instance_mock = mock.Mock() - instance_mock.testsuite.sysbuild = False + instance_mock.sysbuild = False build_dir = os.path.join('build', 'dir') instance_mock.build_dir = build_dir env_mock = mock.Mock() diff --git a/scripts/tests/twister/test_testinstance.py b/scripts/tests/twister/test_testinstance.py index 4f820532aeaf70..560923173b0948 100644 --- a/scripts/tests/twister/test_testinstance.py +++ b/scripts/tests/twister/test_testinstance.py @@ -597,7 +597,7 @@ def test_testinstance_get_elf_file(caplog, tmp_path, testinstance, sysbuild, exp sysbuild_elf2 = zephyr_dir / 'dummy2.elf' sysbuild_elf2.write_bytes(b'0') - testinstance.testsuite.sysbuild = sysbuild + testinstance.sysbuild = sysbuild testinstance.domains = mock.Mock( get_default_domain=mock.Mock( return_value=mock.Mock( From 80ad595b4477b40fad3f30f2838f163443388414 Mon Sep 17 00:00:00 2001 From: Maciej Perkowski Date: Wed, 5 Jun 2024 14:33:49 +0200 Subject: [PATCH 2/2] boards: nrf: Update nrf54h and nrf54l yamls to use sysbuild in twister Nrf54h's and nrf54l's targets are the first targets complex enough that a sysbuild must be used on every build for them. This information is reflected in their yamls. These entries tell twister to always use sysbuild for those targets. Signed-off-by: Maciej Perkowski --- boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuapp.yaml | 1 + boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuppr.yaml | 1 + boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuppr_xip.yaml | 1 + boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpurad.yaml | 1 + boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuapp.yaml | 1 + boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuflpr.yaml | 1 + boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuflpr_xip.yaml | 1 + 7 files changed, 7 insertions(+) diff --git a/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuapp.yaml b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuapp.yaml index 560a4cfa294bce..e07bbee7d14a95 100644 --- a/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuapp.yaml +++ b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuapp.yaml @@ -9,6 +9,7 @@ toolchain: - gnuarmemb - xtools - zephyr +sysbuild: true ram: 256 flash: 296 supported: diff --git a/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuppr.yaml b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuppr.yaml index af81ae6e28edf6..8bd648416b60e5 100644 --- a/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuppr.yaml +++ b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuppr.yaml @@ -7,6 +7,7 @@ type: mcu arch: riscv toolchain: - zephyr +sysbuild: true ram: 62 flash: 62 supported: diff --git a/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuppr_xip.yaml b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuppr_xip.yaml index d0b1f4481190dd..8cfc343647ff90 100644 --- a/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuppr_xip.yaml +++ b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuppr_xip.yaml @@ -7,6 +7,7 @@ type: mcu arch: riscv toolchain: - zephyr +sysbuild: true ram: 62 flash: 64 supported: diff --git a/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpurad.yaml b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpurad.yaml index e36f2e21ffea6a..36c0fc01dce13f 100644 --- a/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpurad.yaml +++ b/boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpurad.yaml @@ -9,6 +9,7 @@ toolchain: - gnuarmemb - xtools - zephyr +sysbuild: true ram: 192 flash: 256 supported: diff --git a/boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuapp.yaml b/boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuapp.yaml index fd563bc6c1e31e..9213c49fdd7ba3 100644 --- a/boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuapp.yaml +++ b/boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuapp.yaml @@ -9,6 +9,7 @@ toolchain: - gnuarmemb - xtools - zephyr +sysbuild: true ram: 188 flash: 324 supported: diff --git a/boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuflpr.yaml b/boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuflpr.yaml index f05b6b74a8bec2..6e8789aeab79fb 100644 --- a/boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuflpr.yaml +++ b/boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuflpr.yaml @@ -7,6 +7,7 @@ type: mcu arch: riscv toolchain: - zephyr +sysbuild: true ram: 96 flash: 96 supported: diff --git a/boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuflpr_xip.yaml b/boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuflpr_xip.yaml index 0b9d635fb8dae6..156cbb6f8b4173 100644 --- a/boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuflpr_xip.yaml +++ b/boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuflpr_xip.yaml @@ -7,6 +7,7 @@ type: mcu arch: riscv toolchain: - zephyr +sysbuild: true ram: 68 flash: 96 supported: