mirror of
https://github.com/espressif/openthread.git
synced 2026-10-03 14:27:38 +00:00
[code-utils] adding helper macro OT_ARRAY_LENGTH() (#2743)
This commit adds helper macro `OT_ARRAY_LENGTH()` to get the number of elements in an array.
This commit is contained in:
committed by
Jonathan Hui
parent
ae7984d3a7
commit
2abd7a2822
@@ -32,6 +32,7 @@
|
||||
#include <openthread/openthread.h>
|
||||
|
||||
#include "test_util.h"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/instance.hpp"
|
||||
#include "thread/topology.hpp"
|
||||
|
||||
@@ -132,7 +133,7 @@ void TestChildIp6Address(void)
|
||||
|
||||
numAddresses++;
|
||||
|
||||
for (uint8_t index = 0; index < static_cast<uint8_t>(sizeof(ip6Addresses) / sizeof(ip6Addresses[0])); index++)
|
||||
for (uint8_t index = 0; index < static_cast<uint8_t>(OT_ARRAY_LENGTH(ip6Addresses)); index++)
|
||||
{
|
||||
VerifyOrQuit(numAddresses < kMaxChildIp6Addresses, "Too many IPv6 addresses in the unit test");
|
||||
SuccessOrQuit(addresses[numAddresses++].FromString(ip6Addresses[index]),
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <openthread/openthread.h>
|
||||
|
||||
#include "test_util.h"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/instance.hpp"
|
||||
#include "thread/child_table.hpp"
|
||||
|
||||
@@ -109,7 +110,7 @@ void VerifyChildTableContent(ChildTable &aTable, uint8_t aChildListLength, const
|
||||
{
|
||||
printf("Test ChildTable with %d entries", aChildListLength);
|
||||
|
||||
for (uint8_t k = 0; k < sizeof(kAllFilters) / sizeof(kAllFilters[0]); k++)
|
||||
for (uint8_t k = 0; k < OT_ARRAY_LENGTH(kAllFilters); k++)
|
||||
{
|
||||
ChildTable::StateFilter filter = kAllFilters[k];
|
||||
|
||||
@@ -296,7 +297,7 @@ void TestChildTable(void)
|
||||
},
|
||||
};
|
||||
|
||||
const uint8_t testListLength = sizeof(testChildList) / sizeof(testChildList[0]);
|
||||
const uint8_t testListLength = OT_ARRAY_LENGTH(testChildList);
|
||||
|
||||
uint8_t testNumAllowedChildren = 2;
|
||||
|
||||
@@ -314,7 +315,7 @@ void TestChildTable(void)
|
||||
VerifyOrQuit(table->GetMaxChildrenAllowed() == table->GetMaxChildren(),
|
||||
"GetMaxChildrenAllowed() initial value is incorrect ");
|
||||
|
||||
for (uint8_t i = 0; i < sizeof(kAllFilters) / sizeof(kAllFilters[0]); i++)
|
||||
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(kAllFilters); i++)
|
||||
{
|
||||
ChildTable::StateFilter filter = kAllFilters[i];
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include <openthread/openthread.h>
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "thread/link_quality.hpp"
|
||||
#include "utils/wrap_string.h"
|
||||
|
||||
@@ -427,7 +428,7 @@ void TestSuccessRateTracker(void)
|
||||
|
||||
// Adding success/failure at different rates and checking the RateTracker rate for every sample
|
||||
|
||||
for (uint16_t testRound = 0; testRound < sizeof(kWeightLimit) / sizeof(kWeightLimit[0]) * 2; testRound++)
|
||||
for (uint16_t testRound = 0; testRound < OT_ARRAY_LENGTH(kWeightLimit) * 2; testRound++)
|
||||
{
|
||||
uint16_t weightLimit;
|
||||
bool reverseLogic;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include <openthread/openthread.h>
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "mac/mac.hpp"
|
||||
#include "mac/mac_frame.hpp"
|
||||
@@ -68,7 +69,7 @@ void TestMacHeader(void)
|
||||
Mac::Frame::kSecMic32 | Mac::Frame::kKeyIdMode2, 19},
|
||||
};
|
||||
|
||||
for (unsigned i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
|
||||
for (unsigned i = 0; i < OT_ARRAY_LENGTH(tests); i++)
|
||||
{
|
||||
uint8_t psdu[Mac::Frame::kMTU];
|
||||
Mac::Frame frame;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include <openthread/config.h>
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/instance.hpp"
|
||||
#include "thread/network_data_local.hpp"
|
||||
|
||||
@@ -108,7 +109,7 @@ void TestNetworkDataIterator(void)
|
||||
printf("\nTest #1: Network data 1");
|
||||
printf("\n-------------------------------------------------");
|
||||
|
||||
for (uint8_t i = 0; i < sizeof(routes) / sizeof(routes[0]); i++)
|
||||
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(routes); i++)
|
||||
{
|
||||
SuccessOrQuit(netData.GetNextExternalRoute(&iter, &config), "GetNextExternalRoute() failed\n");
|
||||
PrintExternalRouteConfig(config);
|
||||
@@ -158,7 +159,7 @@ void TestNetworkDataIterator(void)
|
||||
printf("\nTest #2: Network data 2");
|
||||
printf("\n-------------------------------------------------");
|
||||
|
||||
for (uint8_t i = 0; i < sizeof(routes) / sizeof(routes[0]); i++)
|
||||
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(routes); i++)
|
||||
{
|
||||
SuccessOrQuit(netData.GetNextExternalRoute(&iter, &config), "GetNextExternalRoute() failed\n");
|
||||
PrintExternalRouteConfig(config);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "test_platform.h"
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "common/instance.hpp"
|
||||
#include "common/timer.hpp"
|
||||
@@ -550,7 +551,7 @@ int TestTenTimers(void)
|
||||
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < sizeof(kTimeShift) / sizeof(kTimeShift[0]); i++)
|
||||
for (i = 0; i < OT_ARRAY_LENGTH(kTimeShift); i++)
|
||||
{
|
||||
TenTimers(kTimeShift[i]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user