Skip to content

[DeepTest] Add unit tests for BBR congestion control#5887

Open
saikat107 wants to merge 6 commits intomainfrom
deeptest/bbr
Open

[DeepTest] Add unit tests for BBR congestion control#5887
saikat107 wants to merge 6 commits intomainfrom
deeptest/bbr

Conversation

@saikat107
Copy link
Copy Markdown
Contributor

Summary

Adds 84 GoogleTest unit tests for src/core/bbr.c, covering all 33 BBR functions. Tests exercise the real BBR implementation with hand-crafted input structs — no mocks or state mutation.

Changes

File Change
src/core/unittest/BbrTest.cpp New — 84 tests (2269 lines)
src/core/unittest/CMakeLists.txt Added BbrTest.cpp to build
.gitignore Added .deeptest/ directory

Test Organization

Following the CubicTest.cpp convention, tests are grouped into three sections:

  1. Spec-conformance (~35 tests) — Verifiable against the BBR RFC/spec without implementation knowledge (initialization, bandwidth filtering, RTT tracking, state transitions).
  2. Loosely coupled (~24 tests) — Test observable behavior driven by implementation strategy (recovery handling, congestion window updates, send quantum).
  3. Tightly coupled (~25 tests) — Test internal state transitions and implementation-specific logic (ack aggregation, round-trip counting, quiescence).

Test Infrastructure

  • BbrTest fixture with InitializeWithDefaults() — allocates a real QUIC_CONNECTION on-stack
  • MakeBbrPacket / MakeBbrAckEvent / MakeBbrLossEvent — factory helpers for input structs
  • PumpBandwidthSample — injects a bandwidth sample with controlled delivery rate
  • DriveToBtlbwFound / EnterRecovery — multi-step helpers for reaching specific BBR states
  • State enums (BBR_STATE, RECOVERY_STATE) mirrored from bbr.c for readable assertions

Assertion Policy

  • All value assertions use ASSERT_EQ with exact expected values
  • Boolean fields/functions use ASSERT_TRUE / ASSERT_FALSE
  • No weak comparisons (ASSERT_LE, ASSERT_GT, etc.)

Coverage (measured via OpenCppCoverage)

  • Lines: 480/484 (99.17%)
  • 4 uncovered lines (844, 848, 849, 850) — all inside PROBE_BW pacing gain cycle logic that depends on a random PacingCycleIndex (set via CxPlatRandom), making deterministic testing infeasible without mocking the RNG

@saikat107 saikat107 requested a review from a team as a code owner March 22, 2026 01:39
@saikat107 saikat107 changed the title Add unit tests for BBR congestion control [DeepTest] Add unit tests for BBR congestion control Mar 22, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.85%. Comparing base (0071278) to head (5b5f8b3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5887      +/-   ##
==========================================
- Coverage   86.23%   85.85%   -0.38%     
==========================================
  Files          60       60              
  Lines       18732    18732              
==========================================
- Hits        16153    16082      -71     
- Misses       2579     2650      +71     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

// Scenario: Sends 5000 bytes via OnDataSent, then triggers a loss event of 1200 bytes
// with LargestPacketNumberLost=5 and LargestSentPacketNumber=10. BBR should enter
// CONSERVATIVE recovery on the first loss event. Asserts that RecoveryState ==
// CONSERVATIVE, EndOfRecoveryValid is TRUE, and BytesInFlight decrements from
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.

nit: The comment about the assert is rather redundant, it describes exactly what the code does.
I find the sentence before describing what the test does and expect at a high level useful, but the last sentence doesn't add value.

Same for the other tests.

Settings.InitialWindowPackets = WindowPackets;
InitBbrMockConnection(Connection, Mtu);
Connection.Settings.PacingEnabled = PacingEnabled ? TRUE : FALSE;
Connection.Settings.NetStatsEventEnabled = NetStatsEnabled ? TRUE : FALSE;
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.

When NetStatsEventEnabled is true, it would be interesting to set a dummy callback and to potentially use it to validate the notification is emitted when expected.

//
// Test: GetSendAllowance - MinRtt at UINT64_MAX With Pacing
// Scenario: Initializes with PacingEnabled=TRUE. MinRtt starts at UINT64_MAX (no RTT
// sample yet). Due to BUG-1 (MinRtt compared to UINT32_MAX not UINT64_MAX), the pacing
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.

What is BUG-1? It sounds like an issue we should potentially fix, but not mention in test comments (and the test should be adapted if a fix is needed of course)

Comment on lines +156 to +164
// Helper: pump a bandwidth sample into the BBR filter via OnDataAcknowledged.
// Creates a packet metadata with HasLastAckedPacketInfo so that
// BbrBandwidthFilterOnPacketAcked computes a delivery rate.
// Returns the TimeNow used so callers can build on it.
//
//
// Pump a bandwidth sample into the BBR filter via OnDataAcknowledged.
// Constructs packet metadata so that BbrBandwidthFilterOnPacketAcked
// computes DeliveryRate = BW_UNIT * SendRate_BytesPerSec.
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.

This comment says the same thing twice.

// near zero after the helper, the DRAIN to PROBE_BW transition fires immediately.
// Asserts BtlbwFound == TRUE and BbrState == PROBE_BW.
//
TEST_F(BbrTest, OnDataAcknowledged_StartupToDrain)
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.

This test is a duplicate of the next one.
Assuming the comment is correct and the transition to PROBE_BW is due to a low number of bytes in flight, we should set it up to pretend that more bytes are in flight.

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.

2 participants