Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | From e9ff55c03e06c044eb9c13f2a3315bf7e35f3659 Mon Sep 17 00:00:00 2001 |
| 2 | From: Imre Kis <imre.kis@arm.com> |
| 3 | Date: Fri, 17 Jun 2022 13:51:21 +0200 |
| 4 | Subject: [PATCH 18/24] Add mock for libsp/sp_discovery |
| 5 | |
| 6 | Add mock_sp_discovery for mocking sp_discovery part of libsp. |
| 7 | |
| 8 | Signed-off-by: Imre Kis <imre.kis@arm.com> |
| 9 | Change-Id: I94460dc03dd6dcd27f6865f852cc9a0d85f4b583 |
| 10 | |
| 11 | Upstream-Status: Pending [In review] |
| 12 | Signed-off-by: Anton Antonov <Anton.Antonov@arm.com> |
| 13 | |
| 14 | --- |
| 15 | .../messaging/ffa/libsp/mock/component.cmake | 1 + |
| 16 | .../ffa/libsp/mock/mock_sp_discovery.cpp | 109 +++++++++++++++++ |
| 17 | .../ffa/libsp/mock/mock_sp_discovery.h | 37 ++++++ |
| 18 | .../mock/test/test_mock_sp_discovery.cpp | 111 ++++++++++++++++++ |
| 19 | components/messaging/ffa/libsp/tests.cmake | 13 ++ |
| 20 | 5 files changed, 271 insertions(+) |
| 21 | create mode 100644 components/messaging/ffa/libsp/mock/mock_sp_discovery.cpp |
| 22 | create mode 100644 components/messaging/ffa/libsp/mock/mock_sp_discovery.h |
| 23 | create mode 100644 components/messaging/ffa/libsp/mock/test/test_mock_sp_discovery.cpp |
| 24 | |
| 25 | diff --git a/components/messaging/ffa/libsp/mock/component.cmake b/components/messaging/ffa/libsp/mock/component.cmake |
| 26 | index 03b8006..15db85a 100644 |
| 27 | --- a/components/messaging/ffa/libsp/mock/component.cmake |
| 28 | +++ b/components/messaging/ffa/libsp/mock/component.cmake |
| 29 | @@ -12,6 +12,7 @@ target_sources(${TGT} PRIVATE |
| 30 | "${CMAKE_CURRENT_LIST_DIR}/mock_assert.cpp" |
| 31 | "${CMAKE_CURRENT_LIST_DIR}/mock_ffa_api.cpp" |
| 32 | "${CMAKE_CURRENT_LIST_DIR}/mock_ffa_internal_api.cpp" |
| 33 | + "${CMAKE_CURRENT_LIST_DIR}/mock_sp_discovery.cpp" |
| 34 | "${CMAKE_CURRENT_LIST_DIR}/mock_sp_rxtx.cpp" |
| 35 | ) |
| 36 | |
| 37 | diff --git a/components/messaging/ffa/libsp/mock/mock_sp_discovery.cpp b/components/messaging/ffa/libsp/mock/mock_sp_discovery.cpp |
| 38 | new file mode 100644 |
| 39 | index 0000000..47f4ef7 |
| 40 | --- /dev/null |
| 41 | +++ b/components/messaging/ffa/libsp/mock/mock_sp_discovery.cpp |
| 42 | @@ -0,0 +1,109 @@ |
| 43 | +// SPDX-License-Identifier: BSD-3-Clause |
| 44 | +/* |
| 45 | + * Copyright (c) 2022, Arm Limited. All rights reserved. |
| 46 | + */ |
| 47 | + |
| 48 | +#include <CppUTestExt/MockSupport.h> |
| 49 | +#include "mock_sp_discovery.h" |
| 50 | + |
| 51 | +void expect_sp_discovery_ffa_version_get(const uint16_t *major, |
| 52 | + const uint16_t *minor, |
| 53 | + sp_result result) |
| 54 | +{ |
| 55 | + mock() |
| 56 | + .expectOneCall("sp_discovery_ffa_version_get") |
| 57 | + .withOutputParameterReturning("major", major, sizeof(*major)) |
| 58 | + .withOutputParameterReturning("minor", minor, sizeof(*minor)) |
| 59 | + .andReturnValue(result); |
| 60 | +} |
| 61 | + |
| 62 | +sp_result sp_discovery_ffa_version_get(uint16_t *major, uint16_t *minor) |
| 63 | +{ |
| 64 | + return mock() |
| 65 | + .actualCall("sp_discovery_ffa_version_get") |
| 66 | + .withOutputParameter("major", major) |
| 67 | + .withOutputParameter("minor", minor) |
| 68 | + .returnIntValue(); |
| 69 | +} |
| 70 | + |
| 71 | +void expect_sp_discovery_own_id_get(const uint16_t *id, sp_result result) |
| 72 | +{ |
| 73 | + mock() |
| 74 | + .expectOneCall("sp_discovery_own_id_get") |
| 75 | + .withOutputParameterReturning("id", id, sizeof(*id)) |
| 76 | + .andReturnValue(result); |
| 77 | +} |
| 78 | + |
| 79 | +sp_result sp_discovery_own_id_get(uint16_t *id) |
| 80 | +{ |
| 81 | + return mock() |
| 82 | + .actualCall("sp_discovery_own_id_get") |
| 83 | + .withOutputParameter("id", id) |
| 84 | + .returnIntValue(); |
| 85 | +} |
| 86 | + |
| 87 | +void expect_sp_discovery_partition_id_get(const struct sp_uuid *uuid, |
| 88 | + const uint16_t *id, sp_result result) |
| 89 | +{ |
| 90 | + mock() |
| 91 | + .expectOneCall("sp_discovery_partition_id_get") |
| 92 | + .withMemoryBufferParameter("uuid", (const unsigned char *)uuid, |
| 93 | + sizeof(*uuid)) |
| 94 | + .withOutputParameterReturning("id", id, sizeof(*id)) |
| 95 | + .andReturnValue(result); |
| 96 | +} |
| 97 | + |
| 98 | +sp_result sp_discovery_partition_id_get(const struct sp_uuid *uuid, |
| 99 | + uint16_t *id) |
| 100 | +{ |
| 101 | + return mock() |
| 102 | + .actualCall("sp_discovery_partition_id_get") |
| 103 | + .withMemoryBufferParameter("uuid", (const unsigned char *)uuid, |
| 104 | + sizeof(*uuid)) |
| 105 | + .withOutputParameter("id", id) |
| 106 | + .returnIntValue(); |
| 107 | +} |
| 108 | + |
| 109 | +void expect_sp_discovery_partition_info_get(const struct sp_uuid *uuid, |
| 110 | + const struct sp_partition_info *info, |
| 111 | + sp_result result) |
| 112 | +{ |
| 113 | + mock() |
| 114 | + .expectOneCall("sp_discovery_partition_info_get") |
| 115 | + .withMemoryBufferParameter("uuid", (const unsigned char *)uuid, |
| 116 | + sizeof(*uuid)) |
| 117 | + .withOutputParameterReturning("info", info, sizeof(*info)) |
| 118 | + .andReturnValue(result); |
| 119 | +} |
| 120 | + |
| 121 | +sp_result sp_discovery_partition_info_get(const struct sp_uuid *uuid, |
| 122 | + struct sp_partition_info *info) |
| 123 | +{ |
| 124 | + return mock() |
| 125 | + .actualCall("sp_discovery_partition_info_get") |
| 126 | + .withMemoryBufferParameter("uuid", (const unsigned char *)uuid, |
| 127 | + sizeof(*uuid)) |
| 128 | + .withOutputParameter("info", info) |
| 129 | + .returnIntValue(); |
| 130 | +} |
| 131 | + |
| 132 | +void expect_sp_discovery_partition_info_get_all(const struct sp_partition_info info[], |
| 133 | + const uint32_t *count, |
| 134 | + sp_result result) |
| 135 | +{ |
| 136 | + mock() |
| 137 | + .expectOneCall("sp_discovery_partition_info_get_all") |
| 138 | + .withOutputParameterReturning("info", info, sizeof(*info) * *count) |
| 139 | + .withOutputParameterReturning("count", count, sizeof(*count)) |
| 140 | + .andReturnValue(result); |
| 141 | +} |
| 142 | + |
| 143 | +sp_result sp_discovery_partition_info_get_all(struct sp_partition_info info[], |
| 144 | + uint32_t *count) |
| 145 | +{ |
| 146 | + return mock() |
| 147 | + .actualCall("sp_discovery_partition_info_get_all") |
| 148 | + .withOutputParameter("info", info) |
| 149 | + .withOutputParameter("count", count) |
| 150 | + .returnIntValue(); |
| 151 | +} |
| 152 | diff --git a/components/messaging/ffa/libsp/mock/mock_sp_discovery.h b/components/messaging/ffa/libsp/mock/mock_sp_discovery.h |
| 153 | new file mode 100644 |
| 154 | index 0000000..a71ce18 |
| 155 | --- /dev/null |
| 156 | +++ b/components/messaging/ffa/libsp/mock/mock_sp_discovery.h |
| 157 | @@ -0,0 +1,37 @@ |
| 158 | +/* SPDX-License-Identifier: BSD-3-Clause */ |
| 159 | +/* |
| 160 | + * Copyright (c) 2022, Arm Limited and Contributors. All rights reserved. |
| 161 | + */ |
| 162 | + |
| 163 | +#ifndef LIBSP_MOCK_MOCK_SP_DISCOVERY_H_ |
| 164 | +#define LIBSP_MOCK_MOCK_SP_DISCOVERY_H_ |
| 165 | + |
| 166 | +#include "../include/sp_discovery.h" |
| 167 | + |
| 168 | +#ifdef __cplusplus |
| 169 | +extern "C" { |
| 170 | +#endif |
| 171 | + |
| 172 | +void expect_sp_discovery_ffa_version_get(const uint16_t *major, |
| 173 | + const uint16_t *minor, |
| 174 | + sp_result result); |
| 175 | + |
| 176 | +void expect_sp_discovery_own_id_get(const uint16_t *id, sp_result result); |
| 177 | + |
| 178 | +void expect_sp_discovery_partition_id_get(const struct sp_uuid *uuid, |
| 179 | + const uint16_t *id, sp_result result); |
| 180 | + |
| 181 | + |
| 182 | +void expect_sp_discovery_partition_info_get(const struct sp_uuid *uuid, |
| 183 | + const struct sp_partition_info *info, |
| 184 | + sp_result result); |
| 185 | + |
| 186 | +void expect_sp_discovery_partition_info_get_all(const struct sp_partition_info info[], |
| 187 | + const uint32_t *count, |
| 188 | + sp_result result); |
| 189 | + |
| 190 | +#ifdef __cplusplus |
| 191 | +} |
| 192 | +#endif |
| 193 | + |
| 194 | +#endif /* LIBSP_MOCK_MOCK_SP_DISCOVERY_H_ */ |
| 195 | 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 |
| 196 | new file mode 100644 |
| 197 | index 0000000..bb4bf07 |
| 198 | --- /dev/null |
| 199 | +++ b/components/messaging/ffa/libsp/mock/test/test_mock_sp_discovery.cpp |
| 200 | @@ -0,0 +1,111 @@ |
| 201 | +// SPDX-License-Identifier: BSD-3-Clause |
| 202 | +/* |
| 203 | + * Copyright (c) 2022, Arm Limited. All rights reserved. |
| 204 | + */ |
| 205 | + |
| 206 | +#include <CppUTestExt/MockSupport.h> |
| 207 | +#include <CppUTest/TestHarness.h> |
| 208 | +#include "mock_sp_discovery.h" |
| 209 | +#include <stdint.h> |
| 210 | +#include <stdlib.h> |
| 211 | + |
| 212 | + |
| 213 | + |
| 214 | + |
| 215 | +TEST_GROUP(mock_sp_discovery) { |
| 216 | + TEST_TEARDOWN() |
| 217 | + { |
| 218 | + mock().checkExpectations(); |
| 219 | + mock().clear(); |
| 220 | + } |
| 221 | + |
| 222 | + static const sp_result result = -1; |
| 223 | +}; |
| 224 | + |
| 225 | +TEST(mock_sp_discovery, sp_discovery_ffa_version_get) |
| 226 | +{ |
| 227 | + const uint16_t expected_major = 0xabcd; |
| 228 | + const uint16_t expected_minor = 0xef01; |
| 229 | + uint16_t major = 0, minor = 0; |
| 230 | + |
| 231 | + expect_sp_discovery_ffa_version_get(&expected_major, &expected_minor, |
| 232 | + result); |
| 233 | + LONGS_EQUAL(result, sp_discovery_ffa_version_get(&major, &minor)); |
| 234 | + UNSIGNED_LONGS_EQUAL(expected_major, major); |
| 235 | + UNSIGNED_LONGS_EQUAL(expected_minor, minor); |
| 236 | +} |
| 237 | + |
| 238 | +TEST(mock_sp_discovery, sp_discovery_own_id_get) |
| 239 | +{ |
| 240 | + const uint16_t expected_id = 0x8765; |
| 241 | + uint16_t id = 0; |
| 242 | + |
| 243 | + expect_sp_discovery_own_id_get(&expected_id, result); |
| 244 | + LONGS_EQUAL(result, sp_discovery_own_id_get(&id)); |
| 245 | + UNSIGNED_LONGS_EQUAL(expected_id, id); |
| 246 | +} |
| 247 | + |
| 248 | +TEST(mock_sp_discovery, sp_discovery_partition_id_get) |
| 249 | +{ |
| 250 | + const struct sp_uuid expected_uuid = { |
| 251 | + .uuid = {0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 252 | + 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}}; |
| 253 | + const uint16_t expected_id = 0xc1ca; |
| 254 | + |
| 255 | + struct sp_uuid uuid = expected_uuid; |
| 256 | + uint16_t id = 0; |
| 257 | + |
| 258 | + expect_sp_discovery_partition_id_get(&expected_uuid, &expected_id, |
| 259 | + result); |
| 260 | + LONGS_EQUAL(result, sp_discovery_partition_id_get(&uuid, &id)); |
| 261 | + UNSIGNED_LONGS_EQUAL(expected_id, id); |
| 262 | +} |
| 263 | + |
| 264 | +TEST(mock_sp_discovery, sp_discovery_partition_info_get) |
| 265 | +{ |
| 266 | + const struct sp_uuid expected_uuid = { |
| 267 | + .uuid = {0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 268 | + 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}}; |
| 269 | + const struct sp_partition_info expected_info = { |
| 270 | + .partition_id = 0x1234, |
| 271 | + .execution_context_count = 0xffff, |
| 272 | + .supports_direct_requests = true, |
| 273 | + .can_send_direct_requests = true, |
| 274 | + .supports_indirect_requests = false |
| 275 | + }; |
| 276 | + |
| 277 | + struct sp_uuid uuid = expected_uuid; |
| 278 | + struct sp_partition_info info = {0}; |
| 279 | + |
| 280 | + expect_sp_discovery_partition_info_get(&expected_uuid, &expected_info, |
| 281 | + result); |
| 282 | + LONGS_EQUAL(result, sp_discovery_partition_info_get(&uuid, &info)); |
| 283 | + MEMCMP_EQUAL(&expected_info, &info, sizeof(&expected_info)); |
| 284 | +} |
| 285 | + |
| 286 | +TEST(mock_sp_discovery, sp_discovery_partition_info_get_all) |
| 287 | +{ |
| 288 | + const uint32_t expected_count = 2; |
| 289 | + const struct sp_partition_info expected_info[expected_count] = {{ |
| 290 | + .partition_id = 0x5678, |
| 291 | + .execution_context_count = 0x1111, |
| 292 | + .supports_direct_requests = false, |
| 293 | + .can_send_direct_requests = false, |
| 294 | + .supports_indirect_requests = true |
| 295 | + }, { |
| 296 | + .partition_id = 0x1234, |
| 297 | + .execution_context_count = 0xffff, |
| 298 | + .supports_direct_requests = true, |
| 299 | + .can_send_direct_requests = true, |
| 300 | + .supports_indirect_requests = false |
| 301 | + }}; |
| 302 | + |
| 303 | + struct sp_partition_info info[expected_count] = {0}; |
| 304 | + uint32_t count = 0; |
| 305 | + |
| 306 | + expect_sp_discovery_partition_info_get_all(expected_info, |
| 307 | + &expected_count, result); |
| 308 | + LONGS_EQUAL(result, sp_discovery_partition_info_get_all(info, &count)); |
| 309 | + MEMCMP_EQUAL(&expected_info, &info, sizeof(&expected_info)); |
| 310 | + UNSIGNED_LONGS_EQUAL(expected_count, count); |
| 311 | +} |
| 312 | \ No newline at end of file |
| 313 | diff --git a/components/messaging/ffa/libsp/tests.cmake b/components/messaging/ffa/libsp/tests.cmake |
| 314 | index 296ae46..7b52248 100644 |
| 315 | --- a/components/messaging/ffa/libsp/tests.cmake |
| 316 | +++ b/components/messaging/ffa/libsp/tests.cmake |
| 317 | @@ -104,6 +104,19 @@ unit_test_add_suite( |
| 318 | -DARM64 |
| 319 | ) |
| 320 | |
| 321 | +unit_test_add_suite( |
| 322 | + NAME libsp_mock_sp_discovery |
| 323 | + SOURCES |
| 324 | + ${CMAKE_CURRENT_LIST_DIR}/mock/test/test_mock_sp_discovery.cpp |
| 325 | + ${CMAKE_CURRENT_LIST_DIR}/mock/mock_sp_discovery.cpp |
| 326 | + INCLUDE_DIRECTORIES |
| 327 | + ${CMAKE_CURRENT_LIST_DIR}/include/ |
| 328 | + ${CMAKE_CURRENT_LIST_DIR}/mock |
| 329 | + ${UNIT_TEST_PROJECT_PATH}/components/common/utils/include |
| 330 | + COMPILE_DEFINITIONS |
| 331 | + -DARM64 |
| 332 | +) |
| 333 | + |
| 334 | unit_test_add_suite( |
| 335 | NAME libsp_sp_memory_management |
| 336 | SOURCES |
| 337 | -- |
| 338 | 2.17.1 |
| 339 | |