Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 1 | From b592a22dbce521522931f8e3d79d6e16f2d334fa Mon Sep 17 00:00:00 2001 |
| 2 | From: Imre Kis <imre.kis@arm.com> |
| 3 | Date: Fri, 17 Jun 2022 14:42:04 +0200 |
| 4 | Subject: [PATCH 19/24] Add mock for libsp/sp_memory_management |
| 5 | |
| 6 | Add mock_sp_memory_management for mocking sp_memory_management part of |
| 7 | libsp. |
| 8 | |
| 9 | Signed-off-by: Imre Kis <imre.kis@arm.com> |
| 10 | Change-Id: I9f74142bc3568dfc59f820ec2c2af81deba0d0da |
| 11 | |
| 12 | Upstream-Status: Pending [In review] |
| 13 | Signed-off-by: Anton Antonov <Anton.Antonov@arm.com> |
| 14 | |
| 15 | --- |
| 16 | .../ffa/libsp/include/sp_memory_management.h | 2 +- |
| 17 | .../messaging/ffa/libsp/mock/component.cmake | 1 + |
| 18 | .../libsp/mock/mock_sp_memory_management.cpp | 523 ++++++++++++++++++ |
| 19 | .../libsp/mock/mock_sp_memory_management.h | 98 ++++ |
| 20 | .../test/test_mock_sp_memory_management.cpp | 260 +++++++++ |
| 21 | components/messaging/ffa/libsp/tests.cmake | 13 + |
| 22 | 6 files changed, 896 insertions(+), 1 deletion(-) |
| 23 | create mode 100644 components/messaging/ffa/libsp/mock/mock_sp_memory_management.cpp |
| 24 | create mode 100644 components/messaging/ffa/libsp/mock/mock_sp_memory_management.h |
| 25 | create mode 100644 components/messaging/ffa/libsp/test/test_mock_sp_memory_management.cpp |
| 26 | |
| 27 | diff --git a/components/messaging/ffa/libsp/include/sp_memory_management.h b/components/messaging/ffa/libsp/include/sp_memory_management.h |
| 28 | index 58a6cc1..ec76a3d 100644 |
| 29 | --- a/components/messaging/ffa/libsp/include/sp_memory_management.h |
| 30 | +++ b/components/messaging/ffa/libsp/include/sp_memory_management.h |
| 31 | @@ -381,7 +381,7 @@ sp_result sp_memory_share_dynamic_is_supported(bool *supported); |
| 32 | * |
| 33 | * @param[in] descriptor The memory descriptor |
| 34 | * @param[in,out] acc_desc Access descriptor |
| 35 | - * @param[in,out regions Memory region array |
| 36 | + * @param[in,out] regions Memory region array |
| 37 | * @param[in] in_region_count Count of the specified regions, can be 0 |
| 38 | * @param[in,out] out_region_count Count of the reserved space of in the |
| 39 | * regions buffer for retrieved regions. After |
| 40 | diff --git a/components/messaging/ffa/libsp/mock/component.cmake b/components/messaging/ffa/libsp/mock/component.cmake |
| 41 | index 15db85a..eb0d28c 100644 |
| 42 | --- a/components/messaging/ffa/libsp/mock/component.cmake |
| 43 | +++ b/components/messaging/ffa/libsp/mock/component.cmake |
| 44 | @@ -13,6 +13,7 @@ target_sources(${TGT} PRIVATE |
| 45 | "${CMAKE_CURRENT_LIST_DIR}/mock_ffa_api.cpp" |
| 46 | "${CMAKE_CURRENT_LIST_DIR}/mock_ffa_internal_api.cpp" |
| 47 | "${CMAKE_CURRENT_LIST_DIR}/mock_sp_discovery.cpp" |
| 48 | + "${CMAKE_CURRENT_LIST_DIR}/mock_sp_memory_management.cpp" |
| 49 | "${CMAKE_CURRENT_LIST_DIR}/mock_sp_rxtx.cpp" |
| 50 | ) |
| 51 | |
| 52 | diff --git a/components/messaging/ffa/libsp/mock/mock_sp_memory_management.cpp b/components/messaging/ffa/libsp/mock/mock_sp_memory_management.cpp |
| 53 | new file mode 100644 |
| 54 | index 0000000..9eb0aaa |
| 55 | --- /dev/null |
| 56 | +++ b/components/messaging/ffa/libsp/mock/mock_sp_memory_management.cpp |
| 57 | @@ -0,0 +1,523 @@ |
| 58 | +// SPDX-License-Identifier: BSD-3-Clause |
| 59 | +/* |
| 60 | + * Copyright (c) 2022, Arm Limited. All rights reserved. |
| 61 | + */ |
| 62 | + |
| 63 | +#include <CppUTestExt/MockSupport.h> |
| 64 | +#include "mock_sp_memory_management.h" |
| 65 | + |
| 66 | +void expect_sp_memory_donate(const struct sp_memory_descriptor *descriptor, |
| 67 | + const struct sp_memory_access_descriptor *acc_desc, |
| 68 | + const struct sp_memory_region regions[], |
| 69 | + uint32_t region_count, const uint64_t *handle, |
| 70 | + sp_result result) |
| 71 | +{ |
| 72 | + mock() |
| 73 | + .expectOneCall("sp_memory_donate") |
| 74 | + .withMemoryBufferParameter("descriptor", (const unsigned char *)descriptor, |
| 75 | + sizeof(*descriptor)) |
| 76 | + .withMemoryBufferParameter("acc_desc", (const unsigned char *)acc_desc, |
| 77 | + sizeof(*acc_desc)) |
| 78 | + .withMemoryBufferParameter("regions", (const unsigned char *)regions, |
| 79 | + sizeof(*regions) * region_count) |
| 80 | + .withUnsignedIntParameter("region_count", region_count) |
| 81 | + .withOutputParameterReturning("handle", handle, sizeof(*handle)) |
| 82 | + .andReturnValue(result); |
| 83 | +} |
| 84 | + |
| 85 | +sp_result sp_memory_donate(struct sp_memory_descriptor *descriptor, |
| 86 | + struct sp_memory_access_descriptor *acc_desc, |
| 87 | + struct sp_memory_region regions[], |
| 88 | + uint32_t region_count, uint64_t *handle) |
| 89 | +{ |
| 90 | + return mock() |
| 91 | + .actualCall("sp_memory_donate") |
| 92 | + .withMemoryBufferParameter("descriptor", (const unsigned char *)descriptor, |
| 93 | + sizeof(*descriptor)) |
| 94 | + .withMemoryBufferParameter("acc_desc", (const unsigned char *)acc_desc, |
| 95 | + sizeof(*acc_desc)) |
| 96 | + .withMemoryBufferParameter("regions", (const unsigned char *)regions, |
| 97 | + sizeof(*regions) * region_count) |
| 98 | + .withUnsignedIntParameter("region_count", region_count) |
| 99 | + .withOutputParameter("handle", handle) |
| 100 | + .returnIntValue(); |
| 101 | +} |
| 102 | + |
| 103 | +void expect_sp_memory_donate_dynamic(const struct sp_memory_descriptor *descriptor, |
| 104 | + const struct sp_memory_access_descriptor *acc_desc, |
| 105 | + const struct sp_memory_region regions[], |
| 106 | + uint32_t region_count, const uint64_t *handle, |
| 107 | + sp_result result) |
| 108 | +{ |
| 109 | + mock() |
| 110 | + .expectOneCall("sp_memory_donate_dynamic") |
| 111 | + .withMemoryBufferParameter("descriptor", (const unsigned char *)descriptor, |
| 112 | + sizeof(*descriptor)) |
| 113 | + .withMemoryBufferParameter("acc_desc", (const unsigned char *)acc_desc, |
| 114 | + sizeof(*acc_desc)) |
| 115 | + .withMemoryBufferParameter("regions", (const unsigned char *)regions, |
| 116 | + sizeof(*regions) * region_count) |
| 117 | + .withUnsignedIntParameter("region_count", region_count) |
| 118 | + .withOutputParameterReturning("handle", handle, sizeof(*handle)) |
| 119 | + .andReturnValue(result); |
| 120 | +} |
| 121 | + |
| 122 | +sp_result sp_memory_donate_dynamic(struct sp_memory_descriptor *descriptor, |
| 123 | + struct sp_memory_access_descriptor *acc_desc, |
| 124 | + struct sp_memory_region regions[], |
| 125 | + uint32_t region_count, uint64_t *handle, |
| 126 | + struct ffa_mem_transaction_buffer *buffer) |
| 127 | +{ |
| 128 | + if (buffer == NULL) { // LCOV_EXCL_BR_LINE |
| 129 | + FAIL("ffa_mem_transaction_buffer is NULL"); // LCOV_EXCL_LINE |
| 130 | + } |
| 131 | + |
| 132 | + return mock() |
| 133 | + .actualCall("sp_memory_donate_dynamic") |
| 134 | + .withMemoryBufferParameter("descriptor", (const unsigned char *)descriptor, |
| 135 | + sizeof(*descriptor)) |
| 136 | + .withMemoryBufferParameter("acc_desc", (const unsigned char *)acc_desc, |
| 137 | + sizeof(*acc_desc)) |
| 138 | + .withMemoryBufferParameter("regions", (const unsigned char *)regions, |
| 139 | + sizeof(*regions) * region_count) |
| 140 | + .withUnsignedIntParameter("region_count", region_count) |
| 141 | + .withOutputParameter("handle", handle) |
| 142 | + .returnIntValue(); |
| 143 | +} |
| 144 | + |
| 145 | +void expect_sp_memory_donate_dynamic_is_supported(const bool *supported, sp_result result) |
| 146 | +{ |
| 147 | + mock() |
| 148 | + .expectOneCall("sp_memory_lend_dynamic_is_supported") |
| 149 | + .withOutputParameterReturning("supported", supported, sizeof(*supported)) |
| 150 | + .andReturnValue(result); |
| 151 | +} |
| 152 | + |
| 153 | +sp_result sp_memory_donate_dynamic_is_supported(bool *supported) |
| 154 | +{ |
| 155 | + return mock() |
| 156 | + .actualCall("sp_memory_lend_dynamic_is_supported") |
| 157 | + .withOutputParameter("supported", supported) |
| 158 | + .returnIntValue(); |
| 159 | +} |
| 160 | + |
| 161 | +void expect_sp_memory_lend(const struct sp_memory_descriptor *descriptor, |
| 162 | + const struct sp_memory_access_descriptor acc_desc[], |
| 163 | + uint32_t acc_desc_count, |
| 164 | + const struct sp_memory_region regions[], |
| 165 | + uint32_t region_count, const uint64_t *handle, |
| 166 | + sp_result result) |
| 167 | +{ |
| 168 | + mock() |
| 169 | + .expectOneCall("sp_memory_lend") |
| 170 | + .withMemoryBufferParameter("descriptor", (const unsigned char *)descriptor, |
| 171 | + sizeof(*descriptor)) |
| 172 | + .withMemoryBufferParameter("acc_desc", (const unsigned char *)acc_desc, |
| 173 | + sizeof(*acc_desc) * acc_desc_count) |
| 174 | + .withUnsignedIntParameter("acc_desc_count", acc_desc_count) |
| 175 | + .withMemoryBufferParameter("regions", (const unsigned char *)regions, |
| 176 | + sizeof(*regions) * region_count) |
| 177 | + .withUnsignedIntParameter("region_count", region_count) |
| 178 | + .withOutputParameterReturning("handle", handle, sizeof(*handle)) |
| 179 | + .andReturnValue(result); |
| 180 | +} |
| 181 | + |
| 182 | +sp_result sp_memory_lend(struct sp_memory_descriptor *descriptor, |
| 183 | + struct sp_memory_access_descriptor acc_desc[], |
| 184 | + uint32_t acc_desc_count, |
| 185 | + struct sp_memory_region regions[], |
| 186 | + uint32_t region_count, uint64_t *handle) |
| 187 | +{ |
| 188 | + return mock() |
| 189 | + .actualCall("sp_memory_lend") |
| 190 | + .withMemoryBufferParameter("descriptor", (const unsigned char *)descriptor, |
| 191 | + sizeof(*descriptor)) |
| 192 | + .withMemoryBufferParameter("acc_desc", (const unsigned char *)acc_desc, |
| 193 | + sizeof(*acc_desc) * acc_desc_count) |
| 194 | + .withUnsignedIntParameter("acc_desc_count", acc_desc_count) |
| 195 | + .withMemoryBufferParameter("regions", (const unsigned char *)regions, |
| 196 | + sizeof(*regions) * region_count) |
| 197 | + .withUnsignedIntParameter("region_count", region_count) |
| 198 | + .withOutputParameter("handle", handle) |
| 199 | + .returnIntValue(); |
| 200 | +} |
| 201 | + |
| 202 | +void expect_sp_memory_lend_dynamic(const struct sp_memory_descriptor *descriptor, |
| 203 | + const struct sp_memory_access_descriptor acc_desc[], |
| 204 | + uint32_t acc_desc_count, |
| 205 | + const struct sp_memory_region regions[], |
| 206 | + const uint32_t region_count, const uint64_t *handle, |
| 207 | + sp_result result) |
| 208 | +{ |
| 209 | + mock() |
| 210 | + .expectOneCall("sp_memory_lend") |
| 211 | + .withMemoryBufferParameter("descriptor", (const unsigned char *)descriptor, |
| 212 | + sizeof(*descriptor)) |
| 213 | + .withMemoryBufferParameter("acc_desc", (const unsigned char *)acc_desc, |
| 214 | + sizeof(*acc_desc) * acc_desc_count) |
| 215 | + .withUnsignedIntParameter("acc_desc_count", acc_desc_count) |
| 216 | + .withMemoryBufferParameter("regions", (const unsigned char *)regions, |
| 217 | + sizeof(*regions) * region_count) |
| 218 | + .withUnsignedIntParameter("region_count", region_count) |
| 219 | + .withOutputParameterReturning("handle", handle, sizeof(*handle)) |
| 220 | + .andReturnValue(result); |
| 221 | +} |
| 222 | + |
| 223 | +sp_result sp_memory_lend_dynamic(struct sp_memory_descriptor *descriptor, |
| 224 | + struct sp_memory_access_descriptor acc_desc[], |
| 225 | + uint32_t acc_desc_count, |
| 226 | + struct sp_memory_region regions[], |
| 227 | + uint32_t region_count, uint64_t *handle, |
| 228 | + struct ffa_mem_transaction_buffer *buffer) |
| 229 | +{ |
| 230 | + if (buffer == NULL) { // LCOV_EXCL_BR_LINE |
| 231 | + FAIL("ffa_mem_transaction_buffer is NULL"); // LCOV_EXCL_LINE |
| 232 | + } |
| 233 | + |
| 234 | + return mock() |
| 235 | + .actualCall("sp_memory_lend") |
| 236 | + .withMemoryBufferParameter("descriptor", (const unsigned char *)descriptor, |
| 237 | + sizeof(*descriptor)) |
| 238 | + .withMemoryBufferParameter("acc_desc", (const unsigned char *)acc_desc, |
| 239 | + sizeof(*acc_desc) * acc_desc_count) |
| 240 | + .withUnsignedIntParameter("acc_desc_count", acc_desc_count) |
| 241 | + .withMemoryBufferParameter("regions", (const unsigned char *)regions, |
| 242 | + sizeof(*regions) * region_count) |
| 243 | + .withUnsignedIntParameter("region_count", region_count) |
| 244 | + .withOutputParameter("handle", handle) |
| 245 | + .returnIntValue(); |
| 246 | +} |
| 247 | + |
| 248 | +void expect_sp_memory_lend_dynamic_is_supported(const bool *supported, sp_result result) |
| 249 | +{ |
| 250 | + mock() |
| 251 | + .expectOneCall("sp_memory_lend_dynamic_is_supported") |
| 252 | + .withOutputParameterReturning("supported", supported, sizeof(*supported)) |
| 253 | + .andReturnValue(result); |
| 254 | +} |
| 255 | + |
| 256 | +sp_result sp_memory_lend_dynamic_is_supported(bool *supported) |
| 257 | +{ |
| 258 | + return mock() |
| 259 | + .actualCall("sp_memory_lend_dynamic_is_supported") |
| 260 | + .withOutputParameter("supported", supported) |
| 261 | + .returnIntValue(); |
| 262 | +} |
| 263 | + |
| 264 | +void expect_sp_memory_share(const struct sp_memory_descriptor *descriptor, |
| 265 | + const struct sp_memory_access_descriptor acc_desc[], |
| 266 | + uint32_t acc_desc_count, |
| 267 | + const struct sp_memory_region regions[], |
| 268 | + uint32_t region_count, const uint64_t *handle, |
| 269 | + sp_result result) |
| 270 | +{ |
| 271 | + mock() |
| 272 | + .expectOneCall("sp_memory_share") |
| 273 | + .withMemoryBufferParameter("descriptor", (const unsigned char *)descriptor, |
| 274 | + sizeof(*descriptor)) |
| 275 | + .withMemoryBufferParameter("acc_desc", (const unsigned char *)acc_desc, |
| 276 | + sizeof(*acc_desc) * acc_desc_count) |
| 277 | + .withUnsignedIntParameter("acc_desc_count", acc_desc_count) |
| 278 | + .withMemoryBufferParameter("regions", (const unsigned char *)regions, |
| 279 | + sizeof(*regions) * region_count) |
| 280 | + .withUnsignedIntParameter("region_count", region_count) |
| 281 | + .withOutputParameterReturning("handle", handle, sizeof(*handle)) |
| 282 | + .andReturnValue(result); |
| 283 | +} |
| 284 | + |
| 285 | +sp_result sp_memory_share(struct sp_memory_descriptor *descriptor, |
| 286 | + struct sp_memory_access_descriptor acc_desc[], |
| 287 | + uint32_t acc_desc_count, |
| 288 | + struct sp_memory_region regions[], |
| 289 | + uint32_t region_count, uint64_t *handle) |
| 290 | +{ |
| 291 | + return mock() |
| 292 | + .actualCall("sp_memory_share") |
| 293 | + .withMemoryBufferParameter("descriptor", (const unsigned char *)descriptor, |
| 294 | + sizeof(*descriptor)) |
| 295 | + .withMemoryBufferParameter("acc_desc", (const unsigned char *)acc_desc, |
| 296 | + sizeof(*acc_desc) * acc_desc_count) |
| 297 | + .withUnsignedIntParameter("acc_desc_count", acc_desc_count) |
| 298 | + .withMemoryBufferParameter("regions", (const unsigned char *)regions, |
| 299 | + sizeof(*regions) * region_count) |
| 300 | + .withUnsignedIntParameter("region_count", region_count) |
| 301 | + .withOutputParameter("handle", handle) |
| 302 | + .returnIntValue(); |
| 303 | +} |
| 304 | + |
| 305 | +void expect_sp_memory_share_dynamic(const struct sp_memory_descriptor *descriptor, |
| 306 | + const struct sp_memory_access_descriptor acc_desc[], |
| 307 | + uint32_t acc_desc_count, |
| 308 | + const struct sp_memory_region regions[], |
| 309 | + uint32_t region_count, const uint64_t *handle, |
| 310 | + sp_result result) |
| 311 | +{ |
| 312 | + mock() |
| 313 | + .expectOneCall("sp_memory_share_dynamic") |
| 314 | + .withMemoryBufferParameter("descriptor", (const unsigned char *)descriptor, |
| 315 | + sizeof(*descriptor)) |
| 316 | + .withMemoryBufferParameter("acc_desc", (const unsigned char *)acc_desc, |
| 317 | + sizeof(*acc_desc) * acc_desc_count) |
| 318 | + .withUnsignedIntParameter("acc_desc_count", acc_desc_count) |
| 319 | + .withMemoryBufferParameter("regions", (const unsigned char *)regions, |
| 320 | + sizeof(*regions) * region_count) |
| 321 | + .withUnsignedIntParameter("region_count", region_count) |
| 322 | + .withOutputParameterReturning("handle", handle, sizeof(*handle)) |
| 323 | + .andReturnValue(result); |
| 324 | +} |
| 325 | + |
| 326 | +sp_result sp_memory_share_dynamic(struct sp_memory_descriptor *descriptor, |
| 327 | + struct sp_memory_access_descriptor acc_desc[], |
| 328 | + uint32_t acc_desc_count, |
| 329 | + struct sp_memory_region regions[], |
| 330 | + uint32_t region_count, uint64_t *handle, |
| 331 | + struct ffa_mem_transaction_buffer *buffer) |
| 332 | +{ |
| 333 | + if (buffer == NULL) { // LCOV_EXCL_BR_LINE |
| 334 | + FAIL("ffa_mem_transaction_buffer is NULL"); // LCOV_EXCL_LINE |
| 335 | + } |
| 336 | + |
| 337 | + return mock() |
| 338 | + .actualCall("sp_memory_share_dynamic") |
| 339 | + .withMemoryBufferParameter("descriptor", (const unsigned char *)descriptor, |
| 340 | + sizeof(*descriptor)) |
| 341 | + .withMemoryBufferParameter("acc_desc", (const unsigned char *)acc_desc, |
| 342 | + sizeof(*acc_desc) * acc_desc_count) |
| 343 | + .withUnsignedIntParameter("acc_desc_count", acc_desc_count) |
| 344 | + .withMemoryBufferParameter("regions", (const unsigned char *)regions, |
| 345 | + sizeof(*regions) * region_count) |
| 346 | + .withUnsignedIntParameter("region_count", region_count) |
| 347 | + .withOutputParameter("handle", handle) |
| 348 | + .returnIntValue(); |
| 349 | +} |
| 350 | + |
| 351 | +void expect_sp_memory_share_dynamic_is_supported(const bool *supported, sp_result result) |
| 352 | +{ |
| 353 | + mock() |
| 354 | + .expectOneCall("sp_memory_share_dynamic_is_supported") |
| 355 | + .withOutputParameterReturning("supported", supported, sizeof(*supported)) |
| 356 | + .andReturnValue(result); |
| 357 | +} |
| 358 | + |
| 359 | +sp_result sp_memory_share_dynamic_is_supported(bool *supported) |
| 360 | +{ |
| 361 | + return mock() |
| 362 | + .actualCall("sp_memory_share_dynamic_is_supported") |
| 363 | + .withOutputParameter("supported", supported) |
| 364 | + .returnIntValue(); |
| 365 | +} |
| 366 | + |
| 367 | +void expect_sp_memory_retrieve(const struct sp_memory_descriptor *descriptor, |
| 368 | + const struct sp_memory_access_descriptor *req_acc_desc, |
| 369 | + const struct sp_memory_access_descriptor *resp_acc_desc, |
| 370 | + const struct sp_memory_region in_regions[], |
| 371 | + const struct sp_memory_region out_regions[], |
| 372 | + uint32_t in_region_count, |
| 373 | + const uint32_t *out_region_count, uint64_t handle, |
| 374 | + sp_result result) |
| 375 | +{ |
| 376 | + mock() |
| 377 | + .expectOneCall("sp_memory_retrieve") |
| 378 | + .withMemoryBufferParameter("descriptor", (const unsigned char *)descriptor, |
| 379 | + sizeof(descriptor)) |
| 380 | + .withMemoryBufferParameter("req_acc_desc", (const unsigned char *)req_acc_desc, |
| 381 | + sizeof(*req_acc_desc)) |
| 382 | + .withOutputParameterReturning("resp_acc_desc", |
| 383 | + (const unsigned char *)resp_acc_desc, |
| 384 | + sizeof(*resp_acc_desc)) |
| 385 | + .withMemoryBufferParameter("in_regions", (const unsigned char *)in_regions, |
| 386 | + sizeof(*in_regions) * in_region_count) |
| 387 | + .withOutputParameterReturning("out_regions", out_regions, |
| 388 | + sizeof(*out_regions) * *out_region_count) |
| 389 | + .withUnsignedIntParameter("in_region_count", in_region_count) |
| 390 | + .withOutputParameterReturning("out_region_count", out_region_count, |
| 391 | + sizeof(*out_region_count)) |
| 392 | + .withUnsignedLongIntParameter("handle", handle) |
| 393 | + .andReturnValue(result); |
| 394 | + |
| 395 | +} |
| 396 | + |
| 397 | +sp_result sp_memory_retrieve(struct sp_memory_descriptor *descriptor, |
| 398 | + struct sp_memory_access_descriptor *acc_desc, |
| 399 | + struct sp_memory_region regions[], |
| 400 | + uint32_t in_region_count, |
| 401 | + uint32_t *out_region_count, uint64_t handle) |
| 402 | +{ |
| 403 | + return mock() |
| 404 | + .actualCall("sp_memory_retrieve") |
| 405 | + .withMemoryBufferParameter("descriptor", (const unsigned char *)descriptor, |
| 406 | + sizeof(descriptor)) |
| 407 | + .withMemoryBufferParameter("req_acc_desc", (const unsigned char *)acc_desc, |
| 408 | + sizeof(*acc_desc)) |
| 409 | + .withOutputParameter("resp_acc_desc", acc_desc) |
| 410 | + .withMemoryBufferParameter("in_regions", (const unsigned char *)regions, |
| 411 | + sizeof(*regions) * in_region_count) |
| 412 | + .withOutputParameter("out_regions", regions) |
| 413 | + .withUnsignedIntParameter("in_region_count", in_region_count) |
| 414 | + .withOutputParameter("out_region_count", out_region_count) |
| 415 | + .withUnsignedLongIntParameter("handle", handle) |
| 416 | + .returnIntValue(); |
| 417 | +} |
| 418 | + |
| 419 | +void expect_sp_memory_retrieve_dynamic(const struct sp_memory_descriptor *descriptor, |
| 420 | + const struct sp_memory_access_descriptor *req_acc_desc, |
| 421 | + const struct sp_memory_access_descriptor *resp_acc_desc, |
| 422 | + const struct sp_memory_region in_regions[], |
| 423 | + const struct sp_memory_region out_regions[], |
| 424 | + uint32_t in_region_count, |
| 425 | + const uint32_t *out_region_count, uint64_t handle, |
| 426 | + sp_result result) |
| 427 | +{ |
| 428 | + mock() |
| 429 | + .expectOneCall("sp_memory_retrieve") |
| 430 | + .withMemoryBufferParameter("descriptor", (const unsigned char *)descriptor, |
| 431 | + sizeof(descriptor)) |
| 432 | + .withMemoryBufferParameter("req_acc_desc", (const unsigned char *)req_acc_desc, |
| 433 | + sizeof(*req_acc_desc)) |
| 434 | + .withOutputParameterReturning("resp_acc_desc", |
| 435 | + (const unsigned char *)resp_acc_desc, |
| 436 | + sizeof(*resp_acc_desc)) |
| 437 | + .withMemoryBufferParameter("in_regions", (const unsigned char *)in_regions, |
| 438 | + sizeof(*in_regions) * in_region_count) |
| 439 | + .withOutputParameterReturning("out_regions", out_regions, |
| 440 | + sizeof(*out_regions) * *out_region_count) |
| 441 | + .withUnsignedIntParameter("in_region_count", in_region_count) |
| 442 | + .withOutputParameterReturning("out_region_count", out_region_count, |
| 443 | + sizeof(*out_region_count)) |
| 444 | + .withUnsignedLongIntParameter("handle", handle) |
| 445 | + .andReturnValue(result); |
| 446 | +} |
| 447 | + |
| 448 | +sp_result |
| 449 | +sp_memory_retrieve_dynamic(struct sp_memory_descriptor *descriptor, |
| 450 | + struct sp_memory_access_descriptor *acc_desc, |
| 451 | + struct sp_memory_region regions[], |
| 452 | + uint32_t in_region_count, uint32_t *out_region_count, |
| 453 | + uint64_t handle, |
| 454 | + struct ffa_mem_transaction_buffer *buffer) |
| 455 | +{ |
| 456 | + if (buffer == NULL) { // LCOV_EXCL_BR_LINE |
| 457 | + FAIL("ffa_mem_transaction_buffer is NULL"); // LCOV_EXCL_LINE |
| 458 | + } |
| 459 | + |
| 460 | + return mock() |
| 461 | + .actualCall("sp_memory_retrieve") |
| 462 | + .withMemoryBufferParameter("descriptor", (const unsigned char *)descriptor, |
| 463 | + sizeof(descriptor)) |
| 464 | + .withMemoryBufferParameter("req_acc_desc", (const unsigned char *)acc_desc, |
| 465 | + sizeof(*acc_desc)) |
| 466 | + .withOutputParameter("resp_acc_desc", acc_desc) |
| 467 | + .withMemoryBufferParameter("in_regions", (const unsigned char *)regions, |
| 468 | + sizeof(*regions) * in_region_count) |
| 469 | + .withOutputParameter("out_regions", regions) |
| 470 | + .withUnsignedIntParameter("in_region_count", in_region_count) |
| 471 | + .withOutputParameter("out_region_count", out_region_count) |
| 472 | + .withUnsignedLongIntParameter("handle", handle) |
| 473 | + .returnIntValue(); |
| 474 | +} |
| 475 | + |
| 476 | +void expect_sp_memory_retrieve_dynamic_is_supported(const bool *supported, sp_result result) |
| 477 | +{ |
| 478 | + mock() |
| 479 | + .expectOneCall("sp_memory_retrieve_dynamic_is_supported") |
| 480 | + .withOutputParameterReturning("supported", supported, sizeof(*supported)) |
| 481 | + .andReturnValue(result); |
| 482 | +} |
| 483 | + |
| 484 | +sp_result sp_memory_retrieve_dynamic_is_supported(bool *supported) |
| 485 | +{ |
| 486 | + return mock() |
| 487 | + .actualCall("sp_memory_retrieve_dynamic_is_supported") |
| 488 | + .withOutputParameter("supported", supported) |
| 489 | + .returnIntValue(); |
| 490 | +} |
| 491 | + |
| 492 | +void expect_sp_memory_relinquish(uint64_t handle, const uint16_t endpoints[], |
| 493 | + uint32_t endpoint_count, |
| 494 | + const struct sp_memory_transaction_flags *flags, |
| 495 | + sp_result result) |
| 496 | +{ |
| 497 | + mock() |
| 498 | + .expectOneCall("sp_memory_relinquish") |
| 499 | + .withUnsignedLongIntParameter("handle", handle) |
| 500 | + .withMemoryBufferParameter("endpoints", (const unsigned char *)endpoints, |
| 501 | + sizeof(*endpoints) * endpoint_count) |
| 502 | + .withMemoryBufferParameter("flags", (const unsigned char *)flags, sizeof(*flags)) |
| 503 | + .andReturnValue(result); |
| 504 | +} |
| 505 | + |
| 506 | +sp_result sp_memory_relinquish(uint64_t handle, const uint16_t endpoints[], |
| 507 | + uint32_t endpoint_count, |
| 508 | + struct sp_memory_transaction_flags *flags) |
| 509 | +{ |
| 510 | + return mock() |
| 511 | + .actualCall("sp_memory_relinquish") |
| 512 | + .withUnsignedLongIntParameter("handle", handle) |
| 513 | + .withMemoryBufferParameter("endpoints", (const unsigned char *)endpoints, |
| 514 | + sizeof(*endpoints) * endpoint_count) |
| 515 | + .withMemoryBufferParameter("flags", (const unsigned char *)flags, sizeof(*flags)) |
| 516 | + .returnIntValue(); |
| 517 | +} |
| 518 | + |
| 519 | +void expect_sp_memory_reclaim(uint64_t handle, uint32_t flags, sp_result result) |
| 520 | +{ |
| 521 | + mock() |
| 522 | + .expectOneCall("sp_memory_reclaim") |
| 523 | + .withUnsignedLongIntParameter("handle", handle) |
| 524 | + .withUnsignedIntParameter("flags", flags) |
| 525 | + .andReturnValue(result); |
| 526 | +} |
| 527 | + |
| 528 | +sp_result sp_memory_reclaim(uint64_t handle, uint32_t flags) |
| 529 | +{ |
| 530 | + return mock() |
| 531 | + .actualCall("sp_memory_reclaim") |
| 532 | + .withUnsignedLongIntParameter("handle", handle) |
| 533 | + .withUnsignedIntParameter("flags", flags) |
| 534 | + .returnIntValue(); |
| 535 | +} |
| 536 | + |
| 537 | +void expect_sp_memory_permission_get(const void *base_address, const struct sp_mem_perm *mem_perm, |
| 538 | + sp_result result) |
| 539 | +{ |
| 540 | + mock() |
| 541 | + .expectOneCall("sp_memory_permission_set") |
| 542 | + .withConstPointerParameter("base_address", base_address) |
| 543 | + .withOutputParameterReturning("mem_perm", mem_perm, |
| 544 | + sizeof(*mem_perm)) |
| 545 | + .andReturnValue(result); |
| 546 | +} |
| 547 | + |
| 548 | +sp_result sp_memory_permission_get(const void *base_address, |
| 549 | + struct sp_mem_perm *mem_perm) |
| 550 | +{ |
| 551 | + return mock() |
| 552 | + .actualCall("sp_memory_permission_set") |
| 553 | + .withConstPointerParameter("base_address", base_address) |
| 554 | + .withOutputParameter("mem_perm", mem_perm) |
| 555 | + .returnIntValue(); |
| 556 | +} |
| 557 | + |
| 558 | +void expect_sp_memory_permission_set(const void *base_address, size_t region_size, |
| 559 | + const struct sp_mem_perm *mem_perm, sp_result result) |
| 560 | +{ |
| 561 | + mock() |
| 562 | + .expectOneCall("sp_memory_permission_set") |
| 563 | + .withConstPointerParameter("base_address", base_address) |
| 564 | + .withUnsignedLongIntParameter("region_size", region_size) |
| 565 | + .withMemoryBufferParameter("mem_perm", (const unsigned char *)mem_perm, |
| 566 | + sizeof(*mem_perm)) |
| 567 | + .andReturnValue(result); |
| 568 | +} |
| 569 | + |
| 570 | +sp_result sp_memory_permission_set(const void *base_address, size_t region_size, |
| 571 | + const struct sp_mem_perm *mem_perm) |
| 572 | +{ |
| 573 | + return mock() |
| 574 | + .actualCall("sp_memory_permission_set") |
| 575 | + .withConstPointerParameter("base_address", base_address) |
| 576 | + .withUnsignedLongIntParameter("region_size", region_size) |
| 577 | + .withMemoryBufferParameter("mem_perm", (const unsigned char *)mem_perm, |
| 578 | + sizeof(*mem_perm)) |
| 579 | + .returnIntValue(); |
| 580 | +} |
| 581 | diff --git a/components/messaging/ffa/libsp/mock/mock_sp_memory_management.h b/components/messaging/ffa/libsp/mock/mock_sp_memory_management.h |
| 582 | new file mode 100644 |
| 583 | index 0000000..458d2af |
| 584 | --- /dev/null |
| 585 | +++ b/components/messaging/ffa/libsp/mock/mock_sp_memory_management.h |
| 586 | @@ -0,0 +1,98 @@ |
| 587 | +/* SPDX-License-Identifier: BSD-3-Clause */ |
| 588 | +/* |
| 589 | + * Copyright (c) 2022, Arm Limited and Contributors. All rights reserved. |
| 590 | + */ |
| 591 | + |
| 592 | +#ifndef LIBSP_MOCK_MOCK_SP_MEMORY_MANAGEMENT_H_ |
| 593 | +#define LIBSP_MOCK_MOCK_SP_MEMORY_MANAGEMENT_H_ |
| 594 | + |
| 595 | +#include "../include/sp_memory_management.h" |
| 596 | + |
| 597 | +#ifdef __cplusplus |
| 598 | +extern "C" { |
| 599 | +#endif |
| 600 | + |
| 601 | +void expect_sp_memory_donate(const struct sp_memory_descriptor *descriptor, |
| 602 | + const struct sp_memory_access_descriptor *acc_desc, |
| 603 | + const struct sp_memory_region regions[], |
| 604 | + uint32_t region_count, const uint64_t *handle, |
| 605 | + sp_result result); |
| 606 | + |
| 607 | +void expect_sp_memory_donate_dynamic(const struct sp_memory_descriptor *descriptor, |
| 608 | + const struct sp_memory_access_descriptor *acc_desc, |
| 609 | + const struct sp_memory_region regions[], |
| 610 | + uint32_t region_count, const uint64_t *handle, |
| 611 | + sp_result result); |
| 612 | + |
| 613 | +void expect_sp_memory_donate_dynamic_is_supported(const bool *supported, sp_result result); |
| 614 | + |
| 615 | +void expect_sp_memory_lend(const struct sp_memory_descriptor *descriptor, |
| 616 | + const struct sp_memory_access_descriptor acc_desc[], |
| 617 | + uint32_t acc_desc_count, |
| 618 | + const struct sp_memory_region regions[], |
| 619 | + uint32_t region_count, const uint64_t *handle, |
| 620 | + sp_result result); |
| 621 | + |
| 622 | +void expect_sp_memory_lend_dynamic(const struct sp_memory_descriptor *descriptor, |
| 623 | + const struct sp_memory_access_descriptor acc_desc[], |
| 624 | + uint32_t acc_desc_count, |
| 625 | + const struct sp_memory_region regions[], |
| 626 | + const uint32_t region_count, const uint64_t *handle, |
| 627 | + sp_result result); |
| 628 | + |
| 629 | +void expect_sp_memory_lend_dynamic_is_supported(const bool *supported, sp_result result); |
| 630 | + |
| 631 | +void expect_sp_memory_share(const struct sp_memory_descriptor *descriptor, |
| 632 | + const struct sp_memory_access_descriptor acc_desc[], |
| 633 | + uint32_t acc_desc_count, |
| 634 | + const struct sp_memory_region regions[], |
| 635 | + uint32_t region_count, const uint64_t *handle, |
| 636 | + sp_result result); |
| 637 | + |
| 638 | +void expect_sp_memory_share_dynamic(const struct sp_memory_descriptor *descriptor, |
| 639 | + const struct sp_memory_access_descriptor acc_desc[], |
| 640 | + uint32_t acc_desc_count, |
| 641 | + const struct sp_memory_region regions[], |
| 642 | + uint32_t region_count, const uint64_t *handle, |
| 643 | + sp_result result); |
| 644 | + |
| 645 | +void expect_sp_memory_share_dynamic_is_supported(const bool *supported, sp_result result); |
| 646 | + |
| 647 | +void expect_sp_memory_retrieve(const struct sp_memory_descriptor *descriptor, |
| 648 | + const struct sp_memory_access_descriptor *req_acc_desc, |
| 649 | + const struct sp_memory_access_descriptor *resp_acc_desc, |
| 650 | + const struct sp_memory_region in_regions[], |
| 651 | + const struct sp_memory_region out_regions[], |
| 652 | + uint32_t in_region_count, |
| 653 | + const uint32_t *out_region_count, uint64_t handle, |
| 654 | + sp_result result); |
| 655 | + |
| 656 | +void expect_sp_memory_retrieve_dynamic(const struct sp_memory_descriptor *descriptor, |
| 657 | + const struct sp_memory_access_descriptor *req_acc_desc, |
| 658 | + const struct sp_memory_access_descriptor *resp_acc_desc, |
| 659 | + const struct sp_memory_region in_regions[], |
| 660 | + const struct sp_memory_region out_regions[], |
| 661 | + uint32_t in_region_count, |
| 662 | + const uint32_t *out_region_count, uint64_t handle, |
| 663 | + sp_result result); |
| 664 | + |
| 665 | +void expect_sp_memory_retrieve_dynamic_is_supported(const bool *supported, sp_result result); |
| 666 | + |
| 667 | +void expect_sp_memory_relinquish(uint64_t handle, const uint16_t endpoints[], |
| 668 | + uint32_t endpoint_count, |
| 669 | + const struct sp_memory_transaction_flags *flags, |
| 670 | + sp_result result); |
| 671 | + |
| 672 | +void expect_sp_memory_reclaim(uint64_t handle, uint32_t flags, sp_result result); |
| 673 | + |
| 674 | +void expect_sp_memory_permission_get(const void *base_address, const struct sp_mem_perm *mem_perm, |
| 675 | + sp_result result); |
| 676 | + |
| 677 | +void expect_sp_memory_permission_set(const void *base_address, size_t region_size, |
| 678 | + const struct sp_mem_perm *mem_perm, sp_result result); |
| 679 | + |
| 680 | +#ifdef __cplusplus |
| 681 | +} |
| 682 | +#endif |
| 683 | + |
| 684 | +#endif /* LIBSP_MOCK_MOCK_SP_MEMORY_MANAGEMENT_H_ */ |
| 685 | diff --git a/components/messaging/ffa/libsp/test/test_mock_sp_memory_management.cpp b/components/messaging/ffa/libsp/test/test_mock_sp_memory_management.cpp |
| 686 | new file mode 100644 |
| 687 | index 0000000..387b50f |
| 688 | --- /dev/null |
| 689 | +++ b/components/messaging/ffa/libsp/test/test_mock_sp_memory_management.cpp |
| 690 | @@ -0,0 +1,260 @@ |
| 691 | +// SPDX-License-Identifier: BSD-3-Clause |
| 692 | +/* |
| 693 | + * Copyright (c) 2022, Arm Limited. All rights reserved. |
| 694 | + */ |
| 695 | + |
| 696 | +#include <CppUTestExt/MockSupport.h> |
| 697 | +#include <CppUTest/TestHarness.h> |
| 698 | +#include "mock_sp_memory_management.h" |
| 699 | +#include <stdint.h> |
| 700 | +#include <stdlib.h> |
| 701 | +#include <string.h> |
| 702 | + |
| 703 | +static const struct sp_memory_descriptor expected_descriptor = { |
| 704 | + .sender_id = 0xfedc, |
| 705 | + .memory_type = sp_memory_type_normal_memory, |
| 706 | + .mem_region_attr = {.normal_memory = { |
| 707 | + .cacheability = sp_cacheability_write_back, |
| 708 | + .shareability = sp_shareability_inner_shareable |
| 709 | + }}, |
| 710 | + .flags = { |
| 711 | + .zero_memory = true, |
| 712 | + .operation_time_slicing = true, |
| 713 | + .zero_memory_after_relinquish = true, |
| 714 | + .transaction_type = sp_memory_transaction_type_relayer_specified, |
| 715 | + .alignment_hint = 0x2000 |
| 716 | + }, |
| 717 | + .tag = 0x0123456789abcdefULL |
| 718 | +}; |
| 719 | +static const struct sp_memory_access_descriptor expected_acc_desc[] = { |
| 720 | + { |
| 721 | + .receiver_id = 0xfafa, |
| 722 | + .instruction_access = sp_instruction_access_executable, |
| 723 | + .data_access = sp_data_access_read_only |
| 724 | + }, { |
| 725 | + .receiver_id = 0xc1ca, |
| 726 | + .instruction_access = sp_instruction_access_not_executable, |
| 727 | + .data_access = sp_data_access_read_write |
| 728 | + } |
| 729 | +}; |
| 730 | +static const struct sp_memory_region expected_regions[2] = { |
| 731 | + {.address = (void *)0x01234567, .page_count = 0x89abcdef}, |
| 732 | + {.address = (void *)0x12345670, .page_count = 0x9abcdef8}, |
| 733 | +}; |
| 734 | +static const uint64_t expected_handle = 0xabcdef0123456789ULL; |
| 735 | +static const void *expected_address = (const void *)0x234567879; |
| 736 | +static const struct sp_mem_perm expected_mem_perm = { |
| 737 | + .data_access = sp_mem_perm_data_perm_read_write, |
| 738 | + .instruction_access = sp_mem_perm_instruction_perm_non_executable, |
| 739 | +}; |
| 740 | + |
| 741 | +TEST_GROUP(mock_sp_memory_management) |
| 742 | +{ |
| 743 | + TEST_SETUP() |
| 744 | + { |
| 745 | + memset(&descriptor, 0x00, sizeof(descriptor)); |
| 746 | + memset(&acc_desc, 0x00, sizeof(acc_desc)); |
| 747 | + memset(®ions, 0x00, sizeof(regions)); |
| 748 | + handle = 0; |
| 749 | + supported = false; |
| 750 | + } |
| 751 | + |
| 752 | + TEST_TEARDOWN() |
| 753 | + { |
| 754 | + mock().checkExpectations(); |
| 755 | + mock().clear(); |
| 756 | + } |
| 757 | + |
| 758 | + struct sp_memory_descriptor descriptor; |
| 759 | + struct sp_memory_access_descriptor acc_desc[2]; |
| 760 | + struct sp_memory_region regions[2]; |
| 761 | + uint64_t handle; |
| 762 | + bool supported; |
| 763 | + struct ffa_mem_transaction_buffer tr_buffer; |
| 764 | + |
| 765 | + static const sp_result result = -1; |
| 766 | +}; |
| 767 | + |
| 768 | +TEST(mock_sp_memory_management, sp_memory_donate) |
| 769 | +{ |
| 770 | + descriptor = expected_descriptor; |
| 771 | + acc_desc[0] = expected_acc_desc[0]; |
| 772 | + memcpy(regions, expected_regions, sizeof(regions)); |
| 773 | + |
| 774 | + expect_sp_memory_donate(&expected_descriptor, expected_acc_desc, expected_regions, 2, |
| 775 | + &expected_handle, result); |
| 776 | + LONGS_EQUAL(result, sp_memory_donate(&descriptor, acc_desc, regions, 2, &handle)); |
| 777 | + |
| 778 | + UNSIGNED_LONGLONGS_EQUAL(expected_handle, handle); |
| 779 | +} |
| 780 | + |
| 781 | +TEST(mock_sp_memory_management, sp_memory_donate_dynamic) |
| 782 | +{ |
| 783 | + descriptor = expected_descriptor; |
| 784 | + acc_desc[0] = expected_acc_desc[0]; |
| 785 | + memcpy(regions, expected_regions, sizeof(regions)); |
| 786 | + |
| 787 | + expect_sp_memory_donate_dynamic(&expected_descriptor, expected_acc_desc, expected_regions, |
| 788 | + 2, &expected_handle, result); |
| 789 | + LONGS_EQUAL(result, sp_memory_donate_dynamic(&descriptor, acc_desc, regions, 2, &handle, |
| 790 | + &tr_buffer)); |
| 791 | + |
| 792 | + UNSIGNED_LONGLONGS_EQUAL(expected_handle, handle); |
| 793 | +} |
| 794 | + |
| 795 | +TEST(mock_sp_memory_management, sp_memory_donate_dynamic_is_supported) |
| 796 | +{ |
| 797 | + const bool expected_supported = true; |
| 798 | + expect_sp_memory_donate_dynamic_is_supported(&expected_supported, result); |
| 799 | + LONGS_EQUAL(result, sp_memory_donate_dynamic_is_supported(&supported)); |
| 800 | + CHECK_TRUE(supported); |
| 801 | +} |
| 802 | + |
| 803 | +TEST(mock_sp_memory_management, sp_memory_lend) |
| 804 | +{ |
| 805 | + descriptor = expected_descriptor; |
| 806 | + memcpy(acc_desc, expected_acc_desc, sizeof(acc_desc)); |
| 807 | + memcpy(regions, expected_regions, sizeof(regions)); |
| 808 | + |
| 809 | + expect_sp_memory_lend(&descriptor, acc_desc, 2, regions, 2, &expected_handle, result); |
| 810 | + LONGS_EQUAL(result, sp_memory_lend(&descriptor, acc_desc, 2, regions, 2, &handle)); |
| 811 | + UNSIGNED_LONGLONGS_EQUAL(expected_handle, handle); |
| 812 | +} |
| 813 | + |
| 814 | +TEST(mock_sp_memory_management, sp_memory_lend_dynamic) |
| 815 | +{ |
| 816 | + descriptor = expected_descriptor; |
| 817 | + memcpy(acc_desc, expected_acc_desc, sizeof(acc_desc)); |
| 818 | + memcpy(regions, expected_regions, sizeof(regions)); |
| 819 | + |
| 820 | + expect_sp_memory_lend_dynamic(&descriptor, acc_desc, 2, regions, 2, &expected_handle, |
| 821 | + result); |
| 822 | + LONGS_EQUAL(result, sp_memory_lend_dynamic(&descriptor, acc_desc, 2, regions, 2, &handle, |
| 823 | + &tr_buffer)); |
| 824 | + UNSIGNED_LONGLONGS_EQUAL(expected_handle, handle); |
| 825 | +} |
| 826 | + |
| 827 | +TEST(mock_sp_memory_management, sp_memory_lend_dynamic_is_supported) |
| 828 | +{ |
| 829 | + const bool expected_supported = true; |
| 830 | + expect_sp_memory_lend_dynamic_is_supported(&expected_supported, result); |
| 831 | + LONGS_EQUAL(result, sp_memory_lend_dynamic_is_supported(&supported)); |
| 832 | + CHECK_TRUE(supported); |
| 833 | +} |
| 834 | + |
| 835 | +TEST(mock_sp_memory_management, sp_memory_share) |
| 836 | +{ |
| 837 | + descriptor = expected_descriptor; |
| 838 | + memcpy(acc_desc, expected_acc_desc, sizeof(acc_desc)); |
| 839 | + memcpy(regions, expected_regions, sizeof(regions)); |
| 840 | + |
| 841 | + expect_sp_memory_share(&descriptor, acc_desc, 2, regions, 2, &expected_handle, result); |
| 842 | + LONGS_EQUAL(result, sp_memory_share(&descriptor, acc_desc, 2, regions, 2, &handle)); |
| 843 | + UNSIGNED_LONGLONGS_EQUAL(expected_handle, handle); |
| 844 | +} |
| 845 | + |
| 846 | +TEST(mock_sp_memory_management, sp_memory_share_dynamic) |
| 847 | +{ |
| 848 | + descriptor = expected_descriptor; |
| 849 | + memcpy(acc_desc, expected_acc_desc, sizeof(acc_desc)); |
| 850 | + memcpy(regions, expected_regions, sizeof(regions)); |
| 851 | + |
| 852 | + expect_sp_memory_share_dynamic(&descriptor, acc_desc, 2, regions, 2, &expected_handle, |
| 853 | + result); |
| 854 | + LONGS_EQUAL(result, sp_memory_share_dynamic(&descriptor, acc_desc, 2, regions, 2, &handle, |
| 855 | + &tr_buffer)); |
| 856 | + UNSIGNED_LONGLONGS_EQUAL(expected_handle, handle); |
| 857 | +} |
| 858 | + |
| 859 | +TEST(mock_sp_memory_management, sp_memory_share_dynamic_is_supported) |
| 860 | +{ |
| 861 | + const bool expected_supported = true; |
| 862 | + expect_sp_memory_share_dynamic_is_supported(&expected_supported, result); |
| 863 | + LONGS_EQUAL(result, sp_memory_share_dynamic_is_supported(&supported)); |
| 864 | + CHECK_TRUE(supported); |
| 865 | +} |
| 866 | + |
| 867 | +TEST(mock_sp_memory_management, sp_memory_retrieve) |
| 868 | +{ |
| 869 | + const uint32_t expected_region_count = 1; |
| 870 | + struct sp_memory_access_descriptor acc_desc = expected_acc_desc[0]; |
| 871 | + struct sp_memory_region region = expected_regions[0]; |
| 872 | + uint32_t out_region_count = 0; |
| 873 | + |
| 874 | + descriptor = expected_descriptor; |
| 875 | + |
| 876 | + expect_sp_memory_retrieve(&expected_descriptor, &expected_acc_desc[0], |
| 877 | + &expected_acc_desc[1], &expected_regions[0], |
| 878 | + &expected_regions[1], 1, &expected_region_count, expected_handle, |
| 879 | + result); |
| 880 | + LONGS_EQUAL(result, sp_memory_retrieve(&descriptor, &acc_desc, ®ion, 1, |
| 881 | + &out_region_count, expected_handle)); |
| 882 | + MEMCMP_EQUAL(&acc_desc, &expected_acc_desc[1], sizeof(acc_desc)); |
| 883 | + MEMCMP_EQUAL(®ion, &expected_regions[1], sizeof(region)); |
| 884 | + UNSIGNED_LONGS_EQUAL(expected_region_count, out_region_count); |
| 885 | +} |
| 886 | + |
| 887 | +TEST(mock_sp_memory_management, sp_memory_retrieve_dynamic) |
| 888 | +{ |
| 889 | + const uint32_t expected_region_count = 1; |
| 890 | + struct sp_memory_access_descriptor acc_desc = expected_acc_desc[0]; |
| 891 | + struct sp_memory_region region = expected_regions[0]; |
| 892 | + uint32_t out_region_count = 0; |
| 893 | + |
| 894 | + descriptor = expected_descriptor; |
| 895 | + |
| 896 | + expect_sp_memory_retrieve_dynamic(&expected_descriptor, &expected_acc_desc[0], |
| 897 | + &expected_acc_desc[1], &expected_regions[0], |
| 898 | + &expected_regions[1], 1, &expected_region_count, |
| 899 | + expected_handle, result); |
| 900 | + LONGS_EQUAL(result, sp_memory_retrieve_dynamic(&descriptor, &acc_desc, ®ion, 1, |
| 901 | + &out_region_count, expected_handle, |
| 902 | + &tr_buffer)); |
| 903 | + MEMCMP_EQUAL(&acc_desc, &expected_acc_desc[1], sizeof(acc_desc)); |
| 904 | + MEMCMP_EQUAL(®ion, &expected_regions[1], sizeof(region)); |
| 905 | + UNSIGNED_LONGS_EQUAL(expected_region_count, out_region_count); |
| 906 | +} |
| 907 | + |
| 908 | +TEST(mock_sp_memory_management, sp_memory_retrieve_dynamic_is_supported) |
| 909 | +{ |
| 910 | + const bool expected_supported = true; |
| 911 | + expect_sp_memory_retrieve_dynamic_is_supported(&expected_supported, result); |
| 912 | + LONGS_EQUAL(result, sp_memory_retrieve_dynamic_is_supported(&supported)); |
| 913 | + CHECK_TRUE(supported); |
| 914 | +} |
| 915 | + |
| 916 | +TEST(mock_sp_memory_management, sp_memory_relinquish) |
| 917 | +{ |
| 918 | + uint16_t endpoints[3] = {1, 2, 3}; |
| 919 | + struct sp_memory_transaction_flags flags = {0}; // TODO: flags |
| 920 | + |
| 921 | + expect_sp_memory_relinquish(expected_handle, endpoints, 3, &flags, result); |
| 922 | + LONGS_EQUAL(result, sp_memory_relinquish(expected_handle, endpoints, 3, &flags)); |
| 923 | +} |
| 924 | + |
| 925 | +TEST(mock_sp_memory_management, sp_memory_reclaim) |
| 926 | +{ |
| 927 | + uint32_t flags = 0xffffffff; |
| 928 | + |
| 929 | + expect_sp_memory_reclaim(expected_handle, flags, result); |
| 930 | + LONGS_EQUAL(result, sp_memory_reclaim(expected_handle, flags)); |
| 931 | +} |
| 932 | + |
| 933 | +TEST(mock_sp_memory_management, sp_memory_permission_get) |
| 934 | +{ |
| 935 | + struct sp_mem_perm mem_perm; |
| 936 | + |
| 937 | + memset(&mem_perm, 0x00, sizeof(mem_perm)); |
| 938 | + |
| 939 | + expect_sp_memory_permission_get(expected_address, &expected_mem_perm, result); |
| 940 | + LONGS_EQUAL(result, sp_memory_permission_get(expected_address, &mem_perm)); |
| 941 | + MEMCMP_EQUAL(&expected_mem_perm, &mem_perm, sizeof(expected_mem_perm)); |
| 942 | +} |
| 943 | + |
| 944 | +TEST(mock_sp_memory_management, sp_memory_permission_set) |
| 945 | +{ |
| 946 | + size_t size = 0x7654; |
| 947 | + |
| 948 | + expect_sp_memory_permission_set(expected_address, size, &expected_mem_perm, result); |
| 949 | + LONGS_EQUAL(result, sp_memory_permission_set(expected_address, size, &expected_mem_perm)); |
| 950 | +} |
| 951 | diff --git a/components/messaging/ffa/libsp/tests.cmake b/components/messaging/ffa/libsp/tests.cmake |
| 952 | index 7b52248..63abb57 100644 |
| 953 | --- a/components/messaging/ffa/libsp/tests.cmake |
| 954 | +++ b/components/messaging/ffa/libsp/tests.cmake |
| 955 | @@ -134,6 +134,19 @@ unit_test_add_suite( |
| 956 | -DARM64 |
| 957 | ) |
| 958 | |
| 959 | +unit_test_add_suite( |
| 960 | + NAME libsp_mock_sp_memory_management |
| 961 | + SOURCES |
| 962 | + ${CMAKE_CURRENT_LIST_DIR}/test/test_mock_sp_memory_management.cpp |
| 963 | + ${CMAKE_CURRENT_LIST_DIR}/mock/mock_sp_memory_management.cpp |
| 964 | + INCLUDE_DIRECTORIES |
| 965 | + ${CMAKE_CURRENT_LIST_DIR}/include/ |
| 966 | + ${CMAKE_CURRENT_LIST_DIR}/mock |
| 967 | + ${UNIT_TEST_PROJECT_PATH}/components/common/utils/include |
| 968 | + COMPILE_DEFINITIONS |
| 969 | + -DARM64 |
| 970 | +) |
| 971 | + |
| 972 | unit_test_add_suite( |
| 973 | NAME libsp_sp_memory_management_internals |
| 974 | SOURCES |
| 975 | -- |
| 976 | 2.17.1 |
| 977 | |