|
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 | +from .fw_helpers import set_region |
| 19 | + |
| 20 | +# Use a different base port for the single-node fixture so it doesn't |
| 21 | +# conflict with the multi-node mesh fixture. |
| 22 | +SINGLE_NODE_BASE_PORT = DEFAULT_BASE_PORT + 100 |
| 23 | + |
| 24 | + |
| 25 | +def _skip_firmware_if_unavailable() -> None: |
| 26 | + """Skip the test when meshtasticd can't run on this host.""" |
| 27 | + if not is_compatible_host(): |
| 28 | + pytest.skip("meshtasticd firmware tests require Linux") |
| 29 | + if find_meshtasticd() is None: |
| 30 | + pytest.skip( |
| 31 | + "meshtasticd not found — set MESHTASTICD_BIN or install it on PATH" |
| 32 | + ) |
| 33 | + |
| 34 | + |
| 35 | +@pytest.fixture(scope="function") |
| 36 | +def firmware_node(): |
| 37 | + """A single meshtasticd sim node for smokevirt tests. |
| 38 | +
|
| 39 | + Function-scoped so every test gets a freshly-erased node with no |
| 40 | + state leaking from previous tests. This makes destructive commands |
| 41 | + (``--reboot``, ``--set factory_reset true``) safe to run and lets |
| 42 | + tests be order-independent. |
| 43 | +
|
| 44 | + Yields the SimNode instance. The node is booted with a fresh erased |
| 45 | + config and listens on localhost at its TCP port. Region is set to US |
| 46 | + so modem-preset tests work against firmware >= 2.8, which clamps |
| 47 | + presets to the legal set for the current region. |
| 48 | + """ |
| 49 | + _skip_firmware_if_unavailable() |
| 50 | + mesh = SimMesh(n_nodes=1, base_port=SINGLE_NODE_BASE_PORT) |
| 51 | + mesh.start() |
| 52 | + node = mesh.get_node(0) |
| 53 | + set_region(node.port, "US") |
| 54 | + # The region commit restarts the TCP listener, so reconnect the harness |
| 55 | + # interface in case a test wants to use it directly. |
| 56 | + if node.iface is not None: |
| 57 | + try: |
| 58 | + node.iface.close() |
| 59 | + except Exception: # pylint: disable=broad-except |
| 60 | + pass |
| 61 | + node.connect() |
| 62 | + yield node |
| 63 | + mesh.stop() |
| 64 | + |
| 65 | + |
| 66 | +@pytest.fixture(scope="function") |
| 67 | +def firmware_mesh(): |
| 68 | + """A 3-node chain (A-B-C) meshtasticd sim mesh for smokemesh tests. |
| 69 | +
|
| 70 | + Yields the SimMesh instance. Nodes are connected and the SIMULATOR_APP |
| 71 | + packet bridge is running. Region is set to US for firmware >= 2.8 |
| 72 | + compatibility, interfaces are reconnected after the region change, and |
| 73 | + node DB convergence is awaited. |
| 74 | + """ |
| 75 | + _skip_firmware_if_unavailable() |
| 76 | + mesh = SimMesh(n_nodes=3, topology=CHAIN_TOPOLOGY) |
| 77 | + mesh.start() |
| 78 | + for node in mesh.nodes: |
| 79 | + set_region(node.port, "US") |
| 80 | + # The region commit restarts each node's TCP listener, so reconnect the |
| 81 | + # harness interfaces before waiting for convergence. |
| 82 | + for node in mesh.nodes: |
| 83 | + if node.iface is not None: |
| 84 | + try: |
| 85 | + node.iface.close() |
| 86 | + except Exception: # pylint: disable=broad-except |
| 87 | + pass |
| 88 | + node.connect() |
| 89 | + mesh.wait_for_convergence(timeout=30) |
| 90 | + yield mesh |
| 91 | + mesh.stop() |
11 | 92 |
|
12 | 93 |
|
13 | 94 | @pytest.fixture |
|
0 commit comments