Skip to content

Commit

Permalink
Merge pull request #14948 from Patater/lorawan-timer-unittest-fake-fix
Browse files Browse the repository at this point in the history
Fix lorawantimer unit test
  • Loading branch information
Patater authored Jul 27, 2021
2 parents 6827b42 + 51b81e0 commit 862a942
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ target_sources(mbed-fakes-ble
${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
)
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ TEST_F(Test_LoRaWANStack, handle_rx)
}
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]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_executable(${TEST_NAME})

target_compile_definitions(${TEST_NAME}
PRIVATE
NDEBUG=1
NDEBUG=1
MBED_CONF_LORA_TX_MAX_SIZE=255
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ TEST_F(Test_LoRaWANTimer, init)

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);
}

Expand Down
13 changes: 13 additions & 0 deletions events/tests/UNITTESTS/doubles/equeue_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion events/tests/UNITTESTS/doubles/fakes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ target_include_directories(mbed-fakes-event-queue
.
)

target_link_options(mbed-fakes-event-queue
PRIVATE
--coverage
)

target_link_libraries(mbed-fakes-event-queue
PRIVATE
mbed-headers
gcov
)
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ TEST_F(TestCircularBuffer, push_pop_multiple)
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);
Expand Down
1 change: 1 addition & 0 deletions platform/tests/UNITTESTS/doubles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ target_link_libraries(mbed-stubs-platform
mbed-headers-base
mbed-headers-hal
mbed-headers-platform
gmock_main
)
7 changes: 7 additions & 0 deletions platform/tests/UNITTESTS/doubles/mbed_assert_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "platform/mbed_assert.h"
#include "gtest/gtest.h"
#include <stdio.h>
#include <stdbool.h>

Expand All @@ -27,4 +28,10 @@ extern "C" void mbed_assert_internal(const char *expr, const char *file, int lin
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();
}

0 comments on commit 862a942

Please sign in to comment.