cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=7a2fa2c61499132498336f9744e2466b62636779

commit 7a2fa2c61499132498336f9744e2466b62636779
Author: Mike Blumenkrantz <[email protected]>
Date:   Mon Oct 28 15:50:02 2019 -0400

    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 <[email protected]>
    Differential Revision: https://phab.enlightenment.org/D10547
---
 src/tests/ecore/ecore_test_timer.c | 83 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)

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)
 }
 EFL_END_TEST
 
+static Eina_Bool
+_recursion()
+{
+   static unsigned int recurse = 0;
+   static Ecore_Timer *timer;
+
+   switch (recurse++)
+     {
+      case 0:
+        /* verify multiple timer expiration in single mainloop iteration */
+        ecore_timer_add(0, _timer_cb, (void *) 2);
+        ecore_timer_add(0, _timer_cb, (void *) 3);
+        ecore_main_loop_iterate();
+        ecore_main_loop_iterate();
+        ck_assert_int_eq(count, 6);
+        ecore_main_loop_quit();
+        break;
+      case 1:
+        /* timers should not expire for one loop iteration */
+        ck_assert_int_eq(count, 1);
+        ecore_timer_add(0, _timer_cb, (void *) 4);
+        ecore_main_loop_iterate();
+        ecore_main_loop_iterate();
+        break;
+      case 2:
+        /* all pending and instantiated timers should expire after exactly one 
loop iteration */
+        ck_assert_int_eq(count, 3);
+        ecore_main_loop_iterate();
+        ecore_main_loop_iterate();
+        break;
+      case 3:
+        /* this should not interfere with successive timer processing */
+        ck_assert_int_eq(count, 4);
+
+        /* verify out-of-order timer processing solely based on timer times */
+        timer = ecore_timer_add(1, _timer_cb, (void *) 6);
+        ecore_main_loop_iterate();
+        ecore_main_loop_iterate();
+        break;
+      case 4:
+        ck_assert_int_eq(count, 4);
+        ecore_timer_add(0, _timer_cb, (void *) 5);
+        ecore_main_loop_iterate();
+        ecore_main_loop_iterate();
+        break;
+      case 5:
+        ck_assert_int_eq(count, 4);
+        /* timer should expire after exactly 2 iterations */
+        ecore_main_loop_iterate();
+        ecore_main_loop_iterate();
+        break;
+      case 6:
+        ck_assert_int_eq(count, 5);
+        ecore_timer_interval_set(timer, 0);
+        ecore_timer_reset(timer);
+        /* timer should expire after exactly 2 iterations since it becomes 
un-instantiated now */
+        ecore_main_loop_iterate();
+        ecore_main_loop_iterate();
+        break;
+      case 7:
+        ecore_main_loop_iterate();
+        ecore_main_loop_iterate();
+        break;
+     }
+   return EINA_FALSE;
+}
+
+EFL_START_TEST(ecore_test_timer_recursion)
+{
+   Eina_Bool crit = eina_log_abort_on_critical_get();
+   int critlevel = eina_log_abort_on_critical_level_get();
+   count = 1;
+   eina_log_abort_on_critical_set(1);
+   eina_log_abort_on_critical_level_set(1);
+   ecore_timer_add(0, _recursion, NULL);
+   ecore_main_loop_begin();
+   ck_assert_int_eq(count, 6);
+   eina_log_abort_on_critical_set(crit);
+   eina_log_abort_on_critical_level_set(critlevel);
+}
+EFL_END_TEST
+
 void ecore_test_timer(TCase *tc)
 {
   tcase_add_test(tc, ecore_test_timers);
@@ -342,4 +424,5 @@ void ecore_test_timer(TCase *tc)
   tcase_add_test(tc, ecore_test_ecore_main_loop_timer);
   tcase_add_test(tc, ecore_test_timer_in_order);
   tcase_add_test(tc, ecore_test_timer_iteration);
+  tcase_add_test(tc, ecore_test_timer_recursion);
 }

-- 


Reply via email to