Skip to content

feat(px4): add failure injection setup page#14578

Open
Claudio-Chies wants to merge 4 commits into
mavlink:masterfrom
Claudio-Chies:cch/qgc-failure-injection
Open

feat(px4): add failure injection setup page#14578
Claudio-Chies wants to merge 4 commits into
mavlink:masterfrom
Claudio-Chies:cch/qgc-failure-injection

Conversation

@Claudio-Chies

Copy link
Copy Markdown
Contributor

Description

Failure injection support in PX4 is being refactored and expanded, with the eventual goal of using it for hardware flight testing — for example, validating system response to a motor-out scenario.
As part of that, this PR adds a PX4 Vehicle Setup page for injecting simulated failures via MAV_CMD_INJECT_FAILURE, so failsafe and EKF response can be validated from the UI instead of hand-crafting MAVLink commands.
Operators pick a failure unit, type, and instance(s) and inject them directly through the page. The page only appears when SYS_FAILURE_EN is present on the vehicle, which depends on the firmware being built with the failure-injection-manager module included — if the module isn't built in, the parameter is absent and the page stays hidden. The unit/type dropdowns are populated directly from MAVLink's FAILURE_UNIT/FAILURE_TYPE enums, so new entries appear automatically as they're added to MAVLink.

Display

Screencast.From.2026-07-01.19-28-43.mp4

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • CI/Build changes
  • Other

Testing

  • Tested locally
  • Added/updated unit tests
  • Tested with simulator (SITL)
  • Tested with hardware

Platforms Tested

  • Linux
  • Windows
  • macOS
  • Android
  • iOS

Flight Stacks Tested

  • PX4
  • ArduPilot

Screenshots

Checklist

  • I have read the Contribution Guidelines
  • I have read the Code of Conduct
  • My code follows the project's coding standards
  • I have added tests that prove my fix/feature works
  • New and existing unit tests pass locally

Related PR's


By submitting this pull request, I confirm that my contribution is made under the terms of the project's dual license (Apache 2.0 and GPL v3).

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 30.69%. Comparing base (f29efd3) to head (25bf70e).
⚠️ Report is 127 commits behind head on master.

Files with missing lines Patch % Lines
src/AutoPilotPlugins/PX4/FailureInjection.cc 52.05% 7 Missing and 28 partials ⚠️
src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc 40.00% 0 Missing and 3 partials ⚠️
.../AutoPilotPlugins/PX4/FailureInjectionComponent.cc 81.81% 0 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14578      +/-   ##
==========================================
+ Coverage   25.47%   30.69%   +5.22%     
==========================================
  Files         769      789      +20     
  Lines       65912    66887     +975     
  Branches    30495    30985     +490     
==========================================
+ Hits        16788    20529    +3741     
+ Misses      37285    32399    -4886     
- Partials    11839    13959    +2120     
Flag Coverage Δ
unittests 30.69% <60.00%> (+5.22%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/AutoPilotPlugins/PX4/FailureInjection.h 100.00% <100.00%> (ø)
...c/AutoPilotPlugins/PX4/FailureInjectionComponent.h 100.00% <100.00%> (ø)
src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.h 0.00% <ø> (ø)
.../AutoPilotPlugins/PX4/FailureInjectionComponent.cc 81.81% <81.81%> (ø)
src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc 40.31% <40.00%> (+14.50%) ⬆️
src/AutoPilotPlugins/PX4/FailureInjection.cc 52.05% <52.05%> (ø)

... and 436 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8caf3c7...25bf70e. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added size/L and removed size/M labels Jul 2, 2026
@Claudio-Chies

Copy link
Copy Markdown
Contributor Author

@bkueng @hamishwillee FYI This would be the PR for the UI side of the Failure injection refactor.

@Claudio-Chies
Claudio-Chies marked this pull request as ready for review July 2, 2026 10:42
@Claudio-Chies
Claudio-Chies requested a review from HTRamsey as a code owner July 2, 2026 10:42
Copilot AI review requested due to automatic review settings July 2, 2026 10:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new PX4 Vehicle Setup page for injecting simulated failures using MAV_CMD_INJECT_FAILURE, gated by the presence of SYS_FAILURE_EN on the connected vehicle. It also updates MAVLink to a newer commit and extends the MAVLink-enum generator so QML can reflect the FAILURE_UNIT/FAILURE_TYPE catalogs directly from the MAVLink dialect.

Changes:

  • Add a PX4 “Failure Injection” setup component + QML page (instance selection, activity log, reset-all).
  • Add a QML singleton (FailureInjection) which builds unit/type catalogs from MAVLink enum reflection and tracks session activity.
  • Update MAVLink git tag and adjust enum-generation to provide QML-reflectable FAILURE_UNIT/FAILURE_TYPE enums, plus add unit/integration/UI tests.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tools/generators/mavlink_enums.py Extends QML enum header generation to locally redeclare specific enums for QML reflection.
cmake/CustomOptions.cmake Bumps the MAVLink repository commit/tag used by the build.
src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.h Adds the Failure Injection component member/include.
src/AutoPilotPlugins/PX4/PX4AutoPilotPlugin.cc Conditionally adds the Failure Injection setup page when SYS_FAILURE_EN exists.
src/AutoPilotPlugins/PX4/FailureInjectionComponent.qml Implements the full PX4 setup UI for injecting and resetting failures via MAVLink command.
src/AutoPilotPlugins/PX4/FailureInjectionInstances.js Shared instance-selection logic for mapping selected instances to MAVLink params.
src/AutoPilotPlugins/PX4/FailureInjectionComponent.h Declares the new Vehicle Setup component wrapper.
src/AutoPilotPlugins/PX4/FailureInjectionComponent.cc Implements component metadata and QML source wiring.
src/AutoPilotPlugins/PX4/FailureInjection.h Declares the QML singleton API and activity/catalog properties.
src/AutoPilotPlugins/PX4/FailureInjection.cc Builds catalogs from Q_ENUM_NS metadata and manages activity + injected-unit tracking.
src/AutoPilotPlugins/PX4/CMakeLists.txt Adds new C++ sources and QML/JS resources to the PX4 plugin build.
test/UnitTestFramework/QmlTesting/tests/tst_FailureInjectionInstances.qml Unit tests for the shared JS instance-selection logic.
test/AutoPilotPlugins/PX4/FailureInjectionTest.h Declares unit tests for the FailureInjection singleton model/logic.
test/AutoPilotPlugins/PX4/FailureInjectionTest.cc Implements unit tests for catalog building and activity/injected tracking behavior.
test/AutoPilotPlugins/CMakeLists.txt Registers the new FailureInjection unit test target.
test/QmlUITests/FailureInjectionUITest.h Declares an integration UI test that drives injection/reset through the real UI.
test/QmlUITests/FailureInjectionUITest.cc Implements the UI test using PX4 MockLink and QML objectName lookups.
test/QmlUITests/CMakeLists.txt Adds the new FailureInjection UI test to the test build/ctest list.

property Fact _sysFailureEn: controller.getParameterFact(-1, "SYS_FAILURE_EN", true /* reportMissing */)
property bool _paramSet: _sysFailureEn && _sysFailureEn.value === 1
property bool _pendingReboot: false // SYS_FAILURE_EN just toggled, reboot not yet triggered
property bool _armed: _paramSet // PX4 honors SYS_FAILURE_EN at boot; arm once the param reads 1
Comment on lines +38 to +41
property int _unitIndex: 4 // GPS
property int _typeIndex: 1 // Off
property var _selectedInstances: [1] // 1-based instance numbers
readonly property int _instanceCount: 8 // fixed number of selectable instances (not tied to the unit)
Comment on lines +25 to +26
Q_PROPERTY(QVariantList units READ units CONSTANT) ///< [{ name, unit, max }]
Q_PROPERTY(QVariantList types READ types CONSTANT) ///< [{ name, type }]

// One ack arrived: resolve the matching log row (only one is pending at a time), then send the next.
function _onAck(ackResult) {
FailureInjection.resolveResult(ackResult) // no-op when the head was a reset (no pending row)
Claudio Chies added 2 commits July 2, 2026 16:13
- Introduced FailureInjection and FailureInjectionComponent classes to manage simulated sensor and system failures.
- Updated CMakeLists.txt to include new source files and tests for Failure Injection.
- Implemented QML interface for Failure Injection, allowing users to inject failures and view activity logs.
- Enhanced MAVLink enums to support new FAILURE_UNIT and FAILURE_TYPE enums for failure injection.
- Added unit tests for FailureInjection functionality to ensure proper behavior and integration.
@Claudio-Chies
Claudio-Chies force-pushed the cch/qgc-failure-injection branch from e7f5ab2 to b6b67e7 Compare July 2, 2026 14:13
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Build Results

Platform Status

Platform Status Details
Linux Passed View
Windows Passed View
MacOS Passed View
Android Passed View

All builds passed.

Pre-commit

Check Status Details
pre-commit Failed (non-blocking) View

Pre-commit hooks: 0 passed, 0 failed, 0 skipped.

Test Results

linux-coverage-integration: 26 passed, 0 skipped
linux-coverage-unit: 104 passed, 0 skipped
Total: 130 passed, 0 skipped

Code Coverage

Coverage Baseline Change
66.3% 66.3% +0.1%

Artifact Sizes

Artifact Size Δ from master
QGroundControl 221.86 MB -4.40 MB (decrease)
QGroundControl-aarch64 179.42 MB -0.00 MB (decrease)
QGroundControl-installer-AMD64 137.92 MB -0.45 MB (decrease)
QGroundControl-installer-AMD64-ARM64 80.46 MB -0.19 MB (decrease)
QGroundControl-installer-ARM64 109.21 MB +0.01 MB (increase)
QGroundControl-linux 87.10 MB -78.78 MB (decrease)
QGroundControl-mac 87.09 MB +0.01 MB (increase)
QGroundControl-windows 86.16 MB +0.01 MB (increase)
QGroundControl-x86_64 191.64 MB -0.01 MB (decrease)
Total size decreased by 83.81 MB

Updated: 2026-07-07 06:20:51 UTC • Commit: 25bf70e • Triggered by: Android

@HTRamsey
HTRamsey requested a review from DonLakeFlyer July 3, 2026 04:56
@DonLakeFlyer DonLakeFlyer added this to the Release V5.2 milestone Jul 3, 2026
@Claudio-Chies
Claudio-Chies force-pushed the cch/qgc-failure-injection branch from cb576ac to 01412ce Compare July 3, 2026 11:45
@DonLakeFlyer

Copy link
Copy Markdown
Contributor

FYI: Since we are currently in Stable 5.1 lockdown this won't get merged until we create the 5.1 branch.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants