summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2019-10-28 15:50:02 -0400
committerMike Blumenkrantz <zmike@samsung.com>2019-10-31 09:58:52 -0400
commit8e711d6ce87cd96548e85b6f2c3300f5ed6c55f6 (patch)
tree1a000713abf5122eb397f7fb6e661e34ed482244
parent71a52060f5a407e0cfc0dc8e8e0c6971258da32d (diff)
tests/ecore: add intensive test for recursive timer usage
this recurses the mainloop to a depth of 8, continually creating and triggering timers as it progresses and tracking the states to ensure that everything is working as expected regardless of depth Reviewed-by: Cedric BAIL <cedric.bail@free.fr> Differential Revision: https://phab.enlightenment.org/D10547
-rw-r--r--src/tests/ecore/ecore_test_timer.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/tests/ecore/ecore_test_timer.c b/src/tests/ecore/ecore_test_timer.c
index 06a648578b..b295738e35 100644
--- a/src/tests/ecore/ecore_test_timer.c
+++ b/src/tests/ecore/ecore_test_timer.c
@@ -334,6 +334,88 @@ EFL_START_TEST(ecore_test_timer_iteration)
334} 334}
335EFL_END_TEST 335EFL_END_TEST
336 336
337static Eina_Bool
338_recursion()
339{
340 static unsigned int recurse = 0;
341 static Ecore_Timer *timer;
342
343 switch (recurse++)
344 {
345 case 0:
346 /* verify multiple timer expiration in single mainloop iteration */
347 ecore_timer_add(0, _timer_cb, (void *) 2);
348 ecore_timer_add(0, _timer_cb, (void *) 3);
349 ecore_main_loop_iterate();
350 ecore_main_loop_iterate();
351 ck_assert_int_eq(count, 6);
352 ecore_main_loop_quit();
353 break;
354 case 1:
355 /* timers should not expire for one loop iteration */
356 ck_assert_int_eq(count, 1);
357 ecore_timer_add(0, _timer_cb, (void *) 4);
358 ecore_main_loop_iterate();
359 ecore_main_loop_iterate();
360 break;
361 case 2:
362 /* all pending and instantiated timers should expire after exactly one loop iteration */
363 ck_assert_int_eq(count, 3);
364 ecore_main_loop_iterate();
365 ecore_main_loop_iterate();
366 break;
367 case 3:
368 /* this should not interfere with successive timer processing */
369 ck_assert_int_eq(count, 4);
370
371 /* verify out-of-order timer processing solely based on timer times */
372 timer = ecore_timer_add(1, _timer_cb, (void *) 6);
373 ecore_main_loop_iterate();
374 ecore_main_loop_iterate();
375 break;
376 case 4:
377 ck_assert_int_eq(count, 4);
378 ecore_timer_add(0, _timer_cb, (void *) 5);
379 ecore_main_loop_iterate();
380 ecore_main_loop_iterate();
381 break;
382 case 5:
383 ck_assert_int_eq(count, 4);
384 /* timer should expire after exactly 2 iterations */
385 ecore_main_loop_iterate();
386 ecore_main_loop_iterate();
387 break;
388 case 6:
389 ck_assert_int_eq(count, 5);
390 ecore_timer_interval_set(timer, 0);
391 ecore_timer_reset(timer);
392 /* timer should expire after exactly 2 iterations since it becomes un-instantiated now */
393 ecore_main_loop_iterate();
394 ecore_main_loop_iterate();
395 break;
396 case 7:
397 ecore_main_loop_iterate();
398 ecore_main_loop_iterate();
399 break;
400 }
401 return EINA_FALSE;
402}
403
404EFL_START_TEST(ecore_test_timer_recursion)
405{
406 Eina_Bool crit = eina_log_abort_on_critical_get();
407 int critlevel = eina_log_abort_on_critical_level_get();
408 count = 1;
409 eina_log_abort_on_critical_set(1);
410 eina_log_abort_on_critical_level_set(1);
411 ecore_timer_add(0, _recursion, NULL);
412 ecore_main_loop_begin();
413 ck_assert_int_eq(count, 6);
414 eina_log_abort_on_critical_set(crit);
415 eina_log_abort_on_critical_level_set(critlevel);
416}
417EFL_END_TEST
418
337void ecore_test_timer(TCase *tc) 419void ecore_test_timer(TCase *tc)
338{ 420{
339 tcase_add_test(tc, ecore_test_timers); 421 tcase_add_test(tc, ecore_test_timers);
@@ -342,4 +424,5 @@ void ecore_test_timer(TCase *tc)
342 tcase_add_test(tc, ecore_test_ecore_main_loop_timer); 424 tcase_add_test(tc, ecore_test_ecore_main_loop_timer);
343 tcase_add_test(tc, ecore_test_timer_in_order); 425 tcase_add_test(tc, ecore_test_timer_in_order);
344 tcase_add_test(tc, ecore_test_timer_iteration); 426 tcase_add_test(tc, ecore_test_timer_iteration);
427 tcase_add_test(tc, ecore_test_timer_recursion);
345} 428}