From 1dd0abc591548a783d708b056817d85e55f9e269 Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Sun, 10 May 2020 08:15:21 +0800 Subject: [PATCH] [style] fix unused variables in release build (#4938) * change package check build Release --- examples/platforms/simulation/CMakeLists.txt | 2 + examples/platforms/simulation/Makefile.am | 6 ++- examples/platforms/simulation/alarm.c | 7 ++- examples/platforms/simulation/flash.c | 13 +++--- .../openthread-core-simulation-config.h | 10 +++++ examples/platforms/simulation/radio.c | 45 +++++++++++++++++++ script/test | 2 + src/core/thread/address_resolver.cpp | 2 +- src/posix/platform/netif.cpp | 6 +++ 9 files changed, 85 insertions(+), 8 deletions(-) diff --git a/examples/platforms/simulation/CMakeLists.txt b/examples/platforms/simulation/CMakeLists.txt index 01d306ba6..48d56c38c 100644 --- a/examples/platforms/simulation/CMakeLists.txt +++ b/examples/platforms/simulation/CMakeLists.txt @@ -79,6 +79,7 @@ if(LIBRT) endif() target_link_libraries(openthread-simulation PRIVATE openthread-platform-utils) +target_link_libraries(openthread-simulation PRIVATE openthread-platform) target_compile_definitions(openthread-simulation PUBLIC @@ -95,6 +96,7 @@ target_include_directories(openthread-simulation PRIVATE ${OT_PUBLIC_INCLUDES} ${OT_PRIVATE_INCLUDES} ${PROJECT_SOURCE_DIR}/examples/platforms + ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/core ) diff --git a/examples/platforms/simulation/Makefile.am b/examples/platforms/simulation/Makefile.am index 444a5a3e7..6e3b40d7f 100644 --- a/examples/platforms/simulation/Makefile.am +++ b/examples/platforms/simulation/Makefile.am @@ -27,12 +27,14 @@ # include $(abs_top_nlbuild_autotools_dir)/automake/pre.am +include $(top_srcdir)/src/lib/common.am lib_LIBRARIES = libopenthread-simulation.a libopenthread_simulation_a_CPPFLAGS = \ -I$(top_srcdir)/include \ -I$(top_srcdir)/examples/platforms \ + -I$(top_srcdir)/src \ -I$(top_srcdir)/src/core \ -D_GNU_SOURCE \ $(NULL) @@ -62,7 +64,9 @@ libopenthread_simulation_a_SOURCES = \ Dash = - libopenthread_simulation_a_LIBADD = \ - $(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o") + $(call ot_list_objects,$(top_builddir)/examples/platforms/utils/libopenthread-platform-utils.a) \ + $(call ot_list_objects,$(top_builddir)/src/lib/platform/libopenthread-platform.a) \ + $(NULL) if OPENTHREAD_BUILD_COVERAGE libopenthread_simulation_a_CPPFLAGS += \ diff --git a/examples/platforms/simulation/alarm.c b/examples/platforms/simulation/alarm.c index 236f1c46d..d31c03f50 100644 --- a/examples/platforms/simulation/alarm.c +++ b/examples/platforms/simulation/alarm.c @@ -57,6 +57,9 @@ timer_t sMicroTimer; #include #include +#include "core/common/logging.hpp" +#include "lib/platform/exit_code.h" + #define MS_PER_S 1000 #define NS_PER_US 1000 #define US_PER_MS 1000 @@ -77,6 +80,8 @@ static void microTimerHandler(int aSignal, siginfo_t *aSignalInfo, void *aUserCo { assert(aSignal == OPENTHREAD_CONFIG_MICRO_TIMER_SIGNAL); assert(aSignalInfo->si_value.sival_ptr == &sMicroTimer); + (void)aSignal; + (void)aSignalInfo; (void)aUserContext; } #endif @@ -126,7 +131,7 @@ uint64_t platformGetNow(void) err = clock_gettime(CLOCK_MONOTONIC, &now); #endif - assert(err == 0); + VerifyOrDie(err == 0, OT_EXIT_ERROR_ERRNO); return (uint64_t)now.tv_sec * sSpeedUpFactor * US_PER_S + (uint64_t)now.tv_nsec * sSpeedUpFactor / NS_PER_US; } diff --git a/examples/platforms/simulation/flash.c b/examples/platforms/simulation/flash.c index df53db731..fe634a85c 100644 --- a/examples/platforms/simulation/flash.c +++ b/examples/platforms/simulation/flash.c @@ -39,6 +39,9 @@ #include #include +#include "core/common/logging.hpp" +#include "lib/platform/exit_code.h" + static int sFlashFd = -1; enum @@ -77,7 +80,7 @@ void otPlatFlashInit(otInstance *aInstance) sFlashFd = open(fileName, O_RDWR | O_CREAT | O_CLOEXEC, 0600); lseek(sFlashFd, 0, SEEK_SET); - assert(sFlashFd >= 0); + VerifyOrDie(sFlashFd >= 0, OT_EXIT_ERROR_ERRNO); if (create) { @@ -109,7 +112,7 @@ void otPlatFlashErase(otInstance *aInstance, uint8_t aSwapIndex) memset(buffer, 0xff, sizeof(buffer)); rval = pwrite(sFlashFd, buffer, sizeof(buffer), (off_t)address); - assert(rval == SWAP_SIZE); + VerifyOrDie(rval == SWAP_SIZE, OT_EXIT_ERROR_ERRNO); } void otPlatFlashRead(otInstance *aInstance, uint8_t aSwapIndex, uint32_t aOffset, void *aData, uint32_t aSize) @@ -124,7 +127,7 @@ void otPlatFlashRead(otInstance *aInstance, uint8_t aSwapIndex, uint32_t aOffset address = aSwapIndex ? SWAP_SIZE : 0; rval = pread(sFlashFd, aData, aSize, (off_t)(address + aOffset)); - assert((uint32_t)rval == aSize); + VerifyOrDie((uint32_t)rval == aSize, OT_EXIT_ERROR_ERRNO); } void otPlatFlashWrite(otInstance *aInstance, uint8_t aSwapIndex, uint32_t aOffset, const void *aData, uint32_t aSize) @@ -143,12 +146,12 @@ void otPlatFlashWrite(otInstance *aInstance, uint8_t aSwapIndex, uint32_t aOffse for (uint32_t offset = 0; offset < aSize; offset++) { rval = pread(sFlashFd, &byte, sizeof(byte), (off_t)(address + offset)); - assert(rval == sizeof(byte)); + VerifyOrDie(rval == sizeof(byte), OT_EXIT_ERROR_ERRNO); // Use bitwise AND to emulate the behavior of flash memory byte &= ((uint8_t *)aData)[offset]; rval = pwrite(sFlashFd, &byte, sizeof(byte), (off_t)(address + offset)); - assert(rval == sizeof(byte)); + VerifyOrDie(rval == sizeof(byte), OT_EXIT_ERROR_ERRNO); } } diff --git a/examples/platforms/simulation/openthread-core-simulation-config.h b/examples/platforms/simulation/openthread-core-simulation-config.h index b1ea2e6bc..50d783579 100644 --- a/examples/platforms/simulation/openthread-core-simulation-config.h +++ b/examples/platforms/simulation/openthread-core-simulation-config.h @@ -155,4 +155,14 @@ #define OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE 1 #endif +/** + * @def OPENTHREAD_CONFIG_LOG_PLATFORM + * + * Define to enable platform region logging. + * + */ +#ifndef OPENTHREAD_CONFIG_LOG_PLATFORM +#define OPENTHREAD_CONFIG_LOG_PLATFORM 1 +#endif + #endif // OPENTHREAD_CORE_SIMULATION_CONFIG_H_ diff --git a/examples/platforms/simulation/radio.c b/examples/platforms/simulation/radio.c index 8fe4c8d08..c53298a08 100644 --- a/examples/platforms/simulation/radio.c +++ b/examples/platforms/simulation/radio.c @@ -198,6 +198,8 @@ void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64) void otPlatRadioSetPanId(otInstance *aInstance, otPanId aPanid) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); sPanid = aPanid; @@ -206,6 +208,8 @@ void otPlatRadioSetPanId(otInstance *aInstance, otPanId aPanid) void otPlatRadioSetExtendedAddress(otInstance *aInstance, const otExtAddress *aExtAddress) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); ReverseExtAddress(&sExtAddress, aExtAddress); @@ -213,6 +217,8 @@ void otPlatRadioSetExtendedAddress(otInstance *aInstance, const otExtAddress *aE void otPlatRadioSetShortAddress(otInstance *aInstance, otShortAddress aAddress) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); sShortAddress = aAddress; @@ -220,6 +226,8 @@ void otPlatRadioSetShortAddress(otInstance *aInstance, otShortAddress aAddress) void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); sPromiscuous = aEnable; @@ -359,6 +367,8 @@ exit: otError otPlatRadioSleep(otInstance *aInstance) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); otError error = OT_ERROR_INVALID_STATE; @@ -374,6 +384,8 @@ otError otPlatRadioSleep(otInstance *aInstance) otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); otError error = OT_ERROR_INVALID_STATE; @@ -391,6 +403,9 @@ otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel) otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aRadio) { + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aRadio); + assert(aInstance != NULL); assert(aRadio != NULL); @@ -407,6 +422,8 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aRadio) otRadioFrame *otPlatRadioGetTransmitBuffer(otInstance *aInstance) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); return &sTransmitFrame; @@ -414,6 +431,8 @@ otRadioFrame *otPlatRadioGetTransmitBuffer(otInstance *aInstance) int8_t otPlatRadioGetRssi(otInstance *aInstance) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); int8_t rssi = SIM_LOW_RSSI_SAMPLE; @@ -439,6 +458,8 @@ exit: otRadioCaps otPlatRadioGetCaps(otInstance *aInstance) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); return OT_RADIO_CAPS_NONE; @@ -446,6 +467,8 @@ otRadioCaps otPlatRadioGetCaps(otInstance *aInstance) bool otPlatRadioGetPromiscuous(otInstance *aInstance) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); return sPromiscuous; @@ -774,6 +797,8 @@ exit: void otPlatRadioEnableSrcMatch(otInstance *aInstance, bool aEnable) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); sSrcMatchEnabled = aEnable; @@ -781,6 +806,10 @@ void otPlatRadioEnableSrcMatch(otInstance *aInstance, bool aEnable) otError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, uint16_t aScanDuration) { + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aScanChannel); + OT_UNUSED_VARIABLE(aScanDuration); + assert(aInstance != NULL); assert(aScanChannel >= SIM_RADIO_CHANNEL_MIN && aScanChannel <= SIM_RADIO_CHANNEL_MAX); assert(aScanDuration > 0); @@ -790,6 +819,8 @@ otError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, uint1 otError otPlatRadioGetTransmitPower(otInstance *aInstance, int8_t *aPower) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); *aPower = sTxPower; @@ -799,6 +830,8 @@ otError otPlatRadioGetTransmitPower(otInstance *aInstance, int8_t *aPower) otError otPlatRadioSetTransmitPower(otInstance *aInstance, int8_t aPower) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); sTxPower = aPower; @@ -808,6 +841,8 @@ otError otPlatRadioSetTransmitPower(otInstance *aInstance, int8_t aPower) otError otPlatRadioGetCcaEnergyDetectThreshold(otInstance *aInstance, int8_t *aThreshold) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); *aThreshold = sCcaEdThresh; @@ -817,6 +852,8 @@ otError otPlatRadioGetCcaEnergyDetectThreshold(otInstance *aInstance, int8_t *aT otError otPlatRadioSetCcaEnergyDetectThreshold(otInstance *aInstance, int8_t aThreshold) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); sCcaEdThresh = aThreshold; @@ -826,6 +863,8 @@ otError otPlatRadioSetCcaEnergyDetectThreshold(otInstance *aInstance, int8_t aTh int8_t otPlatRadioGetReceiveSensitivity(otInstance *aInstance) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); return SIM_RECEIVE_SENSITIVITY; @@ -841,6 +880,8 @@ otRadioState otPlatRadioGetState(otInstance *aInstance) #if OPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE otError otPlatRadioSetCoexEnabled(otInstance *aInstance, bool aEnabled) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); sRadioCoexEnabled = aEnabled; @@ -849,6 +890,8 @@ otError otPlatRadioSetCoexEnabled(otInstance *aInstance, bool aEnabled) bool otPlatRadioIsCoexEnabled(otInstance *aInstance) { + OT_UNUSED_VARIABLE(aInstance); + assert(aInstance != NULL); return sRadioCoexEnabled; @@ -856,6 +899,8 @@ bool otPlatRadioIsCoexEnabled(otInstance *aInstance) otError otPlatRadioGetCoexMetrics(otInstance *aInstance, otRadioCoexMetrics *aCoexMetrics) { + OT_UNUSED_VARIABLE(aInstance); + otError error = OT_ERROR_NONE; assert(aInstance != NULL); diff --git a/script/test b/script/test index e5b609948..2451c23dd 100755 --- a/script/test +++ b/script/test @@ -335,10 +335,12 @@ EXAMPLES: do_package() { local builddir="${OT_BUILDDIR}/cmake/openthread-sim" local options=( + "-DCMAKE_BUILD_TYPE=Release" "-DOT_BORDER_AGENT=ON" "-DOT_BORDER_ROUTER=ON" "-DOT_CHILD_SUPERVISION=ON" "-DOT_COMMISSIONER=ON" + "-DOT_COMPILE_WARNING_AS_ERROR=ON" "-DOT_DIAGNOSTIC=ON" "-DOT_IP6_FRAGM=ON" "-DOT_JAM_DETECTION=ON" diff --git a/src/core/thread/address_resolver.cpp b/src/core/thread/address_resolver.cpp index 7eb96424c..d2d5d0d6b 100644 --- a/src/core/thread/address_resolver.cpp +++ b/src/core/thread/address_resolver.cpp @@ -477,7 +477,7 @@ otError AddressResolver::Resolve(const Ip6::Address &aEid, uint16_t &aRloc16) { otError error = OT_ERROR_NONE; CacheEntry * entry; - CacheEntry * prev; + CacheEntry * prev = NULL; CacheEntryList *list; entry = FindCacheEntry(aEid, list, prev); diff --git a/src/posix/platform/netif.cpp b/src/posix/platform/netif.cpp index 0afb8aef6..c75f4af2b 100644 --- a/src/posix/platform/netif.cpp +++ b/src/posix/platform/netif.cpp @@ -290,6 +290,8 @@ static uint8_t NetmaskToPrefixLength(const struct sockaddr_in6 *netmask) static void UpdateUnicast(otInstance *aInstance, const otIp6Address &aAddress, uint8_t aPrefixLength, bool aIsAdded) { + OT_UNUSED_VARIABLE(aInstance); + otError error = OT_ERROR_NONE; assert(sInstance == aInstance); @@ -358,6 +360,8 @@ exit: static void UpdateMulticast(otInstance *aInstance, const otIp6Address &aAddress, bool aIsAdded) { + OT_UNUSED_VARIABLE(aInstance); + struct ipv6_mreq mreq; otError error = OT_ERROR_NONE; @@ -455,6 +459,8 @@ static void processStateChange(otChangedFlags aFlags, void *aContext) static void processReceive(otMessage *aMessage, void *aContext) { + OT_UNUSED_VARIABLE(aContext); + char packet[kMaxIp6Size + 4]; otError error = OT_ERROR_NONE; uint16_t length = otMessageGetLength(aMessage);