[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:
Abtin Keshavarzian
2026-04-12 21:49:28 -05:00
committed by GitHub
parent dea5c4559d
commit b5d0ea36be
3 changed files with 30 additions and 13 deletions
+17
View File
@@ -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)
{