Commit Graph

184 Commits (master)

Author SHA1 Message Date
Vincent Coubard db4b02c5b1 Fix replacement of event queue background.
This was discovered when EventQueue::background was called with a nullptr.
It crashes the software as it tries to call into a nullptr.
2021-09-10 12:13:09 +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 71962481a4 Unit tests: Remove mbed.h stub from target_h
The header `mbed.h` is a convenient wrapper that pre-includes some
platform headers, for use by user applications. Libraries and tests
internal to Mbed OS should not use it, and they should explicitly
include headers they need. So a stub is not needed.
2021-08-02 17:42:42 +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 162ae220b1 equeue: Enable use of stub from C++
Add extern "C" to the equeue_stub declaration to avoid an error when a C
file implements the equeue_stub symbol (as we do in equeue_stub.c).

    Undefined symbols for architecture x86_64:
      "_equeue_stub", referenced from:
          Test_LoRaWANTimer_start_Test::TestBody() in Test_LoRaWANTimer.cpp.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
2021-07-22 18:03:47 +01:00
Jaeden Amero 4480abeaf9 cmake: Avoid linking to gcov
Use the `--coverage` option instead of manually linking to gcov, as some
host platforms (like macOS, FreeBSD) don't have gcov by default and use
an llvm equivalent instead.
2021-07-22 15:41:49 +01:00
Jaeden Amero a1e61b61c2 equeue: Add missing header guards
The header equeue_stub.h was missing header guards to enforce single
inclusion. Add some header guards.
2021-07-22 15:41:06 +01:00
Rajkumar Kanagaraj 863ef79ed4 CMake: Move events fakes into events double dir
Previously events fakes as part of UNITTESTS/fakes, this PR moves
events fakes to events double directory to make events stubs
to be self-contained.
2021-07-09 02:56:26 -07:00
Rajkumar Kanagaraj 652b421388 CMake: unit-tests: Make events stub only depend on headers it uses
Previously the events stub library depended on `mbed-headers`, which
is a collection of all available headers in mbed-os. To make it easier
to separate the library, only depend on the headers we're using.
2021-07-09 02:56:26 -07:00
Rajkumar Kanagaraj 447754f6cf CMake: Move events stub headers to the events/tests/UNITTESTS/double dir
Move events stubs headers to the mbed-os/events/tests/UNITTESTS/double
directory and update double CMake to include stub headers
2021-07-09 02:56:26 -07:00
Rajkumar Kanagaraj 65d202b93b CMake: unit-tests: Move mbed-headers-events to the events directory
Move the header-only mbed-headers-events library the unit test stubs
depend on into the events component directory. This makes the events
stubs more self-contained and improves the composition of the library.
2021-07-09 02:56:26 -07:00
Rajkumar Kanagaraj 88410a5f85 CMake: Move events stubs sources to the mbed-os/events directory
Move the events stub into the events component directory.
so we can avoid duplicating the mbed-os source tree in a central
UNITTESTS folder.
2021-07-09 02:56:26 -07:00
jeromecoutant 64027e4a03 events-timing test should not need any LED1 2021-07-06 17:13:45 +02:00
Jaeden Amero 472c688a83
Merge pull request #14828 from hazzlim/add-cmake-supports-psa-tests
CMake: Add CMake to mbed-psa greentea tests
2021-06-29 15:17:01 +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
Rajkumar Kanagaraj ef5c86f1dd CMake: unit-tests: Make events UNITTESTS only depend on headers it uses
Previously the events unit tests depended on `mbed-headers`, which
is a collection of all available headers in mbed-os. To make it easier
to separate the library, only depend on the headers we're using.
2021-06-24 03:03:40 -07: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
Rajkumar Kanagaraj 6d4caad83d CMake: Move CMAKE_CROSSCOMPILING check inside library CMake 2021-05-20 06:26:10 -07:00
Rajkumar Kanagaraj b6647355bf CMake: Refactor event unittest cmake
- Added CMake configuration file into events 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
Eric Marks 4ba07d9413
Update UserAllocatedEvent.h 2021-03-17 09:55:13 -05:00
Eric Marks 956e5ce163
Update Event.h 2021-03-17 09:54:06 -05:00
Eric Marks a07c00e6c3
Update equeue.h 2021-03-17 09:52:20 -05:00
Eric Marks e8332aa7e9
Update EventQueue.h 2021-03-17 09:51:34 -05:00
Eric Marks 13351c9253
Update equeue.h 2021-03-17 09:50:44 -05:00
Eric Marks ecbef81572
Update README.md 2021-03-17 09:19:22 -05:00
Eric Marks 4638ce9bc3
Update README.md 2021-03-17 09:18:42 -05:00
Eric Marks 06b7ba0a55
Update README.md 2021-03-17 09:17:33 -05:00
Paul Szczepanek 86f8b0b818 extend the event generation int 2021-03-10 18:21:07 +00:00
Paul Szczepanek 3f9c734e1a bigger equeue generation size and only increment when needed
to mitigate against generation clash
2021-03-09 22:08:43 +00:00
Martin Kojtal 9607ceaebf
Merge pull request #13975 from adbridge/eventq
Update EventQueue API to use chrono times
2021-02-08 12:44:39 +00:00
adbridge c7c30fe9f7 Remove trailing space 2021-02-04 14:25:29 +00:00
adbridge d1b768ad9a Tweak events API update and update Greentea tests accordingly 2021-02-04 12:48:41 +00:00
Rajkumar Kanagaraj 6824b14e48 CMake: rename greentea test macro 2021-02-02 07:43:40 -08:00
Martin Kojtal 97c7c91655
Merge pull request #14087 from adbridge/events
Update events period method to check for invalid values
2021-01-18 16:29:30 +00:00
adbridge 81d7ac683b Minor formatting tweak to fix file permissions 2021-01-18 14:59:30 +00:00
adbridge 4f558743e1 Revert "one final whitespace change!"
This reverts commit c9a3375042.
2021-01-18 14:42:02 +00:00
adbridge c9a3375042 one final whitespace change! 2021-01-12 14:38:37 +00:00
adbridge 27689ef2b3 Further whitespace fixes 2021-01-12 13:29:26 +00:00
adbridge 1746ed0bc0 Fix whitespace to stop astyle complaining 2021-01-12 12:54:56 +00:00
adbridge 9e7c82ceed Fix astyle issues 2021-01-08 17:33:51 +00:00
adbridge 37f13bdeb2 Remove unecessary namespace qualified
(Also minor whitespace correction)
2021-01-08 17:15:13 +00:00
Rajkumar Kanagaraj bc4b3f5846
Apply suggestions from code review
Co-authored-by: Hugues Kamba <41612201+hugueskamba@users.noreply.github.com>
2021-01-08 03:20:15 -08:00
adbridge f2b86864d5 Fix some whitespace issues 2021-01-06 16:07:04 +00:00
adbridge c0a57ba3b9 Updated event period handling and greentea test
non_periodic constant has been moved out of the Event class and
made static within the events namespace so that it is available
both internally within the class and externally.

The MBED_ASSERT has been changed to MBED_WARNING.

The greentea test has been updated:
1) timings reduced to make the test cases run faster
2) The call handler simplified
2021-01-06 16:07:04 +00:00
adbridge 6b2a0fe1d4 Update events period method to check for invalid values
The period method currently allows any ms value positive, negative
and zero. A negative value means dispatch a non periodic event
ie just once. 0 is unspecified behaviour. This commit forces the
user to use either positive periods or a new constant non_periodic
and should any other value be provided will default to
non_periodic.

A Greentea test case is also provided to check this works as
expected.
2021-01-06 16:07:04 +00:00
Rajkumar Kanagaraj accf24aeaf CMake: Add CMake support for events greentea test 2021-01-05 09:11:06 -08:00