Move libsp mocks into separate component
Enable deployments to include libsp mocks in tests by simply adding
the newly created libsp mock component.
Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: I40805fd49362c6cc71b5b34f9ba888d27ce01ed8
diff --git a/components/messaging/ffa/libsp/mock/component.cmake b/components/messaging/ffa/libsp/mock/component.cmake
new file mode 100644
index 0000000..03b8006
--- /dev/null
+++ b/components/messaging/ffa/libsp/mock/component.cmake
@@ -0,0 +1,27 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+if (NOT DEFINED TGT)
+ message(FATAL_ERROR "mandatory parameter TGT is not defined.")
+endif()
+
+target_sources(${TGT} PRIVATE
+ "${CMAKE_CURRENT_LIST_DIR}/mock_assert.cpp"
+ "${CMAKE_CURRENT_LIST_DIR}/mock_ffa_api.cpp"
+ "${CMAKE_CURRENT_LIST_DIR}/mock_ffa_internal_api.cpp"
+ "${CMAKE_CURRENT_LIST_DIR}/mock_sp_rxtx.cpp"
+ )
+
+target_include_directories(${TGT}
+ PUBLIC
+ ${CMAKE_CURRENT_LIST_DIR}
+ ${CMAKE_CURRENT_LIST_DIR}/../include
+)
+
+target_compile_definitions(${TGT}
+ PUBLIC
+ "ARM64=1"
+)
\ No newline at end of file
diff --git a/components/messaging/ffa/libsp/mock/mock_assert.cpp b/components/messaging/ffa/libsp/mock/mock_assert.cpp
new file mode 100644
index 0000000..f79021a
--- /dev/null
+++ b/components/messaging/ffa/libsp/mock/mock_assert.cpp
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+ */
+
+#include "mock_assert.h"
+#include <assert.h>
+#include <CppUTest/TestHarness.h>
+#include <CppUTestExt/MockSupport.h>
+
+int expect_assert(assert_environment_t *env)
+{
+ mock().expectOneCall("__assert_fail").andReturnValue(env);
+ return 0;
+}
+
+void __assert_fail(const char *assertion, const char *file, unsigned int line,
+ const char *function)
+{
+ (void)assertion;
+ (void)file;
+ (void)line;
+ (void)function;
+
+ assert_environment_t *env = (assert_environment_t *)mock()
+ .actualCall("__assert_fail")
+ .returnPointerValue();
+ longjmp(*env, 1);
+}
diff --git a/components/messaging/ffa/libsp/mock/mock_assert.h b/components/messaging/ffa/libsp/mock/mock_assert.h
new file mode 100644
index 0000000..33a03d5
--- /dev/null
+++ b/components/messaging/ffa/libsp/mock/mock_assert.h
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+ */
+
+#ifndef LIBSP_TEST_MOCK_ASSERT_H_
+#define LIBSP_TEST_MOCK_ASSERT_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <setjmp.h>
+
+typedef jmp_buf assert_environment_t;
+
+/*
+ * SETUP_ASSERT_ENVIRONMENT
+ * Both expect_assert and setjmp must be called without putting them into a new
+ * function. The only way is to use an operator between them. Logical operators
+ * would introduce branches which could introduce uncovered branches. The
+ * solution is use arithmetic operators. expect_assert always return 0 so the
+ * value of the sum is determined by the setjmp return value.
+ *
+ * Example usage:
+ * assert_environment_t env;
+ *
+ * if (SETUP_ASSERT_ENVIRONMENT(env) {
+ * function_with_assert_fail();
+ * }
+ */
+#define SETUP_ASSERT_ENVIRONMENT(env) (expect_assert(&env) + (setjmp(env) == 0))
+
+int expect_assert(assert_environment_t *env);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LIBSP_TEST_MOCK_ASSERT_H_ */
diff --git a/components/messaging/ffa/libsp/mock/mock_ffa_api.cpp b/components/messaging/ffa/libsp/mock/mock_ffa_api.cpp
new file mode 100644
index 0000000..ceebcbf
--- /dev/null
+++ b/components/messaging/ffa/libsp/mock/mock_ffa_api.cpp
@@ -0,0 +1,491 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2020-2022, Arm Limited. All rights reserved.
+ */
+
+#include <CppUTestExt/MockSupport.h>
+#include "mock_ffa_api.h"
+
+void expect_ffa_version(const uint32_t *version, ffa_result result)
+{
+ mock().expectOneCall("ffa_version")
+ .withOutputParameterReturning("version", version,
+ sizeof(*version))
+ .andReturnValue(result);
+}
+
+ffa_result ffa_version(uint32_t *version)
+{
+ return mock()
+ .actualCall("ffa_version")
+ .withOutputParameter("version", version)
+ .returnIntValue();
+}
+
+void expect_ffa_features(
+ uint32_t ffa_function_id,
+ const struct ffa_interface_properties *interface_properties,
+ ffa_result result)
+{
+ mock().expectOneCall("ffa_features")
+ .withOutputParameterReturning("interface_properties",
+ interface_properties,
+ sizeof(*interface_properties))
+ .andReturnValue(result);
+}
+
+ffa_result ffa_features(uint32_t ffa_function_id,
+ struct ffa_interface_properties *interface_properties)
+{
+ return mock()
+ .actualCall("ffa_features")
+ .withOutputParameter("interface_properties",
+ interface_properties)
+ .returnIntValue();
+}
+
+void expect_ffa_rx_release(ffa_result result)
+{
+ mock().expectOneCall("ffa_rx_telease").andReturnValue(result);
+}
+
+ffa_result ffa_rx_release(void)
+{
+ return mock().actualCall("ffa_rx_telease").returnIntValue();
+}
+
+void expect_ffa_rxtx_map(const void *tx_buffer, const void *rx_buffer,
+ uint32_t page_count, ffa_result result)
+{
+ mock().expectOneCall("ffa_rxtx_map")
+ .withConstPointerParameter("tx_buffer", tx_buffer)
+ .withConstPointerParameter("rx_buffer", rx_buffer)
+ .withUnsignedIntParameter("page_count", page_count)
+ .andReturnValue(result);
+}
+
+ffa_result ffa_rxtx_map(const void *tx_buffer, const void *rx_buffer,
+ uint32_t page_count)
+{
+ return mock()
+ .actualCall("ffa_rxtx_map")
+ .withConstPointerParameter("tx_buffer", tx_buffer)
+ .withConstPointerParameter("rx_buffer", rx_buffer)
+ .withUnsignedIntParameter("page_count", page_count)
+ .returnIntValue();
+}
+
+void expect_ffa_rxtx_unmap(uint16_t id, ffa_result result)
+{
+ mock().expectOneCall("ffa_rxtx_unmap")
+ .withUnsignedIntParameter("id", id)
+ .andReturnValue(result);
+}
+
+ffa_result ffa_rxtx_unmap(uint16_t id)
+{
+ return mock()
+ .actualCall("ffa_rxtx_unmap")
+ .withUnsignedIntParameter("id", id)
+ .returnIntValue();
+}
+
+void expect_ffa_partition_info_get(const struct ffa_uuid *uuid,
+ const uint32_t *count, ffa_result result)
+{
+ mock().expectOneCall("ffa_partition_info_get")
+ .withMemoryBufferParameter("uuid", (const unsigned char *)uuid,
+ sizeof(*uuid))
+ .withOutputParameterReturning("count", count, sizeof(*count))
+ .andReturnValue(result);
+}
+
+ffa_result ffa_partition_info_get(const struct ffa_uuid *uuid, uint32_t *count)
+{
+ return mock()
+ .actualCall("ffa_partition_info_get")
+ .withMemoryBufferParameter("uuid", (const unsigned char *)uuid,
+ sizeof(*uuid))
+ .withOutputParameter("count", count)
+ .returnIntValue();
+}
+
+void expect_ffa_id_get(const uint16_t *id, ffa_result result)
+{
+ mock().expectOneCall("ffa_id_get")
+ .withOutputParameterReturning("id", id, sizeof(*id))
+ .andReturnValue(result);
+}
+
+ffa_result ffa_id_get(uint16_t *id)
+{
+ return mock()
+ .actualCall("ffa_id_get")
+ .withOutputParameter("id", id)
+ .returnIntValue();
+}
+
+void expect_ffa_msg_wait(const struct ffa_direct_msg *msg, ffa_result result)
+{
+ mock().expectOneCall("ffa_msg_wait")
+ .withOutputParameterReturning("msg", msg, sizeof(*msg))
+ .andReturnValue(result);
+}
+
+ffa_result ffa_msg_wait(struct ffa_direct_msg *msg)
+{
+ return mock()
+ .actualCall("ffa_msg_wait")
+ .withOutputParameter("msg", msg)
+ .returnIntValue();
+}
+
+void expect_ffa_msg_send_direct_req(uint16_t source, uint16_t dest, uint32_t a0,
+ uint32_t a1, uint32_t a2, uint32_t a3,
+ uint32_t a4,
+ const struct ffa_direct_msg *msg,
+ ffa_result result)
+{
+ mock().expectOneCall("ffa_msg_send_direct_req")
+ .withUnsignedIntParameter("source", source)
+ .withUnsignedIntParameter("dest", dest)
+ .withUnsignedIntParameter("a0", a0)
+ .withUnsignedIntParameter("a1", a1)
+ .withUnsignedIntParameter("a2", a2)
+ .withUnsignedIntParameter("a3", a3)
+ .withUnsignedIntParameter("a4", a4)
+ .withOutputParameterReturning("msg", msg, sizeof(*msg))
+ .andReturnValue(result);
+}
+
+ffa_result ffa_msg_send_direct_req(uint16_t source, uint16_t dest, uint32_t a0,
+ uint32_t a1, uint32_t a2, uint32_t a3,
+ uint32_t a4, struct ffa_direct_msg *msg)
+{
+ return mock()
+ .actualCall("ffa_msg_send_direct_req")
+ .withUnsignedIntParameter("source", source)
+ .withUnsignedIntParameter("dest", dest)
+ .withUnsignedIntParameter("a0", a0)
+ .withUnsignedIntParameter("a1", a1)
+ .withUnsignedIntParameter("a2", a2)
+ .withUnsignedIntParameter("a3", a3)
+ .withUnsignedIntParameter("a4", a4)
+ .withOutputParameter("msg", msg)
+ .returnIntValue();
+}
+
+void expect_ffa_msg_send_direct_resp(uint16_t source, uint16_t dest,
+ uint32_t a0, uint32_t a1, uint32_t a2,
+ uint32_t a3, uint32_t a4,
+ const struct ffa_direct_msg *msg,
+ ffa_result result)
+{
+ mock().expectOneCall("ffa_msg_send_direct_resp")
+ .withUnsignedIntParameter("source", source)
+ .withUnsignedIntParameter("dest", dest)
+ .withUnsignedIntParameter("a0", a0)
+ .withUnsignedIntParameter("a1", a1)
+ .withUnsignedIntParameter("a2", a2)
+ .withUnsignedIntParameter("a3", a3)
+ .withUnsignedIntParameter("a4", a4)
+ .withOutputParameterReturning("msg", msg, sizeof(*msg))
+ .andReturnValue(result);
+}
+
+ffa_result ffa_msg_send_direct_resp(uint16_t source, uint16_t dest, uint32_t a0,
+ uint32_t a1, uint32_t a2, uint32_t a3,
+ uint32_t a4, struct ffa_direct_msg *msg)
+{
+ return mock()
+ .actualCall("ffa_msg_send_direct_resp")
+ .withUnsignedIntParameter("source", source)
+ .withUnsignedIntParameter("dest", dest)
+ .withUnsignedIntParameter("a0", a0)
+ .withUnsignedIntParameter("a1", a1)
+ .withUnsignedIntParameter("a2", a2)
+ .withUnsignedIntParameter("a3", a3)
+ .withUnsignedIntParameter("a4", a4)
+ .withOutputParameter("msg", msg)
+ .returnIntValue();
+}
+
+void expect_ffa_mem_donate(uint32_t total_length, uint32_t fragment_length,
+ void *buffer_address, uint32_t page_count,
+ const uint64_t *handle, ffa_result result)
+{
+ mock().expectOneCall("ffa_mem_donate")
+ .withUnsignedIntParameter("total_length", total_length)
+ .withUnsignedIntParameter("fragment_length", fragment_length)
+ .withPointerParameter("buffer_address", buffer_address)
+ .withUnsignedIntParameter("page_count", page_count)
+ .withOutputParameterReturning("handle", handle, sizeof(*handle))
+ .andReturnValue(result);
+}
+
+ffa_result ffa_mem_donate(uint32_t total_length, uint32_t fragment_length,
+ void *buffer_address, uint32_t page_count,
+ uint64_t *handle)
+{
+ return mock()
+ .actualCall("ffa_mem_donate")
+ .withUnsignedIntParameter("total_length", total_length)
+ .withUnsignedIntParameter("fragment_length", fragment_length)
+ .withPointerParameter("buffer_address", buffer_address)
+ .withUnsignedIntParameter("page_count", page_count)
+ .withOutputParameter("handle", handle)
+ .returnIntValue();
+}
+
+void expect_ffa_mem_donate_rxtx(uint32_t total_length, uint32_t fragment_length,
+ const uint64_t *handle, ffa_result result)
+{
+ mock().expectOneCall("ffa_mem_donate_rxtx")
+ .withUnsignedIntParameter("total_length", total_length)
+ .withUnsignedIntParameter("fragment_length", fragment_length)
+ .withOutputParameterReturning("handle", handle, sizeof(*handle))
+ .andReturnValue(result);
+}
+
+ffa_result ffa_mem_donate_rxtx(uint32_t total_length, uint32_t fragment_length,
+ uint64_t *handle)
+{
+ return mock()
+ .actualCall("ffa_mem_donate_rxtx")
+ .withUnsignedIntParameter("total_length", total_length)
+ .withUnsignedIntParameter("fragment_length", fragment_length)
+ .withOutputParameter("handle", handle)
+ .returnIntValue();
+}
+
+void expect_ffa_mem_lend(uint32_t total_length, uint32_t fragment_length,
+ void *buffer_address, uint32_t page_count,
+ const uint64_t *handle, ffa_result result)
+{
+ mock().expectOneCall("ffa_mem_lend")
+ .withUnsignedIntParameter("total_length", total_length)
+ .withUnsignedIntParameter("fragment_length", fragment_length)
+ .withPointerParameter("buffer_address", buffer_address)
+ .withUnsignedIntParameter("page_count", page_count)
+ .withOutputParameterReturning("handle", handle, sizeof(*handle))
+ .andReturnValue(result);
+}
+
+ffa_result ffa_mem_lend(uint32_t total_length, uint32_t fragment_length,
+ void *buffer_address, uint32_t page_count,
+ uint64_t *handle)
+{
+ return mock()
+ .actualCall("ffa_mem_lend")
+ .withUnsignedIntParameter("total_length", total_length)
+ .withUnsignedIntParameter("fragment_length", fragment_length)
+ .withPointerParameter("buffer_address", buffer_address)
+ .withUnsignedIntParameter("page_count", page_count)
+ .withOutputParameter("handle", handle)
+ .returnIntValue();
+}
+
+void expect_ffa_mem_lend_rxtx(uint32_t total_length, uint32_t fragment_length,
+ const uint64_t *handle, ffa_result result)
+{
+ mock().expectOneCall("ffa_mem_lend_rxtx")
+ .withUnsignedIntParameter("total_length", total_length)
+ .withUnsignedIntParameter("fragment_length", fragment_length)
+ .withOutputParameterReturning("handle", handle, sizeof(*handle))
+ .andReturnValue(result);
+}
+
+ffa_result ffa_mem_lend_rxtx(uint32_t total_length, uint32_t fragment_length,
+ uint64_t *handle)
+{
+ return mock()
+ .actualCall("ffa_mem_lend_rxtx")
+ .withUnsignedIntParameter("total_length", total_length)
+ .withUnsignedIntParameter("fragment_length", fragment_length)
+ .withOutputParameter("handle", handle)
+ .returnIntValue();
+}
+
+void expect_ffa_mem_share(uint32_t total_length, uint32_t fragment_length,
+ void *buffer_address, uint32_t page_count,
+ const uint64_t *handle, ffa_result result)
+{
+ mock().expectOneCall("ffa_mem_share")
+ .withUnsignedIntParameter("total_length", total_length)
+ .withUnsignedIntParameter("fragment_length", fragment_length)
+ .withPointerParameter("buffer_address", buffer_address)
+ .withUnsignedIntParameter("page_count", page_count)
+ .withOutputParameterReturning("handle", handle, sizeof(*handle))
+ .andReturnValue(result);
+}
+
+ffa_result ffa_mem_share(uint32_t total_length, uint32_t fragment_length,
+ void *buffer_address, uint32_t page_count,
+ uint64_t *handle)
+{
+ return mock()
+ .actualCall("ffa_mem_share")
+ .withUnsignedIntParameter("total_length", total_length)
+ .withUnsignedIntParameter("fragment_length", fragment_length)
+ .withPointerParameter("buffer_address", buffer_address)
+ .withUnsignedIntParameter("page_count", page_count)
+ .withOutputParameter("handle", handle)
+ .returnIntValue();
+}
+
+void expect_ffa_mem_share_rxtx(uint32_t total_length, uint32_t fragment_length,
+ const uint64_t *handle, ffa_result result)
+{
+ mock().expectOneCall("ffa_mem_share_rxtx")
+ .withUnsignedIntParameter("total_length", total_length)
+ .withUnsignedIntParameter("fragment_length", fragment_length)
+ .withOutputParameterReturning("handle", handle, sizeof(*handle))
+ .andReturnValue(result);
+}
+
+ffa_result ffa_mem_share_rxtx(uint32_t total_length, uint32_t fragment_length,
+ uint64_t *handle)
+{
+ return mock()
+ .actualCall("ffa_mem_share_rxtx")
+ .withUnsignedIntParameter("total_length", total_length)
+ .withUnsignedIntParameter("fragment_length", fragment_length)
+ .withOutputParameter("handle", handle)
+ .returnIntValue();
+}
+
+void expect_ffa_mem_retrieve_req(uint32_t total_length,
+ uint32_t fragment_length, void *buffer_address,
+ uint32_t page_count,
+ const uint32_t *resp_total_length,
+ const uint32_t *resp_fragment_length,
+ ffa_result result)
+{
+ mock().expectOneCall("ffa_mem_retrieve_req")
+ .withUnsignedIntParameter("total_length", total_length)
+ .withUnsignedIntParameter("fragment_length", fragment_length)
+ .withPointerParameter("buffer_address", buffer_address)
+ .withUnsignedIntParameter("page_count", page_count)
+ .withOutputParameterReturning("resp_total_length",
+ resp_total_length,
+ sizeof(*resp_total_length))
+ .withOutputParameterReturning("resp_fragment_length",
+ resp_fragment_length,
+ sizeof(*resp_fragment_length))
+ .andReturnValue(result);
+}
+
+ffa_result ffa_mem_retrieve_req(uint32_t total_length, uint32_t fragment_length,
+ void *buffer_address, uint32_t page_count,
+ uint32_t *resp_total_length,
+ uint32_t *resp_fragment_length)
+{
+ return mock()
+ .actualCall("ffa_mem_retrieve_req")
+ .withUnsignedIntParameter("total_length", total_length)
+ .withUnsignedIntParameter("fragment_length", fragment_length)
+ .withPointerParameter("buffer_address", buffer_address)
+ .withUnsignedIntParameter("page_count", page_count)
+ .withOutputParameter("resp_total_length", resp_total_length)
+ .withOutputParameter("resp_fragment_length",
+ resp_fragment_length)
+ .returnIntValue();
+}
+
+void expect_ffa_mem_retrieve_req_rxtx(uint32_t total_length,
+ uint32_t fragment_length,
+ const uint32_t *resp_total_length,
+ const uint32_t *resp_fragment_length,
+ ffa_result result)
+{
+ mock().expectOneCall("ffa_mem_retrieve_req_rxtx")
+ .withUnsignedIntParameter("total_length", total_length)
+ .withUnsignedIntParameter("fragment_length", fragment_length)
+ .withOutputParameterReturning("resp_total_length",
+ resp_total_length,
+ sizeof(*resp_total_length))
+ .withOutputParameterReturning("resp_fragment_length",
+ resp_fragment_length,
+ sizeof(*resp_fragment_length))
+ .andReturnValue(result);
+}
+
+ffa_result ffa_mem_retrieve_req_rxtx(uint32_t total_length,
+ uint32_t fragment_length,
+ uint32_t *resp_total_length,
+ uint32_t *resp_fragment_length)
+{
+ return mock()
+ .actualCall("ffa_mem_retrieve_req_rxtx")
+ .withUnsignedIntParameter("total_length", total_length)
+ .withUnsignedIntParameter("fragment_length", fragment_length)
+ .withOutputParameter("resp_total_length", resp_total_length)
+ .withOutputParameter("resp_fragment_length",
+ resp_fragment_length)
+ .returnIntValue();
+}
+
+void expect_ffa_mem_relinquish(ffa_result result)
+{
+ mock().expectOneCall("ffa_mem_relinquish").andReturnValue(result);
+}
+
+ffa_result ffa_mem_relinquish(void)
+{
+ return mock().actualCall("ffa_mem_relinquish").returnIntValue();
+}
+
+void expect_ffa_mem_reclaim(uint64_t handle, uint32_t flags, ffa_result result)
+{
+ mock().expectOneCall("ffa_mem_reclaim")
+ .withUnsignedLongIntParameter("handle", handle)
+ .withUnsignedIntParameter("flags", flags)
+ .andReturnValue(result);
+}
+
+ffa_result ffa_mem_reclaim(uint64_t handle, uint32_t flags)
+{
+ return mock()
+ .actualCall("ffa_mem_reclaim")
+ .withUnsignedLongIntParameter("handle", handle)
+ .withUnsignedIntParameter("flags", flags)
+ .returnIntValue();
+}
+
+void expect_ffa_mem_perm_get(const void *base_address, const uint32_t *mem_perm,
+ ffa_result result)
+{
+ mock().expectOneCall("ffa_mem_perm_get")
+ .withConstPointerParameter("base_address", base_address)
+ .withOutputParameterReturning("mem_perm", mem_perm,
+ sizeof(*mem_perm))
+ .andReturnValue(result);
+}
+
+ffa_result ffa_mem_perm_get(const void *base_address, uint32_t *mem_perm)
+{
+ return mock().actualCall("ffa_mem_perm_get")
+ .withConstPointerParameter("base_address", base_address)
+ .withOutputParameter("mem_perm", mem_perm)
+ .returnIntValue();
+}
+
+void expect_ffa_mem_perm_set(const void *base_address, uint32_t page_count,
+ uint32_t mem_perm, ffa_result result)
+{
+ mock().expectOneCall("ffa_mem_perm_set")
+ .withConstPointerParameter("base_address", base_address)
+ .withUnsignedIntParameter("page_count", page_count)
+ .withUnsignedIntParameter("mem_perm", mem_perm)
+ .andReturnValue(result);
+}
+
+ffa_result ffa_mem_perm_set(const void *base_address, uint32_t page_count,
+ uint32_t mem_perm)
+{
+ return mock().actualCall("ffa_mem_perm_set")
+ .withConstPointerParameter("base_address", base_address)
+ .withUnsignedIntParameter("page_count", page_count)
+ .withUnsignedIntParameter("mem_perm", mem_perm)
+ .returnIntValue();
+}
diff --git a/components/messaging/ffa/libsp/mock/mock_ffa_api.h b/components/messaging/ffa/libsp/mock/mock_ffa_api.h
new file mode 100644
index 0000000..b1c794f
--- /dev/null
+++ b/components/messaging/ffa/libsp/mock/mock_ffa_api.h
@@ -0,0 +1,89 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2020-2022, Arm Limited. All rights reserved.
+ */
+
+#ifndef LIBSP_TEST_MOCK_FFA_API_H_
+#define LIBSP_TEST_MOCK_FFA_API_H_
+
+#include <stdint.h>
+#include "../include/ffa_api.h"
+
+void expect_ffa_version(const uint32_t *version, ffa_result result);
+
+void expect_ffa_features(
+ uint32_t ffa_function_id,
+ const struct ffa_interface_properties *interface_properties,
+ ffa_result result);
+
+void expect_ffa_rx_release(ffa_result result);
+
+void expect_ffa_rxtx_map(const void *tx_buffer, const void *rx_buffer,
+ uint32_t page_count, ffa_result result);
+
+void expect_ffa_rxtx_unmap(uint16_t id, ffa_result result);
+
+void expect_ffa_partition_info_get(const struct ffa_uuid *uuid,
+ const uint32_t *count, ffa_result result);
+
+void expect_ffa_id_get(const uint16_t *id, ffa_result result);
+
+void expect_ffa_msg_wait(const struct ffa_direct_msg *msg, ffa_result result);
+
+void expect_ffa_msg_send_direct_req(uint16_t source, uint16_t dest, uint32_t a0,
+ uint32_t a1, uint32_t a2, uint32_t a3,
+ uint32_t a4,
+ const struct ffa_direct_msg *msg,
+ ffa_result result);
+
+void expect_ffa_msg_send_direct_resp(uint16_t source, uint16_t dest,
+ uint32_t a0, uint32_t a1, uint32_t a2,
+ uint32_t a3, uint32_t a4,
+ const struct ffa_direct_msg *msg,
+ ffa_result result);
+
+void expect_ffa_mem_donate(uint32_t total_length, uint32_t fragment_length,
+ void *buffer_address, uint32_t page_count,
+ const uint64_t *handle, ffa_result result);
+
+void expect_ffa_mem_donate_rxtx(uint32_t total_length, uint32_t fragment_length,
+ const uint64_t *handle, ffa_result result);
+
+void expect_ffa_mem_lend(uint32_t total_length, uint32_t fragment_length,
+ void *buffer_address, uint32_t page_count,
+ const uint64_t *handle, ffa_result result);
+
+void expect_ffa_mem_lend_rxtx(uint32_t total_length, uint32_t fragment_length,
+ const uint64_t *handle, ffa_result result);
+
+void expect_ffa_mem_share(uint32_t total_length, uint32_t fragment_length,
+ void *buffer_address, uint32_t page_count,
+ const uint64_t *handle, ffa_result result);
+
+void expect_ffa_mem_share_rxtx(uint32_t total_length, uint32_t fragment_length,
+ const uint64_t *handle, ffa_result result);
+
+void expect_ffa_mem_retrieve_req(uint32_t total_length,
+ uint32_t fragment_length, void *buffer_address,
+ uint32_t page_count,
+ const uint32_t *resp_total_length,
+ const uint32_t *resp_fragment_length,
+ ffa_result result);
+
+void expect_ffa_mem_retrieve_req_rxtx(uint32_t total_length,
+ uint32_t fragment_length,
+ const uint32_t *resp_total_length,
+ const uint32_t *resp_fragment_length,
+ ffa_result result);
+
+void expect_ffa_mem_relinquish(ffa_result result);
+
+void expect_ffa_mem_reclaim(uint64_t handle, uint32_t flags, ffa_result result);
+
+void expect_ffa_mem_perm_get(const void *base_address, const uint32_t *mem_perm,
+ ffa_result result);
+
+void expect_ffa_mem_perm_set(const void *base_address, uint32_t page_count,
+ uint32_t mem_perm, ffa_result result);
+
+#endif /* FFA_LIBSP_TEST_MOCK_FFA_API_H_ */
diff --git a/components/messaging/ffa/libsp/mock/mock_ffa_internal_api.cpp b/components/messaging/ffa/libsp/mock/mock_ffa_internal_api.cpp
new file mode 100644
index 0000000..56b82d8
--- /dev/null
+++ b/components/messaging/ffa/libsp/mock/mock_ffa_internal_api.cpp
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+ */
+
+#include "mock_ffa_internal_api.h"
+#include <CppUTestExt/MockSupport.h>
+
+void expect_ffa_svc(uint64_t a0, uint64_t a1, uint64_t a2, uint64_t a3,
+ uint64_t a4, uint64_t a5, uint64_t a6, uint64_t a7,
+ const struct ffa_params *result)
+{
+ mock().expectOneCall("ffa_svc")
+ .withUnsignedLongIntParameter("a0", a0)
+ .withUnsignedLongIntParameter("a1", a1)
+ .withUnsignedLongIntParameter("a2", a2)
+ .withUnsignedLongIntParameter("a3", a3)
+ .withUnsignedLongIntParameter("a4", a4)
+ .withUnsignedLongIntParameter("a5", a5)
+ .withUnsignedLongIntParameter("a6", a6)
+ .withUnsignedLongIntParameter("a7", a7)
+ .withOutputParameterReturning("result", result,
+ sizeof(*result));
+}
+
+void ffa_svc(uint64_t a0, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4,
+ uint64_t a5, uint64_t a6, uint64_t a7, struct ffa_params *result)
+{
+ mock().actualCall("ffa_svc")
+ .withUnsignedLongIntParameter("a0", a0)
+ .withUnsignedLongIntParameter("a1", a1)
+ .withUnsignedLongIntParameter("a2", a2)
+ .withUnsignedLongIntParameter("a3", a3)
+ .withUnsignedLongIntParameter("a4", a4)
+ .withUnsignedLongIntParameter("a5", a5)
+ .withUnsignedLongIntParameter("a6", a6)
+ .withUnsignedLongIntParameter("a7", a7)
+ .withOutputParameter("result", result);
+}
diff --git a/components/messaging/ffa/libsp/mock/mock_ffa_internal_api.h b/components/messaging/ffa/libsp/mock/mock_ffa_internal_api.h
new file mode 100644
index 0000000..d706896
--- /dev/null
+++ b/components/messaging/ffa/libsp/mock/mock_ffa_internal_api.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+ */
+
+#ifndef LIBSP_TEST_MOCK_FFA_INTERNAL_API_H_
+#define LIBSP_TEST_MOCK_FFA_INTERNAL_API_H_
+
+#include "ffa_internal_api.h"
+#include <stdint.h>
+
+void expect_ffa_svc(uint64_t a0, uint64_t a1, uint64_t a2, uint64_t a3,
+ uint64_t a4, uint64_t a5, uint64_t a6, uint64_t a7,
+ const struct ffa_params *result);
+
+#endif /* LIBSP_TEST_MOCK_FFA_INTERNAL_API_H_ */
diff --git a/components/messaging/ffa/libsp/mock/mock_sp_rxtx.cpp b/components/messaging/ffa/libsp/mock/mock_sp_rxtx.cpp
new file mode 100644
index 0000000..24111b8
--- /dev/null
+++ b/components/messaging/ffa/libsp/mock/mock_sp_rxtx.cpp
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+ */
+
+#include <CppUTestExt/MockSupport.h>
+#include "mock_sp_rxtx.h"
+
+void expect_sp_rxtx_buffer_map(void *tx_buffer, const void *rx_buffer,
+ size_t size, sp_result result)
+{
+ mock().expectOneCall("sp_rxtx_buffer_map")
+ .withPointerParameter("tx_buffer", tx_buffer)
+ .withConstPointerParameter("rx_buffer", rx_buffer)
+ .withUnsignedIntParameter("size", size)
+ .andReturnValue(result);
+}
+
+sp_result sp_rxtx_buffer_map(void *tx_buffer, const void *rx_buffer,
+ size_t size)
+{
+ return mock()
+ .actualCall("sp_rxtx_buffer_map")
+ .withPointerParameter("tx_buffer", tx_buffer)
+ .withConstPointerParameter("rx_buffer", rx_buffer)
+ .withUnsignedIntParameter("size", size)
+ .returnIntValue();
+}
+
+void expect_sp_rxtx_buffer_unmap(sp_result result)
+{
+ mock().expectOneCall("sp_rxtx_buffer_unmap").andReturnValue(result);
+}
+
+sp_result sp_rxtx_buffer_unmap(void)
+{
+ return mock().actualCall("sp_rxtx_buffer_unmap").returnIntValue();
+}
+
+void expect_sp_rxtx_buffer_alignment_boundary_get(const uintptr_t *alignment,
+ sp_result result)
+{
+ mock().expectOneCall("sp_rxtx_buffer_alignment_boundary_get")
+ .withOutputParameterReturning("alignment", alignment,
+ sizeof(*alignment))
+ .andReturnValue(result);
+}
+
+sp_result sp_rxtx_buffer_alignment_boundary_get(uintptr_t *alignment)
+{
+ return mock()
+ .actualCall("sp_rxtx_buffer_alignment_boundary_get")
+ .withOutputParameter("alignment", alignment)
+ .returnIntValue();
+}
+
+void expect_sp_rxtx_buffer_rx_get(const void **buffer, size_t *size,
+ sp_result result)
+{
+ mock().expectOneCall("sp_rxtx_buffer_rx_get")
+ .withOutputParameterReturning("buffer", buffer, sizeof(*buffer))
+ .withOutputParameterReturning("size", size, sizeof(*size))
+ .andReturnValue(result);
+}
+
+sp_result sp_rxtx_buffer_rx_get(const void **buffer, size_t *size)
+{
+ return mock()
+ .actualCall("sp_rxtx_buffer_rx_get")
+ .withOutputParameter("buffer", buffer)
+ .withOutputParameter("size", size)
+ .returnIntValue();
+}
+
+void expect_sp_rxtx_buffer_tx_get(void **buffer, size_t *size, sp_result result)
+{
+ mock().expectOneCall("sp_rxtx_buffer_tx_get")
+ .withOutputParameterReturning("buffer", buffer, sizeof(*buffer))
+ .withOutputParameterReturning("size", size, sizeof(*size))
+ .andReturnValue(result);
+}
+
+sp_result sp_rxtx_buffer_tx_get(void **buffer, size_t *size)
+{
+ return mock()
+ .actualCall("sp_rxtx_buffer_tx_get")
+ .withOutputParameter("buffer", buffer)
+ .withOutputParameter("size", size)
+ .returnIntValue();
+}
diff --git a/components/messaging/ffa/libsp/mock/mock_sp_rxtx.h b/components/messaging/ffa/libsp/mock/mock_sp_rxtx.h
new file mode 100644
index 0000000..c036d36
--- /dev/null
+++ b/components/messaging/ffa/libsp/mock/mock_sp_rxtx.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+ */
+
+#ifndef LIBSP_TEST_MOCK_SP_RXTX_H_
+#define LIBSP_TEST_MOCK_SP_RXTX_H_
+
+#include "../include/sp_rxtx.h"
+
+void expect_sp_rxtx_buffer_map(void *tx_buffer, const void *rx_buffer,
+ size_t size, sp_result result);
+sp_result sp_rxtx_buffer_map(void *tx_buffer, const void *rx_buffer,
+ size_t size);
+
+void expect_sp_rxtx_buffer_unmap(sp_result result);
+sp_result sp_rxtx_buffer_unmap(void);
+
+void expect_sp_rxtx_buffer_alignment_boundary_get(const uintptr_t *alignment,
+ sp_result result);
+sp_result sp_rxtx_buffer_alignment_boundary_get(uintptr_t *alignment);
+
+void expect_sp_rxtx_buffer_rx_get(const void **buffer, size_t *size,
+ sp_result sp_result);
+sp_result sp_rxtx_buffer_rx_get(const void **buffer, size_t *size);
+
+void expect_sp_rxtx_buffer_tx_get(void **buffer, size_t *size,
+ sp_result result);
+sp_result sp_rxtx_buffer_tx_get(void **buffer, size_t *size);
+
+#endif /* LIBSP_TEST_MOCK_SP_RXTX_H_ */
diff --git a/components/messaging/ffa/libsp/mock/test/test_mock_assert.cpp b/components/messaging/ffa/libsp/mock/test/test_mock_assert.cpp
new file mode 100644
index 0000000..39004d6
--- /dev/null
+++ b/components/messaging/ffa/libsp/mock/test/test_mock_assert.cpp
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+ */
+
+#include <assert.h>
+#include <CppUTest/TestHarness.h>
+#include <CppUTestExt/MockSupport.h>
+#include "mock_assert.h"
+
+TEST_GROUP(mock_assert)
+{
+ TEST_TEARDOWN()
+ {
+ mock().checkExpectations();
+ mock().clear();
+ }
+};
+
+TEST(mock_assert, assert)
+{
+ assert_environment_t assert_env;
+
+ if (SETUP_ASSERT_ENVIRONMENT(assert_env)) {
+ assert(false);
+ FAIL("Assert jump not happened"); // Should not be called
+ }
+}
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
new file mode 100644
index 0000000..ab33649
--- /dev/null
+++ b/components/messaging/ffa/libsp/mock/test/test_mock_ffa_api.cpp
@@ -0,0 +1,313 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2020-2022, Arm Limited. All rights reserved.
+ */
+
+#include <assert.h>
+#include <CppUTest/TestHarness.h>
+#include <CppUTestExt/MockSupport.h>
+#include "mock_ffa_api.h"
+
+const struct ffa_direct_msg expected_msg = { 0xffeeddcc, 0xaabb, 0x8899,
+ 0x12345678, 0x23456789, 0x3456789a,
+ 0x456789ab, 0x56789abc };
+
+TEST_GROUP(mock_ffa_api)
+{
+ TEST_TEARDOWN()
+ {
+ mock().checkExpectations();
+ mock().clear();
+ }
+
+ static const ffa_result result = -1;
+};
+
+TEST(mock_ffa_api, ffa_version)
+{
+ const uint32_t expected_version = 0x12345678U;
+ uint32_t version = 0;
+
+ expect_ffa_version(&expected_version, result);
+ LONGS_EQUAL(result, ffa_version(&version));
+ UNSIGNED_LONGS_EQUAL(expected_version, version);
+}
+
+TEST(mock_ffa_api, ffa_features)
+{
+ const uint32_t ffa_function_id = 0xfedcba98U;
+ const struct ffa_interface_properties expected_interface_properties = {
+ 0xaabbccdd, 0x44556677
+ };
+ struct ffa_interface_properties interface_properties = { 0 };
+
+ expect_ffa_features(ffa_function_id, &expected_interface_properties,
+ result);
+ LONGS_EQUAL(result,
+ ffa_features(ffa_function_id, &interface_properties));
+ MEMCMP_EQUAL(&expected_interface_properties, &interface_properties,
+ sizeof(expected_interface_properties));
+}
+
+TEST(mock_ffa_api, ffa_rx_release)
+{
+ expect_ffa_rx_release(result);
+ LONGS_EQUAL(result, ffa_rx_release());
+}
+
+TEST(mock_ffa_api, ffa_rxtx_map)
+{
+ const char tx_buffer = 0;
+ const char rx_buffer = 0;
+ const uint32_t page_count = 0x89abcdefU;
+
+ expect_ffa_rxtx_map(&tx_buffer, &rx_buffer, page_count, result);
+ LONGS_EQUAL(result, ffa_rxtx_map(&tx_buffer, &rx_buffer, page_count));
+}
+
+TEST(mock_ffa_api, ffa_rxtx_unmap)
+{
+ const uint16_t id = 0xffee;
+
+ expect_ffa_rxtx_unmap(id, result);
+ LONGS_EQUAL(result, ffa_rxtx_unmap(id));
+}
+
+TEST(mock_ffa_api, ffa_partition_info_get)
+{
+ const struct ffa_uuid uuid = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54,
+ 0x32, 0x10, 0x01, 0x23, 0x45, 0x67,
+ 0x89, 0xab, 0xcd, 0xef };
+ const uint32_t expect_count = 0xff00ee11U;
+ uint32_t count = 0;
+
+ expect_ffa_partition_info_get(&uuid, &expect_count, result);
+ LONGS_EQUAL(result, ffa_partition_info_get(&uuid, &count));
+ UNSIGNED_LONGS_EQUAL(expect_count, count);
+}
+
+TEST(mock_ffa_api, ffa_id_get)
+{
+ const uint16_t expected_id = 0xabcd;
+ uint16_t id = 0;
+
+ expect_ffa_id_get(&expected_id, result);
+ LONGS_EQUAL(result, ffa_id_get(&id));
+ UNSIGNED_LONGS_EQUAL(expected_id, id);
+}
+
+TEST(mock_ffa_api, ffa_msg_wait)
+{
+ struct ffa_direct_msg msg = { 0 };
+
+ expect_ffa_msg_wait(&expected_msg, result);
+ LONGS_EQUAL(result, ffa_msg_wait(&msg));
+ MEMCMP_EQUAL(&expected_msg, &msg, sizeof(expected_msg));
+}
+
+TEST(mock_ffa_api, ffa_msg_send_direct_req)
+{
+ const uint16_t source = 0x1122;
+ const uint16_t dest = 0x2233;
+ const uint32_t a0 = 0x45678912;
+ const uint32_t a1 = 0x56789124;
+ const uint32_t a2 = 0x67891245;
+ const uint32_t a3 = 0x78912456;
+ const uint32_t a4 = 0x89124567;
+ struct ffa_direct_msg msg = { 0 };
+
+ expect_ffa_msg_send_direct_req(source, dest, a0, a1, a2, a3, a4,
+ &expected_msg, result);
+ LONGS_EQUAL(result, ffa_msg_send_direct_req(source, dest, a0, a1, a2,
+ a3, a4, &msg));
+}
+
+TEST(mock_ffa_api, ffa_msg_send_direct_resp)
+{
+ const uint16_t source = 0x1122;
+ const uint16_t dest = 0x2233;
+ const uint32_t a0 = 0x45678912;
+ const uint32_t a1 = 0x56789124;
+ const uint32_t a2 = 0x67891245;
+ const uint32_t a3 = 0x78912456;
+ const uint32_t a4 = 0x89124567;
+ struct ffa_direct_msg msg = { 0 };
+
+ expect_ffa_msg_send_direct_resp(source, dest, a0, a1, a2, a3, a4,
+ &expected_msg, result);
+ LONGS_EQUAL(result, ffa_msg_send_direct_resp(source, dest, a0, a1, a2,
+ a3, a4, &msg));
+}
+
+TEST(mock_ffa_api, ffa_mem_donate)
+{
+ const uint32_t total_length = 0x12345678U;
+ const uint32_t fragment_length = 0x23456789U;
+ const char buffer = 0;
+ const uint32_t page_count = 0x3456789au;
+ const uint64_t expected_handle = 0xfedcba9876543210ULL;
+ uint64_t handle = 0;
+
+ expect_ffa_mem_donate(total_length, fragment_length, (void *)&buffer,
+ page_count, &expected_handle, result);
+ LONGS_EQUAL(result,
+ ffa_mem_donate(total_length, fragment_length,
+ (void *)&buffer, page_count, &handle));
+ UNSIGNED_LONGLONGS_EQUAL(expected_handle, handle);
+}
+
+TEST(mock_ffa_api, ffa_mem_donate_rxtx)
+{
+ const uint32_t total_length = 0x12345678U;
+ const uint32_t fragment_length = 0x23456789U;
+ const uint64_t expected_handle = 0xfedcba9876543210ULL;
+ uint64_t handle = 0;
+
+ expect_ffa_mem_donate_rxtx(total_length, fragment_length,
+ &expected_handle, result);
+ LONGS_EQUAL(result, ffa_mem_donate_rxtx(total_length, fragment_length,
+ &handle));
+ UNSIGNED_LONGLONGS_EQUAL(expected_handle, handle);
+}
+
+TEST(mock_ffa_api, ffa_mem_lend)
+{
+ const uint32_t total_length = 0x12345678U;
+ const uint32_t fragment_length = 0x23456789U;
+ const char buffer = 0;
+ const uint32_t page_count = 0x3456789au;
+ const uint64_t expected_handle = 0xfedcba9876543210ULL;
+ uint64_t handle = 0;
+
+ expect_ffa_mem_lend(total_length, fragment_length, (void *)&buffer,
+ page_count, &expected_handle, result);
+ LONGS_EQUAL(result, ffa_mem_lend(total_length, fragment_length,
+ (void *)&buffer, page_count, &handle));
+ UNSIGNED_LONGLONGS_EQUAL(expected_handle, handle);
+}
+
+TEST(mock_ffa_api, ffa_mem_lend_rxtx)
+{
+ const uint32_t total_length = 0x12345678U;
+ const uint32_t fragment_length = 0x23456789U;
+ const uint64_t expected_handle = 0xfedcba9876543210ULL;
+ uint64_t handle = 0;
+
+ expect_ffa_mem_lend_rxtx(total_length, fragment_length,
+ &expected_handle, result);
+ LONGS_EQUAL(result,
+ ffa_mem_lend_rxtx(total_length, fragment_length, &handle));
+ UNSIGNED_LONGLONGS_EQUAL(expected_handle, handle);
+}
+
+TEST(mock_ffa_api, ffa_mem_share)
+{
+ const uint32_t total_length = 0x12345678U;
+ const uint32_t fragment_length = 0x23456789U;
+ const char buffer = 0;
+ const uint32_t page_count = 0x3456789au;
+ const uint64_t expected_handle = 0xfedcba9876543210ULL;
+ uint64_t handle = 0;
+
+ expect_ffa_mem_share(total_length, fragment_length, (void *)&buffer,
+ page_count, &expected_handle, result);
+ LONGS_EQUAL(result,
+ ffa_mem_share(total_length, fragment_length,
+ (void *)&buffer, page_count, &handle));
+ UNSIGNED_LONGLONGS_EQUAL(expected_handle, handle);
+}
+
+TEST(mock_ffa_api, ffa_mem_share_rxtx)
+{
+ const uint32_t total_length = 0x12345678U;
+ const uint32_t fragment_length = 0x23456789U;
+ const uint64_t expected_handle = 0xfedcba9876543210ULL;
+ uint64_t handle = 0;
+
+ expect_ffa_mem_share_rxtx(total_length, fragment_length,
+ &expected_handle, result);
+ LONGS_EQUAL(result,
+ ffa_mem_share_rxtx(total_length, fragment_length, &handle));
+ UNSIGNED_LONGLONGS_EQUAL(expected_handle, handle);
+}
+
+TEST(mock_ffa_api, ffa_mem_retrieve_req)
+{
+ const uint32_t total_length = 0x12345678U;
+ const uint32_t fragment_length = 0x23456789U;
+ const char buffer = 0;
+ const uint32_t page_count = 0x3456789aU;
+ const uint32_t expected_resp_total_length = 0xfedcba98U;
+ const uint32_t expected_resp_fragment_length = 0xedcba987U;
+ uint32_t resp_total_length = 0;
+ uint32_t resp_fragment_length = 0;
+
+ expect_ffa_mem_retrieve_req(total_length, fragment_length,
+ (void *)&buffer, page_count,
+ &expected_resp_total_length,
+ &expected_resp_fragment_length, result);
+ LONGS_EQUAL(result, ffa_mem_retrieve_req(total_length, fragment_length,
+ (void *)&buffer, page_count,
+ &resp_total_length,
+ &resp_fragment_length));
+ UNSIGNED_LONGS_EQUAL(expected_resp_total_length, resp_total_length);
+ UNSIGNED_LONGS_EQUAL(expected_resp_fragment_length,
+ resp_fragment_length);
+}
+
+TEST(mock_ffa_api, ffa_mem_retrieve_req_rxtx)
+{
+ const uint32_t total_length = 0x12345678U;
+ const uint32_t fragment_length = 0x23456789U;
+ const uint32_t expected_resp_total_length = 0xfedcba98U;
+ const uint32_t expected_resp_fragment_length = 0xedcba987U;
+ uint32_t resp_total_length = 0;
+ uint32_t resp_fragment_length = 0;
+
+ expect_ffa_mem_retrieve_req_rxtx(total_length, fragment_length,
+ &expected_resp_total_length,
+ &expected_resp_fragment_length,
+ result);
+ LONGS_EQUAL(result, ffa_mem_retrieve_req_rxtx(
+ total_length, fragment_length,
+ &resp_total_length, &resp_fragment_length));
+ UNSIGNED_LONGS_EQUAL(expected_resp_total_length, resp_total_length);
+ UNSIGNED_LONGS_EQUAL(expected_resp_fragment_length,
+ resp_fragment_length);
+}
+
+TEST(mock_ffa_api, ffa_mem_relinquish)
+{
+ expect_ffa_mem_relinquish(result);
+ LONGS_EQUAL(result, ffa_mem_relinquish());
+}
+
+TEST(mock_ffa_api, ffa_mem_reclaim)
+{
+ const uint64_t handle = 0xfedcba9876543210ULL;
+ const uint32_t flags = 0xaaccbbddU;
+
+ expect_ffa_mem_reclaim(handle, flags, result);
+ LONGS_EQUAL(result, ffa_mem_reclaim(handle, flags));
+}
+
+TEST(mock_ffa_api, ffa_mem_perm_get)
+{
+ const void *base_address = (const void *)0x01234567;
+ uint32_t expected_mem_perm = 0x89abcdef;
+ uint32_t mem_perm = 0;
+
+ expect_ffa_mem_perm_get(base_address, &expected_mem_perm, result);
+ LONGS_EQUAL(result, ffa_mem_perm_get(base_address, &mem_perm));
+ UNSIGNED_LONGS_EQUAL(expected_mem_perm, mem_perm);
+}
+
+TEST(mock_ffa_api, ffa_mem_perm_set)
+{
+ const void *base_address = (const void *)0x01234567;
+ const uint32_t page_count = 0x76543210;
+ const uint32_t mem_perm = 0x89abcdef;
+
+ expect_ffa_mem_perm_set(base_address, page_count, mem_perm, result);
+ LONGS_EQUAL(result, ffa_mem_perm_set(base_address, page_count, mem_perm));
+}
diff --git a/components/messaging/ffa/libsp/mock/test/test_mock_ffa_internal_api.cpp b/components/messaging/ffa/libsp/mock/test/test_mock_ffa_internal_api.cpp
new file mode 100644
index 0000000..ca07606
--- /dev/null
+++ b/components/messaging/ffa/libsp/mock/test/test_mock_ffa_internal_api.cpp
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+ */
+
+#include <CppUTest/TestHarness.h>
+#include <CppUTestExt/MockSupport.h>
+#include <stdint.h>
+#include "mock_ffa_internal_api.h"
+
+TEST_GROUP(mock_ffa_internal_api)
+{
+ TEST_TEARDOWN()
+ {
+ mock().checkExpectations();
+ mock().clear();
+ }
+};
+
+TEST(mock_ffa_internal_api, ffa_svc)
+{
+ const uint64_t a0 = 0x0123456789abcdefULL;
+ const uint64_t a1 = 0x123456789abcdef0ULL;
+ const uint64_t a2 = 0x23456789abcdef01ULL;
+ const uint64_t a3 = 0x3456789abcdef012ULL;
+ const uint64_t a4 = 0x456789abcdef0123ULL;
+ const uint64_t a5 = 0x56789abcdef01234ULL;
+ const uint64_t a6 = 0x6789abcdef012345ULL;
+ const uint64_t a7 = 0x789abcdef0123456ULL;
+ const struct ffa_params expect_result = {
+ a7, a6, a5, a4, a3, a2, a1, a0
+ };
+ struct ffa_params result = { 0 };
+
+ expect_ffa_svc(a0, a1, a2, a3, a4, a5, a6, a7, &expect_result);
+ ffa_svc(a0, a1, a2, a3, a4, a5, a6, a7, &result);
+
+ MEMCMP_EQUAL(&expect_result, &result, sizeof(result));
+}
diff --git a/components/messaging/ffa/libsp/mock/test/test_mock_sp_rxtx.cpp b/components/messaging/ffa/libsp/mock/test/test_mock_sp_rxtx.cpp
new file mode 100644
index 0000000..66f1f84
--- /dev/null
+++ b/components/messaging/ffa/libsp/mock/test/test_mock_sp_rxtx.cpp
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2021, Arm Limited. All rights reserved.
+ */
+
+#include <CppUTestExt/MockSupport.h>
+#include <CppUTest/TestHarness.h>
+#include "mock_sp_rxtx.h"
+#include <stdint.h>
+#include <stdlib.h>
+
+static uint8_t tx_buf[16] = { 0 };
+static const uint8_t rx_buf[16] = { 0 };
+
+static void *expected_tx_buffer = tx_buf;
+static const void *expected_rx_buffer = rx_buf;
+static size_t expected_size = 1234;
+
+TEST_GROUP(mock_sp_rxtx)
+{
+ TEST_TEARDOWN()
+ {
+ mock().checkExpectations();
+ mock().clear();
+ }
+
+ static const sp_result result = -1;
+};
+
+TEST(mock_sp_rxtx, sp_rxtx_buffer_map)
+{
+ expect_sp_rxtx_buffer_map(expected_tx_buffer, expected_rx_buffer,
+ expected_size, result);
+ LONGS_EQUAL(result,
+ sp_rxtx_buffer_map(expected_tx_buffer, expected_rx_buffer,
+ expected_size));
+}
+
+TEST(mock_sp_rxtx, sp_rxtx_buffer_unmap)
+{
+ expect_sp_rxtx_buffer_unmap(result);
+ LONGS_EQUAL(result, sp_rxtx_buffer_unmap());
+}
+
+TEST(mock_sp_rxtx, sp_rxtx_buffer_alignment_boundary_get)
+{
+ const uintptr_t expected_alignment = 4096;
+ uintptr_t alignment = 0;
+
+ expect_sp_rxtx_buffer_alignment_boundary_get(&expected_alignment,
+ result);
+ LONGS_EQUAL(result, sp_rxtx_buffer_alignment_boundary_get(&alignment));
+ UNSIGNED_LONGLONGS_EQUAL(expected_alignment, alignment);
+}
+
+TEST(mock_sp_rxtx, sp_rxtx_buffer_rx_get)
+{
+ const void *buffer = NULL;
+ size_t size = 0;
+
+ expect_sp_rxtx_buffer_rx_get(&expected_rx_buffer, &expected_size,
+ result);
+ LONGS_EQUAL(result, sp_rxtx_buffer_rx_get(&buffer, &size));
+ POINTERS_EQUAL(expected_rx_buffer, buffer);
+ UNSIGNED_LONGLONGS_EQUAL(expected_size, size);
+}
+
+TEST(mock_sp_rxtx, sp_rxtx_buffer_tx_get)
+{
+ void *buffer = NULL;
+ size_t size = 0;
+
+ expect_sp_rxtx_buffer_tx_get((void **)&expected_tx_buffer,
+ &expected_size, result);
+ LONGS_EQUAL(result, sp_rxtx_buffer_tx_get(&buffer, &size));
+ POINTERS_EQUAL(expected_tx_buffer, buffer);
+ UNSIGNED_LONGLONGS_EQUAL(expected_size, size);
+}