-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Increase unit test code coverage of ble/
by 1.9%
#39890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Th 8000 ere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request aims to increase unit test coverage for the ble/
directory by adding tests for BleLayer::NewConnectionByDiscriminators
. The changes introduce a test accessor for BleLayer
and several new test cases. While the new tests cover various scenarios like initialization failures and delegate issues, the core success and error path tests have logical flaws in how they simulate and verify callbacks. I've also pointed out a few minor issues in comments and build files. Addressing the issues in the test logic is important to ensure the BleLayer
's callback mechanism is correctly validated.
c41cbcd
to
efdcd51
Compare
src/ble/BleLayer.h
Outdated
@@ -224,7 +231,7 @@ class DLL_EXPORT BleLayer | |||
kState_NotInitialized = 0, | |||
kState_Initialized = 1, | |||
kState_Disconnecting = 2 | |||
} mState; ///< [READ-ONLY] external access is deprecated, use IsInitialized() / IsBleClosing() | |||
} mState; ///< [READ-ONLY] external access is deprecated, use () / IsBleClosing() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was the bot's (correct) comment resolved without actually resolving the issue?
src/ble/BleLayer.h
Outdated
@@ -354,6 +361,7 @@ class DLL_EXPORT BleLayer | |||
|
|||
static void OnConnectionComplete(void * appState, BLE_CONNECTION_OBJECT connObj); | |||
static void OnConnectionError(void * appState, CHIP_ERROR err); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thank you.
src/ble/tests/TestBleLayer.cpp
Outdated
|
||
// Create a list of discriminators | ||
SetupDiscriminator discriminators[] = { SetupDiscriminator(), SetupDiscriminator() }; | ||
Span<const SetupDiscriminator> discriminatorsSpan(discriminators, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Span<const SetupDiscriminator> discriminatorsSpan(discriminators, 2); | |
Span<const SetupDiscriminator> discriminatorsSpan(discriminators); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
// Checks that the connection could not be established due to an error | ||
TEST_F(TestBleLayer, NewConnectionByDiscriminatorsError) | ||
{ | ||
chip::Test::BleLayerTestAccess access(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the chip::
prefix here and elsewhere in this PR? Is this not all inside namespace chip
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The chip::
prefix here is needed, because otherwise compiler identifies Test
as pw::unit_test::internal::Test
.
src/ble/tests/TestBleLayer.cpp
Outdated
access.SetConnectionDelegate(nullptr); | ||
|
||
SetupDiscriminator discriminators[] = { SetupDiscriminator(), SetupDiscriminator() }; | ||
Span<const SetupDiscriminator> discriminatorsSpan(discriminators, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please drop the extra , 2
various places. I'll stop commenting on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review. This PR is still a draft, I'll make the changes based on your feedback.
aafb339
to
7b4f187
Compare
d19f134
to
bc25c93
Compare
PR #39890: Size comparison from 1446be8 to bc25c93 Full report (72 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
… completes succesfully
Adds a test to callback to the BLE layer to notify when a connection is complete. This change also adds a test case to verify the callback is working. - The old BleLayerAccess.h is removed - -`CallOnConnectionComplete` function is added to `BleLayerTestAccess.h` as a wrapper to `OnConnectionComplete` function of `BleLayer` to test the new callback functionality.
It tries to ensure that the connection delegate is properly set before attempting to establish a connection, preventing potential incorrect state errors.
in the test BLE layer. This allows for better verification of connection establishment success and failure scenarios.
Refactors the Ble connection success test by simplifying the OnSuccess callback invocation and adding assertions to verify the connection and error counts, ensuring more robust test coverage.
Introduces validation to handle empty discriminator Span in BLE connection logic, returning an error for invalid arguments. Adds unit tests to cover scenarios such as uninitialized states, missing connection delegates, and empty discriminator spans.
Introduces a new test to validate error handling during BLE connection establishment using discriminators.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
bc25c93
to
7893a87
Compare
PR #39890: Size comparison from bde480e to 7893a87 Full report (45 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, nrfconnect, psoc6, qpg, stm32, telink, tizen)
|
PR #39890: Size comparison from f804504 to a241cd3 Full report (72 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
@@ -383,5 +408,127 @@ TEST_F(TestBleLayer, ExceedBleConnectionEndPointLimit) | |||
EXPECT_FALSE(HandleWriteReceivedCapabilitiesRequest(connObj)); | |||
} | |||
|
|||
TEST_F(TestBleLayer, NewBleConnectionByDiscriminatorsNotInitialized) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe consider adding a comment.
EXPECT_EQ(NewBleConnectionByDiscriminators(discriminatorsSpan, this, OnSuccess, OnError), CHIP_ERROR_INCORRECT_STATE); | ||
} | ||
|
||
TEST_F(TestBleLayer, NewBleConnectionByDiscriminatorsNoConnectionDelegate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe consider adding a comment.
EXPECT_EQ(NewBleConnectionByDiscriminators(discriminatorsSpan, this, OnSuccess, OnError), CHIP_ERROR_INCORRECT_STATE); | ||
} | ||
|
||
TEST_F(TestBleLayer, NewBleConnectionByDiscriminatorsNoBleTransportLayer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe consider adding a comment.
EXPECT_EQ(NewBleConnectionByDiscriminators(discriminatorsSpan, this, OnSuccess, OnError), CHIP_ERROR_INCORRECT_STATE); | ||
} | ||
|
||
TEST_F(TestBleLayer, NewConnectionByDiscriminatorsSuccess) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe consider adding a comment.
EXPECT_EQ(mOnConnectionErrorCount, 1); | ||
} | ||
|
||
TEST_F(TestBleLayer, NewConnectionByDiscriminatorsEmptySpan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe consider adding a comment.
Summary
This PR adds comprehensive unit tests for the
BleLayer::NewConnectionByDiscriminators
method inTestBleLayer.cpp
, increasing test coverage ofble/
folder from 67.2% to 69.1%. The tests cover the following scenarios:BleLayer
BleConnectionDelegate
OnSuccess
callback)OnError
callback)Implementation Notes
BLE_LAYER_NUM_BLE_ENDPOINTS
macro being set to 1, restrictingBleLayer
to one connection at a time. MultipleOnSuccess
callback calls when multiple discriminators match cannot be tested at the moment beacuse of this endpoint limitation.BleLayerTestAccess
accessor class inBleLayerTestAccess.h
to access private membermConnectionDelegate
andOnConnectionComplete
method ofBleLayer
for testing purposes, following the testing guidelines defined in the Connected Home IP unit testing documentationOnSuccess
andOnError
callback validation is achieved through custom lambda functions implemented specifically for testing purposes to simulate connection success/failure scenarios.Related issues
Main Issue #37732
Testing
This PR only adds new unit tests. No changes made to production code.