Skip to content

test(ekf2): run EKF2SelectorTest on simulated time - #30033

Open
MaEtUgR wants to merge 3 commits into
mainfrom
maetugr/multi-ekf-test-fix
Open

MaEtUgR wants to merge 3 commits into
mainfrom
maetugr/multi-ekf-test-fix

Conversation

@MaEtUgR

@MaEtUgR MaEtUgR commented Nov 25, 2026

Copy link
Copy Markdown
Member

Solved Problem

EKF2SelectorTest fails intermittently, e.g. this run. The test ran the selector on its work queue in real time. Which instance a fresh selector picked first depended on thread scheduling, and when it picked instance 1, the selector's 10 s lockout on recently selected instances made the test time out.

Solution

  • EKF2Selector::Run() reads the clock once per cycle and passes it to Update(now). The selection logic, sensor_selection and the selector status all use that time.
  • The republish functions keep their own clock reads. They check samples that can arrive after the cycle started, which would make now minus the sample timestamp wrap around and drop them as stale.
  • The test calls Update() directly on a simulated clock without starting the work queue. The selector always starts on instance 0, every run behaves the same, and the suite takes milliseconds instead of about 26 s.

Changelog Entry

No change in flight behaviour.

Test coverage

  • The rewritten tests catch the bugs they were written for. With the timeout bypass of the warned-fallback delay removed, timedOutPrimaryFallsBackImmediately fails. With sustained warnings ignored, i.e. the fix for [Bug] v1.17.0 - Altitude spikes in fixed wing mode #27013 reverted, noFallbackToSustainedWarnedInstance fails.
  • 20 runs in a row passed.

The test gave the selector a fixed 2.5 s to switch away from the warned
primary. When a fresh selector first picks instance 1 and settleBaseline()
moves it back to 0, instance 1 was just selected and the selector blocks
switching back to it for 10 s, so the test failed on CI:
https://github.com/PX4/PX4-Autopilot/actions/runs/45669361735/job/139400126257

Use degradeUntilSwitched() like the other switch-away tests, which
publishes the same data until the switch happens, within 15 s.
The selection logic read the clock about a dozen times per cycle, so it
could only be tested in real time. Run() now reads it once and passes it
to Update(now), which the selection logic, the sensor_selection and the
selector status use. Tests can call Update() with a simulated time.
The test ran the selector on its work queue in real time. Which instance
a fresh selector picked first depended on thread scheduling, and when it
picked instance 1 the selector's 10 s lockout made
timedOutPrimaryFallsBackImmediately fail:
https://github.com/PX4/PX4-Autopilot/actions/runs/45669361735/job/139400126257

The test now steps Update() on a simulated clock without starting the
work queue. The selector always starts on instance 0, every run behaves
the same, and the suite takes milliseconds instead of about 26 s.
@MaEtUgR
MaEtUgR requested review from Saibernard and bresch November 25, 2026 22:24
@MaEtUgR MaEtUgR self-assigned this Nov 25, 2026
@github-actions github-actions Bot added kind:test Adds or improves tests. scope:estimation EKF, local position, attitude, wind, bias, or aiding logic. labels Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:test Adds or improves tests. scope:estimation EKF, local position, attitude, wind, bias, or aiding logic.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant