Commit Graph

739 Commits (75513154d2c3737ea4663eb0bf45c5e549891863)

Author SHA1 Message Date
Lingkai Dong 48cf1c9c80 rtos: Thread: Make stack allocation failure runtime catchable
When a Thread object's stack memory is not provided, its `start()`
member function dynamically allocates its stack from the heap. If
allocation fails, there is no way to catch it because
* `std::nothrow` is missing after the `new` keyword. As Mbed OS
is built with `-fno-exceptions` (C++ exceptions disabled), failed
allocation results in an unrecoverable fault.
* The attempted `nullptr` check, which doesn't work anyway due to
the first point, is an assertion instead of error returning.
Assertions should be used as a development tool to ensure code
behaves correctly. But out-of-memory is a completely valid runtime
situation.

This commit adds the missing `std::nothrow`, and makes `Thread::start()`
return `osErrorNoMemory` if allocation fails so the caller can handle
it.

Note: A case when a thread should never fail due to lack of memory
is the main thread. But the main thread's stack is a pre-allocated
array in the static memory, passed to the `Thread()` constructor
during thread creation, so it's not impacted by this change.
2021-09-08 14:17:58 +01:00
Martin Kojtal c14396a5b6
Merge pull request #15045 from LDong-Arm/malloc_newlib_nano
Workaround for a bug in malloc() from newlib-nano 4.1.0 (in GCC 10.3)
2021-09-03 15:03:31 +01:00
Rajkumar Kanagaraj 9a144308ec Incorporate the review comments 2021-09-02 12:49:33 +01:00
Lingkai Dong 8e412987b1 Revert "TESTS: Reduce allocate memory size"
This reverts commit 6649e95106.

In the malloc test, `ALLOC_ARRAY_SIZE` defines the *capacity* of array
that stores pointers to `malloc`'d buffers. It is *not* the number
of allocations.

In an ideal scenario, the test makes as many allocations as possible
until the heap runs out and malloc() returns NULL. So revert the
capacity of the array of pointers from 50 back to 100 so this array
is less likely to run out before the heap does.
2021-09-01 17:21:32 +01:00
Rajkumar Kanagaraj b9439920c0 Update rtos CMake to include greentea test dir 2021-08-23 21:44:36 +01:00
Rajkumar Kanagaraj 5d31b71f81 CMake: greentea: Add skip reason to rtos test 2021-08-23 21:44:16 +01:00
Rajkumar Kanagaraj 174e01667f CMake: Refactor rtos greentea test CMake
Initially, every library greentea test has its project() creation in
their CMake. As running greentea using CTest move all greentea test
suite under one global project mbed-os and MBED_CONFIG_PATH set at
the root mbed os CMake under the condition BUILD_GREENTEA_TESTS
check so refactored rtos greentea CMake accordingly.
2021-08-23 21:43:39 +01:00
Qinghao Shi 6649e95106 TESTS: Reduce allocate memory size 2021-08-17 09:59:00 +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 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
Lingkai Dong 5fe0f8916b Unit tests: Fix style in rtos Thread.h stubs 2021-08-02 17:42:42 +01:00
Lingkai Dong 1f99729474 Unit tests: Move rtos target_h stubs 2021-08-02 17:42:42 +01:00
Martin Kojtal 5e29db6e30 rtos: fix delay with 0
Fixes error osErrorParameter that triggers our assert.
RTX delay ignored 0 previously, it now returns osErrorParameter instead.
2021-07-29 14:31:39 +01:00
Rajkumar Kanagaraj bb3cd37a5e CMake: Remove mbed-stubs-rtos-headers library
- Previous changes moved all rtos stubs headers into mbed-stubs-rtos-headers
lib, but the decision to keep all stubs headers under the respective
component stubs library so moved all stubs rtos headers under
mbed-stubs-rtos and updated it depend component CMake
- Remove unnecessary add_definition call for UNITTEST as any of the stubs library
added from UNITTEST/CMakeLists.txt is not required this macro
2021-07-08 07:14:56 -07:00
Lingkai Dong 3a24305916 rtos: Remove UNITTEST macro from rtos
Production code should not contain any test-specific checks. Rather
than checking `UNITTEST`, unit tests can directly set
`MBED_CONF_RTOS_PRESENT=1` to make RTOS available for testing.

Note: The cellular ATHandler test also has `MBED_CONF_RTOS_PRESENT=1`
added because `ATHandler.cpp` contains a check of this variable.
2021-07-06 16:50:49 +01:00
Jaeden Amero b5c2f7079e
Merge pull request #14718 from Meano/develop
Feature: Make changes for Cortex-A5 support
2021-07-01 10:23:41 +01:00
Martin Kojtal 8902a0c866
Merge pull request #14819 from ARMmbed/move_rtos_stubs
Move rtos stubs to the rtos directory
2021-06-30 11:49:41 +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
Rajkumar Kanagaraj 4412e76531 CMake: unit-tests: Move mbed-headers-rtos to the rtos directory
Move the header-only mbed-headers-rtos library the unit test stubs
depend on into the rtos component directory. This makes the rtos
stubs more self-contained and improves the composition of the library.
2021-06-28 06:31:37 -07:00
Rajkumar Kanagaraj 062638e835 CMake: Move rtos stub headers to the rtos/tests/UNITTESTS/double directory
Move rtos stubs headers to the mbed-os/rtos/tests/UNITTESTS/double
directory and update CMake to create a mbed-stubs-rtos-headers
library for rtos stub headers
2021-06-28 06:31:37 -07:00
Rajkumar Kanagaraj 6a5f3ae661 CMake: Move rtos stubs sources to the mbed-os/rtos directory
Move the rtos stub library into the rtos component directory.
so we can avoid duplicating the mbed-os source tree in a central
UNITTESTS folder.
2021-06-28 06:31:37 -07:00
Meano ff2188150a Make changes for Cortex-A5 support 2021-06-23 13:36:55 +08:00
Kevin Bracey 537bee9f4c Better document MemoryPool behaviour
Make explicit that `MemoryPool` is a raw allocator, and users need to
take care of object construction and destruction.
2021-04-13 14:37:47 +03:00
Rajkumar Kanagaraj 6824b14e48 CMake: rename greentea test macro 2021-02-02 07:43:40 -08:00
Rajkumar Kanagaraj 2d53e005e8 CMake: Add CMake support for rtos greentea test 2021-01-05 09:11:41 -08:00
Evelyne Donnaes 786c64af06 Fix ThisThread warnings 2020-11-27 11:57:09 +00:00
Martin Kojtal 57bbb4739b
Merge pull request #13085 from pea-pod/remove-deprecated-mbed-assert
Change MBED_STATIC_ASSERTs version for built-in
2020-11-24 13:38:07 +00:00
Hugues Kamba 794e32df74 CMake: Use relative paths to list source files and directories
The absolute path is still required for listing linker
files as they are referenced from a function in the top
level CMake input source file.
2020-11-09 12:32:30 +00:00
Martin Kojtal f8a02ce5de Update rtos/CMakeLists.txt
Co-authored-by: Hugues Kamba <41612201+hugueskamba@users.noreply.github.com>
2020-11-06 17:25:22 +00:00
Rajkumar Kanagaraj e7c0d93ad4 CMake: add mbed-os and mbed-baremetal targets
mbed-os consists of mbed-core and mbed-rtos
mbed-baremetal consists of mbed-core

The main change is for mbed-core. Changing from object library to be interface. This way it allows us to do the above to have 2 main targets for users to use.

This should be backward compatible change as mbed-os target we used contains the same files/options as previously set.
2020-11-06 17:25:22 +00:00
Rajkumar Kanagaraj d2be577b01 CMake: split rtos from core target
Add or remove and directories containing source files, header files, and macro definitions that implement RTOS support.
This includes:
- cmsis/CMSIS_5/CMSIS/RTOS2/
- cmsis/device/rtos/
- rtos/source/ConditionVariable.cpp
- rtos/source/Thread.cpp
2020-11-06 17:25:22 +00:00
Hugues Kamba bf84a5b329 CMake: Rename CMake targets
* mbed-os renamed mbed-core
* mbed-os-<COMPONENT> renamed mbed-<COMPONENT>
2020-11-06 17:25:22 +00:00
Hugues Kamba c82e8c2337 CMake: Restore rtos api and netsocket presence macro names
The old tools rely on the old names to build
2020-11-06 17:25:22 +00:00
Martin Kojtal 8529e88e61 cmake: fix present inclusion
We use only _PRESENT macros for components if they are enabled. Use the same in
the mbed.h file or anywhere else.
2020-11-06 17:25:21 +00:00
Hugues Kamba fa98689639 CMake: Componentize Mbed OS into multiple CMake targets (#13732)
Aside from the core mbed-os CMake target, a number of targets have been created so they can optionally be included by application executables that require them using `target_link_libraries()`.

Co-authored-by: Martin Kojtal <martin.kojtal@arm.com>
Co-authored-by: Rajkumar Kanagaraj <rajkumar.kanagaraj@arm.com>
2020-11-06 17:25:21 +00:00
Hugues Kamba a0fbe2947a CMake: Fix build failure due to CMSIS restructure 2020-11-06 17:25:20 +00:00
Hugues Kamba 42cd929418 CMake: Fix detection of RTX assembly file
Access MBED_TARGET_LABELS as a global variable instead of a property.
At this point the evaluation of the property MBED_TARGET_LABELS
created in the top level CMakeLists.txt results in an empty string.
2020-11-06 17:25:18 +00:00
Hugues Kamba 06f4e1bc8b CMake: Break down RTX CMake source file into 2 source files 2020-11-06 17:25:18 +00:00
Hugues Kamba b78ef7ac08 CMake: Fix CI error due to dir restruct of rtos and storage dirs 2020-11-06 17:25:16 +00:00
Hugues Kamba 554a5d3597 CMake: Fix failure due to restructure of rtos and ppp directories 2020-11-06 17:25:16 +00:00
Hugues Kamba 5c453e5d46 CMake: Add support for rtos dir 2020-11-06 17:25:15 +00:00
pea-pod 507181d262 Change MBED_STATIC_ASSERTs version for built-in 2020-10-27 08:30:40 -05:00
Rajkumar Kanagaraj fcf36bb9e2 Move rtos greentea test closure to library 2020-09-16 13:06:05 +01:00
Hugues Kamba 834e530abd CMSIS: Restructure ported CMSIS_5
See docs/adr/0001_cmsis_component_source_structure_recommendations.md
For details information.
2020-09-01 15:55:13 +01:00
Anna Bridge b3c19227a4
Merge pull request #13459 from 0xc0170/fix_platform_component
platform: fix internal platform headers
2020-08-25 15:53:12 +01:00
Martin Kojtal a6ce2c53a0 platform: move internal headers to internal/
They belong to internal folder to follow our guideline, not in source as they were.
2020-08-20 08:58:00 +01:00
Lingkai Dong 017b043473 TARGET_PSOC6: set CY_RTOS_AWARE based on RTOS availability 2020-08-13 12:12:46 +01:00
Martin Kojtal e127bb245e
Merge pull request #13374 from caoyuan96421/bugfix2
Fixed ThisThread flag_wait_any functions (fix #13360)
2020-08-10 11:45:37 +01:00
George Beckstein e77cdffbaa Include mbed_assert.h in Queue 2020-07-30 11:23:24 -04:00
Yuan Cao 8a2428b4dc Fixed ThisThread flag_wait_any functions 2020-07-29 20:47:05 -04:00