1 /*
2 * Arm SCP/MCP Software
3 * Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8 #include "scp_unity.h"
9 #include "unity.h"
10
11 #include <Mockfwk_id.h>
12 #include <Mockfwk_mm.h>
13 #include <Mockfwk_module.h>
14 #include <Mockfwk_notification.h>
15 #include <config_traffic_cop.h>
16
17 #include <internal/Mockfwk_core_internal.h>
18
19 #include <mod_power_domain.h>
20
21 #include <fwk_element.h>
22 #include <fwk_macros.h>
23 #include <fwk_module_idx.h>
24 #include <fwk_notification.h>
25
26 #include UNIT_TEST_SRC
27
28 static struct mod_tcop_domain_ctx dev_ctx_table[1];
29 struct mod_tcop_core_ctx core_ctx_table[2];
30
setUp(void)31 void setUp(void)
32 {
33 struct mod_tcop_core_config const *core_config;
34 struct mod_tcop_domain_ctx *domain_ctx;
35 struct mod_tcop_core_ctx *core_ctx;
36 uint32_t core_idx;
37
38 tcop_ctx.tcop_domain_count = 1;
39 tcop_ctx.domain_ctx = domain_ctx = &dev_ctx_table[0];
40
41 domain_ctx->domain_id = FWK_ID_ELEMENT(FWK_MODULE_IDX_TRAFFIC_COP, 0);
42 domain_ctx->num_cores = 2;
43 domain_ctx->domain_config = &fake_domain_conf[0];
44 domain_ctx->core_ctx = &core_ctx_table[0];
45 domain_ctx->num_cores_online = 0;
46
47 /* Initialize each core */
48 for (core_idx = 0; core_idx < domain_ctx->num_cores; core_idx++) {
49 core_ctx = &domain_ctx->core_ctx[core_idx];
50 core_config = &domain_ctx->domain_config->core_config[core_idx];
51
52 if (core_config->core_starts_online) {
53 domain_ctx->num_cores_online++;
54 core_ctx->online = true;
55 }
56 }
57 }
58
tearDown(void)59 void tearDown(void)
60 {
61 }
62
test_function_tcop_start_mod_id_success(void)63 void test_function_tcop_start_mod_id_success(void)
64 {
65 int status;
66
67 fwk_module_is_valid_module_id_ExpectAndReturn(
68 fwk_module_id_traffic_cop, true);
69
70 status = tcop_start(fwk_module_id_traffic_cop);
71 TEST_ASSERT_EQUAL(status, FWK_SUCCESS);
72 }
73
test_function_tcop_start_notif_subscribe_success(void)74 void test_function_tcop_start_notif_subscribe_success(void)
75 {
76 int status;
77 fwk_id_t elem_id = FWK_ID_ELEMENT(FWK_MODULE_IDX_TRAFFIC_COP, 0);
78
79 fwk_module_is_valid_module_id_ExpectAnyArgsAndReturn(false);
80 fwk_id_get_element_idx_ExpectAndReturn(elem_id, 0);
81 fwk_notification_subscribe_IgnoreAndReturn(FWK_SUCCESS);
82
83 status = tcop_start(elem_id);
84 TEST_ASSERT_EQUAL(status, FWK_SUCCESS);
85 fwk_notification_subscribe_StopIgnore();
86 }
87
fwk_notif_sub_cback_fail_subscribe_pre_transition(fwk_id_t notification_id,fwk_id_t source_id,fwk_id_t target_id,int cmock_num_calls)88 int fwk_notif_sub_cback_fail_subscribe_pre_transition(
89 fwk_id_t notification_id,
90 fwk_id_t source_id,
91 fwk_id_t target_id,
92 int cmock_num_calls)
93 {
94 if (cmock_num_calls == 0) {
95 return FWK_E_STATE;
96 }
97
98 return FWK_SUCCESS;
99 }
100
fwk_notif_sub_cback_fail_subscribe_post_transition(fwk_id_t notification_id,fwk_id_t source_id,fwk_id_t target_id,int cmock_num_calls)101 int fwk_notif_sub_cback_fail_subscribe_post_transition(
102 fwk_id_t notification_id,
103 fwk_id_t source_id,
104 fwk_id_t target_id,
105 int cmock_num_calls)
106 {
107 if (cmock_num_calls == 2) {
108 return FWK_E_STATE;
109 }
110
111 return FWK_SUCCESS;
112 }
113
test_function_tcop_start_notif_subscribe_fail_1st_call(void)114 void test_function_tcop_start_notif_subscribe_fail_1st_call(void)
115 {
116 int status;
117 fwk_id_t elem_id = FWK_ID_ELEMENT(FWK_MODULE_IDX_TRAFFIC_COP, 0);
118
119 fwk_module_is_valid_module_id_IgnoreAndReturn(false);
120
121 fwk_id_get_element_idx_ExpectAndReturn(elem_id, 0);
122 fwk_notification_subscribe_Stub(
123 fwk_notif_sub_cback_fail_subscribe_pre_transition);
124
125 status = tcop_start(elem_id);
126 TEST_ASSERT_EQUAL(status, FWK_E_STATE);
127 }
128
test_function_tcop_start_notif_subscribe_fail_2nd_call(void)129 void test_function_tcop_start_notif_subscribe_fail_2nd_call(void)
130 {
131 int status;
132 fwk_id_t elem_id = FWK_ID_ELEMENT(FWK_MODULE_IDX_TRAFFIC_COP, 0);
133
134 fwk_module_is_valid_module_id_IgnoreAndReturn(false);
135
136 fwk_id_get_element_idx_ExpectAndReturn(elem_id, 0);
137 fwk_notification_subscribe_Stub(
138 fwk_notif_sub_cback_fail_subscribe_post_transition);
139
140 status = tcop_start(elem_id);
141 TEST_ASSERT_EQUAL(status, FWK_E_STATE);
142 }
143
test_function_tcop_start_elem_id_domain_limits_init_success(void)144 void test_function_tcop_start_elem_id_domain_limits_init_success(void)
145 {
146 int status;
147 struct mod_tcop_domain_ctx *domain_ctx;
148 struct mod_tcop_pct_table *pct;
149
150 fwk_id_t elem_id = FWK_ID_ELEMENT(FWK_MODULE_IDX_TRAFFIC_COP, 0);
151
152 fwk_module_is_valid_module_id_IgnoreAndReturn(false);
153 fwk_id_get_element_idx_IgnoreAndReturn(0);
154 fwk_notification_subscribe_IgnoreAndReturn(FWK_SUCCESS);
155
156 status = tcop_start(elem_id);
157 TEST_ASSERT_EQUAL(status, FWK_SUCCESS);
158
159 domain_ctx = &dev_ctx_table[0];
160 pct = &fake_pct_table[0];
161
162 TEST_ASSERT_EQUAL(pct[1].perf_limit, domain_ctx->perf_limit);
163 fwk_module_is_valid_module_id_StopIgnore();
164 fwk_id_get_element_idx_StopIgnore();
165 fwk_notification_subscribe_StopIgnore();
166 }
167
mod_tcop_test_main(void)168 int mod_tcop_test_main(void)
169 {
170 UNITY_BEGIN();
171
172 RUN_TEST(test_function_tcop_start_mod_id_success);
173
174 RUN_TEST(test_function_tcop_start_notif_subscribe_success);
175
176 RUN_TEST(test_function_tcop_start_notif_subscribe_fail_1st_call);
177 RUN_TEST(test_function_tcop_start_notif_subscribe_fail_2nd_call);
178
179 RUN_TEST(test_function_tcop_start_elem_id_domain_limits_init_success);
180
181 return UNITY_END();
182 }
183
main(void)184 int main(void)
185 {
186 return mod_tcop_test_main();
187 }
188