From 85fb7a451c8716fdec131c502b1858d5ca1db196 Mon Sep 17 00:00:00 2001 From: pvanhorn Date: Fri, 28 Oct 2016 18:42:19 -0700 Subject: [PATCH] Remove otPlatFlash API's and move settings from core to examples. (#889) * Remove otPlatFlash API's and move settings from core to examples. --- etc/visual-studio/UnitTests.vcxproj | 1 - etc/visual-studio/UnitTests.vcxproj.filters | 3 - .../libopenthread-windows.vcxproj | 1 + .../libopenthread-windows.vcxproj.filters | 3 + etc/visual-studio/libopenthread.vcxproj | 1 - .../libopenthread.vcxproj.filters | 3 - .../libopenthread_k.vcxproj.filters | 3 - examples/platforms/Makefile.am | 4 + examples/platforms/cc2538/Makefile.am | 9 +- examples/platforms/cc2538/flash.c | 20 +-- examples/platforms/cc2538/platform.c | 2 - examples/platforms/posix/Makefile.am | 8 +- .../platforms/posix/flash-windows-stubs.c | 12 +- examples/platforms/posix/flash.c | 18 +- examples/platforms/posix/platform.c | 2 - .../platforms/utils}/flash.h | 22 +-- .../platforms/utils}/settings.cpp | 168 +++++++++++------- include/platform/Makefile.am | 1 - src/core/Makefile.am | 3 +- src/core/openthread-core-default-config.h | 30 ---- src/core/openthread-instance.h | 7 - tests/unit/Makefile.am | 4 - tests/unit/test_platform.cpp | 110 ++++++------ tests/unit/test_settings.cpp | 159 ----------------- tests/unit/test_windows.cpp | 6 - 25 files changed, 221 insertions(+), 379 deletions(-) rename {include/platform => examples/platforms/utils}/flash.h (89%) rename {src/core/common => examples/platforms/utils}/settings.cpp (63%) delete mode 100644 tests/unit/test_settings.cpp diff --git a/etc/visual-studio/UnitTests.vcxproj b/etc/visual-studio/UnitTests.vcxproj index 3f686dcfe..2dba8d3e2 100644 --- a/etc/visual-studio/UnitTests.vcxproj +++ b/etc/visual-studio/UnitTests.vcxproj @@ -170,7 +170,6 @@ - diff --git a/etc/visual-studio/UnitTests.vcxproj.filters b/etc/visual-studio/UnitTests.vcxproj.filters index 6f88bbc98..1b018e3bc 100644 --- a/etc/visual-studio/UnitTests.vcxproj.filters +++ b/etc/visual-studio/UnitTests.vcxproj.filters @@ -36,9 +36,6 @@ Source Files - - Source Files - Source Files diff --git a/etc/visual-studio/libopenthread-windows.vcxproj b/etc/visual-studio/libopenthread-windows.vcxproj index 15c9487db..7a855f12b 100644 --- a/etc/visual-studio/libopenthread-windows.vcxproj +++ b/etc/visual-studio/libopenthread-windows.vcxproj @@ -28,6 +28,7 @@ + diff --git a/etc/visual-studio/libopenthread-windows.vcxproj.filters b/etc/visual-studio/libopenthread-windows.vcxproj.filters index 68f59f463..0c62eba82 100644 --- a/etc/visual-studio/libopenthread-windows.vcxproj.filters +++ b/etc/visual-studio/libopenthread-windows.vcxproj.filters @@ -37,6 +37,9 @@ Source Files + + Source Files + diff --git a/etc/visual-studio/libopenthread.vcxproj b/etc/visual-studio/libopenthread.vcxproj index 77716830d..57d1a46b8 100644 --- a/etc/visual-studio/libopenthread.vcxproj +++ b/etc/visual-studio/libopenthread.vcxproj @@ -25,7 +25,6 @@ - diff --git a/etc/visual-studio/libopenthread.vcxproj.filters b/etc/visual-studio/libopenthread.vcxproj.filters index 3c4baf3a6..ee61b4fb3 100644 --- a/etc/visual-studio/libopenthread.vcxproj.filters +++ b/etc/visual-studio/libopenthread.vcxproj.filters @@ -72,9 +72,6 @@ Source Files\common - - Source Files\common - Source Files\common diff --git a/etc/visual-studio/libopenthread_k.vcxproj.filters b/etc/visual-studio/libopenthread_k.vcxproj.filters index 2a18beeb7..c485a5dae 100644 --- a/etc/visual-studio/libopenthread_k.vcxproj.filters +++ b/etc/visual-studio/libopenthread_k.vcxproj.filters @@ -72,9 +72,6 @@ Source Files\common - - Source Files\common - Source Files\common diff --git a/examples/platforms/Makefile.am b/examples/platforms/Makefile.am index 8ee1859ed..3cce7f202 100644 --- a/examples/platforms/Makefile.am +++ b/examples/platforms/Makefile.am @@ -35,6 +35,10 @@ DIST_SUBDIRS = \ posix \ $(NULL) +EXTRA_DIST = \ + utils \ + $(NULL) + # Always build (e.g. for 'make all') these subdirectories. if OPENTHREAD_EXAMPLES_POSIX diff --git a/examples/platforms/cc2538/Makefile.am b/examples/platforms/cc2538/Makefile.am index a1ab9ec62..af246f597 100644 --- a/examples/platforms/cc2538/Makefile.am +++ b/examples/platforms/cc2538/Makefile.am @@ -36,6 +36,12 @@ libopenthread_cc2538_a_CPPFLAGS = \ -I$(top_srcdir)/src/core \ $(NULL) + +libopenthread_cc2538_settings.cpp: $(srcdir)/../utils/settings.cpp + cp $? $@ + +CLEANFILES = libopenthread_cc2538_settings.cpp + libopenthread_cc2538_a_SOURCES = \ alarm.c \ flash.c \ @@ -46,6 +52,7 @@ libopenthread_cc2538_a_SOURCES = \ random.c \ startup-gcc.c \ uart.c \ + libopenthread_cc2538_settings.cpp \ $(NULL) if OPENTHREAD_ENABLE_DIAG @@ -61,7 +68,7 @@ noinst_HEADERS = \ $(NULL) if OPENTHREAD_BUILD_COVERAGE -CLEANFILES = $(wildcard *.gcda *.gcno) +CLEANFILES += $(wildcard *.gcda *.gcno) endif # OPENTHREAD_BUILD_COVERAGE include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/examples/platforms/cc2538/flash.c b/examples/platforms/cc2538/flash.c index 4c7758e34..49632550d 100644 --- a/examples/platforms/cc2538/flash.c +++ b/examples/platforms/cc2538/flash.c @@ -33,7 +33,7 @@ #include #include -#include +#include #include #include "platform-cc2538.h" @@ -71,25 +71,25 @@ static ThreadError romStatusToThread(int32_t aStatus) return error; } -ThreadError otPlatFlashInit(void) +ThreadError utilsFlashInit(void) { return kThreadError_None; } -uint32_t otPlatFlashGetSize(void) +uint32_t utilsFlashGetSize(void) { uint32_t reg = (HWREG(FLASH_CTRL_DIECFG0) & 0x00000070) >> 4; return reg ? (0x20000 * reg) : 0x10000; } -ThreadError otPlatFlashErasePage(uint32_t aAddress) +ThreadError utilsFlashErasePage(uint32_t aAddress) { ThreadError error = kThreadError_None; int32_t status; uint32_t address; - VerifyOrExit(aAddress < otPlatFlashGetSize(), error = kThreadError_InvalidArgs); + VerifyOrExit(aAddress < utilsFlashGetSize(), error = kThreadError_InvalidArgs); address = FLASH_BASE + aAddress - (aAddress & (FLASH_PAGE_SIZE - 1)); status = ROM_PageErase(address, FLASH_PAGE_SIZE); @@ -99,7 +99,7 @@ exit: return error; } -ThreadError otPlatFlashStatusWait(uint32_t aTimeout) +ThreadError utilsFlashStatusWait(uint32_t aTimeout) { ThreadError error = kThreadError_None; uint32_t start = otPlatAlarmGetNow(); @@ -116,14 +116,14 @@ exit: return error; } -uint32_t otPlatFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize) +uint32_t utilsFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize) { int32_t status; uint32_t busy = 1; uint32_t *data; uint32_t size = 0; - VerifyOrExit(((aAddress + aSize) < otPlatFlashGetSize()) && + VerifyOrExit(((aAddress + aSize) < utilsFlashGetSize()) && (!(aAddress & 3)) && (!(aSize & 3)), aSize = 0); data = (uint32_t *)(aData); @@ -147,11 +147,11 @@ exit: return size; } -uint32_t otPlatFlashRead(uint32_t aAddress, uint8_t *aData, uint32_t aSize) +uint32_t utilsFlashRead(uint32_t aAddress, uint8_t *aData, uint32_t aSize) { uint32_t size = 0; - VerifyOrExit((aAddress + aSize) < otPlatFlashGetSize(), ;); + VerifyOrExit((aAddress + aSize) < utilsFlashGetSize(), ;); while (size < aSize) { diff --git a/examples/platforms/cc2538/platform.c b/examples/platforms/cc2538/platform.c index 15a9ca23d..72bcea2b2 100644 --- a/examples/platforms/cc2538/platform.c +++ b/examples/platforms/cc2538/platform.c @@ -33,7 +33,6 @@ */ #include -#include #include "platform-cc2538.h" otInstance *sInstance; @@ -44,7 +43,6 @@ void PlatformInit(int argc, char *argv[]) cc2538RandomInit(); cc2538RadioInit(); otPlatUartEnable(); - otPlatFlashInit(); (void)argc; (void)argv; diff --git a/examples/platforms/posix/Makefile.am b/examples/platforms/posix/Makefile.am index d567f4f57..ba91bfc7c 100644 --- a/examples/platforms/posix/Makefile.am +++ b/examples/platforms/posix/Makefile.am @@ -37,6 +37,11 @@ libopenthread_posix_a_CPPFLAGS = \ -D_GNU_SOURCE \ $(NULL) +libopenthread_posix_settings.cpp: $(srcdir)/../utils/settings.cpp + cp $? $@ + +CLEANFILES = libopenthread_posix_settings.cpp + libopenthread_posix_a_SOURCES = \ alarm.c \ misc.c \ @@ -46,6 +51,7 @@ libopenthread_posix_a_SOURCES = \ random.c \ uart-posix.c \ flash.c \ + libopenthread_posix_settings.cpp \ $(NULL) if OPENTHREAD_ENABLE_DIAG @@ -65,7 +71,7 @@ noinst_HEADERS = \ $(NULL) if OPENTHREAD_BUILD_COVERAGE -CLEANFILES = $(wildcard *.gcda *.gcno) +CLEANFILES += $(wildcard *.gcda *.gcno) endif # OPENTHREAD_BUILD_COVERAGE include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/examples/platforms/posix/flash-windows-stubs.c b/examples/platforms/posix/flash-windows-stubs.c index b174fefe9..a907df7c4 100644 --- a/examples/platforms/posix/flash-windows-stubs.c +++ b/examples/platforms/posix/flash-windows-stubs.c @@ -28,32 +28,32 @@ #include "platform-posix.h" -ThreadError otPlatFlashInit(void) +ThreadError utilsFlashInit(void) { return kThreadError_NotImplemented; } -uint32_t otPlatFlashGetSize(void) +uint32_t utilsFlashGetSize(void) { return 0; } -ThreadError otPlatFlashErasePage(uint32_t aAddress) +ThreadError utilsFlashErasePage(uint32_t aAddress) { return kThreadError_NotImplemented; } -ThreadError otPlatFlashStatusWait(uint32_t aTimeout) +ThreadError utilsFlashStatusWait(uint32_t aTimeout) { return kThreadError_None; } -uint32_t otPlatFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize) +uint32_t utilsFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize) { return 0; } -uint32_t otPlatFlashRead(uint32_t aAddress, uint8_t *aData, uint32_t aSize) +uint32_t utilsFlashRead(uint32_t aAddress, uint8_t *aData, uint32_t aSize) { return 0; } diff --git a/examples/platforms/posix/flash.c b/examples/platforms/posix/flash.c index 9aa853007..b6e7869a7 100644 --- a/examples/platforms/posix/flash.c +++ b/examples/platforms/posix/flash.c @@ -36,7 +36,7 @@ #include #include -#include +#include #include @@ -50,7 +50,7 @@ enum FLASH_PAGE_NUM = 128, }; -ThreadError otPlatFlashInit(void) +ThreadError utilsFlashInit(void) { ThreadError error = kThreadError_None; char fileName[20]; @@ -83,7 +83,7 @@ ThreadError otPlatFlashInit(void) { for (uint16_t index = 0; index < FLASH_PAGE_NUM; index++) { - SuccessOrExit(error = otPlatFlashErasePage(index * FLASH_PAGE_SIZE)); + SuccessOrExit(error = utilsFlashErasePage(index * FLASH_PAGE_SIZE)); } } @@ -91,12 +91,12 @@ exit: return error; } -uint32_t otPlatFlashGetSize(void) +uint32_t utilsFlashGetSize(void) { return FLASH_SIZE; } -ThreadError otPlatFlashErasePage(uint32_t aAddress) +ThreadError utilsFlashErasePage(uint32_t aAddress) { ThreadError error = kThreadError_None; uint8_t buf = 0xff; @@ -117,13 +117,13 @@ exit: return error; } -ThreadError otPlatFlashStatusWait(uint32_t aTimeout) +ThreadError utilsFlashStatusWait(uint32_t aTimeout) { (void)aTimeout; return kThreadError_None; } -uint32_t otPlatFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize) +uint32_t utilsFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize) { uint32_t ret = 0; uint32_t index = 0; @@ -133,7 +133,7 @@ uint32_t otPlatFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize) for (index = 0; index < aSize; index++) { - VerifyOrExit((ret = otPlatFlashRead(aAddress + index, &byte, 1)) == 1, ;); + VerifyOrExit((ret = utilsFlashRead(aAddress + index, &byte, 1)) == 1, ;); // Use bitwise AND to emulate the behavior of flash memory byte &= aData[index]; VerifyOrExit((ret = (uint32_t)pwrite(sFlashFd, &byte, 1, aAddress + index)) == 1, ;); @@ -143,7 +143,7 @@ exit: return index; } -uint32_t otPlatFlashRead(uint32_t aAddress, uint8_t *aData, uint32_t aSize) +uint32_t utilsFlashRead(uint32_t aAddress, uint8_t *aData, uint32_t aSize) { uint32_t ret = 0; diff --git a/examples/platforms/posix/platform.c b/examples/platforms/posix/platform.c index ee2f7d018..e83ee60bc 100644 --- a/examples/platforms/posix/platform.c +++ b/examples/platforms/posix/platform.c @@ -43,7 +43,6 @@ #include #include -#include #include uint32_t NODE_ID = 1; @@ -69,7 +68,6 @@ void PlatformInit(int argc, char *argv[]) platformAlarmInit(); platformRadioInit(); platformRandomInit(); - otPlatFlashInit(); } bool UartInitialized = false; diff --git a/include/platform/flash.h b/examples/platforms/utils/flash.h similarity index 89% rename from include/platform/flash.h rename to examples/platforms/utils/flash.h index b1a6f4be6..290f7b1a6 100644 --- a/include/platform/flash.h +++ b/examples/platforms/utils/flash.h @@ -29,11 +29,11 @@ /** * @file * @brief - * This file defines flash interface. + * This file defines the flash interface used by settings.cpp. */ -#ifndef OT_PLATFORM_FLASH_H -#define OT_PLATFORM_FLASH_H +#ifndef UTILS_FLASH_H +#define UTILS_FLASH_H #include @@ -49,7 +49,7 @@ extern "C" { * @retval ::kThreadError_None Initialize flash driver success. * @retval ::kThreadError_Failed Initialize flash driver fail. */ -ThreadError otPlatFlashInit(void); +ThreadError utilsFlashInit(void); /** * Get the size of flash that can be read/write by the caller. @@ -57,11 +57,11 @@ ThreadError otPlatFlashInit(void); * * @returns The size of the flash. */ -uint32_t otPlatFlashGetSize(void); +uint32_t utilsFlashGetSize(void); /** * Erase one flash page that include the input address. - * This is a non-blocking function. It can work with otPlatFlashStatusWait to check when erase is done. + * This is a non-blocking function. It can work with utilsFlashStatusWait to check when erase is done. * * The flash address starts from 0, and this function maps the input address to the physical address of flash for erasing. * 0 is always mapped to the beginning of one flash page. @@ -73,7 +73,7 @@ uint32_t otPlatFlashGetSize(void); * @retval kThreadError_Failed Erase flash operation is not started. * @retval kThreadError_InvalidArgs aAddress is out of range of flash or not aligend. */ -ThreadError otPlatFlashErasePage(uint32_t aAddress); +ThreadError utilsFlashErasePage(uint32_t aAddress); /** * Check whether flash is ready or busy. @@ -85,7 +85,7 @@ ThreadError otPlatFlashErasePage(uint32_t aAddress); * @retval kThreadError_None Flash is ready for any operation. * @retval kThreadError_Busy Flash is busy. */ -ThreadError otPlatFlashStatusWait(uint32_t aTimeout); +ThreadError utilsFlashStatusWait(uint32_t aTimeout); /** * Write flash. The write operation only clears bits, but never set bits. @@ -102,7 +102,7 @@ ThreadError otPlatFlashStatusWait(uint32_t aTimeout); * It is expected the same as aSize, and may be less than aSize. * 0 indicates that something wrong happens when writing. */ -uint32_t otPlatFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize); +uint32_t utilsFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize); /** * Read flash. @@ -119,10 +119,10 @@ uint32_t otPlatFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize); * It is expected the same as aSize, and may be less than aSize. * 0 indicates that something wrong happens when reading. */ -uint32_t otPlatFlashRead(uint32_t aAddress, uint8_t *aData, uint32_t aSize); +uint32_t utilsFlashRead(uint32_t aAddress, uint8_t *aData, uint32_t aSize); #ifdef __cplusplus } // extern "C" #endif -#endif // OT_PLATFORM_FLASH_H +#endif // UTILS_FLASH_H diff --git a/src/core/common/settings.cpp b/examples/platforms/utils/settings.cpp similarity index 63% rename from src/core/common/settings.cpp rename to examples/platforms/utils/settings.cpp index 03a097675..f68f69045 100644 --- a/src/core/common/settings.cpp +++ b/examples/platforms/utils/settings.cpp @@ -39,11 +39,10 @@ #include #include -#include #include #include -#include +#include #ifdef __cplusplus extern "C" { @@ -76,6 +75,40 @@ struct settingsBlock uint16_t reserved; } OT_TOOL_PACKED_END; + +/** + * @def SETTINGS_CONFIG_BASE_ADDRESS + * + * The base address of settings. + * + */ +#ifndef SETTINGS_CONFIG_BASE_ADDRESS +#define SETTINGS_CONFIG_BASE_ADDRESS 0x39000 +#endif // SETTINGS_CONFIG_BASE_ADDRESS + +/** + * @def SETTINGS_CONFIG_PAGE_SIZE + * + * The page size of settings. + * + */ +#ifndef SETTINGS_CONFIG_PAGE_SIZE +#define SETTINGS_CONFIG_PAGE_SIZE 0x800 +#endif // SETTINGS_CONFIG_PAGE_SIZE + +/** + * @def SETTINGS_CONFIG_PAGE_NUM + * + * The page number of settings. + * + */ +#ifndef SETTINGS_CONFIG_PAGE_NUM +#define SETTINGS_CONFIG_PAGE_NUM 2 +#endif // SETTINGS_CONFIG_PAGE_NUM + +static uint32_t sSettingsBaseAddress; +static uint32_t sSettingsUsedSize; + static uint16_t getAlignLength(uint16_t length) { return (length + 3) & 0xfffc; @@ -83,21 +116,21 @@ static uint16_t getAlignLength(uint16_t length) static void setSettingsFlag(uint32_t aBase, uint32_t aFlag) { - otPlatFlashWrite(aBase, reinterpret_cast(&aFlag), sizeof(aFlag)); + utilsFlashWrite(aBase, reinterpret_cast(&aFlag), sizeof(aFlag)); } static void initSettings(uint32_t aBase, uint32_t aFlag) { uint32_t address = aBase; - uint32_t settingsSize = OPENTHREAD_CONFIG_SETTINGS_PAGE_NUM > 1 ? - OPENTHREAD_CONFIG_SETTINGS_PAGE_SIZE * OPENTHREAD_CONFIG_SETTINGS_PAGE_NUM / 2 : - OPENTHREAD_CONFIG_SETTINGS_PAGE_SIZE; + uint32_t settingsSize = SETTINGS_CONFIG_PAGE_NUM > 1 ? + SETTINGS_CONFIG_PAGE_SIZE * SETTINGS_CONFIG_PAGE_NUM / 2 : + SETTINGS_CONFIG_PAGE_SIZE; while (address < (aBase + settingsSize)) { - otPlatFlashErasePage(address); - otPlatFlashStatusWait(1000); - address += OPENTHREAD_CONFIG_SETTINGS_PAGE_SIZE; + utilsFlashErasePage(address); + utilsFlashStatusWait(1000); + address += SETTINGS_CONFIG_PAGE_SIZE; } setSettingsFlag(aBase, aFlag); @@ -105,21 +138,23 @@ static void initSettings(uint32_t aBase, uint32_t aFlag) static uint32_t swapSettingsBlock(otInstance *aInstance) { - uint32_t oldBase = aInstance->mSettingsBaseAddress; + uint32_t oldBase = sSettingsBaseAddress; uint32_t swapAddress = oldBase; - uint32_t usedSize = aInstance->mSettingsUsedSize; - uint8_t pageNum = OPENTHREAD_CONFIG_SETTINGS_PAGE_NUM; - uint32_t settingsSize = pageNum > 1 ? OPENTHREAD_CONFIG_SETTINGS_PAGE_SIZE * pageNum / 2 : - OPENTHREAD_CONFIG_SETTINGS_PAGE_SIZE; + uint32_t usedSize = sSettingsUsedSize; + uint8_t pageNum = SETTINGS_CONFIG_PAGE_NUM; + uint32_t settingsSize = pageNum > 1 ? SETTINGS_CONFIG_PAGE_SIZE * pageNum / 2 : + SETTINGS_CONFIG_PAGE_SIZE; + + (void)aInstance; VerifyOrExit(pageNum > 1, ;); - aInstance->mSettingsBaseAddress = (swapAddress == OPENTHREAD_CONFIG_SETTINGS_BASE_ADDRESS) ? + sSettingsBaseAddress = (swapAddress == SETTINGS_CONFIG_BASE_ADDRESS) ? (swapAddress + settingsSize) : - OPENTHREAD_CONFIG_SETTINGS_BASE_ADDRESS; + SETTINGS_CONFIG_BASE_ADDRESS; - initSettings(aInstance->mSettingsBaseAddress, static_cast(kSettingsInSwap)); - aInstance->mSettingsUsedSize = kSettingsFlagSize; + initSettings(sSettingsBaseAddress, static_cast(kSettingsInSwap)); + sSettingsUsedSize = kSettingsFlagSize; swapAddress += kSettingsFlagSize; while (swapAddress < (oldBase + usedSize)) @@ -132,7 +167,7 @@ static uint32_t swapSettingsBlock(otInstance *aInstance) } OT_TOOL_PACKED_END addBlock; bool valid = true; - otPlatFlashRead(swapAddress, reinterpret_cast(&addBlock.block), sizeof(struct settingsBlock)); + utilsFlashRead(swapAddress, reinterpret_cast(&addBlock.block), sizeof(struct settingsBlock)); swapAddress += sizeof(struct settingsBlock); if (!(addBlock.block.flag & kBlockAddCompleteFlag) && (addBlock.block.flag & kBlockDeleteFlag)) @@ -143,7 +178,7 @@ static uint32_t swapSettingsBlock(otInstance *aInstance) { struct settingsBlock block; - otPlatFlashRead(address, reinterpret_cast(&block), sizeof(block)); + utilsFlashRead(address, reinterpret_cast(&block), sizeof(block)); if (!(block.flag & kBlockAddCompleteFlag) && (block.flag & kBlockDeleteFlag) && !(block.flag & kBlockIndex0Flag) && (block.key == addBlock.block.key)) @@ -157,11 +192,11 @@ static uint32_t swapSettingsBlock(otInstance *aInstance) if (valid) { - otPlatFlashRead(swapAddress, addBlock.data, getAlignLength(addBlock.block.length)); - otPlatFlashWrite(aInstance->mSettingsBaseAddress + aInstance->mSettingsUsedSize, - reinterpret_cast(&addBlock), - getAlignLength(addBlock.block.length) + sizeof(struct settingsBlock)); - aInstance->mSettingsUsedSize += (sizeof(struct settingsBlock) + getAlignLength(addBlock.block.length)); + utilsFlashRead(swapAddress, addBlock.data, getAlignLength(addBlock.block.length)); + utilsFlashWrite(sSettingsBaseAddress + sSettingsUsedSize, + reinterpret_cast(&addBlock), + getAlignLength(addBlock.block.length) + sizeof(struct settingsBlock)); + sSettingsUsedSize += (sizeof(struct settingsBlock) + getAlignLength(addBlock.block.length)); } } else if (addBlock.block.flag == 0xff) @@ -172,11 +207,11 @@ static uint32_t swapSettingsBlock(otInstance *aInstance) swapAddress += getAlignLength(addBlock.block.length); } - setSettingsFlag(aInstance->mSettingsBaseAddress, static_cast(kSettingsInUse)); + setSettingsFlag(sSettingsBaseAddress, static_cast(kSettingsInUse)); setSettingsFlag(oldBase, static_cast(kSettingsNotUse)); exit: - return settingsSize - aInstance->mSettingsUsedSize; + return settingsSize - sSettingsUsedSize; } static ThreadError addSetting(otInstance *aInstance, uint16_t aKey, bool aIndex0, const uint8_t *aValue, @@ -189,9 +224,9 @@ static ThreadError addSetting(otInstance *aInstance, uint16_t aKey, bool aIndex0 struct settingsBlock block; uint8_t data[kSettingsBlockDataSize]; } OT_TOOL_PACKED_END addBlock; - uint32_t settingsSize = OPENTHREAD_CONFIG_SETTINGS_PAGE_NUM > 1 ? - OPENTHREAD_CONFIG_SETTINGS_PAGE_SIZE * OPENTHREAD_CONFIG_SETTINGS_PAGE_NUM / 2 : - OPENTHREAD_CONFIG_SETTINGS_PAGE_SIZE; + uint32_t settingsSize = SETTINGS_CONFIG_PAGE_NUM > 1 ? + SETTINGS_CONFIG_PAGE_SIZE * SETTINGS_CONFIG_PAGE_NUM / 2 : + SETTINGS_CONFIG_PAGE_SIZE; addBlock.block.flag = 0xff; addBlock.block.key = aKey; @@ -204,28 +239,28 @@ static ThreadError addSetting(otInstance *aInstance, uint16_t aKey, bool aIndex0 addBlock.block.flag &= (~kBlockAddBeginFlag); addBlock.block.length = aValueLength; - if ((aInstance->mSettingsUsedSize + getAlignLength(addBlock.block.length) + sizeof(struct settingsBlock)) >= + if ((sSettingsUsedSize + getAlignLength(addBlock.block.length) + sizeof(struct settingsBlock)) >= settingsSize) { VerifyOrExit(swapSettingsBlock(aInstance) >= (getAlignLength(addBlock.block.length) + sizeof(struct settingsBlock)), error = kThreadError_NoBufs); } - otPlatFlashWrite(aInstance->mSettingsBaseAddress + aInstance->mSettingsUsedSize, - reinterpret_cast(&addBlock.block), - sizeof(struct settingsBlock)); + utilsFlashWrite(sSettingsBaseAddress + sSettingsUsedSize, + reinterpret_cast(&addBlock.block), + sizeof(struct settingsBlock)); memset(addBlock.data, 0xff, kSettingsBlockDataSize); memcpy(addBlock.data, aValue, addBlock.block.length); - otPlatFlashWrite(aInstance->mSettingsBaseAddress + aInstance->mSettingsUsedSize + sizeof(struct settingsBlock), - reinterpret_cast(addBlock.data), getAlignLength(addBlock.block.length)); + utilsFlashWrite(sSettingsBaseAddress + sSettingsUsedSize + sizeof(struct settingsBlock), + reinterpret_cast(addBlock.data), getAlignLength(addBlock.block.length)); addBlock.block.flag &= (~kBlockAddCompleteFlag); - otPlatFlashWrite(aInstance->mSettingsBaseAddress + aInstance->mSettingsUsedSize, - reinterpret_cast(&addBlock.block), - sizeof(struct settingsBlock)); - aInstance->mSettingsUsedSize += (sizeof(struct settingsBlock) + getAlignLength(addBlock.block.length)); + utilsFlashWrite(sSettingsBaseAddress + sSettingsUsedSize, + reinterpret_cast(&addBlock.block), + sizeof(struct settingsBlock)); + sSettingsUsedSize += (sizeof(struct settingsBlock) + getAlignLength(addBlock.block.length)); exit: return error; @@ -235,17 +270,22 @@ exit: void otPlatSettingsInit(otInstance *aInstance) { uint8_t index; - uint32_t settingsSize = OPENTHREAD_CONFIG_SETTINGS_PAGE_NUM > 1 ? - OPENTHREAD_CONFIG_SETTINGS_PAGE_SIZE * OPENTHREAD_CONFIG_SETTINGS_PAGE_NUM / 2 : - OPENTHREAD_CONFIG_SETTINGS_PAGE_SIZE; - aInstance->mSettingsBaseAddress = OPENTHREAD_CONFIG_SETTINGS_BASE_ADDRESS; + uint32_t settingsSize = SETTINGS_CONFIG_PAGE_NUM > 1 ? + SETTINGS_CONFIG_PAGE_SIZE * SETTINGS_CONFIG_PAGE_NUM / 2 : + SETTINGS_CONFIG_PAGE_SIZE; + + (void)aInstance; + + sSettingsBaseAddress = SETTINGS_CONFIG_BASE_ADDRESS; + + utilsFlashInit(); for (index = 0; index < 2; index++) { uint32_t blockFlag; - aInstance->mSettingsBaseAddress += settingsSize * index; - otPlatFlashRead(aInstance->mSettingsBaseAddress, reinterpret_cast(&blockFlag), sizeof(blockFlag)); + sSettingsBaseAddress += settingsSize * index; + utilsFlashRead(sSettingsBaseAddress, reinterpret_cast(&blockFlag), sizeof(blockFlag)); if (blockFlag == kSettingsInUse) { @@ -255,21 +295,21 @@ void otPlatSettingsInit(otInstance *aInstance) if (index == 2) { - initSettings(aInstance->mSettingsBaseAddress, static_cast(kSettingsInUse)); + initSettings(sSettingsBaseAddress, static_cast(kSettingsInUse)); } - aInstance->mSettingsUsedSize = kSettingsFlagSize; + sSettingsUsedSize = kSettingsFlagSize; - while (aInstance->mSettingsUsedSize < settingsSize) + while (sSettingsUsedSize < settingsSize) { struct settingsBlock block; - otPlatFlashRead(aInstance->mSettingsBaseAddress + aInstance->mSettingsUsedSize, - reinterpret_cast(&block), sizeof(block)); + utilsFlashRead(sSettingsBaseAddress + sSettingsUsedSize, + reinterpret_cast(&block), sizeof(block)); if (!(block.flag & kBlockAddBeginFlag)) { - aInstance->mSettingsUsedSize += (getAlignLength(block.length) + sizeof(struct settingsBlock)); + sSettingsUsedSize += (getAlignLength(block.length) + sizeof(struct settingsBlock)); } else { @@ -299,14 +339,16 @@ ThreadError otPlatSettingsAbandonChange(otInstance *aInstance) ThreadError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength) { ThreadError error = kThreadError_NotFound; - uint32_t address = aInstance->mSettingsBaseAddress + kSettingsFlagSize; + uint32_t address = sSettingsBaseAddress + kSettingsFlagSize; int index = 0; - while (address < (aInstance->mSettingsBaseAddress + aInstance->mSettingsUsedSize)) + (void)aInstance; + + while (address < (sSettingsBaseAddress + sSettingsUsedSize)) { struct settingsBlock block; - otPlatFlashRead(address, reinterpret_cast(&block), sizeof(block)); + utilsFlashRead(address, reinterpret_cast(&block), sizeof(block)); if (block.key == aKey) { @@ -329,7 +371,7 @@ ThreadError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, if (aValue) { VerifyOrExit(aValueLength, error = kThreadError_InvalidArgs); - otPlatFlashRead(address + sizeof(struct settingsBlock), aValue, block.length); + utilsFlashRead(address + sizeof(struct settingsBlock), aValue, block.length); } } @@ -361,14 +403,16 @@ ThreadError otPlatSettingsAdd(otInstance *aInstance, uint16_t aKey, const uint8_ ThreadError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex) { ThreadError error = kThreadError_NotFound; - uint32_t address = aInstance->mSettingsBaseAddress + kSettingsFlagSize; + uint32_t address = sSettingsBaseAddress + kSettingsFlagSize; int index = 0; - while (address < (aInstance->mSettingsBaseAddress + aInstance->mSettingsUsedSize)) + (void)aInstance; + + while (address < (sSettingsBaseAddress + sSettingsUsedSize)) { struct settingsBlock block; - otPlatFlashRead(address, reinterpret_cast(&block), sizeof(block)); + utilsFlashRead(address, reinterpret_cast(&block), sizeof(block)); if (block.key == aKey) { @@ -383,13 +427,13 @@ ThreadError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aInde { error = kThreadError_None; block.flag &= (~kBlockDeleteFlag); - otPlatFlashWrite(address, reinterpret_cast(&block), sizeof(block)); + utilsFlashWrite(address, reinterpret_cast(&block), sizeof(block)); } if (index == 1 && aIndex == 0) { block.flag &= (~kBlockIndex0Flag); - otPlatFlashWrite(address, reinterpret_cast(&block), sizeof(block)); + utilsFlashWrite(address, reinterpret_cast(&block), sizeof(block)); } index++; @@ -404,7 +448,7 @@ ThreadError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aInde void otPlatSettingsWipe(otInstance *aInstance) { - initSettings(aInstance->mSettingsBaseAddress, static_cast(kSettingsInUse)); + initSettings(sSettingsBaseAddress, static_cast(kSettingsInUse)); otPlatSettingsInit(aInstance); } diff --git a/include/platform/Makefile.am b/include/platform/Makefile.am index a5e8592b1..db9c1d3d8 100644 --- a/include/platform/Makefile.am +++ b/include/platform/Makefile.am @@ -39,7 +39,6 @@ ot_platform_headers =\ random.h \ uart.h \ spi-slave.h \ - flash.h \ settings.h \ messagepool.h \ toolchain.h \ diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 6f0492692..cbec4d46f 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -45,7 +45,6 @@ libopenthread_a_SOURCES = \ common/message.cpp \ common/tasklet.cpp \ common/timer.cpp \ - common/settings.cpp \ common/trickle_timer.cpp \ crypto/aes_ccm.cpp \ crypto/aes_ecb.cpp \ @@ -125,8 +124,8 @@ noinst_HEADERS = \ common/encoding.hpp \ common/logging.hpp \ common/message.hpp \ - common/new.hpp \ common/settings.hpp \ + common/new.hpp \ common/tasklet.hpp \ common/timer.hpp \ common/trickle_timer.hpp \ diff --git a/src/core/openthread-core-default-config.h b/src/core/openthread-core-default-config.h index e40b6d59f..10f5ddcc7 100644 --- a/src/core/openthread-core-default-config.h +++ b/src/core/openthread-core-default-config.h @@ -342,34 +342,4 @@ */ #define OPENTHREAD_CONFIG_LOG_NETDIAG -/** - * @def OPENTHREAD_CONFIG_SETTINGS_BASE_ADDRESS - * - * The base address of settings. - * - */ -#ifndef OPENTHREAD_CONFIG_SETTINGS_BASE_ADDRESS -#define OPENTHREAD_CONFIG_SETTINGS_BASE_ADDRESS 0x39000 -#endif // OPENTHREAD_CONFIG_SETTINGS_BASE_ADDRESS - -/** - * @def OPENTHREAD_CONFIG_SETTINGS_PAGE_SIZE - * - * The page size of settings. - * - */ -#ifndef OPENTHREAD_CONFIG_SETTINGS_PAGE_SIZE -#define OPENTHREAD_CONFIG_SETTINGS_PAGE_SIZE 0x800 -#endif // OPENTHREAD_CONFIG_SETTINGS_PAGE_SIZE - -/** - * @def OPENTHREAD_CONFIG_SETTINGS_PAGE_NUM - * - * The page number of settings. - * - */ -#ifndef OPENTHREAD_CONFIG_SETTINGS_PAGE_NUM -#define OPENTHREAD_CONFIG_SETTINGS_PAGE_NUM 2 -#endif // OPENTHREAD_CONFIG_SETTINGS_PAGE_NUM - #endif // OPENTHREAD_CORE_DEFAULT_CONFIG_H_ diff --git a/src/core/openthread-instance.h b/src/core/openthread-instance.h index 48057a8c8..96a460926 100644 --- a/src/core/openthread-instance.h +++ b/src/core/openthread-instance.h @@ -77,13 +77,6 @@ typedef struct otInstance Thread::Ip6::Ip6 mIp6; Thread::ThreadNetif mThreadNetif; - // - // Platform specific variables - // - - uint32_t mSettingsBaseAddress; - uint32_t mSettingsUsedSize; - // Constructor otInstance(void); diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 52fb881df..fad64a538 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -78,7 +78,6 @@ check_PROGRAMS = \ test-link-quality \ test-mac-frame \ test-message \ - test-settings \ test-timer \ test-toolchain \ $(NULL) @@ -137,9 +136,6 @@ test_message_SOURCES = test_platform.cpp test_message.cpp test_ncp_buffer_LDADD = $(COMMON_LDADD) test_ncp_buffer_SOURCES = test_platform.cpp test_ncp_buffer.cpp -test_settings_LDADD = $(COMMON_LDADD) -test_settings_SOURCES = test_platform.cpp test_settings.cpp - test_timer_LDADD = $(COMMON_LDADD) test_timer_SOURCES = test_platform.cpp test_timer.cpp diff --git a/tests/unit/test_platform.cpp b/tests/unit/test_platform.cpp index fcdf2423c..cd1c6d2bd 100644 --- a/tests/unit/test_platform.cpp +++ b/tests/unit/test_platform.cpp @@ -61,14 +61,6 @@ uint32_t sCallCount[kCallCountIndexMax]; bool sDiagMode = false; -enum -{ - kFlashSize = 0x40000, - kFlashPageSize = 0x800, -}; - -uint8_t sFlashBuffer[kFlashSize]; - extern "C" { void otSignalTaskletPending(otInstance *) @@ -311,71 +303,79 @@ exit: } // - // Flash + // Settings // - ThreadError otPlatFlashInit(void) + + void otPlatSettingsInit(otInstance *aInstance) { - memset(sFlashBuffer, 0xff, kFlashSize); + (void)aInstance; + } + + ThreadError otPlatSettingsBeginChange(otInstance *aInstance) + { + (void)aInstance; + return kThreadError_None; } - uint32_t otPlatFlashGetSize(void) + ThreadError otPlatSettingsCommitChange(otInstance *aInstance) { - return kFlashSize; - } + (void)aInstance; - ThreadError otPlatFlashErasePage(uint32_t aAddress) - { - ThreadError error = kThreadError_None; - uint32_t address; - - VerifyOrExit(aAddress < kFlashSize, error = kThreadError_InvalidArgs); - - // Get start address of the flash page that includes aAddress - address = aAddress & (~(uint32_t)(kFlashPageSize - 1)); - memset(sFlashBuffer + address, 0xff, kFlashPageSize); - -exit: - return error; - } - - ThreadError otPlatFlashStatusWait(uint32_t aTimeout) - { - (void)aTimeout; return kThreadError_None; } - uint32_t otPlatFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize) + ThreadError otPlatSettingsAbandonChange(otInstance *aInstance) { - uint32_t ret = 0; - uint8_t byte; + (void)aInstance; - VerifyOrExit(aAddress < kFlashSize, ;); - - for (uint32_t index = 0; index < aSize; index++) - { - byte = sFlashBuffer[aAddress + index]; - byte &= aData[index]; - sFlashBuffer[aAddress + index] = byte; - } - - ret = aSize; - -exit: - return ret; + return kThreadError_None; } - uint32_t otPlatFlashRead(uint32_t aAddress, uint8_t *aData, uint32_t aSize) + ThreadError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, uint8_t *aValue, + uint16_t *aValueLength) { - uint32_t ret = 0; + (void)aInstance; + (void)aKey; + (void)aIndex; + (void)aValue; + (void)aValueLength; - VerifyOrExit(aAddress < kFlashSize, ;); + return kThreadError_None; + } - memcpy(aData, sFlashBuffer + aAddress, aSize); - ret = aSize; + ThreadError otPlatSettingsSet(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength) + { + (void)aInstance; + (void)aKey; + (void)aValue; + (void)aValueLength; -exit: - return ret; + return kThreadError_None; + } + + ThreadError otPlatSettingsAdd(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength) + { + (void)aInstance; + (void)aKey; + (void)aValue; + (void)aValueLength; + + return kThreadError_None; + } + + ThreadError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex) + { + (void)aInstance; + (void)aKey; + (void)aIndex; + + return kThreadError_None; + } + + void otPlatSettingsWipe(otInstance *aInstance) + { + (void)aInstance; } } // extern "C" diff --git a/tests/unit/test_settings.cpp b/tests/unit/test_settings.cpp deleted file mode 100644 index 0f3f0ba1e..000000000 --- a/tests/unit/test_settings.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2016, The OpenThread Authors. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "test_util.h" -#include -#include -#include -#include -#include -#include - -enum -{ - kMaxStageDataLen = 32, -}; - -static uint8_t sWriteBuffer[kMaxStageDataLen]; -static int sWriteBufferLength; -static otInstance sInstance; - -void TestSettingsInit(void) -{ - uint8_t index; - - otPlatFlashInit(); - otPlatSettingsInit(&sInstance); - otPlatSettingsWipe(&sInstance); - - for (index = 0; index < kMaxStageDataLen; index++) - { - sWriteBuffer[index] = index; - } - - sWriteBufferLength = index; -} - -void TestSettingsAdd(void) -{ - uint8_t key = 7; - uint8_t readBuffer[kMaxStageDataLen]; - uint16_t readBufferLength; - - VerifyOrQuit(otPlatSettingsAdd(&sInstance, key, sWriteBuffer, sWriteBufferLength) == kThreadError_None, - "Settings::Add::Add Fail\n"); - VerifyOrQuit(otPlatSettingsGet(&sInstance, key, 0, readBuffer, &readBufferLength) == kThreadError_None, - "Settings::Add::Get Fail\n"); - VerifyOrQuit(!memcmp(readBuffer, sWriteBuffer, static_cast(sWriteBufferLength)), - "Settings::Add::Add Check Fail\n"); -} - -void TestSettingsDelete(void) -{ - uint8_t key = 8; - uint8_t readBuffer[kMaxStageDataLen]; - uint16_t readBufferLength; - - VerifyOrQuit(otPlatSettingsAdd(&sInstance, key, sWriteBuffer, sWriteBufferLength) == kThreadError_None, - "Settings::Delete::Add Fail\n"); - VerifyOrQuit(otPlatSettingsGet(&sInstance, key, 0, readBuffer, &readBufferLength) == kThreadError_None, - "Settings::Delete::Get Fail\n"); - VerifyOrQuit(!memcmp(readBuffer, sWriteBuffer, static_cast(sWriteBufferLength)), - "Settings::Delete::Add Check Fail\n"); - VerifyOrQuit(otPlatSettingsDelete(&sInstance, key, -1) == kThreadError_None, "Settings::Delete::Delete Fail\n"); - VerifyOrQuit(otPlatSettingsGet(&sInstance, key, 0, readBuffer, &readBufferLength) == kThreadError_NotFound, - "Settings::Delete::Get Fail\n"); -} - -void TestSettingsSet(void) -{ - uint8_t key = 9; - uint8_t readBuffer[kMaxStageDataLen]; - uint16_t readBufferLength; - - for (uint8_t index = 0; index < 2; index++) - { - VerifyOrQuit(otPlatSettingsAdd(&sInstance, key, sWriteBuffer, sWriteBufferLength) == kThreadError_None, - "Settings::Set::Add Fail\n"); - } - - VerifyOrQuit(otPlatSettingsSet(&sInstance, key, sWriteBuffer, sWriteBufferLength) == kThreadError_None, - "Settings::Set::Set Fail\n"); - VerifyOrQuit(otPlatSettingsGet(&sInstance, key, 0, readBuffer, &readBufferLength) == kThreadError_None, - "Settings::Set::Get Fail\n"); - VerifyOrQuit(!memcmp(readBuffer, sWriteBuffer, static_cast(sWriteBufferLength)), - "Settings::Set::Set Check Fail\n"); -} - -void TestSettingsSwap(void) -{ - ThreadError error = kThreadError_None; - uint8_t key = 11; - uint16_t index = 0; - uint8_t readBuffer[kMaxStageDataLen]; - uint16_t readBufferLength = kMaxStageDataLen; - - while (true) - { - error = otPlatSettingsAdd(&sInstance, key, sWriteBuffer, sWriteBufferLength); - VerifyOrQuit(error == kThreadError_None || error == kThreadError_NoBufs, "Settings::Swap::Add Fail\n"); - - if (error == kThreadError_NoBufs) - { - break; - } - - index++; - } - - VerifyOrQuit(otPlatSettingsDelete(&sInstance, key, 0) == kThreadError_None, "Settings::Swap::Delete Fail\n"); - VerifyOrQuit(otPlatSettingsAdd(&sInstance, key, sWriteBuffer, sWriteBufferLength) == kThreadError_None, - "Settings::Swap::Add Fail after swap\n"); - VerifyOrQuit(otPlatSettingsGet(&sInstance, key, index - 1, readBuffer, &readBufferLength) == kThreadError_None, - "Settings::Swap::Get Fail\n"); - VerifyOrQuit(!memcmp(readBuffer, sWriteBuffer, static_cast(sWriteBufferLength)), - "Settings::Swap::Add and Swap Check Fail\n"); -} - -void RunSettingsTests(void) -{ - TestSettingsInit(); - TestSettingsAdd(); - TestSettingsDelete(); - TestSettingsSet(); - TestSettingsSwap(); -} - -#ifdef ENABLE_TEST_MAIN -int main(void) -{ - RunSettingsTests(); - printf("All tests passed\n"); - return 0; -} -#endif diff --git a/tests/unit/test_windows.cpp b/tests/unit/test_windows.cpp index f2c18e38f..14eb3ffff 100644 --- a/tests/unit/test_windows.cpp +++ b/tests/unit/test_windows.cpp @@ -80,9 +80,6 @@ void test_packed2(); void test_packed_union(); void test_packed_enum(); -// test_settings.cpp -void RunSettingsTests(); - #pragma endregion utAssertTrue s_AssertTrue; @@ -134,8 +131,5 @@ namespace Thread TEST_METHOD(test_packed2) { ::test_packed2(); } TEST_METHOD(test_packed_union) { ::test_packed_union(); } TEST_METHOD(test_packed_enum) { ::test_packed_enum(); } - - // test_settings.cpp - TEST_METHOD(RunSettingsTests) { ::RunSettingsTests(); } }; }