Skip to content

Commit 862a942

Browse files
authored
Merge pull request ARMmbed#14948 from Patater/lorawan-timer-unittest-fake-fix
Fix lorawantimer unit test
2 parents 6827b42 + 51b81e0 commit 862a942

File tree

9 files changed

+38
-6
lines changed

9 files changed

+38
-6
lines changed

connectivity/FEATURE_BLE/tests/UNITTESTS/doubles/fakes/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ target_sources(mbed-fakes-ble
3333
${mbed-os_SOURCE_DIR}/connectivity/FEATURE_BLE/tests/UNITTESTS/doubles/fakes/SecurityManagerImpl_mock.h
3434
)
3535

36+
target_link_options(mbed-fakes-ble
37+
PRIVATE
38+
--coverage
39+
)
40+
3641
target_link_libraries(mbed-fakes-ble
3742
PRIVATE
3843
mbed-headers-base
3944
mbed-headers-platform
4045
mbed-headers-events
41-
gcov
4246
)

connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawanstack/Test_LoRaWANStack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ TEST_F(Test_LoRaWANStack, handle_rx)
554554
}
555555
ind.buffer = ind_buf;
556556
ind.buffer_size = 50;
557-
ind.type = mcps_type_t(66);
557+
ind.type = MCPS_MULTICAST;
558558
radio._ev->rx_done(NULL, 0, 0, 0);
559559
EXPECT_TRUE(50 == object->handle_rx(data, 50, port, flags, false));
560560
EXPECT_EQ(10, data[10]);

connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawantimer/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_executable(${TEST_NAME})
77

88
target_compile_definitions(${TEST_NAME}
99
PRIVATE
10-
NDEBUG=1
10+
NDEBUG=1
1111
MBED_CONF_LORA_TX_MAX_SIZE=255
1212
)
1313

connectivity/lorawan/tests/UNITTESTS/features/lorawan/lorawantimer/Test_LoRaWANTimer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,12 @@ TEST_F(Test_LoRaWANTimer, init)
7171

7272
TEST_F(Test_LoRaWANTimer, start)
7373
{
74-
equeue_stub.void_ptr = NULL;
74+
struct equeue_event ptr;
75+
equeue_stub.void_ptr = &ptr;
7576
timer_event_t ev;
7677
memset(&ev, 0, sizeof(ev));
78+
object->init(ev, my_callback);
79+
equeue_stub.call_cb_immediately = true;
7780
object->start(ev, 10);
7881
}
7982

events/tests/UNITTESTS/doubles/equeue_stub.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,25 @@
1515
* limitations under the License.
1616
*/
1717

18+
#ifndef __EQUEUE_STUB_H__
19+
#define __EQUEUE_STUB_H__
20+
1821
#include "stdint.h"
1922
#include "stdbool.h"
2023

24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
2128
typedef struct {
2229
void *void_ptr;
2330
bool call_cb_immediately;
2431
} equeue_stub_def;
2532

2633
extern equeue_stub_def equeue_stub;
34+
35+
#ifdef __cplusplus
36+
}
37+
#endif
38+
39+
#endif

events/tests/UNITTESTS/doubles/fakes/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ target_include_directories(mbed-fakes-event-queue
1313
.
1414
)
1515

16+
target_link_options(mbed-fakes-event-queue
17+
PRIVATE
18+
--coverage
19+
)
20+
1621
target_link_libraries(mbed-fakes-event-queue
1722
PRIVATE
1823
mbed-headers
19-
gcov
2024
)

platform/tests/UNITTESTS/CircularBuffer/test_CircularBuffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ TEST_F(TestCircularBuffer, push_pop_multiple)
6969
const int test_numbers[TEST_BUFFER_SIZE] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
7070

7171
/* this will check pushing across the buffer end */
72-
for (int i = 0; i < TEST_BUFFER_SIZE; i++) {
72+
for (int i = 1; i < TEST_BUFFER_SIZE; i++) {
7373
int test_numbers_popped[TEST_BUFFER_SIZE] = { 0 };
7474
buf->push(test_numbers, i);
7575
EXPECT_EQ(buf->size(), i);

platform/tests/UNITTESTS/doubles/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ target_link_libraries(mbed-stubs-platform
3535
mbed-headers-base
3636
mbed-headers-hal
3737
mbed-headers-platform
38+
gmock_main
3839
)

platform/tests/UNITTESTS/doubles/mbed_assert_stub.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
#include "platform/mbed_assert.h"
19+
#include "gtest/gtest.h"
1920
#include <stdio.h>
2021
#include <stdbool.h>
2122

@@ -27,4 +28,10 @@ extern "C" void mbed_assert_internal(const char *expr, const char *file, int lin
2728
if (mbed_assert_throw_errors) {
2829
throw 1;
2930
}
31+
32+
/* Ensure we fail the unit test if the Mbed assertion fails. Without this,
33+
* we might not notice the assertion failure as it wouldn't be bubbled up
34+
* to googletest. Note that this is after the above throw, as some tests
35+
* check that an exception is thrown (i.e. negative tests). */
36+
FAIL();
3037
}

0 commit comments

Comments
 (0)