mirror of
https://github.com/espressif/openthread.git
synced 2026-11-06 22:43:09 +00:00
[style] convert to C++11 for loops (#5263)
This commit is contained in:
+16
-16
@@ -450,9 +450,9 @@ void Interpreter::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (unsigned int i = 0; i < OT_ARRAY_LENGTH(sCommands); i++)
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
mServer->OutputFormat("%s\r\n", sCommands[i].mName);
|
||||
mServer->OutputFormat("%s\r\n", command.mName);
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < mUserCommandsLength; i++)
|
||||
@@ -876,9 +876,9 @@ void Interpreter::ProcessChild(uint8_t aArgsLength, char *aArgs[])
|
||||
mServer->OutputFormat("|%1d", childInfo.mFullNetworkData);
|
||||
mServer->OutputFormat("| ");
|
||||
|
||||
for (size_t j = 0; j < sizeof(childInfo.mExtAddress); j++)
|
||||
for (uint8_t b : childInfo.mExtAddress.m8)
|
||||
{
|
||||
mServer->OutputFormat("%02x", childInfo.mExtAddress.m8[j]);
|
||||
mServer->OutputFormat("%02x", b);
|
||||
}
|
||||
|
||||
mServer->OutputFormat(" |\r\n");
|
||||
@@ -900,9 +900,9 @@ void Interpreter::ProcessChild(uint8_t aArgsLength, char *aArgs[])
|
||||
mServer->OutputFormat("Rloc: %04x\r\n", childInfo.mRloc16);
|
||||
mServer->OutputFormat("Ext Addr: ");
|
||||
|
||||
for (size_t j = 0; j < sizeof(childInfo.mExtAddress); j++)
|
||||
for (uint8_t b : childInfo.mExtAddress.m8)
|
||||
{
|
||||
mServer->OutputFormat("%02x", childInfo.mExtAddress.m8[j]);
|
||||
mServer->OutputFormat("%02x", b);
|
||||
}
|
||||
|
||||
mServer->OutputFormat("\r\n");
|
||||
@@ -1837,9 +1837,9 @@ void Interpreter::ProcessPskc(uint8_t aArgsLength, char *aArgs[])
|
||||
{
|
||||
const otPskc *pskc = otThreadGetPskc(mInstance);
|
||||
|
||||
for (int i = 0; i < OT_PSKC_MAX_SIZE; i++)
|
||||
for (uint8_t b : pskc->m8)
|
||||
{
|
||||
mServer->OutputFormat("%02x", pskc->m8[i]);
|
||||
mServer->OutputFormat("%02x", b);
|
||||
}
|
||||
|
||||
mServer->OutputFormat("\r\n");
|
||||
@@ -2000,9 +2000,9 @@ void Interpreter::ProcessNeighbor(uint8_t aArgsLength, char *aArgs[])
|
||||
mServer->OutputFormat("|%1d", neighborInfo.mFullNetworkData);
|
||||
mServer->OutputFormat("| ");
|
||||
|
||||
for (size_t j = 0; j < sizeof(neighborInfo.mExtAddress); j++)
|
||||
for (uint8_t b : neighborInfo.mExtAddress.m8)
|
||||
{
|
||||
mServer->OutputFormat("%02x", neighborInfo.mExtAddress.m8[j]);
|
||||
mServer->OutputFormat("%02x", b);
|
||||
}
|
||||
|
||||
mServer->OutputFormat(" |\r\n");
|
||||
@@ -2321,9 +2321,9 @@ void Interpreter::ProcessParent(uint8_t aArgsLength, char *aArgs[])
|
||||
SuccessOrExit(error = otThreadGetParentInfo(mInstance, &parentInfo));
|
||||
mServer->OutputFormat("Ext Addr: ");
|
||||
|
||||
for (size_t i = 0; i < sizeof(parentInfo.mExtAddress); i++)
|
||||
for (uint8_t b : parentInfo.mExtAddress.m8)
|
||||
{
|
||||
mServer->OutputFormat("%02x", parentInfo.mExtAddress.m8[i]);
|
||||
mServer->OutputFormat("%02x", b);
|
||||
}
|
||||
|
||||
mServer->OutputFormat("\r\n");
|
||||
@@ -3163,9 +3163,9 @@ void Interpreter::ProcessRouter(uint8_t aArgsLength, char *aArgs[])
|
||||
mServer->OutputFormat("| %3d ", routerInfo.mAge);
|
||||
mServer->OutputFormat("| ");
|
||||
|
||||
for (size_t j = 0; j < sizeof(routerInfo.mExtAddress); j++)
|
||||
for (uint8_t b : routerInfo.mExtAddress.m8)
|
||||
{
|
||||
mServer->OutputFormat("%02x", routerInfo.mExtAddress.m8[j]);
|
||||
mServer->OutputFormat("%02x", b);
|
||||
}
|
||||
|
||||
mServer->OutputFormat(" |\r\n");
|
||||
@@ -3196,9 +3196,9 @@ void Interpreter::ProcessRouter(uint8_t aArgsLength, char *aArgs[])
|
||||
{
|
||||
mServer->OutputFormat("Ext Addr: ");
|
||||
|
||||
for (size_t j = 0; j < sizeof(routerInfo.mExtAddress); j++)
|
||||
for (uint8_t b : routerInfo.mExtAddress.m8)
|
||||
{
|
||||
mServer->OutputFormat("%02x", routerInfo.mExtAddress.m8[j]);
|
||||
mServer->OutputFormat("%02x", b);
|
||||
}
|
||||
|
||||
mServer->OutputFormat("\r\n");
|
||||
|
||||
@@ -173,9 +173,9 @@ otError Coap::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(sCommands); i++)
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
mInterpreter.mServer->OutputFormat("%s\r\n", sCommands[i].mName);
|
||||
mInterpreter.mServer->OutputFormat("%s\r\n", command.mName);
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
@@ -523,11 +523,11 @@ otError Coap::Process(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(sCommands); i++)
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
if (strcmp(aArgs[0], sCommands[i].mName) == 0)
|
||||
if (strcmp(aArgs[0], command.mName) == 0)
|
||||
{
|
||||
error = (this->*sCommands[i].mCommand)(aArgsLength, aArgs);
|
||||
error = (this->*command.mCommand)(aArgsLength, aArgs);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,9 +106,9 @@ otError CoapSecure::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(sCommands); i++)
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
mInterpreter.mServer->OutputFormat("%s\r\n", sCommands[i].mName);
|
||||
mInterpreter.mServer->OutputFormat("%s\r\n", command.mName);
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
@@ -420,11 +420,11 @@ otError CoapSecure::Process(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(sCommands); i++)
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
if (strcmp(aArgs[0], sCommands[i].mName) == 0)
|
||||
if (strcmp(aArgs[0], command.mName) == 0)
|
||||
{
|
||||
error = (this->*sCommands[i].mCommand)(aArgsLength, aArgs);
|
||||
error = (this->*command.mCommand)(aArgsLength, aArgs);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@ otError Commissioner::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(sCommands); i++)
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
mInterpreter.mServer->OutputFormat("%s\r\n", sCommands[i].mName);
|
||||
mInterpreter.mServer->OutputFormat("%s\r\n", command.mName);
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
@@ -406,11 +406,11 @@ otError Commissioner::Process(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(sCommands); i++)
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
if (strcmp(aArgs[0], sCommands[i].mName) == 0)
|
||||
if (strcmp(aArgs[0], command.mName) == 0)
|
||||
{
|
||||
error = (this->*sCommands[i].mCommand)(aArgsLength, aArgs);
|
||||
error = (this->*command.mCommand)(aArgsLength, aArgs);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,11 +192,11 @@ otError Dataset::Process(uint8_t aArgsLength, char *aArgs[])
|
||||
ExitNow(error = Print(sDataset));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(sCommands); i++)
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
if (strcmp(aArgs[0], sCommands[i].mName) == 0)
|
||||
if (strcmp(aArgs[0], command.mName) == 0)
|
||||
{
|
||||
error = (this->*sCommands[i].mCommand)(aArgsLength - 1, aArgs + 1);
|
||||
error = (this->*command.mCommand)(aArgsLength - 1, aArgs + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -210,9 +210,9 @@ otError Dataset::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(sCommands); i++)
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
mInterpreter.mServer->OutputFormat("%s\r\n", sCommands[i].mName);
|
||||
mInterpreter.mServer->OutputFormat("%s\r\n", command.mName);
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
|
||||
@@ -53,9 +53,9 @@ otError Joiner::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(sCommands); i++)
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
mInterpreter.mServer->OutputFormat("%s\r\n", sCommands[i].mName);
|
||||
mInterpreter.mServer->OutputFormat("%s\r\n", command.mName);
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
@@ -115,11 +115,11 @@ otError Joiner::Process(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(sCommands); i++)
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
if (strcmp(aArgs[0], sCommands[i].mName) == 0)
|
||||
if (strcmp(aArgs[0], command.mName) == 0)
|
||||
{
|
||||
error = (this->*sCommands[i].mCommand)(aArgsLength, aArgs);
|
||||
error = (this->*command.mCommand)(aArgsLength, aArgs);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -60,9 +60,9 @@ otError UdpExample::ProcessHelp(uint8_t aArgsLength, char *aArgs[])
|
||||
OT_UNUSED_VARIABLE(aArgsLength);
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(sCommands); i++)
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
mInterpreter.mServer->OutputFormat("%s\r\n", sCommands[i].mName);
|
||||
mInterpreter.mServer->OutputFormat("%s\r\n", command.mName);
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
@@ -269,11 +269,11 @@ otError UdpExample::Process(uint8_t aArgsLength, char *aArgs[])
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(sCommands); i++)
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
if (strcmp(aArgs[0], sCommands[i].mName) == 0)
|
||||
if (strcmp(aArgs[0], command.mName) == 0)
|
||||
{
|
||||
error = (this->*sCommands[i].mCommand)(aArgsLength - 1, aArgs + 1);
|
||||
error = (this->*command.mCommand)(aArgsLength - 1, aArgs + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -840,9 +840,9 @@ void MessageQueue::GetInfo(uint16_t &aMessageCount, uint16_t &aBufferCount) cons
|
||||
|
||||
PriorityQueue::PriorityQueue(void)
|
||||
{
|
||||
for (int priority = 0; priority < Message::kNumPriorities; priority++)
|
||||
for (Message *&tail : mTails)
|
||||
{
|
||||
mTails[priority] = nullptr;
|
||||
tail = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,10 +54,10 @@ Notifier::Notifier(Instance &aInstance)
|
||||
, mTask(aInstance, Notifier::EmitEvents, this)
|
||||
, mReceivers()
|
||||
{
|
||||
for (unsigned int i = 0; i < kMaxExternalHandlers; i++)
|
||||
for (ExternalCallback &callback : mExternalCallbacks)
|
||||
{
|
||||
mExternalCallbacks[i].mHandler = nullptr;
|
||||
mExternalCallbacks[i].mContext = nullptr;
|
||||
callback.mHandler = nullptr;
|
||||
callback.mContext = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,10 +73,8 @@ otError Notifier::RegisterCallback(otStateChangedCallback aCallback, void *aCont
|
||||
|
||||
VerifyOrExit(aCallback != nullptr, OT_NOOP);
|
||||
|
||||
for (unsigned int i = 0; i < kMaxExternalHandlers; i++)
|
||||
for (ExternalCallback &callback : mExternalCallbacks)
|
||||
{
|
||||
ExternalCallback &callback = mExternalCallbacks[i];
|
||||
|
||||
if (callback.mHandler == nullptr)
|
||||
{
|
||||
if (unusedCallback == nullptr)
|
||||
@@ -103,10 +101,8 @@ void Notifier::RemoveCallback(otStateChangedCallback aCallback, void *aContext)
|
||||
{
|
||||
VerifyOrExit(aCallback != nullptr, OT_NOOP);
|
||||
|
||||
for (unsigned int i = 0; i < kMaxExternalHandlers; i++)
|
||||
for (ExternalCallback &callback : mExternalCallbacks)
|
||||
{
|
||||
ExternalCallback &callback = mExternalCallbacks[i];
|
||||
|
||||
if ((callback.mHandler == aCallback) && (callback.mContext == aContext))
|
||||
{
|
||||
callback.mHandler = nullptr;
|
||||
@@ -157,10 +153,8 @@ void Notifier::EmitEvents(void)
|
||||
receiver->Emit(events);
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < kMaxExternalHandlers; i++)
|
||||
for (ExternalCallback &callback : mExternalCallbacks)
|
||||
{
|
||||
ExternalCallback &callback = mExternalCallbacks[i];
|
||||
|
||||
if (callback.mHandler != nullptr)
|
||||
{
|
||||
callback.mHandler(events.GetAsFlags(), callback.mContext);
|
||||
|
||||
@@ -577,12 +577,12 @@ otError Diags::ProcessCmd(uint8_t aArgsLength, char *aArgs[], char *aOutput, siz
|
||||
aOutput[0] = '\0';
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(sCommands); i++)
|
||||
for (const Command &command : sCommands)
|
||||
{
|
||||
if (strcmp(aArgs[0], sCommands[i].mName) == 0)
|
||||
if (strcmp(aArgs[0], command.mName) == 0)
|
||||
{
|
||||
error = (this->*sCommands[i].mCommand)(aArgsLength - 1, (aArgsLength > 1) ? &aArgs[1] : nullptr, aOutput,
|
||||
aOutputMaxLen);
|
||||
error = (this->*command.mCommand)(aArgsLength - 1, (aArgsLength > 1) ? &aArgs[1] : nullptr, aOutput,
|
||||
aOutputMaxLen);
|
||||
ExitNow();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,10 +247,10 @@ void SteeringData::CalculateHashBitIndexes(const Mac::ExtAddress &aJoinerId, Has
|
||||
Crc16 ccitt(Crc16::kCcitt);
|
||||
Crc16 ansi(Crc16::kAnsi);
|
||||
|
||||
for (uint8_t i = 0; i < sizeof(Mac::ExtAddress); i++)
|
||||
for (uint8_t b : aJoinerId.m8)
|
||||
{
|
||||
ccitt.Update(aJoinerId.m8[i]);
|
||||
ansi.Update(aJoinerId.m8[i]);
|
||||
ccitt.Update(b);
|
||||
ansi.Update(b);
|
||||
}
|
||||
|
||||
aIndexes.mIndex[0] = ccitt.Get();
|
||||
|
||||
@@ -76,11 +76,9 @@ void Dhcp6Client::UpdateAddresses(void)
|
||||
NetworkData::OnMeshPrefixConfig config;
|
||||
|
||||
// remove addresses directly if prefix not valid in network data
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(mIdentityAssociations); i++)
|
||||
for (IdentityAssociation &idAssociation : mIdentityAssociations)
|
||||
{
|
||||
IdentityAssociation &ia = mIdentityAssociations[i];
|
||||
|
||||
if (ia.mStatus == kIaStatusInvalid || ia.mValidLifetime == 0)
|
||||
if (idAssociation.mStatus == kIaStatusInvalid || idAssociation.mValidLifetime == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -95,7 +93,7 @@ void Dhcp6Client::UpdateAddresses(void)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (MatchNetifAddressWithPrefix(ia.mNetifAddress, config.mPrefix))
|
||||
if (MatchNetifAddressWithPrefix(idAssociation.mNetifAddress, config.mPrefix))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
@@ -104,8 +102,8 @@ void Dhcp6Client::UpdateAddresses(void)
|
||||
|
||||
if (!found)
|
||||
{
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(ia.mNetifAddress);
|
||||
mIdentityAssociations[i].mStatus = kIaStatusInvalid;
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(idAssociation.mNetifAddress);
|
||||
idAssociation.mStatus = kIaStatusInvalid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +112,7 @@ void Dhcp6Client::UpdateAddresses(void)
|
||||
|
||||
while (Get<NetworkData::Leader>().GetNextOnMeshPrefix(iterator, config) == OT_ERROR_NONE)
|
||||
{
|
||||
IdentityAssociation *ia = nullptr;
|
||||
IdentityAssociation *idAssociation = nullptr;
|
||||
|
||||
if (!config.mDhcp)
|
||||
{
|
||||
@@ -124,32 +122,32 @@ void Dhcp6Client::UpdateAddresses(void)
|
||||
doesAgentExist = true;
|
||||
found = false;
|
||||
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(mIdentityAssociations); i++)
|
||||
for (IdentityAssociation &ia : mIdentityAssociations)
|
||||
{
|
||||
if (mIdentityAssociations[i].mStatus == kIaStatusInvalid)
|
||||
if (ia.mStatus == kIaStatusInvalid)
|
||||
{
|
||||
// record an available ia
|
||||
if (ia == nullptr)
|
||||
// record an available IdentityAssociation
|
||||
if (idAssociation == nullptr)
|
||||
{
|
||||
ia = &mIdentityAssociations[i];
|
||||
idAssociation = &ia;
|
||||
}
|
||||
}
|
||||
else if (MatchNetifAddressWithPrefix(mIdentityAssociations[i].mNetifAddress, config.mPrefix))
|
||||
else if (MatchNetifAddressWithPrefix(ia.mNetifAddress, config.mPrefix))
|
||||
{
|
||||
found = true;
|
||||
ia = &mIdentityAssociations[i];
|
||||
found = true;
|
||||
idAssociation = &ia;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
if (ia != nullptr)
|
||||
if (idAssociation != nullptr)
|
||||
{
|
||||
ia->mNetifAddress.mAddress = config.mPrefix.mPrefix;
|
||||
ia->mNetifAddress.mPrefixLength = config.mPrefix.mLength;
|
||||
ia->mStatus = kIaStatusSolicit;
|
||||
ia->mValidLifetime = 0;
|
||||
idAssociation->mNetifAddress.mAddress = config.mPrefix.mPrefix;
|
||||
idAssociation->mNetifAddress.mPrefixLength = config.mPrefix.mLength;
|
||||
idAssociation->mStatus = kIaStatusSolicit;
|
||||
idAssociation->mValidLifetime = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -158,7 +156,7 @@ void Dhcp6Client::UpdateAddresses(void)
|
||||
}
|
||||
}
|
||||
|
||||
ia->mPrefixAgentRloc = config.mRloc16;
|
||||
idAssociation->mPrefixAgentRloc = config.mRloc16;
|
||||
}
|
||||
|
||||
if (doesAgentExist)
|
||||
@@ -202,9 +200,9 @@ bool Dhcp6Client::ProcessNextIdentityAssociation()
|
||||
|
||||
mTrickleTimer.Stop();
|
||||
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(mIdentityAssociations); ++i)
|
||||
for (IdentityAssociation &idAssociation : mIdentityAssociations)
|
||||
{
|
||||
if (mIdentityAssociations[i].mStatus != kIaStatusSolicit)
|
||||
if (idAssociation.mStatus != kIaStatusSolicit)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -212,7 +210,7 @@ bool Dhcp6Client::ProcessNextIdentityAssociation()
|
||||
// new transaction id
|
||||
IgnoreError(Random::Crypto::FillBuffer(mTransactionId, kTransactionIdSize));
|
||||
|
||||
mIdentityAssociationCurrent = &mIdentityAssociations[i];
|
||||
mIdentityAssociationCurrent = &idAssociation;
|
||||
|
||||
mTrickleTimer.Start(Time::SecToMsec(kTrickleTimerImin), Time::SecToMsec(kTrickleTimerImax),
|
||||
TrickleTimer::kModeNormal);
|
||||
@@ -352,15 +350,14 @@ otError Dhcp6Client::AppendIaNa(Message &aMessage, uint16_t aRloc16)
|
||||
|
||||
VerifyOrExit(mIdentityAssociationCurrent != nullptr, error = OT_ERROR_DROP);
|
||||
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(mIdentityAssociations); ++i)
|
||||
for (IdentityAssociation &idAssociation : mIdentityAssociations)
|
||||
{
|
||||
if (mIdentityAssociations[i].mStatus == kIaStatusInvalid ||
|
||||
mIdentityAssociations[i].mStatus == kIaStatusSolicitReplied)
|
||||
if (idAssociation.mStatus == kIaStatusInvalid || idAssociation.mStatus == kIaStatusSolicitReplied)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mIdentityAssociations[i].mPrefixAgentRloc == aRloc16)
|
||||
if (idAssociation.mPrefixAgentRloc == aRloc16)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
@@ -389,13 +386,12 @@ otError Dhcp6Client::AppendIaAddress(Message &aMessage, uint16_t aRloc16)
|
||||
|
||||
option.Init();
|
||||
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(mIdentityAssociations); ++i)
|
||||
for (IdentityAssociation &idAssociation : mIdentityAssociations)
|
||||
{
|
||||
if ((mIdentityAssociations[i].mStatus == kIaStatusSolicit ||
|
||||
mIdentityAssociations[i].mStatus == kIaStatusSoliciting) &&
|
||||
(mIdentityAssociations[i].mPrefixAgentRloc == aRloc16))
|
||||
if ((idAssociation.mStatus == kIaStatusSolicit || idAssociation.mStatus == kIaStatusSoliciting) &&
|
||||
(idAssociation.mPrefixAgentRloc == aRloc16))
|
||||
{
|
||||
option.SetAddress(mIdentityAssociations[i].mNetifAddress.mAddress);
|
||||
option.SetAddress(idAssociation.mNetifAddress.mAddress);
|
||||
option.SetPreferredLifetime(0);
|
||||
option.SetValidLifetime(0);
|
||||
SuccessOrExit(error = aMessage.Append(&option, sizeof(option)));
|
||||
@@ -582,25 +578,24 @@ otError Dhcp6Client::ProcessIaAddress(Message &aMessage, uint16_t aOffset)
|
||||
(option.GetLength() == (sizeof(option) - sizeof(Dhcp6Option)))),
|
||||
error = OT_ERROR_PARSE);
|
||||
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(mIdentityAssociations); ++i)
|
||||
for (IdentityAssociation &idAssociation : mIdentityAssociations)
|
||||
{
|
||||
IdentityAssociation &ia = mIdentityAssociations[i];
|
||||
|
||||
if (ia.mStatus == kIaStatusInvalid || ia.mValidLifetime != 0)
|
||||
if (idAssociation.mStatus == kIaStatusInvalid || idAssociation.mValidLifetime != 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ia.mNetifAddress.GetAddress().PrefixMatch(option.GetAddress()) >= ia.mNetifAddress.mPrefixLength)
|
||||
if (idAssociation.mNetifAddress.GetAddress().PrefixMatch(option.GetAddress()) >=
|
||||
idAssociation.mNetifAddress.mPrefixLength)
|
||||
{
|
||||
mIdentityAssociations[i].mNetifAddress.mAddress = option.GetAddress();
|
||||
mIdentityAssociations[i].mPreferredLifetime = option.GetPreferredLifetime();
|
||||
mIdentityAssociations[i].mValidLifetime = option.GetValidLifetime();
|
||||
mIdentityAssociations[i].mNetifAddress.mAddressOrigin = OT_ADDRESS_ORIGIN_DHCPV6;
|
||||
mIdentityAssociations[i].mNetifAddress.mPreferred = option.GetPreferredLifetime() != 0;
|
||||
mIdentityAssociations[i].mNetifAddress.mValid = option.GetValidLifetime() != 0;
|
||||
mIdentityAssociations[i].mStatus = kIaStatusSolicitReplied;
|
||||
Get<ThreadNetif>().AddUnicastAddress(ia.mNetifAddress);
|
||||
idAssociation.mNetifAddress.mAddress = option.GetAddress();
|
||||
idAssociation.mPreferredLifetime = option.GetPreferredLifetime();
|
||||
idAssociation.mValidLifetime = option.GetValidLifetime();
|
||||
idAssociation.mNetifAddress.mAddressOrigin = OT_ADDRESS_ORIGIN_DHCPV6;
|
||||
idAssociation.mNetifAddress.mPreferred = option.GetPreferredLifetime() != 0;
|
||||
idAssociation.mNetifAddress.mValid = option.GetValidLifetime() != 0;
|
||||
idAssociation.mStatus = kIaStatusSolicitReplied;
|
||||
Get<ThreadNetif>().AddUnicastAddress(idAssociation.mNetifAddress);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,11 +64,11 @@ otError Dhcp6Server::UpdateService(void)
|
||||
Lowpan::Context lowpanContext;
|
||||
|
||||
// remove dhcp agent aloc and prefix delegation
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++)
|
||||
for (PrefixAgent &prefixAgent : mPrefixAgents)
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
if (!mPrefixAgents[i].IsValid())
|
||||
if (!prefixAgent.IsValid())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -82,9 +82,9 @@ otError Dhcp6Server::UpdateService(void)
|
||||
continue;
|
||||
}
|
||||
|
||||
error = Get<NetworkData::Leader>().GetContext(mPrefixAgents[i].GetPrefix(), lowpanContext);
|
||||
error = Get<NetworkData::Leader>().GetContext(prefixAgent.GetPrefix(), lowpanContext);
|
||||
|
||||
if ((error == OT_ERROR_NONE) && (mPrefixAgents[i].GetContextId() == lowpanContext.mContextId))
|
||||
if ((error == OT_ERROR_NONE) && (prefixAgent.GetContextId() == lowpanContext.mContextId))
|
||||
{
|
||||
// still in network data
|
||||
found = true;
|
||||
@@ -94,7 +94,7 @@ otError Dhcp6Server::UpdateService(void)
|
||||
|
||||
if (!found)
|
||||
{
|
||||
mPrefixAgents[i].Clear();
|
||||
prefixAgent.Clear();
|
||||
mPrefixAgentsCount--;
|
||||
}
|
||||
}
|
||||
@@ -149,13 +149,13 @@ void Dhcp6Server::AddPrefixAgent(const otIp6Prefix &aIp6Prefix, const Lowpan::Co
|
||||
otError error = OT_ERROR_NONE;
|
||||
PrefixAgent *newEntry = nullptr;
|
||||
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++)
|
||||
for (PrefixAgent &prefixAgent : mPrefixAgents)
|
||||
{
|
||||
if (!mPrefixAgents[i].IsValid())
|
||||
if (!prefixAgent.IsValid())
|
||||
{
|
||||
newEntry = &mPrefixAgents[i];
|
||||
newEntry = &prefixAgent;
|
||||
}
|
||||
else if (mPrefixAgents[i].IsPrefixMatch(aIp6Prefix))
|
||||
else if (prefixAgent.IsPrefixMatch(aIp6Prefix))
|
||||
{
|
||||
// already added
|
||||
ExitNow();
|
||||
@@ -449,11 +449,11 @@ otError Dhcp6Server::AppendIaAddress(Message &aMessage, ClientIdentifier &aClien
|
||||
else
|
||||
{
|
||||
// if not specified, apply all configured prefixes
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++)
|
||||
for (const PrefixAgent &prefixAgent : mPrefixAgents)
|
||||
{
|
||||
if (mPrefixAgents[i].IsValid())
|
||||
if (prefixAgent.IsValid())
|
||||
{
|
||||
SuccessOrExit(error = AddIaAddress(aMessage, mPrefixAgents[i].GetPrefix(), aClientId));
|
||||
SuccessOrExit(error = AddIaAddress(aMessage, prefixAgent.GetPrefix(), aClientId));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -489,11 +489,11 @@ otError Dhcp6Server::AppendRapidCommit(Message &aMessage)
|
||||
|
||||
void Dhcp6Server::ApplyMeshLocalPrefix(void)
|
||||
{
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++)
|
||||
for (PrefixAgent &prefixAgent : mPrefixAgents)
|
||||
{
|
||||
if (mPrefixAgents[i].IsValid())
|
||||
if (prefixAgent.IsValid())
|
||||
{
|
||||
PrefixAgent *entry = &mPrefixAgents[i];
|
||||
PrefixAgent *entry = &prefixAgent;
|
||||
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(entry->GetAloc());
|
||||
entry->GetAloc().GetAddress().SetPrefix(Get<Mle::MleRouter>().GetMeshLocalPrefix());
|
||||
|
||||
@@ -108,9 +108,9 @@ bool Filter::Accept(Message &aMessage) const
|
||||
}
|
||||
|
||||
// Check against allowed unsecure port list
|
||||
for (int i = 0; i < kMaxUnsecurePorts; i++)
|
||||
for (uint16_t unsecurePort : mUnsecurePorts)
|
||||
{
|
||||
if (mUnsecurePorts[i] != 0 && mUnsecurePorts[i] == dstport)
|
||||
if (unsecurePort != 0 && unsecurePort == dstport)
|
||||
{
|
||||
ExitNow(rval = true);
|
||||
}
|
||||
@@ -126,19 +126,19 @@ otError Filter::AddUnsecurePort(uint16_t aPort)
|
||||
|
||||
VerifyOrExit(aPort != 0, error = OT_ERROR_INVALID_ARGS);
|
||||
|
||||
for (int i = 0; i < kMaxUnsecurePorts; i++)
|
||||
for (uint16_t unsecurePort : mUnsecurePorts)
|
||||
{
|
||||
if (mUnsecurePorts[i] == aPort)
|
||||
if (unsecurePort == aPort)
|
||||
{
|
||||
ExitNow();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < kMaxUnsecurePorts; i++)
|
||||
for (uint16_t &unsecurePort : mUnsecurePorts)
|
||||
{
|
||||
if (mUnsecurePorts[i] == 0)
|
||||
if (unsecurePort == 0)
|
||||
{
|
||||
mUnsecurePorts[i] = aPort;
|
||||
unsecurePort = aPort;
|
||||
otLogInfoIp6("Added unsecure port %d", aPort);
|
||||
ExitNow();
|
||||
}
|
||||
@@ -184,9 +184,9 @@ bool Filter::IsUnsecurePort(uint16_t aPort)
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
for (int i = 0; i < kMaxUnsecurePorts; i++)
|
||||
for (uint16_t unsecurePort : mUnsecurePorts)
|
||||
{
|
||||
if (mUnsecurePorts[i] == aPort)
|
||||
if (unsecurePort == aPort)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
|
||||
@@ -77,10 +77,9 @@ void AddressResolver::Clear(void)
|
||||
{
|
||||
CacheEntryList *lists[] = {&mCachedList, &mSnoopedList, &mQueryList, &mQueryRetryList};
|
||||
|
||||
for (size_t index = 0; index < OT_ARRAY_LENGTH(lists); index++)
|
||||
for (CacheEntryList *list : lists)
|
||||
{
|
||||
CacheEntryList *list = lists[index];
|
||||
CacheEntry * entry;
|
||||
CacheEntry *entry;
|
||||
|
||||
while ((entry = list->Pop()) != nullptr)
|
||||
{
|
||||
@@ -193,11 +192,10 @@ void AddressResolver::Remove(Mac::ShortAddress aRloc16, bool aMatchRouterId)
|
||||
{
|
||||
CacheEntryList *lists[] = {&mCachedList, &mSnoopedList};
|
||||
|
||||
for (size_t index = 0; index < OT_ARRAY_LENGTH(lists); index++)
|
||||
for (CacheEntryList *list : lists)
|
||||
{
|
||||
CacheEntryList *list = lists[index];
|
||||
CacheEntry * prev = nullptr;
|
||||
CacheEntry * entry;
|
||||
CacheEntry *prev = nullptr;
|
||||
CacheEntry *entry;
|
||||
|
||||
while ((entry = GetEntryAfter(prev, *list)) != nullptr)
|
||||
{
|
||||
@@ -225,9 +223,9 @@ AddressResolver::CacheEntry *AddressResolver::FindCacheEntry(const Ip6::Address
|
||||
CacheEntry * entry = nullptr;
|
||||
CacheEntryList *lists[] = {&mCachedList, &mSnoopedList, &mQueryList, &mQueryRetryList};
|
||||
|
||||
for (size_t index = 0; index < OT_ARRAY_LENGTH(lists); index++)
|
||||
for (CacheEntryList *list : lists)
|
||||
{
|
||||
aList = lists[index];
|
||||
aList = list;
|
||||
entry = aList->FindMatching(aEid, aPrevEntry);
|
||||
VerifyOrExit(entry == nullptr, OT_NOOP);
|
||||
}
|
||||
@@ -277,12 +275,11 @@ AddressResolver::CacheEntry *AddressResolver::NewCacheEntry(bool aSnoopedEntry)
|
||||
newEntry = mCacheEntryPool.Allocate();
|
||||
VerifyOrExit(newEntry == nullptr, OT_NOOP);
|
||||
|
||||
for (size_t index = 0; index < OT_ARRAY_LENGTH(lists); index++)
|
||||
for (CacheEntryList *list : lists)
|
||||
{
|
||||
CacheEntryList *list = lists[index];
|
||||
CacheEntry * prev;
|
||||
CacheEntry * entry;
|
||||
uint16_t numNonEvictable = 0;
|
||||
CacheEntry *prev;
|
||||
CacheEntry *entry;
|
||||
uint16_t numNonEvictable = 0;
|
||||
|
||||
for (prev = nullptr; (entry = GetEntryAfter(prev, *list)) != nullptr; prev = entry)
|
||||
{
|
||||
|
||||
@@ -111,9 +111,9 @@ public:
|
||||
{
|
||||
bool rval = false;
|
||||
|
||||
for (size_t i = 0; i < sizeof(mMask); i++)
|
||||
for (uint8_t b : mMask)
|
||||
{
|
||||
if (mMask[i] != 0)
|
||||
if (b != 0)
|
||||
{
|
||||
ExitNow(rval = true);
|
||||
}
|
||||
|
||||
@@ -182,12 +182,12 @@ otError MeshForwarder::EvictMessage(Message::Priority aPriority)
|
||||
Message * evict = nullptr;
|
||||
|
||||
// search for a lower priority message to evict (choose lowest priority message among all queues)
|
||||
for (uint8_t index = 0; index < OT_ARRAY_LENGTH(queues); index++)
|
||||
for (PriorityQueue *queue : queues)
|
||||
{
|
||||
for (uint8_t priority = 0; priority < aPriority; priority++)
|
||||
{
|
||||
for (Message *message = queues[index]->GetHeadForPriority(static_cast<Message::Priority>(priority));
|
||||
message; message = message->GetNext())
|
||||
for (Message *message = queue->GetHeadForPriority(static_cast<Message::Priority>(priority)); message;
|
||||
message = message->GetNext())
|
||||
{
|
||||
if (message->GetPriority() != priority)
|
||||
{
|
||||
|
||||
+14
-14
@@ -140,16 +140,16 @@ Mle::Mle(Instance &aInstance)
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
|
||||
// Service Alocs
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(mServiceAlocs); i++)
|
||||
for (Ip6::NetifUnicastAddress &serviceAloc : mServiceAlocs)
|
||||
{
|
||||
mServiceAlocs[i].Clear();
|
||||
mServiceAlocs[i].mPrefixLength = MeshLocalPrefix::kLength;
|
||||
mServiceAlocs[i].mAddressOrigin = OT_ADDRESS_ORIGIN_THREAD;
|
||||
mServiceAlocs[i].mPreferred = true;
|
||||
mServiceAlocs[i].mValid = true;
|
||||
mServiceAlocs[i].mScopeOverride = Ip6::Address::kRealmLocalScope;
|
||||
mServiceAlocs[i].mScopeOverrideValid = true;
|
||||
mServiceAlocs[i].GetAddress().GetIid().SetLocator(Mac::kShortAddrInvalid);
|
||||
serviceAloc.Clear();
|
||||
serviceAloc.mPrefixLength = MeshLocalPrefix::kLength;
|
||||
serviceAloc.mAddressOrigin = OT_ADDRESS_ORIGIN_THREAD;
|
||||
serviceAloc.mPreferred = true;
|
||||
serviceAloc.mValid = true;
|
||||
serviceAloc.mScopeOverride = Ip6::Address::kRealmLocalScope;
|
||||
serviceAloc.mScopeOverrideValid = true;
|
||||
serviceAloc.GetAddress().GetIid().SetLocator(Mac::kShortAddrInvalid);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -887,13 +887,13 @@ void Mle::ApplyMeshLocalPrefix(void)
|
||||
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(mServiceAlocs); i++)
|
||||
for (Ip6::NetifUnicastAddress &serviceAloc : mServiceAlocs)
|
||||
{
|
||||
if (mServiceAlocs[i].GetAddress().GetIid().GetLocator() != Mac::kShortAddrInvalid)
|
||||
if (serviceAloc.GetAddress().GetIid().GetLocator() != Mac::kShortAddrInvalid)
|
||||
{
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(mServiceAlocs[i]);
|
||||
mServiceAlocs[i].GetAddress().SetPrefix(GetMeshLocalPrefix());
|
||||
Get<ThreadNetif>().AddUnicastAddress(mServiceAlocs[i]);
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(serviceAloc);
|
||||
serviceAloc.GetAddress().SetPrefix(GetMeshLocalPrefix());
|
||||
Get<ThreadNetif>().AddUnicastAddress(serviceAloc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -176,15 +176,15 @@ otError Child::AddIp6Address(const Ip6::Address &aAddress)
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
for (uint16_t index = 0; index < kNumIp6Addresses; index++)
|
||||
for (Ip6::Address &ip6Address : mIp6Address)
|
||||
{
|
||||
if (mIp6Address[index].IsUnspecified())
|
||||
if (ip6Address.IsUnspecified())
|
||||
{
|
||||
mIp6Address[index] = aAddress;
|
||||
ip6Address = aAddress;
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
VerifyOrExit(mIp6Address[index] != aAddress, error = OT_ERROR_ALREADY);
|
||||
VerifyOrExit(ip6Address != aAddress, error = OT_ERROR_ALREADY);
|
||||
}
|
||||
|
||||
error = OT_ERROR_NO_BUFS;
|
||||
@@ -247,11 +247,11 @@ bool Child::HasIp6Address(const Ip6::Address &aAddress) const
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
for (uint16_t index = 0; index < kNumIp6Addresses; index++)
|
||||
for (const Ip6::Address &ip6Address : mIp6Address)
|
||||
{
|
||||
VerifyOrExit(!mIp6Address[index].IsUnspecified(), OT_NOOP);
|
||||
VerifyOrExit(!ip6Address.IsUnspecified(), OT_NOOP);
|
||||
|
||||
if (mIp6Address[index] == aAddress)
|
||||
if (ip6Address == aAddress)
|
||||
{
|
||||
ExitNow(retval = true);
|
||||
}
|
||||
|
||||
@@ -193,9 +193,9 @@ void ChannelMonitor::LogResults(void)
|
||||
const size_t kStringSize = 128;
|
||||
String<kStringSize> logString;
|
||||
|
||||
for (size_t i = 0; i < kNumChannels; i++)
|
||||
for (uint16_t channel : mChannelOccupancy)
|
||||
{
|
||||
IgnoreError(logString.Append("%02x ", mChannelOccupancy[i] >> 8));
|
||||
IgnoreError(logString.Append("%02x ", channel >> 8));
|
||||
}
|
||||
|
||||
otLogInfoUtil("ChannelMonitor: %u [%s]", mSampleCount, logString.AsCString());
|
||||
|
||||
@@ -46,9 +46,9 @@ Buffer::Buffer(uint8_t *aBuffer, uint16_t aBufferLength)
|
||||
, mBufferLength(aBufferLength)
|
||||
{
|
||||
#if OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
|
||||
for (uint8_t priority = 0; priority < kNumPrios; priority++)
|
||||
for (otMessageQueue &queue : mMessageQueue)
|
||||
{
|
||||
otMessageQueueInit(&mMessageQueue[priority]);
|
||||
otMessageQueueInit(&queue);
|
||||
}
|
||||
|
||||
otMessageQueueInit(&mWriteFrameMessageQueue);
|
||||
@@ -100,11 +100,11 @@ void Buffer::Clear(void)
|
||||
// be freed.
|
||||
}
|
||||
|
||||
for (uint8_t priority = 0; priority < kNumPrios; priority++)
|
||||
for (otMessageQueue &queue : mMessageQueue)
|
||||
{
|
||||
while ((message = otMessageQueueGetHead(&mMessageQueue[priority])) != nullptr)
|
||||
while ((message = otMessageQueueGetHead(&queue)) != nullptr)
|
||||
{
|
||||
otMessageQueueDequeue(&mMessageQueue[priority], message);
|
||||
otMessageQueueDequeue(&queue, message);
|
||||
otMessageFree(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3744,13 +3744,13 @@ void NcpBase::ProcessThreadChangedFlags(void)
|
||||
|
||||
// Convert OT_CHANGED flags to corresponding NCP property update.
|
||||
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(kFlags); i++)
|
||||
for (auto flag : kFlags)
|
||||
{
|
||||
uint32_t threadFlag = kFlags[i].mThreadFlag;
|
||||
uint32_t threadFlag = flag.mThreadFlag;
|
||||
|
||||
if (mThreadChangedFlags & threadFlag)
|
||||
{
|
||||
spinel_prop_key_t propKey = kFlags[i].mPropKey;
|
||||
spinel_prop_key_t propKey = flag.mPropKey;
|
||||
bool shouldAddProperty = true;
|
||||
|
||||
// Child table changes are reported using the `HandleChildAdded()` and
|
||||
|
||||
@@ -136,11 +136,10 @@ void TestChildIp6Address(void)
|
||||
|
||||
numAddresses++;
|
||||
|
||||
for (uint8_t index = 0; index < static_cast<uint8_t>(OT_ARRAY_LENGTH(ip6Addresses)); index++)
|
||||
for (const char *ip6Address : ip6Addresses)
|
||||
{
|
||||
VerifyOrQuit(numAddresses < kMaxChildIp6Addresses, "Too many IPv6 addresses in the unit test");
|
||||
SuccessOrQuit(addresses[numAddresses++].FromString(ip6Addresses[index]),
|
||||
"could not convert IPv6 address from string");
|
||||
SuccessOrQuit(addresses[numAddresses++].FromString(ip6Address), "could not convert IPv6 address from string");
|
||||
}
|
||||
|
||||
printf(" -- PASS\n");
|
||||
|
||||
@@ -109,10 +109,8 @@ void VerifyChildTableContent(ChildTable &aTable, uint16_t aChildListLength, cons
|
||||
{
|
||||
printf("Test ChildTable with %d entries", aChildListLength);
|
||||
|
||||
for (uint16_t k = 0; k < OT_ARRAY_LENGTH(kAllFilters); k++)
|
||||
for (Child::StateFilter filter : kAllFilters)
|
||||
{
|
||||
Child::StateFilter filter = kAllFilters[k];
|
||||
|
||||
// Verify that we can find all children from given list by rloc or extended address.
|
||||
|
||||
for (uint16_t listIndex = 0; listIndex < aChildListLength; listIndex++)
|
||||
@@ -302,10 +300,8 @@ void TestChildTable(void)
|
||||
VerifyOrQuit(table->GetMaxChildrenAllowed() == table->GetMaxChildren(),
|
||||
"GetMaxChildrenAllowed() initial value is incorrect ");
|
||||
|
||||
for (uint16_t i = 0; i < OT_ARRAY_LENGTH(kAllFilters); i++)
|
||||
for (Child::StateFilter filter : kAllFilters)
|
||||
{
|
||||
Child::StateFilter filter = kAllFilters[i];
|
||||
|
||||
VerifyOrQuit(table->HasChildren(filter) == false, "HasChildren() failed after init");
|
||||
VerifyOrQuit(table->GetNumChildren(filter) == 0, "GetNumChildren() failed after init");
|
||||
}
|
||||
|
||||
@@ -130,9 +130,9 @@ void TestIp6AddressFromString(void)
|
||||
{":f:0:0:c:0:f:f:.", {0}, OT_ERROR_PARSE},
|
||||
};
|
||||
|
||||
for (uint32_t index = 0; index < OT_ARRAY_LENGTH(testVectors); index++)
|
||||
for (Ip6AddressStringTestVector &testVector : testVectors)
|
||||
{
|
||||
checkAddressFromString(&testVectors[index]);
|
||||
checkAddressFromString(&testVector);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,10 +194,8 @@ void TestIp6AddressSetPrefix(void)
|
||||
allZeroAddress.Clear();
|
||||
memset(&allOneAddress, 0xff, sizeof(allOneAddress));
|
||||
|
||||
for (uint8_t index = 0; index < OT_ARRAY_LENGTH(kPrefixes); index++)
|
||||
for (auto prefix : kPrefixes)
|
||||
{
|
||||
const uint8_t *prefix = kPrefixes[index];
|
||||
|
||||
memcpy(address.mFields.m8, prefix, sizeof(address));
|
||||
printf("Prefix is %s\n", address.ToString().AsCString());
|
||||
|
||||
|
||||
@@ -270,7 +270,7 @@ void TestMacHeader(void)
|
||||
Mac::Frame::kSecMic32 | Mac::Frame::kKeyIdMode2, 19, 6},
|
||||
};
|
||||
|
||||
for (unsigned i = 0; i < OT_ARRAY_LENGTH(tests); i++)
|
||||
for (const auto &test : tests)
|
||||
{
|
||||
uint8_t psdu[Mac::Frame::kMtu];
|
||||
Mac::TxFrame frame;
|
||||
@@ -278,10 +278,10 @@ void TestMacHeader(void)
|
||||
frame.mPsdu = psdu;
|
||||
frame.mLength = 0;
|
||||
|
||||
frame.InitMacHeader(tests[i].fcf, tests[i].secCtl);
|
||||
VerifyOrQuit(frame.GetHeaderLength() == tests[i].headerLength, "MacHeader test failed");
|
||||
VerifyOrQuit(frame.GetFooterLength() == tests[i].footerLength, "MacHeader test failed");
|
||||
VerifyOrQuit(frame.GetLength() == tests[i].headerLength + tests[i].footerLength, "MacHeader test failed");
|
||||
frame.InitMacHeader(test.fcf, test.secCtl);
|
||||
VerifyOrQuit(frame.GetHeaderLength() == test.headerLength, "MacHeader test failed");
|
||||
VerifyOrQuit(frame.GetFooterLength() == test.footerLength, "MacHeader test failed");
|
||||
VerifyOrQuit(frame.GetLength() == test.headerLength + test.footerLength, "MacHeader test failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,9 +365,9 @@ void TestMacChannelMask(void)
|
||||
VerifyOrQuit(mask1.IsEmpty(), "ChannelMask.IsEmpty failed");
|
||||
VerifyChannelMaskContent(mask1, nullptr, 0);
|
||||
|
||||
for (uint16_t index = 0; index < sizeof(channels1); index++)
|
||||
for (uint8_t channel : channels1)
|
||||
{
|
||||
mask1.AddChannel(channels1[index]);
|
||||
mask1.AddChannel(channel);
|
||||
}
|
||||
|
||||
printf("channels1 = %s\n", mask1.ToString().AsCString());
|
||||
@@ -377,9 +377,9 @@ void TestMacChannelMask(void)
|
||||
|
||||
mask2.Clear();
|
||||
|
||||
for (uint16_t index = 0; index < sizeof(channels2); index++)
|
||||
for (uint8_t channel : channels2)
|
||||
{
|
||||
mask2.AddChannel(channels2[index]);
|
||||
mask2.AddChannel(channel);
|
||||
}
|
||||
|
||||
printf("channels2 = %s\n", mask2.ToString().AsCString());
|
||||
|
||||
@@ -46,9 +46,9 @@ void TestMessage(void)
|
||||
|
||||
messagePool = &instance->Get<ot::MessagePool>();
|
||||
|
||||
for (unsigned i = 0; i < sizeof(writeBuffer); i++)
|
||||
for (uint8_t &b : writeBuffer)
|
||||
{
|
||||
writeBuffer[i] = static_cast<uint8_t>(random());
|
||||
b = static_cast<uint8_t>(random());
|
||||
}
|
||||
|
||||
VerifyOrQuit((message = messagePool->New(ot::Message::kTypeIp6, 0)) != nullptr, "Message::New failed");
|
||||
|
||||
@@ -78,7 +78,7 @@ void VerifyMessageQueueContent(ot::MessageQueue &aMessageQueue, int aExpectedLen
|
||||
void TestMessageQueue(void)
|
||||
{
|
||||
ot::MessageQueue messageQueue;
|
||||
ot::Message * msg[kNumTestMessages];
|
||||
ot::Message * messages[kNumTestMessages];
|
||||
uint16_t msgCount, bufferCount;
|
||||
|
||||
sInstance = testInitInstance();
|
||||
@@ -86,92 +86,92 @@ void TestMessageQueue(void)
|
||||
|
||||
sMessagePool = &sInstance->Get<ot::MessagePool>();
|
||||
|
||||
for (int i = 0; i < kNumTestMessages; i++)
|
||||
for (ot::Message *&msg : messages)
|
||||
{
|
||||
msg[i] = sMessagePool->New(ot::Message::kTypeIp6, 0);
|
||||
VerifyOrQuit(msg[i] != nullptr, "Message::New failed");
|
||||
msg = sMessagePool->New(ot::Message::kTypeIp6, 0);
|
||||
VerifyOrQuit(msg != nullptr, "Message::New failed");
|
||||
}
|
||||
|
||||
VerifyMessageQueueContent(messageQueue, 0);
|
||||
|
||||
// Enqueue 1 message and remove it
|
||||
messageQueue.Enqueue(*msg[0]);
|
||||
VerifyMessageQueueContent(messageQueue, 1, msg[0]);
|
||||
messageQueue.Dequeue(*msg[0]);
|
||||
messageQueue.Enqueue(*messages[0]);
|
||||
VerifyMessageQueueContent(messageQueue, 1, messages[0]);
|
||||
messageQueue.Dequeue(*messages[0]);
|
||||
VerifyMessageQueueContent(messageQueue, 0);
|
||||
|
||||
// Enqueue 1 message at head and remove it
|
||||
messageQueue.Enqueue(*msg[0], ot::MessageQueue::kQueuePositionHead);
|
||||
VerifyMessageQueueContent(messageQueue, 1, msg[0]);
|
||||
messageQueue.Dequeue(*msg[0]);
|
||||
messageQueue.Enqueue(*messages[0], ot::MessageQueue::kQueuePositionHead);
|
||||
VerifyMessageQueueContent(messageQueue, 1, messages[0]);
|
||||
messageQueue.Dequeue(*messages[0]);
|
||||
VerifyMessageQueueContent(messageQueue, 0);
|
||||
|
||||
// Enqueue 5 messages
|
||||
messageQueue.Enqueue(*msg[0]);
|
||||
VerifyMessageQueueContent(messageQueue, 1, msg[0]);
|
||||
messageQueue.Enqueue(*msg[1]);
|
||||
VerifyMessageQueueContent(messageQueue, 2, msg[0], msg[1]);
|
||||
messageQueue.Enqueue(*msg[2]);
|
||||
VerifyMessageQueueContent(messageQueue, 3, msg[0], msg[1], msg[2]);
|
||||
messageQueue.Enqueue(*msg[3]);
|
||||
VerifyMessageQueueContent(messageQueue, 4, msg[0], msg[1], msg[2], msg[3]);
|
||||
messageQueue.Enqueue(*msg[4]);
|
||||
VerifyMessageQueueContent(messageQueue, 5, msg[0], msg[1], msg[2], msg[3], msg[4]);
|
||||
messageQueue.Enqueue(*messages[0]);
|
||||
VerifyMessageQueueContent(messageQueue, 1, messages[0]);
|
||||
messageQueue.Enqueue(*messages[1]);
|
||||
VerifyMessageQueueContent(messageQueue, 2, messages[0], messages[1]);
|
||||
messageQueue.Enqueue(*messages[2]);
|
||||
VerifyMessageQueueContent(messageQueue, 3, messages[0], messages[1], messages[2]);
|
||||
messageQueue.Enqueue(*messages[3]);
|
||||
VerifyMessageQueueContent(messageQueue, 4, messages[0], messages[1], messages[2], messages[3]);
|
||||
messageQueue.Enqueue(*messages[4]);
|
||||
VerifyMessageQueueContent(messageQueue, 5, messages[0], messages[1], messages[2], messages[3], messages[4]);
|
||||
|
||||
// Check the GetInfo()
|
||||
messageQueue.GetInfo(msgCount, bufferCount);
|
||||
VerifyOrQuit(msgCount == 5, "MessageQueue::GetInfo() failed.");
|
||||
|
||||
// Remove from head
|
||||
messageQueue.Dequeue(*msg[0]);
|
||||
VerifyMessageQueueContent(messageQueue, 4, msg[1], msg[2], msg[3], msg[4]);
|
||||
messageQueue.Dequeue(*messages[0]);
|
||||
VerifyMessageQueueContent(messageQueue, 4, messages[1], messages[2], messages[3], messages[4]);
|
||||
|
||||
// Remove a message in middle
|
||||
messageQueue.Dequeue(*msg[3]);
|
||||
VerifyMessageQueueContent(messageQueue, 3, msg[1], msg[2], msg[4]);
|
||||
messageQueue.Dequeue(*messages[3]);
|
||||
VerifyMessageQueueContent(messageQueue, 3, messages[1], messages[2], messages[4]);
|
||||
|
||||
// Remove from tail
|
||||
messageQueue.Dequeue(*msg[4]);
|
||||
VerifyMessageQueueContent(messageQueue, 2, msg[1], msg[2]);
|
||||
messageQueue.Dequeue(*messages[4]);
|
||||
VerifyMessageQueueContent(messageQueue, 2, messages[1], messages[2]);
|
||||
|
||||
// Add after remove
|
||||
messageQueue.Enqueue(*msg[0]);
|
||||
VerifyMessageQueueContent(messageQueue, 3, msg[1], msg[2], msg[0]);
|
||||
messageQueue.Enqueue(*msg[3]);
|
||||
VerifyMessageQueueContent(messageQueue, 4, msg[1], msg[2], msg[0], msg[3]);
|
||||
messageQueue.Enqueue(*messages[0]);
|
||||
VerifyMessageQueueContent(messageQueue, 3, messages[1], messages[2], messages[0]);
|
||||
messageQueue.Enqueue(*messages[3]);
|
||||
VerifyMessageQueueContent(messageQueue, 4, messages[1], messages[2], messages[0], messages[3]);
|
||||
|
||||
// Remove from middle
|
||||
messageQueue.Dequeue(*msg[2]);
|
||||
VerifyMessageQueueContent(messageQueue, 3, msg[1], msg[0], msg[3]);
|
||||
messageQueue.Dequeue(*messages[2]);
|
||||
VerifyMessageQueueContent(messageQueue, 3, messages[1], messages[0], messages[3]);
|
||||
|
||||
// Add to head
|
||||
messageQueue.Enqueue(*msg[2], ot::MessageQueue::kQueuePositionHead);
|
||||
VerifyMessageQueueContent(messageQueue, 4, msg[2], msg[1], msg[0], msg[3]);
|
||||
messageQueue.Enqueue(*messages[2], ot::MessageQueue::kQueuePositionHead);
|
||||
VerifyMessageQueueContent(messageQueue, 4, messages[2], messages[1], messages[0], messages[3]);
|
||||
|
||||
// Remove from head
|
||||
messageQueue.Dequeue(*msg[2]);
|
||||
VerifyMessageQueueContent(messageQueue, 3, msg[1], msg[0], msg[3]);
|
||||
messageQueue.Dequeue(*messages[2]);
|
||||
VerifyMessageQueueContent(messageQueue, 3, messages[1], messages[0], messages[3]);
|
||||
|
||||
// Remove from head
|
||||
messageQueue.Dequeue(*msg[1]);
|
||||
VerifyMessageQueueContent(messageQueue, 2, msg[0], msg[3]);
|
||||
messageQueue.Dequeue(*messages[1]);
|
||||
VerifyMessageQueueContent(messageQueue, 2, messages[0], messages[3]);
|
||||
|
||||
// Add to head
|
||||
messageQueue.Enqueue(*msg[1], ot::MessageQueue::kQueuePositionHead);
|
||||
VerifyMessageQueueContent(messageQueue, 3, msg[1], msg[0], msg[3]);
|
||||
messageQueue.Enqueue(*messages[1], ot::MessageQueue::kQueuePositionHead);
|
||||
VerifyMessageQueueContent(messageQueue, 3, messages[1], messages[0], messages[3]);
|
||||
|
||||
// Add to tail
|
||||
messageQueue.Enqueue(*msg[2], ot::MessageQueue::kQueuePositionTail);
|
||||
VerifyMessageQueueContent(messageQueue, 4, msg[1], msg[0], msg[3], msg[2]);
|
||||
messageQueue.Enqueue(*messages[2], ot::MessageQueue::kQueuePositionTail);
|
||||
VerifyMessageQueueContent(messageQueue, 4, messages[1], messages[0], messages[3], messages[2]);
|
||||
|
||||
// Remove all messages.
|
||||
messageQueue.Dequeue(*msg[3]);
|
||||
VerifyMessageQueueContent(messageQueue, 3, msg[1], msg[0], msg[2]);
|
||||
messageQueue.Dequeue(*msg[1]);
|
||||
VerifyMessageQueueContent(messageQueue, 2, msg[0], msg[2]);
|
||||
messageQueue.Dequeue(*msg[2]);
|
||||
VerifyMessageQueueContent(messageQueue, 1, msg[0]);
|
||||
messageQueue.Dequeue(*msg[0]);
|
||||
messageQueue.Dequeue(*messages[3]);
|
||||
VerifyMessageQueueContent(messageQueue, 3, messages[1], messages[0], messages[2]);
|
||||
messageQueue.Dequeue(*messages[1]);
|
||||
VerifyMessageQueueContent(messageQueue, 2, messages[0], messages[2]);
|
||||
messageQueue.Dequeue(*messages[2]);
|
||||
VerifyMessageQueueContent(messageQueue, 1, messages[0]);
|
||||
messageQueue.Dequeue(*messages[0]);
|
||||
VerifyMessageQueueContent(messageQueue, 0);
|
||||
|
||||
testFreeInstance(sInstance);
|
||||
@@ -213,17 +213,17 @@ void VerifyMessageQueueContentUsingOtApi(otMessageQueue *aQueue, int aExpectedLe
|
||||
// This test checks all the OpenThread C APIs for `otMessageQueue`
|
||||
void TestMessageQueueOtApis(void)
|
||||
{
|
||||
otMessage * msg[kNumTestMessages];
|
||||
otMessage * messages[kNumTestMessages];
|
||||
otMessage * message;
|
||||
otMessageQueue queue, queue2;
|
||||
|
||||
sInstance = testInitInstance();
|
||||
VerifyOrQuit(sInstance != nullptr, "Null instance");
|
||||
|
||||
for (int i = 0; i < kNumTestMessages; i++)
|
||||
for (otMessage *&msg : messages)
|
||||
{
|
||||
msg[i] = otIp6NewMessage(sInstance, nullptr);
|
||||
VerifyOrQuit(msg[i] != nullptr, "otIp6NewMessage() failed.");
|
||||
msg = otIp6NewMessage(sInstance, nullptr);
|
||||
VerifyOrQuit(msg != nullptr, "otIp6NewMessage() failed.");
|
||||
}
|
||||
|
||||
otMessageQueueInit(&queue);
|
||||
@@ -233,42 +233,42 @@ void TestMessageQueueOtApis(void)
|
||||
VerifyMessageQueueContentUsingOtApi(&queue, 0);
|
||||
|
||||
// Add message to the queue and check the content
|
||||
otMessageQueueEnqueue(&queue, msg[0]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue, 1, msg[0]);
|
||||
otMessageQueueEnqueue(&queue, msg[1]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue, 2, msg[0], msg[1]);
|
||||
otMessageQueueEnqueueAtHead(&queue, msg[2]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue, 3, msg[2], msg[0], msg[1]);
|
||||
otMessageQueueEnqueue(&queue, msg[3]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue, 4, msg[2], msg[0], msg[1], msg[3]);
|
||||
otMessageQueueEnqueue(&queue, messages[0]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue, 1, messages[0]);
|
||||
otMessageQueueEnqueue(&queue, messages[1]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue, 2, messages[0], messages[1]);
|
||||
otMessageQueueEnqueueAtHead(&queue, messages[2]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue, 3, messages[2], messages[0], messages[1]);
|
||||
otMessageQueueEnqueue(&queue, messages[3]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue, 4, messages[2], messages[0], messages[1], messages[3]);
|
||||
|
||||
// Remove elements and check the content
|
||||
otMessageQueueDequeue(&queue, msg[1]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue, 3, msg[2], msg[0], msg[3]);
|
||||
otMessageQueueDequeue(&queue, msg[0]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue, 2, msg[2], msg[3]);
|
||||
otMessageQueueDequeue(&queue, msg[3]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue, 1, msg[2]);
|
||||
otMessageQueueDequeue(&queue, messages[1]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue, 3, messages[2], messages[0], messages[3]);
|
||||
otMessageQueueDequeue(&queue, messages[0]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue, 2, messages[2], messages[3]);
|
||||
otMessageQueueDequeue(&queue, messages[3]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue, 1, messages[2]);
|
||||
|
||||
// Check the failure cases for otMessageQueueGetNext()
|
||||
message = otMessageQueueGetNext(&queue, nullptr);
|
||||
VerifyOrQuit(message == nullptr, "otMessageQueueGetNext(queue, nullptr) did not return nullptr.");
|
||||
message = otMessageQueueGetNext(&queue, msg[1]);
|
||||
message = otMessageQueueGetNext(&queue, messages[1]);
|
||||
VerifyOrQuit(message == nullptr, "otMessageQueueGetNext() did not return nullptr for a message not in the queue.");
|
||||
|
||||
// Check the failure case when attempting to do otMessageQueueGetNext() but passing in a wrong queue pointer.
|
||||
otMessageQueueEnqueue(&queue2, msg[0]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue2, 1, msg[0]);
|
||||
otMessageQueueEnqueue(&queue2, msg[1]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue2, 2, msg[0], msg[1]);
|
||||
otMessageQueueEnqueue(&queue2, messages[0]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue2, 1, messages[0]);
|
||||
otMessageQueueEnqueue(&queue2, messages[1]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue2, 2, messages[0], messages[1]);
|
||||
|
||||
message = otMessageQueueGetNext(&queue2, msg[0]);
|
||||
VerifyOrQuit(message == msg[1], "otMessageQueueGetNext() failed");
|
||||
message = otMessageQueueGetNext(&queue, msg[0]);
|
||||
message = otMessageQueueGetNext(&queue2, messages[0]);
|
||||
VerifyOrQuit(message == messages[1], "otMessageQueueGetNext() failed");
|
||||
message = otMessageQueueGetNext(&queue, messages[0]);
|
||||
VerifyOrQuit(message == nullptr, "otMessageQueueGetNext() did not return nullptr for message not in the queue.");
|
||||
|
||||
// Remove all element and make sure queue is empty
|
||||
otMessageQueueDequeue(&queue, msg[2]);
|
||||
otMessageQueueDequeue(&queue, messages[2]);
|
||||
VerifyMessageQueueContentUsingOtApi(&queue, 0);
|
||||
|
||||
testFreeInstance(sInstance);
|
||||
|
||||
@@ -53,9 +53,9 @@ void PrintExternalRouteConfig(const ExternalRouteConfig &aConfig)
|
||||
{
|
||||
printf("\nprefix:");
|
||||
|
||||
for (uint8_t i = 0; i < 16; i++)
|
||||
for (uint8_t b : aConfig.mPrefix.mPrefix.mFields.m8)
|
||||
{
|
||||
printf("%02x", aConfig.mPrefix.mPrefix.mFields.m8[i]);
|
||||
printf("%02x", b);
|
||||
}
|
||||
|
||||
printf(", length:%d, rloc16:%04x, preference:%d, stable:%d, nexthop:%d", aConfig.mPrefix.mLength, aConfig.mRloc16,
|
||||
@@ -110,11 +110,11 @@ void TestNetworkDataIterator(void)
|
||||
printf("\nTest #1: Network data 1");
|
||||
printf("\n-------------------------------------------------");
|
||||
|
||||
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(routes); i++)
|
||||
for (const auto &route : routes)
|
||||
{
|
||||
SuccessOrQuit(netData.GetNextExternalRoute(iter, config), "GetNextExternalRoute() failed");
|
||||
PrintExternalRouteConfig(config);
|
||||
VerifyOrQuit(CompareExternalRouteConfig(config, routes[i]) == true,
|
||||
VerifyOrQuit(CompareExternalRouteConfig(config, route) == true,
|
||||
"external route config does not match expectation");
|
||||
}
|
||||
}
|
||||
@@ -160,11 +160,11 @@ void TestNetworkDataIterator(void)
|
||||
printf("\nTest #2: Network data 2");
|
||||
printf("\n-------------------------------------------------");
|
||||
|
||||
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(routes); i++)
|
||||
for (const auto &route : routes)
|
||||
{
|
||||
SuccessOrQuit(netData.GetNextExternalRoute(iter, config), "GetNextExternalRoute() failed");
|
||||
PrintExternalRouteConfig(config);
|
||||
VerifyOrQuit(CompareExternalRouteConfig(config, routes[i]) == true,
|
||||
VerifyOrQuit(CompareExternalRouteConfig(config, route) == true,
|
||||
"external route config does not match expectation");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,12 +86,12 @@ void TestPool(EntryPool &aPool, bool aInitWithInstance)
|
||||
|
||||
VerifyOrQuit(aPool.GetSize() == kPoolSize, "Pool::GetSize() failed");
|
||||
|
||||
for (uint16_t i = 0; i < kPoolSize; i++)
|
||||
for (Entry *&entry : entries)
|
||||
{
|
||||
entries[i] = aPool.Allocate();
|
||||
VerifyOrQuit(entries[i] != nullptr, "Pool::Allocate() failed");
|
||||
entry = aPool.Allocate();
|
||||
VerifyOrQuit(entry != nullptr, "Pool::Allocate() failed");
|
||||
|
||||
VerifyEntry(aPool, *entries[i], aInitWithInstance);
|
||||
VerifyEntry(aPool, *entry, aInitWithInstance);
|
||||
}
|
||||
|
||||
for (uint16_t numEntriesToFree = 1; numEntriesToFree <= kPoolSize; numEntriesToFree++)
|
||||
|
||||
@@ -585,21 +585,17 @@ int TestTimerTime(void)
|
||||
ot::Time t1;
|
||||
ot::Time t2;
|
||||
|
||||
for (size_t i = 0; i < OT_ARRAY_LENGTH(kStartTimes); i++)
|
||||
for (uint32_t startTime : kStartTimes)
|
||||
{
|
||||
uint32_t start = kStartTimes[i];
|
||||
|
||||
for (size_t j = 0; j < OT_ARRAY_LENGTH(kDurations); j++)
|
||||
for (uint32_t duration : kDurations)
|
||||
{
|
||||
uint32_t duration = kDurations[j];
|
||||
printf("TestTimerTime() start=%-10x duration=%-10x ", startTime, duration);
|
||||
|
||||
printf("TestTimerTime() start=%-10x duration=%-10x ", start, duration);
|
||||
|
||||
t1.SetValue(start);
|
||||
VerifyOrQuit(t1.GetValue() == start, "Time::SetValue() failed.");
|
||||
t1.SetValue(startTime);
|
||||
VerifyOrQuit(t1.GetValue() == startTime, "Time::SetValue() failed.");
|
||||
|
||||
t2 = t1;
|
||||
VerifyOrQuit(t1.GetValue() == start, "Time assignment failed.");
|
||||
VerifyOrQuit(t1.GetValue() == startTime, "Time assignment failed.");
|
||||
|
||||
VerifyOrQuit(t1 == t2, "Time == failed.");
|
||||
VerifyOrQuit(!(t1 != t2), "Time != failed.");
|
||||
|
||||
Reference in New Issue
Block a user