Skip to content

Commit 602b8b4

Browse files
danieldegrassenashif
authored andcommitted
scripts: twister: add support for sysbuild
Add support for building with sysbuild using twister, via the "sysbuild" yaml property in testsuites. This will currently disable Kconfig and devicetree filtering. Signed-off-by: Daniel DeGrasse <[email protected]>
1 parent d823f88 commit 602b8b4

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed

scripts/pylib/twister/twisterlib/config_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class TwisterConfigParser:
3636
"filter": {"type": "str"},
3737
"harness": {"type": "str", "default": "test"},
3838
"harness_config": {"type": "map", "default": {}},
39-
"seed": {"type": "int", "default": 0}
39+
"seed": {"type": "int", "default": 0},
40+
"sysbuild": {"type": "bool", "default": False}
4041
}
4142

4243
def __init__(self, filename, schema):

scripts/pylib/twister/twisterlib/runner.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import time
1515
import multiprocessing
1616
import traceback
17+
import scl
1718
from colorama import Fore
1819
from multiprocessing import Lock, Process, Value
1920
from multiprocessing.managers import BaseManager
@@ -285,7 +286,6 @@ def run_cmake(self, args=""):
285286
logger.debug("Running cmake on %s for %s" % (self.source_dir, self.platform.name))
286287
cmake_args = [
287288
f'-B{self.build_dir}',
288-
f'-S{self.source_dir}',
289289
f'-DTC_RUNID={self.instance.run_id}',
290290
f'-DEXTRA_CFLAGS={cflags}',
291291
f'-DEXTRA_AFLAGS={aflags}',
@@ -294,6 +294,18 @@ def run_cmake(self, args=""):
294294
f'-G{self.env.generator}'
295295
]
296296

297+
if self.testsuite.sysbuild:
298+
logger.debug("Building %s using sysbuild" % (self.source_dir))
299+
source_args = [
300+
f'-S{canonical_zephyr_base}/share/sysbuild',
301+
f'-DAPP_DIR={self.source_dir}'
302+
]
303+
else:
304+
source_args = [
305+
f'-S{self.source_dir}'
306+
]
307+
cmake_args.extend(source_args)
308+
297309
cmake_args.extend(args)
298310

299311
cmake_opts = ['-DBOARD={}'.format(self.platform.name)]
@@ -351,8 +363,24 @@ def parse_generated(self):
351363
if self.platform.name == "unit_testing":
352364
return {}
353365

354-
cmake_cache_path = os.path.join(self.build_dir, "CMakeCache.txt")
355-
defconfig_path = os.path.join(self.build_dir, "zephyr", ".config")
366+
if self.testsuite.sysbuild:
367+
# We must parse the domains.yaml file to determine the
368+
# default sysbuild application
369+
domain_path = os.path.join(self.build_dir, "domains.yaml")
370+
domain_yaml = scl.yaml_load(domain_path)
371+
logger.debug("Loaded sysbuild domain data from %s" % (domain_path))
372+
default_domain = domain_yaml['default']
373+
for domain in domain_yaml['domains']:
374+
if domain['name'] == default_domain:
375+
domain_build = domain['build_dir']
376+
cmake_cache_path = os.path.join(domain_build, "CMakeCache.txt")
377+
defconfig_path = os.path.join(domain_build, "zephyr", ".config")
378+
edt_pickle = os.path.join(domain_build, "zephyr", "edt.pickle")
379+
else:
380+
cmake_cache_path = os.path.join(self.build_dir, "CMakeCache.txt")
381+
defconfig_path = os.path.join(self.build_dir, "zephyr", ".config")
382+
edt_pickle = os.path.join(self.build_dir, "zephyr", "edt.pickle")
383+
356384

357385
with open(defconfig_path, "r") as fp:
358386
defconfig = {}
@@ -385,7 +413,21 @@ def parse_generated(self):
385413
filter_data.update(self.defconfig)
386414
filter_data.update(self.cmake_cache)
387415

388-
edt_pickle = os.path.join(self.build_dir, "zephyr", "edt.pickle")
416+
if self.testsuite.sysbuild and self.env.options.device_testing:
417+
# Verify that twister's arguments support sysbuild.
418+
# Twister sysbuild flashing currently only works with west, so
419+
# --west-flash must be passed. Additionally, erasing the DUT
420+
# before each test with --west-flash=--erase will inherently not
421+
# work with sysbuild.
422+
if self.env.options.west_flash is None:
423+
logger.warning("Sysbuild test will be skipped. " +
424+
"West must be used for flashing.")
425+
return {os.path.join(self.platform.name, self.testsuite.name): True}
426+
elif "--erase" in self.env.options.west_flash:
427+
logger.warning("Sysbuild test will be skipped, " +
428+
"--erase is not supported with --west-flash")
429+
return {os.path.join(self.platform.name, self.testsuite.name): True}
430+
389431
if self.testsuite and self.testsuite.filter:
390432
try:
391433
if os.path.exists(edt_pickle):

scripts/schemas/twister/testsuite-schema.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ mapping:
130130
"slow":
131131
type: bool
132132
required: false
133+
"sysbuild":
134+
type: bool
135+
required: false
133136
# The sample descriptor, if present
134137
"sample":
135138
type: map
@@ -278,3 +281,6 @@ mapping:
278281
"slow":
279282
type: bool
280283
required: false
284+
"sysbuild":
285+
type: bool
286+
required: false

scripts/twister

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ pairs:
4444
Extra configuration options to be merged with a master prj.conf
4545
when building or running the test case.
4646
47+
sysbuild: <True|False> (default False)
48+
If true, build the sample using the sysbuild infrastructure. Filtering
49+
will only be enabled for the main project, and is not supported for
50+
other projects included by sysbuild.
51+
4752
build_only: <True|False> (default False)
4853
If true, don't try to run the test even if the selected platform
4954
supports it.

0 commit comments

Comments
 (0)