Unit-test FFA ABI-s for notification handling
This change implements unit-tests for the listed FFA ABI-s:
- FFA_NOTIFICATION_BIND
- FFA_NOTIFICATION_UNBIND
- FFA_NOTIFICATION_SET
- FFA_NOTIFICATION_GET
Change-Id: I2faa440a408f1846ffd8f4c1f6528292e49ced4c
Signed-off-by: Gabor Toth <gabor.toth2@arm.com>
diff --git a/components/messaging/ffa/libsp/mock/component.cmake b/components/messaging/ffa/libsp/mock/component.cmake
index 101a56f..a3c3c65 100644
--- a/components/messaging/ffa/libsp/mock/component.cmake
+++ b/components/messaging/ffa/libsp/mock/component.cmake
@@ -17,6 +17,7 @@
"${CMAKE_CURRENT_LIST_DIR}/mock_sp_discovery.cpp"
"${CMAKE_CURRENT_LIST_DIR}/mock_sp_memory_management.cpp"
"${CMAKE_CURRENT_LIST_DIR}/mock_sp_messaging.cpp"
+ "${CMAKE_CURRENT_LIST_DIR}/mock_sp_notification.cpp"
"${CMAKE_CURRENT_LIST_DIR}/mock_sp_rxtx.cpp"
)
diff --git a/components/messaging/ffa/libsp/mock/mock_ffa_api.cpp b/components/messaging/ffa/libsp/mock/mock_ffa_api.cpp
index b18731d..aa277f9 100644
--- a/components/messaging/ffa/libsp/mock/mock_ffa_api.cpp
+++ b/components/messaging/ffa/libsp/mock/mock_ffa_api.cpp
@@ -636,3 +636,102 @@
.withUnsignedIntParameter("length", length)
.returnIntValue();
}
+
+void expect_ffa_notification_bind(uint16_t sender, uint16_t receiver, uint32_t flags,
+ uint64_t notification_bitmap, ffa_result result)
+{
+ mock().expectOneCall("ffa_notification_bind")
+ .withUnsignedIntParameter("sender", sender)
+ .withUnsignedIntParameter("receiver", receiver)
+ .withUnsignedIntParameter("flags", flags)
+ .withUnsignedIntParameter("notification_bitmap", notification_bitmap)
+ .andReturnValue(result);
+}
+
+ffa_result ffa_notification_bind(uint16_t sender, uint16_t receiver, uint32_t flags,
+ uint64_t notification_bitmap)
+{
+ return mock()
+ .actualCall("ffa_notification_bind")
+ .withUnsignedIntParameter("sender", sender)
+ .withUnsignedIntParameter("receiver", receiver)
+ .withUnsignedIntParameter("flags", flags)
+ .withUnsignedIntParameter("notification_bitmap", notification_bitmap)
+ .returnIntValue();
+}
+
+void expect_ffa_notification_unbind(uint16_t sender, uint16_t receiver,
+ uint64_t notification_bitmap, ffa_result result)
+{
+ mock().expectOneCall("ffa_notification_unbind")
+ .withUnsignedIntParameter("sender", sender)
+ .withUnsignedIntParameter("receiver", receiver)
+ .withUnsignedIntParameter("notification_bitmap", notification_bitmap)
+ .andReturnValue(result);
+}
+
+ffa_result ffa_notification_unbind(uint16_t sender, uint16_t receiver, uint64_t notification_bitmap)
+{
+ return mock()
+ .actualCall("ffa_notification_unbind")
+ .withUnsignedIntParameter("sender", sender)
+ .withUnsignedIntParameter("receiver", receiver)
+ .withUnsignedIntParameter("notification_bitmap", notification_bitmap)
+ .returnIntValue();
+}
+
+void expect_ffa_notification_set(uint16_t sender, uint16_t receiver, uint32_t flags,
+ uint64_t notification_bitmap, ffa_result result)
+{
+ mock().expectOneCall("ffa_notification_set")
+ .withUnsignedIntParameter("sender", sender)
+ .withUnsignedIntParameter("receiver", receiver)
+ .withUnsignedIntParameter("flags", flags)
+ .withUnsignedIntParameter("notification_bitmap", notification_bitmap)
+ .andReturnValue(result);
+}
+
+ffa_result ffa_notification_set(uint16_t sender, uint16_t receiver, uint32_t flags,
+ uint64_t notification_bitmap)
+{
+ return mock()
+ .actualCall("ffa_notification_set")
+ .withUnsignedIntParameter("sender", sender)
+ .withUnsignedIntParameter("receiver", receiver)
+ .withUnsignedIntParameter("flags", flags)
+ .withUnsignedIntParameter("notification_bitmap", notification_bitmap)
+ .returnIntValue();
+}
+
+void expect_ffa_notification_get(uint16_t sender, uint16_t receiver, uint32_t flags,
+ uint64_t *sp_notification_bitmap, uint64_t *vm_notification_bitmap,
+ uint64_t *framework_notification_bitmap, ffa_result result)
+{
+ mock().expectOneCall("ffa_notification_get")
+ .withUnsignedIntParameter("sender", sender)
+ .withUnsignedIntParameter("receiver", receiver)
+ .withUnsignedIntParameter("flags", flags)
+ .withOutputParameterReturning("sp_notification_bitmap", sp_notification_bitmap,
+ sizeof(*sp_notification_bitmap))
+ .withOutputParameterReturning("vm_notification_bitmap", vm_notification_bitmap,
+ sizeof(*vm_notification_bitmap))
+ .withOutputParameterReturning("framework_notification_bitmap",
+ framework_notification_bitmap,
+ sizeof(*framework_notification_bitmap))
+ .andReturnValue(result);
+}
+
+ffa_result ffa_notification_get(uint16_t sender, uint16_t receiver, uint32_t flags,
+ uint64_t *sp_notification_bitmap, uint64_t *vm_notification_bitmap,
+ uint64_t *framework_notification_bitmap)
+{
+ return mock()
+ .actualCall("ffa_notification_get")
+ .withUnsignedIntParameter("sender", sender)
+ .withUnsignedIntParameter("receiver", receiver)
+ .withUnsignedIntParameter("flags", flags)
+ .withOutputParameter("sp_notification_bitmap", sp_notification_bitmap)
+ .withOutputParameter("vm_notification_bitmap", vm_notification_bitmap)
+ .withOutputParameter("framework_notification_bitmap", framework_notification_bitmap)
+ .returnIntValue();
+}
diff --git a/components/messaging/ffa/libsp/mock/mock_ffa_api.h b/components/messaging/ffa/libsp/mock/mock_ffa_api.h
index 9e43c13..4aad6f5 100644
--- a/components/messaging/ffa/libsp/mock/mock_ffa_api.h
+++ b/components/messaging/ffa/libsp/mock/mock_ffa_api.h
@@ -112,4 +112,17 @@
void expect_ffa_console_log_64(const char *message, size_t length,
ffa_result result);
+void expect_ffa_notification_bind(uint16_t sender, uint16_t receiver, uint32_t flags,
+ uint64_t notification_bitmap, ffa_result result);
+
+void expect_ffa_notification_unbind(uint16_t sender, uint16_t receiver,
+ uint64_t notification_bitmap, ffa_result result);
+
+void expect_ffa_notification_set(uint16_t sender, uint16_t receiver, uint32_t flags,
+ uint64_t notification_bitmap, ffa_result result);
+
+void expect_ffa_notification_get(uint16_t sender, uint16_t receiver, uint32_t flags,
+ uint64_t *sp_notification_bitmap, uint64_t *vm_notification_bitmap,
+ uint64_t *framework_notification_bitmap, ffa_result result);
+
#endif /* FFA_LIBSP_TEST_MOCK_FFA_API_H_ */
diff --git a/components/messaging/ffa/libsp/mock/mock_sp_notification.cpp b/components/messaging/ffa/libsp/mock/mock_sp_notification.cpp
new file mode 100644
index 0000000..fef2840
--- /dev/null
+++ b/components/messaging/ffa/libsp/mock/mock_sp_notification.cpp
@@ -0,0 +1,109 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2025, Arm Limited. All rights reserved.
+ */
+
+#include <CppUTestExt/MockSupport.h>
+#include "mock_sp_notification.h"
+
+void expect_sp_notification_bind(uint16_t sender, uint16_t receiver,
+ struct sp_notif_bind_flags *flags, uint64_t notification_bitmap,
+ sp_result result)
+{
+ mock().expectOneCall("sp_notification_bind")
+ .withUnsignedIntParameter("sender", sender)
+ .withUnsignedIntParameter("receiver", receiver)
+ .withMemoryBufferParameter("flags", (const uint8_t *)flags, sizeof(*flags))
+ .withUnsignedIntParameter("notification_bitmap", notification_bitmap)
+ .andReturnValue(result);
+}
+
+sp_result sp_notification_bind(uint16_t sender, uint16_t receiver,
+ struct sp_notif_bind_flags *flags, uint64_t notification_bitmap)
+{
+ return mock()
+ .actualCall("sp_notification_bind")
+ .withUnsignedIntParameter("sender", sender)
+ .withUnsignedIntParameter("receiver", receiver)
+ .withMemoryBufferParameter("flags", (const uint8_t *)flags, sizeof(*flags))
+ .withUnsignedIntParameter("notification_bitmap", notification_bitmap)
+ .returnIntValue();
+}
+
+void expect_sp_notification_unbind(uint16_t sender, uint16_t receiver, uint64_t notification_bitmap,
+ sp_result result)
+{
+ mock().expectOneCall("sp_notification_unbind")
+ .withUnsignedIntParameter("sender", sender)
+ .withUnsignedIntParameter("receiver", receiver)
+ .withUnsignedIntParameter("notification_bitmap", notification_bitmap)
+ .andReturnValue(result);
+}
+
+sp_result sp_notification_unbind(uint16_t sender, uint16_t receiver, uint64_t notification_bitmap)
+{
+ return mock()
+ .actualCall("sp_notification_unbind")
+ .withUnsignedIntParameter("sender", sender)
+ .withUnsignedIntParameter("receiver", receiver)
+ .withUnsignedIntParameter("notification_bitmap", notification_bitmap)
+ .returnIntValue();
+}
+
+void expect_sp_notification_set(uint16_t sender, uint16_t receiver,
+ struct sp_notif_set_flags *flags, uint64_t notification_bitmap,
+ sp_result result)
+{
+ mock().expectOneCall("sp_notification_set")
+ .withUnsignedIntParameter("sender", sender)
+ .withUnsignedIntParameter("receiver", receiver)
+ .withMemoryBufferParameter("flags", (const uint8_t *)flags, sizeof(*flags))
+ .withUnsignedIntParameter("notification_bitmap", notification_bitmap)
+ .andReturnValue(result);
+}
+
+sp_result sp_notification_set(uint16_t sender, uint16_t receiver, struct sp_notif_set_flags *flags,
+ uint64_t notification_bitmap)
+{
+ return mock()
+ .actualCall("sp_notification_set")
+ .withUnsignedIntParameter("sender", sender)
+ .withUnsignedIntParameter("receiver", receiver)
+ .withMemoryBufferParameter("flags", (const uint8_t *)flags, sizeof(*flags))
+ .withUnsignedIntParameter("notification_bitmap", notification_bitmap)
+ .returnIntValue();
+}
+
+void expect_sp_notification_get(uint16_t sender, uint16_t receiver,
+ uint64_t *sp_notification_bitmap, uint64_t *vm_notification_bitmap,
+ uint32_t *spm_notification_bitmap, uint32_t *hv_notification_bitmap,
+ sp_result result)
+{
+ mock().expectOneCall("sp_notification_get")
+ .withUnsignedIntParameter("sender", sender)
+ .withUnsignedIntParameter("receiver", receiver)
+ .withOutputParameterReturning("sp_notification_bitmap", sp_notification_bitmap,
+ sizeof(*sp_notification_bitmap))
+ .withOutputParameterReturning("vm_notification_bitmap", vm_notification_bitmap,
+ sizeof(*vm_notification_bitmap))
+ .withOutputParameterReturning("spm_notification_bitmap", spm_notification_bitmap,
+ sizeof(*spm_notification_bitmap))
+ .withOutputParameterReturning("hv_notification_bitmap", hv_notification_bitmap,
+ sizeof(*hv_notification_bitmap))
+ .andReturnValue(result);
+}
+
+sp_result sp_notification_get(uint16_t sender, uint16_t receiver, uint64_t *sp_notification_bitmap,
+ uint64_t *vm_notification_bitmap, uint32_t *spm_notification_bitmap,
+ uint32_t *hv_notification_bitmap)
+{
+ return mock()
+ .actualCall("sp_notification_get")
+ .withUnsignedIntParameter("sender", sender)
+ .withUnsignedIntParameter("receiver", receiver)
+ .withOutputParameter("sp_notification_bitmap", sp_notification_bitmap)
+ .withOutputParameter("vm_notification_bitmap", vm_notification_bitmap)
+ .withOutputParameter("spm_notification_bitmap", spm_notification_bitmap)
+ .withOutputParameter("hv_notification_bitmap", hv_notification_bitmap)
+ .returnIntValue();
+}
diff --git a/components/messaging/ffa/libsp/mock/mock_sp_notification.h b/components/messaging/ffa/libsp/mock/mock_sp_notification.h
new file mode 100644
index 0000000..3e9bcc2
--- /dev/null
+++ b/components/messaging/ffa/libsp/mock/mock_sp_notification.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2025, Arm Limited and Contributors. All rights reserved.
+ */
+
+#ifndef LIBSP_MOCK_MOCK_SP_NOTIFICATION_H_
+#define LIBSP_MOCK_MOCK_SP_NOTIFICATION_H_
+
+#include "../include/sp_notification.h"
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void expect_sp_notification_bind(uint16_t sender, uint16_t receiver,
+ struct sp_notif_bind_flags *flags, uint64_t notification_bitmap,
+ sp_result result);
+void expect_sp_notification_unbind(uint16_t sender, uint16_t receiver, uint64_t notification_bitmap,
+ sp_result result);
+void expect_sp_notification_set(uint16_t sender, uint16_t receiver,
+ struct sp_notif_set_flags *flags, uint64_t notification_bitmap,
+ sp_result result);
+void expect_sp_notification_get(uint16_t sender, uint16_t receiver,
+ uint64_t *sp_notification_bitmap, uint64_t *vm_notification_bitmap,
+ uint32_t *spm_notification_bitmap, uint32_t *hv_notification_bitmap,
+ sp_result result);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LIBSP_MOCK_MOCK_SP_NOTIFICATION_H_ */
diff --git a/components/messaging/ffa/libsp/mock/test/test_mock_ffa_api.cpp b/components/messaging/ffa/libsp/mock/test/test_mock_ffa_api.cpp
index 4405712..7be80c8 100644
--- a/components/messaging/ffa/libsp/mock/test/test_mock_ffa_api.cpp
+++ b/components/messaging/ffa/libsp/mock/test/test_mock_ffa_api.cpp
@@ -388,3 +388,56 @@
expect_ffa_console_log_64(message, length, result);
LONGS_EQUAL(result, ffa_console_log_64(message, length));
}
+
+TEST(mock_ffa_api, ffa_notification_bind)
+{
+ const uint16_t sender = 1;
+ const uint16_t receiver = 2;
+ const uint32_t flags = 0xAAAA;
+ const uint64_t notification_bitmap = 0x55555555;
+
+ expect_ffa_notification_bind(sender, receiver, flags, notification_bitmap, result);
+ LONGS_EQUAL(result, ffa_notification_bind(sender, receiver, flags, notification_bitmap));
+}
+
+TEST(mock_ffa_api, ffa_notification_unbind)
+{
+ const uint16_t sender = 1;
+ const uint16_t receiver = 2;
+ const uint64_t notification_bitmap = 0x55555555;
+
+ expect_ffa_notification_unbind(sender, receiver, notification_bitmap, result);
+ LONGS_EQUAL(result, ffa_notification_unbind(sender, receiver, notification_bitmap));
+}
+
+TEST(mock_ffa_api, ffa_notification_set)
+{
+ const uint16_t sender = 1;
+ const uint16_t receiver = 2;
+ const uint32_t flags = 0xAAAA;
+ const uint64_t notification_bitmap = 0x55555555;
+
+ expect_ffa_notification_set(sender, receiver, flags, notification_bitmap, result);
+ LONGS_EQUAL(result, ffa_notification_set(sender, receiver, flags, notification_bitmap));
+}
+
+TEST(mock_ffa_api, ffa_notification_get)
+{
+ const uint16_t sender = 1;
+ const uint16_t receiver = 2;
+ const uint32_t flags = 0xAAAA;
+ uint64_t expected_notification_bitmap = 0x55555555;
+ uint64_t sp_notification_bitmap = 0;
+ uint64_t vm_notification_bitmap = 0;
+ uint64_t framework_notification_bitmap = 0;
+
+ expect_ffa_notification_get(sender, receiver, flags, &expected_notification_bitmap,
+ &expected_notification_bitmap, &expected_notification_bitmap,
+ result);
+ LONGS_EQUAL(result,
+ ffa_notification_get(sender, receiver, flags, &sp_notification_bitmap,
+ &vm_notification_bitmap, &framework_notification_bitmap));
+ LONGS_EQUAL(sp_notification_bitmap, expected_notification_bitmap);
+ LONGS_EQUAL(vm_notification_bitmap, expected_notification_bitmap);
+ LONGS_EQUAL(framework_notification_bitmap, expected_notification_bitmap);
+}
diff --git a/components/messaging/ffa/libsp/mock/test/test_mock_sp_notification.cpp b/components/messaging/ffa/libsp/mock/test/test_mock_sp_notification.cpp
new file mode 100644
index 0000000..3eac96d
--- /dev/null
+++ b/components/messaging/ffa/libsp/mock/test/test_mock_sp_notification.cpp
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2025, Arm Limited. All rights reserved.
+ */
+
+#include <CppUTestExt/MockSupport.h>
+#include <CppUTest/TestHarness.h>
+#include "mock_sp_notification.h"
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+TEST_GROUP(mock_sp_notification)
+{
+ TEST_TEARDOWN()
+ {
+ mock().checkExpectations();
+ mock().clear();
+ }
+
+ static const sp_result result = -1;
+ struct sp_notif_bind_flags bind_flags = { .per_cpu = 1 };
+ struct sp_notif_set_flags set_flags = { .per_cpu = 1,
+ .delay_sched_rec_intr = 0,
+ .receiver_vcpu_id = 42 };
+};
+
+TEST(mock_sp_notification, sp_notification_bind)
+{
+ const uint16_t sender = 1;
+ const uint16_t receiver = 2;
+ const uint64_t notification_bitmap = 0x55555555;
+
+ expect_sp_notification_bind(sender, receiver, &bind_flags, notification_bitmap, result);
+ LONGS_EQUAL(result,
+ sp_notification_bind(sender, receiver, &bind_flags, notification_bitmap));
+}
+
+TEST(mock_sp_notification, sp_notification_unbind)
+{
+ const uint16_t sender = 1;
+ const uint16_t receiver = 2;
+ const uint64_t notification_bitmap = 0x55555555;
+
+ expect_sp_notification_unbind(sender, receiver, notification_bitmap, result);
+ LONGS_EQUAL(result, sp_notification_unbind(sender, receiver, notification_bitmap));
+}
+
+TEST(mock_sp_notification, sp_notification_set)
+{
+ const uint16_t sender = 1;
+ const uint16_t receiver = 2;
+ const uint64_t notification_bitmap = 0x55555555;
+
+ expect_sp_notification_set(sender, receiver, &set_flags, notification_bitmap, result);
+ LONGS_EQUAL(result, sp_notification_set(sender, receiver, &set_flags, notification_bitmap));
+}
+
+TEST(mock_sp_notification, sp_notification_get)
+{
+ const uint16_t sender = 1;
+ const uint16_t receiver = 2;
+ uint64_t expected_notification_bitmap = 0x55555555;
+ uint64_t sp_notification_bitmap = 0;
+ uint64_t vm_notification_bitmap = 0;
+ uint32_t spm_notification_bitmap = 0;
+ uint32_t hv_notification_bitmap = 0;
+
+ expect_sp_notification_get(sender, receiver, &expected_notification_bitmap,
+ &expected_notification_bitmap,
+ (uint32_t *)&expected_notification_bitmap,
+ (uint32_t *)&expected_notification_bitmap, result);
+ LONGS_EQUAL(result, sp_notification_get(sender, receiver, &sp_notification_bitmap,
+ &vm_notification_bitmap, &spm_notification_bitmap,
+ &hv_notification_bitmap));
+ LONGS_EQUAL(sp_notification_bitmap, expected_notification_bitmap);
+ LONGS_EQUAL(vm_notification_bitmap, expected_notification_bitmap);
+ LONGS_EQUAL(spm_notification_bitmap, expected_notification_bitmap);
+ LONGS_EQUAL(hv_notification_bitmap, expected_notification_bitmap);
+}