refactor(cactus): notification set command for SRI test

Refactored slightly the notification set command in order to validate
behavior from SWd for different configurations of the SRI flag.
The test command now accepts another argument, which specifies the ID
of an SP to send a request after setting the notification. This will be
useful to test that sending SRI was delayed, and after the notification
set call the execution continued in the SWd. TFTF will be able to check
if the specified SP processed a command recurring to the test command
CACTUS_GET_REQ_COUNT_CMD.

Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: I10779629be06275c844a2ad9afed72bd61c8a14a
diff --git a/spm/cactus/cactus_tests/cactus_test_notifications.c b/spm/cactus/cactus_tests/cactus_test_notifications.c
index 66eaf36..01839c5 100644
--- a/spm/cactus/cactus_tests/cactus_test_notifications.c
+++ b/spm/cactus/cactus_tests/cactus_test_notifications.c
@@ -88,9 +88,10 @@
 {
 	ffa_id_t source = ffa_dir_msg_source(*args);
 	ffa_id_t vm_id = ffa_dir_msg_dest(*args);
-	ffa_id_t receiver = cactus_notification_get_receiver(*args);
-	ffa_id_t sender = cactus_notification_get_sender(*args);
 	ffa_notification_bitmap_t notifications = cactus_notification_get_notifications(*args);
+	ffa_id_t receiver = cactus_notifications_set_get_receiver(*args);
+	ffa_id_t sender = cactus_notifications_set_get_sender(*args);
+	ffa_id_t echo_dest = cactus_req_echo_get_echo_dest(*args);
 	uint32_t flags = cactus_notification_get_flags(*args);
 	smc_ret_values ret;
 
@@ -102,5 +103,25 @@
 		return cactus_error_resp(vm_id, source, ffa_error_code(ret));
 	}
 
+	/*
+	 * If flag to delay notification pending interrupt, an echo test command
+	 * should be sent to another SP, to validate SWd is not preempted.
+	 */
+	if ((flags & FFA_NOTIFICATIONS_FLAG_DELAY_SRI) != 0 &&
+	    IS_SP_ID(echo_dest)) {
+		VERBOSE("Delay SRI. Test Echo to %x.\n", echo_dest);
+		ret = cactus_echo_send_cmd(vm_id, echo_dest,
+					   FFA_NOTIFICATION_SET);
+
+		if (!is_expected_cactus_response(ret, CACTUS_SUCCESS,
+						 FFA_NOTIFICATION_SET)) {
+			ERROR("Echo Failed!\n");
+			return cactus_error_resp(vm_id, source,
+						 CACTUS_ERROR_TEST);
+		}
+	}
+
+	VERBOSE("Set notifications handled!\n");
+
 	return cactus_response(vm_id, source, CACTUS_SUCCESS);
 }