Skip to content

[pfcwd] Add unit tests for hardware PFC watchdog#4418

Open
arawat-nexthop wants to merge 9 commits intosonic-net:masterfrom
nexthop-ai:hw-pfcwd-unit-tests
Open

[pfcwd] Add unit tests for hardware PFC watchdog#4418
arawat-nexthop wants to merge 9 commits intosonic-net:masterfrom
nexthop-ai:hw-pfcwd-unit-tests

Conversation

@arawat-nexthop
Copy link
Copy Markdown

@arawat-nexthop arawat-nexthop commented Mar 31, 2026

What I did

Add comprehensive unit test coverage for hardware-based PFC (Priority Flow Control) watchdog functionality. This PR includes two sets of tests:

1. PfcWdHwOrch orchestration tests (30 test cases):

  • Configuration validation: Invalid ports, time ranges, actions, and parameters
  • Action management: Global action setting, consistency enforcement, reset behavior
  • Port lifecycle: Reconfiguration, STATE_DB lifecycle, warm reboot recovery
  • Hardware configuration: Detection/restoration intervals, DLDR enable/disable
  • Deadlock handling: Callback registration, detection/restoration flow, statistics, edge cases
  • SAI failure handling: Rollback on switch action, interval, and queue DLDR failures
  • SKU detection: Hardware PFC watchdog SKU validation

2. PfcWdHwOrch counter management tests:

  • Storm detection and counter initialization
  • Periodic counter updates and delta calculation
  • Storm restoration and counter cleanup
  • Counter underflow protection
  • Hardware counter reading from COUNTERS_DB
  • Queue statistics persistence

Why I did it

Prior to this change, there was no unit test coverage for the hardware-based PFC watchdog component. These tests enable verification of correct behavior, catch regressions, and validate error handling.

How to verify it

cd sonic-swss/tests/mock_tests
make tests
./tests --gtest_filter="PfcWdHwOrchTest*"

Which release branch to backport (optional)

  • 202505
  • 202511

Dependencies

This PR is based on PR #4412 - [Hw PFCWD feature] Implementation for H/w based PFCWD

Once PR #4412 is merged, this PR will show only the 2 unit test commits.

Related PRs:

  • sonic-swss-common: Hardware state table schema definition
  • sonic-utilities: Hardware PFCWD CLI support
  • sonic-mgmt: Hardware-aware test suite

Signed-off-by: Abhishek <abhishek@nexthop.ai>
… functions.

Signed-off-by: Abhishek <abhishek@nexthop.ai>
Signed-off-by: Abhishek <abhishek@nexthop.ai>
Signed-off-by: Abhishek <abhishek@nexthop.ai>
Signed-off-by: Abhishek <abhishek@nexthop.ai>
Signed-off-by: Abhishek <abhishek@nexthop.ai>
…onality.

Signed-off-by: Abhishek <abhishek@nexthop.ai>
@arawat-nexthop arawat-nexthop requested a review from prsunny as a code owner March 31, 2026 13:37
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

What I did:

Add comprehensive unit test coverage for the hardware-based PFC (Priority Flow Control) watchdog orchestration agent (PfcWdHwOrch). Prior to this change, there was no unit test coverage for this critical component.

Changes include:

1. **Test infrastructure**:
   - Created PfcWdHwOrchTest fixture with SAI API mocks for switch, port, and queue operations
   - Set platform environment variable required by PfcWdBaseOrch constructor
   - Implemented helper functions: bringUpPorts(), enablePfcOnPort(), deleteHwWdEntry()

2. **30 unit tests covering**:
   - Configuration validation (7 tests): Invalid ports, time ranges, actions, and parameters
   - Action management (4 tests): Global action setting, consistency enforcement, reset behavior
   - Port lifecycle (3 tests): Reconfiguration, STATE_DB lifecycle, warm reboot recovery
   - Hardware configuration (3 tests): Detection/restoration intervals, DLDR enable/disable
   - Deadlock handling (6 tests): Callback registration, detection/restoration flow, statistics, edge cases
   - SAI failure handling (4 tests): Rollback on switch action, interval, and queue DLDR failures
   - SKU detection (1 test): Hardware PFC watchdog SKU validation

Why I did it:

Enable verification of correct behavior, catch regressions, and validate error handling for hardware-based PFC watchdog.

How to verify it:

```bash
cd sonic-swss/tests/mock_tests
make tests
./tests --gtest_filter="PfcWdHwOrchTest*"
```

Which release branch to backport (optional):

- [ ] 202505
- [ ] 202511

Signed-off-by: Abhishek Rawat <arawat@nexthop.ai>
What I did:

Add comprehensive unit tests for the hardware-based PFC watchdog (PFCWD) counter management logic in PfcWdHwOrch.

Test coverage includes:
- Storm detection and counter initialization (initQueueCounters())
- Periodic counter updates and delta calculation (updateQueueCounters() periodic path)
- Storm restoration and counter cleanup (updateQueueCounters() restoration path)
- Counter underflow protection
- Hardware counter reading from COUNTERS_DB (readHwCounters())
- Queue statistics persistence (getQueueStats()/updateQueueStats())

Implementation details:
- Created pfcwdhw_counters_ut.cpp with comprehensive test cases
- Updated Makefile.am to include the new test in the build
- Follows existing test patterns from flexcounter_ut.cpp
- Uses MockOrchTest base fixture for DB infrastructure

Why I did it:

Ensure correct behavior of hardware counter tracking, delta calculation, and statistics management for hardware-based PFC watchdog.

How to verify it:

```bash
cd sonic-swss/tests/mock_tests
make tests
./tests --gtest_filter="PfcWdHwOrchTest*"
```

Which release branch to backport (optional):

- [ ] 202505
- [ ] 202511

Signed-off-by: Abhishek Rawat <arawat@nexthop.ai>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

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