From 004a1eff1cc254c967338efe1044827ea41f7acf Mon Sep 17 00:00:00 2001 From: Jett Rink Date: Tue, 28 Jan 2020 10:02:08 -0700 Subject: test: add repeating deferred test Adding simple unit test that ensures that a deferred call can call itself and won't repeat forever. I thought this might be a problem, but it wasn't. We might as well add this code as a unit test. BRANCH=none BUG=none TEST=test passes Change-Id: Ie9791606e4a401821594df122481f22d87eadbbd Signed-off-by: Jett Rink Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2025073 Reviewed-by: Diana Z --- test/hooks.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/hooks.c b/test/hooks.c index 09ed981ae1..e7226ea353 100644 --- a/test/hooks.c +++ b/test/hooks.c @@ -134,6 +134,31 @@ static int test_deferred(void) return EC_SUCCESS; } +static int repeating_deferred_count; +static void deferred_repeating_func(void); +DECLARE_DEFERRED(deferred_repeating_func); + +static void deferred_repeating_func(void) +{ + ++repeating_deferred_count; + + usleep(100 * MSEC); + if (repeating_deferred_count < 5) + hook_call_deferred(&deferred_repeating_func_data, SECOND); + + usleep(100 * MSEC); +} + +static int test_repeating_deferred(void) +{ + repeating_deferred_count = 0; + hook_call_deferred(&deferred_repeating_func_data, 0); + usleep(MINUTE); + TEST_EQ(repeating_deferred_count, 5, "%d"); + + return EC_SUCCESS; +} + void run_test(void) { test_reset(); @@ -142,6 +167,7 @@ void run_test(void) RUN_TEST(test_ticks); RUN_TEST(test_priority); RUN_TEST(test_deferred); + RUN_TEST(test_repeating_deferred); test_print_result(); } -- cgit v1.2.1