Skip to content

[mmu probing] pr07.test: Add comprehensive unit tests for probe framework#22545

Merged
StormLiangMS merged 11 commits intosonic-net:masterfrom
XuChen-MSFT:xuchen3/mmu_probe/pr07-unit-tests
Mar 25, 2026
Merged

[mmu probing] pr07.test: Add comprehensive unit tests for probe framework#22545
StormLiangMS merged 11 commits intosonic-net:masterfrom
XuChen-MSFT:xuchen3/mmu_probe/pr07-unit-tests

Conversation

@XuChen-MSFT
Copy link
Copy Markdown
Contributor

@XuChen-MSFT XuChen-MSFT commented Feb 23, 2026

Description of PR

Summary:

Implement complete unit test suite for all probe framework components using pytest with mock-based testing approach.

Test Infrastructure:

  • conftest.py: Shared pytest fixtures and test utilities
  • pytest.ini: Pytest configuration for unit test execution

Component Tests (22 test modules):

Data Structures & Protocols:

  • test_iteration_outcome.py: Iteration result enumeration tests
  • test_probing_result.py: Threshold result data class tests
  • test_probing_executor_protocol.py: Executor protocol interface tests
  • test_observer_config.py: Observer configuration tests

Algorithms:

  • test_lower_bound_probing_algorithm.py: Lower bound binary search tests
  • test_upper_bound_probing_algorithm.py: Upper bound binary search tests
  • test_threshold_point_probing_algorithm.py: Precise threshold tests
  • test_threshold_range_probing_algorithm.py: Threshold range tests

Infrastructure:

  • test_executor_registry.py: Executor factory pattern tests
  • test_stream_manager.py: Traffic stream management tests
  • test_buffer_occupancy_controller.py: Buffer control tests
  • test_probing_observer.py: Observer pattern implementation tests

Executors:

  • test_pfc_xoff_probing_executor.py: Physical PFC executor tests
  • test_sim_pfc_xoff_probing_executor.py: Simulated PFC executor tests
  • test_ingress_drop_probing_executor.py: Physical drop executor tests
  • test_sim_ingress_drop_probing_executor.py: Simulated drop executor tests

Framework & Implementations:

  • test_probing_base.py: Base framework template method tests
  • test_pfc_xoff_probing.py: PFC Xoff probing implementation tests
  • test_ingress_drop_probing.py: Ingress drop probing tests
  • test_headroom_pool_probing.py: Headroom pool probing tests

All tests use mock executors and dependency injection for isolation, achieving comprehensive coverage of framework functionality.

Fixes # (issue)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • New Test case
    • Skipped for non-supported platforms
  • Test case improvement

Back port request

  • 202205
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511

Approach

What is the motivation for this PR?

qos refactoring

How did you do it?

How did you verify/test it?

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

relevant PRs:
[mmu probing] pr01.docs: Add MMU threshold probing framework design
[mmu probing] pr02.probe: Add core probing algorithms with essential data structures
[mmu probing] pr03.probe: Add probing executors and executor registry
[mmu probing] pr04.probe: Add observer pattern for metrics tracking
[mmu probing] pr05.probe: Add stream manager and buffer occupancy controller
[mmu probing] pr06.probe: Add base framework and all probing implementations
[mmu probing] pr07.test: Add comprehensive unit tests for probe framework
[mmu probing] pr08.test: Add integration tests for end-to-end probing workflows
[mmu probing] pr09.test: Add production probe test and infrastructure updates

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

yxieca
yxieca previously approved these changes Feb 23, 2026
Copy link
Copy Markdown
Collaborator

@yxieca yxieca left a comment

Choose a reason for hiding this comment

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

Deep review done. Unit tests look fine; no issues found.

yxieca
yxieca previously approved these changes Feb 24, 2026
Copy link
Copy Markdown
Collaborator

@yxieca yxieca left a comment

Choose a reason for hiding this comment

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

Re-reviewed updates; no new issues found.

@XuChen-MSFT
Copy link
Copy Markdown
Contributor Author

Below is sample test log for running this unit test for probe framework:
(run in any environment with pytest installation).

$  cd /mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/mock/ut && python3 -m pytest . -v
[Cleanup] Removed /mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/mock/ut/__pycache__
[Cleanup] Removed /mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/mock/ut/../../probe/__pycache__
============================================================================================= test session starts ==============================================================================================
platform linux -- Python 3.8.10, pytest-8.3.5, pluggy-1.5.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/mock/ut
configfile: pytest.ini
plugins: cov-5.0.0, order-1.3.0
collected 390 items

test_sim_pfc_xoff_probing_executor.py::test_pfc_xoff_normal_scenario
=== Testing PFC XOFF Normal Scenario ===
  Check at 400 packets: NOT triggered (expected: NOT triggered)
  Check at 499 packets: NOT triggered (expected: NOT triggered)
  Check at 500 packets: TRIGGERED (expected: TRIGGERED)
  Check at 600 packets: TRIGGERED (expected: TRIGGERED)
  Check at 1000 packets: TRIGGERED (expected: TRIGGERED)

Total checks performed: 5
[OK] PFC XOFF normal scenario test passed
PASSED
test_sim_pfc_xoff_probing_executor.py::test_pfc_xoff_noisy_hardware [OK] PFC XOFF noisy hardware test passed
PASSED
test_sim_ingress_drop_probing_executor.py::test_ingress_drop_normal_scenario
=== Testing Ingress Drop Normal Scenario ===
  Check at 400 packets: NO drop (expected: NO drop)
  Check at 499 packets: NO drop (expected: NO drop)
  Check at 500 packets: DROP (expected: DROP)
  Check at 600 packets: DROP (expected: DROP)
  Check at 1000 packets: DROP (expected: DROP)

Total checks performed: 5
[OK] Ingress Drop normal scenario test passed
PASSED
test_sim_ingress_drop_probing_executor.py::test_ingress_drop_wrong_config
=== Testing Ingress Drop Wrong Config Scenario ===
Configured threshold: 500, Offset: +100 -> Effective threshold: 600

Testing behavior:
  Check at 500 packets (configured threshold): NO drop (expected: NO drop due to offset)
  Check at 599 packets: NO drop (expected: NO drop)
  Check at 600 packets (effective threshold): DROP (expected: DROP)
  Check at 700 packets: DROP (expected: DROP)

Comparing with normal executor (no offset):
  At 500 packets: Normal=DROP, WrongConfig=NO drop
[OK] Ingress Drop wrong configuration test passed (detected offset behavior)
PASSED
test_executor_registry.py::test_register_decorator_physical
=== UT: register() decorator - physical ===
[OK] Physical executor registered correctly
PASSED

... omitted ...


-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

---------- coverage: platform linux, python 3.8.10-final-0 -----------
Name                                                                                                     Stmts   Miss Branch BrPart  Cover   Missing
----------------------------------------------------------------------------------------------------------------------------------------------------
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/__init__.py                                1      1      0      0     0%   46
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/buffer_occupancy_controller.py            66      0     24      0   100%
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/executor_registry.py                      42      0     14      0   100%
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/headroom_pool_probing.py                 231     17     66     18    88%   48->50, 50->53, 113-114, 133, 287-288, 327->335, 339-340, 347-348, 355-356, 361->376, 362->376, 369->376, 400->409, 413-414, 421-422, 429-430, 435->448, 436->448, 443->448
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/ingress_drop_probing.py                  112      9     34      2    91%   39, 41, 92-102
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/ingress_drop_probing_executor.py          95     22     37      3    77%   51-66, 181-182, 221-230, 282->284
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/iteration_outcome.py                      11      0      2      0   100%
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/lower_bound_probing_algorithm.py          42      1     12      2    94%   24->32, 29
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/observer_config.py                        15      0      4      0   100%
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/pfc_xoff_probing.py                      112      9     34      2    91%   39, 41, 92-102
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/pfc_xoff_probing_executor.py              71      9     20      1    89%   45-54, 200->202
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/probing_base.py                          102     21     22      1    77%   45, 119-154, 158
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/probing_executor_protocol.py               7      2      2      0    78%   47, 76
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/probing_observer.py                      126      2     28      2    97%   43, 327
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/probing_result.py                         37      0     10      0   100%
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/sim_ingress_drop_probing_executor.py      74     18     32      7    67%   58->exit, 75-76, 100->106, 110->exit, 136->exit, 149->156, 181->exit, 196->203, 225-230, 238-261
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/sim_pfc_xoff_probing_executor.py          74     28     32      5    56%   58->exit, 75-76, 100->106, 110->exit, 136->exit, 149->156, 178-182, 190-203, 225-230, 238-261
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/stream_manager.py                         59      0     14      0   100%
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/threshold_point_probing_algorithm.py      43      1     12      2    95%   23->31, 28
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/threshold_range_probing_algorithm.py      60      2     18      3    94%   24->32, 29, 166
/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/probe/upper_bound_probing_algorithm.py          40      0     10      2    96%   24->32, 28->30
----------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                                                                     1420    142    427     50    87%
Coverage HTML written to dir htmlcov

======================================================================================= 390 passed, 4 warnings in 11.06s =======================================================================================
xuchen3@xuchen3-devbox:/mnt/c/ws/repo/sonic-mgmt-int/sonic-mgmt-int/tests/saitests/mock/ut

@XuChen-MSFT XuChen-MSFT marked this pull request as draft February 25, 2026 11:22
@XuChen-MSFT XuChen-MSFT marked this pull request as ready for review February 25, 2026 11:23
@StormLiangMS
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@XuChen-MSFT
Copy link
Copy Markdown
Contributor Author

Added 10 unit tests to improve bug fix coverage (6c11ce9):

  • is_range None guard: 3 tests (None lower, None upper, both None with success=True)
  • is_point None guard: 3 tests (same patterns)
  • Lower-bound infinite loop: 1 test (verify ≤5 iterations at current=1)
  • Point algo buffer drain: 1 test (verify drain_buffer=True after failure)
  • repr invalid state: 2 tests (None bounds don't crash repr)

UT total: 390 → 400. See PR #22540 for the corresponding source code fixes.

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@XuChen-MSFT
Copy link
Copy Markdown
Contributor Author

Added 15 unit tests for anti-oscillation and BadSpot executors (d4fff81):

BadSpot executor UTs (+8):

Anti-oscillation backtrack UTs (+7):

  • Scenario 1-2: single-layer backtrack (parent unreached/reached)
  • Scenario 3-4: multi-layer backtrack (grandparent unreached/reached)
  • Bad region convergence: algorithm navigates around 20-value bad region
  • Nudge size proportional calculation
  • Oscillation: bad value not retested more than 3 times

Registry fix: hardcoded executor count -> issubset check (supports new executors)

UT total: 400 -> 415. Validates algorithm fix in PR #22540 (036f27c).

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

XuChen-MSFT added a commit to XuChen-MSFT/sonic-mgmt that referenced this pull request Mar 22, 2026
…ing Exception

Physical executors catch hardware errors and return (False, False).
Algorithm callers expect a tuple and check 'if not success:' without
try/except. Raising Exception crashes the algorithm instead of
triggering graceful retry/backtrack.

Changed: raise Exception(error_msg) → return (False, False)
Files: sim_pfc_xoff_probing_executor.py, sim_ingress_drop_probing_executor.py

UT coverage: PR sonic-net#22545 (74b3efb) — 4 new tests verifying the return contract.

Addresses @StormLiangMS review: sim intermittent raises exceptions
instead of returning (False, False) like physical executors.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@XuChen-MSFT
Copy link
Copy Markdown
Contributor Author

Added 4 UTs for intermittent executor return contract (74b3efb):

  • test_pfc_xoff_intermittent_returns_tuple_not_exception: failure_rate=1.0, verify returns (False, False) not raise Exception
  • test_ingress_drop_intermittent_returns_tuple_not_exception: same pattern
  • test_pfc_xoff_intermittent_success_path: failure_rate=0.0, verify normal detection
  • test_ingress_drop_intermittent_success_path: same pattern

Validates fix in PR #22541 (2210ae6): raise Exceptionreturn (False, False).

UT total: 431 → 435.

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

XuChen-MSFT added a commit to XuChen-MSFT/sonic-mgmt that referenced this pull request Mar 23, 2026
Refactored multi-PG probe loop from 6 scattered 'continue' statements
to while-True single-pass block with unified cleanup:
- break + fail_reason on any phase failure
- pg_success flag tracks completion
- Single drain_buffer([dst_port_id]) call in cleanup block

This ensures buffer state is always drained before moving to the next PG,
preventing corrupted buffer from affecting subsequent PG probing.

UT coverage: PR sonic-net#22545 (3d75029) — 7 new tests
IT coverage: PR sonic-net#22546 (14a29c2) — 2 new tests

Addresses @StormLiangMS review: continue on PG failure skips buffer cleanup.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@XuChen-MSFT
Copy link
Copy Markdown
Contributor Author

Added 7 UTs for buffer cleanup on PG failure (3d75029):

Tests verify drain_buffer() is called when a PG phase fails in the multi-PG loop (order 4250-4256):

  • PFC upper/lower/range failure (3 tests)
  • Ingress Drop upper/lower/range failure (3 tests)
  • Different dst_ports isolation (1 test)

Validates fix in PR #22544 (7c6b4fa): while-True unified cleanup pattern.

UT total: 435 → 442.

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

XuChen-MSFT added a commit to XuChen-MSFT/sonic-mgmt that referenced this pull request Mar 24, 2026
When candidate_threshold is small (e.g. 10), precision target
candidate * 0.05 = 0.5 < 1. With bad_spot at the threshold value,
range_size stays at 1 but 1 <= 0.5 is never satisfied, burning all
50 max_iterations. Use max(1, ...) to ensure precision check can
terminate when range narrows to 1 packet granularity.

Validated by UT (PR sonic-net#22545) and IT (PR sonic-net#22546) — both FAIL without
this fix (50 iterations), PASS with fix (~18 iterations).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xu Chen <xuchen3@microsoft.com>
XuChen-MSFT added a commit to XuChen-MSFT/sonic-mgmt that referenced this pull request Mar 24, 2026
…p executors

PfcXoff used explicit all_true/all_false/all_equal pattern (8 lines).
IngressDrop used concise set-dedup pattern (3 lines). Both produce
identical outcomes for all input combinations.

Unified to the concise pattern with descriptive comment:
  return_result = (True, results[0])
  # Multiple attempts: check consistency (set dedup detects mixed True/False)
  if len(results) > 1 and len(set(results)) > 1:
      return_result = (False, False)

UT coverage: PR sonic-net#22545 (e2fca74) — 12 new tests covering all 6 input
combinations for both executors.

Addresses @StormLiangMS review: inconsistent result patterns.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xu Chen <xuchen3@microsoft.com>
XuChen-MSFT added a commit to XuChen-MSFT/sonic-mgmt that referenced this pull request Mar 24, 2026
…ing Exception

Physical executors catch hardware errors and return (False, False).
Algorithm callers expect a tuple and check 'if not success:' without
try/except. Raising Exception crashes the algorithm instead of
triggering graceful retry/backtrack.

Changed: raise Exception(error_msg) → return (False, False)
Files: sim_pfc_xoff_probing_executor.py, sim_ingress_drop_probing_executor.py

UT coverage: PR sonic-net#22545 (74b3efb) — 4 new tests verifying the return contract.

Addresses @StormLiangMS review: sim intermittent raises exceptions
instead of returning (False, False) like physical executors.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xu Chen <xuchen3@microsoft.com>
XuChen-MSFT added a commit to XuChen-MSFT/sonic-mgmt that referenced this pull request Mar 24, 2026
Refactored multi-PG probe loop from 6 scattered 'continue' statements
to while-True single-pass block with unified cleanup:
- break + fail_reason on any phase failure
- pg_success flag tracks completion
- Single drain_buffer([dst_port_id]) call in cleanup block

This ensures buffer state is always drained before moving to the next PG,
preventing corrupted buffer from affecting subsequent PG probing.

UT coverage: PR sonic-net#22545 (3d75029) — 7 new tests
IT coverage: PR sonic-net#22546 (14a29c2) — 2 new tests

Addresses @StormLiangMS review: continue on PG failure skips buffer cleanup.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xu Chen <xuchen3@microsoft.com>
XuChen-MSFT and others added 11 commits March 24, 2026 12:59
Implement complete unit test suite for all probe framework components
using pytest with mock-based testing approach.

Test Infrastructure:
- conftest.py: Shared pytest fixtures and test utilities
- pytest.ini: Pytest configuration for unit test execution

Component Tests (22 test modules):

Data Structures & Protocols:
- test_iteration_outcome.py: Iteration result enumeration tests
- test_probing_result.py: Threshold result data class tests
- test_probing_executor_protocol.py: Executor protocol interface tests
- test_observer_config.py: Observer configuration tests

Algorithms:
- test_lower_bound_probing_algorithm.py: Lower bound binary search tests
- test_upper_bound_probing_algorithm.py: Upper bound binary search tests
- test_threshold_point_probing_algorithm.py: Precise threshold tests
- test_threshold_range_probing_algorithm.py: Threshold range tests

Infrastructure:
- test_executor_registry.py: Executor factory pattern tests
- test_stream_manager.py: Traffic stream management tests
- test_buffer_occupancy_controller.py: Buffer control tests
- test_probing_observer.py: Observer pattern implementation tests

Executors:
- test_pfc_xoff_probing_executor.py: Physical PFC executor tests
- test_sim_pfc_xoff_probing_executor.py: Simulated PFC executor tests
- test_ingress_drop_probing_executor.py: Physical drop executor tests
- test_sim_ingress_drop_probing_executor.py: Simulated drop executor tests

Framework & Implementations:
- test_probing_base.py: Base framework template method tests
- test_pfc_xoff_probing.py: PFC Xoff probing implementation tests
- test_ingress_drop_probing.py: Ingress drop probing tests
- test_headroom_pool_probing.py: Headroom pool probing tests

All tests use mock executors and dependency injection for isolation,
achieving comprehensive coverage of framework functionality.

Signed-off-by: Xu Chen <xuchen3@microsoft.com>
Signed-off-by: Xu Chen <xuchen3@microsoft.com>
Add UT coverage for 4 fixed issues:
- is_range None guard: 3 tests (None lower, None upper, both None)
- is_point None guard: 3 tests (same patterns as is_range)
- Lower-bound infinite loop at current=1: 1 test (verify <= 5 iterations)
- Point algo buffer drain after failure: 1 test (verify drain_buffer=True)
- __repr__ with invalid state: 2 tests (both None, partial None)

UT total: 390 -> 400

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xu Chen <xuchen3@microsoft.com>
BadSpot executor UTs (+8):
- PFC XOFF: normal values, bad values, empty, repeated (4 tests)
- Ingress Drop: same pattern (4 tests)

Anti-oscillation backtrack UTs (+7):
- Scenario 1-2: single-layer backtrack (parent unreached/reached)
- Scenario 3-4: multi-layer backtrack (grandparent unreached/reached)
- Bad region convergence: algorithm navigates around 20-value bad region
- Nudge size: proportional calculation verification
- Oscillation: bad value not retested more than 3 times

Registry fix: hardcoded executor count → issubset check

UT total: 400 -> 415

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xu Chen <xuchen3@microsoft.com>
New UT cases (+2):
- test_precision_check_at_small_threshold_with_bad_spot: threshold=1
  with bad_spot, verifies algorithm exits via precision_reached not
  max_iterations. Without fix: 50 iterations FAIL. With fix: PASS.
- test_precision_check_at_small_threshold: small threshold=5 convergence

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xu Chen <xuchen3@microsoft.com>
2 new tests (order 8817-8818) covering the observer None guard fix:
- test_check_verbose_observer_none_guard_result_path: verifies L281 guard
- test_check_verbose_observer_none_guard_exception_path: verifies L290 guard

Both tests bypass the L162 assert by nullifying observer mid-execution
via counter read side_effect, then verify no AttributeError crash.

Related: PR sonic-net#22541 fix (observer None guard)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xu Chen <xuchen3@microsoft.com>
…stry tests

The autouse fixture in conftest.py (reset_executor_registry) already calls
ExecutorRegistry.clear_registry() and cleans sys.modules before and after
each test via yield (guaranteed by pytest even on test failure).

Removed 6 redundant manual del/discard statements that were pre-fixture
legacy code. Updated docstring to document the fixture-based isolation.

Addresses @StormLiangMS review: class-level mutable state cleanup concern.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xu Chen <xuchen3@microsoft.com>
6 UTs for IngressDropProbingExecutor (order 8819-8824):
  single detected/not-detected, multi all/none/inconsistent-TF/FT

6 UTs for PfcXoffProbingExecutor (order 8719-8724):
  same 6 input combinations

Covers all result analysis code paths for the consistency pattern
unification in PR sonic-net#22541. All 6 scenarios produce identical outcomes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xu Chen <xuchen3@microsoft.com>
2 bug reproduction tests (failure_rate=1.0):
- test_pfc_xoff_intermittent_returns_tuple_not_exception (order 12)
- test_ingress_drop_intermittent_returns_tuple_not_exception (order 14)
  Verify check() returns (False, False) on failure, not raise Exception.

2 success path tests (failure_rate=0.0):
- test_pfc_xoff_intermittent_success_path (order 13)
- test_ingress_drop_intermittent_success_path (order 15)
  Verify normal detection works when no failure occurs.

Related: PR sonic-net#22541 fix (intermittent raise → return)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xu Chen <xuchen3@microsoft.com>
…bing

Tests verify drain_buffer() is called before continue when a PG phase
fails in the multi-PG loop (order 4250-4256):
- PFC upper/lower/range failure (3 tests)
- Ingress Drop upper/lower/range failure (3 tests)
- Different dst_ports isolation (1 test)

Uses per-type mock side_effects to correctly handle 2-tuple (upper/lower)
vs 3-tuple (range/point) algorithm return values.

Related: PR sonic-net#22544 fix (while-True unified cleanup)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Xu Chen <xuchen3@microsoft.com>
- E127: fix continuation line indentation in test_headroom_pool_probing.py
- F811: remove redundant local imports of SimIngressDropProbingExecutorIntermittent
  and SimPfcXoffProbingExecutorIntermittent (already imported at module level)
- EOF: add trailing newline to test_ingress_drop_probing_executor.py

Signed-off-by: Xu Chen <xuchen3@microsoft.com>
@XuChen-MSFT XuChen-MSFT force-pushed the xuchen3/mmu_probe/pr07-unit-tests branch from d901a80 to d4509f5 Compare March 24, 2026 04:59
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown
Collaborator

@StormLiangMS StormLiangMS left a comment

Choose a reason for hiding this comment

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

✅ LGTM — Comprehensive unit test suite

22 test files covering all framework components with >90% coverage target:

  • Good test isolation via conftest.py with autouse registry reset and sys.modules cleanup
  • pytest_sessionstart hook for __pycache__ cleanup prevents stale bytecode issues
  • pytest-order ensures correct test execution sequence
  • Coverage config with branch tracking and term-missing report

No issues found.

@StormLiangMS StormLiangMS merged commit 58ba876 into sonic-net:master Mar 25, 2026
15 checks passed
ravaliyel pushed a commit to ravaliyel/sonic-mgmt that referenced this pull request Mar 27, 2026
…work (sonic-net#22545)

Description of PR
Summary:

Implement complete unit test suite for all probe framework components using pytest with mock-based testing approach.

Test Infrastructure:

conftest.py: Shared pytest fixtures and test utilities
pytest.ini: Pytest configuration for unit test execution
Component Tests (22 test modules):

Data Structures & Protocols:

test_iteration_outcome.py: Iteration result enumeration tests
test_probing_result.py: Threshold result data class tests
test_probing_executor_protocol.py: Executor protocol interface tests
test_observer_config.py: Observer configuration tests
Algorithms:

test_lower_bound_probing_algorithm.py: Lower bound binary search tests
test_upper_bound_probing_algorithm.py: Upper bound binary search tests
test_threshold_point_probing_algorithm.py: Precise threshold tests
test_threshold_range_probing_algorithm.py: Threshold range tests
Infrastructure:

test_executor_registry.py: Executor factory pattern tests
test_stream_manager.py: Traffic stream management tests
test_buffer_occupancy_controller.py: Buffer control tests
test_probing_observer.py: Observer pattern implementation tests
Executors:

test_pfc_xoff_probing_executor.py: Physical PFC executor tests
test_sim_pfc_xoff_probing_executor.py: Simulated PFC executor tests
test_ingress_drop_probing_executor.py: Physical drop executor tests
test_sim_ingress_drop_probing_executor.py: Simulated drop executor tests
Framework & Implementations:

test_probing_base.py: Base framework template method tests
test_pfc_xoff_probing.py: PFC Xoff probing implementation tests
test_ingress_drop_probing.py: Ingress drop probing tests
test_headroom_pool_probing.py: Headroom pool probing tests
All tests use mock executors and dependency injection for isolation, achieving comprehensive coverage of framework functionality.

Signed-off-by: Xu Chen <xuchen3@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

4 participants