Skip to content

Commit

Permalink
Switch CASE tests to async message delivery (#13106)
Browse files Browse the repository at this point in the history
* Switch CASE tests to LoopbackMessagingContext.

* Use async message delivery in CASE tests.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jan 4, 2022
1 parent c8c370d commit 1388084
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 37 deletions.
36 changes: 18 additions & 18 deletions src/protocols/secure_channel/tests/TestCASESession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ using namespace chip::Transport;
using namespace chip::Messaging;
using namespace chip::Protocols;

using TestContext = chip::Test::MessagingContext;
using TestContext = Test::LoopbackMessagingContext<>;

namespace {
TransportMgrBase gTransportMgr;
Test::LoopbackTransport gLoopback;
chip::Test::IOContext gIOContext;
TestContext sContext;

auto & gLoopback = sContext.GetLoopback();

FabricTable gCommissionerFabrics;
FabricIndex gCommissionerFabricIndex;
Expand Down Expand Up @@ -179,12 +179,17 @@ void CASE_SecurePairingStartTest(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite,
pairing.EstablishSession(Transport::PeerAddress(Transport::Type::kBle), nullptr, Node01_01, 0, nullptr,
nullptr) != CHIP_NO_ERROR);
ctx.DrainAndServiceIO();

NL_TEST_ASSERT(inSuite,
pairing.EstablishSession(Transport::PeerAddress(Transport::Type::kBle), fabric, Node01_01, 0, nullptr,
nullptr) != CHIP_NO_ERROR);
ctx.DrainAndServiceIO();

NL_TEST_ASSERT(inSuite,
pairing.EstablishSession(Transport::PeerAddress(Transport::Type::kBle), fabric, Node01_01, 0, context,
&delegate) == CHIP_NO_ERROR);
ctx.DrainAndServiceIO();

NL_TEST_ASSERT(inSuite, gLoopback.mSentMessageCount == 1);

Expand All @@ -205,6 +210,8 @@ void CASE_SecurePairingStartTest(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite,
pairing1.EstablishSession(Transport::PeerAddress(Transport::Type::kBle), fabric, Node01_01, 0, context1,
&delegate) == CHIP_ERROR_BAD_REQUEST);
ctx.DrainAndServiceIO();

gLoopback.mMessageSendError = CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -237,6 +244,7 @@ void CASE_SecurePairingHandshakeTestCommon(nlTestSuite * inSuite, void * inConte
NL_TEST_ASSERT(inSuite,
pairingCommissioner.EstablishSession(Transport::PeerAddress(Transport::Type::kBle), fabric, Node01_01, 0,
contextCommissioner, &delegateCommissioner) == CHIP_NO_ERROR);
ctx.DrainAndServiceIO();

NL_TEST_ASSERT(inSuite, gLoopback.mSentMessageCount == 5);
NL_TEST_ASSERT(inSuite, delegateAccessory.mNumPairingComplete == 1);
Expand Down Expand Up @@ -363,7 +371,7 @@ void CASE_SecurePairingHandshakeServerTest(nlTestSuite * inSuite, void * inConte
SessionIDAllocator idAllocator;

NL_TEST_ASSERT(inSuite,
gPairingServer.ListenForSessionEstablishment(&ctx.GetExchangeManager(), &gTransportMgr, nullptr,
gPairingServer.ListenForSessionEstablishment(&ctx.GetExchangeManager(), &ctx.GetTransportMgr(), nullptr,
&ctx.GetSecureSessionManager(), &gDeviceFabrics,
&idAllocator) == CHIP_NO_ERROR);

Expand All @@ -375,6 +383,7 @@ void CASE_SecurePairingHandshakeServerTest(nlTestSuite * inSuite, void * inConte
NL_TEST_ASSERT(inSuite,
pairingCommissioner->EstablishSession(Transport::PeerAddress(Transport::Type::kBle), fabric, Node01_01, 0,
contextCommissioner, &delegateCommissioner) == CHIP_NO_ERROR);
ctx.DrainAndServiceIO();

NL_TEST_ASSERT(inSuite, gLoopback.mSentMessageCount == 5);
NL_TEST_ASSERT(inSuite, delegateCommissioner.mNumPairingComplete == 1);
Expand All @@ -386,6 +395,7 @@ void CASE_SecurePairingHandshakeServerTest(nlTestSuite * inSuite, void * inConte
NL_TEST_ASSERT(inSuite,
pairingCommissioner1->EstablishSession(Transport::PeerAddress(Transport::Type::kBle), fabric, Node01_01, 0,
contextCommissioner1, &delegateCommissioner) == CHIP_NO_ERROR);
ctx.DrainAndServiceIO();

chip::Platform::Delete(pairingCommissioner);
chip::Platform::Delete(pairingCommissioner1);
Expand Down Expand Up @@ -637,8 +647,6 @@ static nlTestSuite sSuite =
};
// clang-format on

static TestContext sContext;

namespace {
/*
* Set up the test suite.
Expand All @@ -647,21 +655,15 @@ CHIP_ERROR CASETestSecurePairingSetup(void * inContext)
{
TestContext & ctx = *reinterpret_cast<TestContext *>(inContext);

ReturnErrorOnFailure(chip::Platform::MemoryInit());

gTransportMgr.Init(&gLoopback);
ReturnErrorOnFailure(gIOContext.Init());

ReturnErrorOnFailure(ctx.Init(&gTransportMgr, &gIOContext));
ReturnErrorOnFailure(ctx.Init());
ctx.EnableAsyncDispatch();

ctx.SetBobNodeId(kPlaceholderNodeId);
ctx.SetAliceNodeId(kPlaceholderNodeId);
ctx.SetBobKeyId(0);
ctx.SetAliceKeyId(0);
ctx.SetFabricIndex(kUndefinedFabricIndex);

gTransportMgr.SetSessionManager(&ctx.GetSecureSessionManager());

gCommissionerFabrics.Init(&gCommissionerStorageDelegate);
gDeviceFabrics.Init(&gDeviceStorageDelegate);

Expand All @@ -682,13 +684,11 @@ int CASE_TestSecurePairing_Setup(void * inContext)
*/
int CASE_TestSecurePairing_Teardown(void * inContext)
{
reinterpret_cast<TestContext *>(inContext)->Shutdown();
gIOContext.Shutdown();
gCommissionerStorageDelegate.Cleanup();
gDeviceStorageDelegate.Cleanup();
gCommissionerFabrics.Reset();
gDeviceFabrics.Reset();
chip::Platform::MemoryShutdown();
static_cast<TestContext *>(inContext)->Shutdown();
return SUCCESS;
}

Expand Down
20 changes: 1 addition & 19 deletions src/protocols/secure_channel/tests/TestCASESessionCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@

using namespace chip;

using TestContext = chip::Test::MessagingContext;

namespace {
TransportMgrBase gTransportMgr;
Test::LoopbackTransport gLoopback;
chip::Test::IOContext gIOContext;

NodeId sTest_PeerId = 0xEDEDEDED00010001;

uint8_t sTest_SharedSecret[] = {
Expand Down Expand Up @@ -197,23 +191,13 @@ static nlTestSuite sSuite =
};
// clang-format on

static TestContext sContext;

namespace {
/*
* Set up the test suite.
*/
CHIP_ERROR CASETestCacheSetup(void * inContext)
{
TestContext & ctx = *reinterpret_cast<TestContext *>(inContext);

ReturnErrorOnFailure(chip::Platform::MemoryInit());

gTransportMgr.Init(&gLoopback);
ReturnErrorOnFailure(gIOContext.Init());

ReturnErrorOnFailure(ctx.Init(&gTransportMgr, &gIOContext));

return CHIP_NO_ERROR;
}
} // anonymous namespace
Expand All @@ -231,8 +215,6 @@ int CASESessionCache_Test_Setup(void * inContext)
*/
int CASESessionCache_Test_Teardown(void * inContext)
{
reinterpret_cast<TestContext *>(inContext)->Shutdown();
gIOContext.Shutdown();
chip::Platform::MemoryShutdown();
return SUCCESS;
}
Expand All @@ -243,7 +225,7 @@ int CASESessionCache_Test_Teardown(void * inContext)
int TestCASESessionCache()
{
// Run test suit against one context
nlTestRunner(&sSuite, &sContext);
nlTestRunner(&sSuite, nullptr);

return (nlTestRunnerStats(&sSuite));
}
Expand Down

0 comments on commit 1388084

Please sign in to comment.