diff --git a/connectivity/FEATURE_BLE/tests/UNITTESTS/doubles/fakes/CMakeLists.txt b/connectivity/FEATURE_BLE/tests/UNITTESTS/doubles/fakes/CMakeLists.txt index 75ae98d..aabae2f 100644 --- a/connectivity/FEATURE_BLE/tests/UNITTESTS/doubles/fakes/CMakeLists.txt +++ b/connectivity/FEATURE_BLE/tests/UNITTESTS/doubles/fakes/CMakeLists.txt @@ -33,10 +33,14 @@ ${mbed-os_SOURCE_DIR}/connectivity/FEATURE_BLE/tests/UNITTESTS/doubles/fakes/SecurityManagerImpl_mock.h ) +target_link_options(mbed-fakes-ble + PRIVATE + --coverage +) + target_link_libraries(mbed-fakes-ble PRIVATE mbed-headers-base mbed-headers-platform mbed-headers-events - gcov ) diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawanstack/Test_LoRaWANStack.cpp b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawanstack/Test_LoRaWANStack.cpp index 13aca43..4903dd7 100644 --- a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawanstack/Test_LoRaWANStack.cpp +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawanstack/Test_LoRaWANStack.cpp @@ -554,7 +554,7 @@ } ind.buffer = ind_buf; ind.buffer_size = 50; - ind.type = mcps_type_t(66); + ind.type = MCPS_MULTICAST; radio._ev->rx_done(NULL, 0, 0, 0); EXPECT_TRUE(50 == object->handle_rx(data, 50, port, flags, false)); EXPECT_EQ(10, data[10]); diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawantimer/CMakeLists.txt b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawantimer/CMakeLists.txt index dea9f68..b0bd225 100644 --- a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawantimer/CMakeLists.txt +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawantimer/CMakeLists.txt @@ -7,7 +7,7 @@ target_compile_definitions(${TEST_NAME} PRIVATE - NDEBUG=1 + NDEBUG=1 MBED_CONF_LORA_TX_MAX_SIZE=255 ) diff --git a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawantimer/Test_LoRaWANTimer.cpp b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawantimer/Test_LoRaWANTimer.cpp index 9fb10a3..fd0ab98 100644 --- a/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawantimer/Test_LoRaWANTimer.cpp +++ b/connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawantimer/Test_LoRaWANTimer.cpp @@ -71,9 +71,12 @@ TEST_F(Test_LoRaWANTimer, start) { - equeue_stub.void_ptr = NULL; + struct equeue_event ptr; + equeue_stub.void_ptr = &ptr; timer_event_t ev; memset(&ev, 0, sizeof(ev)); + object->init(ev, my_callback); + equeue_stub.call_cb_immediately = true; object->start(ev, 10); } diff --git a/events/tests/UNITTESTS/doubles/equeue_stub.h b/events/tests/UNITTESTS/doubles/equeue_stub.h index 648d920..168b393 100644 --- a/events/tests/UNITTESTS/doubles/equeue_stub.h +++ b/events/tests/UNITTESTS/doubles/equeue_stub.h @@ -15,12 +15,25 @@ * limitations under the License. */ +#ifndef __EQUEUE_STUB_H__ +#define __EQUEUE_STUB_H__ + #include "stdint.h" #include "stdbool.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { void *void_ptr; bool call_cb_immediately; } equeue_stub_def; extern equeue_stub_def equeue_stub; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/events/tests/UNITTESTS/doubles/fakes/CMakeLists.txt b/events/tests/UNITTESTS/doubles/fakes/CMakeLists.txt index 1baacb1..65bf2ce 100644 --- a/events/tests/UNITTESTS/doubles/fakes/CMakeLists.txt +++ b/events/tests/UNITTESTS/doubles/fakes/CMakeLists.txt @@ -13,8 +13,12 @@ . ) +target_link_options(mbed-fakes-event-queue + PRIVATE + --coverage +) + target_link_libraries(mbed-fakes-event-queue PRIVATE mbed-headers - gcov ) diff --git a/platform/tests/UNITTESTS/CircularBuffer/test_CircularBuffer.cpp b/platform/tests/UNITTESTS/CircularBuffer/test_CircularBuffer.cpp index 9d45a54..26f0296 100644 --- a/platform/tests/UNITTESTS/CircularBuffer/test_CircularBuffer.cpp +++ b/platform/tests/UNITTESTS/CircularBuffer/test_CircularBuffer.cpp @@ -69,7 +69,7 @@ const int test_numbers[TEST_BUFFER_SIZE] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; /* this will check pushing across the buffer end */ - for (int i = 0; i < TEST_BUFFER_SIZE; i++) { + for (int i = 1; i < TEST_BUFFER_SIZE; i++) { int test_numbers_popped[TEST_BUFFER_SIZE] = { 0 }; buf->push(test_numbers, i); EXPECT_EQ(buf->size(), i); diff --git a/platform/tests/UNITTESTS/doubles/CMakeLists.txt b/platform/tests/UNITTESTS/doubles/CMakeLists.txt index ac94aab..3171096 100644 --- a/platform/tests/UNITTESTS/doubles/CMakeLists.txt +++ b/platform/tests/UNITTESTS/doubles/CMakeLists.txt @@ -35,4 +35,5 @@ mbed-headers-base mbed-headers-hal mbed-headers-platform + gmock_main ) diff --git a/platform/tests/UNITTESTS/doubles/mbed_assert_stub.cpp b/platform/tests/UNITTESTS/doubles/mbed_assert_stub.cpp index 875ef87..baea5f2 100644 --- a/platform/tests/UNITTESTS/doubles/mbed_assert_stub.cpp +++ b/platform/tests/UNITTESTS/doubles/mbed_assert_stub.cpp @@ -16,6 +16,7 @@ */ #include "platform/mbed_assert.h" +#include "gtest/gtest.h" #include #include @@ -27,4 +28,10 @@ if (mbed_assert_throw_errors) { throw 1; } + + /* Ensure we fail the unit test if the Mbed assertion fails. Without this, + * we might not notice the assertion failure as it wouldn't be bubbled up + * to googletest. Note that this is after the above throw, as some tests + * check that an exception is thrown (i.e. negative tests). */ + FAIL(); }