test: arch timer in nwd is honored across world switch

This patch introduces a test to ensure that the functionality of arch
(EL1 physical) timer configured by NWd endpoint, such as an hypervisor,
is not corrupted by SPMC when an SP also configures the arch timer for
its own use.

Also, necessary helpers and utilities to create the test scenario have
been added.

Signed-off-by: Madhukar Pappireddy <madhukar.pappireddy@arm.com>
Signed-off-by: Olivier Deprez <olivier.deprez@arm.com>
Change-Id: I1cfd1e1117412b2b23a57af30064c41dc2e66e0b
diff --git a/spm/cactus/cactus_tests/cactus_test_timer.c b/spm/cactus/cactus_tests/cactus_test_timer.c
new file mode 100644
index 0000000..6c8af0c
--- /dev/null
+++ b/spm/cactus/cactus_tests/cactus_test_timer.c
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2024, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "cactus_message_loop.h"
+#include "cactus_test_cmds.h"
+#include "debug.h"
+
+uint32_t ms_to_ticks(uint64_t ms)
+{
+	return ms * read_cntfrq_el0() / 1000;
+}
+
+CACTUS_CMD_HANDLER(set_virtual_timer, CACTUS_SET_ARCH_TIMER_CMD)
+{
+	uint64_t deadline_ms = cactus_get_timer_deadline(*args);
+	uint64_t wait_time = cactus_get_timer_wait_time(*args);
+	uint32_t ticks = ms_to_ticks(deadline_ms);
+
+	write_cntp_ctl_el0(0);
+	write_cntp_tval_el0(ticks);
+	write_cntp_ctl_el0(1);
+
+	if (wait_time != 0U) {
+		waitms(wait_time);
+	}
+
+	return cactus_response(ffa_dir_msg_dest(*args),
+			       ffa_dir_msg_source(*args),
+			       CACTUS_SUCCESS);
+}