mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-04 13:14:32 +02:00
Add testcase for eloop execution
This commit is contained in:
@@ -29,6 +29,7 @@ struct eloop_timeout {
|
||||
struct eloop_data {
|
||||
struct dl_list timeout;
|
||||
ETSTimer eloop_timer;
|
||||
bool eloop_started;
|
||||
};
|
||||
|
||||
#define ELOOP_LOCK() xSemaphoreTakeRecursive(eloop_data_lock, portMAX_DELAY)
|
||||
@@ -51,6 +52,7 @@ int eloop_init(void)
|
||||
wpa_printf(MSG_ERROR, "failed to create eloop data loop");
|
||||
return -1;
|
||||
}
|
||||
eloop.eloop_started = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -299,6 +301,9 @@ void eloop_destroy(void)
|
||||
struct eloop_timeout *timeout, *prev;
|
||||
struct os_reltime now;
|
||||
|
||||
if (!eloop.eloop_started) {
|
||||
return;
|
||||
}
|
||||
os_get_reltime(&now);
|
||||
dl_list_for_each_safe(timeout, prev, &eloop.timeout,
|
||||
struct eloop_timeout, list) {
|
||||
|
66
components/wpa_supplicant/test/test_eloop.c
Normal file
66
components/wpa_supplicant/test/test_eloop.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include "string.h"
|
||||
#include "esp_system.h"
|
||||
#include "unity.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_wifi_types.h"
|
||||
#include "utils/common.h"
|
||||
#include "utils/eloop.h"
|
||||
#include "common/ieee802_11_defs.h"
|
||||
#include "../esp_supplicant/src/esp_wifi_driver.h"
|
||||
#include "esp_log.h"
|
||||
#include "test_utils.h"
|
||||
#include "memory_checks.h"
|
||||
|
||||
uint32_t timeouts_usec[6] = { 10000, 1000, 10000, 5000, 15000, 1000 };
|
||||
uint32_t timeouts_sec[6] = { 10, 1, 10, 5, 15, 1 };
|
||||
int executed_order[6];
|
||||
int t;
|
||||
struct os_reltime ts;
|
||||
|
||||
/* there is only single instance of esp_timer so no need of protection */
|
||||
void callback(void *a, void *b)
|
||||
{
|
||||
int *i = a;
|
||||
struct os_time age, now;
|
||||
|
||||
os_get_reltime(&now);
|
||||
os_time_sub(&now, &ts, &age);
|
||||
|
||||
/* let's give 5 ms offset for this small block */
|
||||
if ((age.sec - timeouts_sec[*i]) || age.usec - timeouts_usec[*i] > 5000) {
|
||||
executed_order[t] = -1;
|
||||
} else {
|
||||
executed_order[t] = *i;
|
||||
}
|
||||
t++;
|
||||
|
||||
ESP_LOGI("Eloop Test", "timer ran after %lu sec and %lu usec of scheduled time", age.sec - timeouts_sec[*i], age.usec - timeouts_usec[*i]);
|
||||
|
||||
}
|
||||
|
||||
/* Check if eloop runs its timers correctly & in correct order */
|
||||
TEST_CASE("Test eloop timers run", "[eloop]")
|
||||
{
|
||||
int execution_order[6] = {1, 5, 3, 0, 2, 4};
|
||||
int index[6] = {0,1,2,3,4,5};
|
||||
|
||||
eloop_init();
|
||||
os_get_reltime(&ts);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
eloop_register_timeout(timeouts_sec[i], timeouts_usec[i],
|
||||
callback, &index[i], NULL);
|
||||
}
|
||||
|
||||
/* wait for all timers to run */
|
||||
os_sleep(20, 0);
|
||||
|
||||
/* check the execution order, this will also check whether they were fired at correct time */
|
||||
TEST_ASSERT(memcmp(execution_order, executed_order, 6*sizeof(int)) == 0);
|
||||
eloop_destroy();
|
||||
}
|
Reference in New Issue
Block a user