Skip to content

Commit 33c8345

Browse files
gchwierrlubos
authored andcommitted
[nrf fromlist] twister: Allow to run sysbuild with native_sim
Fix issue 72083. Update path to zephyr.exe binary using default domain from domains.yaml file. Upstream PR: zephyrproject-rtos/zephyr#72100 Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
1 parent 2e8f954 commit 33c8345

File tree

2 files changed

+27
-42
lines changed

2 files changed

+27
-42
lines changed

scripts/pylib/twister/twisterlib/handlers.py

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def __init__(self, instance, type_str="build"):
7575
self.run = False
7676
self.type_str = type_str
7777

78-
self.binary = None
7978
self.pid_fn = None
8079
self.call_make_run = True
8180

@@ -167,6 +166,19 @@ def _final_handle_actions(self, harness, handler_time):
167166

168167
self.record(harness)
169168

169+
def get_default_domain_build_dir(self):
170+
if self.instance.testsuite.sysbuild:
171+
# Load domain yaml to get default domain build directory
172+
# Note: for targets using QEMU, we assume that the target will
173+
# have added any additional images to the run target manually
174+
domain_path = os.path.join(self.build_dir, "domains.yaml")
175+
domains = Domains.from_file(domain_path)
176+
logger.debug("Loaded sysbuild domain data from %s" % domain_path)
177+
build_dir = domains.get_default_domain().build_dir
178+
else:
179+
build_dir = self.build_dir
180+
return build_dir
181+
170182

171183
class BinaryHandler(Handler):
172184
def __init__(self, instance, type_str):
@@ -239,7 +251,8 @@ def _create_command(self, robot_test):
239251
elif self.call_make_run:
240252
command = [self.generator_cmd, "run"]
241253
else:
242-
command = [self.binary]
254+
binary = os.path.join(self.get_default_domain_build_dir(), "zephyr", "zephyr.exe")
255+
command = [binary]
243256

244257
if self.options.enable_valgrind:
245258
command = ["valgrind", "--error-exitcode=2",
@@ -344,7 +357,6 @@ def __init__(self, instance, type_str):
344357
self.pid_fn = os.path.join(instance.build_dir, "renode.pid")
345358
elif type_str == 'native':
346359
self.call_make_run = False
347-
self.binary = os.path.join(instance.build_dir, "zephyr", "zephyr.exe")
348360
self.ready = True
349361

350362

@@ -949,20 +961,6 @@ def _thread(handler, timeout, outdir, logfile, fifo_fn, pid_fn,
949961

950962
QEMUHandler._thread_close_files(fifo_in, fifo_out, pid, out_fp, in_fp, log_out_fp)
951963

952-
def _get_sysbuild_build_dir(self):
953-
if self.instance.testsuite.sysbuild:
954-
# Load domain yaml to get default domain build directory
955-
# Note: for targets using QEMU, we assume that the target will
956-
# have added any additional images to the run target manually
957-
domain_path = os.path.join(self.build_dir, "domains.yaml")
958-
domains = Domains.from_file(domain_path)
959-
logger.debug("Loaded sysbuild domain data from %s" % domain_path)
960-
build_dir = domains.get_default_domain().build_dir
961-
else:
962-
build_dir = self.build_dir
963-
964-
return build_dir
965-
966964
def _set_qemu_filenames(self, sysbuild_build_dir):
967965
# We pass this to QEMU which looks for fifos with .in and .out suffixes.
968966
# QEMU fifo will use main build dir
@@ -994,11 +992,11 @@ def _update_instance_info(self, harness_state, is_timeout):
994992
def handle(self, harness):
995993
self.run = True
996994

997-
sysbuild_build_dir = self._get_sysbuild_build_dir()
995+
domain_build_dir = self.get_default_domain_build_dir()
998996

999-
command = self._create_command(sysbuild_build_dir)
997+
command = self._create_command(domain_build_dir)
1000998

1001-
self._set_qemu_filenames(sysbuild_build_dir)
999+
self._set_qemu_filenames(domain_build_dir)
10021000

10031001
self.thread = threading.Thread(name=self.name, target=QEMUHandler._thread,
10041002
args=(self, self.get_test_timeout(), self.build_dir,
@@ -1138,20 +1136,6 @@ def _monitor_update_instance_info(handler, handler_time, out_state):
11381136
handler.instance.status = out_state
11391137
handler.instance.reason = "Unknown"
11401138

1141-
def _get_sysbuild_build_dir(self):
1142-
if self.instance.testsuite.sysbuild:
1143-
# Load domain yaml to get default domain build directory
1144-
# Note: for targets using QEMU, we assume that the target will
1145-
# have added any additional images to the run target manually
1146-
domain_path = os.path.join(self.build_dir, "domains.yaml")
1147-
domains = Domains.from_file(domain_path)
1148-
logger.debug("Loaded sysbuild domain data from %s" % domain_path)
1149-
build_dir = domains.get_default_domain().build_dir
1150-
else:
1151-
build_dir = self.build_dir
1152-
1153-
return build_dir
1154-
11551139
def _set_qemu_filenames(self, sysbuild_build_dir):
11561140
# PID file will be created in the main sysbuild app's build dir
11571141
self.pid_fn = os.path.join(sysbuild_build_dir, "qemu.pid")
@@ -1291,9 +1275,9 @@ def _monitor_output(self, queue, timeout, logfile, pid_fn, harness, ignore_unexp
12911275
def handle(self, harness):
12921276
self.run = True
12931277

1294-
sysbuild_build_dir = self._get_sysbuild_build_dir()
1295-
command = self._create_command(sysbuild_build_dir)
1296-
self._set_qemu_filenames(sysbuild_build_dir)
1278+
domain_build_dir = self.get_default_domain_build_dir()
1279+
command = self._create_command(domain_build_dir)
1280+
self._set_qemu_filenames(domain_build_dir)
12971281

12981282
logger.debug("Running %s (%s)" % (self.name, self.type_str))
12991283
is_timeout = False

scripts/tests/twister/test_handlers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ def wait(self, *args, **kwargs):
448448
'--log-file=build_dir/valgrind.log', '--track-origins=yes',
449449
'generator', 'run_renode_test']),
450450
(False, True, False, 123, None, ['generator', 'run', '--seed=123']),
451-
(False, False, False, None, ['ex1', 'ex2'], ['bin', 'ex1', 'ex2']),
451+
(False, False, False, None, ['ex1', 'ex2'], ['build_dir/zephyr/zephyr.exe', 'ex1', 'ex2']),
452452
]
453453

454454
@pytest.mark.parametrize(
@@ -474,6 +474,7 @@ def test_binaryhandler_create_command(
474474
handler.seed = seed
475475
handler.extra_test_args = extra_args
476476
handler.build_dir = 'build_dir'
477+
handler.instance.testsuite.sysbuild = False
477478

478479
command = handler._create_command(robot_test)
479480

@@ -1478,7 +1479,7 @@ def mock_process(pid):
14781479
TESTDATA_19,
14791480
ids=['domains build dir', 'self build dir']
14801481
)
1481-
def test_qemuhandler_get_sysbuild_build_dir(
1482+
def test_qemuhandler_get_default_domain_build_dir(
14821483
mocked_instance,
14831484
self_sysbuild,
14841485
self_build_dir,
@@ -1495,7 +1496,7 @@ def test_qemuhandler_get_sysbuild_build_dir(
14951496
handler.build_dir = self_build_dir
14961497

14971498
with mock.patch('domains.Domains.from_file', from_file_mock):
1498-
result = handler._get_sysbuild_build_dir()
1499+
result = handler.get_default_domain_build_dir()
14991500

15001501
assert result == expected
15011502

@@ -2017,7 +2018,7 @@ def mock_filenames(sysbuild_build_dir):
20172018
harness = mock.Mock(state=harness_state)
20182019
handler_options_west_flash = []
20192020

2020-
sysbuild_build_dir = os.path.join('sysbuild', 'dummydir')
2021+
domain_build_dir = os.path.join('sysbuild', 'dummydir')
20212022
command = ['generator_cmd', '-C', os.path.join('cmd', 'path'), 'run']
20222023

20232024
handler.options = mock.Mock(
@@ -2030,7 +2031,7 @@ def mock_filenames(sysbuild_build_dir):
20302031
handler._final_handle_actions = mock.Mock(return_value=None)
20312032
handler._create_command = mock.Mock(return_value=command)
20322033
handler._set_qemu_filenames = mock.Mock(side_effect=mock_filenames)
2033-
handler._get_sysbuild_build_dir = mock.Mock(return_value=sysbuild_build_dir)
2034+
handler.get_default_domain_build_dir = mock.Mock(return_value=domain_build_dir)
20342035
handler.terminate = mock.Mock()
20352036

20362037
unlink_mock = mock.Mock()

0 commit comments

Comments
 (0)