|
13 | 13 | from twister_harness.device.factory import DeviceFactory
|
14 | 14 | from twister_harness.twister_harness_config import DeviceConfig, TwisterHarnessConfig
|
15 | 15 | from twister_harness.helpers.shell import Shell
|
16 |
| -from twister_harness.helpers.mcumgr import MCUmgr |
| 16 | +from twister_harness.helpers.mcumgr import MCUmgr, MCUmgrBle |
17 | 17 | from twister_harness.helpers.utils import find_in_config
|
18 | 18 |
|
19 | 19 | logger = logging.getLogger(__name__)
|
@@ -46,14 +46,17 @@ def determine_scope(fixture_name, config):
|
46 | 46 |
|
47 | 47 |
|
48 | 48 | @pytest.fixture(scope=determine_scope)
|
49 |
| -def unlaunched_dut(request: pytest.FixtureRequest, device_object: DeviceAdapter) -> Generator[DeviceAdapter, None, None]: |
| 49 | +def unlaunched_dut( |
| 50 | + request: pytest.FixtureRequest, device_object: DeviceAdapter |
| 51 | +) -> Generator[DeviceAdapter, None, None]: |
50 | 52 | """Return device object - with logs connected, but not run"""
|
51 | 53 | device_object.initialize_log_files(request.node.name)
|
52 | 54 | try:
|
53 | 55 | yield device_object
|
54 | 56 | finally: # to make sure we close all running processes execution
|
55 | 57 | device_object.close()
|
56 | 58 |
|
| 59 | + |
57 | 60 | @pytest.fixture(scope=determine_scope)
|
58 | 61 | def dut(request: pytest.FixtureRequest, device_object: DeviceAdapter) -> Generator[DeviceAdapter, None, None]:
|
59 | 62 | """Return launched device - with run application."""
|
@@ -83,12 +86,34 @@ def shell(dut: DeviceAdapter) -> Shell:
|
83 | 86 | return shell
|
84 | 87 |
|
85 | 88 |
|
86 |
| -@pytest.fixture(scope='session') |
87 |
| -def is_mcumgr_available() -> None: |
| 89 | +@pytest.fixture() |
| 90 | +def mcumgr(device_object: DeviceAdapter) -> Generator[MCUmgr, None, None]: |
| 91 | + """Fixture to create an MCUmgr instance for serial connection.""" |
88 | 92 | if not MCUmgr.is_available():
|
89 | 93 | pytest.skip('mcumgr not available')
|
| 94 | + yield MCUmgr.create_for_serial(device_object.device_config.serial) |
90 | 95 |
|
91 | 96 |
|
92 | 97 | @pytest.fixture()
|
93 |
| -def mcumgr(is_mcumgr_available: None, dut: DeviceAdapter) -> Generator[MCUmgr, None, None]: |
94 |
| - yield MCUmgr.create_for_serial(dut.device_config.serial) |
| 98 | +def mcumgr_ble(device_object: DeviceAdapter) -> Generator[MCUmgrBle, None, None]: |
| 99 | + """Fixture to create an MCUmgr instance for BLE connection.""" |
| 100 | + if not MCUmgrBle.is_available(): |
| 101 | + pytest.skip('mcumgr for ble not available') |
| 102 | + |
| 103 | + for fixture in device_object.device_config.fixtures: |
| 104 | + if fixture.startswith('usb_hci:'): |
| 105 | + hci_name = fixture.split(':', 1)[1] |
| 106 | + break |
| 107 | + else: |
| 108 | + pytest.skip('usb_hci fixture not found') |
| 109 | + |
| 110 | + try: |
| 111 | + hci_index = int(hci_name.split('hci')[-1]) |
| 112 | + except ValueError: |
| 113 | + pytest.skip(f'Invalid HCI name: {hci_name}. Expected format is "hciX".') |
| 114 | + |
| 115 | + peer_name = find_in_config( |
| 116 | + Path(device_object.device_config.app_build_dir) / 'zephyr' / '.config', 'CONFIG_BT_DEVICE_NAME' |
| 117 | + ) or 'Zephyr' |
| 118 | + |
| 119 | + yield MCUmgrBle.create_for_ble(hci_index, peer_name) |
0 commit comments