diff --git a/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c b/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c index 9d8ba7bd924..60a00b9addb 100644 --- a/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c +++ b/tests/net/lib/lwm2m/lwm2m_rd_client/src/main.c @@ -21,7 +21,7 @@ DEFINE_FFF_GLOBALS; /* Maximum number of iterations within the state machine of RD Client * service that is waited for until a possible event occurs */ -static const uint8_t RD_CLIENT_MAX_LOOKUP_ITERATIONS = 10; +static const uint8_t RD_CLIENT_MAX_LOOKUP_ITERATIONS = 100; FAKE_VOID_FUNC(show_lwm2m_event, enum lwm2m_rd_client_event); FAKE_VOID_FUNC(show_lwm2m_observe, enum lwm2m_observe_event); @@ -143,7 +143,10 @@ static void my_suite_before(void *data) RESET_FAKE(show_lwm2m_event); RESET_FAKE(show_lwm2m_observe); +} +static void my_suite_after(void *data) +{ test_lwm2m_engine_stop_service(); } @@ -165,7 +168,7 @@ void message_reply_timeout_cb_default(struct lwm2m_message *msg) msg->message_timeout_cb(msg); } -ZTEST_SUITE(lwm2m_rd_client, NULL, NULL, my_suite_before, NULL, NULL); +ZTEST_SUITE(lwm2m_rd_client, NULL, NULL, my_suite_before, my_suite_after, NULL); ZTEST(lwm2m_rd_client, test_start_registration_ok) { diff --git a/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c b/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c index 72c59de8c6f..877dfdc40d3 100644 --- a/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c +++ b/tests/net/lib/lwm2m/lwm2m_rd_client/src/stubs.c @@ -94,10 +94,11 @@ int lwm2m_engine_call_at(k_work_handler_t work, int64_t timestamp) uint16_t counter = RD_CLIENT_MAX_SERVICE_ITERATIONS; struct lwm2m_message *pending_message; void *(*pending_message_cb)(); +static bool running; static void service_work_fn(struct k_work *work) { - while (true) { + while (running) { if (pending_message != NULL && pending_message_cb != NULL) { pending_message_cb(pending_message); pending_message = NULL; @@ -132,6 +133,7 @@ K_WORK_DEFINE(service_work, service_work_fn); void test_lwm2m_engine_start_service(void) { + running = true; counter = RD_CLIENT_MAX_SERVICE_ITERATIONS; k_work_submit(&service_work); } @@ -139,6 +141,7 @@ void test_lwm2m_engine_start_service(void) void test_lwm2m_engine_stop_service(void) { pending_message_cb = NULL; + running = false; k_work_cancel(&service_work); }