Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 1 | From 1e5ce152214e22a7cd9617a5059e42c370351354 Mon Sep 17 00:00:00 2001 |
| 2 | From: Imre Kis <imre.kis@arm.com> |
| 3 | Date: Fri, 17 Jun 2022 15:40:18 +0200 |
| 4 | Subject: [PATCH 20/24] Add mock for libsp/sp_messaging |
| 5 | |
| 6 | Add mock_sp_messaging for mocking sp_messaging part of libsp. |
| 7 | |
| 8 | Signed-off-by: Imre Kis <imre.kis@arm.com> |
| 9 | Change-Id: I87478027c61b41028682b10e2535a7e14cf6922f |
| 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_messaging.cpp | 86 +++++++++++++++++++ |
| 17 | .../ffa/libsp/mock/mock_sp_messaging.h | 39 +++++++++ |
| 18 | .../mock/test/test_mock_sp_messaging.cpp | 77 +++++++++++++++++ |
| 19 | components/messaging/ffa/libsp/tests.cmake | 14 +++ |
| 20 | 5 files changed, 217 insertions(+) |
| 21 | create mode 100644 components/messaging/ffa/libsp/mock/mock_sp_messaging.cpp |
| 22 | create mode 100644 components/messaging/ffa/libsp/mock/mock_sp_messaging.h |
| 23 | create mode 100644 components/messaging/ffa/libsp/mock/test/test_mock_sp_messaging.cpp |
| 24 | |
| 25 | diff --git a/components/messaging/ffa/libsp/mock/component.cmake b/components/messaging/ffa/libsp/mock/component.cmake |
| 26 | index eb0d28c..375cb46 100644 |
| 27 | --- a/components/messaging/ffa/libsp/mock/component.cmake |
| 28 | +++ b/components/messaging/ffa/libsp/mock/component.cmake |
| 29 | @@ -14,6 +14,7 @@ target_sources(${TGT} PRIVATE |
| 30 | "${CMAKE_CURRENT_LIST_DIR}/mock_ffa_internal_api.cpp" |
| 31 | "${CMAKE_CURRENT_LIST_DIR}/mock_sp_discovery.cpp" |
| 32 | "${CMAKE_CURRENT_LIST_DIR}/mock_sp_memory_management.cpp" |
| 33 | + "${CMAKE_CURRENT_LIST_DIR}/mock_sp_messaging.cpp" |
| 34 | "${CMAKE_CURRENT_LIST_DIR}/mock_sp_rxtx.cpp" |
| 35 | ) |
| 36 | |
| 37 | diff --git a/components/messaging/ffa/libsp/mock/mock_sp_messaging.cpp b/components/messaging/ffa/libsp/mock/mock_sp_messaging.cpp |
| 38 | new file mode 100644 |
| 39 | index 0000000..522abb3 |
| 40 | --- /dev/null |
| 41 | +++ b/components/messaging/ffa/libsp/mock/mock_sp_messaging.cpp |
| 42 | @@ -0,0 +1,86 @@ |
| 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_messaging.h" |
| 50 | + |
| 51 | +void expect_sp_msg_wait(const struct sp_msg *msg, sp_result result) |
| 52 | +{ |
| 53 | + mock() |
| 54 | + .expectOneCall("sp_msg_wait") |
| 55 | + .withOutputParameterReturning("msg", msg, sizeof(*msg)) |
| 56 | + .andReturnValue(result); |
| 57 | +} |
| 58 | + |
| 59 | +sp_result sp_msg_wait(struct sp_msg *msg) |
| 60 | +{ |
| 61 | + return mock() |
| 62 | + .actualCall("sp_msg_wait") |
| 63 | + .withOutputParameter("msg", msg) |
| 64 | + .returnIntValue(); |
| 65 | +} |
| 66 | + |
| 67 | +void expect_sp_msg_send_direct_req(const struct sp_msg *req, |
| 68 | + const struct sp_msg *resp, |
| 69 | + sp_result result) |
| 70 | +{ |
| 71 | + mock() |
| 72 | + .expectOneCall("sp_msg_send_direct_req") |
| 73 | + .withMemoryBufferParameter("req", (const unsigned char *)req, sizeof(*req)) |
| 74 | + .withOutputParameterReturning("resp", resp, sizeof(*resp)) |
| 75 | + .andReturnValue(result); |
| 76 | +} |
| 77 | + |
| 78 | +sp_result sp_msg_send_direct_req(const struct sp_msg *req, struct sp_msg *resp) |
| 79 | +{ |
| 80 | + return mock() |
| 81 | + .actualCall("sp_msg_send_direct_req") |
| 82 | + .withMemoryBufferParameter("req", (const unsigned char *)req, sizeof(*req)) |
| 83 | + .withOutputParameter("resp", resp) |
| 84 | + .returnIntValue(); |
| 85 | +} |
| 86 | + |
| 87 | +void expect_sp_msg_send_direct_resp(const struct sp_msg *resp, |
| 88 | + const struct sp_msg *req, |
| 89 | + sp_result result) |
| 90 | +{ |
| 91 | + mock() |
| 92 | + .expectOneCall("sp_msg_send_direct_resp") |
| 93 | + .withMemoryBufferParameter("resp", (const unsigned char *)resp, sizeof(*resp)) |
| 94 | + .withOutputParameterReturning("req", req, sizeof(*req)) |
| 95 | + .andReturnValue(result); |
| 96 | +} |
| 97 | + |
| 98 | +sp_result sp_msg_send_direct_resp(const struct sp_msg *resp, |
| 99 | + struct sp_msg *req) |
| 100 | +{ |
| 101 | + return mock() |
| 102 | + .actualCall("sp_msg_send_direct_resp") |
| 103 | + .withMemoryBufferParameter("resp", (const unsigned char *)resp, sizeof(*resp)) |
| 104 | + .withOutputParameter("req", req) |
| 105 | + .returnIntValue(); |
| 106 | +} |
| 107 | + |
| 108 | +#if FFA_DIRECT_MSG_ROUTING_EXTENSION |
| 109 | +void expect_sp_msg_send_rc_req(const struct sp_msg *req, |
| 110 | + const struct sp_msg *resp, |
| 111 | + sp_result result) |
| 112 | +{ |
| 113 | + mock() |
| 114 | + .expectOneCall("sp_msg_send_rc_req") |
| 115 | + .withMemoryBufferParameter("req", (const unsigned char *)req, sizeof(*req)) |
| 116 | + .withOutputParameterReturning("resp", resp, sizeof(*resp)) |
| 117 | + .andReturnValue(result); |
| 118 | +} |
| 119 | + |
| 120 | +sp_result sp_msg_send_rc_req(const struct sp_msg *req, struct sp_msg *resp) |
| 121 | +{ |
| 122 | + return mock() |
| 123 | + .actualCall("sp_msg_send_rc_req") |
| 124 | + .withMemoryBufferParameter("req", (const unsigned char *)req, sizeof(*req)) |
| 125 | + .withOutputParameter("resp", resp) |
| 126 | + .returnIntValue(); |
| 127 | +} |
| 128 | +#endif /* FFA_DIRECT_MSG_ROUTING_EXTENSION */ |
| 129 | diff --git a/components/messaging/ffa/libsp/mock/mock_sp_messaging.h b/components/messaging/ffa/libsp/mock/mock_sp_messaging.h |
| 130 | new file mode 100644 |
| 131 | index 0000000..8183012 |
| 132 | --- /dev/null |
| 133 | +++ b/components/messaging/ffa/libsp/mock/mock_sp_messaging.h |
| 134 | @@ -0,0 +1,39 @@ |
| 135 | +/* SPDX-License-Identifier: BSD-3-Clause */ |
| 136 | +/* |
| 137 | + * Copyright (c) 2022, Arm Limited and Contributors. All rights reserved. |
| 138 | + */ |
| 139 | + |
| 140 | +#ifndef LIBSP_MOCK_MOCK_SP_MESSAGING_H_ |
| 141 | +#define LIBSP_MOCK_MOCK_SP_MESSAGING_H_ |
| 142 | + |
| 143 | +#include "../include/sp_messaging.h" |
| 144 | + |
| 145 | +#include <stdint.h> |
| 146 | + |
| 147 | +#ifdef __cplusplus |
| 148 | +extern "C" { |
| 149 | +#endif |
| 150 | + |
| 151 | +void expect_sp_msg_wait(const struct sp_msg *msg, sp_result result); |
| 152 | + |
| 153 | + |
| 154 | +void expect_sp_msg_send_direct_req(const struct sp_msg *req, |
| 155 | + const struct sp_msg *resp, |
| 156 | + sp_result result); |
| 157 | + |
| 158 | + |
| 159 | +void expect_sp_msg_send_direct_resp(const struct sp_msg *resp, |
| 160 | + const struct sp_msg *req, |
| 161 | + sp_result result); |
| 162 | + |
| 163 | +#if FFA_DIRECT_MSG_ROUTING_EXTENSION |
| 164 | +void expect_sp_msg_send_rc_req(const struct sp_msg *req, |
| 165 | + const struct sp_msg *resp, |
| 166 | + sp_result result); |
| 167 | +#endif /* FFA_DIRECT_MSG_ROUTING_EXTENSION */ |
| 168 | + |
| 169 | +#ifdef __cplusplus |
| 170 | +} |
| 171 | +#endif |
| 172 | + |
| 173 | +#endif /* LIBSP_MOCK_MOCK_SP_MESSAGING_H_ */ |
| 174 | diff --git a/components/messaging/ffa/libsp/mock/test/test_mock_sp_messaging.cpp b/components/messaging/ffa/libsp/mock/test/test_mock_sp_messaging.cpp |
| 175 | new file mode 100644 |
| 176 | index 0000000..bfc7959 |
| 177 | --- /dev/null |
| 178 | +++ b/components/messaging/ffa/libsp/mock/test/test_mock_sp_messaging.cpp |
| 179 | @@ -0,0 +1,77 @@ |
| 180 | +// SPDX-License-Identifier: BSD-3-Clause |
| 181 | +/* |
| 182 | + * Copyright (c) 2022, Arm Limited. All rights reserved. |
| 183 | + */ |
| 184 | + |
| 185 | +#include <CppUTestExt/MockSupport.h> |
| 186 | +#include <CppUTest/TestHarness.h> |
| 187 | +#include "mock_sp_messaging.h" |
| 188 | +#include <stdint.h> |
| 189 | +#include <stdlib.h> |
| 190 | +#include <string.h> |
| 191 | + |
| 192 | +static const struct sp_msg expected_req = { |
| 193 | + .source_id = 0x0123, |
| 194 | + .destination_id = 0x4567, |
| 195 | + .args = {0x89abcdef, 0xfedcba98, 0x76543210, 0xabcdef01} |
| 196 | +}; |
| 197 | +static const struct sp_msg expected_resp = { |
| 198 | + .source_id = 0x1234, |
| 199 | + .destination_id = 0x5678, |
| 200 | + .args = {0x9abcdef8, 0xedcba98f, 0x65432107, 0xbcdef01a} |
| 201 | +}; |
| 202 | + |
| 203 | +TEST_GROUP(mock_sp_messaging) |
| 204 | +{ |
| 205 | + TEST_SETUP() |
| 206 | + { |
| 207 | + memset(&req, 0x00, sizeof(req)); |
| 208 | + memset(&resp, 0x00, sizeof(resp)); |
| 209 | + } |
| 210 | + |
| 211 | + TEST_TEARDOWN() |
| 212 | + { |
| 213 | + mock().checkExpectations(); |
| 214 | + mock().clear(); |
| 215 | + } |
| 216 | + |
| 217 | + struct sp_msg req; |
| 218 | + struct sp_msg resp; |
| 219 | + static const sp_result result = -1; |
| 220 | +}; |
| 221 | + |
| 222 | +TEST(mock_sp_messaging, sp_msg_wait) |
| 223 | +{ |
| 224 | + expect_sp_msg_wait(&expected_req, result); |
| 225 | + LONGS_EQUAL(result, sp_msg_wait(&req)); |
| 226 | + MEMCMP_EQUAL(&expected_req, &req, sizeof(expected_req)); |
| 227 | +} |
| 228 | + |
| 229 | +TEST(mock_sp_messaging, sp_msg_send_direct_req) |
| 230 | +{ |
| 231 | + req = expected_req; |
| 232 | + |
| 233 | + expect_sp_msg_send_direct_req(&expected_req, &expected_resp, result); |
| 234 | + LONGS_EQUAL(result, sp_msg_send_direct_req(&req, &resp)); |
| 235 | + MEMCMP_EQUAL(&expected_resp, &resp, sizeof(expected_resp)); |
| 236 | +} |
| 237 | + |
| 238 | +TEST(mock_sp_messaging, sp_msg_send_direct_resp) |
| 239 | +{ |
| 240 | + resp = expected_resp; |
| 241 | + |
| 242 | + expect_sp_msg_send_direct_resp(&expected_resp, &expected_req, result); |
| 243 | + LONGS_EQUAL(result, sp_msg_send_direct_resp(&resp, &req)); |
| 244 | + MEMCMP_EQUAL(&expected_req, &req, sizeof(expected_req)); |
| 245 | +} |
| 246 | + |
| 247 | +#if FFA_DIRECT_MSG_ROUTING_EXTENSION |
| 248 | +TEST(mock_sp_messaging, sp_msg_send_rc_req) |
| 249 | +{ |
| 250 | + req = expected_req; |
| 251 | + |
| 252 | + expect_sp_msg_send_rc_req(&expected_req, &expected_resp, result); |
| 253 | + LONGS_EQUAL(result, sp_msg_send_rc_req(&req, &resp)); |
| 254 | + MEMCMP_EQUAL(&expected_resp, &resp, sizeof(expected_resp)); |
| 255 | +} |
| 256 | +#endif /* FFA_DIRECT_MSG_ROUTING_EXTENSION */ |
| 257 | diff --git a/components/messaging/ffa/libsp/tests.cmake b/components/messaging/ffa/libsp/tests.cmake |
| 258 | index 63abb57..eb0b41e 100644 |
| 259 | --- a/components/messaging/ffa/libsp/tests.cmake |
| 260 | +++ b/components/messaging/ffa/libsp/tests.cmake |
| 261 | @@ -176,6 +176,20 @@ unit_test_add_suite( |
| 262 | -DARM64 |
| 263 | ) |
| 264 | |
| 265 | +unit_test_add_suite( |
| 266 | + NAME libsp_mock_sp_messaging |
| 267 | + SOURCES |
| 268 | + ${CMAKE_CURRENT_LIST_DIR}/mock/test/test_mock_sp_messaging.cpp |
| 269 | + ${CMAKE_CURRENT_LIST_DIR}/mock/mock_sp_messaging.cpp |
| 270 | + INCLUDE_DIRECTORIES |
| 271 | + ${CMAKE_CURRENT_LIST_DIR}/include/ |
| 272 | + ${CMAKE_CURRENT_LIST_DIR}/mock |
| 273 | + ${UNIT_TEST_PROJECT_PATH}/components/common/utils/include |
| 274 | + COMPILE_DEFINITIONS |
| 275 | + -DARM64 |
| 276 | + -DFFA_DIRECT_MSG_ROUTING_EXTENSION=1 |
| 277 | +) |
| 278 | + |
| 279 | unit_test_add_suite( |
| 280 | NAME libsp_sp_messaging_with_routing_extension |
| 281 | SOURCES |
| 282 | -- |
| 283 | 2.17.1 |
| 284 | |