diff options
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 000000000..56b82d89a --- /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 000000000..d7068960e --- /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 000000000..ca0760665 --- /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 f140b6044..77153ffd2 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 +) + |