From 97a7910172b9e8895fb9ef0d0affc7e65c68779a Mon Sep 17 00:00:00 2001 From: jinran-google Date: Fri, 8 Apr 2022 01:37:48 +0800 Subject: [PATCH] [posix] stop setting up and de-initializing uninitialized modules when dry run (#7550) Initialization of these modules is not called when dry run, so setup and de-initialization should not be called either. --- src/posix/platform/settings.cpp | 2 ++ src/posix/platform/system.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/posix/platform/settings.cpp b/src/posix/platform/settings.cpp index 8b1578037..7ea03abf3 100644 --- a/src/posix/platform/settings.cpp +++ b/src/posix/platform/settings.cpp @@ -224,6 +224,8 @@ void otPlatSettingsDeinit(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance); + VerifyOrExit(!IsSystemDryRun()); + #if OPENTHREAD_POSIX_CONFIG_SECURE_SETTINGS_ENABLE otPosixSecureSettingsDeinit(aInstance); #endif diff --git a/src/posix/platform/system.cpp b/src/posix/platform/system.cpp index eff0d7d4d..c3e176abe 100644 --- a/src/posix/platform/system.cpp +++ b/src/posix/platform/system.cpp @@ -161,6 +161,8 @@ exit: void platformSetUp(void) { + VerifyOrExit(!gDryRun); + #if OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE platformBackboneSetUp(); #endif @@ -184,6 +186,9 @@ void platformSetUp(void) #if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE || OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE SuccessOrDie(otSetStateChangedCallback(gInstance, processStateChange, gInstance)); #endif + +exit: + return; } otInstance *otSysInit(otPlatformConfig *aPlatformConfig) @@ -203,6 +208,8 @@ otInstance *otSysInit(otPlatformConfig *aPlatformConfig) void platformTearDown(void) { + VerifyOrExit(!gDryRun); + #if OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE ot::Posix::Daemon::Get().TearDown(); #endif @@ -222,6 +229,9 @@ void platformTearDown(void) #if OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE platformBackboneTearDown(); #endif + +exit: + return; } void platformDeinit(void) @@ -230,6 +240,10 @@ void platformDeinit(void) virtualTimeDeinit(); #endif platformRadioDeinit(); + + // For Dry-Run option, only the radio is initialized. + VerifyOrExit(!gDryRun); + #if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE ot::Posix::Udp::Get().Deinit(); #endif @@ -247,6 +261,9 @@ void platformDeinit(void) #if OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE platformBackboneDeinit(); #endif + +exit: + return; } void otSysDeinit(void)