Add hardware-in-the-loop and fault injection tests - #282
Conversation
Docs updated, implemented 4 more tests, improved existing tests Fixes for CI Added Android to HIL tests
|
@usmanmehmood55 thanks for the PR. Would https://www.adafruit.com/product/3406 or https://www.ebay.de/itm/406283688259 work? |
|
@fotiDim technically yes, but both of these boards have different ways of installing/flashing the firmware onto the boards, compared to the standard nRF development kit. They use UART over the USB port, and need the firmware to be partitioned in their specific bootloader's styles, so I'd have to get one myself and test out the flashing process and do some trial and error on the partition sizes etc. They also might require a physical button to be pressed during every installation/flashing, which would make CI automation difficult. Standard nRF52 devkits have onboard flasher/debugger, so it'll work right out of the box, and won't require physical button presses. I will look into the Adafruit board, it might be easier than the ebay link one. But again, the standard devkit would be the easiest. |
Summary
This PR adds a hardware-in-the-loop (HIL) test suite for
universal_bleand uses it to harden the Windows implementation.The fixture is a physical nRF52 DK running purpose-built Zephyr firmware. The firmware lives in the separate universal_ble_hil_firmware repository.
The Windows suite currently has 57 working tests:
The host controls the fixture over BLE. USB serial is used for firmware logs.
What the tests cover
The baseline suite covers:
The FIT suite arms the firmware with a fault plan before starting an ordinary BLE operation. The fixture can then:
Most tests also verify recovery. After the injected failure, the test performs another read, write, reconnect, or subscription. This catches cases where the original call fails correctly but leaves the connection or operation queue in a broken state.
These tests go through the complete path: Dart API, operation queue, Pigeon, Windows C++, WinRT, Windows Bluetooth stack, the radio link, and finally the Zephyr GATT server. This gives us coverage which mocks and software-only tests cannot provide.
Windows implementation improvements
The HIL work also led to a larger review of the Windows implementation. Production changes are kept separate from the test fixture and include:
GattServicesChangedis handled. Windows rebuilds the GATT map safely, rejects stale refresh results, waits for active operations, and restores existing subscriptions.readDescriptorAPI also returns the descriptor value instead ofvoid.value.buffercan no longer expose unrelated bytes from the surrounding Pigeon message.The deterministic native lifetime logic also has software-only tests, which now run in the Windows CI job.
Bugs found
The suite had caught several real issues:
ValueChangedafter the CCC enable operation had completed.value.buffercould include unrelated envelope data.The stale connection, stale completion, descriptor, service refresh, and notification timing tests now cover these paths against the physical fixture.
Running the suite
These are manual hardware tests. They are not intended to run in normal pull-request CI because they require an nRF52 DK and exclusive access to a Bluetooth adapter.
Generated Android, Web, and Windows runner files are not committed. They can be recreated with
flutter create, which keeps the PR focused on the actual fixture, tests, and production changes.The Windows suite should be run when changing:
The Web runner provides an interactive path for the portable baseline behavior. The suite also contains skipped placeholders for faults which still need firmware support and proper assertions. Those can be implemented gradually as the fixture develops.