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_discovery.h"
9 #include <stdint.h>
10 #include <stdlib.h>
11
12
13
14
TEST_GROUP(mock_sp_discovery)15 TEST_GROUP(mock_sp_discovery) {
16 TEST_TEARDOWN()
17 {
18 mock().checkExpectations();
19 mock().clear();
20 }
21
22 static const sp_result result = -1;
23 };
24
TEST(mock_sp_discovery,sp_discovery_ffa_version_get)25 TEST(mock_sp_discovery, sp_discovery_ffa_version_get)
26 {
27 const uint16_t expected_major = 0xabcd;
28 const uint16_t expected_minor = 0xef01;
29 uint16_t major = 0, minor = 0;
30
31 expect_sp_discovery_ffa_version_get(&expected_major, &expected_minor,
32 result);
33 LONGS_EQUAL(result, sp_discovery_ffa_version_get(&major, &minor));
34 UNSIGNED_LONGS_EQUAL(expected_major, major);
35 UNSIGNED_LONGS_EQUAL(expected_minor, minor);
36 }
37
TEST(mock_sp_discovery,sp_discovery_own_id_get)38 TEST(mock_sp_discovery, sp_discovery_own_id_get)
39 {
40 const uint16_t expected_id = 0x8765;
41 uint16_t id = 0;
42
43 expect_sp_discovery_own_id_get(&expected_id, result);
44 LONGS_EQUAL(result, sp_discovery_own_id_get(&id));
45 UNSIGNED_LONGS_EQUAL(expected_id, id);
46 }
47
TEST(mock_sp_discovery,sp_discovery_partition_id_get)48 TEST(mock_sp_discovery, sp_discovery_partition_id_get)
49 {
50 const struct sp_uuid expected_uuid = {
51 .uuid = {0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
52 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}};
53 const uint16_t expected_id = 0xc1ca;
54
55 struct sp_uuid uuid = expected_uuid;
56 uint16_t id = 0;
57
58 expect_sp_discovery_partition_id_get(&expected_uuid, &expected_id,
59 result);
60 LONGS_EQUAL(result, sp_discovery_partition_id_get(&uuid, &id));
61 UNSIGNED_LONGS_EQUAL(expected_id, id);
62 }
63
TEST(mock_sp_discovery,sp_discovery_partition_info_get)64 TEST(mock_sp_discovery, sp_discovery_partition_info_get)
65 {
66 const struct sp_uuid expected_uuid = {
67 .uuid = {0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
68 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}};
69 const struct sp_partition_info expected_info = {
70 .partition_id = 0x1234,
71 .execution_context_count = 0xffff,
72 .supports_direct_requests = true,
73 .can_send_direct_requests = true,
74 .supports_indirect_requests = false
75 };
76
77 struct sp_uuid uuid = expected_uuid;
78 struct sp_partition_info info = {0};
79 uint32_t in_count = 16;
80 uint32_t expected_out_count = 8;
81 uint32_t out_count = in_count;
82
83
84 expect_sp_discovery_partition_info_get(&expected_uuid, &expected_info,
85 in_count, &expected_out_count,
86 result);
87 LONGS_EQUAL(result, sp_discovery_partition_info_get(&uuid, &info, &out_count));
88 MEMCMP_EQUAL(&expected_info, &info, sizeof(&expected_info));
89 UNSIGNED_LONGS_EQUAL(expected_out_count, out_count);
90 }
91
TEST(mock_sp_discovery,sp_discovery_partition_info_get_all)92 TEST(mock_sp_discovery, sp_discovery_partition_info_get_all)
93 {
94 const uint32_t expected_count = 2;
95 const struct sp_partition_info expected_info[expected_count] = {{
96 .partition_id = 0x5678,
97 .execution_context_count = 0x1111,
98 .supports_direct_requests = false,
99 .can_send_direct_requests = false,
100 .supports_indirect_requests = true
101 }, {
102 .partition_id = 0x1234,
103 .execution_context_count = 0xffff,
104 .supports_direct_requests = true,
105 .can_send_direct_requests = true,
106 .supports_indirect_requests = false
107 }};
108
109 struct sp_partition_info info[expected_count] = {0};
110 uint32_t count = 0;
111
112 expect_sp_discovery_partition_info_get_all(expected_info,
113 &expected_count, result);
114 LONGS_EQUAL(result, sp_discovery_partition_info_get_all(info, &count));
115 MEMCMP_EQUAL(&expected_info, &info, sizeof(&expected_info));
116 UNSIGNED_LONGS_EQUAL(expected_count, count);
117 }