1 // SPDX-License-Identifier: BSD-3-Clause
2 /*
3 * Copyright (c) 2022, Arm Limited. All rights reserved.
4 */
5
6 #include <CppUTestExt/MockSupport.h>
7 #include <CppUTest/TestHarness.h>
8 #include "mock_sp_messaging.h"
9 #include <stdint.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 static const struct sp_msg expected_req = {
14 .source_id = 0x0123,
15 .destination_id = 0x4567,
16 .is_64bit_message = false,
17 .args = {0x89abcdef, 0xfedcba98, 0x76543210, 0xabcdef01}
18 };
19 static const struct sp_msg expected_resp = {
20 .source_id = 0x1234,
21 .destination_id = 0x5678,
22 .is_64bit_message = false,
23 .args = {0x9abcdef8, 0xedcba98f, 0x65432107, 0xbcdef01a}
24 };
25
TEST_GROUP(mock_sp_messaging)26 TEST_GROUP(mock_sp_messaging)
27 {
28 TEST_SETUP()
29 {
30 memset(&req, 0x00, sizeof(req));
31 memset(&resp, 0x00, sizeof(resp));
32 }
33
34 TEST_TEARDOWN()
35 {
36 mock().checkExpectations();
37 mock().clear();
38 }
39
40 struct sp_msg req;
41 struct sp_msg resp;
42 static const sp_result result = -1;
43 };
44
TEST(mock_sp_messaging,sp_msg_wait)45 TEST(mock_sp_messaging, sp_msg_wait)
46 {
47 expect_sp_msg_wait(&expected_req, result);
48 LONGS_EQUAL(result, sp_msg_wait(&req));
49 MEMCMP_EQUAL(&expected_req, &req, sizeof(expected_req));
50 }
51
TEST(mock_sp_messaging,sp_msg_send_direct_req)52 TEST(mock_sp_messaging, sp_msg_send_direct_req)
53 {
54 req = expected_req;
55
56 expect_sp_msg_send_direct_req(&expected_req, &expected_resp, result);
57 LONGS_EQUAL(result, sp_msg_send_direct_req(&req, &resp));
58 MEMCMP_EQUAL(&expected_resp, &resp, sizeof(expected_resp));
59 }
60
TEST(mock_sp_messaging,sp_msg_send_direct_resp)61 TEST(mock_sp_messaging, sp_msg_send_direct_resp)
62 {
63 resp = expected_resp;
64
65 expect_sp_msg_send_direct_resp(&expected_resp, &expected_req, result);
66 LONGS_EQUAL(result, sp_msg_send_direct_resp(&resp, &req));
67 MEMCMP_EQUAL(&expected_req, &req, sizeof(expected_req));
68 }
69
70 #if FFA_DIRECT_MSG_ROUTING_EXTENSION
TEST(mock_sp_messaging,sp_msg_send_rc_req)71 TEST(mock_sp_messaging, sp_msg_send_rc_req)
72 {
73 req = expected_req;
74
75 expect_sp_msg_send_rc_req(&expected_req, &expected_resp, result);
76 LONGS_EQUAL(result, sp_msg_send_rc_req(&req, &resp));
77 MEMCMP_EQUAL(&expected_resp, &resp, sizeof(expected_resp));
78 }
79 #endif /* FFA_DIRECT_MSG_ROUTING_EXTENSION */
80