From ca8264cd529512acd6b306434fed658372815277 Mon Sep 17 00:00:00 2001 From: Madhukar Pappireddy Date: Fri, 28 Jan 2022 17:14:21 -0600 Subject: test(interrupts): use custom handler for interrupt SP registers a custom handler that checks and updates a flag. Once the watchdog interrupt triggers, the custom handler is invoked at the tail end of interrupt handling. This helps the test to ensure the virtual interrupt corresponding to the trusted watchdog timer was correctly handled. Signed-off-by: Madhukar Pappireddy Change-Id: I7e388076165d097ec7f2bb493b83fe11d2bc0f34 --- spm/cactus/cactus_tests/cactus_test_interrupts.c | 41 ++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'spm/cactus/cactus_tests') diff --git a/spm/cactus/cactus_tests/cactus_test_interrupts.c b/spm/cactus/cactus_tests/cactus_test_interrupts.c index 2d37f8a..3fa5f23 100644 --- a/spm/cactus/cactus_tests/cactus_test_interrupts.c +++ b/spm/cactus/cactus_tests/cactus_test_interrupts.c @@ -14,6 +14,14 @@ #include +static int flag_set; + +static void sec_wdog_interrupt_handled(void) +{ + expect(flag_set, 0); + flag_set = 1; +} + CACTUS_CMD_HANDLER(sleep_cmd, CACTUS_SLEEP_CMD) { uint64_t time_lapsed; @@ -102,16 +110,35 @@ CACTUS_CMD_HANDLER(twdog_cmd, CACTUS_TWDOG_START_CMD) return cactus_success_resp(vm_id, source, time_ms); } +bool handle_twdog_interrupt_sp_sleep(uint32_t sleep_time, uint64_t *time_lapsed) +{ + sp_register_interrupt_tail_end_handler(sec_wdog_interrupt_handled, + IRQ_TWDOG_INTID); + *time_lapsed += sp_sleep_elapsed_time(sleep_time); + + if (flag_set == 0) { + return false; + } + + /* Reset the flag and unregister the handler. */ + flag_set = 0; + sp_unregister_interrupt_tail_end_handler(IRQ_TWDOG_INTID); + + return true; +} + CACTUS_CMD_HANDLER(sleep_twdog_cmd, CACTUS_SLEEP_TRIGGER_TWDOG_CMD) { - uint64_t time_lapsed; + uint64_t time_lapsed = 0; uint32_t sleep_time = cactus_get_sleep_time(*args) / 2; uint64_t time_ms = cactus_get_wdog_trigger_duration(*args); VERBOSE("Request to sleep %x for %ums.\n", ffa_dir_msg_dest(*args), sleep_time); - time_lapsed = sp_sleep_elapsed_time(sleep_time); + if (!handle_twdog_interrupt_sp_sleep(sleep_time, &time_lapsed)) { + goto fail; + } /* Lapsed time should be at least equal to sleep time. */ VERBOSE("Sleep complete: %llu\n", time_lapsed); @@ -123,7 +150,9 @@ CACTUS_CMD_HANDLER(sleep_twdog_cmd, CACTUS_SLEEP_TRIGGER_TWDOG_CMD) VERBOSE("2nd Request to sleep %x for %ums.\n", ffa_dir_msg_dest(*args), sleep_time); - time_lapsed += sp_sleep_elapsed_time(sleep_time); + if (!handle_twdog_interrupt_sp_sleep(sleep_time, &time_lapsed)) { + goto fail; + } /* Lapsed time should be at least equal to sleep time. */ VERBOSE("2nd Sleep complete: %llu\n", time_lapsed); @@ -131,4 +160,10 @@ CACTUS_CMD_HANDLER(sleep_twdog_cmd, CACTUS_SLEEP_TRIGGER_TWDOG_CMD) return cactus_response(ffa_dir_msg_dest(*args), ffa_dir_msg_source(*args), time_lapsed); +fail: + /* Test failed. */ + ERROR("Watchdog interrupt not handled\n"); + return cactus_error_resp(ffa_dir_msg_dest(*args), + ffa_dir_msg_source(*args), + CACTUS_ERROR_TEST); } -- cgit v1.2.3