blob: d5f3df31fb84d78a0165d2727400e8a5a3234d8f [file] [log] [blame]
Karl Zhang3de5ab12021-05-31 11:45:48 +08001/*
Nik Dewallybacae6c2024-07-30 16:58:14 +01002 * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
Karl Zhang3de5ab12021-05-31 11:45:48 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8/* Objects typed to subclasses of the these classes are constructed and filled in by
9 the parser as it parses test-template lines. There is not necessarily a one-to-one
10 correspondence between the template lines and either the PSA commands generated nor
11 PSA assets they manipulate. PSA assets (which persist through the test) and PSA
12 commands are therefore tracked in separate objects, but referenced here. */
13
14#include <vector>
Karl Zhang3de5ab12021-05-31 11:45:48 +080015
16#include "data_blocks.hpp"
Karl Zhang3de5ab12021-05-31 11:45:48 +080017#include "find_or_create_asset.hpp"
18#include "template_line.hpp"
Karl Zhang3de5ab12021-05-31 11:45:48 +080019#include "psa_call.hpp"
Nik Dewallybacae6c2024-07-30 16:58:14 +010020
21class tf_fuzz_info;
Karl Zhang3de5ab12021-05-31 11:45:48 +080022
23
24
25/**********************************************************************************
26 Methods of class template_line follow:
27**********************************************************************************/
28
29// Constructor, passing in the tf_fuzz object for reference to all objects:
30template_line::template_line (tf_fuzz_info *resources) : test_state(resources)
31{
32 set_data.file_path.assign ("");
33 assign_data_var_specified = false;
34 set_data.flags_string.assign ("");
35 random_asset = psa_asset_usage::all;
36 // if not deleting a random asset of a certain type, then search all as usual
37 target_barrier = "";
38 set_data.file_specified = false;
39 print_data = hash_data = false;
40 call_ser_no = -1;
41 asset_2_name.assign (""); asset_3_name.assign ("");
42 is_remove = false; // will correct this in the remove case
43}
44
45/**********************************************************************************
46 Class template_line methods regarding setting and getting asset-names follow:
47**********************************************************************************/
48
49// Default destructor:
50template_line::~template_line (void)
51{
52 // Destruct the vectors of asset names/IDs:
53 asset_info.asset_name_vector.erase (asset_info.asset_name_vector.begin(),
54 asset_info.asset_name_vector.end());
55 asset_info.asset_id_n_vector.erase (asset_info.asset_id_n_vector.begin(),
56 asset_info.asset_id_n_vector.end());
57}
58
59// (Default constructor not used)
60
61/**********************************************************************************
62 End of methods of class template_line.
63**********************************************************************************/
64
65
66/**********************************************************************************
67 Methods of class sst_template_line follow:
68**********************************************************************************/
69
70// (Currently, no need to specialize copy_template_to_call() for individual SST ops.)
71bool sst_template_line::copy_template_to_call (psa_call *call)
72{
73 // Copy asset info to call object for creation code:
74 call->asset_info = asset_info;
75 call->set_data = set_data;
76 call->set_data.string_specified = set_data.string_specified
77 || set_data.random_data;
78 // not really right, but more convenient to combine these two cases
79 call->assign_data_var_specified = assign_data_var_specified;
80 call->assign_data_var = assign_data_var;
81 call->random_asset = random_asset;
82 if (target_barrier == "") { // barriers are probably not used for SST, but...
83 call->target_barrier = asset_info.get_name();
84 } else {
85 call->target_barrier = target_barrier;
86 }
87 call->set_data.flags_string.assign (set_data.flags_string);
88 call->exp_data = expect;
89 call->exp_data.pf_info_incomplete = true;
90 call->id_string = asset_name; // data = expected
91 call->print_data = print_data;
92 call->hash_data = hash_data;
93 return true;
94}
95
96sst_template_line::sst_template_line (tf_fuzz_info *resources)
97 : template_line (resources)
98{
99 asset_info.asset_type = psa_asset_type::sst;
100}
101
102// Default destructor:
103sst_template_line::~sst_template_line (void)
104{
105 // No real clean-up needed.
106 return; // just to have something to pin a breakpoint onto
107}
108
109// (Default constructor not used)
110
111
112
113/**********************************************************************************
114 End of methods of class sst_template_line.
115**********************************************************************************/
116
117
118/**********************************************************************************
119 Methods of class key_template_line follow:
120**********************************************************************************/
121
122key_template_line::key_template_line (tf_fuzz_info *resources)
123 : template_line (resources)
124{
125 asset_info.asset_type = psa_asset_type::key;
126}
127
128bool key_template_line::copy_template_to_call (psa_call *call)
129{
130 // Copy asset info to call object for creation code:
131 call->asset_info = asset_info;
132 call->set_data = set_data;
133 call->set_data = set_data;
134 call->policy = policy_info;
135 call->asset_2_name = asset_2_name;
136 call->asset_3_name = asset_3_name;
137 call->set_data.string_specified = set_data.string_specified
138 || set_data.random_data;
139 // not really right, but more convenient to combine these two cases
140 call->assign_data_var_specified = assign_data_var_specified;
141 call->assign_data_var = assign_data_var;
142 call->random_asset = random_asset;
143 if (target_barrier == "") { // barriers are probably not used for SST, but...
144 call->target_barrier = asset_info.get_name();
145 } else {
146 call->target_barrier = target_barrier;
147 }
148 call->set_data.flags_string.assign (set_data.flags_string);
149 call->exp_data = expect;
150 call->exp_data.pf_info_incomplete = true;
151 call->id_string = asset_name; // data = expected
152 call->print_data = print_data;
153 call->hash_data = hash_data;
154 return true;
155}
156
157// Create ID-based name:
158string key_template_line::make_id_based_name (uint64_t id_n, string &name)
159{
160 string result = "Key_ID_";
161 result.append(to_string(id_n));
162 return result;
163}
164
165// Default destructor:
166key_template_line::~key_template_line (void)
167{
168 // No real clean-up needed.
169 return; // just to have something to pin a breakpoint onto
170}
171
172// (Default constructor not used)
173
174
175
176/**********************************************************************************
177 End of methods of class key_template_line.
178**********************************************************************************/
179
180
181/**********************************************************************************
182 Methods of class policy_template_line follow:
183**********************************************************************************/
184
185policy_template_line::policy_template_line (tf_fuzz_info *resources)
186 : template_line (resources)
187{
188 asset_info.asset_type = psa_asset_type::policy;
189}
190
191bool policy_template_line::copy_template_to_call (psa_call *call)
192{
193 // Copy asset info to call object for creation code:
194 call->asset_info = asset_info;
195 call->set_data = set_data;
196 call->set_data = set_data;
197 call->policy = policy_info;
198 call->asset_2_name = asset_2_name;
199 call->asset_3_name = asset_3_name;
200 call->set_data.string_specified = set_data.string_specified
201 || set_data.random_data;
202 // not really right, but more convenient to combine these two cases
203 call->assign_data_var_specified = assign_data_var_specified;
204 call->assign_data_var = assign_data_var;
205 call->random_asset = random_asset;
206 if (target_barrier == "") { // barriers are probably not used for SST, but...
207 call->target_barrier = asset_info.get_name();
208 } else {
209 call->target_barrier = target_barrier;
210 }
211 call->set_data.flags_string.assign (set_data.flags_string);
212 call->exp_data = expect;
213 call->exp_data.pf_info_incomplete = true;
214 call->id_string = asset_name; // data = expected
215 call->print_data = print_data;
216 call->hash_data = hash_data;
217 return true;
218}
219
220// Create ID-based name:
221string policy_template_line::make_id_based_name (uint64_t id_n, string &name)
222{
223 string result = "Policy_ID_";
224 result.append(to_string(id_n));
225 //
226 return result;
227}
228
229// Default destructor:
230policy_template_line::~policy_template_line (void)
231{
232 // No real clean-up needed.
233 return; // just to have something to pin a breakpoint onto
234}
235
236// (Default constructor not used)
237
238
239
240/**********************************************************************************
241 End of methods of class policy_template_line.
242**********************************************************************************/
243
244
245/**********************************************************************************
246 Methods of class security_template_line follow:
247**********************************************************************************/
248
249security_template_line::security_template_line (tf_fuzz_info *resources)
250 : template_line (resources)
251{
252}
253
254// Default destructor:
255security_template_line::~security_template_line (void)
256{
257 // No real clean-up needed.
258 return; // just to have something to pin a breakpoint onto
259}
260
261// (Default constructor not used)
262
263
264/**********************************************************************************
265 End of methods of class security_template_line.
266**********************************************************************************/