|
8 | 8 | from meshtastic import mt_config |
9 | 9 |
|
10 | 10 | from ..mesh_interface import MeshInterface |
| 11 | +from .firmware_harness import ( |
| 12 | + CHAIN_TOPOLOGY, |
| 13 | + DEFAULT_BASE_PORT, |
| 14 | + SimMesh, |
| 15 | + find_meshtasticd, |
| 16 | + is_compatible_host, |
| 17 | +) |
| 18 | + |
| 19 | +# Use a different base port for the single-node fixture so it doesn't |
| 20 | +# conflict with the multi-node mesh fixture (both are session-scoped). |
| 21 | +SINGLE_NODE_BASE_PORT = DEFAULT_BASE_PORT + 100 |
| 22 | + |
| 23 | + |
| 24 | +def _skip_firmware_if_unavailable() -> None: |
| 25 | + """Skip the test when meshtasticd can't run on this host.""" |
| 26 | + if not is_compatible_host(): |
| 27 | + pytest.skip("meshtasticd firmware tests require Linux") |
| 28 | + if find_meshtasticd() is None: |
| 29 | + pytest.skip( |
| 30 | + "meshtasticd not found — set MESHTASTICD_BIN or install it on PATH" |
| 31 | + ) |
| 32 | + |
| 33 | + |
| 34 | +@pytest.fixture(scope="session") |
| 35 | +def firmware_node(): |
| 36 | + """A single meshtasticd sim node for smokevirt tests. |
| 37 | +
|
| 38 | + Yields the SimNode instance. The node is booted with a fresh erased |
| 39 | + config and listens on localhost at its TCP port. |
| 40 | + """ |
| 41 | + _skip_firmware_if_unavailable() |
| 42 | + mesh = SimMesh(n_nodes=1, base_port=SINGLE_NODE_BASE_PORT) |
| 43 | + mesh.start() |
| 44 | + yield mesh.get_node(0) |
| 45 | + mesh.stop() |
| 46 | + |
| 47 | + |
| 48 | +@pytest.fixture(scope="function") |
| 49 | +def firmware_mesh(): |
| 50 | + """A 3-node chain (A-B-C) meshtasticd sim mesh for smokemesh tests. |
| 51 | +
|
| 52 | + Yields the SimMesh instance. Nodes are connected and the SIMULATOR_APP |
| 53 | + packet bridge is running. Node DB convergence is awaited. |
| 54 | + """ |
| 55 | + _skip_firmware_if_unavailable() |
| 56 | + mesh = SimMesh(n_nodes=3, topology=CHAIN_TOPOLOGY) |
| 57 | + mesh.start() |
| 58 | + mesh.wait_for_convergence(timeout=30) |
| 59 | + yield mesh |
| 60 | + mesh.stop() |
11 | 61 |
|
12 | 62 |
|
13 | 63 | @pytest.fixture |
|
0 commit comments