newlib: Mitigate UT - time adjustment happens linearly

This commit is contained in:
KonstantinKondrashov 2021-07-08 19:21:44 +05:00
parent ee3e817a93
commit 04a6aae1d1

View File

@ -216,6 +216,7 @@ static void get_time_task(void *pvParameters)
// although exit flag is set in another task, checking (exit_flag == false) is safe
while (exit_flag == false) {
gettimeofday(&tv_time, NULL);
vTaskDelay(1500 / portTICK_PERIOD_MS);
}
xSemaphoreGive(*sema);
vTaskDelete(NULL);
@ -224,13 +225,9 @@ static void get_time_task(void *pvParameters)
static void start_measure(int64_t* sys_time, int64_t* real_time)
{
struct timeval tv_time;
int64_t t1, t2;
do {
t1 = esp_timer_get_time();
gettimeofday(&tv_time, NULL);
t2 = esp_timer_get_time();
} while (t2 - t1 > 40);
*real_time = t2;
// there shouldn't be much time between gettimeofday and esp_timer_get_time
gettimeofday(&tv_time, NULL);
*real_time = esp_timer_get_time();
*sys_time = (int64_t)tv_time.tv_sec * 1000000L + tv_time.tv_usec;
}
@ -266,7 +263,7 @@ static void measure_time_task(void *pvParameters)
int64_t sys_time_us[2] = { main_sys_time_us[0], 0};
// although exit flag is set in another task, checking (exit_flag == false) is safe
while (exit_flag == false) {
ets_delay_us(2 * 1000000); // 2 sec
vTaskDelay(2000 / portTICK_PERIOD_MS);
start_measure(&sys_time_us[1], &real_time_us[1]);
result_adjtime_correction_us[1] += calc_correction("measure", sys_time_us, real_time_us);
@ -287,7 +284,7 @@ static void measure_time_task(void *pvParameters)
vTaskDelete(NULL);
}
TEST_CASE("test time adjustment happens linearly", "[newlib][timeout=35]")
TEST_CASE("test time adjustment happens linearly", "[newlib][timeout=15]")
{
exit_flag = false;
@ -300,8 +297,8 @@ TEST_CASE("test time adjustment happens linearly", "[newlib][timeout=35]")
xTaskCreatePinnedToCore(get_time_task, "get_time_task", 4096, &exit_sema[0], UNITY_FREERTOS_PRIORITY - 1, NULL, 0);
xTaskCreatePinnedToCore(measure_time_task, "measure_time_task", 4096, &exit_sema[1], UNITY_FREERTOS_PRIORITY - 1, NULL, 1);
printf("start waiting for 30 seconds\n");
vTaskDelay(30000 / portTICK_PERIOD_MS);
printf("start waiting for 10 seconds\n");
vTaskDelay(10000 / portTICK_PERIOD_MS);
// set exit flag to let thread exit
exit_flag = true;