| From e9ff55c03e06c044eb9c13f2a3315bf7e35f3659 Mon Sep 17 00:00:00 2001 |
| From: Imre Kis <imre.kis@arm.com> |
| Date: Fri, 17 Jun 2022 13:51:21 +0200 |
| Subject: [PATCH 18/24] Add mock for libsp/sp_discovery |
| |
| Add mock_sp_discovery for mocking sp_discovery part of libsp. |
| |
| Signed-off-by: Imre Kis <imre.kis@arm.com> |
| Change-Id: I94460dc03dd6dcd27f6865f852cc9a0d85f4b583 |
| |
| Upstream-Status: Pending [In review] |
| Signed-off-by: Anton Antonov <Anton.Antonov@arm.com> |
| |
| --- |
| .../messaging/ffa/libsp/mock/component.cmake | 1 + |
| .../ffa/libsp/mock/mock_sp_discovery.cpp | 109 +++++++++++++++++ |
| .../ffa/libsp/mock/mock_sp_discovery.h | 37 ++++++ |
| .../mock/test/test_mock_sp_discovery.cpp | 111 ++++++++++++++++++ |
| components/messaging/ffa/libsp/tests.cmake | 13 ++ |
| 5 files changed, 271 insertions(+) |
| create mode 100644 components/messaging/ffa/libsp/mock/mock_sp_discovery.cpp |
| create mode 100644 components/messaging/ffa/libsp/mock/mock_sp_discovery.h |
| create mode 100644 components/messaging/ffa/libsp/mock/test/test_mock_sp_discovery.cpp |
| |
| diff --git a/components/messaging/ffa/libsp/mock/component.cmake b/components/messaging/ffa/libsp/mock/component.cmake |
| index 03b8006..15db85a 100644 |
| --- a/components/messaging/ffa/libsp/mock/component.cmake |
| +++ b/components/messaging/ffa/libsp/mock/component.cmake |
| @@ -12,6 +12,7 @@ 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_discovery.cpp" |
| "${CMAKE_CURRENT_LIST_DIR}/mock_sp_rxtx.cpp" |
| ) |
| |
| diff --git a/components/messaging/ffa/libsp/mock/mock_sp_discovery.cpp b/components/messaging/ffa/libsp/mock/mock_sp_discovery.cpp |
| new file mode 100644 |
| index 0000000..47f4ef7 |
| --- /dev/null |
| +++ b/components/messaging/ffa/libsp/mock/mock_sp_discovery.cpp |
| @@ -0,0 +1,109 @@ |
| +// SPDX-License-Identifier: BSD-3-Clause |
| +/* |
| + * Copyright (c) 2022, Arm Limited. All rights reserved. |
| + */ |
| + |
| +#include <CppUTestExt/MockSupport.h> |
| +#include "mock_sp_discovery.h" |
| + |
| +void expect_sp_discovery_ffa_version_get(const uint16_t *major, |
| + const uint16_t *minor, |
| + sp_result result) |
| +{ |
| + mock() |
| + .expectOneCall("sp_discovery_ffa_version_get") |
| + .withOutputParameterReturning("major", major, sizeof(*major)) |
| + .withOutputParameterReturning("minor", minor, sizeof(*minor)) |
| + .andReturnValue(result); |
| +} |
| + |
| +sp_result sp_discovery_ffa_version_get(uint16_t *major, uint16_t *minor) |
| +{ |
| + return mock() |
| + .actualCall("sp_discovery_ffa_version_get") |
| + .withOutputParameter("major", major) |
| + .withOutputParameter("minor", minor) |
| + .returnIntValue(); |
| +} |
| + |
| +void expect_sp_discovery_own_id_get(const uint16_t *id, sp_result result) |
| +{ |
| + mock() |
| + .expectOneCall("sp_discovery_own_id_get") |
| + .withOutputParameterReturning("id", id, sizeof(*id)) |
| + .andReturnValue(result); |
| +} |
| + |
| +sp_result sp_discovery_own_id_get(uint16_t *id) |
| +{ |
| + return mock() |
| + .actualCall("sp_discovery_own_id_get") |
| + .withOutputParameter("id", id) |
| + .returnIntValue(); |
| +} |
| + |
| +void expect_sp_discovery_partition_id_get(const struct sp_uuid *uuid, |
| + const uint16_t *id, sp_result result) |
| +{ |
| + mock() |
| + .expectOneCall("sp_discovery_partition_id_get") |
| + .withMemoryBufferParameter("uuid", (const unsigned char *)uuid, |
| + sizeof(*uuid)) |
| + .withOutputParameterReturning("id", id, sizeof(*id)) |
| + .andReturnValue(result); |
| +} |
| + |
| +sp_result sp_discovery_partition_id_get(const struct sp_uuid *uuid, |
| + uint16_t *id) |
| +{ |
| + return mock() |
| + .actualCall("sp_discovery_partition_id_get") |
| + .withMemoryBufferParameter("uuid", (const unsigned char *)uuid, |
| + sizeof(*uuid)) |
| + .withOutputParameter("id", id) |
| + .returnIntValue(); |
| +} |
| + |
| +void expect_sp_discovery_partition_info_get(const struct sp_uuid *uuid, |
| + const struct sp_partition_info *info, |
| + sp_result result) |
| +{ |
| + mock() |
| + .expectOneCall("sp_discovery_partition_info_get") |
| + .withMemoryBufferParameter("uuid", (const unsigned char *)uuid, |
| + sizeof(*uuid)) |
| + .withOutputParameterReturning("info", info, sizeof(*info)) |
| + .andReturnValue(result); |
| +} |
| + |
| +sp_result sp_discovery_partition_info_get(const struct sp_uuid *uuid, |
| + struct sp_partition_info *info) |
| +{ |
| + return mock() |
| + .actualCall("sp_discovery_partition_info_get") |
| + .withMemoryBufferParameter("uuid", (const unsigned char *)uuid, |
| + sizeof(*uuid)) |
| + .withOutputParameter("info", info) |
| + .returnIntValue(); |
| +} |
| + |
| +void expect_sp_discovery_partition_info_get_all(const struct sp_partition_info info[], |
| + const uint32_t *count, |
| + sp_result result) |
| +{ |
| + mock() |
| + .expectOneCall("sp_discovery_partition_info_get_all") |
| + .withOutputParameterReturning("info", info, sizeof(*info) * *count) |
| + .withOutputParameterReturning("count", count, sizeof(*count)) |
| + .andReturnValue(result); |
| +} |
| + |
| +sp_result sp_discovery_partition_info_get_all(struct sp_partition_info info[], |
| + uint32_t *count) |
| +{ |
| + return mock() |
| + .actualCall("sp_discovery_partition_info_get_all") |
| + .withOutputParameter("info", info) |
| + .withOutputParameter("count", count) |
| + .returnIntValue(); |
| +} |
| diff --git a/components/messaging/ffa/libsp/mock/mock_sp_discovery.h b/components/messaging/ffa/libsp/mock/mock_sp_discovery.h |
| new file mode 100644 |
| index 0000000..a71ce18 |
| --- /dev/null |
| +++ b/components/messaging/ffa/libsp/mock/mock_sp_discovery.h |
| @@ -0,0 +1,37 @@ |
| +/* SPDX-License-Identifier: BSD-3-Clause */ |
| +/* |
| + * Copyright (c) 2022, Arm Limited and Contributors. All rights reserved. |
| + */ |
| + |
| +#ifndef LIBSP_MOCK_MOCK_SP_DISCOVERY_H_ |
| +#define LIBSP_MOCK_MOCK_SP_DISCOVERY_H_ |
| + |
| +#include "../include/sp_discovery.h" |
| + |
| +#ifdef __cplusplus |
| +extern "C" { |
| +#endif |
| + |
| +void expect_sp_discovery_ffa_version_get(const uint16_t *major, |
| + const uint16_t *minor, |
| + sp_result result); |
| + |
| +void expect_sp_discovery_own_id_get(const uint16_t *id, sp_result result); |
| + |
| +void expect_sp_discovery_partition_id_get(const struct sp_uuid *uuid, |
| + const uint16_t *id, sp_result result); |
| + |
| + |
| +void expect_sp_discovery_partition_info_get(const struct sp_uuid *uuid, |
| + const struct sp_partition_info *info, |
| + sp_result result); |
| + |
| +void expect_sp_discovery_partition_info_get_all(const struct sp_partition_info info[], |
| + const uint32_t *count, |
| + sp_result result); |
| + |
| +#ifdef __cplusplus |
| +} |
| +#endif |
| + |
| +#endif /* LIBSP_MOCK_MOCK_SP_DISCOVERY_H_ */ |
| diff --git a/components/messaging/ffa/libsp/mock/test/test_mock_sp_discovery.cpp b/components/messaging/ffa/libsp/mock/test/test_mock_sp_discovery.cpp |
| new file mode 100644 |
| index 0000000..bb4bf07 |
| --- /dev/null |
| +++ b/components/messaging/ffa/libsp/mock/test/test_mock_sp_discovery.cpp |
| @@ -0,0 +1,111 @@ |
| +// SPDX-License-Identifier: BSD-3-Clause |
| +/* |
| + * Copyright (c) 2022, Arm Limited. All rights reserved. |
| + */ |
| + |
| +#include <CppUTestExt/MockSupport.h> |
| +#include <CppUTest/TestHarness.h> |
| +#include "mock_sp_discovery.h" |
| +#include <stdint.h> |
| +#include <stdlib.h> |
| + |
| + |
| + |
| + |
| +TEST_GROUP(mock_sp_discovery) { |
| + TEST_TEARDOWN() |
| + { |
| + mock().checkExpectations(); |
| + mock().clear(); |
| + } |
| + |
| + static const sp_result result = -1; |
| +}; |
| + |
| +TEST(mock_sp_discovery, sp_discovery_ffa_version_get) |
| +{ |
| + const uint16_t expected_major = 0xabcd; |
| + const uint16_t expected_minor = 0xef01; |
| + uint16_t major = 0, minor = 0; |
| + |
| + expect_sp_discovery_ffa_version_get(&expected_major, &expected_minor, |
| + result); |
| + LONGS_EQUAL(result, sp_discovery_ffa_version_get(&major, &minor)); |
| + UNSIGNED_LONGS_EQUAL(expected_major, major); |
| + UNSIGNED_LONGS_EQUAL(expected_minor, minor); |
| +} |
| + |
| +TEST(mock_sp_discovery, sp_discovery_own_id_get) |
| +{ |
| + const uint16_t expected_id = 0x8765; |
| + uint16_t id = 0; |
| + |
| + expect_sp_discovery_own_id_get(&expected_id, result); |
| + LONGS_EQUAL(result, sp_discovery_own_id_get(&id)); |
| + UNSIGNED_LONGS_EQUAL(expected_id, id); |
| +} |
| + |
| +TEST(mock_sp_discovery, sp_discovery_partition_id_get) |
| +{ |
| + const struct sp_uuid expected_uuid = { |
| + .uuid = {0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, |
| + 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}}; |
| + const uint16_t expected_id = 0xc1ca; |
| + |
| + struct sp_uuid uuid = expected_uuid; |
| + uint16_t id = 0; |
| + |
| + expect_sp_discovery_partition_id_get(&expected_uuid, &expected_id, |
| + result); |
| + LONGS_EQUAL(result, sp_discovery_partition_id_get(&uuid, &id)); |
| + UNSIGNED_LONGS_EQUAL(expected_id, id); |
| +} |
| + |
| +TEST(mock_sp_discovery, sp_discovery_partition_info_get) |
| +{ |
| + const struct sp_uuid expected_uuid = { |
| + .uuid = {0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, |
| + 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}}; |
| + const struct sp_partition_info expected_info = { |
| + .partition_id = 0x1234, |
| + .execution_context_count = 0xffff, |
| + .supports_direct_requests = true, |
| + .can_send_direct_requests = true, |
| + .supports_indirect_requests = false |
| + }; |
| + |
| + struct sp_uuid uuid = expected_uuid; |
| + struct sp_partition_info info = {0}; |
| + |
| + expect_sp_discovery_partition_info_get(&expected_uuid, &expected_info, |
| + result); |
| + LONGS_EQUAL(result, sp_discovery_partition_info_get(&uuid, &info)); |
| + MEMCMP_EQUAL(&expected_info, &info, sizeof(&expected_info)); |
| +} |
| + |
| +TEST(mock_sp_discovery, sp_discovery_partition_info_get_all) |
| +{ |
| + const uint32_t expected_count = 2; |
| + const struct sp_partition_info expected_info[expected_count] = {{ |
| + .partition_id = 0x5678, |
| + .execution_context_count = 0x1111, |
| + .supports_direct_requests = false, |
| + .can_send_direct_requests = false, |
| + .supports_indirect_requests = true |
| + }, { |
| + .partition_id = 0x1234, |
| + .execution_context_count = 0xffff, |
| + .supports_direct_requests = true, |
| + .can_send_direct_requests = true, |
| + .supports_indirect_requests = false |
| + }}; |
| + |
| + struct sp_partition_info info[expected_count] = {0}; |
| + uint32_t count = 0; |
| + |
| + expect_sp_discovery_partition_info_get_all(expected_info, |
| + &expected_count, result); |
| + LONGS_EQUAL(result, sp_discovery_partition_info_get_all(info, &count)); |
| + MEMCMP_EQUAL(&expected_info, &info, sizeof(&expected_info)); |
| + UNSIGNED_LONGS_EQUAL(expected_count, count); |
| +} |
| \ No newline at end of file |
| diff --git a/components/messaging/ffa/libsp/tests.cmake b/components/messaging/ffa/libsp/tests.cmake |
| index 296ae46..7b52248 100644 |
| --- a/components/messaging/ffa/libsp/tests.cmake |
| +++ b/components/messaging/ffa/libsp/tests.cmake |
| @@ -104,6 +104,19 @@ unit_test_add_suite( |
| -DARM64 |
| ) |
| |
| +unit_test_add_suite( |
| + NAME libsp_mock_sp_discovery |
| + SOURCES |
| + ${CMAKE_CURRENT_LIST_DIR}/mock/test/test_mock_sp_discovery.cpp |
| + ${CMAKE_CURRENT_LIST_DIR}/mock/mock_sp_discovery.cpp |
| + INCLUDE_DIRECTORIES |
| + ${CMAKE_CURRENT_LIST_DIR}/include/ |
| + ${CMAKE_CURRENT_LIST_DIR}/mock |
| + ${UNIT_TEST_PROJECT_PATH}/components/common/utils/include |
| + COMPILE_DEFINITIONS |
| + -DARM64 |
| +) |
| + |
| unit_test_add_suite( |
| NAME libsp_sp_memory_management |
| SOURCES |
| -- |
| 2.17.1 |
| |