mirror of
https://github.com/espressif/openthread.git
synced 2026-08-26 12:11:17 +00:00
[nexus] add AddTestVar flavor for uint values (#12813)
This commit adds a new `AddTestVar` overload that accepts a `uint32_t` value, simplifying the addition of numeric test variables in Nexus tests. Previously, adding a numeric test variable required manual string formatting using a local `String` object. The new flavor handles the uint to string conversion internally. The change also introduces a `NewTestVar` private helper method in the `Core` class to consolidate the logic for creating and initializing a new `TestVar` entry. Various Nexus test cases are updated to use the new `AddTestVar` flavor, removing redundant string formatting code.
This commit is contained in:
@@ -295,12 +295,22 @@ exit:
|
||||
|
||||
void Core::AddNetworkKey(const NetworkKey &aKey) { SuccessOrQuit(mNetworkKeys.PushBack(aKey)); }
|
||||
|
||||
void Core::AddTestVar(const char *aName, const char *aValue)
|
||||
Core::TestVar &Core::NewTestVar(const char *aName)
|
||||
{
|
||||
TestVar *var = mTestVars.PushBack();
|
||||
|
||||
VerifyOrQuit(var != nullptr);
|
||||
var->mName.Clear().Append("%s", aName);
|
||||
var->mValue.Clear().Append("%s", aValue);
|
||||
var->mValue.Clear();
|
||||
|
||||
return *var;
|
||||
}
|
||||
|
||||
void Core::AddTestVar(const char *aName, const char *aValue) { NewTestVar(aName).mValue.Append("%s", aValue); }
|
||||
|
||||
void Core::AddTestVar(const char *aName, uint32_t aUintValue)
|
||||
{
|
||||
NewTestVar(aName).mValue.Append("%lu", ToUlong(aUintValue));
|
||||
}
|
||||
|
||||
void Core::AddOmrPrefixTestVar(const char *aName, Node &aNode)
|
||||
|
||||
@@ -66,6 +66,7 @@ public:
|
||||
void SaveTestInfo(const char *aFilename, Node *aLeaderNode = nullptr);
|
||||
void AddNetworkKey(const NetworkKey &aKey);
|
||||
void AddTestVar(const char *aName, const char *aValue);
|
||||
void AddTestVar(const char *aName, uint32_t aValue);
|
||||
void AddOmrPrefixTestVar(const char *aName, Node &aNode);
|
||||
void SendAndVerifyEchoRequest(Node &aSender,
|
||||
const Ip6::Address &aDestination,
|
||||
@@ -106,6 +107,8 @@ private:
|
||||
String<64> mValue;
|
||||
};
|
||||
|
||||
TestVar &NewTestVar(const char *aName);
|
||||
|
||||
void Process(Node &aNode);
|
||||
void ProcessRadio(Node &aNode);
|
||||
void ProcessInfraIf(Node &aNode);
|
||||
|
||||
@@ -157,11 +157,7 @@ void TestMatnTc22(void)
|
||||
VerifyOrQuit(br1.Get<BackboneRouter::Local>().IsPrimary());
|
||||
|
||||
nexus.AddTestVar("MA1", kMA1);
|
||||
{
|
||||
String<16> timeoutString;
|
||||
timeoutString.Append("%lu", ToUlong(kMlrTimeoutMin));
|
||||
nexus.AddTestVar("MLR_TIMEOUT_MIN", timeoutString.AsCString());
|
||||
}
|
||||
nexus.AddTestVar("MLR_TIMEOUT_MIN", kMlrTimeoutMin);
|
||||
|
||||
SuccessOrQuit(dut1.Get<Ip6::Netif>().SubscribeExternalMulticast(ma1));
|
||||
SuccessOrQuit(dut2.Get<Ip6::Netif>().SubscribeExternalMulticast(ma1));
|
||||
|
||||
@@ -143,12 +143,7 @@ void TestMatnTc23(void)
|
||||
VerifyOrQuit(br2.Get<BackboneRouter::Local>().GetState() == BackboneRouter::Local::kStateSecondary);
|
||||
|
||||
nexus.AddTestVar("MA1", kMulticastAddr1);
|
||||
{
|
||||
String<16> timeoutStr;
|
||||
|
||||
timeoutStr.Append("%u", kMlrTimeout);
|
||||
nexus.AddTestVar("MLR_TIMEOUT", timeoutStr.AsCString());
|
||||
}
|
||||
nexus.AddTestVar("MLR_TIMEOUT", kMlrTimeout);
|
||||
|
||||
/**
|
||||
* Step 1
|
||||
|
||||
@@ -195,11 +195,7 @@ void TestMatnTc5(void)
|
||||
// Add multicast variables to test info manually to ensure verify script sees them.
|
||||
nexus.AddTestVar("MA1", kMA1);
|
||||
nexus.AddTestVar("HOST_ULA", hostUla->ToString().AsCString());
|
||||
{
|
||||
String<16> timeoutString;
|
||||
timeoutString.Append("%lu", ToUlong(kMlrTimeoutMin));
|
||||
nexus.AddTestVar("MLR_TIMEOUT_MIN", timeoutString.AsCString());
|
||||
}
|
||||
nexus.AddTestVar("MLR_TIMEOUT_MIN", kMlrTimeoutMin);
|
||||
|
||||
/**
|
||||
* Step 1
|
||||
|
||||
@@ -202,10 +202,7 @@ void Test_1_3_SRPC_TC_1(const char *aJsonFileName)
|
||||
br1.Get<Srp::Server>().SetEnabled(true);
|
||||
nexus.AdvanceTime(kStabilizationTime);
|
||||
|
||||
/** Add SRP port to test variables for Python script. */
|
||||
String<6> portString;
|
||||
portString.Append("%u", br1.Get<Srp::Server>().GetPort());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", portString.AsCString());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", br1.Get<Srp::Server>().GetPort());
|
||||
|
||||
Log("---------------------------------------------------------------------------------------");
|
||||
Log("Step 4: ED 1 (DUT) Harness instructs DUT to add a service to the device.");
|
||||
@@ -286,9 +283,7 @@ void Test_1_3_SRPC_TC_1(const char *aJsonFileName)
|
||||
br2.Get<Srp::Server>().SetEnabled(true);
|
||||
nexus.AdvanceTime(30 * 1000);
|
||||
|
||||
/** Add SRP port to test variables for Python script. */
|
||||
portString.Clear().Append("%u", br2.Get<Srp::Server>().GetPort());
|
||||
nexus.AddTestVar("BR_2_SRP_PORT", portString.AsCString());
|
||||
nexus.AddTestVar("BR_2_SRP_PORT", br2.Get<Srp::Server>().GetPort());
|
||||
|
||||
Log("---------------------------------------------------------------------------------------");
|
||||
Log("Step 8: BR 1 Harness deactivates the device.");
|
||||
|
||||
@@ -182,10 +182,7 @@ void Test_1_3_SRPC_TC_4(const char *aJsonFileName)
|
||||
nexus.AddTestVar("BR_1_MLEID_ADDR", br1.Get<Mle::Mle>().GetMeshLocalEid().ToString().AsCString());
|
||||
nexus.AddTestVar("TD_1_MLEID_ADDR", td1.Get<Mle::Mle>().GetMeshLocalEid().ToString().AsCString());
|
||||
nexus.AddTestVar("TD_1_OMR_ADDR", td1.FindGlobalAddress().ToString().AsCString());
|
||||
|
||||
String<6> portString;
|
||||
portString.Append("%u", br1.Get<Srp::Server>().GetPort());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", portString.AsCString());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", br1.Get<Srp::Server>().GetPort());
|
||||
|
||||
Log("---------------------------------------------------------------------------------------");
|
||||
Log("Step 4: Device: TD 1 (DUT) Description (SRPC-3.4): Harness instructs device to register a new service");
|
||||
|
||||
@@ -151,10 +151,7 @@ void Test_1_3_SRPC_TC_7(const char *aJsonFileName)
|
||||
nexus.AddTestVar("BR_1_MLEID_ADDR", br1.Get<Mle::Mle>().GetMeshLocalEid().ToString().AsCString());
|
||||
nexus.AddTestVar("TD_1_MLEID_ADDR", td1.Get<Mle::Mle>().GetMeshLocalEid().ToString().AsCString());
|
||||
nexus.AddTestVar("TD_1_OMR_ADDR", td1.FindGlobalAddress().ToString().AsCString());
|
||||
|
||||
String<6> portString;
|
||||
portString.Append("%u", br1.Get<Srp::Server>().GetPort());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", portString.AsCString());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", br1.Get<Srp::Server>().GetPort());
|
||||
|
||||
Log("Step 2: Harness instructs the DUT to register the service");
|
||||
|
||||
|
||||
@@ -543,11 +543,7 @@ void Test_1_3_SRP_TC_1(const char *aJsonFileName)
|
||||
ed1.FindMatchingAddress(omrPrefix.ToString().AsCString()).ToString().AsCString());
|
||||
}
|
||||
|
||||
{
|
||||
String<10> srpPortString;
|
||||
srpPortString.Append("%u", br1.Get<Srp::Server>().GetPort());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", srpPortString.AsCString());
|
||||
}
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", br1.Get<Srp::Server>().GetPort());
|
||||
|
||||
nexus.SaveTestInfo(aJsonFileName);
|
||||
}
|
||||
|
||||
@@ -167,11 +167,7 @@ void Test_1_3_SRP_TC_11(const char *aJsonFileName)
|
||||
Log("Step 3: BR 1 (DUT) Automatically adds SRP Server information in the Thread Network Data.");
|
||||
nexus.AdvanceTime(kSrpServerInfoUpdateTime);
|
||||
|
||||
{
|
||||
String<10> srpPortString;
|
||||
srpPortString.Append("%u", br1.Get<Srp::Server>().GetPort());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT_1", srpPortString.AsCString());
|
||||
}
|
||||
nexus.AddTestVar("BR_1_SRP_PORT_1", br1.Get<Srp::Server>().GetPort());
|
||||
|
||||
/**
|
||||
* Step 4
|
||||
@@ -361,9 +357,7 @@ void Test_1_3_SRP_TC_11(const char *aJsonFileName)
|
||||
nexus.AdvanceTime(kFormNetworkTime);
|
||||
nexus.AdvanceTime(kSrpServerInfoUpdateTime);
|
||||
|
||||
String<10> srpPortString;
|
||||
srpPortString.Append("%u", br1.Get<Srp::Server>().GetPort());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT_2", srpPortString.AsCString());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT_2", br1.Get<Srp::Server>().GetPort());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -292,25 +292,10 @@ void Test_1_3_SRP_TC_12(const char *aJsonFileName)
|
||||
|
||||
Log("All steps completed.");
|
||||
|
||||
{
|
||||
String<10> string;
|
||||
|
||||
string.Clear();
|
||||
string.Append("%u", kBr2UnicastPort);
|
||||
nexus.AddTestVar("BR_2_UNICAST_PORT", string.AsCString());
|
||||
|
||||
string.Clear();
|
||||
string.Append("%u", kBr3UnicastPort);
|
||||
nexus.AddTestVar("BR_3_UNICAST_PORT", string.AsCString());
|
||||
|
||||
string.Clear();
|
||||
string.Append("%u", kBr1AnycastSeqNum);
|
||||
nexus.AddTestVar("BR_1_ANYCAST_SEQ", string.AsCString());
|
||||
|
||||
string.Clear();
|
||||
string.Append("%u", kBr2AnycastSeqNum);
|
||||
nexus.AddTestVar("BR_2_ANYCAST_SEQ", string.AsCString());
|
||||
}
|
||||
nexus.AddTestVar("BR_2_UNICAST_PORT", kBr2UnicastPort);
|
||||
nexus.AddTestVar("BR_3_UNICAST_PORT", kBr3UnicastPort);
|
||||
nexus.AddTestVar("BR_1_ANYCAST_SEQ", kBr1AnycastSeqNum);
|
||||
nexus.AddTestVar("BR_2_ANYCAST_SEQ", kBr2AnycastSeqNum);
|
||||
|
||||
nexus.AddTestVar("BR_2_UNICAST_ADDR", kBr2UnicastAddr);
|
||||
nexus.AddTestVar("BR_3_UNICAST_ADDR", kBr3UnicastAddr);
|
||||
|
||||
@@ -167,11 +167,7 @@ void Test_1_3_SRP_TC_13(const char *aJsonFileName)
|
||||
|
||||
nexus.AddTestVar("BR_1_MLEID_ADDR", br1.Get<Mle::Mle>().GetMeshLocalEid().ToString().AsCString());
|
||||
nexus.AddTestVar("ED_1_MLEID_ADDR", ed1.Get<Mle::Mle>().GetMeshLocalEid().ToString().AsCString());
|
||||
{
|
||||
String<10> srpPortString;
|
||||
srpPortString.Append("%u", br1.Get<Srp::Server>().GetPort());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", srpPortString.AsCString());
|
||||
}
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", br1.Get<Srp::Server>().GetPort());
|
||||
|
||||
/**
|
||||
* Step 4
|
||||
|
||||
@@ -625,11 +625,7 @@ void Test_1_3_SRP_TC_15(const char *aJsonFileName)
|
||||
ed1.FindMatchingAddress(omrPrefix.ToString().AsCString()).ToString().AsCString());
|
||||
}
|
||||
|
||||
{
|
||||
String<10> srpPortString;
|
||||
srpPortString.Append("%u", br1.Get<Srp::Server>().GetPort());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", srpPortString.AsCString());
|
||||
}
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", br1.Get<Srp::Server>().GetPort());
|
||||
|
||||
nexus.SaveTestInfo(aJsonFileName);
|
||||
}
|
||||
|
||||
@@ -581,12 +581,7 @@ void Test_1_3_SRP_TC_2(const char *aJsonFileName)
|
||||
nexus.AddTestVar("BR_1_MLEID_ADDR", br1.Get<Mle::Mle>().GetMeshLocalEid().ToString().AsCString());
|
||||
nexus.AddTestVar("ED_1_MLEID_ADDR", ed1.Get<Mle::Mle>().GetMeshLocalEid().ToString().AsCString());
|
||||
nexus.AddTestVar("ED_2_MLEID_ADDR", ed2.Get<Mle::Mle>().GetMeshLocalEid().ToString().AsCString());
|
||||
|
||||
{
|
||||
String<10> srpPortString;
|
||||
srpPortString.Append("%u", br1.Get<Srp::Server>().GetPort());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", srpPortString.AsCString());
|
||||
}
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", br1.Get<Srp::Server>().GetPort());
|
||||
|
||||
Ip6::Prefix omrPrefix;
|
||||
SuccessOrQuit(br1.Get<BorderRouter::RoutingManager>().GetOmrPrefix(omrPrefix));
|
||||
|
||||
@@ -552,12 +552,7 @@ void Test_1_3_SRP_TC_3(const char *aJsonFileName)
|
||||
|
||||
nexus.AddTestVar("BR_1_MLEID_ADDR", br1.Get<Mle::Mle>().GetMeshLocalEid().ToString().AsCString());
|
||||
nexus.AddTestVar("ED_1_MLEID_ADDR", ed1.Get<Mle::Mle>().GetMeshLocalEid().ToString().AsCString());
|
||||
|
||||
{
|
||||
String<10> srpPortString;
|
||||
srpPortString.Append("%u", br1.Get<Srp::Server>().GetPort());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", srpPortString.AsCString());
|
||||
}
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", br1.Get<Srp::Server>().GetPort());
|
||||
|
||||
Ip6::Prefix omrPrefix;
|
||||
SuccessOrQuit(br1.Get<BorderRouter::RoutingManager>().GetOmrPrefix(omrPrefix));
|
||||
|
||||
@@ -461,11 +461,7 @@ void Test_1_3_SRP_TC_4(const char *aJsonFileName)
|
||||
ed2.FindMatchingAddress(omrPrefix.ToString().AsCString()).ToString().AsCString());
|
||||
}
|
||||
|
||||
{
|
||||
String<10> srpPortString;
|
||||
srpPortString.Append("%u", br1.Get<Srp::Server>().GetPort());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", srpPortString.AsCString());
|
||||
}
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", br1.Get<Srp::Server>().GetPort());
|
||||
|
||||
nexus.SaveTestInfo(aJsonFileName);
|
||||
}
|
||||
|
||||
@@ -378,12 +378,7 @@ void Test_1_3_SRP_TC_5(const char *aJsonFileName)
|
||||
|
||||
nexus.AddTestVar("BR_1_MLEID_ADDR", br1.Get<Mle::Mle>().GetMeshLocalEid().ToString().AsCString());
|
||||
nexus.AddTestVar("ED_1_MLEID_ADDR", ed1.Get<Mle::Mle>().GetMeshLocalEid().ToString().AsCString());
|
||||
|
||||
{
|
||||
String<10> srpPortString;
|
||||
srpPortString.Append("%u", br1.Get<Srp::Server>().GetPort());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", srpPortString.AsCString());
|
||||
}
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", br1.Get<Srp::Server>().GetPort());
|
||||
|
||||
nexus.SaveTestInfo(aJsonFileName);
|
||||
}
|
||||
|
||||
@@ -370,11 +370,7 @@ void Test_1_3_SRP_TC_6(const char *aJsonFileName)
|
||||
ed1.FindMatchingAddress(omrPrefix.ToString().AsCString()).ToString().AsCString());
|
||||
}
|
||||
nexus.AddTestVar("BR_1_MLEID_ADDR", br1.Get<Mle::Mle>().GetMeshLocalEid().ToString().AsCString());
|
||||
{
|
||||
String<10> portStr;
|
||||
portStr.Append("%u", br1.Get<Srp::Server>().GetPort());
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", portStr.AsCString());
|
||||
}
|
||||
nexus.AddTestVar("BR_1_SRP_PORT", br1.Get<Srp::Server>().GetPort());
|
||||
|
||||
nexus.SaveTestInfo(aJsonFileName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user