From 71b179d12d1b8aabbfda4e6fb56e09095dbafabd Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Thu, 1 Jul 2021 18:02:04 +0100 Subject: [PATCH 1/9] Unit tests: Remove unused EmulatedSD --- UNITTESTS/stubs/EmulatedSD.h | 93 ------------------- UNITTESTS/stubs/storage/CMakeLists.txt | 1 - UNITTESTS/stubs/storage/EmulatedSD.cpp | 120 ------------------------- 3 files changed, 214 deletions(-) delete mode 100644 UNITTESTS/stubs/EmulatedSD.h delete mode 100644 UNITTESTS/stubs/storage/EmulatedSD.cpp 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 index 721f0f1d92..c6a1de0351 100644 --- a/UNITTESTS/stubs/storage/CMakeLists.txt +++ b/UNITTESTS/stubs/storage/CMakeLists.txt @@ -7,7 +7,6 @@ target_sources(mbed-stubs-storage PRIVATE BufferedBlockDevice_stub.cpp ChainingBlockDevice_stub.cpp - EmulatedSD.cpp ExhaustibleBlockDevice_stub.cpp FlashSimBlockDevice_stub.cpp HeapBlockDevice_stub.cpp 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"; -} From 436291fd895cb3c02510486e68f6b76644beeef4 Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Fri, 2 Jul 2021 11:48:20 +0100 Subject: [PATCH 2/9] CMake: storage: Remove trailing whitespaces --- storage/blockdevice/tests/UNITTESTS/SFDP/CMakeLists.txt | 2 +- .../UNITTESTS/blockdevice/BufferedBlockDevice/CMakeLists.txt | 2 +- .../UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt | 2 +- .../UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt | 2 +- .../UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt | 2 +- .../tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt | 2 +- .../tests/UNITTESTS/blockdevice/MBRBlockDevice/CMakeLists.txt | 2 +- .../UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt | 2 +- .../UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt | 2 +- .../UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt | 2 +- .../UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt | 2 +- .../kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/storage/blockdevice/tests/UNITTESTS/SFDP/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/SFDP/CMakeLists.txt index a2bbd95796..8f5c3750bf 100644 --- a/storage/blockdevice/tests/UNITTESTS/SFDP/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/SFDP/CMakeLists.txt @@ -19,7 +19,7 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers - mbed-stubs-platform + 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..b0f0b40469 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/CMakeLists.txt @@ -15,7 +15,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers mbed-stubs-headers - mbed-stubs-platform + mbed-stubs-platform gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt index f80de82a18..d5a49ac9b2 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt @@ -16,7 +16,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers mbed-stubs-headers - mbed-stubs-platform + mbed-stubs-platform gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt index 80c47486be..ea596a7f39 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt @@ -15,7 +15,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers mbed-stubs-headers - mbed-stubs-platform + mbed-stubs-platform gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt index 99e4a37809..c708f3eaef 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt @@ -15,7 +15,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers mbed-stubs-headers - mbed-stubs-platform + mbed-stubs-platform gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt index e2bbd7323d..822e44746a 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt @@ -58,7 +58,7 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers - mbed-stubs-platform + mbed-stubs-platform gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/CMakeLists.txt index 6a0fa5f8fa..31f7ad1959 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/CMakeLists.txt @@ -15,7 +15,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers mbed-stubs-headers - mbed-stubs-platform + mbed-stubs-platform gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt index ab71b4e3f2..fe5785dddb 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt @@ -16,7 +16,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers mbed-stubs-headers - mbed-stubs-platform + mbed-stubs-platform gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt index 9d60f63dd3..b58bd7140c 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt @@ -16,7 +16,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers mbed-stubs-headers - mbed-stubs-platform + mbed-stubs-platform gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt index a8314edbe1..e96d524beb 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt @@ -16,7 +16,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers mbed-stubs-headers - mbed-stubs-platform + mbed-stubs-platform gmock_main ) diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt index 8d6e078392..a907791915 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt @@ -15,7 +15,7 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers - mbed-stubs-platform + mbed-stubs-platform gmock_main ) diff --git a/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt b/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt index 1c1606c41b..1163e6b5ed 100644 --- a/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt +++ b/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt @@ -21,7 +21,7 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers - mbed-stubs-platform + mbed-stubs-platform gmock_main ) From b1645b2afa40d8933464a8e8126277e01bbaf6a7 Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Thu, 1 Jul 2021 17:58:22 +0100 Subject: [PATCH 3/9] Move storage stubs into subdirectories of Mbed OS storage Move storage stubs from UNITTESTS/stubs into components inside the top-level storage directory. Specifically, * storage/blockdevice/tests/UNITTESTS/doubles/ for BlockDevice stubs. * storage/kvstore/filesystemstore/tests/UNITTESTS/ for a stub used by the FileSystemStore test. The stub has been renamed from kv_config_stub.cpp to filesystemstore_kv_config_stub.cpp, to make it evident why it doesn't go into storage/kvstore/kv_config/. --- UNITTESTS/stubs/CMakeLists.txt | 2 -- .../blockdevice/tests/UNITTESTS/CMakeLists.txt | 1 + .../BufferedBlockDevice/CMakeLists.txt | 1 + .../ChainingBlockDevice/CMakeLists.txt | 1 + .../ExhaustibleBlockDevice/CMakeLists.txt | 1 + .../FlashSimBlockDevice/CMakeLists.txt | 1 + .../blockdevice/HeapBlockDevice/CMakeLists.txt | 1 + .../blockdevice/MBRBlockDevice/CMakeLists.txt | 1 + .../ObservingBlockDevice/CMakeLists.txt | 1 + .../ProfilingBlockDevice/CMakeLists.txt | 1 + .../ReadOnlyBlockDevice/CMakeLists.txt | 1 + .../blockdevice/SlicingBlockDevice/CMakeLists.txt | 1 + .../tests/UNITTESTS/doubles}/BlockDevice_mock.h | 0 .../doubles}/BufferedBlockDevice_stub.cpp | 0 .../tests/UNITTESTS/doubles}/CMakeLists.txt | 12 ++++++++---- .../doubles}/ChainingBlockDevice_stub.cpp | 0 .../doubles}/ExhaustibleBlockDevice_stub.cpp | 0 .../doubles}/FlashSimBlockDevice_stub.cpp | 0 .../UNITTESTS/doubles}/HeapBlockDevice_stub.cpp | 0 .../UNITTESTS/doubles}/MBRBlockDevice_stub.cpp | 0 .../doubles}/ObservingBlockDevice_stub.cpp | 0 .../doubles}/ProfilingBlockDevice_stub.cpp | 0 .../doubles}/ReadOnlyBlockDevice_stub.cpp | 0 .../doubles}/SlicingBlockDevice_stub.cpp | 0 .../tests/UNITTESTS/CMakeLists.txt | 1 + .../UNITTESTS/FileSystemStore/CMakeLists.txt | 2 +- .../tests/UNITTESTS/doubles/CMakeLists.txt | 15 +++++++++++++++ .../doubles/filesystemstore_kv_config_stub.cpp | 0 28 files changed, 36 insertions(+), 7 deletions(-) rename {UNITTESTS/stubs => storage/blockdevice/tests/UNITTESTS/doubles}/BlockDevice_mock.h (100%) rename {UNITTESTS/stubs/storage => storage/blockdevice/tests/UNITTESTS/doubles}/BufferedBlockDevice_stub.cpp (100%) rename {UNITTESTS/stubs/storage => storage/blockdevice/tests/UNITTESTS/doubles}/CMakeLists.txt (73%) rename {UNITTESTS/stubs/storage => storage/blockdevice/tests/UNITTESTS/doubles}/ChainingBlockDevice_stub.cpp (100%) rename {UNITTESTS/stubs/storage => storage/blockdevice/tests/UNITTESTS/doubles}/ExhaustibleBlockDevice_stub.cpp (100%) rename {UNITTESTS/stubs/storage => storage/blockdevice/tests/UNITTESTS/doubles}/FlashSimBlockDevice_stub.cpp (100%) rename {UNITTESTS/stubs/storage => storage/blockdevice/tests/UNITTESTS/doubles}/HeapBlockDevice_stub.cpp (100%) rename {UNITTESTS/stubs/storage => storage/blockdevice/tests/UNITTESTS/doubles}/MBRBlockDevice_stub.cpp (100%) rename {UNITTESTS/stubs/storage => storage/blockdevice/tests/UNITTESTS/doubles}/ObservingBlockDevice_stub.cpp (100%) rename {UNITTESTS/stubs/storage => storage/blockdevice/tests/UNITTESTS/doubles}/ProfilingBlockDevice_stub.cpp (100%) rename {UNITTESTS/stubs/storage => storage/blockdevice/tests/UNITTESTS/doubles}/ReadOnlyBlockDevice_stub.cpp (100%) rename {UNITTESTS/stubs/storage => storage/blockdevice/tests/UNITTESTS/doubles}/SlicingBlockDevice_stub.cpp (100%) create mode 100644 storage/kvstore/filesystemstore/tests/UNITTESTS/doubles/CMakeLists.txt rename UNITTESTS/stubs/storage/kv_config_stub.cpp => storage/kvstore/filesystemstore/tests/UNITTESTS/doubles/filesystemstore_kv_config_stub.cpp (100%) diff --git a/UNITTESTS/stubs/CMakeLists.txt b/UNITTESTS/stubs/CMakeLists.txt index 677566fe77..3e1881c1cc 100644 --- a/UNITTESTS/stubs/CMakeLists.txt +++ b/UNITTESTS/stubs/CMakeLists.txt @@ -103,7 +103,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 +114,4 @@ target_link_libraries(mbed-stubs mbed-stubs-hal mbed-stubs-platform mbed-stubs-rtos - mbed-stubs-storage ) 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/blockdevice/BufferedBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/CMakeLists.txt index b0f0b40469..ac90fa55f1 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/CMakeLists.txt @@ -16,6 +16,7 @@ target_link_libraries(${TEST_NAME} mbed-headers mbed-stubs-headers 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 d5a49ac9b2..cccd23bd29 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt @@ -17,6 +17,7 @@ target_link_libraries(${TEST_NAME} mbed-headers mbed-stubs-headers 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 ea596a7f39..26ba970585 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt @@ -16,6 +16,7 @@ target_link_libraries(${TEST_NAME} mbed-headers mbed-stubs-headers 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 c708f3eaef..db5d173795 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt @@ -16,6 +16,7 @@ target_link_libraries(${TEST_NAME} mbed-headers mbed-stubs-headers 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 822e44746a..7e3aaa4429 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt @@ -59,6 +59,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers 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 31f7ad1959..5b77b4b48a 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/CMakeLists.txt @@ -16,6 +16,7 @@ target_link_libraries(${TEST_NAME} mbed-headers mbed-stubs-headers 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 fe5785dddb..023ab1c95a 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt @@ -17,6 +17,7 @@ target_link_libraries(${TEST_NAME} mbed-headers mbed-stubs-headers 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 b58bd7140c..ed4ed3b8f9 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt @@ -17,6 +17,7 @@ target_link_libraries(${TEST_NAME} mbed-headers mbed-stubs-headers 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 e96d524beb..463b589e9e 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt @@ -17,6 +17,7 @@ target_link_libraries(${TEST_NAME} mbed-headers mbed-stubs-headers 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 a907791915..c9c869e953 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt @@ -16,6 +16,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers 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/UNITTESTS/stubs/storage/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/doubles/CMakeLists.txt similarity index 73% rename from UNITTESTS/stubs/storage/CMakeLists.txt rename to storage/blockdevice/tests/UNITTESTS/doubles/CMakeLists.txt index c6a1de0351..b9b800968a 100644 --- a/UNITTESTS/stubs/storage/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/doubles/CMakeLists.txt @@ -1,9 +1,14 @@ # Copyright (c) 2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -add_library(mbed-stubs-storage) +add_library(mbed-stubs-blockdevice) -target_sources(mbed-stubs-storage +target_include_directories(mbed-stubs-blockdevice + PUBLIC + . +) + +target_sources(mbed-stubs-blockdevice PRIVATE BufferedBlockDevice_stub.cpp ChainingBlockDevice_stub.cpp @@ -15,10 +20,9 @@ target_sources(mbed-stubs-storage ProfilingBlockDevice_stub.cpp ReadOnlyBlockDevice_stub.cpp SlicingBlockDevice_stub.cpp - kv_config_stub.cpp ) -target_link_libraries(mbed-stubs-storage +target_link_libraries(mbed-stubs-blockdevice PRIVATE mbed-headers mbed-stubs-headers 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 100% rename from UNITTESTS/stubs/storage/ExhaustibleBlockDevice_stub.cpp rename to storage/blockdevice/tests/UNITTESTS/doubles/ExhaustibleBlockDevice_stub.cpp 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 100% rename from UNITTESTS/stubs/storage/ObservingBlockDevice_stub.cpp rename to storage/blockdevice/tests/UNITTESTS/doubles/ObservingBlockDevice_stub.cpp 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/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..7c420d1a0c 100644 --- a/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt +++ b/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt @@ -34,7 +34,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers 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..27782fbd6c --- /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 + mbed-stubs-headers +) 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 From 7e039125873b64579d7dab798c12fa2fcb02eb24 Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Fri, 2 Jul 2021 13:31:49 +0100 Subject: [PATCH 4/9] Unit tests: Do not include mbed.h in storage stubs The header `mbed.h` pulls in headers from a number of Mbed OS components that are not necessarily used. It was intended for user applications only, and libraries and unit tests should explicitly include library headers it uses to limit dependencies. This change avoids having to link unnecessary libraries in storage unit tests' CMake definitions. --- .../tests/UNITTESTS/doubles/ExhaustibleBlockDevice_stub.cpp | 1 - .../tests/UNITTESTS/doubles/ObservingBlockDevice_stub.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/storage/blockdevice/tests/UNITTESTS/doubles/ExhaustibleBlockDevice_stub.cpp b/storage/blockdevice/tests/UNITTESTS/doubles/ExhaustibleBlockDevice_stub.cpp index 845da43e6d..58682cd3e4 100644 --- a/storage/blockdevice/tests/UNITTESTS/doubles/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/storage/blockdevice/tests/UNITTESTS/doubles/ObservingBlockDevice_stub.cpp b/storage/blockdevice/tests/UNITTESTS/doubles/ObservingBlockDevice_stub.cpp index 550bf722a3..1a099c3ff2 100644 --- a/storage/blockdevice/tests/UNITTESTS/doubles/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) From 352ad1a55f1ac3dcbc75b372a096519c75e0b548 Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Fri, 2 Jul 2021 13:42:56 +0100 Subject: [PATCH 5/9] Unit tests: Limit storage stubs to link what it uses --- storage/blockdevice/tests/UNITTESTS/doubles/CMakeLists.txt | 5 +++-- .../filesystemstore/tests/UNITTESTS/doubles/CMakeLists.txt | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/storage/blockdevice/tests/UNITTESTS/doubles/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/doubles/CMakeLists.txt index b9b800968a..99337e6a35 100644 --- a/storage/blockdevice/tests/UNITTESTS/doubles/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/doubles/CMakeLists.txt @@ -24,6 +24,7 @@ target_sources(mbed-stubs-blockdevice target_link_libraries(mbed-stubs-blockdevice PRIVATE - mbed-headers - mbed-stubs-headers + mbed-headers-base + mbed-headers-platform + mbed-headers-storage ) diff --git a/storage/kvstore/filesystemstore/tests/UNITTESTS/doubles/CMakeLists.txt b/storage/kvstore/filesystemstore/tests/UNITTESTS/doubles/CMakeLists.txt index 27782fbd6c..4152c91e04 100644 --- a/storage/kvstore/filesystemstore/tests/UNITTESTS/doubles/CMakeLists.txt +++ b/storage/kvstore/filesystemstore/tests/UNITTESTS/doubles/CMakeLists.txt @@ -10,6 +10,5 @@ target_sources(mbed-stubs-filesystemstore target_link_libraries(mbed-stubs-filesystemstore PRIVATE - mbed-headers - mbed-stubs-headers + mbed-headers-storage ) From 90446a034599865e9e309a66349af2c2a023e6de Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Fri, 2 Jul 2021 14:50:58 +0100 Subject: [PATCH 6/9] Unit tests: Create mbed-headers-blockdevice Create a CMake target mbed-headers-blockdevice to separate BlockDevice headers from the generic mbed-headers-storage. Update tests to use it. --- UNITTESTS/stubs/CMakeLists.txt | 2 -- .../blockdevice/tests/UNITTESTS/SFDP/CMakeLists.txt | 1 + .../blockdevice/BufferedBlockDevice/CMakeLists.txt | 1 + .../blockdevice/ChainingBlockDevice/CMakeLists.txt | 1 + .../blockdevice/ExhaustibleBlockDevice/CMakeLists.txt | 1 + .../blockdevice/FlashSimBlockDevice/CMakeLists.txt | 1 + .../blockdevice/HeapBlockDevice/CMakeLists.txt | 1 + .../blockdevice/MBRBlockDevice/CMakeLists.txt | 1 + .../blockdevice/ObservingBlockDevice/CMakeLists.txt | 1 + .../blockdevice/ProfilingBlockDevice/CMakeLists.txt | 1 + .../blockdevice/ReadOnlyBlockDevice/CMakeLists.txt | 1 + .../blockdevice/SlicingBlockDevice/CMakeLists.txt | 1 + .../blockdevice/tests/UNITTESTS/doubles/CMakeLists.txt | 10 +++++++++- .../tests/UNITTESTS/FileSystemStore/CMakeLists.txt | 1 + .../tests/UNITTESTS/doubles/CMakeLists.txt | 1 + .../tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt | 1 + 16 files changed, 23 insertions(+), 3 deletions(-) diff --git a/UNITTESTS/stubs/CMakeLists.txt b/UNITTESTS/stubs/CMakeLists.txt index 3e1881c1cc..7090c2250c 100644 --- a/UNITTESTS/stubs/CMakeLists.txt +++ b/UNITTESTS/stubs/CMakeLists.txt @@ -50,7 +50,6 @@ target_include_directories(mbed-headers-storage ${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 @@ -58,7 +57,6 @@ target_include_directories(mbed-headers-storage ${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 diff --git a/storage/blockdevice/tests/UNITTESTS/SFDP/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/SFDP/CMakeLists.txt index 8f5c3750bf..25f9207f58 100644 --- a/storage/blockdevice/tests/UNITTESTS/SFDP/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/SFDP/CMakeLists.txt @@ -19,6 +19,7 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + 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 ac90fa55f1..8e20de29c5 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/BufferedBlockDevice/CMakeLists.txt @@ -14,6 +14,7 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-headers mbed-stubs-platform mbed-stubs-blockdevice diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt index cccd23bd29..b994c42c61 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ChainingBlockDevice/CMakeLists.txt @@ -15,6 +15,7 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-headers mbed-stubs-platform mbed-stubs-blockdevice diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt index 26ba970585..7209f6305a 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ExhaustibleBlockDevice/CMakeLists.txt @@ -14,6 +14,7 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-headers mbed-stubs-platform mbed-stubs-blockdevice diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt index db5d173795..6661f795fb 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/FlashSimBlockDevice/CMakeLists.txt @@ -14,6 +14,7 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-headers mbed-stubs-platform mbed-stubs-blockdevice diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt index 7e3aaa4429..c6a1e12816 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/HeapBlockDevice/CMakeLists.txt @@ -58,6 +58,7 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + 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 5b77b4b48a..33943640f4 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/MBRBlockDevice/CMakeLists.txt @@ -14,6 +14,7 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-headers mbed-stubs-platform mbed-stubs-blockdevice diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt index 023ab1c95a..c1a0a4b3a3 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ObservingBlockDevice/CMakeLists.txt @@ -15,6 +15,7 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-headers mbed-stubs-platform mbed-stubs-blockdevice diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt index ed4ed3b8f9..767c5cae01 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ProfilingBlockDevice/CMakeLists.txt @@ -15,6 +15,7 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-headers mbed-stubs-platform mbed-stubs-blockdevice diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt index 463b589e9e..d23fcf1e69 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/ReadOnlyBlockDevice/CMakeLists.txt @@ -15,6 +15,7 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-headers mbed-stubs-platform mbed-stubs-blockdevice diff --git a/storage/blockdevice/tests/UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt index c9c869e953..37d8ed9aa5 100644 --- a/storage/blockdevice/tests/UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/blockdevice/SlicingBlockDevice/CMakeLists.txt @@ -15,6 +15,7 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-platform mbed-stubs-blockdevice gmock_main diff --git a/storage/blockdevice/tests/UNITTESTS/doubles/CMakeLists.txt b/storage/blockdevice/tests/UNITTESTS/doubles/CMakeLists.txt index 99337e6a35..f322f98e23 100644 --- a/storage/blockdevice/tests/UNITTESTS/doubles/CMakeLists.txt +++ b/storage/blockdevice/tests/UNITTESTS/doubles/CMakeLists.txt @@ -1,6 +1,14 @@ # 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 @@ -26,5 +34,5 @@ target_link_libraries(mbed-stubs-blockdevice PRIVATE mbed-headers-base mbed-headers-platform - mbed-headers-storage + mbed-headers-blockdevice ) diff --git a/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt b/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt index 7c420d1a0c..c2256548a7 100644 --- a/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt +++ b/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt @@ -33,6 +33,7 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-platform 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 index 4152c91e04..e780ad9da8 100644 --- a/storage/kvstore/filesystemstore/tests/UNITTESTS/doubles/CMakeLists.txt +++ b/storage/kvstore/filesystemstore/tests/UNITTESTS/doubles/CMakeLists.txt @@ -10,5 +10,6 @@ target_sources(mbed-stubs-filesystemstore target_link_libraries(mbed-stubs-filesystemstore PRIVATE + mbed-headers-blockdevice mbed-headers-storage ) diff --git a/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt b/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt index 1163e6b5ed..bd603f6dd5 100644 --- a/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt +++ b/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt @@ -21,6 +21,7 @@ target_sources(${TEST_NAME} target_link_libraries(${TEST_NAME} PRIVATE mbed-headers + mbed-headers-blockdevice mbed-stubs-platform gmock_main ) From 7c74d31c57d00ffbb620bf42ac9f7d3b44655611 Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Fri, 2 Jul 2021 16:07:51 +0100 Subject: [PATCH 7/9] Unit tests: Create mbed-headers-filesystem Create a CMake target mbed-headers-filesystem to separate FileSystem headers from the generic mbed-headers-storage. Update tests to use it. --- UNITTESTS/stubs/CMakeLists.txt | 8 -------- .../framework/AT/at_cellularcontext/CMakeLists.txt | 1 + storage/CMakeLists.txt | 1 + storage/filesystem/CMakeLists.txt | 4 ++++ storage/filesystem/tests/UNITTESTS/.mbedignore | 1 + storage/filesystem/tests/UNITTESTS/CMakeLists.txt | 11 +++++++++++ .../tests/UNITTESTS/FileSystemStore/CMakeLists.txt | 1 + 7 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 storage/filesystem/tests/UNITTESTS/.mbedignore create mode 100644 storage/filesystem/tests/UNITTESTS/CMakeLists.txt diff --git a/UNITTESTS/stubs/CMakeLists.txt b/UNITTESTS/stubs/CMakeLists.txt index 7090c2250c..154868a61b 100644 --- a/UNITTESTS/stubs/CMakeLists.txt +++ b/UNITTESTS/stubs/CMakeLists.txt @@ -43,14 +43,6 @@ target_include_directories(mbed-headers-base 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/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 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/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/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt b/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt index c2256548a7..b505e0c4cc 100644 --- a/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt +++ b/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt @@ -34,6 +34,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers mbed-headers-blockdevice + mbed-headers-filesystem mbed-stubs-platform mbed-stubs-filesystemstore gmock_main From e1331d58733fa5a6c26f001cb6498ebdf5d31493 Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Fri, 2 Jul 2021 16:20:42 +0100 Subject: [PATCH 8/9] Unit tests: Create mbed-headers-kvstore Create a CMake target mbed-headers-kvstore to separate KVStore headers from the generic mbed-headers-storage. Update tests to use it. --- UNITTESTS/stubs/CMakeLists.txt | 6 ------ storage/kvstore/CMakeLists.txt | 4 ++++ .../tests/UNITTESTS/FileSystemStore/CMakeLists.txt | 1 + .../tests/UNITTESTS/doubles/CMakeLists.txt | 2 +- .../tests/UNITTESTS/TDBStore/CMakeLists.txt | 1 + storage/kvstore/tests/UNITTESTS/.mbedignore | 1 + storage/kvstore/tests/UNITTESTS/CMakeLists.txt | 14 ++++++++++++++ 7 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 storage/kvstore/tests/UNITTESTS/.mbedignore create mode 100644 storage/kvstore/tests/UNITTESTS/CMakeLists.txt diff --git a/UNITTESTS/stubs/CMakeLists.txt b/UNITTESTS/stubs/CMakeLists.txt index 154868a61b..0d69fc3730 100644 --- a/UNITTESTS/stubs/CMakeLists.txt +++ b/UNITTESTS/stubs/CMakeLists.txt @@ -43,12 +43,6 @@ target_include_directories(mbed-headers-base target_include_directories(mbed-headers-storage INTERFACE - ${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 ) target_include_directories(mbed-headers-connectivity 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/FileSystemStore/CMakeLists.txt b/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt index b505e0c4cc..a11b900194 100644 --- a/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt +++ b/storage/kvstore/filesystemstore/tests/UNITTESTS/FileSystemStore/CMakeLists.txt @@ -35,6 +35,7 @@ target_link_libraries(${TEST_NAME} mbed-headers mbed-headers-blockdevice mbed-headers-filesystem + mbed-headers-kvstore mbed-stubs-platform 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 index e780ad9da8..3b8c4df373 100644 --- a/storage/kvstore/filesystemstore/tests/UNITTESTS/doubles/CMakeLists.txt +++ b/storage/kvstore/filesystemstore/tests/UNITTESTS/doubles/CMakeLists.txt @@ -11,5 +11,5 @@ target_sources(mbed-stubs-filesystemstore target_link_libraries(mbed-stubs-filesystemstore PRIVATE mbed-headers-blockdevice - mbed-headers-storage + mbed-headers-kvstore ) diff --git a/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt b/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt index bd603f6dd5..46dd748b1f 100644 --- a/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt +++ b/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/CMakeLists.txt @@ -22,6 +22,7 @@ target_link_libraries(${TEST_NAME} PRIVATE mbed-headers 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 +) From f8e3f71ea5740cd999de616d80de2839abc5006b Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Fri, 2 Jul 2021 16:29:41 +0100 Subject: [PATCH 9/9] Unit tests: Remove mbed-headers-storage --- UNITTESTS/stubs/CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/UNITTESTS/stubs/CMakeLists.txt b/UNITTESTS/stubs/CMakeLists.txt index 0d69fc3730..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,10 +39,6 @@ target_include_directories(mbed-headers-base ${mbed-os_SOURCE_DIR}/UNITTESTS/target_h/sys ) -target_include_directories(mbed-headers-storage - INTERFACE -) - target_include_directories(mbed-headers-connectivity INTERFACE ${mbed-os_SOURCE_DIR}/connectivity/libraries/nanostack-libservice