tests: coap_client: Proper slow-down

Use real-time scheduler with 100x speedup, so timeouts are
accurate enough, but still fast for tests to run.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
This commit is contained in:
Seppo Takalo 2024-11-18 15:28:38 +02:00 committed by Henrik Brix Andersen
commit 34a6d5a5dc
4 changed files with 18 additions and 5 deletions

View file

@ -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)

View file

@ -0,0 +1 @@
CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME=y

View file

@ -8,7 +8,9 @@
#include <zephyr/logging/log.h>
#include <zephyr/misc/lorem_ipsum.h>
#include <zephyr/ztest.h>
#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));

View file

@ -7,7 +7,7 @@
#include <zephyr/logging/log.h>
#include <stubs.h>
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;
}