mirror of
https://github.com/espressif/openthread.git
synced 2026-06-05 21:14:49 +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:
committed by
GitHub
parent
dea5c4559d
commit
b5d0ea36be
@@ -75,6 +75,23 @@ ot::Instance *testInitInstance(void)
|
||||
return static_cast<ot::Instance *>(instance);
|
||||
}
|
||||
|
||||
ot::Instance *testResetInstance(ot::Instance *aInstance)
|
||||
{
|
||||
otInstanceFinalize(aInstance);
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
|
||||
{
|
||||
size_t instanceBufferLength = sizeof(ot::Instance);
|
||||
|
||||
aInstance = static_cast<ot::Instance *>(otInstanceInit(aInstance, &instanceBufferLength));
|
||||
}
|
||||
#else
|
||||
aInstance = static_cast<ot::Instance *>(otInstanceInitSingle());
|
||||
#endif
|
||||
|
||||
return aInstance;
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE && OPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE
|
||||
ot::Instance *testInitAdditionalInstance(uint8_t id)
|
||||
{
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
#include "test_util.h"
|
||||
|
||||
ot::Instance *testInitInstance(void);
|
||||
ot::Instance *testResetInstance(ot::Instance *aInstance);
|
||||
#if OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE && OPENTHREAD_CONFIG_MULTIPLE_STATIC_INSTANCE_ENABLE
|
||||
ot::Instance *testInitAdditionalInstance(uint8_t id);
|
||||
#endif
|
||||
|
||||
@@ -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