Skip to content

Commit

Permalink
Update CRMP test to wait for ack and check retransmit table (#7008)
Browse files Browse the repository at this point in the history
* Update CRMP test to wait for ack and check retransmit table

* address review comments
  • Loading branch information
pan-apple authored and pull[bot] committed Aug 31, 2021
1 parent 9882dc3 commit 1933202
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/messaging/ReliableMessageMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ void ReliableMessageMgr::ExecuteActions()
continue;

uint8_t sendCount = entry.sendCount;
uint32_t msgId = entry.retainedBuf.GetMsgId();

if (sendCount == CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS)
{
err = CHIP_ERROR_MESSAGE_NOT_ACKNOWLEDGED;

ChipLogError(ExchangeManager, "Failed to Send CHIP MsgId:%08" PRIX32 " sendCount: %" PRIu8 " max retries: %" PRIu8,
entry.retainedBuf.GetMsgId(), sendCount, CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS);
msgId, sendCount, CHIP_CONFIG_RMP_DEFAULT_MAX_RETRANS);

// Remove from Table
ClearRetransTable(entry);
Expand All @@ -155,8 +156,7 @@ void ReliableMessageMgr::ExecuteActions()
// If the retransmission was successful, update the passive timer
entry.nextRetransTimeTick = static_cast<uint16_t>(rc->GetActiveRetransmitTimeoutTick());
#if !defined(NDEBUG)
ChipLogDetail(ExchangeManager, "Retransmit MsgId:%08" PRIX32 " Send Cnt %d", entry.retainedBuf.GetMsgId(),
entry.sendCount);
ChipLogDetail(ExchangeManager, "Retransmit MsgId:%08" PRIX32 " Send Cnt %d", msgId, entry.sendCount);
#endif
}
}
Expand Down
48 changes: 35 additions & 13 deletions src/messaging/tests/TestReliableMessageProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,36 @@ TestContext sContext;

const char PAYLOAD[] = "Hello!";

int gSendMessageCount = 0;

class OutgoingTransport : public Transport::Base
{
public:
/// Transports are required to have a constructor that takes exactly one argument
CHIP_ERROR Init(const char * unused) { return CHIP_NO_ERROR; }

CHIP_ERROR SendMessage(const PeerAddress & address, System::PacketBufferHandle && msgBuf) override
{
gSendMessageCount++;
mSendMessageCount++;

if (mNumMessagesToDrop == 0)
{
System::PacketBufferHandle receivedMessage = msgBuf.CloneData();
HandleMessageReceived(address, std::move(receivedMessage));
}
else
{
mNumMessagesToDrop--;
mDroppedMessageCount++;
}

return CHIP_NO_ERROR;
}

bool CanSendToPeer(const PeerAddress & address) override { return true; }

uint32_t mNumMessagesToDrop = 0;
uint32_t mDroppedMessageCount = 0;
uint32_t mSendMessageCount = 0;
};

TransportMgr<OutgoingTransport> gTransportMgr;
TransportMgrBase gTransportMgr;
OutgoingTransport gLoopback;

class MockAppDelegate : public ExchangeDelegate
{
Expand Down Expand Up @@ -179,20 +190,32 @@ void CheckResendMessage(nlTestSuite * inSuite, void * inContext)
1, // CHIP_CONFIG_RMP_DEFAULT_ACTIVE_RETRY_INTERVAL
});

gSendMessageCount = 0;
gLoopback.mSendMessageCount = 0;
gLoopback.mNumMessagesToDrop = 2;

err = exchange->SendMessage(Echo::MsgType::EchoRequest, std::move(buffer));
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, gLoopback.mNumMessagesToDrop == 1);
NL_TEST_ASSERT(inSuite, gLoopback.mDroppedMessageCount == 1);
NL_TEST_ASSERT(inSuite, rm->TestGetCountRetransTable() == 1);

// 1 tick is 64 ms, sleep 65 ms to trigger first re-transmit
test_os_sleep_ms(65);
ReliableMessageMgr::Timeout(&ctx.GetSystemLayer(), rm, CHIP_SYSTEM_NO_ERROR);
NL_TEST_ASSERT(inSuite, gSendMessageCount == 2);
NL_TEST_ASSERT(inSuite, gLoopback.mSendMessageCount == 2);
NL_TEST_ASSERT(inSuite, gLoopback.mNumMessagesToDrop == 0);
NL_TEST_ASSERT(inSuite, gLoopback.mDroppedMessageCount == 2);
NL_TEST_ASSERT(inSuite, rm->TestGetCountRetransTable() == 1);

// sleep another 65 ms to trigger second re-transmit
test_os_sleep_ms(65);
ReliableMessageMgr::Timeout(&ctx.GetSystemLayer(), rm, CHIP_SYSTEM_NO_ERROR);
NL_TEST_ASSERT(inSuite, gSendMessageCount == 3);
NL_TEST_ASSERT(inSuite, gLoopback.mSendMessageCount >= 3);
NL_TEST_ASSERT(inSuite, gLoopback.mDroppedMessageCount == 2);

ChipLogProgress(ExchangeManager, "Checking that retransmit table is empty now");
test_os_sleep_ms(65);
NL_TEST_ASSERT(inSuite, rm->TestGetCountRetransTable() == 0);

rm->ClearRetransTable(rc);
exchange->Close();
Expand Down Expand Up @@ -257,9 +280,7 @@ int Initialize(void * aContext)
if (err != CHIP_NO_ERROR)
return FAILURE;

err = gTransportMgr.Init("LOOPBACK");
if (err != CHIP_NO_ERROR)
return FAILURE;
gTransportMgr.Init(&gLoopback);

auto * ctx = reinterpret_cast<TestContext *>(aContext);
err = ctx->Init(&sSuite, &gTransportMgr);
Expand All @@ -268,6 +289,7 @@ int Initialize(void * aContext)
return FAILURE;
}

gTransportMgr.SetSecureSessionMgr(&ctx->GetSecureSessionManager());
return SUCCESS;
}

Expand Down

0 comments on commit 1933202

Please sign in to comment.