test: lwm2m: Fix minor timing issue
RD client tests work well on emulated (fast) environments but tend to fail on real HW with real time sleeps. This change refactors wait_for_service() to be a bit more syncronous on background service, instead of relying hardcoded sleeps. Fixes #61824 Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
This commit is contained in:
parent
008a82e3ba
commit
4798187801
2 changed files with 8 additions and 6 deletions
|
@ -23,7 +23,7 @@ add_compile_definitions(CONFIG_LWM2M_RD_CLIENT_ENDPOINT_NAME_MAX_LENGTH=32)
|
|||
add_compile_definitions(CONFIG_LWM2M_RD_CLIENT_MAX_RETRIES=2)
|
||||
add_compile_definitions(CONFIG_LWM2M_COAP_BLOCK_SIZE=256)
|
||||
add_compile_definitions(CONFIG_LWM2M_COAP_MAX_MSG_SIZE=512)
|
||||
add_compile_definitions(CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=60)
|
||||
add_compile_definitions(CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=20)
|
||||
add_compile_definitions(CONFIG_LWM2M_SECURITY_INSTANCE_COUNT=1)
|
||||
add_compile_definitions(CONFIG_LWM2M_SECONDS_TO_UPDATE_EARLY=10)
|
||||
add_compile_definitions(CONFIG_LWM2M_QUEUE_MODE_UPTIME=10)
|
||||
|
|
|
@ -117,10 +117,12 @@ uint16_t counter = RD_CLIENT_MAX_SERVICE_ITERATIONS;
|
|||
struct lwm2m_message *pending_message;
|
||||
void *(*pending_message_cb)();
|
||||
static bool running;
|
||||
K_SEM_DEFINE(srv_sem, 0, 1);
|
||||
|
||||
static void service_work_fn(struct k_work *work)
|
||||
{
|
||||
while (running) {
|
||||
k_sleep(K_MSEC(10));
|
||||
if (pending_message != NULL && pending_message_cb != NULL) {
|
||||
pending_message_cb(pending_message);
|
||||
pending_message = NULL;
|
||||
|
@ -129,8 +131,9 @@ static void service_work_fn(struct k_work *work)
|
|||
if (next && next < k_uptime_get()) {
|
||||
next = 0;
|
||||
service(NULL);
|
||||
k_sem_give(&srv_sem);
|
||||
}
|
||||
k_sleep(K_MSEC(10));
|
||||
|
||||
counter--;
|
||||
|
||||
/* avoid endless loop if rd client is stuck somewhere */
|
||||
|
@ -143,10 +146,8 @@ static void service_work_fn(struct k_work *work)
|
|||
|
||||
void wait_for_service(uint16_t cycles)
|
||||
{
|
||||
uint16_t end = counter - cycles;
|
||||
|
||||
while (counter > end) {
|
||||
k_sleep(K_MSEC(10));
|
||||
while (cycles--) {
|
||||
k_sem_take(&srv_sem, K_MSEC(100));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,6 +158,7 @@ void test_lwm2m_engine_start_service(void)
|
|||
running = true;
|
||||
counter = RD_CLIENT_MAX_SERVICE_ITERATIONS;
|
||||
k_work_submit(&service_work);
|
||||
k_sem_reset(&srv_sem);
|
||||
}
|
||||
|
||||
void test_lwm2m_engine_stop_service(void)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue