diff --git a/UNITTESTS/stubs/CMakeLists.txt b/UNITTESTS/stubs/CMakeLists.txt index 677566fe77..ad0e22b673 100644 --- a/UNITTESTS/stubs/CMakeLists.txt +++ b/UNITTESTS/stubs/CMakeLists.txt @@ -6,7 +6,6 @@ add_library(mbed-headers INTERFACE) add_library(mbed-headers-base INTERFACE) add_library(mbed-headers-platform INTERFACE) add_library(mbed-headers-connectivity INTERFACE) -add_library(mbed-headers-storage INTERFACE) add_library(mbed-headers-events INTERFACE) target_link_libraries(mbed-headers @@ -14,7 +13,6 @@ target_link_libraries(mbed-headers mbed-headers-base mbed-headers-platform mbed-headers-connectivity - mbed-headers-storage mbed-headers-drivers mbed-headers-hal mbed-headers-events @@ -41,26 +39,6 @@ target_include_directories(mbed-headers-base ${mbed-os_SOURCE_DIR}/UNITTESTS/target_h/sys ) -target_include_directories(mbed-headers-storage - INTERFACE - ${mbed-os_SOURCE_DIR}/storage/filesystem/fat/include - ${mbed-os_SOURCE_DIR}/storage/filesystem/fat/ChaN - ${mbed-os_SOURCE_DIR}/storage/filesystem/littlefs - ${mbed-os_SOURCE_DIR}/storage/filesystem/littlefs/include - ${mbed-os_SOURCE_DIR}/storage/filesystem/littlefsv2/littlefs - ${mbed-os_SOURCE_DIR}/storage/filesystem/littlefsv2/littlefs/bd - ${mbed-os_SOURCE_DIR}/storage/filesystem/littlefs/littlefs - ${mbed-os_SOURCE_DIR}/storage/blockdevice/include - ${mbed-os_SOURCE_DIR}/storage/filesystem/include - ${mbed-os_SOURCE_DIR}/storage/kvstore/include - ${mbed-os_SOURCE_DIR}/storage/kvstore/kv_config - ${mbed-os_SOURCE_DIR}/storage/kvstore/kv_config/include - ${mbed-os_SOURCE_DIR}/storage/kvstore/tdbstore/include - ${mbed-os_SOURCE_DIR}/storage/kvstore/filesystemstore/include - ${mbed-os_SOURCE_DIR}/storage/kvstore/kvstore_global_api/include - ${mbed-os_SOURCE_DIR}/storage/blockdevice/include/blockdevice -) - target_include_directories(mbed-headers-connectivity INTERFACE ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice @@ -103,7 +81,6 @@ target_include_directories(mbed-stubs-headers add_subdirectory(connectivity) add_subdirectory(events) add_subdirectory(platform) -add_subdirectory(storage) add_library(mbed-stubs INTERFACE) @@ -115,5 +92,4 @@ target_link_libraries(mbed-stubs mbed-stubs-hal mbed-stubs-platform mbed-stubs-rtos - mbed-stubs-storage ) diff --git a/UNITTESTS/stubs/EmulatedSD.h b/UNITTESTS/stubs/EmulatedSD.h deleted file mode 100644 index 4246f63ca0..0000000000 --- a/UNITTESTS/stubs/EmulatedSD.h +++ /dev/null @@ -1,93 +0,0 @@ -/* Copyright (c) 2020 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef EMULATEDSD_H -#define EMULATEDSD_H - -#include "blockdevice/BlockDevice.h" - -class EmulatedSD_Private; - -class EmulatedSD : public mbed::BlockDevice { -public: - EmulatedSD(const char *path); - ~EmulatedSD(); - - /** Initialize a block device - * - * @return 0 on success or a negative error code on failure - */ - virtual int init(); - - /** Deinitialize a block device - * - * @return 0 on success or a negative error code on failure - */ - virtual int deinit(); - - /** Read blocks from a block device - * - * If a failure occurs, it is not possible to determine how many bytes succeeded - * - * @param buffer Buffer to write blocks to - * @param addr Address of block to begin reading from - * @param size Size to read in bytes, must be a multiple of the read block size - * @return 0 on success or a negative error code on failure - */ - virtual int read(void *buffer, bd_addr_t addr, bd_size_t size); - - /** Program blocks to a block device - * - * The blocks must have been erased prior to being programmed - * - * If a failure occurs, it is not possible to determine how many bytes succeeded - * - * @param buffer Buffer of data to write to blocks - * @param addr Address of block to begin writing to - * @param size Size to write in bytes, must be a multiple of the program block size - * @return 0 on success or a negative error code on failure - */ - virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size); - - /** Get the size of a readable block - * - * @return Size of a readable block in bytes - */ - virtual bd_size_t get_read_size() const; - - /** Get the size of a programmable block - * - * @return Size of a programmable block in bytes - * @note Must be a multiple of the read size - */ - virtual bd_size_t get_program_size() const; - - /** Get the total size of the underlying device - * - * @return Size of the underlying device in bytes - */ - virtual bd_size_t size() const; - - /** Get the BlockDevice class type. - * - * @return A string represent the BlockDevice class type. - */ - virtual const char *get_type() const; -private: - EmulatedSD_Private *_p; -}; - -#endif // EMULATEDSD_H diff --git a/UNITTESTS/stubs/storage/CMakeLists.txt b/UNITTESTS/stubs/storage/CMakeLists.txt deleted file mode 100644 index 721f0f1d92..0000000000 --- a/UNITTESTS/stubs/storage/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (c) 2021 ARM Limited. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 - -add_library(mbed-stubs-storage) - -target_sources(mbed-stubs-storage - PRIVATE - BufferedBlockDevice_stub.cpp - ChainingBlockDevice_stub.cpp - EmulatedSD.cpp - ExhaustibleBlockDevice_stub.cpp - FlashSimBlockDevice_stub.cpp - HeapBlockDevice_stub.cpp - MBRBlockDevice_stub.cpp - ObservingBlockDevice_stub.cpp - ProfilingBlockDevice_stub.cpp - ReadOnlyBlockDevice_stub.cpp - SlicingBlockDevice_stub.cpp - kv_config_stub.cpp -) - -target_link_libraries(mbed-stubs-storage - PRIVATE - mbed-headers - mbed-stubs-headers -) diff --git a/UNITTESTS/stubs/storage/EmulatedSD.cpp b/UNITTESTS/stubs/storage/EmulatedSD.cpp deleted file mode 100644 index 9b9fe83477..0000000000 --- a/UNITTESTS/stubs/storage/EmulatedSD.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* Copyright (c) 2020 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "EmulatedSD.h" -#include - -class EmulatedSD_Private { -public: - ~EmulatedSD_Private() { - if (fs) { - fclose(fs); - } - } - const char *path; - FILE *fs; - bd_size_t size; -}; - -EmulatedSD::EmulatedSD(const char *path) -{ - _p = new EmulatedSD_Private; - _p->path = path; -} - -EmulatedSD::~EmulatedSD() -{ - delete _p; -} - -int EmulatedSD::init() -{ - _p->fs = fopen(_p->path, "r+"); - if (!_p->fs) { - perror("fdopen():"); - return -1; - } - if (fseek(_p->fs, 0, SEEK_END)) { - perror("fseek()"); - fclose(_p->fs); - _p->fs = nullptr; - return -1; - } - _p->size = ftell(_p->fs); - rewind(_p->fs); - return 0; -} - -int EmulatedSD::deinit() -{ - fclose(_p->fs); - _p->fs = nullptr; - return 0; -} - -int EmulatedSD::read(void *buffer, bd_addr_t addr, bd_size_t size) -{ - if (!_p->fs) { - return -1; - } - if (fseek(_p->fs, addr, SEEK_SET)) { - perror("fseek()"); - return -1; - } - size_t r = fread(buffer, size, 1, _p->fs); - if (r < 1) { - perror("fread()"); - return -1; - } - return 0; -} - -int EmulatedSD::program(const void *buffer, bd_addr_t addr, bd_size_t size) -{ - if (!_p->fs) { - return -1; - } - if (fseek(_p->fs, addr, SEEK_SET)) { - perror("fseek()"); - return -1; - } - size_t r = fwrite(buffer, size, 1, _p->fs); - if (r < 1) { - perror("fread()"); - return -1; - } - return 0; -} - -bd_size_t EmulatedSD::get_read_size() const -{ - return 512; -} -bd_size_t EmulatedSD::get_program_size() const -{ - return 512; -} -bd_size_t EmulatedSD::size() const -{ - if (!_p->fs) { - return -1; - } - return _p->size; -} -const char *EmulatedSD::get_type() const -{ - return "SD"; -} diff --git a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularcontext/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularcontext/CMakeLists.txt index b56698292a..17c73c0573 100644 --- a/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularcontext/CMakeLists.txt +++ b/connectivity/cellular/tests/UNITTESTS/framework/AT/at_cellularcontext/CMakeLists.txt @@ -25,6 +25,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers mbed-headers-cellular + mbed-headers-filesystem mbed-stubs mbed-stubs-cellular mbed-stubs-headers diff --git a/storage/CMakeLists.txt b/storage/CMakeLists.txt index df4d8a2932..e27f47dd11 100644 --- a/storage/CMakeLists.txt +++ b/storage/CMakeLists.txt @@ -35,6 +35,7 @@ if(${CMAKE_CROSSCOMPILING}) else() # Add these subdirectories for the Unit test add_subdirectory(blockdevice) + add_subdirectory(filesystem) add_subdirectory(kvstore) endif() diff --git a/storage/blockdevice/tests/UNITTESTS/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/CMakeLists.txt index c4980cb0db..40827f215f 100644 --- a/storage/blockdevice/tests/UNITTESTS/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/CMakeLists.txt @@ -3,3 +3,4 @@ add_subdirectory(blockdevice) add_subdirectory(SFDP) +add_subdirectory(doubles) diff --git a/storage/blockdevice/tests/UNITTESTS/SFDP/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/SFDP/CMakeLists.txt index a2bbd95796..25f9207f58 100644 --- a/storage/blockdevice/tests/UNITTESTS/SFDP/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/SFDP/CMakeLists.txt @@ -19,7 +19,8 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers - mbed-stubs-platform + mbed-headers-blockdevice + mbed-stubs-platform gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/CMakeLists.txt index 4fdbe0e969..8e20de29c5 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/CMakeLists.txt @@ -14,8 +14,10 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-headers - mbed-stubs-platform + mbed-stubs-platform + mbed-stubs-blockdevice gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt index f80de82a18..b994c42c61 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt @@ -15,8 +15,10 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-headers - mbed-stubs-platform + mbed-stubs-platform + mbed-stubs-blockdevice gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt index 80c47486be..7209f6305a 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt @@ -14,8 +14,10 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-headers - mbed-stubs-platform + mbed-stubs-platform + mbed-stubs-blockdevice gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt index 99e4a37809..6661f795fb 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt @@ -14,8 +14,10 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-headers - mbed-stubs-platform + mbed-stubs-platform + mbed-stubs-blockdevice gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt index e2bbd7323d..c6a1e12816 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt @@ -58,7 +58,9 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers - mbed-stubs-platform + mbed-headers-blockdevice + mbed-stubs-platform + mbed-stubs-blockdevice gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/CMakeLists.txt index 6a0fa5f8fa..33943640f4 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/CMakeLists.txt @@ -14,8 +14,10 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-headers - mbed-stubs-platform + mbed-stubs-platform + mbed-stubs-blockdevice gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt index ab71b4e3f2..c1a0a4b3a3 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt @@ -15,8 +15,10 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-headers - mbed-stubs-platform + mbed-stubs-platform + mbed-stubs-blockdevice gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt index 9d60f63dd3..767c5cae01 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt @@ -15,8 +15,10 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-headers - mbed-stubs-platform + mbed-stubs-platform + mbed-stubs-blockdevice gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt index a8314edbe1..d23fcf1e69 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt @@ -15,8 +15,10 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-headers - mbed-stubs-platform + mbed-stubs-platform + mbed-stubs-blockdevice gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt index 8d6e078392..37d8ed9aa5 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt @@ -15,7 +15,9 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers - mbed-stubs-platform + mbed-headers-blockdevice + mbed-stubs-platform + mbed-stubs-blockdevice gmock_main ) diff --git a/UNITTESTS/stubs/BlockDevice_mock.h b/storage/blockdevice/tests/UNITTESTS/doubles/BlockDevice_mock.h similarity index 100% rename from UNITTESTS/stubs/BlockDevice_mock.h rename to storage/blockdevice/tests/UNITTESTS/doubles/BlockDevice_mock.h diff --git a/UNITTESTS/stubs/storage/BufferedBlockDevice_stub.cpp b/storage/blockdevice/tests/UNITTESTS/doubles/BufferedBlockDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/storage/BufferedBlockDevice_stub.cpp rename to storage/blockdevice/tests/UNITTESTS/doubles/BufferedBlockDevice_stub.cpp diff --git a/storage/blockdevice/tests/UNITTESTS/doubles/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/doubles/CMakeLists.txt new file mode 100644 index 0000000000..f322f98e23 --- /dev/null +++ b/storage/blockdevice/tests/UNITTESTS/doubles/CMakeLists.txt @@ -0,0 +1,38 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_library(mbed-headers-blockdevice INTERFACE) + +target_include_directories(mbed-headers-blockdevice + INTERFACE + ${mbed-os_SOURCE_DIR}/storage/blockdevice/include + ${mbed-os_SOURCE_DIR}/storage/blockdevice/include/blockdevice +) + +add_library(mbed-stubs-blockdevice) + +target_include_directories(mbed-stubs-blockdevice + PUBLIC + . +) + +target_sources(mbed-stubs-blockdevice + PRIVATE + BufferedBlockDevice_stub.cpp + ChainingBlockDevice_stub.cpp + ExhaustibleBlockDevice_stub.cpp + FlashSimBlockDevice_stub.cpp + HeapBlockDevice_stub.cpp + MBRBlockDevice_stub.cpp + ObservingBlockDevice_stub.cpp + ProfilingBlockDevice_stub.cpp + ReadOnlyBlockDevice_stub.cpp + SlicingBlockDevice_stub.cpp +) + +target_link_libraries(mbed-stubs-blockdevice + PRIVATE + mbed-headers-base + mbed-headers-platform + mbed-headers-blockdevice +) diff --git a/UNITTESTS/stubs/storage/ChainingBlockDevice_stub.cpp b/storage/blockdevice/tests/UNITTESTS/doubles/ChainingBlockDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/storage/ChainingBlockDevice_stub.cpp rename to storage/blockdevice/tests/UNITTESTS/doubles/ChainingBlockDevice_stub.cpp diff --git a/UNITTESTS/stubs/storage/ExhaustibleBlockDevice_stub.cpp b/storage/blockdevice/tests/UNITTESTS/doubles/ExhaustibleBlockDevice_stub.cpp similarity index 98% rename from UNITTESTS/stubs/storage/ExhaustibleBlockDevice_stub.cpp rename to storage/blockdevice/tests/UNITTESTS/doubles/ExhaustibleBlockDevice_stub.cpp index 845da43e6d..58682cd3e4 100644 --- a/UNITTESTS/stubs/storage/ExhaustibleBlockDevice_stub.cpp +++ b/storage/blockdevice/tests/UNITTESTS/doubles/ExhaustibleBlockDevice_stub.cpp @@ -16,7 +16,6 @@ */ #include "ExhaustibleBlockDevice.h" -#include "mbed.h" #include "mbed_critical.h" diff --git a/UNITTESTS/stubs/storage/FlashSimBlockDevice_stub.cpp b/storage/blockdevice/tests/UNITTESTS/doubles/FlashSimBlockDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/storage/FlashSimBlockDevice_stub.cpp rename to storage/blockdevice/tests/UNITTESTS/doubles/FlashSimBlockDevice_stub.cpp diff --git a/UNITTESTS/stubs/storage/HeapBlockDevice_stub.cpp b/storage/blockdevice/tests/UNITTESTS/doubles/HeapBlockDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/storage/HeapBlockDevice_stub.cpp rename to storage/blockdevice/tests/UNITTESTS/doubles/HeapBlockDevice_stub.cpp diff --git a/UNITTESTS/stubs/storage/MBRBlockDevice_stub.cpp b/storage/blockdevice/tests/UNITTESTS/doubles/MBRBlockDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/storage/MBRBlockDevice_stub.cpp rename to storage/blockdevice/tests/UNITTESTS/doubles/MBRBlockDevice_stub.cpp diff --git a/UNITTESTS/stubs/storage/ObservingBlockDevice_stub.cpp b/storage/blockdevice/tests/UNITTESTS/doubles/ObservingBlockDevice_stub.cpp similarity index 99% rename from UNITTESTS/stubs/storage/ObservingBlockDevice_stub.cpp rename to storage/blockdevice/tests/UNITTESTS/doubles/ObservingBlockDevice_stub.cpp index 550bf722a3..1a099c3ff2 100644 --- a/UNITTESTS/stubs/storage/ObservingBlockDevice_stub.cpp +++ b/storage/blockdevice/tests/UNITTESTS/doubles/ObservingBlockDevice_stub.cpp @@ -17,7 +17,6 @@ #include "ObservingBlockDevice.h" #include "ReadOnlyBlockDevice.h" -#include "mbed.h" ObservingBlockDevice::ObservingBlockDevice(BlockDevice *bd) diff --git a/UNITTESTS/stubs/storage/ProfilingBlockDevice_stub.cpp b/storage/blockdevice/tests/UNITTESTS/doubles/ProfilingBlockDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/storage/ProfilingBlockDevice_stub.cpp rename to storage/blockdevice/tests/UNITTESTS/doubles/ProfilingBlockDevice_stub.cpp diff --git a/UNITTESTS/stubs/storage/ReadOnlyBlockDevice_stub.cpp b/storage/blockdevice/tests/UNITTESTS/doubles/ReadOnlyBlockDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/storage/ReadOnlyBlockDevice_stub.cpp rename to storage/blockdevice/tests/UNITTESTS/doubles/ReadOnlyBlockDevice_stub.cpp diff --git a/UNITTESTS/stubs/storage/SlicingBlockDevice_stub.cpp b/storage/blockdevice/tests/UNITTESTS/doubles/SlicingBlockDevice_stub.cpp similarity index 100% rename from UNITTESTS/stubs/storage/SlicingBlockDevice_stub.cpp rename to storage/blockdevice/tests/UNITTESTS/doubles/SlicingBlockDevice_stub.cpp diff --git a/storage/filesystem/CMakeLists.txt b/storage/filesystem/CMakeLists.txt index c3ec4fbe64..cacd423208 100644 --- a/storage/filesystem/CMakeLists.txt +++ b/storage/filesystem/CMakeLists.txt @@ -1,6 +1,10 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) + add_subdirectory(tests/UNITTESTS) +endif() + add_subdirectory(fat) add_subdirectory(littlefs) add_subdirectory(littlefsv2) diff --git a/storage/filesystem/tests/UNITTESTS/.mbedignore b/storage/filesystem/tests/UNITTESTS/.mbedignore new file mode 100644 index 0000000000..72e8ffc0db --- /dev/null +++ b/storage/filesystem/tests/UNITTESTS/.mbedignore @@ -0,0 +1 @@ +* diff --git a/storage/filesystem/tests/UNITTESTS/CMakeLists.txt b/storage/filesystem/tests/UNITTESTS/CMakeLists.txt new file mode 100644 index 0000000000..ef65aa7f99 --- /dev/null +++ b/storage/filesystem/tests/UNITTESTS/CMakeLists.txt @@ -0,0 +1,11 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_library(mbed-headers-filesystem INTERFACE) + +target_include_directories(mbed-headers-filesystem + INTERFACE + ${mbed-os_SOURCE_DIR}/storage/filesystem/littlefs + ${mbed-os_SOURCE_DIR}/storage/filesystem/littlefs/include + ${mbed-os_SOURCE_DIR}/storage/filesystem/include +) diff --git a/storage/kvstore/CMakeLists.txt b/storage/kvstore/CMakeLists.txt index 2f32123f2d..3f9f137edb 100644 --- a/storage/kvstore/CMakeLists.txt +++ b/storage/kvstore/CMakeLists.txt @@ -1,6 +1,10 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) + add_subdirectory(tests/UNITTESTS) +endif() + add_subdirectory(tdbstore) add_subdirectory(filesystemstore) add_subdirectory(securestore) diff --git a/storage/kvstore/filesystemstore/tests/UNITTESTS/CMakeLists.txt b/storage/kvstore/filesystemstore/tests/UNITTESTS/CMakeLists.txt index d1af4569d2..c5286de2c6 100644 --- a/storage/kvstore/filesystemstore/tests/UNITTESTS/CMakeLists.txt +++ b/storage/kvstore/filesystemstore/tests/UNITTESTS/CMakeLists.txt @@ -2,3 +2,4 @@ # SPDX-License-Identifier: Apache-2.0 add_subdirectory(FileSystemStore) +add_subdirectory(doubles) diff --git a/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt b/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt index bd120f19a5..a11b900194 100644 --- a/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt +++ b/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt @@ -33,8 +33,11 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice + mbed-headers-filesystem + mbed-headers-kvstore mbed-stubs-platform - mbed-stubs-storage + mbed-stubs-filesystemstore gmock_main ) diff --git a/storage/kvstore/filesystemstore/tests/UNITTESTS/doubles/CMakeLists.txt b/storage/kvstore/filesystemstore/tests/UNITTESTS/doubles/CMakeLists.txt new file mode 100644 index 0000000000..3b8c4df373 --- /dev/null +++ b/storage/kvstore/filesystemstore/tests/UNITTESTS/doubles/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_library(mbed-stubs-filesystemstore) + +target_sources(mbed-stubs-filesystemstore + PRIVATE + filesystemstore_kv_config_stub.cpp +) + +target_link_libraries(mbed-stubs-filesystemstore + PRIVATE + mbed-headers-blockdevice + mbed-headers-kvstore +) diff --git a/UNITTESTS/stubs/storage/kv_config_stub.cpp b/storage/kvstore/filesystemstore/tests/UNITTESTS/doubles/filesystemstore_kv_config_stub.cpp similarity index 100% rename from UNITTESTS/stubs/storage/kv_config_stub.cpp rename to storage/kvstore/filesystemstore/tests/UNITTESTS/doubles/filesystemstore_kv_config_stub.cpp diff --git a/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt b/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt index 1c1606c41b..46dd748b1f 100644 --- a/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt +++ b/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt @@ -21,7 +21,9 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers - mbed-stubs-platform + mbed-headers-blockdevice + mbed-headers-kvstore + mbed-stubs-platform gmock_main ) diff --git a/storage/kvstore/tests/UNITTESTS/.mbedignore b/storage/kvstore/tests/UNITTESTS/.mbedignore new file mode 100644 index 0000000000..72e8ffc0db --- /dev/null +++ b/storage/kvstore/tests/UNITTESTS/.mbedignore @@ -0,0 +1 @@ +* diff --git a/storage/kvstore/tests/UNITTESTS/CMakeLists.txt b/storage/kvstore/tests/UNITTESTS/CMakeLists.txt new file mode 100644 index 0000000000..0f249218fa --- /dev/null +++ b/storage/kvstore/tests/UNITTESTS/CMakeLists.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_library(mbed-headers-kvstore INTERFACE) + +target_include_directories(mbed-headers-kvstore + INTERFACE + ${mbed-os_SOURCE_DIR}/storage/kvstore/include + ${mbed-os_SOURCE_DIR}/storage/kvstore/kv_config/include + ${mbed-os_SOURCE_DIR}/storage/kvstore/kvstore_global_api/include + ${mbed-os_SOURCE_DIR}/storage/kvstore/securestore/include + ${mbed-os_SOURCE_DIR}/storage/kvstore/tdbstore/include + ${mbed-os_SOURCE_DIR}/storage/kvstore/filesystemstore/include +)