Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

twister: Add means for requiring sysbuild from platform level #73790

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ toolchain:
- gnuarmemb
- xtools
- zephyr
sysbuild: true
ram: 256
flash: 296
supported:
Expand Down
1 change: 1 addition & 0 deletions boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpuppr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type: mcu
arch: riscv
toolchain:
- zephyr
sysbuild: true
ram: 62
flash: 62
supported:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type: mcu
arch: riscv
toolchain:
- zephyr
sysbuild: true
ram: 62
flash: 64
supported:
Expand Down
1 change: 1 addition & 0 deletions boards/nordic/nrf54h20dk/nrf54h20dk_nrf54h20_cpurad.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ toolchain:
- gnuarmemb
- xtools
- zephyr
sysbuild: true
ram: 192
flash: 256
supported:
Expand Down
1 change: 1 addition & 0 deletions boards/nordic/nrf54l15pdk/nrf54l15pdk_nrf54l15_cpuapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ toolchain:
- gnuarmemb
- xtools
- zephyr
sysbuild: true
ram: 188
flash: 324
supported:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type: mcu
arch: riscv
toolchain:
- zephyr
sysbuild: true
ram: 96
flash: 96
supported:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type: mcu
arch: riscv
toolchain:
- zephyr
sysbuild: true
ram: 68
flash: 96
supported:
Expand Down
2 changes: 1 addition & 1 deletion scripts/pylib/twister/twisterlib/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions scripts/pylib/twister/twisterlib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions scripts/pylib/twister/twisterlib/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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',
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion scripts/pylib/twister/twisterlib/testinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
PerMac marked this conversation as resolved.
Show resolved Hide resolved

self.run = False
self.testcases: list[TestCase] = []
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions scripts/schemas/twister/platform-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ mapping:
type: seq
seq:
- type: str
"sysbuild":
type: bool
"env":
type: seq
seq:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions scripts/tests/twister/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions scripts/tests/twister/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -131,15 +132,15 @@ 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)


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)
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests/twister/test_testinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading