diff --git a/tests/net/lib/coap_client/CMakeLists.txt b/tests/net/lib/coap_client/CMakeLists.txt index 6e3b6353e08..9ed7926a204 100644 --- a/tests/net/lib/coap_client/CMakeLists.txt +++ b/tests/net/lib/coap_client/CMakeLists.txt @@ -26,7 +26,7 @@ add_compile_definitions(CONFIG_COAP_CLIENT_MESSAGE_HEADER_SIZE=48) add_compile_definitions(CONFIG_COAP_CLIENT_STACK_SIZE=1024) add_compile_definitions(CONFIG_COAP_CLIENT_THREAD_PRIORITY=10) add_compile_definitions(CONFIG_COAP_LOG_LEVEL=4) -add_compile_definitions(CONFIG_COAP_INIT_ACK_TIMEOUT_MS=100) +add_compile_definitions(CONFIG_COAP_INIT_ACK_TIMEOUT_MS=1000) add_compile_definitions(CONFIG_COAP_CLIENT_MAX_REQUESTS=2) add_compile_definitions(CONFIG_COAP_CLIENT_MAX_INSTANCES=2) add_compile_definitions(CONFIG_COAP_MAX_RETRANSMIT=4) diff --git a/tests/net/lib/coap_client/boards/native_sim.conf b/tests/net/lib/coap_client/boards/native_sim.conf new file mode 100644 index 00000000000..0843e94acbd --- /dev/null +++ b/tests/net/lib/coap_client/boards/native_sim.conf @@ -0,0 +1 @@ +CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME=y diff --git a/tests/net/lib/coap_client/src/main.c b/tests/net/lib/coap_client/src/main.c index 2f3fa28ebff..72b84a60f5e 100644 --- a/tests/net/lib/coap_client/src/main.c +++ b/tests/net/lib/coap_client/src/main.c @@ -8,7 +8,9 @@ #include #include #include - +#if defined(CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME) +#include "timer_model.h" +#endif #include "stubs.h" LOG_MODULE_REGISTER(coap_client_test, LOG_LEVEL_DBG); @@ -16,12 +18,12 @@ LOG_MODULE_REGISTER(coap_client_test, LOG_LEVEL_DBG); DEFINE_FFF_GLOBALS; #define FFF_FAKES_LIST(FAKE) -#define LONG_ACK_TIMEOUT_MS 200 +#define LONG_ACK_TIMEOUT_MS (2 * CONFIG_COAP_INIT_ACK_TIMEOUT_MS) #define MORE_THAN_EXCHANGE_LIFETIME_MS 4 * CONFIG_COAP_INIT_ACK_TIMEOUT_MS #define MORE_THAN_LONG_EXCHANGE_LIFETIME_MS 4 * LONG_ACK_TIMEOUT_MS #define MORE_THAN_ACK_TIMEOUT_MS \ (CONFIG_COAP_INIT_ACK_TIMEOUT_MS + CONFIG_COAP_INIT_ACK_TIMEOUT_MS / 2) -#define COAP_SEPARATE_TIMEOUT (6000 * 3) /* Needs a safety marging, tests run faster than -rt */ +#define COAP_SEPARATE_TIMEOUT (6000 * 2) /* Needs a safety marging, tests run faster than -rt */ #define VALID_MESSAGE_ID BIT(31) #define TOKEN_OFFSET 4 @@ -425,6 +427,13 @@ extern void net_coap_init(void); static void *suite_setup(void) { +#if defined(CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME) + /* It is enough that some slow-down is happening on sleeps, it does not have to be + * real time + */ + hwtimer_set_rt_ratio(100.0); + k_sleep(K_MSEC(1)); +#endif net_coap_init(); zassert_ok(coap_client_init(&client, NULL)); zassert_ok(coap_client_init(&client2, NULL)); diff --git a/tests/net/lib/coap_client/src/stubs.c b/tests/net/lib/coap_client/src/stubs.c index 8d251157ac1..76289991155 100644 --- a/tests/net/lib/coap_client/src/stubs.c +++ b/tests/net/lib/coap_client/src/stubs.c @@ -7,7 +7,7 @@ #include #include -LOG_MODULE_DECLARE(coap_client_test); +LOG_MODULE_DECLARE(coap_client_test, LOG_LEVEL_DBG); DEFINE_FAKE_VALUE_FUNC(uint32_t, z_impl_sys_rand32_get); DEFINE_FAKE_VALUE_FUNC(ssize_t, z_impl_zsock_recvfrom, int, void *, size_t, int, struct sockaddr *, @@ -45,6 +45,9 @@ int z_impl_zvfs_poll(struct zvfs_pollfd *fds, int nfds, int poll_timeout) events++; } } + if (events == 0) { + k_sleep(K_MSEC(poll_timeout)); + } return events; }