Commit Graph

85 Commits (fe1adbcc8685aba9fa1b21bdc5d82274266ed13f)

Author SHA1 Message Date
Robert Walton 7842320ab7 CMake: Add option to enable greentea tests
Add an option to enable the greentea tests independently from the unit
tests.

We can't just use the typical BUILD_TESTING option to enable greentea
tests. BUILD_TESTING enables unit tests and fetches googletest, which
are compiled for the host. Greentea tests are cross compiled and require
a toolchain file. For this reason we add a new option just to enable
greentea tests, preventing build failures triggered by the unit tests
and googletest.
2021-08-10 16:35:11 +01:00
Lingkai Dong dca2aa79a0 Unit tests: Remove redundant CMake target mbed-headers-base
Individual libraries' `target_h` stub headers have now all been moved
from `mbed-headers-base` to `mbed-headers-<library>`.

Note: Even though headers previously in `target_h` are technically
stubs/fakes too, they are used by not only unit tests but also regular
libraries when compiled for unit tests, because no target-specific HAL
implementation exists in this case. In order for regular library
sources to pick up `target_h` headers, those headers must

* have the same names as regular headers
* appear first in include paths

This is why those headers are part of `mbed-headers-<library>` and not
`mbed-stubs-<library>`. Before this refactoring, `mbed-headers-base`
was the first in unit tests' include paths.
2021-08-02 17:42:43 +01:00
Robert Walton b0c0fc9f66 unittests: Reduce runtime of TDBStoreModuleTest.corrupted_set_deinit_init_get
Instead of performing 10,000 "set, deinit, get" operations, let's just
perform 100. This reduces test time from 4.8s to 0.02s.
2021-07-27 21:09:39 +01:00
Robert Walton a09d08917b CMake: unittests: Show all tests in CTest report
Previously a test executable was recognised as a single test by CTest.
However, test executables usually contain multiple test cases, the
results of the test cases should be individually reported. With our
previous setup we could miss test case failures that didn't cause the
executable to return an error code.

This commit uses gtest_discover_test to discover all test cases in a
test executable. This enables CTest to match test passes and failures
from the googletest binary output.
2021-07-27 21:09:39 +01:00
Robert Walton 1e48a61d89 CMake: unittests: Remove trailing whitespace 2021-07-27 21:09:38 +01:00
Jaeden Amero b490c67241
Merge pull request #14882 from LDong-Arm/storage_tests_cleanup
Unit tests: storage: Only use headers, sources and definitions needed by each test
2021-07-07 16:12:10 +01:00
Lingkai Dong 9b8acca136 Remove `#ifdef UNITTEST` from MbedCRC.h
Production code should not contain any test-specific checks. Rather
than checking `UNITTEST`, MbedCRC.h can simply include in all cases
<mstd_type_traits> whose unit test stub exists.

Also remove the `UNITTEST` macro from CMake definitions of kvstore
unit tests which depend on MbedCRC.h.
2021-07-06 17:29:15 +01:00
Lingkai Dong 5c6c08cb75 Unit tests: Make storage tests depend explicitly on headers it uses
The CMake target `mbed-headers` brings in all headers, and we are
gradually moving away from it and explicitly use only headers needed
by each unit test.
2021-07-06 16:20:16 +01:00
Lingkai Dong e1331d5873 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.
2021-07-02 16:27:00 +01:00
Lingkai Dong 7c74d31c57 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.
2021-07-02 16:25:43 +01:00
Lingkai Dong 90446a0345 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.
2021-07-02 16:25:00 +01:00
Lingkai Dong 352ad1a55f Unit tests: Limit storage stubs to link what it uses 2021-07-02 13:44:28 +01:00
Lingkai Dong b1645b2afa 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/.
2021-07-02 13:44:28 +01:00
Lingkai Dong 436291fd89 CMake: storage: Remove trailing whitespaces 2021-07-02 13:44:28 +01:00
Hari Limaye f95052cf6f CMake: Require TEST_SOURCES in greentea CMake file
Assumption that greentea test file is always named main.cpp is
incorrect. Updated mbed_greentea_add_test() macro to make TEST_SOURCES
parameter compulsory, which is used to specify greentea test
file(s). This allows tests to use C, or have a different name.
Therefore also updated all pre-existing greentea test CMake files to
explicity add main.cpp to TEST_SOURCES.
2021-06-29 13:33:42 +01:00
Robert Walton a0befae2d4 CMake: Only build unit tests if Mbed OS is the current project
Typically when adding a unit test directory to a CMake project a check
will be used to ensure the subdirectory is added only if the following
are true:

* The BUILD_TESTING option is set to ON.
* The current CMake project is the top-level project.

The reason being, if a downstream project includes our project they
generally don't want to build our unit tests.

In mbed-os, we do correctly specify the above condition before adding
the central UNITTEST subdirectory, which fetches googletest and adds the
"stub" libraries the unit tests depend on. However, we only check if
CMAKE_CROSSCOMPILING is OFF (or undefined) before actually adding the
unit tests. This mismatched logic would lead to unexpected build
failures in various scenarios. One likely case could be: a downstream
project including mbed-os happens to set CMAKE_CROSSCOMPILING to
OFF/undefined for any reason (possibly to build its own unit tests).
mbed-os would go ahead and attempt to build its tests without fetching
googletest or adding the required stub targets.

To fix the issue replace the check for CMAKE_CROSSCOMPILING in the unit
tests with the same BUILD_TESTING idiom we use for adding the central
UNITTESTS subdirectory.
2021-06-10 23:34:14 +01:00
Rajkumar Kanagaraj 50fc85dc44 CMake: Remove all unittest.cmake script from test suite
- Remove redundant cmake script as already added the CMake configuration file
- Remove redundant empty_baseline as it is no longer needed with the help of CMake configuration file
2021-05-26 07:09:14 -07:00
Anna Bridge 4e586a93d3
Merge pull request #14426 from ARMmbed/feature_unittest_refactor
CMake: Refactor UNITTESTS CMake
2021-05-24 13:04:22 +01:00
harmut01 468ee97bdd Deprecate TDB_EXTERNAL_NO_RBP and FILESYSTEM_NO_RBP in kv_config
NO_RBP (no rollback protection) is intended to not require an internal
TDB, however, DeviceKey, which we use to derive SecureStore's
encryption key, still does. Currently, no internal TDB is created with
these two configurations, meaning there's no way to store the DeviceKey
and SecureStore doesn't work.
2021-05-11 17:19:10 +01:00
Rajkumar Kanagaraj c0a8fe62f5 CMake: Refactor storage TDBstore and FileSystemStore unittest cmake
- Add CMake configuration file in TDBstore and FileSystemStore unittest.
2021-05-11 02:29:56 -07:00
Rajkumar Kanagaraj ba04c1cf76 CMake: Add add_subdirectory of unittests
- add every libraries unittest directory into respective CMake
  which allows to include unittest source into build based on
  MBED_BUILD_UNITTESTS flag
2021-05-11 02:29:56 -07:00
Lingkai Dong 7b763be0e3 TDBStore Whitebox tests: fix memory check
Each block of HeapBlockDevice is only allocated from the heap when
that block is programmed. And erasing a block frees the associated
buffer.

To decide if there is enough heap to run the TDBStore Whitebox tests,
we need to perform a trial program() instead of erase().
2021-04-14 17:19:38 +01:00
Lingkai Dong aedc6009ea TDBStore: call `BlockDevice::erase()` regarless of erase value
From the documentations of `BlockDevice::get_erase_value()`:

    -1 if you can't rely on the value of the erased storage

and `BlockDevice::program()`:

    The blocks must have been erased prior to being programmed

So, `BlockDevice::erase()` should always be called regardless of
erase value.
2021-04-14 17:19:38 +01:00
Lingkai Dong fb4e5e80b4 TDBStore: optimize erase algorithms
Currently `TDBStore::offset_in_erase_unit()` and
`TDBStore::check_erase_before_write()` loop through erase units
one-by-one, until the entire range is covered. This is very inefficient
when the erase size is tiny, e.g. one-byte on a non-flash device for
which we use program as erase.

This commit reworks the algorithms, based on the fact that a block
device can erase or program as many units as needed in one go.
2021-04-14 17:19:38 +01:00
Lingkai Dong e8070514b1 FileSystemStore unit test: remove erased_set_get test
The "erased_set_get" test case deinits `FileSystemStore`, erases the
block device, and reinits `FileSystemStore`. This of course fails,
because `BlockDevice::erase()` removes all stored data including the
format of the `FileSystem` (middle layer), unless the particular type
of block device has a no-op erase implementation.

Note: Previously `HeapBlockDevice::erase()` was essentially a no-op
so this test case did not fail. We recently added the freeing of heap
memory and it uncovered the problem.
2021-04-14 17:16:54 +01:00
Vikas Katariya 8648e4f4d6 Remove: ARM_MUSCA_A1 support
ARM_MUSCA_A1 is not supported since Mbed OS 6.0
Refer: https://github.com/ARMmbed/mbed-os/pull/13165

Therefore remove files from kv_config and TF-M post binary hook script.
2021-02-25 14:02:56 +00:00
Martin Kojtal e6565a4486
Merge pull request #14031 from arduino/blockdevices_namespaces
BlockDevices: specify mbed namespace where needed
2021-02-04 20:08:07 +00:00
Rajkumar Kanagaraj 6824b14e48 CMake: rename greentea test macro 2021-02-02 07:43:40 -08:00
Oliver Wildtgrube 6b0215c687 fix namespaces for MBED_NO_GLOBAL_USING_DIRECTIVE feature
added namespaces in various files
2021-02-02 12:49:11 +01:00
Martin Kojtal 8effecdf29
Merge pull request #14063 from dustin-crossman/pr/wifi_reserved_region
Support arbitrary storage alongside WiFi firmware in external storage on Cypress targets
2021-01-20 08:34:23 +00:00
Martin Kojtal 5021c01852
Merge pull request #14088 from hugueskamba/hk_cmake_greentea_kvstore
CMake: Add support for KVstore Greentea tests
2021-01-11 11:46:34 +00:00
Hugues Kamba 377fba47e2 CMake: Add support for KVstore Greentea tests
The KVstore Greentea tests can now be built with CMake
2020-12-24 14:16:07 +00:00
Hugues Kamba 69b4c13761 CMake: Add Blockdevice dependency to KVstore library
As KVstore relies on BlockDevice add the dependency
in Mbed OS so applications do not have to specify it
2020-12-21 13:57:52 +00:00
Hugues Kamba eedd0b3258 CMake: streamline kvstore support
Link KVStore dependency in Mbed OS so application projects do not have to.
2020-12-17 13:09:38 +00:00
Matthew Macovsky 8c60ce3e32 Create non-public target for Cypress boards with externally-stored WiFi firmware
Targets that inherit from this target will have the defines necessary to
place the WiFi firmware in external storage and enable use of the
external WiFi firmware reserved region block device.
Currently, the only target inheriting from this new target is
CY8CPROTO-062S3-4343W.
2020-12-16 15:31:05 -08:00
Lingkai Dong bfbc18860b KVStore general_tests_phase_1/2: flash simulation no longer required 2020-12-11 14:56:40 +00:00
Lingkai Dong 2064adee7c TDBStore Doxygen: flash characteristics no longer required 2020-12-11 14:56:39 +00:00
Lingkai Dong cfedf1b027 TDBStore whitebox test: flash simulation no longer required 2020-12-11 14:56:39 +00:00
Lingkai Dong 2d8a566718 SecureStore whitebox test: flash simulation no longer required 2020-12-11 14:56:39 +00:00
Lingkai Dong 15e582fc27 TDBStore unit test: flash simulation no longer required 2020-12-11 14:56:36 +00:00
Lingkai Dong 3786d3958d kv_config: TDBStore doesn't require flash simulation anymore 2020-12-11 14:55:16 +00:00
Lingkai Dong 479b704542 "kvstore_global_api" requires "kvstore" for backward compatibility
PR #13908 replaces the umbrella library for all KVStore from
"kvstore_global_api" to "kvstore". Now "kvstore_global_api"
still exists but is restricted to the global API part only.

By adding "kvstore" as a dependency of "kvstore_global_api",
existing bare metal projects (e.g. mbed-bootloader) that use
the latter library name to pull in the KVStore prototype class
will continue to work.
2020-12-09 17:26:32 +00:00
Lingkai Dong 170c07ccdf KVStore: drop './' from CMake paths 2020-12-09 17:26:32 +00:00
Lingkai Dong 34bbcbff92 Fix astyle in KVStore unit tests 2020-12-09 17:26:32 +00:00
Lingkai Dong 0c33db04d5 KVStore: componentize CMake definitions into sub-components 2020-12-09 17:20:43 +00:00
Lingkai Dong 26acbd141a Relocate kvstore Greentea tests into each store type's path 2020-12-09 17:20:43 +00:00
Lingkai Dong 8c1dd01066 Relocate kvstore unit tests into each store type's path 2020-12-09 17:20:42 +00:00
Lingkai Dong b3c13bbea9 Update UNITTEST for kvstore 2020-12-09 17:20:42 +00:00
Lingkai Dong 8ba64c4139 Update include paths 2020-12-09 17:20:42 +00:00
Lingkai Dong e27a6e0fa6 Create a kvstore_global_api for the global API and KVMap 2020-12-09 17:20:42 +00:00