Skip to content

Commit 9239599

Browse files
ycsincarlescufi
authored andcommitted
twister: add support for custom emulator in simulator
Enable the possibility for boards to implement a custom `run` target in its board.cmake to run any arbitrary commands. This is helpful for devs who would like to add support for proprietary simulator to their boards that can't be upstreamed. Signed-off-by: Yong Cong Sin <[email protected]>
1 parent 0a2d538 commit 9239599

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

cmake/emu/custom.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# ${ZEPHYR_BASE}/CMakeLists.txt looks for ${ZEPHYR_BASE}/cmake/emu/${EMU_PLATFORM}.cmake
4+
# when building the `run` target. Create this placeholder file so it doesn't complain.
5+
# The real 'run' custom_target should be defined in `board.cmake` instead.
6+
#
7+
# See https://docs.zephyrproject.org/latest/develop/test/twister.html#running-tests-on-custom-emulator
8+
#

doc/develop/test/twister.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,42 @@ integration keyword in the testcase definition file (testcase.yaml and
643643
sample.yaml).
644644

645645

646+
Running tests on custom emulator
647+
********************************
648+
649+
Apart from the already supported QEMU and other simulated environments, Twister
650+
supports running any out-of-tree custom emulator defined in the board's :file:`board.cmake`.
651+
To use this type of simulation, add the following properties to
652+
:file:`custom_board/custom_board.yaml`:
653+
654+
::
655+
656+
simulation: custom
657+
simulation_exec: <name_of_emu_binary>
658+
659+
This tells Twister that the board is using a custom emulator called ``<name_of_emu_binary>``,
660+
make sure this binary exists in the PATH.
661+
662+
Then, in :file:`custom_board/board.cmake`, set the supported emulation platforms to ``custom``:
663+
664+
::
665+
666+
set(SUPPORTED_EMU_PLATFORMS custom)
667+
668+
Finally, implement the ``run_custom`` target in :file:`custom_board/board.cmake`.
669+
It should look something like this:
670+
671+
::
672+
673+
add_custom_target(run_custom
674+
COMMAND
675+
<name_of_emu_binary to invoke during 'run'>
676+
<any args to be passed to the command, i.e. ${BOARD}, ${APPLICATION_BINARY_DIR}/zephyr/zephyr.elf>
677+
WORKING_DIRECTORY ${APPLICATION_BINARY_DIR}
678+
DEPENDS ${logical_target_for_zephyr_elf}
679+
USES_TERMINAL
680+
)
681+
646682
Running Tests on Hardware
647683
*************************
648684

scripts/pylib/twister/twisterlib/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
logger = logging.getLogger('twister')
4040
logger.setLevel(logging.DEBUG)
4141

42-
SUPPORTED_SIMS = ["mdb-nsim", "nsim", "renode", "qemu", "tsim", "armfvp", "xt-sim", "native"]
42+
SUPPORTED_SIMS = ["mdb-nsim", "nsim", "renode", "qemu", "tsim", "armfvp", "xt-sim", "native", "custom"]
4343
SUPPORTED_SIMS_IN_PYTEST = ['native', 'qemu']
4444

4545

scripts/schemas/twister/platform-schema.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,19 @@ mapping:
2424
enum: ["mcu", "qemu", "sim", "unit", "native"]
2525
"simulation":
2626
type: str
27-
enum: ["qemu", "simics", "xt-sim", "renode", "nsim", "mdb-nsim", "tsim", "armfvp", "native"]
27+
enum:
28+
[
29+
"qemu",
30+
"simics",
31+
"xt-sim",
32+
"renode",
33+
"nsim",
34+
"mdb-nsim",
35+
"tsim",
36+
"armfvp",
37+
"native",
38+
"custom",
39+
]
2840
"simulation_exec":
2941
type: str
3042
"arch":

0 commit comments

Comments
 (0)