mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-05 13:44:32 +02:00
unit tests: more robust esp_timer test
This commit is contained in:
@@ -103,7 +103,7 @@ TEST_CASE("esp_timer produces correct delay", "[esp_timer]")
|
|||||||
esp_timer_delete(timer1);
|
esp_timer_delete(timer1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("periodic ets_timer produces correct delays", "[esp_timer]")
|
TEST_CASE("periodic esp_timer produces correct delays", "[esp_timer]")
|
||||||
{
|
{
|
||||||
// no, we can't make this a const size_t (§6.7.5.2)
|
// no, we can't make this a const size_t (§6.7.5.2)
|
||||||
#define NUM_INTERVALS 16
|
#define NUM_INTERVALS 16
|
||||||
@@ -113,6 +113,7 @@ TEST_CASE("periodic ets_timer produces correct delays", "[esp_timer]")
|
|||||||
size_t cur_interval;
|
size_t cur_interval;
|
||||||
int intervals[NUM_INTERVALS];
|
int intervals[NUM_INTERVALS];
|
||||||
int64_t t_start;
|
int64_t t_start;
|
||||||
|
SemaphoreHandle_t done;
|
||||||
} test_args_t;
|
} test_args_t;
|
||||||
|
|
||||||
void timer_func(void* arg)
|
void timer_func(void* arg)
|
||||||
@@ -128,6 +129,7 @@ TEST_CASE("periodic ets_timer produces correct delays", "[esp_timer]")
|
|||||||
if (p_args->cur_interval == NUM_INTERVALS) {
|
if (p_args->cur_interval == NUM_INTERVALS) {
|
||||||
printf("done\n");
|
printf("done\n");
|
||||||
TEST_ESP_OK(esp_timer_stop(p_args->timer));
|
TEST_ESP_OK(esp_timer_stop(p_args->timer));
|
||||||
|
xSemaphoreGive(p_args->done);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,15 +139,16 @@ TEST_CASE("periodic ets_timer produces correct delays", "[esp_timer]")
|
|||||||
esp_timer_create_args_t create_args = {
|
esp_timer_create_args_t create_args = {
|
||||||
.callback = &timer_func,
|
.callback = &timer_func,
|
||||||
.arg = &args,
|
.arg = &args,
|
||||||
.name = "timer1"
|
.name = "timer1",
|
||||||
};
|
};
|
||||||
TEST_ESP_OK(esp_timer_create(&create_args, &timer1));
|
TEST_ESP_OK(esp_timer_create(&create_args, &timer1));
|
||||||
ref_clock_init();
|
ref_clock_init();
|
||||||
args.timer = timer1;
|
args.timer = timer1;
|
||||||
args.t_start = ref_clock_get();
|
args.t_start = ref_clock_get();
|
||||||
|
args.done = xSemaphoreCreateBinary();
|
||||||
TEST_ESP_OK(esp_timer_start_periodic(timer1, delay_ms * 1000));
|
TEST_ESP_OK(esp_timer_start_periodic(timer1, delay_ms * 1000));
|
||||||
|
|
||||||
vTaskDelay(delay_ms * (NUM_INTERVALS + 1));
|
TEST_ASSERT(xSemaphoreTake(args.done, delay_ms * NUM_INTERVALS * 2));
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_UINT32(NUM_INTERVALS, args.cur_interval);
|
TEST_ASSERT_EQUAL_UINT32(NUM_INTERVALS, args.cur_interval);
|
||||||
for (size_t i = 0; i < NUM_INTERVALS; ++i) {
|
for (size_t i = 0; i < NUM_INTERVALS; ++i) {
|
||||||
@@ -155,6 +158,7 @@ TEST_CASE("periodic ets_timer produces correct delays", "[esp_timer]")
|
|||||||
TEST_ESP_OK( esp_timer_dump(stdout) );
|
TEST_ESP_OK( esp_timer_dump(stdout) );
|
||||||
|
|
||||||
TEST_ESP_OK( esp_timer_delete(timer1) );
|
TEST_ESP_OK( esp_timer_delete(timer1) );
|
||||||
|
vSemaphoreDelete(args.done);
|
||||||
#undef NUM_INTERVALS
|
#undef NUM_INTERVALS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user