blob: 10e88a7019a750253e603e8815edd06e9d9a7512 [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;
Karl Zhang3de5ab12021-05-31 11:45:48 +080089 call->id_string = asset_name; // data = expected
90 call->print_data = print_data;
91 call->hash_data = hash_data;
92 return true;
93}
94
95sst_template_line::sst_template_line (tf_fuzz_info *resources)
96 : template_line (resources)
97{
98 asset_info.asset_type = psa_asset_type::sst;
99}
100
101// Default destructor:
102sst_template_line::~sst_template_line (void)
103{
104 // No real clean-up needed.
105 return; // just to have something to pin a breakpoint onto
106}
107
108// (Default constructor not used)
109
110
111
112/**********************************************************************************
113 End of methods of class sst_template_line.
114**********************************************************************************/
115
116
117/**********************************************************************************
118 Methods of class key_template_line follow:
119**********************************************************************************/
120
121key_template_line::key_template_line (tf_fuzz_info *resources)
122 : template_line (resources)
123{
124 asset_info.asset_type = psa_asset_type::key;
125}
126
127bool key_template_line::copy_template_to_call (psa_call *call)
128{
129 // Copy asset info to call object for creation code:
130 call->asset_info = asset_info;
131 call->set_data = set_data;
132 call->set_data = set_data;
133 call->policy = policy_info;
134 call->asset_2_name = asset_2_name;
135 call->asset_3_name = asset_3_name;
136 call->set_data.string_specified = set_data.string_specified
137 || set_data.random_data;
138 // not really right, but more convenient to combine these two cases
139 call->assign_data_var_specified = assign_data_var_specified;
140 call->assign_data_var = assign_data_var;
141 call->random_asset = random_asset;
142 if (target_barrier == "") { // barriers are probably not used for SST, but...
143 call->target_barrier = asset_info.get_name();
144 } else {
145 call->target_barrier = target_barrier;
146 }
147 call->set_data.flags_string.assign (set_data.flags_string);
148 call->exp_data = expect;
Karl Zhang3de5ab12021-05-31 11:45:48 +0800149 call->id_string = asset_name; // data = expected
150 call->print_data = print_data;
151 call->hash_data = hash_data;
152 return true;
153}
154
155// Create ID-based name:
156string key_template_line::make_id_based_name (uint64_t id_n, string &name)
157{
158 string result = "Key_ID_";
159 result.append(to_string(id_n));
160 return result;
161}
162
163// Default destructor:
164key_template_line::~key_template_line (void)
165{
166 // No real clean-up needed.
167 return; // just to have something to pin a breakpoint onto
168}
169
170// (Default constructor not used)
171
172
173
174/**********************************************************************************
175 End of methods of class key_template_line.
176**********************************************************************************/
177
178
179/**********************************************************************************
180 Methods of class policy_template_line follow:
181**********************************************************************************/
182
183policy_template_line::policy_template_line (tf_fuzz_info *resources)
184 : template_line (resources)
185{
186 asset_info.asset_type = psa_asset_type::policy;
187}
188
189bool policy_template_line::copy_template_to_call (psa_call *call)
190{
191 // Copy asset info to call object for creation code:
192 call->asset_info = asset_info;
193 call->set_data = set_data;
194 call->set_data = set_data;
195 call->policy = policy_info;
196 call->asset_2_name = asset_2_name;
197 call->asset_3_name = asset_3_name;
198 call->set_data.string_specified = set_data.string_specified
199 || set_data.random_data;
200 // not really right, but more convenient to combine these two cases
201 call->assign_data_var_specified = assign_data_var_specified;
202 call->assign_data_var = assign_data_var;
203 call->random_asset = random_asset;
204 if (target_barrier == "") { // barriers are probably not used for SST, but...
205 call->target_barrier = asset_info.get_name();
206 } else {
207 call->target_barrier = target_barrier;
208 }
209 call->set_data.flags_string.assign (set_data.flags_string);
210 call->exp_data = expect;
Karl Zhang3de5ab12021-05-31 11:45:48 +0800211 call->id_string = asset_name; // data = expected
212 call->print_data = print_data;
213 call->hash_data = hash_data;
214 return true;
215}
216
217// Create ID-based name:
218string policy_template_line::make_id_based_name (uint64_t id_n, string &name)
219{
220 string result = "Policy_ID_";
221 result.append(to_string(id_n));
222 //
223 return result;
224}
225
226// Default destructor:
227policy_template_line::~policy_template_line (void)
228{
229 // No real clean-up needed.
230 return; // just to have something to pin a breakpoint onto
231}
232
233// (Default constructor not used)
234
235
236
237/**********************************************************************************
238 End of methods of class policy_template_line.
239**********************************************************************************/
240
241
242/**********************************************************************************
243 Methods of class security_template_line follow:
244**********************************************************************************/
245
246security_template_line::security_template_line (tf_fuzz_info *resources)
247 : template_line (resources)
248{
249}
250
251// Default destructor:
252security_template_line::~security_template_line (void)
253{
254 // No real clean-up needed.
255 return; // just to have something to pin a breakpoint onto
256}
257
258// (Default constructor not used)
259
260
261/**********************************************************************************
262 End of methods of class security_template_line.
263**********************************************************************************/