mirror of
https://github.com/espressif/openthread.git
synced 2026-08-23 10:49:51 +00:00
[test] add testResetInstance() to simulate device reset (#12878)
This commit introduces `testResetInstance()` in the unit test platform layer to finalize an existing `ot::Instance` and re-initialize it using the same underlying memory buffer, simulating a device reset. This commit also updates `test_routing_manager.cpp` to use this new function to streamline the test implementation.
This commit is contained in:
@@ -1386,19 +1386,23 @@ void VerifyFavoredOnLinkPrefix(const Ip6::Prefix &aPrefix)
|
||||
VerifyOrQuit(favoredPrefix == aPrefix);
|
||||
}
|
||||
|
||||
void InitTest(bool aEnablBorderRouting = false, bool aAfterReset = false)
|
||||
void InitTest(bool aEnablBorderRouting = false, bool aResetInstance = false)
|
||||
{
|
||||
uint32_t delay = 10000;
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Initialize OT instance.
|
||||
|
||||
sNow = 0;
|
||||
sAlarmOn = false;
|
||||
sInstance = static_cast<Instance *>(testInitInstance());
|
||||
sNow = 0;
|
||||
sAlarmOn = false;
|
||||
|
||||
if (aAfterReset)
|
||||
if (!aResetInstance)
|
||||
{
|
||||
sInstance = testInitInstance();
|
||||
}
|
||||
else
|
||||
{
|
||||
sInstance = testResetInstance(sInstance);
|
||||
delay += 26000; // leader reset sync delay
|
||||
}
|
||||
|
||||
@@ -4285,9 +4289,7 @@ void TestSavedOnLinkPrefixes(void)
|
||||
|
||||
Log("Disabling and re-enabling OT Instance");
|
||||
|
||||
testFreeInstance(sInstance);
|
||||
|
||||
InitTest(/* aEnablBorderRouting */ true, /* aAfterReset */ true);
|
||||
InitTest(/* aEnablBorderRouting */ true, /* aResetInstance */ true);
|
||||
|
||||
sExpectedPio = kPioAdvertisingLocalOnLink;
|
||||
|
||||
@@ -4331,9 +4333,7 @@ void TestSavedOnLinkPrefixes(void)
|
||||
|
||||
Log("Disabling and re-enabling OT Instance");
|
||||
|
||||
testFreeInstance(sInstance);
|
||||
|
||||
InitTest(/* aEnablBorderRouting */ false, /* aAfterReset */ true);
|
||||
InitTest(/* aEnablBorderRouting */ false, /* aResetInstance */ true);
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Start Routing Manager.
|
||||
@@ -4381,8 +4381,7 @@ void TestSavedOnLinkPrefixes(void)
|
||||
|
||||
Log("Disabling and re-enabling OT Instance again");
|
||||
|
||||
testFreeInstance(sInstance);
|
||||
InitTest(/* aEnablBorderRouting */ false, /* aAfterReset */ true);
|
||||
InitTest(/* aEnablBorderRouting */ false, /* aResetInstance */ true);
|
||||
|
||||
SuccessOrQuit(sInstance->Get<BorderRouter::RoutingManager>().SetEnabled(true));
|
||||
AdvanceTime(100);
|
||||
|
||||
Reference in New Issue
Block a user