mirror of
https://github.com/espressif/openthread.git
synced 2026-06-05 21:14:49 +00:00
[test] define all unit tests in ot namespace (#9617)
This commit updates unit test modules to be defined under the `ot` namespace. This aligns all the unit tests to follow the same model, eliminating the need to use `ot::` prefix in unit test code.
This commit is contained in:
committed by
GitHub
parent
b77573586c
commit
23c0fc4d4b
+27
-23
@@ -34,6 +34,8 @@
|
||||
#include "test_platform.h"
|
||||
#include "test_util.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
/**
|
||||
* Verifies test vectors from IEEE 802.15.4-2006 Annex C Section C.2.1
|
||||
*/
|
||||
@@ -55,11 +57,11 @@ void TestMacBeaconFrame(void)
|
||||
0xAC, 0x02, 0x05, 0x00, 0x00, 0x00, 0x55, 0xCF, 0x00, 0x00, 0x51, 0x52,
|
||||
0x53, 0x54, 0x22, 0x3B, 0xC1, 0xEC, 0x84, 0x1A, 0xB5, 0x53};
|
||||
|
||||
otInstance *instance = testInitInstance();
|
||||
ot::Crypto::AesCcm aesCcm;
|
||||
uint32_t headerLength = sizeof(test) - 8;
|
||||
uint32_t payloadLength = 0;
|
||||
uint8_t tagLength = 8;
|
||||
otInstance *instance = testInitInstance();
|
||||
Crypto::AesCcm aesCcm;
|
||||
uint32_t headerLength = sizeof(test) - 8;
|
||||
uint32_t payloadLength = 0;
|
||||
uint8_t tagLength = 8;
|
||||
|
||||
uint8_t nonce[] = {
|
||||
0xAC, 0xDE, 0x48, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x02,
|
||||
@@ -122,23 +124,23 @@ void TestMacCommandFrame(void)
|
||||
|
||||
uint8_t tag[kTagLength];
|
||||
|
||||
ot::Instance *instance = testInitInstance();
|
||||
ot::Message *message;
|
||||
ot::Crypto::AesCcm aesCcm;
|
||||
Instance *instance = testInitInstance();
|
||||
Message *message;
|
||||
Crypto::AesCcm aesCcm;
|
||||
|
||||
VerifyOrQuit(instance != nullptr);
|
||||
|
||||
aesCcm.SetKey(key, sizeof(key));
|
||||
aesCcm.Init(kHeaderLength, kPayloadLength, kTagLength, nonce, sizeof(nonce));
|
||||
aesCcm.Header(test, kHeaderLength);
|
||||
aesCcm.Payload(test + kHeaderLength, test + kHeaderLength, kPayloadLength, ot::Crypto::AesCcm::kEncrypt);
|
||||
aesCcm.Payload(test + kHeaderLength, test + kHeaderLength, kPayloadLength, Crypto::AesCcm::kEncrypt);
|
||||
VerifyOrQuit(aesCcm.GetTagLength() == kTagLength);
|
||||
aesCcm.Finalize(test + kHeaderLength + kPayloadLength);
|
||||
VerifyOrQuit(memcmp(test, encrypted, sizeof(encrypted)) == 0);
|
||||
|
||||
aesCcm.Init(kHeaderLength, kPayloadLength, kTagLength, nonce, sizeof(nonce));
|
||||
aesCcm.Header(test, kHeaderLength);
|
||||
aesCcm.Payload(test + kHeaderLength, test + kHeaderLength, kPayloadLength, ot::Crypto::AesCcm::kDecrypt);
|
||||
aesCcm.Payload(test + kHeaderLength, test + kHeaderLength, kPayloadLength, Crypto::AesCcm::kDecrypt);
|
||||
VerifyOrQuit(aesCcm.GetTagLength() == kTagLength);
|
||||
aesCcm.Finalize(test + kHeaderLength + kPayloadLength);
|
||||
|
||||
@@ -146,7 +148,7 @@ void TestMacCommandFrame(void)
|
||||
|
||||
// Verify encryption/decryption in place within a message.
|
||||
|
||||
message = instance->Get<ot::MessagePool>().Allocate(ot::Message::kTypeIp6);
|
||||
message = instance->Get<MessagePool>().Allocate(Message::kTypeIp6);
|
||||
VerifyOrQuit(message != nullptr);
|
||||
|
||||
SuccessOrQuit(message->AppendBytes(test, kHeaderLength + kPayloadLength));
|
||||
@@ -154,7 +156,7 @@ void TestMacCommandFrame(void)
|
||||
aesCcm.Init(kHeaderLength, kPayloadLength, kTagLength, nonce, sizeof(nonce));
|
||||
aesCcm.Header(test, kHeaderLength);
|
||||
|
||||
aesCcm.Payload(*message, kHeaderLength, kPayloadLength, ot::Crypto::AesCcm::kEncrypt);
|
||||
aesCcm.Payload(*message, kHeaderLength, kPayloadLength, Crypto::AesCcm::kEncrypt);
|
||||
VerifyOrQuit(aesCcm.GetTagLength() == kTagLength);
|
||||
aesCcm.Finalize(tag);
|
||||
SuccessOrQuit(message->Append(tag));
|
||||
@@ -163,7 +165,7 @@ void TestMacCommandFrame(void)
|
||||
|
||||
aesCcm.Init(kHeaderLength, kPayloadLength, kTagLength, nonce, sizeof(nonce));
|
||||
aesCcm.Header(test, kHeaderLength);
|
||||
aesCcm.Payload(*message, kHeaderLength, kPayloadLength, ot::Crypto::AesCcm::kDecrypt);
|
||||
aesCcm.Payload(*message, kHeaderLength, kPayloadLength, Crypto::AesCcm::kDecrypt);
|
||||
|
||||
VerifyOrQuit(message->GetLength() == sizeof(encrypted));
|
||||
VerifyOrQuit(message->Compare(0, decrypted));
|
||||
@@ -194,14 +196,14 @@ void TestInPlaceAesCcmProcessing(void)
|
||||
uint8_t tag[kTagLength];
|
||||
uint8_t header[kHeaderLength];
|
||||
|
||||
ot::Crypto::AesCcm aesCcm;
|
||||
ot::Instance *instance = testInitInstance();
|
||||
ot::Message *message;
|
||||
ot::Message *messageClone;
|
||||
Crypto::AesCcm aesCcm;
|
||||
Instance *instance = testInitInstance();
|
||||
Message *message;
|
||||
Message *messageClone;
|
||||
|
||||
VerifyOrQuit(instance != nullptr);
|
||||
|
||||
message = instance->Get<ot::MessagePool>().Allocate(ot::Message::kTypeIp6);
|
||||
message = instance->Get<MessagePool>().Allocate(Message::kTypeIp6);
|
||||
VerifyOrQuit(message != nullptr);
|
||||
|
||||
aesCcm.SetKey(kKey, sizeof(kKey));
|
||||
@@ -226,7 +228,7 @@ void TestInPlaceAesCcmProcessing(void)
|
||||
// Encrypt in place
|
||||
aesCcm.Init(kHeaderLength, msgLength - kHeaderLength, kTagLength, kNonce, sizeof(kNonce));
|
||||
aesCcm.Header(header);
|
||||
aesCcm.Payload(*message, kHeaderLength, msgLength - kHeaderLength, ot::Crypto::AesCcm::kEncrypt);
|
||||
aesCcm.Payload(*message, kHeaderLength, msgLength - kHeaderLength, Crypto::AesCcm::kEncrypt);
|
||||
|
||||
// Append the tag
|
||||
aesCcm.Finalize(tag);
|
||||
@@ -237,7 +239,7 @@ void TestInPlaceAesCcmProcessing(void)
|
||||
// Decrypt in place
|
||||
aesCcm.Init(kHeaderLength, msgLength - kHeaderLength, kTagLength, kNonce, sizeof(kNonce));
|
||||
aesCcm.Header(header);
|
||||
aesCcm.Payload(*message, kHeaderLength, msgLength - kHeaderLength, ot::Crypto::AesCcm::kDecrypt);
|
||||
aesCcm.Payload(*message, kHeaderLength, msgLength - kHeaderLength, Crypto::AesCcm::kDecrypt);
|
||||
|
||||
// Check the tag against what is the message
|
||||
aesCcm.Finalize(tag);
|
||||
@@ -253,11 +255,13 @@ void TestInPlaceAesCcmProcessing(void)
|
||||
testFreeInstance(instance);
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TestMacBeaconFrame();
|
||||
TestMacCommandFrame();
|
||||
TestInPlaceAesCcmProcessing();
|
||||
ot::TestMacBeaconFrame();
|
||||
ot::TestMacCommandFrame();
|
||||
ot::TestInPlaceAesCcmProcessing();
|
||||
printf("All tests passed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
namespace ot {
|
||||
|
||||
static ot::Instance *sInstance;
|
||||
static Instance *sInstance;
|
||||
|
||||
enum
|
||||
{
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
namespace ot {
|
||||
|
||||
static ot::Instance *sInstance;
|
||||
static Instance *sInstance;
|
||||
|
||||
enum
|
||||
{
|
||||
|
||||
@@ -37,16 +37,18 @@
|
||||
|
||||
#include "test_util.hpp"
|
||||
|
||||
using ot::Utils::CmdLineParser::ParseAsBool;
|
||||
using ot::Utils::CmdLineParser::ParseAsHexString;
|
||||
using ot::Utils::CmdLineParser::ParseAsHexStringSegment;
|
||||
using ot::Utils::CmdLineParser::ParseAsInt16;
|
||||
using ot::Utils::CmdLineParser::ParseAsInt32;
|
||||
using ot::Utils::CmdLineParser::ParseAsInt8;
|
||||
using ot::Utils::CmdLineParser::ParseAsUint16;
|
||||
using ot::Utils::CmdLineParser::ParseAsUint32;
|
||||
using ot::Utils::CmdLineParser::ParseAsUint64;
|
||||
using ot::Utils::CmdLineParser::ParseAsUint8;
|
||||
namespace ot {
|
||||
|
||||
using Utils::CmdLineParser::ParseAsBool;
|
||||
using Utils::CmdLineParser::ParseAsHexString;
|
||||
using Utils::CmdLineParser::ParseAsHexStringSegment;
|
||||
using Utils::CmdLineParser::ParseAsInt16;
|
||||
using Utils::CmdLineParser::ParseAsInt32;
|
||||
using Utils::CmdLineParser::ParseAsInt8;
|
||||
using Utils::CmdLineParser::ParseAsUint16;
|
||||
using Utils::CmdLineParser::ParseAsUint32;
|
||||
using Utils::CmdLineParser::ParseAsUint64;
|
||||
using Utils::CmdLineParser::ParseAsUint8;
|
||||
|
||||
template <typename ValueType> struct TestCase
|
||||
{
|
||||
@@ -352,10 +354,12 @@ void TestParsingHexStrings(void)
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TestParsingInts();
|
||||
TestParsingHexStrings();
|
||||
ot::TestParsingInts();
|
||||
ot::TestParsingHexStrings();
|
||||
|
||||
printf("All tests passed\n");
|
||||
return 0;
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
#include "instance/instance.hpp"
|
||||
#include "net/dns_dso.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
#if OPENTHREAD_CONFIG_DNS_DSO_ENABLE
|
||||
|
||||
extern "C" {
|
||||
@@ -73,7 +75,7 @@ void AdvanceTime(uint32_t aDuration)
|
||||
|
||||
Log(" AdvanceTime for %u.%03u", aDuration / 1000, aDuration % 1000);
|
||||
|
||||
while (ot::TimeMilli(sAlarmTime) <= ot::TimeMilli(time))
|
||||
while (TimeMilli(sAlarmTime) <= TimeMilli(time))
|
||||
{
|
||||
sNow = sAlarmTime;
|
||||
otPlatAlarmMilliFired(sInstance);
|
||||
@@ -82,7 +84,6 @@ void AdvanceTime(uint32_t aDuration)
|
||||
sNow = time;
|
||||
}
|
||||
|
||||
namespace ot {
|
||||
namespace Dns {
|
||||
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
@@ -1218,10 +1219,11 @@ void TestDso(void)
|
||||
}
|
||||
|
||||
} // namespace Dns
|
||||
} // namespace ot
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_DNS_DSO_ENABLE
|
||||
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_DNS_DSO_ENABLE
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
#include "test_platform.h"
|
||||
#include "test_util.h"
|
||||
|
||||
namespace ot {
|
||||
|
||||
#if !OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
||||
|
||||
/**
|
||||
@@ -175,10 +177,12 @@ void RunTimerTests(void)
|
||||
|
||||
#endif // !OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
||||
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
#if !OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
||||
RunTimerTests();
|
||||
ot::RunTimerTests();
|
||||
printf("All tests passed\n");
|
||||
#endif // !OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE
|
||||
return 0;
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
#include "common/debug.hpp"
|
||||
#include "crypto/hkdf_sha256.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
struct TestVector
|
||||
{
|
||||
const uint8_t *mInKey;
|
||||
@@ -126,11 +128,11 @@ void TestHkdfSha256(void)
|
||||
|
||||
VerifyOrQuit(instance != nullptr);
|
||||
|
||||
for (const TestVector *test = &kTestVectors[0]; test < ot::GetArrayEnd(kTestVectors); test++)
|
||||
for (const TestVector *test = &kTestVectors[0]; test < GetArrayEnd(kTestVectors); test++)
|
||||
{
|
||||
ot::Crypto::HkdfSha256 hkdf;
|
||||
uint8_t outKey[kMaxOuttKey];
|
||||
ot::Crypto::Key testInputKey;
|
||||
Crypto::HkdfSha256 hkdf;
|
||||
uint8_t outKey[kMaxOuttKey];
|
||||
Crypto::Key testInputKey;
|
||||
|
||||
printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
|
||||
DumpBuffer("\nInput Key", test->mInKey, test->mInKeyLength);
|
||||
@@ -159,9 +161,11 @@ void TestHkdfSha256(void)
|
||||
testFreeInstance(instance);
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TestHkdfSha256();
|
||||
ot::TestHkdfSha256();
|
||||
printf("All tests passed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
+139
-134
@@ -36,16 +36,18 @@
|
||||
|
||||
#include "test_util.h"
|
||||
|
||||
namespace ot {
|
||||
|
||||
template <typename AddressType> struct TestVector
|
||||
{
|
||||
const char *mString;
|
||||
const uint8_t mAddr[sizeof(AddressType)];
|
||||
ot::Error mError;
|
||||
Error mError;
|
||||
};
|
||||
|
||||
template <typename AddressType> static void checkAddressFromString(TestVector<AddressType> *aTestVector)
|
||||
{
|
||||
ot::Error error;
|
||||
Error error;
|
||||
AddressType address;
|
||||
|
||||
address.Clear();
|
||||
@@ -53,11 +55,11 @@ template <typename AddressType> static void checkAddressFromString(TestVector<Ad
|
||||
error = address.FromString(aTestVector->mString);
|
||||
|
||||
printf("%-42s -> %-42s\n", aTestVector->mString,
|
||||
(error == ot::kErrorNone) ? address.ToString().AsCString() : "(parse error)");
|
||||
(error == kErrorNone) ? address.ToString().AsCString() : "(parse error)");
|
||||
|
||||
VerifyOrQuit(error == aTestVector->mError, "Address::FromString returned unexpected error code");
|
||||
|
||||
if (error == ot::kErrorNone)
|
||||
if (error == kErrorNone)
|
||||
{
|
||||
VerifyOrQuit(0 == memcmp(address.GetBytes(), aTestVector->mAddr, sizeof(AddressType)),
|
||||
"Address::FromString parsing failed");
|
||||
@@ -66,102 +68,102 @@ template <typename AddressType> static void checkAddressFromString(TestVector<Ad
|
||||
|
||||
void TestIp6AddressFromString(void)
|
||||
{
|
||||
typedef TestVector<ot::Ip6::Address> Ip6AddressTestVector;
|
||||
typedef TestVector<Ip6::Address> Ip6AddressTestVector;
|
||||
|
||||
Ip6AddressTestVector testVectors[] = {
|
||||
// Valid full IPv6 address.
|
||||
{"0102:0304:0506:0708:090a:0b0c:0d0e:0f00",
|
||||
{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00},
|
||||
ot::kErrorNone},
|
||||
kErrorNone},
|
||||
|
||||
// Valid full address using capital letters.
|
||||
{"0102:0304:0506:0708:090A:0B0C:0D0E:0F00",
|
||||
{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00},
|
||||
ot::kErrorNone},
|
||||
kErrorNone},
|
||||
|
||||
// Valid full IPv6 address with mixed capital and small letters.
|
||||
{"0102:0304:0506:0708:090a:0B0C:0d0E:0F00",
|
||||
{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00},
|
||||
ot::kErrorNone},
|
||||
kErrorNone},
|
||||
|
||||
// Short prefix and full IID.
|
||||
{"fd11::abcd:e0e0:d10e:0001",
|
||||
{0xfd, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xab, 0xcd, 0xe0, 0xe0, 0xd1, 0x0e, 0x00, 0x01},
|
||||
ot::kErrorNone},
|
||||
kErrorNone},
|
||||
|
||||
// Valid IPv6 address with unnecessary :: symbol.
|
||||
{"fd11:1234:5678:abcd::abcd:e0e0:d10e:1000",
|
||||
{0xfd, 0x11, 0x12, 0x34, 0x56, 0x78, 0xab, 0xcd, 0xab, 0xcd, 0xe0, 0xe0, 0xd1, 0x0e, 0x10, 0x00},
|
||||
ot::kErrorNone},
|
||||
kErrorNone},
|
||||
|
||||
// Short multicast address.
|
||||
{"ff03::0b",
|
||||
{0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b},
|
||||
ot::kErrorNone},
|
||||
kErrorNone},
|
||||
|
||||
// Unspecified address.
|
||||
{"::", {0}, ot::kErrorNone},
|
||||
{"::", {0}, kErrorNone},
|
||||
|
||||
// Starts with ::
|
||||
{"::1:2:3:4",
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04},
|
||||
ot::kErrorNone},
|
||||
kErrorNone},
|
||||
|
||||
// Ends with ::
|
||||
{"1001:2002:3003:4004::",
|
||||
{0x10, 0x01, 0x20, 0x02, 0x30, 0x03, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
ot::kErrorNone},
|
||||
kErrorNone},
|
||||
|
||||
// Valid embedded IPv4 address.
|
||||
{"64:ff9b::100.200.15.4",
|
||||
{0x00, 0x64, 0xff, 0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0xc8, 0x0f, 0x04},
|
||||
ot::kErrorNone},
|
||||
kErrorNone},
|
||||
|
||||
// Valid embedded IPv4 address.
|
||||
{"2001:db8::abc:def1:127.0.0.1",
|
||||
{0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xbc, 0xde, 0xf1, 0x7f, 0x00, 0x00, 0x01},
|
||||
ot::kErrorNone},
|
||||
kErrorNone},
|
||||
|
||||
// Valid embedded IPv4 address.
|
||||
{"1:2:3:4:5:6:127.1.2.3",
|
||||
{0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x7f, 0x01, 0x02, 0x03},
|
||||
ot::kErrorNone},
|
||||
kErrorNone},
|
||||
|
||||
// Two :: should cause a parse error.
|
||||
{"2001:db8::a::b", {0}, ot::kErrorParse},
|
||||
{"2001:db8::a::b", {0}, kErrorParse},
|
||||
|
||||
// The "g" and "h" are not the hex characters.
|
||||
{"2001:db8::abcd:efgh", {0}, ot::kErrorParse},
|
||||
{"2001:db8::abcd:efgh", {0}, kErrorParse},
|
||||
|
||||
// Too many colons.
|
||||
{"1:2:3:4:5:6:7:8:9", {0}, ot::kErrorParse},
|
||||
{"1:2:3:4:5:6:7:8:9", {0}, kErrorParse},
|
||||
|
||||
// Too many characters in a single part.
|
||||
{"2001:db8::abc:def12:1:2", {0}, ot::kErrorParse},
|
||||
{"2001:db8::abc:def12:1:2", {0}, kErrorParse},
|
||||
|
||||
// Invalid embedded IPv4 address.
|
||||
{"64:ff9b::123.231.0.257", {0}, ot::kErrorParse},
|
||||
{"64:ff9b::123.231.0.257", {0}, kErrorParse},
|
||||
|
||||
// Invalid embedded IPv4 address.
|
||||
{"64:ff9b::1.22.33", {0}, ot::kErrorParse},
|
||||
{"64:ff9b::1.22.33", {0}, kErrorParse},
|
||||
|
||||
// Invalid embedded IPv4 address.
|
||||
{"64:ff9b::1.22.33.44.5", {0}, ot::kErrorParse},
|
||||
{"64:ff9b::1.22.33.44.5", {0}, kErrorParse},
|
||||
|
||||
// Too long with embedded IPv4 address.
|
||||
{"1:2:3:4:5:6:7:127.1.2.3", {0}, ot::kErrorParse},
|
||||
{"1:2:3:4:5:6:7:127.1.2.3", {0}, kErrorParse},
|
||||
|
||||
// Invalid embedded IPv4 address.
|
||||
{".", {0}, ot::kErrorParse},
|
||||
{".", {0}, kErrorParse},
|
||||
|
||||
// Invalid embedded IPv4 address.
|
||||
{":.", {0}, ot::kErrorParse},
|
||||
{":.", {0}, kErrorParse},
|
||||
|
||||
// Invalid embedded IPv4 address.
|
||||
{"::.", {0}, ot::kErrorParse},
|
||||
{"::.", {0}, kErrorParse},
|
||||
|
||||
// Invalid embedded IPv4 address.
|
||||
{":f:0:0:c:0:f:f:.", {0}, ot::kErrorParse},
|
||||
{":f:0:0:c:0:f:f:.", {0}, kErrorParse},
|
||||
};
|
||||
|
||||
for (Ip6AddressTestVector &testVector : testVectors)
|
||||
@@ -175,11 +177,11 @@ void TestIp6AddressFromString(void)
|
||||
{
|
||||
constexpr uint16_t kMaxString = 80;
|
||||
|
||||
ot::Ip6::Prefix prefix;
|
||||
char string[kMaxString];
|
||||
uint16_t length;
|
||||
Ip6::Prefix prefix;
|
||||
char string[kMaxString];
|
||||
uint16_t length;
|
||||
|
||||
length = ot::StringLength(testVector.mString, kMaxString);
|
||||
length = StringLength(testVector.mString, kMaxString);
|
||||
memcpy(string, testVector.mString, length);
|
||||
VerifyOrQuit(length + sizeof("/128") <= kMaxString);
|
||||
strcpy(&string[length], "/128");
|
||||
@@ -188,9 +190,9 @@ void TestIp6AddressFromString(void)
|
||||
|
||||
VerifyOrQuit(prefix.FromString(string) == testVector.mError);
|
||||
|
||||
if (testVector.mError == ot::kErrorNone)
|
||||
if (testVector.mError == kErrorNone)
|
||||
{
|
||||
VerifyOrQuit(memcmp(prefix.GetBytes(), testVector.mAddr, sizeof(ot::Ip6::Address)) == 0);
|
||||
VerifyOrQuit(memcmp(prefix.GetBytes(), testVector.mAddr, sizeof(Ip6::Address)) == 0);
|
||||
VerifyOrQuit(prefix.GetLength() == 128);
|
||||
}
|
||||
}
|
||||
@@ -198,7 +200,7 @@ void TestIp6AddressFromString(void)
|
||||
|
||||
void TestIp6PrefixFromString(void)
|
||||
{
|
||||
ot::Ip6::Prefix prefix;
|
||||
Ip6::Prefix prefix;
|
||||
|
||||
SuccessOrQuit(prefix.FromString("::/128"));
|
||||
VerifyOrQuit(prefix.GetLength() == 128);
|
||||
@@ -212,32 +214,32 @@ void TestIp6PrefixFromString(void)
|
||||
SuccessOrQuit(prefix.FromString("::/0"));
|
||||
VerifyOrQuit(prefix.GetLength() == 0);
|
||||
|
||||
VerifyOrQuit(prefix.FromString("::") == ot::kErrorParse);
|
||||
VerifyOrQuit(prefix.FromString("::/") == ot::kErrorParse);
|
||||
VerifyOrQuit(prefix.FromString("::/129") == ot::kErrorParse);
|
||||
VerifyOrQuit(prefix.FromString(":: /12") == ot::kErrorParse);
|
||||
VerifyOrQuit(prefix.FromString("::/a1") == ot::kErrorParse);
|
||||
VerifyOrQuit(prefix.FromString("::/12 ") == ot::kErrorParse);
|
||||
VerifyOrQuit(prefix.FromString("::") == kErrorParse);
|
||||
VerifyOrQuit(prefix.FromString("::/") == kErrorParse);
|
||||
VerifyOrQuit(prefix.FromString("::/129") == kErrorParse);
|
||||
VerifyOrQuit(prefix.FromString(":: /12") == kErrorParse);
|
||||
VerifyOrQuit(prefix.FromString("::/a1") == kErrorParse);
|
||||
VerifyOrQuit(prefix.FromString("::/12 ") == kErrorParse);
|
||||
}
|
||||
|
||||
void TestIp4AddressFromString(void)
|
||||
{
|
||||
typedef TestVector<ot::Ip4::Address> Ip4AddressTestVector;
|
||||
typedef TestVector<Ip4::Address> Ip4AddressTestVector;
|
||||
|
||||
Ip4AddressTestVector testVectors[] = {
|
||||
{"0.0.0.0", {0, 0, 0, 0}, ot::kErrorNone},
|
||||
{"255.255.255.255", {255, 255, 255, 255}, ot::kErrorNone},
|
||||
{"127.0.0.1", {127, 0, 0, 1}, ot::kErrorNone},
|
||||
{"1.2.3.4", {1, 2, 3, 4}, ot::kErrorNone},
|
||||
{"001.002.003.004", {1, 2, 3, 4}, ot::kErrorNone},
|
||||
{"00000127.000.000.000001", {127, 0, 0, 1}, ot::kErrorNone},
|
||||
{"123.231.0.256", {0}, ot::kErrorParse}, // Invalid byte value.
|
||||
{"100123.231.0.256", {0}, ot::kErrorParse}, // Invalid byte value.
|
||||
{"1.22.33", {0}, ot::kErrorParse}, // Too few bytes.
|
||||
{"1.22.33.44.5", {0}, ot::kErrorParse}, // Too many bytes.
|
||||
{"a.b.c.d", {0}, ot::kErrorParse}, // Wrong digit char.
|
||||
{"123.23.45 .12", {0}, ot::kErrorParse}, // Extra space.
|
||||
{".", {0}, ot::kErrorParse}, // Invalid.
|
||||
{"0.0.0.0", {0, 0, 0, 0}, kErrorNone},
|
||||
{"255.255.255.255", {255, 255, 255, 255}, kErrorNone},
|
||||
{"127.0.0.1", {127, 0, 0, 1}, kErrorNone},
|
||||
{"1.2.3.4", {1, 2, 3, 4}, kErrorNone},
|
||||
{"001.002.003.004", {1, 2, 3, 4}, kErrorNone},
|
||||
{"00000127.000.000.000001", {127, 0, 0, 1}, kErrorNone},
|
||||
{"123.231.0.256", {0}, kErrorParse}, // Invalid byte value.
|
||||
{"100123.231.0.256", {0}, kErrorParse}, // Invalid byte value.
|
||||
{"1.22.33", {0}, kErrorParse}, // Too few bytes.
|
||||
{"1.22.33.44.5", {0}, kErrorParse}, // Too many bytes.
|
||||
{"a.b.c.d", {0}, kErrorParse}, // Wrong digit char.
|
||||
{"123.23.45 .12", {0}, kErrorParse}, // Extra space.
|
||||
{".", {0}, kErrorParse}, // Invalid.
|
||||
};
|
||||
|
||||
for (Ip4AddressTestVector &testVector : testVectors)
|
||||
@@ -251,24 +253,24 @@ struct CidrTestVector
|
||||
const char *mString;
|
||||
const uint8_t mAddr[sizeof(otIp4Address)];
|
||||
const uint8_t mLength;
|
||||
ot::Error mError;
|
||||
Error mError;
|
||||
};
|
||||
|
||||
static void checkCidrFromString(CidrTestVector *aTestVector)
|
||||
{
|
||||
ot::Error error;
|
||||
ot::Ip4::Cidr cidr;
|
||||
Error error;
|
||||
Ip4::Cidr cidr;
|
||||
|
||||
cidr.Clear();
|
||||
|
||||
error = cidr.FromString(aTestVector->mString);
|
||||
|
||||
printf("%-42s -> %-42s\n", aTestVector->mString,
|
||||
(error == ot::kErrorNone) ? cidr.ToString().AsCString() : "(parse error)");
|
||||
(error == kErrorNone) ? cidr.ToString().AsCString() : "(parse error)");
|
||||
|
||||
VerifyOrQuit(error == aTestVector->mError, "Address::FromString returned unexpected error code");
|
||||
|
||||
if (error == ot::kErrorNone)
|
||||
if (error == kErrorNone)
|
||||
{
|
||||
VerifyOrQuit(0 == memcmp(cidr.GetBytes(), aTestVector->mAddr, sizeof(aTestVector->mAddr)),
|
||||
"Cidr::FromString parsing failed");
|
||||
@@ -279,37 +281,37 @@ static void checkCidrFromString(CidrTestVector *aTestVector)
|
||||
void TestIp4CidrFromString(void)
|
||||
{
|
||||
CidrTestVector testVectors[] = {
|
||||
{"0.0.0.0/0", {0, 0, 0, 0}, 0, ot::kErrorNone},
|
||||
{"255.255.255.255/32", {255, 255, 255, 255}, 32, ot::kErrorNone},
|
||||
{"127.0.0.1/8", {127, 0, 0, 1}, 8, ot::kErrorNone},
|
||||
{"1.2.3.4/24", {1, 2, 3, 4}, 24, ot::kErrorNone},
|
||||
{"001.002.003.004/20", {1, 2, 3, 4}, 20, ot::kErrorNone},
|
||||
{"00000127.000.000.000001/8", {127, 0, 0, 1}, 8, ot::kErrorNone},
|
||||
{"0.0.0.0/0", {0, 0, 0, 0}, 0, kErrorNone},
|
||||
{"255.255.255.255/32", {255, 255, 255, 255}, 32, kErrorNone},
|
||||
{"127.0.0.1/8", {127, 0, 0, 1}, 8, kErrorNone},
|
||||
{"1.2.3.4/24", {1, 2, 3, 4}, 24, kErrorNone},
|
||||
{"001.002.003.004/20", {1, 2, 3, 4}, 20, kErrorNone},
|
||||
{"00000127.000.000.000001/8", {127, 0, 0, 1}, 8, kErrorNone},
|
||||
// Valid suffix, invalid address
|
||||
{"123.231.0.256/4", {0}, 0, ot::kErrorParse}, // Invalid byte value.
|
||||
{"100123.231.0.256/4", {0}, 0, ot::kErrorParse}, // Invalid byte value.
|
||||
{"1.22.33/4", {0}, 0, ot::kErrorParse}, // Too few bytes.
|
||||
{"1.22.33.44.5/4", {0}, 0, ot::kErrorParse}, // Too many bytes.
|
||||
{"a.b.c.d/4", {0}, 0, ot::kErrorParse}, // Wrong digit char.
|
||||
{"123.23.45 .12/4", {0}, 0, ot::kErrorParse}, // Extra space.
|
||||
{"./4", {0}, 0, ot::kErrorParse}, // Invalid.
|
||||
{"123.231.0.256/4", {0}, 0, kErrorParse}, // Invalid byte value.
|
||||
{"100123.231.0.256/4", {0}, 0, kErrorParse}, // Invalid byte value.
|
||||
{"1.22.33/4", {0}, 0, kErrorParse}, // Too few bytes.
|
||||
{"1.22.33.44.5/4", {0}, 0, kErrorParse}, // Too many bytes.
|
||||
{"a.b.c.d/4", {0}, 0, kErrorParse}, // Wrong digit char.
|
||||
{"123.23.45 .12/4", {0}, 0, kErrorParse}, // Extra space.
|
||||
{"./4", {0}, 0, kErrorParse}, // Invalid.
|
||||
// valid address, invalid suffix
|
||||
{"1.2.3.4/33", {0}, 0, ot::kErrorParse}, // Prefix length too large
|
||||
{"1.2.3.4/12345678", {0}, 0, ot::kErrorParse}, // Prefix length too large?
|
||||
{"1.2.3.4/12a", {0}, 0, ot::kErrorParse}, // Extra char after prefix length.
|
||||
{"1.2.3.4/-1", {0}, 0, ot::kErrorParse}, // Not even a non-negative integer.
|
||||
{"1.2.3.4/3.14", {0}, 0, ot::kErrorParse}, // Not even a integer.
|
||||
{"1.2.3.4/abcd", {0}, 0, ot::kErrorParse}, // Not even a number.
|
||||
{"1.2.3.4/", {0}, 0, ot::kErrorParse}, // Where is the suffix?
|
||||
{"1.2.3.4", {0}, 0, ot::kErrorParse}, // Where is the suffix?
|
||||
{"1.2.3.4/33", {0}, 0, kErrorParse}, // Prefix length too large
|
||||
{"1.2.3.4/12345678", {0}, 0, kErrorParse}, // Prefix length too large?
|
||||
{"1.2.3.4/12a", {0}, 0, kErrorParse}, // Extra char after prefix length.
|
||||
{"1.2.3.4/-1", {0}, 0, kErrorParse}, // Not even a non-negative integer.
|
||||
{"1.2.3.4/3.14", {0}, 0, kErrorParse}, // Not even a integer.
|
||||
{"1.2.3.4/abcd", {0}, 0, kErrorParse}, // Not even a number.
|
||||
{"1.2.3.4/", {0}, 0, kErrorParse}, // Where is the suffix?
|
||||
{"1.2.3.4", {0}, 0, kErrorParse}, // Where is the suffix?
|
||||
// invalid address and invalid suffix
|
||||
{"123.231.0.256/41", {0}, 0, ot::kErrorParse}, // Invalid byte value.
|
||||
{"100123.231.0.256/abc", {0}, 0, ot::kErrorParse}, // Invalid byte value.
|
||||
{"1.22.33", {0}, 0, ot::kErrorParse}, // Too few bytes.
|
||||
{"1.22.33.44.5/36", {0}, 0, ot::kErrorParse}, // Too many bytes.
|
||||
{"a.b.c.d/99", {0}, 0, ot::kErrorParse}, // Wrong digit char.
|
||||
{"123.23.45 .12", {0}, 0, ot::kErrorParse}, // Extra space.
|
||||
{".", {0}, 0, ot::kErrorParse}, // Invalid.
|
||||
{"123.231.0.256/41", {0}, 0, kErrorParse}, // Invalid byte value.
|
||||
{"100123.231.0.256/abc", {0}, 0, kErrorParse}, // Invalid byte value.
|
||||
{"1.22.33", {0}, 0, kErrorParse}, // Too few bytes.
|
||||
{"1.22.33.44.5/36", {0}, 0, kErrorParse}, // Too many bytes.
|
||||
{"a.b.c.d/99", {0}, 0, kErrorParse}, // Wrong digit char.
|
||||
{"123.23.45 .12", {0}, 0, kErrorParse}, // Extra space.
|
||||
{".", {0}, 0, kErrorParse}, // Invalid.
|
||||
};
|
||||
|
||||
for (CidrTestVector &testVector : testVectors)
|
||||
@@ -318,7 +320,7 @@ void TestIp4CidrFromString(void)
|
||||
}
|
||||
}
|
||||
|
||||
bool CheckPrefix(const ot::Ip6::Address &aAddress, const uint8_t *aPrefix, uint8_t aPrefixLength)
|
||||
bool CheckPrefix(const Ip6::Address &aAddress, const uint8_t *aPrefix, uint8_t aPrefixLength)
|
||||
{
|
||||
// Check the first aPrefixLength bits of aAddress to match the given aPrefix.
|
||||
|
||||
@@ -339,7 +341,7 @@ bool CheckPrefix(const ot::Ip6::Address &aAddress, const uint8_t *aPrefix, uint8
|
||||
return matches;
|
||||
}
|
||||
|
||||
bool CheckPrefixInIid(const ot::Ip6::InterfaceIdentifier &aIid, const uint8_t *aPrefix, uint8_t aPrefixLength)
|
||||
bool CheckPrefixInIid(const Ip6::InterfaceIdentifier &aIid, const uint8_t *aPrefix, uint8_t aPrefixLength)
|
||||
{
|
||||
// Check the IID to contain the prefix bits (applicable when prefix length is longer than 64).
|
||||
|
||||
@@ -360,13 +362,13 @@ bool CheckPrefixInIid(const ot::Ip6::InterfaceIdentifier &aIid, const uint8_t *a
|
||||
return matches;
|
||||
}
|
||||
|
||||
bool CheckInterfaceId(const ot::Ip6::Address &aAddress1, const ot::Ip6::Address &aAddress2, uint8_t aPrefixLength)
|
||||
bool CheckInterfaceId(const Ip6::Address &aAddress1, const Ip6::Address &aAddress2, uint8_t aPrefixLength)
|
||||
{
|
||||
// Check whether all the bits after aPrefixLength of the two given IPv6 Address match or not.
|
||||
|
||||
bool matches = true;
|
||||
|
||||
for (size_t bit = aPrefixLength; bit < sizeof(ot::Ip6::Address) * CHAR_BIT; bit++)
|
||||
for (size_t bit = aPrefixLength; bit < sizeof(Ip6::Address) * CHAR_BIT; bit++)
|
||||
{
|
||||
uint8_t index = bit / CHAR_BIT;
|
||||
uint8_t mask = (0x80 >> (bit % CHAR_BIT));
|
||||
@@ -390,10 +392,10 @@ void TestIp6AddressSetPrefix(void)
|
||||
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
|
||||
};
|
||||
|
||||
ot::Ip6::Address address;
|
||||
ot::Ip6::Address allZeroAddress;
|
||||
ot::Ip6::Address allOneAddress;
|
||||
ot::Ip6::Prefix ip6Prefix;
|
||||
Ip6::Address address;
|
||||
Ip6::Address allZeroAddress;
|
||||
Ip6::Address allOneAddress;
|
||||
Ip6::Prefix ip6Prefix;
|
||||
|
||||
allZeroAddress.Clear();
|
||||
memset(&allOneAddress, 0xff, sizeof(allOneAddress));
|
||||
@@ -403,7 +405,7 @@ void TestIp6AddressSetPrefix(void)
|
||||
memcpy(address.mFields.m8, prefix, sizeof(address));
|
||||
printf("Prefix is %s\n", address.ToString().AsCString());
|
||||
|
||||
for (size_t prefixLength = 0; prefixLength <= sizeof(ot::Ip6::Address) * CHAR_BIT; prefixLength++)
|
||||
for (size_t prefixLength = 0; prefixLength <= sizeof(Ip6::Address) * CHAR_BIT; prefixLength++)
|
||||
{
|
||||
ip6Prefix.Clear();
|
||||
ip6Prefix.Set(prefix, prefixLength);
|
||||
@@ -436,10 +438,10 @@ void TestIp6AddressSetPrefix(void)
|
||||
}
|
||||
}
|
||||
|
||||
ot::Ip6::Prefix PrefixFrom(const char *aAddressString, uint8_t aPrefixLength)
|
||||
Ip6::Prefix PrefixFrom(const char *aAddressString, uint8_t aPrefixLength)
|
||||
{
|
||||
ot::Ip6::Prefix prefix;
|
||||
ot::Ip6::Address address;
|
||||
Ip6::Prefix prefix;
|
||||
Ip6::Address address;
|
||||
|
||||
SuccessOrQuit(address.FromString(aAddressString));
|
||||
prefix.Set(address.GetBytes(), aPrefixLength);
|
||||
@@ -455,8 +457,8 @@ void TestIp6Prefix(void)
|
||||
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
|
||||
};
|
||||
|
||||
ot::Ip6::Prefix prefix;
|
||||
ot::Ip6::Address address1, address2;
|
||||
Ip6::Prefix prefix;
|
||||
Ip6::Address address1, address2;
|
||||
|
||||
for (auto prefixBytes : kPrefixes)
|
||||
{
|
||||
@@ -464,7 +466,7 @@ void TestIp6Prefix(void)
|
||||
address2 = address1;
|
||||
address2.mFields.m8[0] ^= 0x80; // Change first bit.
|
||||
|
||||
for (uint8_t prefixLength = 1; prefixLength <= ot::Ip6::Prefix::kMaxLength; prefixLength++)
|
||||
for (uint8_t prefixLength = 1; prefixLength <= Ip6::Prefix::kMaxLength; prefixLength++)
|
||||
{
|
||||
prefix.Set(prefixBytes, prefixLength);
|
||||
|
||||
@@ -482,7 +484,7 @@ void TestIp6Prefix(void)
|
||||
|
||||
for (uint8_t subPrefixLength = 1; subPrefixLength <= prefixLength; subPrefixLength++)
|
||||
{
|
||||
ot::Ip6::Prefix subPrefix;
|
||||
Ip6::Prefix subPrefix;
|
||||
|
||||
subPrefix.Set(prefixBytes, subPrefixLength);
|
||||
|
||||
@@ -504,10 +506,10 @@ void TestIp6Prefix(void)
|
||||
|
||||
for (uint8_t bitNumber = 0; bitNumber < prefixLength; bitNumber++)
|
||||
{
|
||||
ot::Ip6::Prefix prefix2;
|
||||
uint8_t mask = static_cast<uint8_t>(1U << (7 - (bitNumber & 7)));
|
||||
uint8_t index = (bitNumber / 8);
|
||||
bool isPrefixSmaller;
|
||||
Ip6::Prefix prefix2;
|
||||
uint8_t mask = static_cast<uint8_t>(1U << (7 - (bitNumber & 7)));
|
||||
uint8_t index = (bitNumber / 8);
|
||||
bool isPrefixSmaller;
|
||||
|
||||
prefix2 = prefix;
|
||||
VerifyOrQuit(prefix == prefix2);
|
||||
@@ -528,8 +530,8 @@ void TestIp6Prefix(void)
|
||||
{
|
||||
struct TestCase
|
||||
{
|
||||
ot::Ip6::Prefix mPrefixA;
|
||||
ot::Ip6::Prefix mPrefixB;
|
||||
Ip6::Prefix mPrefixA;
|
||||
Ip6::Prefix mPrefixB;
|
||||
};
|
||||
|
||||
TestCase kTestCases[] = {
|
||||
@@ -735,16 +737,16 @@ void TestIp6PrefixTidy(void)
|
||||
|
||||
for (auto test : kPrefixes)
|
||||
{
|
||||
for (uint16_t i = 0; i < ot::GetArrayLength(test.prefixStringAfterTidy); i++)
|
||||
for (uint16_t i = 0; i < GetArrayLength(test.prefixStringAfterTidy); i++)
|
||||
{
|
||||
ot::Ip6::Prefix prefix, answer;
|
||||
Ip6::Prefix prefix, answer;
|
||||
|
||||
SuccessOrQuit(answer.FromString(test.prefixStringAfterTidy[i]));
|
||||
prefix.Set(test.originalPrefix, i);
|
||||
prefix.Tidy();
|
||||
|
||||
{
|
||||
ot::Ip6::Prefix::InfoString prefixString = prefix.ToString();
|
||||
Ip6::Prefix::InfoString prefixString = prefix.ToString();
|
||||
|
||||
printf("Prefix: %-36s TidyResult: %-36s\n", test.prefixStringAfterTidy[i],
|
||||
prefix.ToString().AsCString());
|
||||
@@ -781,7 +783,7 @@ void TestIp4Ip6Translation(void)
|
||||
|
||||
const uint8_t kIp4Address[] = {192, 0, 2, 33};
|
||||
|
||||
ot::Ip4::Address ip4Address;
|
||||
Ip4::Address ip4Address;
|
||||
|
||||
printf("\nTestIp4Ip6Translation()\n");
|
||||
|
||||
@@ -789,9 +791,9 @@ void TestIp4Ip6Translation(void)
|
||||
|
||||
for (const TestCase &testCase : kTestCases)
|
||||
{
|
||||
ot::Ip6::Prefix prefix;
|
||||
ot::Ip6::Address address;
|
||||
ot::Ip6::Address expectedAddress;
|
||||
Ip6::Prefix prefix;
|
||||
Ip6::Address address;
|
||||
Ip6::Address expectedAddress;
|
||||
|
||||
SuccessOrQuit(address.FromString(testCase.mPrefix));
|
||||
prefix.Set(address.GetBytes(), testCase.mLength);
|
||||
@@ -809,9 +811,9 @@ void TestIp4Ip6Translation(void)
|
||||
|
||||
for (const TestCase &testCase : kTestCases)
|
||||
{
|
||||
const ot::Ip4::Address expectedAddress = ip4Address;
|
||||
ot::Ip4::Address address;
|
||||
ot::Ip6::Address ip6Address;
|
||||
const Ip4::Address expectedAddress = ip4Address;
|
||||
Ip4::Address address;
|
||||
Ip6::Address ip6Address;
|
||||
|
||||
SuccessOrQuit(ip6Address.FromString(testCase.mIp6Address));
|
||||
|
||||
@@ -826,7 +828,7 @@ void TestIp4Ip6Translation(void)
|
||||
|
||||
void TestIp4Cidr(void)
|
||||
{
|
||||
using ot::Encoding::BigEndian::HostSwap32;
|
||||
using Encoding::BigEndian::HostSwap32;
|
||||
struct TestCase
|
||||
{
|
||||
const char *mNetwork;
|
||||
@@ -857,9 +859,9 @@ void TestIp4Cidr(void)
|
||||
|
||||
for (const TestCase &testCase : kTestCases)
|
||||
{
|
||||
ot::Ip4::Address network;
|
||||
ot::Ip4::Cidr cidr;
|
||||
ot::Ip4::Address generated;
|
||||
Ip4::Address network;
|
||||
Ip4::Cidr cidr;
|
||||
Ip4::Address generated;
|
||||
|
||||
SuccessOrQuit(network.FromString(testCase.mNetwork));
|
||||
cidr.mAddress = network;
|
||||
@@ -875,17 +877,20 @@ void TestIp4Cidr(void)
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TestIp6AddressSetPrefix();
|
||||
TestIp4AddressFromString();
|
||||
TestIp6AddressFromString();
|
||||
TestIp6PrefixFromString();
|
||||
TestIp6Prefix();
|
||||
TestIp6PrefixTidy();
|
||||
TestIp4Ip6Translation();
|
||||
TestIp4Cidr();
|
||||
TestIp4CidrFromString();
|
||||
ot::TestIp6AddressSetPrefix();
|
||||
ot::TestIp4AddressFromString();
|
||||
ot::TestIp6AddressFromString();
|
||||
ot::TestIp6PrefixFromString();
|
||||
ot::TestIp6Prefix();
|
||||
ot::TestIp6PrefixTidy();
|
||||
ot::TestIp4Ip6Translation();
|
||||
ot::TestIp4Cidr();
|
||||
ot::TestIp4CidrFromString();
|
||||
|
||||
printf("All tests passed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
namespace ot {
|
||||
|
||||
static ot::Instance *sInstance;
|
||||
static Instance *sInstance;
|
||||
|
||||
#if OPENTHREAD_CONFIG_LINK_METRICS_MANAGER_ENABLE
|
||||
|
||||
@@ -77,17 +77,17 @@ const TestChild UnitTester::mTestChildList[] = {
|
||||
{
|
||||
Child::kStateValid,
|
||||
{{0x10, 0x20, 0x03, 0x15, 0x10, 0x00, 0x60, 0x16}},
|
||||
ot::kThreadVersion1p2,
|
||||
kThreadVersion1p2,
|
||||
},
|
||||
{
|
||||
Child::kStateValid,
|
||||
{{0x10, 0x20, 0x03, 0x15, 0x10, 0x00, 0x60, 0x17}},
|
||||
ot::kThreadVersion1p2,
|
||||
kThreadVersion1p2,
|
||||
},
|
||||
{
|
||||
Child::kStateParentRequest,
|
||||
{{0x10, 0x20, 0x03, 0x15, 0x10, 0x00, 0x60, 0x18}},
|
||||
ot::kThreadVersion1p2,
|
||||
kThreadVersion1p2,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
namespace ot {
|
||||
|
||||
static ot::Instance *sInstance;
|
||||
static Instance *sInstance;
|
||||
|
||||
enum
|
||||
{
|
||||
|
||||
@@ -31,11 +31,9 @@
|
||||
#include "test_platform.h"
|
||||
#include "test_util.hpp"
|
||||
|
||||
using namespace ot;
|
||||
|
||||
namespace ot {
|
||||
|
||||
ot::Instance *sInstance;
|
||||
Instance *sInstance;
|
||||
Ip6::Ip6 *sIp6;
|
||||
Lowpan::Lowpan *sLowpan;
|
||||
|
||||
@@ -2091,9 +2089,9 @@ void TestLowpanFragmentHeader(void)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TestLowpanIphc();
|
||||
TestLowpanMeshHeader();
|
||||
TestLowpanFragmentHeader();
|
||||
ot::TestLowpanIphc();
|
||||
ot::TestLowpanMeshHeader();
|
||||
ot::TestLowpanFragmentHeader();
|
||||
|
||||
printf("All tests passed\n");
|
||||
return 0;
|
||||
|
||||
@@ -82,7 +82,7 @@ void TestMacAddress(void)
|
||||
const uint8_t kExtAddr[OT_EXT_ADDRESS_SIZE] = {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0};
|
||||
const Mac::ShortAddress kShortAddr = 0x1234;
|
||||
|
||||
ot::Instance *instance;
|
||||
Instance *instance;
|
||||
Mac::Address addr;
|
||||
Mac::ExtAddress extAddr;
|
||||
uint8_t buffer[OT_EXT_ADDRESS_SIZE];
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
|
||||
#include "common/arg_macros.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
static constexpr uint8_t NumberOfArgs(void) { return 0; }
|
||||
|
||||
static constexpr uint8_t NumberOfArgs(uint8_t) { return 1; }
|
||||
@@ -132,13 +134,15 @@ exit:
|
||||
VerifyOrQuit(!reachedEnd && didAction, "VerifyOrExit() failed");
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TestMacros();
|
||||
TestVerifyOrExitSuccessNoAction();
|
||||
TestVerifyOrExitFailureNoAction();
|
||||
TestVerifyOrExitSuccessWithAction();
|
||||
TestVerifyOrExitFailureWithAction();
|
||||
ot::TestMacros();
|
||||
ot::TestVerifyOrExitSuccessNoAction();
|
||||
ot::TestVerifyOrExitFailureNoAction();
|
||||
ot::TestVerifyOrExitSuccessWithAction();
|
||||
ot::TestVerifyOrExitFailureWithAction();
|
||||
printf("All tests passed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -38,18 +38,20 @@
|
||||
|
||||
#include "test_util.h"
|
||||
|
||||
namespace ot {
|
||||
|
||||
#define kNumTestMessages 5
|
||||
|
||||
static ot::Instance *sInstance;
|
||||
static ot::MessagePool *sMessagePool;
|
||||
static Instance *sInstance;
|
||||
static MessagePool *sMessagePool;
|
||||
|
||||
// This function verifies the content of the message queue to match the passed in messages
|
||||
void VerifyMessageQueueContent(ot::MessageQueue &aMessageQueue, int aExpectedLength, ...)
|
||||
void VerifyMessageQueueContent(MessageQueue &aMessageQueue, int aExpectedLength, ...)
|
||||
{
|
||||
const ot::MessageQueue &constQueue = aMessageQueue;
|
||||
va_list args;
|
||||
ot::Message *message;
|
||||
ot::Message *msgArg;
|
||||
const MessageQueue &constQueue = aMessageQueue;
|
||||
va_list args;
|
||||
Message *message;
|
||||
Message *msgArg;
|
||||
|
||||
va_start(args, aExpectedLength);
|
||||
|
||||
@@ -64,7 +66,7 @@ void VerifyMessageQueueContent(ot::MessageQueue &aMessageQueue, int aExpectedLen
|
||||
{
|
||||
VerifyOrQuit(aExpectedLength != 0, "contains more entries than expected");
|
||||
|
||||
msgArg = va_arg(args, ot::Message *);
|
||||
msgArg = va_arg(args, Message *);
|
||||
VerifyOrQuit(msgArg == message, "content does not match what is expected.");
|
||||
|
||||
aExpectedLength--;
|
||||
@@ -79,7 +81,7 @@ void VerifyMessageQueueContent(ot::MessageQueue &aMessageQueue, int aExpectedLen
|
||||
|
||||
message = aMessageQueue.GetHead();
|
||||
|
||||
for (ot::Message &msg : aMessageQueue)
|
||||
for (Message &msg : aMessageQueue)
|
||||
{
|
||||
VerifyOrQuit(message == &msg, "`for` loop iteration does not match expected");
|
||||
message = message->GetNext();
|
||||
@@ -91,7 +93,7 @@ void VerifyMessageQueueContent(ot::MessageQueue &aMessageQueue, int aExpectedLen
|
||||
|
||||
message = aMessageQueue.GetHead();
|
||||
|
||||
for (const ot::Message &constMsg : constQueue)
|
||||
for (const Message &constMsg : constQueue)
|
||||
{
|
||||
VerifyOrQuit(message == &constMsg, "`for` loop iteration does not match expected");
|
||||
message = message->GetNext();
|
||||
@@ -102,18 +104,18 @@ void VerifyMessageQueueContent(ot::MessageQueue &aMessageQueue, int aExpectedLen
|
||||
|
||||
void TestMessageQueue(void)
|
||||
{
|
||||
ot::MessageQueue messageQueue;
|
||||
ot::Message *messages[kNumTestMessages];
|
||||
ot::MessageQueue::Info info;
|
||||
MessageQueue messageQueue;
|
||||
Message *messages[kNumTestMessages];
|
||||
MessageQueue::Info info;
|
||||
|
||||
sInstance = testInitInstance();
|
||||
VerifyOrQuit(sInstance != nullptr);
|
||||
|
||||
sMessagePool = &sInstance->Get<ot::MessagePool>();
|
||||
sMessagePool = &sInstance->Get<MessagePool>();
|
||||
|
||||
for (ot::Message *&msg : messages)
|
||||
for (Message *&msg : messages)
|
||||
{
|
||||
msg = sMessagePool->Allocate(ot::Message::kTypeIp6);
|
||||
msg = sMessagePool->Allocate(Message::kTypeIp6);
|
||||
VerifyOrQuit(msg != nullptr, "Message::Allocate() failed");
|
||||
}
|
||||
|
||||
@@ -126,7 +128,7 @@ void TestMessageQueue(void)
|
||||
VerifyMessageQueueContent(messageQueue, 0);
|
||||
|
||||
// Enqueue 1 message at head and remove it
|
||||
messageQueue.Enqueue(*messages[0], ot::MessageQueue::kQueuePositionHead);
|
||||
messageQueue.Enqueue(*messages[0], MessageQueue::kQueuePositionHead);
|
||||
VerifyMessageQueueContent(messageQueue, 1, messages[0]);
|
||||
messageQueue.Dequeue(*messages[0]);
|
||||
VerifyMessageQueueContent(messageQueue, 0);
|
||||
@@ -171,7 +173,7 @@ void TestMessageQueue(void)
|
||||
VerifyMessageQueueContent(messageQueue, 3, messages[1], messages[0], messages[3]);
|
||||
|
||||
// Add to head
|
||||
messageQueue.Enqueue(*messages[2], ot::MessageQueue::kQueuePositionHead);
|
||||
messageQueue.Enqueue(*messages[2], MessageQueue::kQueuePositionHead);
|
||||
VerifyMessageQueueContent(messageQueue, 4, messages[2], messages[1], messages[0], messages[3]);
|
||||
|
||||
// Remove from head
|
||||
@@ -183,11 +185,11 @@ void TestMessageQueue(void)
|
||||
VerifyMessageQueueContent(messageQueue, 2, messages[0], messages[3]);
|
||||
|
||||
// Add to head
|
||||
messageQueue.Enqueue(*messages[1], ot::MessageQueue::kQueuePositionHead);
|
||||
messageQueue.Enqueue(*messages[1], MessageQueue::kQueuePositionHead);
|
||||
VerifyMessageQueueContent(messageQueue, 3, messages[1], messages[0], messages[3]);
|
||||
|
||||
// Add to tail
|
||||
messageQueue.Enqueue(*messages[2], ot::MessageQueue::kQueuePositionTail);
|
||||
messageQueue.Enqueue(*messages[2], MessageQueue::kQueuePositionTail);
|
||||
VerifyMessageQueueContent(messageQueue, 4, messages[1], messages[0], messages[3], messages[2]);
|
||||
|
||||
// Remove all messages.
|
||||
@@ -214,7 +216,7 @@ void TestMessageQueue(void)
|
||||
VerifyMessageQueueContent(messageQueue, 5, messages[0], messages[1], messages[2], messages[3], messages[4]);
|
||||
|
||||
// While iterating over the queue remove the entry at `removeIndex`
|
||||
for (ot::Message &message : messageQueue)
|
||||
for (Message &message : messageQueue)
|
||||
{
|
||||
if (index == removeIndex)
|
||||
{
|
||||
@@ -227,7 +229,7 @@ void TestMessageQueue(void)
|
||||
index = 0;
|
||||
|
||||
// Iterate over the queue and remove all
|
||||
for (ot::Message &message : messageQueue)
|
||||
for (Message &message : messageQueue)
|
||||
{
|
||||
if (index == removeIndex)
|
||||
{
|
||||
@@ -341,10 +343,12 @@ void TestMessageQueueOtApis(void)
|
||||
testFreeInstance(sInstance);
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TestMessageQueue();
|
||||
TestMessageQueueOtApis();
|
||||
ot::TestMessageQueue();
|
||||
ot::TestMessageQueueOtApis();
|
||||
printf("All tests passed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
namespace ot {
|
||||
|
||||
static ot::Instance *sInstance;
|
||||
static Instance *sInstance;
|
||||
|
||||
using namespace ot::BackboneRouter;
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
namespace ot {
|
||||
|
||||
static ot::Instance *sInstance;
|
||||
static Instance *sInstance;
|
||||
|
||||
using namespace ot::BackboneRouter;
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ void TestNetworkDataIterator(void)
|
||||
{
|
||||
static constexpr uint8_t kMaxRlocsArray = 10;
|
||||
|
||||
ot::Instance *instance;
|
||||
Instance *instance;
|
||||
Iterator iter = kIteratorInit;
|
||||
ExternalRouteConfig rconfig;
|
||||
OnMeshPrefixConfig pconfig;
|
||||
@@ -496,7 +496,7 @@ void TestNetworkDataIterator(void)
|
||||
class TestNetworkData : public Local
|
||||
{
|
||||
public:
|
||||
explicit TestNetworkData(ot::Instance &aInstance)
|
||||
explicit TestNetworkData(Instance &aInstance)
|
||||
: Local(aInstance)
|
||||
{
|
||||
}
|
||||
@@ -583,7 +583,7 @@ public:
|
||||
|
||||
void TestNetworkDataFindNextService(void)
|
||||
{
|
||||
ot::Instance *instance;
|
||||
Instance *instance;
|
||||
|
||||
printf("\n\n-------------------------------------------------");
|
||||
printf("\nTestNetworkDataFindNextService()\n");
|
||||
@@ -616,7 +616,7 @@ void TestNetworkDataDsnSrpServices(void)
|
||||
}
|
||||
};
|
||||
|
||||
ot::Instance *instance;
|
||||
Instance *instance;
|
||||
|
||||
printf("\n\n-------------------------------------------------");
|
||||
printf("\nTestNetworkDataDsnSrpServices()\n");
|
||||
@@ -764,7 +764,7 @@ void TestNetworkDataDsnSrpAnycastSeqNumSelection(void)
|
||||
uint8_t mPreferredSeqNum;
|
||||
};
|
||||
|
||||
ot::Instance *instance;
|
||||
Instance *instance;
|
||||
|
||||
printf("\n\n-------------------------------------------------");
|
||||
printf("\nTestNetworkDataDsnSrpAnycastSeqNumSelection()\n");
|
||||
|
||||
@@ -35,12 +35,14 @@
|
||||
|
||||
#include "test_util.h"
|
||||
|
||||
namespace ot {
|
||||
|
||||
struct EntryBase
|
||||
{
|
||||
EntryBase *mNext;
|
||||
};
|
||||
|
||||
struct Entry : public EntryBase, ot::LinkedListEntry<Entry>
|
||||
struct Entry : public EntryBase, LinkedListEntry<Entry>
|
||||
{
|
||||
public:
|
||||
Entry(void)
|
||||
@@ -48,7 +50,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void Init(ot::Instance &) { mInitWithInstance = true; }
|
||||
void Init(Instance &) { mInitWithInstance = true; }
|
||||
|
||||
bool IsInitializedWithInstance(void) const { return mInitWithInstance; }
|
||||
|
||||
@@ -61,7 +63,7 @@ enum : uint16_t
|
||||
kPoolSize = 11,
|
||||
};
|
||||
|
||||
typedef ot::Pool<Entry, kPoolSize> EntryPool;
|
||||
typedef Pool<Entry, kPoolSize> EntryPool;
|
||||
|
||||
static Entry sNonPoolEntry;
|
||||
|
||||
@@ -118,9 +120,9 @@ void TestPool(EntryPool &aPool, bool aInitWithInstance)
|
||||
|
||||
void TestPool(void)
|
||||
{
|
||||
ot::Instance *instance = testInitInstance();
|
||||
EntryPool pool1;
|
||||
EntryPool pool2(*instance);
|
||||
Instance *instance = testInitInstance();
|
||||
EntryPool pool1;
|
||||
EntryPool pool2(*instance);
|
||||
|
||||
TestPool(pool1, /* aInitWithInstance */ false);
|
||||
TestPool(pool2, /* aInitWithInstance */ true);
|
||||
@@ -128,9 +130,11 @@ void TestPool(void)
|
||||
testFreeInstance(instance);
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TestPool();
|
||||
ot::TestPool();
|
||||
printf("All tests passed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -144,8 +144,8 @@ int main(void)
|
||||
#if OPENTHREAD_CONFIG_POWER_CALIBRATION_ENABLE && OPENTHREAD_CONFIG_PLATFORM_POWER_CALIBRATION_ENABLE
|
||||
ot::TestPowerCalibration();
|
||||
printf("All tests passed\n");
|
||||
#else // OPENTHREAD_CONFIG_POWER_CALIBRATION_ENABLE && OPENTHREAD_CONFIG_PLATFORM_POWER_CALIBRATION_ENABLE
|
||||
#else
|
||||
printf("Power calibration is not enabled\n");
|
||||
#endif // OPENTHREAD_CONFIG_POWER_CALIBRATION_ENABLE && OPENTHREAD_CONFIG_PLATFORM_POWER_CALIBRATION_ENABLE
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -35,19 +35,21 @@
|
||||
#include "test_platform.h"
|
||||
#include "test_util.h"
|
||||
|
||||
namespace ot {
|
||||
|
||||
#define kNumNewPriorityTestMessages 2
|
||||
#define kNumSetPriorityTestMessages 2
|
||||
#define kNumTestMessages (kNumNewPriorityTestMessages + kNumSetPriorityTestMessages)
|
||||
|
||||
// This function verifies the content of the priority queue to match the passed in messages
|
||||
void VerifyPriorityQueueContent(ot::PriorityQueue &aPriorityQueue, int aExpectedLength, ...)
|
||||
void VerifyPriorityQueueContent(PriorityQueue &aPriorityQueue, int aExpectedLength, ...)
|
||||
{
|
||||
const ot::PriorityQueue &constQueue = aPriorityQueue;
|
||||
va_list args;
|
||||
ot::Message *message;
|
||||
ot::Message *msgArg;
|
||||
int8_t curPriority = ot::Message::kNumPriorities;
|
||||
ot::PriorityQueue::Info info;
|
||||
const PriorityQueue &constQueue = aPriorityQueue;
|
||||
va_list args;
|
||||
Message *message;
|
||||
Message *msgArg;
|
||||
int8_t curPriority = Message::kNumPriorities;
|
||||
PriorityQueue::Info info;
|
||||
|
||||
// Check the `GetInfo`
|
||||
memset(&info, 0, sizeof(info));
|
||||
@@ -61,10 +63,10 @@ void VerifyPriorityQueueContent(ot::PriorityQueue &aPriorityQueue, int aExpected
|
||||
message = aPriorityQueue.GetHead();
|
||||
VerifyOrQuit(message == nullptr, "PriorityQueue is not empty when expected len is zero.");
|
||||
|
||||
VerifyOrQuit(aPriorityQueue.GetHeadForPriority(ot::Message::kPriorityLow) == nullptr);
|
||||
VerifyOrQuit(aPriorityQueue.GetHeadForPriority(ot::Message::kPriorityNormal) == nullptr);
|
||||
VerifyOrQuit(aPriorityQueue.GetHeadForPriority(ot::Message::kPriorityHigh) == nullptr);
|
||||
VerifyOrQuit(aPriorityQueue.GetHeadForPriority(ot::Message::kPriorityNet) == nullptr);
|
||||
VerifyOrQuit(aPriorityQueue.GetHeadForPriority(Message::kPriorityLow) == nullptr);
|
||||
VerifyOrQuit(aPriorityQueue.GetHeadForPriority(Message::kPriorityNormal) == nullptr);
|
||||
VerifyOrQuit(aPriorityQueue.GetHeadForPriority(Message::kPriorityHigh) == nullptr);
|
||||
VerifyOrQuit(aPriorityQueue.GetHeadForPriority(Message::kPriorityNet) == nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -73,7 +75,7 @@ void VerifyPriorityQueueContent(ot::PriorityQueue &aPriorityQueue, int aExpected
|
||||
{
|
||||
VerifyOrQuit(aExpectedLength != 0, "PriorityQueue contains more entries than expected.");
|
||||
|
||||
msgArg = va_arg(args, ot::Message *);
|
||||
msgArg = va_arg(args, Message *);
|
||||
|
||||
if (msgArg->GetPriority() != curPriority)
|
||||
{
|
||||
@@ -81,14 +83,13 @@ void VerifyPriorityQueueContent(ot::PriorityQueue &aPriorityQueue, int aExpected
|
||||
{
|
||||
// Check the `GetHeadForPriority` is nullptr if there are no expected message for this priority
|
||||
// level.
|
||||
VerifyOrQuit(aPriorityQueue.GetHeadForPriority(static_cast<ot::Message::Priority>(curPriority)) ==
|
||||
VerifyOrQuit(aPriorityQueue.GetHeadForPriority(static_cast<Message::Priority>(curPriority)) ==
|
||||
nullptr,
|
||||
"is non-nullptr when no expected msg for this priority.");
|
||||
}
|
||||
|
||||
// Check the `GetHeadForPriority`.
|
||||
VerifyOrQuit(aPriorityQueue.GetHeadForPriority(static_cast<ot::Message::Priority>(curPriority)) ==
|
||||
msgArg);
|
||||
VerifyOrQuit(aPriorityQueue.GetHeadForPriority(static_cast<Message::Priority>(curPriority)) == msgArg);
|
||||
}
|
||||
|
||||
// Check the queued message to match the one from argument list
|
||||
@@ -102,7 +103,7 @@ void VerifyPriorityQueueContent(ot::PriorityQueue &aPriorityQueue, int aExpected
|
||||
// Check the `GetHeadForPriority` is nullptr if there are no expected message for any remaining priority level.
|
||||
for (curPriority--; curPriority >= 0; curPriority--)
|
||||
{
|
||||
VerifyOrQuit(aPriorityQueue.GetHeadForPriority(static_cast<ot::Message::Priority>(curPriority)) == nullptr,
|
||||
VerifyOrQuit(aPriorityQueue.GetHeadForPriority(static_cast<Message::Priority>(curPriority)) == nullptr,
|
||||
"is non-nullptr when no expected msg for this priority.");
|
||||
}
|
||||
}
|
||||
@@ -113,7 +114,7 @@ void VerifyPriorityQueueContent(ot::PriorityQueue &aPriorityQueue, int aExpected
|
||||
|
||||
message = aPriorityQueue.GetHead();
|
||||
|
||||
for (ot::Message &msg : aPriorityQueue)
|
||||
for (Message &msg : aPriorityQueue)
|
||||
{
|
||||
VerifyOrQuit(message == &msg, "`for` loop iteration does not match expected");
|
||||
message = message->GetNext();
|
||||
@@ -125,7 +126,7 @@ void VerifyPriorityQueueContent(ot::PriorityQueue &aPriorityQueue, int aExpected
|
||||
|
||||
message = aPriorityQueue.GetHead();
|
||||
|
||||
for (const ot::Message &constMsg : constQueue)
|
||||
for (const Message &constMsg : constQueue)
|
||||
{
|
||||
VerifyOrQuit(message == &constMsg, "`for` loop iteration does not match expected");
|
||||
message = message->GetNext();
|
||||
@@ -135,11 +136,11 @@ void VerifyPriorityQueueContent(ot::PriorityQueue &aPriorityQueue, int aExpected
|
||||
}
|
||||
|
||||
// This function verifies the content of the message queue to match the passed in messages
|
||||
void VerifyMsgQueueContent(ot::MessageQueue &aMessageQueue, int aExpectedLength, ...)
|
||||
void VerifyMsgQueueContent(MessageQueue &aMessageQueue, int aExpectedLength, ...)
|
||||
{
|
||||
va_list args;
|
||||
ot::Message *message;
|
||||
ot::Message *msgArg;
|
||||
va_list args;
|
||||
Message *message;
|
||||
Message *msgArg;
|
||||
|
||||
va_start(args, aExpectedLength);
|
||||
|
||||
@@ -154,7 +155,7 @@ void VerifyMsgQueueContent(ot::MessageQueue &aMessageQueue, int aExpectedLength,
|
||||
{
|
||||
VerifyOrQuit(aExpectedLength != 0, "contains more entries than expected");
|
||||
|
||||
msgArg = va_arg(args, ot::Message *);
|
||||
msgArg = va_arg(args, Message *);
|
||||
VerifyOrQuit(msgArg == message, "content does not match what is expected.");
|
||||
|
||||
aExpectedLength--;
|
||||
@@ -168,58 +169,57 @@ void VerifyMsgQueueContent(ot::MessageQueue &aMessageQueue, int aExpectedLength,
|
||||
|
||||
void TestPriorityQueue(void)
|
||||
{
|
||||
ot::Instance *instance;
|
||||
ot::MessagePool *messagePool;
|
||||
ot::PriorityQueue queue;
|
||||
ot::MessageQueue messageQueue;
|
||||
ot::Message *msgNet[kNumTestMessages];
|
||||
ot::Message *msgHigh[kNumTestMessages];
|
||||
ot::Message *msgNor[kNumTestMessages];
|
||||
ot::Message *msgLow[kNumTestMessages];
|
||||
Instance *instance;
|
||||
MessagePool *messagePool;
|
||||
PriorityQueue queue;
|
||||
MessageQueue messageQueue;
|
||||
Message *msgNet[kNumTestMessages];
|
||||
Message *msgHigh[kNumTestMessages];
|
||||
Message *msgNor[kNumTestMessages];
|
||||
Message *msgLow[kNumTestMessages];
|
||||
|
||||
instance = testInitInstance();
|
||||
VerifyOrQuit(instance != nullptr, "Null OpenThread instance");
|
||||
|
||||
messagePool = &instance->Get<ot::MessagePool>();
|
||||
messagePool = &instance->Get<MessagePool>();
|
||||
|
||||
// Use the function "Allocate()" to allocate messages with different priorities
|
||||
for (int i = 0; i < kNumNewPriorityTestMessages; i++)
|
||||
{
|
||||
msgNet[i] = messagePool->Allocate(ot::Message::kTypeIp6, 0, ot::Message::Settings(ot::Message::kPriorityNet));
|
||||
msgNet[i] = messagePool->Allocate(Message::kTypeIp6, 0, Message::Settings(Message::kPriorityNet));
|
||||
VerifyOrQuit(msgNet[i] != nullptr);
|
||||
msgHigh[i] = messagePool->Allocate(ot::Message::kTypeIp6, 0, ot::Message::Settings(ot::Message::kPriorityHigh));
|
||||
msgHigh[i] = messagePool->Allocate(Message::kTypeIp6, 0, Message::Settings(Message::kPriorityHigh));
|
||||
VerifyOrQuit(msgHigh[i] != nullptr);
|
||||
msgNor[i] =
|
||||
messagePool->Allocate(ot::Message::kTypeIp6, 0, ot::Message::Settings(ot::Message::kPriorityNormal));
|
||||
msgNor[i] = messagePool->Allocate(Message::kTypeIp6, 0, Message::Settings(Message::kPriorityNormal));
|
||||
VerifyOrQuit(msgNor[i] != nullptr);
|
||||
msgLow[i] = messagePool->Allocate(ot::Message::kTypeIp6, 0, ot::Message::Settings(ot::Message::kPriorityLow));
|
||||
msgLow[i] = messagePool->Allocate(Message::kTypeIp6, 0, Message::Settings(Message::kPriorityLow));
|
||||
VerifyOrQuit(msgLow[i] != nullptr);
|
||||
}
|
||||
|
||||
// Use the function "SetPriority()" to allocate messages with different priorities
|
||||
for (int i = kNumNewPriorityTestMessages; i < kNumTestMessages; i++)
|
||||
{
|
||||
msgNet[i] = messagePool->Allocate(ot::Message::kTypeIp6);
|
||||
msgNet[i] = messagePool->Allocate(Message::kTypeIp6);
|
||||
VerifyOrQuit(msgNet[i] != nullptr);
|
||||
SuccessOrQuit(msgNet[i]->SetPriority(ot::Message::kPriorityNet));
|
||||
msgHigh[i] = messagePool->Allocate(ot::Message::kTypeIp6);
|
||||
SuccessOrQuit(msgNet[i]->SetPriority(Message::kPriorityNet));
|
||||
msgHigh[i] = messagePool->Allocate(Message::kTypeIp6);
|
||||
VerifyOrQuit(msgHigh[i] != nullptr);
|
||||
SuccessOrQuit(msgHigh[i]->SetPriority(ot::Message::kPriorityHigh));
|
||||
msgNor[i] = messagePool->Allocate(ot::Message::kTypeIp6);
|
||||
SuccessOrQuit(msgHigh[i]->SetPriority(Message::kPriorityHigh));
|
||||
msgNor[i] = messagePool->Allocate(Message::kTypeIp6);
|
||||
VerifyOrQuit(msgNor[i] != nullptr);
|
||||
SuccessOrQuit(msgNor[i]->SetPriority(ot::Message::kPriorityNormal));
|
||||
msgLow[i] = messagePool->Allocate(ot::Message::kTypeIp6);
|
||||
SuccessOrQuit(msgNor[i]->SetPriority(Message::kPriorityNormal));
|
||||
msgLow[i] = messagePool->Allocate(Message::kTypeIp6);
|
||||
VerifyOrQuit(msgLow[i] != nullptr);
|
||||
SuccessOrQuit(msgLow[i]->SetPriority(ot::Message::kPriorityLow));
|
||||
SuccessOrQuit(msgLow[i]->SetPriority(Message::kPriorityLow));
|
||||
}
|
||||
|
||||
// Check the `GetPriority()`
|
||||
for (int i = 0; i < kNumTestMessages; i++)
|
||||
{
|
||||
VerifyOrQuit(msgLow[i]->GetPriority() == ot::Message::kPriorityLow);
|
||||
VerifyOrQuit(msgNor[i]->GetPriority() == ot::Message::kPriorityNormal);
|
||||
VerifyOrQuit(msgHigh[i]->GetPriority() == ot::Message::kPriorityHigh);
|
||||
VerifyOrQuit(msgNet[i]->GetPriority() == ot::Message::kPriorityNet);
|
||||
VerifyOrQuit(msgLow[i]->GetPriority() == Message::kPriorityLow);
|
||||
VerifyOrQuit(msgNor[i]->GetPriority() == Message::kPriorityNormal);
|
||||
VerifyOrQuit(msgHigh[i]->GetPriority() == Message::kPriorityHigh);
|
||||
VerifyOrQuit(msgNet[i]->GetPriority() == Message::kPriorityNet);
|
||||
}
|
||||
|
||||
// Verify case of an empty queue.
|
||||
@@ -272,18 +272,18 @@ void TestPriorityQueue(void)
|
||||
queue.Enqueue(*msgLow[0]);
|
||||
VerifyPriorityQueueContent(queue, 3, msgHigh[0], msgNor[0], msgLow[0]);
|
||||
|
||||
SuccessOrQuit(msgNor[0]->SetPriority(ot::Message::kPriorityNet));
|
||||
SuccessOrQuit(msgNor[0]->SetPriority(Message::kPriorityNet));
|
||||
VerifyPriorityQueueContent(queue, 3, msgNor[0], msgHigh[0], msgLow[0]);
|
||||
SuccessOrQuit(msgLow[0]->SetPriority(ot::Message::kPriorityLow));
|
||||
SuccessOrQuit(msgLow[0]->SetPriority(Message::kPriorityLow));
|
||||
VerifyPriorityQueueContent(queue, 3, msgNor[0], msgHigh[0], msgLow[0]);
|
||||
SuccessOrQuit(msgLow[0]->SetPriority(ot::Message::kPriorityNormal));
|
||||
SuccessOrQuit(msgLow[0]->SetPriority(Message::kPriorityNormal));
|
||||
VerifyPriorityQueueContent(queue, 3, msgNor[0], msgHigh[0], msgLow[0]);
|
||||
SuccessOrQuit(msgLow[0]->SetPriority(ot::Message::kPriorityHigh));
|
||||
SuccessOrQuit(msgLow[0]->SetPriority(Message::kPriorityHigh));
|
||||
VerifyPriorityQueueContent(queue, 3, msgNor[0], msgHigh[0], msgLow[0]);
|
||||
SuccessOrQuit(msgLow[0]->SetPriority(ot::Message::kPriorityNet));
|
||||
SuccessOrQuit(msgLow[0]->SetPriority(Message::kPriorityNet));
|
||||
VerifyPriorityQueueContent(queue, 3, msgNor[0], msgLow[0], msgHigh[0]);
|
||||
SuccessOrQuit(msgNor[0]->SetPriority(ot::Message::kPriorityNormal));
|
||||
SuccessOrQuit(msgLow[0]->SetPriority(ot::Message::kPriorityLow));
|
||||
SuccessOrQuit(msgNor[0]->SetPriority(Message::kPriorityNormal));
|
||||
SuccessOrQuit(msgLow[0]->SetPriority(Message::kPriorityLow));
|
||||
VerifyPriorityQueueContent(queue, 3, msgHigh[0], msgNor[0], msgLow[0]);
|
||||
|
||||
messageQueue.Enqueue(*msgNor[1]);
|
||||
@@ -292,10 +292,10 @@ void TestPriorityQueue(void)
|
||||
VerifyMsgQueueContent(messageQueue, 3, msgNor[1], msgHigh[1], msgNet[1]);
|
||||
|
||||
// Change priority of message and check for not in messageQueue.
|
||||
SuccessOrQuit(msgNor[1]->SetPriority(ot::Message::kPriorityNet));
|
||||
SuccessOrQuit(msgNor[1]->SetPriority(Message::kPriorityNet));
|
||||
VerifyMsgQueueContent(messageQueue, 3, msgNor[1], msgHigh[1], msgNet[1]);
|
||||
|
||||
SuccessOrQuit(msgLow[0]->SetPriority(ot::Message::kPriorityHigh));
|
||||
SuccessOrQuit(msgLow[0]->SetPriority(Message::kPriorityHigh));
|
||||
VerifyPriorityQueueContent(queue, 3, msgHigh[0], msgLow[0], msgNor[0]);
|
||||
VerifyMsgQueueContent(messageQueue, 3, msgNor[1], msgHigh[1], msgNet[1]);
|
||||
|
||||
@@ -321,9 +321,9 @@ void TestPriorityQueue(void)
|
||||
messageQueue.Dequeue(*msgNor[1]);
|
||||
VerifyMsgQueueContent(messageQueue, 0);
|
||||
|
||||
for (ot::Message *message : msgNor)
|
||||
for (Message *message : msgNor)
|
||||
{
|
||||
SuccessOrQuit(message->SetPriority(ot::Message::kPriorityNormal));
|
||||
SuccessOrQuit(message->SetPriority(Message::kPriorityNormal));
|
||||
}
|
||||
|
||||
// Range-based `for` and dequeue during iteration
|
||||
@@ -339,7 +339,7 @@ void TestPriorityQueue(void)
|
||||
VerifyPriorityQueueContent(queue, 4, msgNor[0], msgNor[1], msgNor[2], msgNor[3]);
|
||||
|
||||
// While iterating over the queue remove the entry at `removeIndex`
|
||||
for (ot::Message &message : queue)
|
||||
for (Message &message : queue)
|
||||
{
|
||||
if (index == removeIndex)
|
||||
{
|
||||
@@ -352,7 +352,7 @@ void TestPriorityQueue(void)
|
||||
index = 0;
|
||||
|
||||
// Iterate over the queue and remove all
|
||||
for (ot::Message &message : queue)
|
||||
for (Message &message : queue)
|
||||
{
|
||||
if (index == removeIndex)
|
||||
{
|
||||
@@ -369,9 +369,11 @@ void TestPriorityQueue(void)
|
||||
testFreeInstance(instance);
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TestPriorityQueue();
|
||||
ot::TestPriorityQueue();
|
||||
printf("All tests passed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
+12
-12
@@ -33,6 +33,8 @@
|
||||
#include "test_platform.h"
|
||||
#include "test_util.h"
|
||||
|
||||
namespace ot {
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
|
||||
void TestMinimumPassphrase(void)
|
||||
@@ -97,21 +99,19 @@ void TestExampleInSpec(void)
|
||||
testFreeInstance(instance);
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
#endif // OPENTHREAD_FTD
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TestMinimumPassphrase();
|
||||
TestMaximumPassphrase();
|
||||
TestExampleInSpec();
|
||||
#if OPENTHREAD_FTD
|
||||
ot::TestMinimumPassphrase();
|
||||
ot::TestMaximumPassphrase();
|
||||
ot::TestExampleInSpec();
|
||||
printf("All tests passed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else // #if OPENTHREAD_FTD
|
||||
|
||||
int main(void)
|
||||
{
|
||||
#else
|
||||
printf("PSKc generation is not supported on non-ftd build\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // #if OPENTHREAD_FTD
|
||||
|
||||
@@ -43,9 +43,9 @@
|
||||
#include "net/icmp6.hpp"
|
||||
#include "net/nd6.hpp"
|
||||
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
namespace ot {
|
||||
|
||||
using namespace ot;
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
|
||||
// Logs a message and adds current time (sNow) as "<hours>:<min>:<secs>.<msec>"
|
||||
#define Log(...) \
|
||||
@@ -111,7 +111,7 @@ static constexpr otOperationalDataset kDataset = {
|
||||
},
|
||||
};
|
||||
|
||||
static ot::Instance *sInstance;
|
||||
static Instance *sInstance;
|
||||
|
||||
static uint32_t sNow = 0;
|
||||
static uint32_t sAlarmTime;
|
||||
@@ -3553,31 +3553,33 @@ void TestBorderRoutingProcessPlatfromGeneratedNd(void)
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||
TestSamePrefixesFromMultipleRouters();
|
||||
TestOmrSelection();
|
||||
TestDefaultRoute();
|
||||
TestAdvNonUlaRoute();
|
||||
TestLocalOnLinkPrefixDeprecation();
|
||||
ot::TestSamePrefixesFromMultipleRouters();
|
||||
ot::TestOmrSelection();
|
||||
ot::TestDefaultRoute();
|
||||
ot::TestAdvNonUlaRoute();
|
||||
ot::TestLocalOnLinkPrefixDeprecation();
|
||||
#if OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE
|
||||
TestDomainPrefixAsOmr();
|
||||
ot::TestDomainPrefixAsOmr();
|
||||
#endif
|
||||
TestExtPanIdChange();
|
||||
TestConflictingPrefix();
|
||||
TestRouterNsProbe();
|
||||
ot::TestExtPanIdChange();
|
||||
ot::TestConflictingPrefix();
|
||||
ot::TestRouterNsProbe();
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE
|
||||
TestSavedOnLinkPrefixes();
|
||||
ot::TestSavedOnLinkPrefixes();
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_SRP_SERVER_ENABLE
|
||||
TestAutoEnableOfSrpServer();
|
||||
ot::TestAutoEnableOfSrpServer();
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE
|
||||
TestNat64PrefixSelection();
|
||||
ot::TestNat64PrefixSelection();
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_DHCP6_PD_ENABLE
|
||||
TestBorderRoutingProcessPlatfromGeneratedNd();
|
||||
ot::TestBorderRoutingProcessPlatfromGeneratedNd();
|
||||
#endif // OPENTHREAD_CONFIG_BORDER_ROUTING_DHCP6_PD_ENABLE
|
||||
|
||||
printf("All tests passed\n");
|
||||
|
||||
@@ -57,8 +57,8 @@ static const uint8_t sMottoText[] = "Think good thoughts, say good words, d
|
||||
static const uint8_t sMysteryText[] = "4871(\\):|(3$}{4|/4/2%14(\\)";
|
||||
static const uint8_t sHexText[] = "0123456789abcdef";
|
||||
|
||||
static ot::Instance *sInstance;
|
||||
static MessagePool *sMessagePool;
|
||||
static Instance *sInstance;
|
||||
static MessagePool *sMessagePool;
|
||||
|
||||
struct CallbackContext
|
||||
{
|
||||
|
||||
@@ -49,9 +49,9 @@
|
||||
#define ENABLE_SRP_TEST 0
|
||||
#endif
|
||||
|
||||
#if ENABLE_SRP_TEST
|
||||
namespace ot {
|
||||
|
||||
using namespace ot;
|
||||
#if ENABLE_SRP_TEST
|
||||
|
||||
// Logs a message and adds current time (sNow) as "<hours>:<min>:<secs>.<msec>"
|
||||
#define Log(...) \
|
||||
@@ -60,7 +60,7 @@ using namespace ot;
|
||||
|
||||
static constexpr uint16_t kMaxRaSize = 800;
|
||||
|
||||
static ot::Instance *sInstance;
|
||||
static Instance *sInstance;
|
||||
|
||||
static uint32_t sNow = 0;
|
||||
static uint32_t sAlarmTime;
|
||||
@@ -1028,16 +1028,18 @@ void TestUpdateLeaseShortVariant(void)
|
||||
|
||||
#endif // ENABLE_SRP_TEST
|
||||
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
#if ENABLE_SRP_TEST
|
||||
TestSrpServerBase();
|
||||
TestSrpServerReject();
|
||||
TestSrpServerIgnore();
|
||||
TestSrpServerClientRemove(/* aShouldRemoveKeyLease */ true);
|
||||
TestSrpServerClientRemove(/* aShouldRemoveKeyLease */ false);
|
||||
ot::TestSrpServerBase();
|
||||
ot::TestSrpServerReject();
|
||||
ot::TestSrpServerIgnore();
|
||||
ot::TestSrpServerClientRemove(/* aShouldRemoveKeyLease */ true);
|
||||
ot::TestSrpServerClientRemove(/* aShouldRemoveKeyLease */ false);
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
TestUpdateLeaseShortVariant();
|
||||
ot::TestUpdateLeaseShortVariant();
|
||||
#endif
|
||||
printf("All tests passed\n");
|
||||
#else
|
||||
|
||||
+27
-23
@@ -35,6 +35,8 @@
|
||||
#include "common/timer.hpp"
|
||||
#include "instance/instance.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
enum
|
||||
{
|
||||
kCallCountIndexAlarmStop = 0,
|
||||
@@ -91,19 +93,19 @@ uint32_t otPlatAlarmMicroGetNow(void) { return sNow; }
|
||||
void InitCounters(void) { memset(sCallCount, 0, sizeof(sCallCount)); }
|
||||
|
||||
/**
|
||||
* `TestTimer` sub-classes `ot::TimerMilli` and provides a handler and a counter to keep track of number of times timer
|
||||
* `TestTimer` sub-classes `TimerMilli` and provides a handler and a counter to keep track of number of times timer
|
||||
* gets fired.
|
||||
*/
|
||||
template <typename TimerType> class TestTimer : public TimerType
|
||||
{
|
||||
public:
|
||||
explicit TestTimer(ot::Instance &aInstance)
|
||||
explicit TestTimer(Instance &aInstance)
|
||||
: TimerType(aInstance, TestTimer::HandleTimerFired)
|
||||
, mFiredCounter(0)
|
||||
{
|
||||
}
|
||||
|
||||
static void HandleTimerFired(ot::Timer &aTimer) { static_cast<TestTimer &>(aTimer).HandleTimerFired(); }
|
||||
static void HandleTimerFired(Timer &aTimer) { static_cast<TestTimer &>(aTimer).HandleTimerFired(); }
|
||||
|
||||
void HandleTimerFired(void)
|
||||
{
|
||||
@@ -115,7 +117,7 @@ public:
|
||||
|
||||
void ResetFiredCounter(void) { mFiredCounter = 0; }
|
||||
|
||||
static void RemoveAll(ot::Instance &aInstance) { TimerType::RemoveAll(aInstance); }
|
||||
static void RemoveAll(Instance &aInstance) { TimerType::RemoveAll(aInstance); }
|
||||
|
||||
private:
|
||||
uint32_t mFiredCounter; //< Number of times timer has been fired so far
|
||||
@@ -123,10 +125,10 @@ private:
|
||||
|
||||
template <typename TimerType> void AlarmFired(otInstance *aInstance);
|
||||
|
||||
template <> void AlarmFired<ot::TimerMilli>(otInstance *aInstance) { otPlatAlarmMilliFired(aInstance); }
|
||||
template <> void AlarmFired<TimerMilli>(otInstance *aInstance) { otPlatAlarmMilliFired(aInstance); }
|
||||
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
|
||||
template <> void AlarmFired<ot::TimerMicro>(otInstance *aInstance) { otPlatAlarmMicroFired(aInstance); }
|
||||
template <> void AlarmFired<TimerMicro>(otInstance *aInstance) { otPlatAlarmMicroFired(aInstance); }
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -136,7 +138,7 @@ template <typename TimerType> int TestOneTimer(void)
|
||||
{
|
||||
const uint32_t kTimeT0 = 1000;
|
||||
const uint32_t kTimerInterval = 10;
|
||||
ot::Instance *instance = testInitInstance();
|
||||
Instance *instance = testInitInstance();
|
||||
TestTimer<TimerType> timer(*instance);
|
||||
|
||||
// Test one Timer basic operation.
|
||||
@@ -262,7 +264,7 @@ template <typename TimerType> int TestTwoTimers(void)
|
||||
{
|
||||
const uint32_t kTimeT0 = 1000;
|
||||
const uint32_t kTimerInterval = 10;
|
||||
ot::Instance *instance = testInitInstance();
|
||||
Instance *instance = testInitInstance();
|
||||
TestTimer<TimerType> timer1(*instance);
|
||||
TestTimer<TimerType> timer2(*instance);
|
||||
|
||||
@@ -338,7 +340,7 @@ template <typename TimerType> int TestTwoTimers(void)
|
||||
|
||||
sNow += kTimerInterval;
|
||||
|
||||
timer2.StartAt(ot::TimeMilli(kTimeT0), kTimerInterval - 2); // Timer 2 is even before timer 1
|
||||
timer2.StartAt(TimeMilli(kTimeT0), kTimerInterval - 2); // Timer 2 is even before timer 1
|
||||
|
||||
VerifyOrQuit(sCallCount[kCallCountIndexTimerHandler] == 0, "Handler CallCount Failed.");
|
||||
VerifyOrQuit(timer1.IsRunning() == true, "Timer running Failed.");
|
||||
@@ -385,7 +387,7 @@ template <typename TimerType> int TestTwoTimers(void)
|
||||
|
||||
sNow += kTimerInterval + 5;
|
||||
|
||||
timer2.Start(ot::Timer::kMaxDelay);
|
||||
timer2.Start(Timer::kMaxDelay);
|
||||
|
||||
VerifyOrQuit(sCallCount[kCallCountIndexAlarmStart] == 1, "Start CallCount Failed.");
|
||||
VerifyOrQuit(sCallCount[kCallCountIndexAlarmStop] == 0, "Stop CallCount Failed.");
|
||||
@@ -401,12 +403,12 @@ template <typename TimerType> int TestTwoTimers(void)
|
||||
VerifyOrQuit(sCallCount[kCallCountIndexTimerHandler] == 1, "Handler CallCount Failed.");
|
||||
VerifyOrQuit(timer1.GetFiredCounter() == 1, "Fire Counter failed.");
|
||||
VerifyOrQuit(sPlatT0 == sNow, "Start params Failed.");
|
||||
VerifyOrQuit(sPlatDt == ot::Timer::kMaxDelay, "Start params Failed.");
|
||||
VerifyOrQuit(sPlatDt == Timer::kMaxDelay, "Start params Failed.");
|
||||
VerifyOrQuit(timer1.IsRunning() == false, "Timer running Failed.");
|
||||
VerifyOrQuit(timer2.IsRunning() == true, "Timer running Failed.");
|
||||
VerifyOrQuit(sTimerOn == true, "Platform Timer State Failed.");
|
||||
|
||||
sNow += ot::Timer::kMaxDelay;
|
||||
sNow += Timer::kMaxDelay;
|
||||
AlarmFired<TimerType>(instance);
|
||||
|
||||
VerifyOrQuit(sCallCount[kCallCountIndexAlarmStart] == 2, "Start CallCount Failed.");
|
||||
@@ -436,7 +438,7 @@ template <typename TimerType> static void TenTimers(uint32_t aTimeShift)
|
||||
const uint32_t kNumTriggers = 7;
|
||||
const uint32_t kTimeT0[kNumTimers] = {1000, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008};
|
||||
const uint32_t kTimerInterval[kNumTimers] = {
|
||||
20, 100, (ot::Timer::kMaxDelay - kTimeT0[2]), 100000, 1000000, 10, ot::Timer::kMaxDelay, 200, 200, 200};
|
||||
20, 100, (Timer::kMaxDelay - kTimeT0[2]), 100000, 1000000, 10, Timer::kMaxDelay, 200, 200, 200};
|
||||
// Expected timer fire order
|
||||
// timer # Trigger time
|
||||
// 5 1014
|
||||
@@ -450,7 +452,7 @@ template <typename TimerType> static void TenTimers(uint32_t aTimeShift)
|
||||
// 2 kMaxDuration
|
||||
// 6 kMaxDuration + 1005
|
||||
const uint32_t kTriggerTimes[kNumTriggers] = {
|
||||
1014, 1020, 1100, 1207, 101004, ot::Timer::kMaxDelay, ot::Timer::kMaxDelay + kTimeT0[6]};
|
||||
1014, 1020, 1100, 1207, 101004, Timer::kMaxDelay, Timer::kMaxDelay + kTimeT0[6]};
|
||||
// Expected timers fired by each kTriggerTimes[] value
|
||||
// Trigger # Timers Fired
|
||||
// 0 5
|
||||
@@ -478,7 +480,7 @@ template <typename TimerType> static void TenTimers(uint32_t aTimeShift)
|
||||
|
||||
const uint32_t kTimerStartCountAfterTrigger[kNumTriggers] = {3, 4, 5, 7, 9, 11, 11};
|
||||
|
||||
ot::Instance *instance = testInitInstance();
|
||||
Instance *instance = testInitInstance();
|
||||
|
||||
TestTimer<TimerType> timer0(*instance);
|
||||
TestTimer<TimerType> timer1(*instance);
|
||||
@@ -567,12 +569,12 @@ template <typename TimerType> int TestTenTimers(void)
|
||||
{
|
||||
// Time shift to change the start/fire time of ten timers.
|
||||
const uint32_t kTimeShift[] = {
|
||||
0, 100000U, 0U - 1U, 0U - 1100U, ot::Timer::kMaxDelay, ot::Timer::kMaxDelay + 1020U,
|
||||
0, 100000U, 0U - 1U, 0U - 1100U, Timer::kMaxDelay, Timer::kMaxDelay + 1020U,
|
||||
};
|
||||
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < ot::GetArrayLength(kTimeShift); i++)
|
||||
for (i = 0; i < GetArrayLength(kTimeShift); i++)
|
||||
{
|
||||
TenTimers<TimerType>(kTimeShift[i]);
|
||||
}
|
||||
@@ -587,10 +589,10 @@ int TestTimerTime(void)
|
||||
{
|
||||
const uint32_t kMaxTime = 0xffffffff;
|
||||
const uint32_t kStartTimes[] = {0, 100, kMaxTime / 2, kMaxTime - 100, kMaxTime};
|
||||
const uint32_t kDurations[] = {1, 100, ot::Timer::kMaxDelay - 1, ot::Timer::kMaxDelay};
|
||||
const uint32_t kDurations[] = {1, 100, Timer::kMaxDelay - 1, Timer::kMaxDelay};
|
||||
|
||||
ot::Time t1;
|
||||
ot::Time t2;
|
||||
Time t1;
|
||||
Time t2;
|
||||
|
||||
for (uint32_t startTime : kStartTimes)
|
||||
{
|
||||
@@ -680,13 +682,15 @@ template <typename TimerType> void RunTimerTests(void)
|
||||
TestTenTimers<TimerType>();
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
RunTimerTests<ot::TimerMilli>();
|
||||
ot::RunTimerTests<ot::TimerMilli>();
|
||||
#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
|
||||
RunTimerTests<ot::TimerMicro>();
|
||||
ot::RunTimerTests<ot::TimerMicro>();
|
||||
#endif
|
||||
TestTimerTime();
|
||||
ot::TestTimerTime();
|
||||
printf("All tests passed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#include "test_util.h"
|
||||
#include "thread/neighbor.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
extern "C" {
|
||||
uint32_t otNetifAddress_Size_c();
|
||||
uint32_t otNetifAddress_offset_mNext_c();
|
||||
@@ -95,11 +97,11 @@ void test_packed_union(void)
|
||||
|
||||
void test_packed_enum(void)
|
||||
{
|
||||
ot::Neighbor neighbor;
|
||||
neighbor.SetState(ot::Neighbor::kStateValid);
|
||||
Neighbor neighbor;
|
||||
neighbor.SetState(Neighbor::kStateValid);
|
||||
|
||||
// Make sure that when we read the 3 bit field it is read as unsigned, so it return '4'
|
||||
VerifyOrQuit(neighbor.GetState() == ot::Neighbor::kStateValid, "OT_TOOL_PACKED failed 4");
|
||||
VerifyOrQuit(neighbor.GetState() == Neighbor::kStateValid, "OT_TOOL_PACKED failed 4");
|
||||
}
|
||||
|
||||
void test_addr_sizes(void)
|
||||
@@ -171,9 +173,11 @@ void TestToolchain(void)
|
||||
test_packed_alignment();
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TestToolchain();
|
||||
ot::TestToolchain();
|
||||
printf("All tests passed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,9 @@
|
||||
#include "common/trickle_timer.hpp"
|
||||
#include "instance/instance.hpp"
|
||||
|
||||
static ot::Instance *sInstance;
|
||||
namespace ot {
|
||||
|
||||
static Instance *sInstance;
|
||||
|
||||
static uint32_t sNow = 0;
|
||||
static uint32_t sAlarmTime;
|
||||
@@ -54,8 +56,6 @@ uint32_t otPlatAlarmMilliGetNow(void) { return sNow; }
|
||||
|
||||
} // extern "C"
|
||||
|
||||
namespace ot {
|
||||
|
||||
void AdvanceTime(uint32_t aDuration)
|
||||
{
|
||||
uint32_t time = sNow + aDuration;
|
||||
|
||||
+20
-20
@@ -36,8 +36,8 @@ namespace Url {
|
||||
|
||||
void TestSimple(void)
|
||||
{
|
||||
char url[] = "spinel:///dev/ttyUSB0?baudrate=115200";
|
||||
ot::Url::Url args;
|
||||
char url[] = "spinel:///dev/ttyUSB0?baudrate=115200";
|
||||
Url args;
|
||||
|
||||
VerifyOrQuit(!args.Init(url));
|
||||
|
||||
@@ -53,8 +53,8 @@ void TestSimple(void)
|
||||
|
||||
void TestSimpleNoQueryString(void)
|
||||
{
|
||||
char url[] = "spinel:///dev/ttyUSB0";
|
||||
ot::Url::Url args;
|
||||
char url[] = "spinel:///dev/ttyUSB0";
|
||||
Url args;
|
||||
|
||||
VerifyOrQuit(!args.Init(url));
|
||||
VerifyOrQuit(!strcmp(args.GetPath(), "/dev/ttyUSB0"));
|
||||
@@ -67,9 +67,9 @@ void TestSimpleNoQueryString(void)
|
||||
|
||||
void TestEmptyValue(void)
|
||||
{
|
||||
char url[] = "spinel:///dev/ttyUSB0?rtscts&baudrate=115200&verbose&verbose&verbose";
|
||||
ot::Url::Url args;
|
||||
const char *arg = nullptr;
|
||||
char url[] = "spinel:///dev/ttyUSB0?rtscts&baudrate=115200&verbose&verbose&verbose";
|
||||
Url args;
|
||||
const char *arg = nullptr;
|
||||
|
||||
VerifyOrQuit(!args.Init(url));
|
||||
VerifyOrQuit(!strcmp(args.GetPath(), "/dev/ttyUSB0"));
|
||||
@@ -85,8 +85,8 @@ void TestEmptyValue(void)
|
||||
|
||||
void TestMultipleProtocols(void)
|
||||
{
|
||||
char url[] = "spinel+spi:///dev/ttyUSB0?baudrate=115200";
|
||||
ot::Url::Url args;
|
||||
char url[] = "spinel+spi:///dev/ttyUSB0?baudrate=115200";
|
||||
Url args;
|
||||
|
||||
VerifyOrQuit(!args.Init(url));
|
||||
VerifyOrQuit(!strcmp(args.GetPath(), "/dev/ttyUSB0"));
|
||||
@@ -97,9 +97,9 @@ void TestMultipleProtocols(void)
|
||||
|
||||
void TestMultipleProtocolsAndDuplicateParameters(void)
|
||||
{
|
||||
char url[] = "spinel+exec:///path/to/ot-rcp?arg=1&arg=arg2&arg=3";
|
||||
ot::Url::Url args;
|
||||
const char *arg = nullptr;
|
||||
char url[] = "spinel+exec:///path/to/ot-rcp?arg=1&arg=arg2&arg=3";
|
||||
Url args;
|
||||
const char *arg = nullptr;
|
||||
|
||||
VerifyOrQuit(!args.Init(url));
|
||||
VerifyOrQuit(!strcmp(args.GetPath(), "/path/to/ot-rcp"));
|
||||
@@ -126,10 +126,10 @@ void TestIntValue(void)
|
||||
char int16url[] = "spinel:///dev/ttyUSB0?val1=1&val2=0x02&val3=-0X03&val4=-400&val5=+500&val6=32768&val7=-32769";
|
||||
char int32url[] =
|
||||
"spinel:///dev/ttyUSB0?val1=1&val2=0x02&val3=-0X03&val4=-40000&val5=+50000&val6=2147483648&val7=-2147483649";
|
||||
ot::Url::Url args;
|
||||
int8_t int8val;
|
||||
int16_t int16val;
|
||||
int32_t int32val;
|
||||
Url args;
|
||||
int8_t int8val;
|
||||
int16_t int16val;
|
||||
int32_t int32val;
|
||||
|
||||
VerifyOrQuit(!args.Init(int8url));
|
||||
VerifyOrQuit(!strcmp(args.GetPath(), "/dev/ttyUSB0"));
|
||||
@@ -199,10 +199,10 @@ void TestUintValue(void)
|
||||
char uint16url[] = "spinel:///dev/ttyUSB0?val1=1&val2=0x02&val3=0X03&val4=-400&val5=+500&val6=65536&val7=-1";
|
||||
char uint32url[] =
|
||||
"spinel:///dev/ttyUSB0?val1=1&val2=0x02&val3=0X03&val4=-40000&val5=+70000&val6=4294967296&val7=-1";
|
||||
ot::Url::Url args;
|
||||
uint8_t uint8val;
|
||||
uint16_t uint16val;
|
||||
uint32_t uint32val;
|
||||
Url args;
|
||||
uint8_t uint8val;
|
||||
uint16_t uint16val;
|
||||
uint32_t uint32val;
|
||||
|
||||
VerifyOrQuit(!args.Init(uint8url));
|
||||
VerifyOrQuit(!strcmp(args.GetPath(), "/dev/ttyUSB0"));
|
||||
|
||||
Reference in New Issue
Block a user