From 36926a610aac269287a93389ee6f7259cab4e003 Mon Sep 17 00:00:00 2001 From: Simon Lin Date: Thu, 6 Aug 2020 12:29:28 +0800 Subject: [PATCH] [tests] add build test for OT_ASSERT=OFF (#5333) This commit adds a build test without OT_ASSERT to catch compile issues. - Add cmake option: OT_ASSERT=ON - Add build test with OT_ASSERT=OFF - Fixes 2 compile errors. --- etc/cmake/options.cmake | 7 +++++++ script/check-simulation-build-cmake | 2 ++ src/core/mac/mac_frame.cpp | 2 +- src/core/utils/otns.cpp | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/etc/cmake/options.cmake b/etc/cmake/options.cmake index 157590bba..483f65d91 100644 --- a/etc/cmake/options.cmake +++ b/etc/cmake/options.cmake @@ -30,6 +30,13 @@ option(OT_APP_CLI "enable CLI app" ON) option(OT_APP_NCP "enable NCP app" ON) option(OT_APP_RCP "enable RCP app" ON) +option(OT_ASSERT "enable assert function OT_ASSERT()" ON) +if(OT_ASSERT) + target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_ASSERT_ENABLE=1") +else() + target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_ASSERT_ENABLE=0") +endif() + option(OT_BACKBONE_ROUTER "enable backbone router functionality") if(OT_BACKBONE_ROUTER) target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE=1") diff --git a/script/check-simulation-build-cmake b/script/check-simulation-build-cmake index a52c84cfe..a31acfa77 100755 --- a/script/check-simulation-build-cmake +++ b/script/check-simulation-build-cmake @@ -42,6 +42,8 @@ build_all_features() "$(dirname "$0")"/cmake-build simulation reset_source "$(dirname "$0")"/cmake-build simulation -DOT_OTNS=ON -DOT_SIMULATION_VIRTUAL_TIME=ON + reset_source + "$(dirname "$0")"/cmake-build simulation -DOT_OTNS=ON -DOT_SIMULATION_VIRTUAL_TIME=ON -DOT_ASSERT=OFF } build_toranj() diff --git a/src/core/mac/mac_frame.cpp b/src/core/mac/mac_frame.cpp index 1e23c535f..be256cd79 100644 --- a/src/core/mac/mac_frame.cpp +++ b/src/core/mac/mac_frame.cpp @@ -1184,7 +1184,7 @@ otError TxFrame::GenerateEnhAck(const RxFrame &aFrame, bool aIsFramePending, con // Set frame length footerLength = GetFooterLength(); OT_ASSERT(footerLength != kInvalidIndex); - mLength = SkipSecurityHeaderIndex() + aIeLength + GetFooterLength(); + mLength = SkipSecurityHeaderIndex() + aIeLength + footerLength; exit: return error; diff --git a/src/core/utils/otns.cpp b/src/core/utils/otns.cpp index f61faac44..74c670b23 100644 --- a/src/core/utils/otns.cpp +++ b/src/core/utils/otns.cpp @@ -79,6 +79,7 @@ void Otns::EmitStatus(const char *aFmt, ...) va_start(ap, aFmt); n = vsnprintf(statusStr, sizeof(statusStr), aFmt, ap); + OT_UNUSED_VARIABLE(n); OT_ASSERT(n >= 0); va_end(ap);