Skip to content

ci: add Windows HIL and fault injection workflow with physical hardware fixture - #382

Draft
fotiDim wants to merge 12 commits into
mainfrom
windows-hil-ci
Draft

fotiDim wants to merge 12 commits into
mainfrom
windows-hil-ci

Conversation

@fotiDim

@fotiDim fotiDim commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds automated Windows Hardware-in-the-Loop (HIL) and fault injection testing for universal_ble using a physical Nordic nRF52 DK fixture running contract v2 firmware.


Changes

  • GitHub Actions Workflow (.github/workflows/windows_hil.yml):
    • Configured
      uns-on.group: windows-hil with labels [self-hosted, Windows, X64, universal-ble-hil].
    • Configured workflow dispatch supporting all test groups (�ll, �aseline, connection-discovery, gatt-operations,
      otifications-indications, mtu-resources, iming-sweeps).
    • Resolves fixture COM port from HIL_JLINK_SERIAL, with support for dual-port J-Link OB devices (auto-selecting VCOM0 / MI_00).
    • Performs automated clean-flashing of universal_ble_hil_firmware (contract v0.2) via J-Link SWD.
    • Collects and uploads test execution logs as workflow artifacts.
  • Harness & Serial Fixes (hil/lib/src/hil_serial_io.dart):
    • Added DiscardInBuffer() on serial port open to purge stale buffer data.
    • Implemented robust substring prefix matching so Zephyr console log timestamps ([00:02:00. ...) do not collide with HIL opcode replies.
  • Runner Script (hil/run_windows_hil_group.ps1):
    • Added timeout supervision, worker isolation, and group execution handling.

Upstream Security & Organization Requirements

Before enabling on the upstream repository, ensure the following organization and repository settings are configured:

  1. Organization Runner Group (windows-hil):

    • Create an organization runner group named windows-hil in Organization Settings > Actions > Runner groups.
    • Add the dedicated Windows self-hosted runner with label universal-ble-hil to this group.
    • Repository access: Set to "Selected repositories" and restrict strictly to Navideck/universal_ble.
    • Workflow access: Restrict to:
      ext Navideck/universal_ble/.github/workflows/windows_hil.yml@refs/heads/main
    • Do not allow pull-request workflows from forks or untrusted branches to access the physical hardware runner.
  2. Repository Environment (windows-hil):

    • Create a repository environment named windows-hil in Repository Settings > Environments.
    • Restrict deployment branches to the protected main branch.
    • Add maintainers as Required reviewers so hardware test runs must be manually approved.
    • Under Environment variables, set HIL_JLINK_SERIAL to the dedicated nRF52 DK onboard J-Link serial number.

Local & CI Verification

  • Cleanly flashed and verified on a physical Nordic nRF52832 DK (PCA10040, S/N 1050344291).
  • Executed end-to-end both locally and through a Windows self-hosted runner:
    • Baseline suite: 25 / 25 passed (100%)
    • Unit tests: 311 / 311 passed (100%)

@fotiDim
fotiDim marked this pull request as draft November 12, 2026 20:36
usmanmehmood55 and others added 9 commits November 19, 2026 18:05
Add a maintainer-triggered workflow that flashes a pinned Zephyr image to
the nRF52 DK fixture and then runs the baseline and fault insertion suites
on a self-hosted Windows runner, one selected group at a time.

Windows now arms fixture faults over the DK's USB virtual COM port instead
of BLE, so a link that the fault under test tears down can no longer drop
the control command:

- hil_serial_io.dart drives a PowerShell serial bridge over a loopback
  socket and serialises request/reply exchanges; hil_serial_stub.dart is
  selected by conditional import where dart:io serial control is absent.
- HilPeripheral opens the wired link, validates the reported fixture
  address and contract revision, exposes wired telemetry reads, and gains
  dispose() so the serial bridge is released with the connection.
- Fault insertion tests carry a group tag in their names so the workflow
  can select a single group, trace FIT-CONN-009/013 timings, and fail
  loudly instead of tolerating BLE control-path write errors when the
  wired path is in use.
- run_windows_hil_group.ps1 runs each group in a worker process under a
  timeout so a hung group cannot block the remaining groups.
…gets

The branch guard cannot protect the self-hosted runner: a workflow_dispatch
run executes the YAML of the selected ref, so anyone with write access can
dispatch a branch whose copy of this file drops the guard. Say so in the
header, name the two organization controls the job actually depends on (the
runner group's workflow-access allowlist and the environment's
deployment-branch and reviewer rules), and add github.workflow_ref as a second
signal rather than implying the file is sufficient on its own.

Budgets:
- pass a per-group -TimeoutSeconds above that group's declared per-test
  timeouts; timing-sweeps alone sums to 34 minutes, so 480 seconds could never
  fit;
- raise the job timeout to cover 180 minutes of group budgets plus
  preparation, the warm build, and the flash;
- warm the CMake/MSVC build once outside the timed groups;
- start from a clean windows/, build/ and .metadata on a persistent runner.

Smaller fixes:
- mask HIL_JLINK_SERIAL, and keep the configured serial (leading zeros
  included) for the jlink -USB selection while matching the PnP instance id
  without them;
- fail and print the discovered ports when no VCOM0 interface exists instead
  of falling back to $ports[0];
- invoke the group script with an explicit execution policy;
- guard the group conditions with `inputs.test_group || 'all'`;
- pin the used actions by SHA on the hardware runner;
- name the PCA10040 board next to the device name;
- warn instead of ignoring a missing log artifact.
…antly

The bridge only read the port while a command was in flight, so 64 KiB of
Zephyr log output could fill the buffer and discard a reply, and a single
ReadLine timeout threw out of the loop and marked the session failed for good.

The helper now reads the port every iteration, forwards whole lines as they
arrive, and treats a short read timeout as "nothing yet" instead of a failure.
The Dart side keeps the 5 second budget as the only timeout authority: a miss
fails that one exchange, the session stays usable, and a late reply is logged
as ordinary fixture output. Teardown bounds the wait for the helper process.

Reply matching no longer assumes the reply is alone on its line. The `HIL
<id> ` marker is located with lastIndexOf, and each call site validates the
payload with an anchored, fully specified pattern (handshake address,
72-hex telemetry, single `0` accept token), ignoring any log text that follows
it. Timeouts report the port and the last helper error.
… script

The 480 second default was smaller than the per-test budgets the timing sweeps
declare. Raise the default well past that sum and document that the caller owns
the budget, that CI passes it per group, and that the warm build keeps a cold
CMake/MSVC build out of it. Note the explicit execution policy needed when
local scripts are restricted.
Mirror the fault suite: a failure path may leave the peripheral disconnected,
and an error from dispose() during teardown must not replace the real test
result.
… built

The maintainer section still described a workflow that no longer exists: the
runner group is already selected, and port resolution only fails at zero
matches, prefers the &MI_00 interface, and now fails instead of silently
falling back to the first port. Rewrite that passage, drop the "before
upstreaming, enable runs-on.group" text, and document the group budgets, the
warm build, and the execution-policy requirement.

Also record what the code now does elsewhere:
- the host-side reply framing and its firmware-side durable fix;
- that the reader drains continuously and only the per-exchange budget fails;
- that Windows has no BLE control path (no HIL_CONTROL=ble escape hatch);
- that the firmware is fetched from a personal account while this is a draft.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants