aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorImre Kis <imre.kis@arm.com>2020-11-30 20:56:08 +0100
committerGy├Ârgy Szing <gyorgy.szing@arm.com>2021-02-02 10:00:13 +0000
commit18dfa71212ab673dc7cd975a400c254228baa156 (patch)
tree6eccc0fa24a596cf9cf5a2420ebcde00bdb55391
parent721104fedfac828690af6a318fb8d1d255f436b3 (diff)
downloadtrusted-services-18dfa71212ab673dc7cd975a400c254228baa156.tar.gz
libsp: Add ffa_internal_api.h mock implementation
ffa_svc calls can be expected from tests instead of real SVC calls to decouple platform dependency. Signed-off-by: Imre Kis <imre.kis@arm.com> Change-Id: I410a5576020871b65010e1f003ea57b73f19a71a
-rw-r--r--components/messaging/ffa/libsp/test/mock_ffa_internal_api.cpp39
-rw-r--r--components/messaging/ffa/libsp/test/mock_ffa_internal_api.h16
-rw-r--r--components/messaging/ffa/libsp/test/test_mock_ffa_internal_api.cpp39
-rw-r--r--components/messaging/ffa/libsp/tests.cmake13
4 files changed, 107 insertions, 0 deletions
diff --git a/components/messaging/ffa/libsp/test/mock_ffa_internal_api.cpp b/components/messaging/ffa/libsp/test/mock_ffa_internal_api.cpp
new file mode 100644
index 0000000..56b82d8
--- /dev/null
+++ b/components/messaging/ffa/libsp/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 "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/test/mock_ffa_internal_api.h b/components/messaging/ffa/libsp/test/mock_ffa_internal_api.h
new file mode 100644
index 0000000..d706896
--- /dev/null
+++ b/components/messaging/ffa/libsp/test/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/test/test_mock_ffa_internal_api.cpp b/components/messaging/ffa/libsp/test/test_mock_ffa_internal_api.cpp
new file mode 100644
index 0000000..ca07606
--- /dev/null
+++ b/components/messaging/ffa/libsp/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/tests.cmake b/components/messaging/ffa/libsp/tests.cmake
index f140b60..77153ff 100644
--- a/components/messaging/ffa/libsp/tests.cmake
+++ b/components/messaging/ffa/libsp/tests.cmake
@@ -17,3 +17,16 @@ unit_test_add_suite(
COMPILE_DEFINITIONS
-DARM64
)
+
+unit_test_add_suite(
+ NAME libsp_mock_ffa_internal_api
+ SOURCES
+ ${CMAKE_CURRENT_LIST_DIR}/test/mock_ffa_internal_api.cpp
+ ${CMAKE_CURRENT_LIST_DIR}/test/test_mock_ffa_internal_api.cpp
+ INCLUDE_DIRECTORIES
+ ${CMAKE_CURRENT_LIST_DIR}/include/
+ ${PROJECT_PATH}/components/common/utils/include
+ COMPILE_DEFINITIONS
+ -DARM64
+)
+