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.
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.
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.
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.
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.
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/.
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.
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.
- 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
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.
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().
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.
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.
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.
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.
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.