diff options
author | Jett Rink <jettrink@chromium.org> | 2020-01-28 10:02:08 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-01-31 17:27:05 +0000 |
commit | 004a1eff1cc254c967338efe1044827ea41f7acf (patch) | |
tree | 5bf7bfc3fa19f02dc4adaab1073756e9b8f834a5 /test | |
parent | b56a56eaba32f4d7d06750ffb3aed3f6e69b0d42 (diff) | |
download | chrome-ec-004a1eff1cc254c967338efe1044827ea41f7acf.tar.gz |
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 <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2025073
Reviewed-by: Diana Z <dzigterman@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/hooks.c | 26 |
1 files changed, 26 insertions, 0 deletions
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(); } |