aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorImre Kis <imre.kis@arm.com>2021-01-12 22:10:07 +0100
committerGy├Ârgy Szing <gyorgy.szing@arm.com>2021-02-02 10:00:13 +0000
commit4844cff1113d3eeb7654f4c5a10f2e74eb55bf85 (patch)
treee9e53341ca6dd07d52a7f21dfd3c796492219311
parent29d775367c5ed5749895d8842ef0d2009c76bb6d (diff)
downloadtrusted-services-4844cff1113d3eeb7654f4c5a10f2e74eb55bf85.tar.gz
libsp: Add ffa_api.h mock implementation
Enables SP layer tests to expect and validate FF-A layer calls. Signed-off-by: Imre Kis <imre.kis@arm.com> Change-Id: I4cb45c73574d26c7eebfc1f1328c98354346d3ef
-rw-r--r--components/messaging/ffa/libsp/test/mock_ffa_api.cpp453
-rw-r--r--components/messaging/ffa/libsp/test/mock_ffa_api.h83
-rw-r--r--components/messaging/ffa/libsp/test/test_mock_ffa_api.cpp292
-rw-r--r--components/messaging/ffa/libsp/tests.cmake12
4 files changed, 840 insertions, 0 deletions
diff --git a/components/messaging/ffa/libsp/test/mock_ffa_api.cpp b/components/messaging/ffa/libsp/test/mock_ffa_api.cpp
new file mode 100644
index 0000000..cf04c1b
--- /dev/null
+++ b/components/messaging/ffa/libsp/test/mock_ffa_api.cpp
@@ -0,0 +1,453 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2020-2021, 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();
+}
diff --git a/components/messaging/ffa/libsp/test/mock_ffa_api.h b/components/messaging/ffa/libsp/test/mock_ffa_api.h
new file mode 100644
index 0000000..34a635c
--- /dev/null
+++ b/components/messaging/ffa/libsp/test/mock_ffa_api.h
@@ -0,0 +1,83 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (c) 2020-2021, 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);
+
+#endif /* FFA_LIBSP_TEST_MOCK_FFA_API_H_ */
diff --git a/components/messaging/ffa/libsp/test/test_mock_ffa_api.cpp b/components/messaging/ffa/libsp/test/test_mock_ffa_api.cpp
new file mode 100644
index 0000000..15b266a
--- /dev/null
+++ b/components/messaging/ffa/libsp/test/test_mock_ffa_api.cpp
@@ -0,0 +1,292 @@
+// 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_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));
+}
diff --git a/components/messaging/ffa/libsp/tests.cmake b/components/messaging/ffa/libsp/tests.cmake
index a176811..1d0b0a5 100644
--- a/components/messaging/ffa/libsp/tests.cmake
+++ b/components/messaging/ffa/libsp/tests.cmake
@@ -45,3 +45,15 @@ unit_test_add_suite(
COMPILE_DEFINITIONS
-DARM64
)
+
+unit_test_add_suite(
+ NAME libsp_mock_ffa_api
+ SOURCES
+ ${CMAKE_CURRENT_LIST_DIR}/test/test_mock_ffa_api.cpp
+ ${CMAKE_CURRENT_LIST_DIR}/test/mock_ffa_api.cpp
+ INCLUDE_DIRECTORIES
+ ${CMAKE_CURRENT_LIST_DIR}/include/
+ ${PROJECT_PATH}/components/common/utils/include
+ COMPILE_DEFINITIONS
+ -DARM64
+)