Commit Graph

100 Commits (fe1adbcc8685aba9fa1b21bdc5d82274266ed13f)

Author SHA1 Message Date
Lingkai Dong 0b868d5a1a General block device test: Fix thread stack allocation
The test case for multithreaded erase/program/read allocates a few
Thread objects from the heap and starts them. It has a few problems:

* To check that there will be enough heap to start a new thread, the
test case tries to allocate a dummy buffer of the thread's heap size
and then frees it, before starting the thread. Then the thread will
allocate its own stack. Such check is not reliable, because threads
that are already running also perform additional allocation (when
running `test_thread_job()`) and may take away the memory we just
checked.
* When deleting all threads in a loop, the loop boundary misses the
last thread if the last thread object was allocated but not started
(i.e. due to failed thread stack allocation check).

To fix the issues
* Start a thread without any allocation test. Following the preceding
commit "rtos: Thread: Make stack allocation failure runtime catchable",
`Thread::start()` now returns `osErrorNoMemory` if stack allocation
fails which we can handle.
* Store pointers to all threads in a zero-initialized array, and
free all elements at the end of the test.
2021-09-08 14:18:21 +01:00
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 a16c2bf173 SFDP: Add unit tests for Sector Map Parameter Table parsing
Add tests for `sfdp_parse_sector_map_table()` which currently (at the
time of this commit) supports flash devices with
* no Sector Map Parameter Table (i.e. the whole flash is uniform and
non-configurable)
* a single descriptor in the Sector Map Parameter Table (i.e. the
flash layout is non-configurable and has multiple regions)

Support and unit tests for flashes with multiple configurable layouts
will be added in the future.

Note: The implementation of `sfdp_parse_sector_map_table()` assumes
the table to be valid if read succeeds, so the SFDP reader callback
needs to ensure it reads data correctly or return an error.
2021-08-06 15:27:28 +01:00
Lingkai Dong f08c3cdfb5 SFDP: TestEraseTypeAlgorithm: Move setup into test case
The test data `struct mbed::sfdp_smptbl_info smptbl` is only relevant
to `TestEraseTypeAlgorithm` and not shared with other test cases.
2021-08-06 14:30:16 +01:00
Lingkai Dong 651099225e SFDP: Set region count to 1 for no sector map
A flash device with no sector map table has uniform sectors, and we
treat the whole flash as one region. In this case the function
`sfdp_parse_sector_map_table()` sets the single region's size and high
boundary accordingly, but it lacks setting of region count to 1, so
users of the SFDP parser may not get the correct number of regions.
This commit fixes the issue.
2021-08-06 14:30:16 +01:00
Lingkai Dong 68694255b5 SFDP: Move handling of no sector map into `if`
When a flash chip's SFDP table has no sector map, we treat the whole
flash as a single region. As an optimization, this should only be
done if there is indeed no sector map.
2021-08-04 14:03:24 +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 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
Martin Kojtal 6827b4275b
Merge pull request #14397 from macronix/macronix_spi_NAND
add SPI NAND Block device driver
2021-07-26 15:24:47 +02:00
Martin Kojtal 11439bf264
Merge pull request #14909 from DDC-NDRS/ndrs-pst
SPIF: fixed _address_size to always initialize as 3_BYTES in ::init()
2021-07-20 09:55:08 +02:00
ndrs-pst 8394988354 SPIF: Moving _address_size = SPIF_ADDR_SIZE_3_BYTES from constructors into ::init() instead 2021-07-19 17:30:00 +07: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
Martin Kojtal 69d1db9730
Merge pull request #14849 from arduino/pr_spif_namespace
SPIFBlockDevice: Add mbed namespace to BD_ERROR_DEVICE_ERROR
2021-07-07 10:13:21 +02:00
Lingkai Dong fcb71fb617 Unit tests: Clean up unused sources and definitions from storage 2021-07-06 16:31:03 +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 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 7e03912587 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.
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
giulcioffi 02108ea2b4 Fix missing 'mbed' namespace error in SPIFBlockDevice 2021-07-01 09:57:38 +02: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
rogeryou 4f29d6a643
Update SPINANDBlockDevice.cpp
Fix the spelling issue
2021-06-10 09:47:43 +08:00
rogeryou e66784fc80
Update SPINANDBlockDevice.h
Fix the spelling issue
2021-06-10 09:46:17 +08:00
rogeryou 99a3bb9896
Update CMakeLists.txt
Fix the issue
2021-06-10 09:38:36 +08:00
Martin Kojtal 5fe4dafc34
Merge pull request #14221 from macronix/macronix_rww
Enable the RWW function of Macronix Flash MX25LW51245G in OSPI block device driver
2021-06-02 16:53:59 +02: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
rogeryou 643a92623b
Update SPINANDBlockDevice.cpp
Modify astyle
2021-05-12 09:37:24 +08:00
Rajkumar Kanagaraj 98215d322d CMake: Fix ChainingBlockDevice unittest
- ChainingBlockModuleTest test case compares two strings with EXPECT_EQ
which normally compare strings residing memory address so replaced it with EXPECT_STREQ  to compare strings.
2021-05-11 02:29:56 -07:00
Rajkumar Kanagaraj 4536fff63a CMake: Refactor storage blockdevice and SFDP unittests cmake
- Add CMake configuration file
- Fix the header inclusion in blockdevice unittests
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
rogeryou 6d90674546
Update OSPIFBlockDevice.cpp
modify the definition of the tables
2021-05-07 09:27:37 +08:00
Lingkai Dong 6b5e467f96 HeapBlockDevice::erase(): free up heap memory
`HeapBlockDevice::erase()` previously performed a range and alignment
check only. This commit adds freeing of heap memory.
2021-04-14 17:00:17 +01:00
Lingkai Dong 7ef9e6175f HeapBlockDevice: allocate with std::nothrow
Mbed OS does not enable C++ exceptions, so we should call `new` with
`std::nothrow` which returns a C-style NULL pointer when allocation
fails to allow error handling.

For consistency of style within the same file, this commit also
replaces `malloc()` and `free()` to `new (std::nothrow)` and `delete`.
2021-04-14 17:00:17 +01:00
George Psimenos 885cdef5f7 Add standard pin-names validation script & tests 2021-03-18 17:01:53 +00:00
jeromecoutant eca714c93f [STD-PIN] update tests and components 2021-03-18 17:01:50 +00:00
rogeryou ce2c0a23bd modify for 1IO read 2021-03-18 15:08:50 +08:00
rogeryou a0ca54c219
Update SPINANDBlockDevice.h
Modify astyle
2021-03-15 15:36:01 +08:00
rogeryou 8c70b355c0
Update CMakeLists.txt
Modify astyle
2021-03-15 15:34:34 +08:00
rogeryou d444e39842 remove 2021-03-11 14:44:12 +08:00
rogeryou 948c8c71c0 modify astyle 2021-03-11 14:36:38 +08:00
rogeryou 1bca44fe2d modify astyle 2021-03-10 16:47:35 +08:00
rogeryou 5f56a5e6d6 modify astyle 2021-03-10 16:18:22 +08:00
rogeryou b8ccb2e662 add SPI NAND Block device driver 2021-03-09 15:40:08 +08: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
rogeryou 8d00a6f39f modify config file 2021-02-04 15:12:26 +08:00
rogeryou 93b6d5554d add MX25LW51245G_config.h 2021-02-03 16:55:18 +08:00
Rajkumar Kanagaraj 6824b14e48 CMake: rename greentea test macro 2021-02-02 07:43:40 -08:00