Skip to content

Fix flaky pytest-advanced-mode-toggle on MIPI devices - #15039

Merged
Nir-Az merged 4 commits into
realsenseai:developmentfrom
remibettan:fix-toggle-am-test
May 12, 2026
Merged

Nir-Az merged 4 commits into
realsenseai:developmentfrom
remibettan:fix-toggle-am-test

Conversation

@remibettan

@remibettan remibettan commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Drop the redundant simulate_device_reconnect call in d400_mipi_device::toggle_advanced_mode. The base ds_advanced_mode_base::toggle_advanced_mode already triggers it via _hardware_reset_action() -> virtual hardware_reset() (since ea4ec76), so the explicit second call fired two removed/added callbacks per toggle and raced the Python test's _wait_for_reconnect.
  • Log assertion failures explicitly with log.error before raising, so the per-test log shows the failure reason instead of jumping straight into the finally cleanup.
  • Bind the test to the parametrized device serial via _test_device_serial instead of taking devices_list[0], so it never accidentally operates on a different device when more than one is visible in the context.

Test plan

  • Run on D457 / D401 (MIPI/GMSL) - no spurious Expected ON after restore but got OFF from the double-callback race
  • Run on D405 (USB) - still passes
  • Run with multiple D400-series devices connected - each parametrized instance binds to its own serial

LibCI nightly run: https://rsjenkins.realsenseai.com/view/LRS/job/LRS_libci_pipeline/15697 - all green

Copilot AI review requested due to automatic review settings May 11, 2026 09:26

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 addresses flakiness in the live unit test that verifies RS400 advanced-mode toggling, primarily affecting MIPI/GMSL D400 devices. It does so by eliminating a redundant simulated reconnect in the MIPI device implementation (which caused duplicate device-changed callbacks) and by making the pytest bind explicitly to the parametrized device serial.

Changes:

  • Remove d400_mipi_device::toggle_advanced_mode() override to avoid a second simulate_device_reconnect() (base advanced-mode toggle already triggers hardware_reset(), which simulates reconnect for MIPI).
  • Update pytest-advanced-mode-toggle to select the device by _test_device_serial from test_context, avoiding accidental operation on a different device when multiple are present.
  • Replace assert statements with explicit log.error(...) + pytest.fail(...) to ensure failures are visible in per-test logs before cleanup runs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
unit-tests/live/hw-reset/pytest-advanced-mode-toggle.py Binds test execution to the parametrized serial and improves failure logging to reduce flakiness and improve diagnosability.
src/ds/d400/d400-mipi-device.h Removes the MIPI-specific toggle_advanced_mode override declaration so base advanced-mode logic is used.
src/ds/d400/d400-mipi-device.cpp Removes the redundant reconnect simulation in toggle_advanced_mode, preventing double device-changed callback cycles per toggle.

@remibettan
remibettan requested a review from Nir-Az May 11, 2026 11:46


def test_advanced_mode_toggle( test_device ):
def test_advanced_mode_toggle( _test_device_serial, test_context ):

@Nir-Az Nir-Az May 11, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If --device solve it locally we don't these changes as they are relevant for all tests

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed

f"[{i}/{TOGGLE_ITERATIONS}] Device did not reconnect within {TOGGLE_WAIT_TIME} sec after toggling advanced mode"
if not _wait_for_reconnect( TOGGLE_WAIT_TIME ):
msg = f"[{i}/{TOGGLE_ITERATIONS}] Device did not reconnect within {TOGGLE_WAIT_TIME} sec after toggling advanced mode"
log.error( msg )

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These should be investigated and fixed at infra level, we don't want to do it on each assert call, we can revert and open a ticket to solve in infra

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

agreed

@Nir-Az
Nir-Az merged commit 8196f96 into realsenseai:development May 12, 2026
30 checks passed
@remibettan
remibettan deleted the fix-toggle-am-test branch May 13, 2026 08:12
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.

3 participants