This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/nuttx-ntfc.git
commit 121a313d06a24d372ed1119efd28abfa90b16d12 Author: raiden00pl <[email protected]> AuthorDate: Tue Aug 4 17:27:42 2026 +0200 device: honor per-core exec_cwd and boot_timeout when starting targets Host devices were spawned with cwd=None. Targets that mount a semihosting hostfs relative to the process working directory (qemu arm/riscv) then cannot find their applications, and the boot wait was fixed at 5s, too short for a kernel-mode boot. Use CoreConfig.exec_cwd for the spawn and CoreConfig.boot_timeout for the boot wait on the host and serial paths. Signed-off-by: raiden00pl <[email protected]> Assisted-by: Claude Code --- src/ntfc/device/host.py | 4 ++-- src/ntfc/device/serial.py | 2 +- tests/device/test_host.py | 33 +++++++++++++++++++++++++++++++++ tests/device/test_serial.py | 28 ++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/ntfc/device/host.py b/src/ntfc/device/host.py index d92c442..fb11750 100644 --- a/src/ntfc/device/host.py +++ b/src/ntfc/device/host.py @@ -50,7 +50,7 @@ class DeviceHost(DeviceCommon): """ DeviceCommon.__init__(self, conf) self._child = None - self._cwd = None + self._cwd = conf.exec_cwd self._cmd: Optional[List[str]] = None @property @@ -139,7 +139,7 @@ class DeviceHost(DeviceCommon): time.sleep(uptime) - ret = self._wait_for_boot() + ret = self._wait_for_boot(self._conf.boot_timeout) if ret is False: # pragma: no cover raise TimeoutError("device boot timeout") diff --git a/src/ntfc/device/serial.py b/src/ntfc/device/serial.py index a937064..fca70fb 100644 --- a/src/ntfc/device/serial.py +++ b/src/ntfc/device/serial.py @@ -150,7 +150,7 @@ class DeviceSerial(DeviceCommon): # reboot device if possible self.reboot() - ret = self._wait_for_boot() + ret = self._wait_for_boot(self._conf.boot_timeout) if ret is False: raise TimeoutError("device boot timeout") diff --git a/tests/device/test_host.py b/tests/device/test_host.py index 6ddebd9..710334a 100644 --- a/tests/device/test_host.py +++ b/tests/device/test_host.py @@ -23,6 +23,7 @@ from unittest.mock import MagicMock import pytest from pexpect.exceptions import ExceptionPexpect +from ntfc.coreconfig import CoreConfig from ntfc.device.host import DeviceHost @@ -202,6 +203,38 @@ def test_device_host_pid(envconfig_dummy): assert dev.pid == 4242 +def test_device_host_exec_cwd_boot_timeout(tmp_path, monkeypatch): + + conf = CoreConfig( + {"name": "t", "exec_cwd": str(tmp_path), "boot_timeout": 9} + ) + dev = DeviceHost2(conf) + + spawn_kwargs = {} + boot_timeouts = [] + + class FakeChild: + pid = 1 + + def fake_spawn(cmd, **kwargs): + spawn_kwargs.update(kwargs) + return FakeChild() + + def fake_wait(timeout=5): + boot_timeouts.append(timeout) + return True + + monkeypatch.setattr("ntfc.device.host.pexpect.spawn", fake_spawn) + monkeypatch.setattr(dev, "_wait_for_boot", fake_wait) + + dev.host_open(["dummy"]) + + # exec_cwd is passed to the spawned process + assert spawn_kwargs["cwd"] == str(tmp_path) + # boot wait uses the configured boot_timeout + assert boot_timeouts == [9] + + # TODO: more tests for host device !!!! # - test for timeout # - test for very long output diff --git a/tests/device/test_serial.py b/tests/device/test_serial.py index 003ed6d..74822a2 100644 --- a/tests/device/test_serial.py +++ b/tests/device/test_serial.py @@ -137,3 +137,31 @@ def test_device_sim_init(serial_config, serial_pair): stop.set() device_thread.join(timeout=1) + + +def test_device_serial_boot_timeout(serial_pair, monkeypatch): + + config = CoreConfig( + { + "name": "main", + "device": "serial", + "exec_path": serial_pair[1], + "boot_timeout": 9, + } + ) + ser = DeviceSerial(config) + + boot_timeouts = [] + + def fake_wait(timeout=5): + boot_timeouts.append(timeout) + return True + + monkeypatch.setattr(ser, "_wait_for_boot", fake_wait) + monkeypatch.setattr(ser, "reboot", lambda *args, **kwargs: True) + + ser._start_impl() + ser.stop() + + # boot wait uses the configured boot_timeout + assert boot_timeouts == [9]
