tests: improve ecore timer test code

Summary:
a stack variable was incorrectly used here, along with some lazy timing
calcs which did not accurately measure the time for each timer iteration,
resulting in a test which intermittently failed in some cases

fix T6878

Reviewers: stefan_schmidt, bu5hm4n, ManMower

Reviewed By: ManMower

Subscribers: ManMower, cedric, #committers

Tags: #efl

Maniphest Tasks: T6878

Differential Revision: https://phab.enlightenment.org/D6256
This commit is contained in:
Mike Blumenkrantz 2018-06-12 10:52:12 -04:00
parent 2cf05bac09
commit d5a4fba118
1 changed files with 14 additions and 9 deletions

View File

@ -174,31 +174,36 @@ typedef struct _Test_Inside_Call
{ {
Ecore_Timer *t; Ecore_Timer *t;
double start; double start;
int it;
} Test_Inside_Call; } Test_Inside_Call;
static Eina_Bool static Eina_Bool
_timeri_cb(void *data) _timeri_cb(void *data)
{ {
static int it = 5;
Test_Inside_Call *c = data; Test_Inside_Call *c = data;
fail_if(fabs(((ecore_time_get() - c->start) / (6 - it)) - 0.011) > 0.01); fail_if(fabs((ecore_time_get() - c->start) - 0.011) > 0.01);
ecore_timer_reset(c->t); ecore_timer_reset(c->t);
c->start = ecore_time_get();
it--; c->it--;
if (it == 0) ecore_main_loop_quit(); if (c->it > 0) return EINA_TRUE;
return it != 0; free(c);
ecore_main_loop_quit();
return EINA_FALSE;
} }
EFL_START_TEST(ecore_test_timer_inside_call) EFL_START_TEST(ecore_test_timer_inside_call)
{ {
Test_Inside_Call c; Test_Inside_Call *c;
c.start = ecore_time_get(); c = malloc(sizeof(Test_Inside_Call));
c.t = ecore_timer_add(0.01, _timeri_cb, &c); c->start = ecore_time_get();
c->it = 5;
c->t = ecore_timer_add(0.01, _timeri_cb, c);
fail_if(!c.t, "Error add timer\n"); fail_if(!c->t, "Error add timer\n");
ecore_main_loop_begin(); ecore_main_loop_begin();
} }