summaryrefslogtreecommitdiff
path: root/spm/cactus/cactus_tests
diff options
context:
space:
mode:
authorMadhukar Pappireddy <madhukar.pappireddy@arm.com>2022-01-28 17:14:21 -0600
committerMadhukar Pappireddy <madhukar.pappireddy@arm.com>2022-03-22 13:07:18 -0500
commitca8264cd529512acd6b306434fed658372815277 (patch)
treedf5f74c0922cb30d9c5cb55d580ba2cef79e299b /spm/cactus/cactus_tests
parent7caaa4a2098b67f73bf8a87a9ec550720f9dc428 (diff)
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 <madhukar.pappireddy@arm.com> Change-Id: I7e388076165d097ec7f2bb493b83fe11d2bc0f34
Diffstat (limited to 'spm/cactus/cactus_tests')
-rw-r--r--spm/cactus/cactus_tests/cactus_test_interrupts.c41
1 files changed, 38 insertions, 3 deletions
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 <platform.h>
+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);
}