diff options
-rw-r--r-- | zephyr/test/drivers/common/src/main.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/zephyr/test/drivers/common/src/main.c b/zephyr/test/drivers/common/src/main.c index 978c699d24..1c8497ab3f 100644 --- a/zephyr/test/drivers/common/src/main.c +++ b/zephyr/test/drivers/common/src/main.c @@ -6,8 +6,25 @@ #include <zephyr/kernel.h> #include <zephyr/ztest.h> #include "ec_app_main.h" +#include "hooks.h" #include "test/drivers/test_state.h" +/** + * @brief Semaphore that signals when hooks have completed + */ +static struct k_sem init_hooks_completed; + +/** + * @brief Hook callback function. Gets registered with the lowest priority so + * that we know all actual hooks have finished. Increments the semaphore. + */ +static void hook_completed_callback(void) +{ + /* Signal that hooks are completed */ + k_sem_give(&init_hooks_completed); +} +DECLARE_HOOK(HOOK_CHIPSET_STARTUP, hook_completed_callback, HOOK_PRIO_LAST); + bool drivers_predicate_pre_main(const void *state) { return ((struct test_state *)state)->ec_app_main_run == false; @@ -20,6 +37,8 @@ bool drivers_predicate_post_main(const void *state) void test_main(void) { + k_sem_init(&init_hooks_completed, 0, 1); + struct test_state state = { .ec_app_main_run = false, }; @@ -30,6 +49,15 @@ void test_main(void) ec_app_main(); state.ec_app_main_run = true; +/* Delay the post-main tests until hooks finish. Allow a generous + * timeout before failing. Tests with mocked power states interfere + * with this mechanism, so proceed normally in this case. + */ +#if !IS_ENABLED(CONFIG_POWER_SEQUENCE_MOCK) + zassert_ok(k_sem_take(&init_hooks_completed, K_SECONDS(10)), + "Timed out waiting for hooks to finish"); +#endif /* !IS_ENABLED(CONFIG_POWER_SEQUENCE_MOCK) */ + /* Run all the suites that depend on main being called */ ztest_run_all(&state); } |