blob: 86426cc7861b31422c05871f0c48141a0c330da3 [file] [log] [blame]
jk-arm957cfea2021-06-18 15:52:12 +05301/** @file
2 * Copyright (c) 2021 Arm Limited or its affiliates. All rights reserved.
3 * SPDX-License-Identifier : Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16**/
17
18#include "val_framework.h"
19#include "val_dispatcher.h"
20#include "val_interfaces.h"
21#include "val_peripherals.h"
22
23
24extern val_api_t val_api;
25
26/* gloabls */
27addr_t g_test_info_addr;
28
29/**
30 @brief - This function prints PSA_{SUITE}_API_VERSION_MAJOR
31 PSA_{SUITE}_API_VERSION_MINOR details.
32 @param - None
33 @return - None
34**/
35static void val_print_api_version(void)
36{
37#ifdef CRYPTO
38 val_print(PRINT_ALWAYS, " %d.", PSA_CRYPTO_API_VERSION_MAJOR);
39 val_print(PRINT_ALWAYS, "%d", PSA_CRYPTO_API_VERSION_MINOR);
40#endif
41#ifdef INTERNAL_TRUSTED_STORAGE
42 val_print(PRINT_ALWAYS, " %d.", PSA_ITS_API_VERSION_MAJOR);
43 val_print(PRINT_ALWAYS, "%d", PSA_ITS_API_VERSION_MINOR);
44#endif
45#ifdef PROTECTED_STORAGE
46 val_print(PRINT_ALWAYS, " %d.", PSA_PS_API_VERSION_MAJOR);
47 val_print(PRINT_ALWAYS, "%d", PSA_PS_API_VERSION_MINOR);
48#endif
49#ifdef STORAGE
50 val_print(PRINT_ALWAYS, " ITS %d.", PSA_ITS_API_VERSION_MAJOR);
51 val_print(PRINT_ALWAYS, "%d", PSA_ITS_API_VERSION_MINOR);
52 val_print(PRINT_ALWAYS, " and PS %d.", PSA_PS_API_VERSION_MAJOR);
53 val_print(PRINT_ALWAYS, "%d", PSA_PS_API_VERSION_MINOR);
54#endif
55#ifdef INITIAL_ATTESTATION
56 val_print(PRINT_ALWAYS, " %d.", PSA_INITIAL_ATTEST_API_VERSION_MAJOR);
57 val_print(PRINT_ALWAYS, "%d", PSA_INITIAL_ATTEST_API_VERSION_MINOR);
58#endif
59}
60
61/**
62 @brief - This function reads the test ELFs from RAM or secondary storage and loads into
63 system memory
64 @param - test_id : Returns the current test ID
65 - test_id_prev : Previous test ID.
66 @return - Error code
67**/
68val_status_t val_test_load(test_id_t *test_id, test_id_t test_id_prev)
69{
70 int i;
71 val_test_info_t test_list[] = {
72#include "test_entry_list.inc"
73 {VAL_INVALID_TEST_ID, NULL}
74 };
75
76 for (i = 0; i < (int)(sizeof(test_list)/sizeof(test_list[0])); i++)
77 {
78 if (test_id_prev == VAL_INVALID_TEST_ID)
79 {
80 *test_id = test_list[i].test_id;
81 g_test_info_addr = (addr_t) test_list[i].entry_addr;
82 return VAL_STATUS_SUCCESS;
83 }
84 else if (test_id_prev == test_list[i].test_id)
85 {
86 *test_id = test_list[i+1].test_id;
87 g_test_info_addr = (addr_t) test_list[i+1].entry_addr;
88 return VAL_STATUS_SUCCESS;
89 }
90 else if (test_list[i].test_id == VAL_INVALID_TEST_ID)
91 {
92 val_print(PRINT_DEBUG, "\n\nNo more valid tests found. Exiting.", 0);
93 *test_id = VAL_INVALID_TEST_ID;
94 return VAL_STATUS_SUCCESS;
95 }
96 }
97
98 *test_id = VAL_INVALID_TEST_ID;
99 val_print(PRINT_ERROR, "\n\nError: No more valid tests found. Exiting.", 0);
100 return VAL_STATUS_LOAD_ERROR;
101}
102
103/**
104 @brief - This function reads the function pointer addresses for
105 test_entry
106 @param - paddr : Returns the Test function address
107 @return - Returns val_status_t
108**/
109val_status_t val_get_test_entry_addr(addr_t *paddr)
110{
111 *paddr = g_test_info_addr;
112 return VAL_STATUS_SUCCESS;
113}
114
115/**
116 @brief - Execute the function pointer which was given to us by the test
117 @param - void
118**/
119void val_execute_test_fn(void)
120{
121 test_fptr_t fn_ptr;
122 addr_t addr;
123
124 val_get_test_entry_addr(&addr);
125 fn_ptr = (test_fptr_t)addr;
126 fn_ptr(&val_api);
127 return;
128}
129
130/*
131 @brief - Reads the pre-defined component name against given test_id
132 @param - test_id : Current Test ID
133 @return - Component name
134*/
135char *val_get_comp_name(test_id_t test_id)
136{
137 switch (VAL_GET_COMP_NUM(test_id))
138 {
139 case VAL_SECURE_DEBUG_BASE:
140 return "Secure Debug Suite";
141 default:
142 return "Unknown Suite";
143 }
144}
145
146/**
147 @brief - This function is responsible for setting up VAL infrastructure.
148 Loads test one by one from combine binary and calls test_entry
149 function of each test image.
150 @return - 0 if success Or error code for the failure.
151**/
152int32_t val_dispatcher(test_id_t test_id_prev)
153{
154
155 test_id_t test_id;
156 val_status_t status;
157 boot_t boot;
158 test_count_t test_count = {0,};
159 uint32_t test_result;
160
161 do
162 {
163 status = val_test_load(&test_id, test_id_prev);
164
165 if (VAL_ERROR(status))
166 {
167 return status;
168 }
169 else if (test_id == VAL_INVALID_TEST_ID)
170 {
171 break;
172 }
173 if (VAL_GET_COMP_NUM(test_id_prev) != VAL_GET_COMP_NUM(test_id))
174 {
175 val_print(PRINT_ALWAYS, "\nRunning.. ", 0);
176 val_print(PRINT_ALWAYS, val_get_comp_name(test_id), 0);
177 val_print(PRINT_ALWAYS, "\n******************************\n", 0);
178 }
179
180 val_execute_test_fn();
181
182 test_result = val_report_status();
183
184 switch (test_result)
185 {
186 case TEST_PASS:
187 test_count.pass_cnt += 1;
188 break;
189 case TEST_FAIL:
190 test_count.fail_cnt += 1;
191 break;
192 case TEST_SKIP:
193 test_count.skip_cnt += 1;
194 break;
195 case TEST_PENDING:
196 test_count.sim_error_cnt += 1;
197 break;
198 }
199
200 test_id_prev = test_id;
201 } while (1);
202
203 val_print(PRINT_ALWAYS, "\n************ ", 0);
204 val_print(PRINT_ALWAYS, val_get_comp_name(test_id_prev), 0);
205 val_print(PRINT_ALWAYS, " Report **********\n", 0);
206 val_print(PRINT_ALWAYS, "TOTAL TESTS : %d\n", test_count.pass_cnt + test_count.fail_cnt
207 + test_count.skip_cnt + test_count.sim_error_cnt);
208 val_print(PRINT_ALWAYS, "TOTAL PASSED : %d\n", test_count.pass_cnt);
209 val_print(PRINT_ALWAYS, "TOTAL SIM ERROR : %d\n", test_count.sim_error_cnt);
210 val_print(PRINT_ALWAYS, "TOTAL FAILED : %d\n", test_count.fail_cnt);
211 val_print(PRINT_ALWAYS, "TOTAL SKIPPED : %d\n", test_count.skip_cnt);
212 val_print(PRINT_ALWAYS, "******************************************\n", 0);
213
214 return (test_count.fail_cnt > 0) ? VAL_STATUS_TEST_FAILED : VAL_STATUS_SUCCESS;
215}
216
217
218
219
220
221
222