Skip to content

Commit

Permalink
[zephyr] Do not build ConfigurationManager::RunUnitTests() without te…
Browse files Browse the repository at this point in the history
…sts (project-chip#30171)

* [zephyr] Do not build ConfigurationManager::RunUnitTests() without tests

Do not build ConfigurationManager::RunUnitTests() nor
ConfigurationManagerImpl::RunConfigUnitTest() when building
a Zephyr application without unit test support.

This saves almost 1kB of flash.

* Fix build
  • Loading branch information
Damian-Nordic authored Nov 2, 2023
1 parent a45b670 commit e574fd8
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/include/platform/ConfigurationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ class ConfigurationManager

virtual CHIP_ERROR GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) = 0;

virtual CHIP_ERROR RunUnitTests() = 0;
#if CHIP_CONFIG_TEST
virtual void RunUnitTests() = 0;
#endif

virtual bool IsFullyProvisioned() = 0;
virtual void InitiateFactoryReset() = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ class GenericConfigurationManagerImpl : public ConfigurationManager
CHIP_ERROR GetUniqueId(char * buf, size_t bufSize) override;
CHIP_ERROR StoreUniqueId(const char * uniqueId, size_t uniqueIdLen) override;
CHIP_ERROR GenerateUniqueId(char * buf, size_t bufSize) override;
CHIP_ERROR RunUnitTests(void) override;
#if CHIP_CONFIG_TEST
void RunUnitTests() override;
#endif
bool IsFullyProvisioned() override;
void InitiateFactoryReset() override;
#if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,15 +663,14 @@ CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetSecondaryPairingInst
return CHIP_NO_ERROR;
}

#if CHIP_CONFIG_TEST
template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::RunUnitTests()
void GenericConfigurationManagerImpl<ConfigClass>::RunUnitTests()
{
#if !defined(NDEBUG)
ChipLogProgress(DeviceLayer, "Running configuration unit test");
RunConfigUnitTest();
#endif
return CHIP_NO_ERROR;
}
#endif

template <class ConfigClass>
void GenericConfigurationManagerImpl<ConfigClass>::LogDeviceConfig()
Expand Down
4 changes: 3 additions & 1 deletion src/platform/Zephyr/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,11 @@ CHIP_ERROR ConfigurationManagerImpl::WriteConfigValueBin(Key key, const uint8_t
return ZephyrConfig::WriteConfigValueBin(key, data, dataLen);
}

void ConfigurationManagerImpl::RunConfigUnitTest(void)
void ConfigurationManagerImpl::RunConfigUnitTest()
{
#if CHIP_CONFIG_TEST
ZephyrConfig::RunConfigUnitTest();
#endif
}

void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
Expand Down
2 changes: 1 addition & 1 deletion src/platform/Zephyr/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
CHIP_ERROR WriteConfigValueStr(Key key, const char * str) override;
CHIP_ERROR WriteConfigValueStr(Key key, const char * str, size_t strLen) override;
CHIP_ERROR WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) override;
void RunConfigUnitTest(void) override;
void RunConfigUnitTest() override;

// ===== Private members reserved for use by this class only.

Expand Down
4 changes: 2 additions & 2 deletions src/platform/fake/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class ConfigurationManagerImpl : public ConfigurationManager
CHIP_ERROR GetUniqueId(char * buf, size_t bufSize) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
CHIP_ERROR StoreUniqueId(const char * uniqueId, size_t uniqueIdLen) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
CHIP_ERROR GenerateUniqueId(char * buf, size_t bufSize) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
#if !defined(NDEBUG)
CHIP_ERROR RunUnitTests(void) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
#if CHIP_CONFIG_TEST
void RunUnitTests() override {}
#endif
bool IsFullyProvisioned() override { return false; }
void LogDeviceConfig() override {}
Expand Down
14 changes: 7 additions & 7 deletions src/platform/tests/TestConfigurationMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ static void TestPlatformMgr_Init(nlTestSuite * inSuite, void * inContext)
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
}

#if !defined(NDEBUG)
static void TestPlatformMgr_RunUnitTest(nlTestSuite * inSuite, void * inContext)
{
CHIP_ERROR err = CHIP_NO_ERROR;
#if CHIP_DEVICE_LAYER_TARGET_OPEN_IOT_SDK
// TODO: Fix RunUnitTests() for Open IOT SDK.
// Previously, TestPlatformMgr_RunUnitTest was only run if !NDEBUG while the Open IOT SDK
// test runner was built with NDEBUG set.
return;
#endif

err = ConfigurationMgr().RunUnitTests();
NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
ConfigurationMgr().RunUnitTests();
}
#endif

static void TestConfigurationMgr_SerialNumber(nlTestSuite * inSuite, void * inContext)
{
Expand Down Expand Up @@ -450,9 +452,7 @@ static void TestConfigurationMgr_GetProductId(nlTestSuite * inSuite, void * inCo
*/
static const nlTest sTests[] = {
NL_TEST_DEF("Test PlatformMgr::Init", TestPlatformMgr_Init),
#if !defined(NDEBUG)
NL_TEST_DEF("Test PlatformMgr::RunUnitTest", TestPlatformMgr_RunUnitTest),
#endif
NL_TEST_DEF("Test ConfigurationMgr::SerialNumber", TestConfigurationMgr_SerialNumber),
NL_TEST_DEF("Test ConfigurationMgr::UniqueId", TestConfigurationMgr_UniqueId),
NL_TEST_DEF("Test ConfigurationMgr::ManufacturingDate", TestConfigurationMgr_ManufacturingDate),
Expand Down

0 comments on commit e574fd8

Please sign in to comment.