From c44538e4df3770236240339ccf34865cef285c60 Mon Sep 17 00:00:00 2001 From: Zhanglong Xia Date: Sat, 23 Nov 2024 08:48:51 +0800 Subject: [PATCH] [simulation] enable the platform assert (#10952) When the ot-rcp enters the assert state, the host crashes and exits. But the ot-rcp still runs in the dead loop and becomes an orphan process. This commit enables the platform assert so that the ot-rcp can automatically exit when entering the assert state. --- examples/platforms/simulation/misc.c | 9 +++++++++ .../simulation/openthread-core-simulation-config.h | 4 ++++ tests/gtest/fake_platform.cpp | 2 +- tests/unit/test_platform.cpp | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/platforms/simulation/misc.c b/examples/platforms/simulation/misc.c index bf8993b76..235f0859e 100644 --- a/examples/platforms/simulation/misc.c +++ b/examples/platforms/simulation/misc.c @@ -113,3 +113,12 @@ otPlatMcuPowerState otPlatGetMcuPowerState(otInstance *aInstance) #if OPENTHREAD_CONFIG_PLATFORM_LOG_CRASH_DUMP_ENABLE otError otPlatLogCrashDump(void) { return OT_ERROR_NONE; } #endif + +void otPlatAssertFail(const char *aFilename, int aLineNumber) +{ + otLogCritPlat("assert failed at %s:%d", aFilename, aLineNumber); + + // For debug build, use assert to generate a core dump + assert(false); + exit(1); +} diff --git a/examples/platforms/simulation/openthread-core-simulation-config.h b/examples/platforms/simulation/openthread-core-simulation-config.h index 1b702788a..9cee9af8b 100644 --- a/examples/platforms/simulation/openthread-core-simulation-config.h +++ b/examples/platforms/simulation/openthread-core-simulation-config.h @@ -147,4 +147,8 @@ #define OPENTHREAD_CONFIG_RADIO_STATS_ENABLE 1 #endif +#ifndef OPENTHREAD_CONFIG_PLATFORM_ASSERT_MANAGEMENT +#define OPENTHREAD_CONFIG_PLATFORM_ASSERT_MANAGEMENT 1 +#endif + #endif // OPENTHREAD_CORE_SIMULATION_CONFIG_H_ diff --git a/tests/gtest/fake_platform.cpp b/tests/gtest/fake_platform.cpp index 5f109e075..34f23f696 100644 --- a/tests/gtest/fake_platform.cpp +++ b/tests/gtest/fake_platform.cpp @@ -575,5 +575,5 @@ otError otPlatUdpLeaveMulticastGroup(otUdpSocket *, otNetifIdentifier, const otI { return OT_ERROR_NOT_IMPLEMENTED; } - +void otPlatAssertFail(const char *, int) {} } // extern "C" diff --git a/tests/unit/test_platform.cpp b/tests/unit/test_platform.cpp index 89dfda775..95f34a644 100644 --- a/tests/unit/test_platform.cpp +++ b/tests/unit/test_platform.cpp @@ -967,4 +967,5 @@ OT_TOOL_WEAK void otPlatDnssdStopIp4AddressResolver(otInstance *aInstance, const OT_TOOL_WEAK otError otPlatLogCrashDump(void) { return OT_ERROR_NONE; } #endif +OT_TOOL_WEAK void otPlatAssertFail(const char *, int) {} } // extern "C"