aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorImre Kis <imre.kis@arm.com>2021-01-12 22:11:08 +0100
committerGy├Ârgy Szing <gyorgy.szing@arm.com>2021-02-02 10:00:13 +0000
commita53ba37f33bb6b7cedf0ddb8dcf3c43a88842ecd (patch)
treece2c5a1dab2d200eb3a54c8b8c6dc0d8774dfebb
parent86ec34fc58a55a8f172e349c447acba55ff5a88d (diff)
downloadtrusted-services-a53ba37f33bb6b7cedf0ddb8dcf3c43a88842ecd.tar.gz
libsp: Add sp_rxtx.h mock implementation
Enabling the validation of SP layer RXTX calls from other SP layer modules or from user code. Signed-off-by: Imre Kis <imre.kis@arm.com> Change-Id: Ia08d5fc0e07a0f18a29c2cc3d8b30c63286954a8
-rw-r--r--components/messaging/ffa/libsp/test/mock_sp_rxtx.cpp90
-rw-r--r--components/messaging/ffa/libsp/test/mock_sp_rxtx.h31
-rw-r--r--components/messaging/ffa/libsp/test/test_mock_sp_rxtx.cpp78
-rw-r--r--components/messaging/ffa/libsp/tests.cmake12
4 files changed, 211 insertions, 0 deletions
diff --git a/components/messaging/ffa/libsp/test/mock_sp_rxtx.cpp b/components/messaging/ffa/libsp/test/mock_sp_rxtx.cpp
new file mode 100644
index 0000000..24111b8
--- /dev/null
+++ b/components/messaging/ffa/libsp/test/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/test/mock_sp_rxtx.h b/components/messaging/ffa/libsp/test/mock_sp_rxtx.h
new file mode 100644
index 0000000..c036d36
--- /dev/null
+++ b/components/messaging/ffa/libsp/test/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/test/test_mock_sp_rxtx.cpp b/components/messaging/ffa/libsp/test/test_mock_sp_rxtx.cpp
new file mode 100644
index 0000000..66f1f84
--- /dev/null
+++ b/components/messaging/ffa/libsp/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);
+}
diff --git a/components/messaging/ffa/libsp/tests.cmake b/components/messaging/ffa/libsp/tests.cmake
index bfa994f..200f8c0 100644
--- a/components/messaging/ffa/libsp/tests.cmake
+++ b/components/messaging/ffa/libsp/tests.cmake
@@ -70,3 +70,15 @@ unit_test_add_suite(
COMPILE_DEFINITIONS
-DARM64
)
+
+unit_test_add_suite(
+ NAME libsp_mock_sp_rxtx
+ SOURCES
+ ${CMAKE_CURRENT_LIST_DIR}/test/test_mock_sp_rxtx.cpp
+ ${CMAKE_CURRENT_LIST_DIR}/test/mock_sp_rxtx.cpp
+ INCLUDE_DIRECTORIES
+ ${CMAKE_CURRENT_LIST_DIR}/include/
+ ${PROJECT_PATH}/components/common/utils/include
+ COMPILE_DEFINITIONS
+ -DARM64
+)