blob: dc2be67fb896b76904981d2aef1d58952323c285 [file] [log] [blame]
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +01001#!/usr/bin/env python3
2
3""" tfm_build_manager.py:
4
5 Controlling class managing multiple build configruations for tfm """
6
7from __future__ import print_function
8
9__copyright__ = """
10/*
Xinyu Zhang7c038b02021-04-20 10:27:49 +080011 * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010012 *
13 * SPDX-License-Identifier: BSD-3-Clause
14 *
15 */
16 """
Karl Zhang08681e62020-10-30 13:56:03 +080017
18__author__ = "tf-m@lists.trustedfirmware.org"
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010019__project__ = "Trusted Firmware-M Open CI"
Xinyu Zhang06286a92021-07-22 14:00:51 +080020__version__ = "1.4.0"
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010021
22import os
23import sys
Karl Zhangaff558a2020-05-15 14:28:23 +010024from .utils import *
Minos Galanakisea421232019-06-20 17:11:28 +010025from time import time
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010026from copy import deepcopy
27from .utils import gen_cfg_combinations, list_chunks, load_json,\
Minos Galanakisea421232019-06-20 17:11:28 +010028 save_json, print_test, show_progress, \
29 resolve_rel_path
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010030from .structured_task import structuredTask
31from .tfm_builder import TFM_Builder
32
33
Xinyu Zhang38b76742021-11-11 13:57:56 +080034mapPlatform = {"cypress/psoc64": "psoc64",
35 "arm/mps2/an519": "AN519",
36 "arm/mps2/an521": "AN521",
37 "arm/mps2/an539": "AN539",
38 "arm/mps2/sse-200_aws": "SSE-200_AWS",
39 "arm/mps3/an524": "AN524",
40 "arm/musca_b1/sse_200": "MUSCA_B1",
41 "arm/musca_b1/secure_enclave": "MUSCA_B1_SE",
42 "arm/musca_s1": "MUSCA_S1",
43 "stm/stm32l562e_dk": "stm32l562e_dk",
44 "arm/corstone1000": "corstone1000",
45 "nxp/lpcxpresso55s69": "lpcxpresso55s69",
46 "arm/mps3/an547": "AN547",
47 "arm/mps3/corstone_polaris": "Polaris",
48 "lairdconnectivity/bl5340_dvk_cpuapp": "BL5340",
49 "nordic_nrf/nrf5340dk_nrf5340_cpuapp": "nrf5340dk",
50 "nordic_nrf/nrf9160dk_nrf9160": "nrf9160dk",
51 "nuvoton/m2351": "M2351",
52 "nuvoton/m2354": "M2354",
53 "stm/b_u585i_iot02a": "b_u585i_iot02a",
54 "stm/nucleo_l552ze_q": "nucleo_l552ze_q"}
Xinyu Zhang1078e812020-10-15 11:52:36 +080055
56mapCompiler = {"toolchain_GNUARM.cmake": "GNUARM",
57 "toolchain_ARMCLANG.cmake": "ARMCLANG"}
58
Xinyu Zhangc371af62020-10-21 10:41:57 +080059mapTestPsaApi = {"IPC": "FF",
Xinyu Zhang1078e812020-10-15 11:52:36 +080060 "CRYPTO": "CRYPTO",
Xinyu Zhang1078e812020-10-15 11:52:36 +080061 "INITIAL_ATTESTATION": "ATTEST",
Xinyu Zhang39acb412021-07-09 20:35:19 +080062 "STORAGE": "STORAGE"}
Xinyu Zhang1078e812020-10-15 11:52:36 +080063
Xinyu Zhang9fd74242020-10-22 11:30:50 +080064mapProfile = {"profile_small": "SMALL",
Xinyu Zhang9b1aef92021-03-12 15:36:44 +080065 "profile_medium": "MEDIUM",
66 "profile_large": "LARGE"}
Xinyu Zhang1078e812020-10-15 11:52:36 +080067
Feder Liang567e8c22021-10-26 14:16:21 +080068mapSFPOption = {"0": "SFP0",
69 "1": "SFP1",
70 "2": "SFP2"}
Xinyu Zhang1078e812020-10-15 11:52:36 +080071
Xinyu Zhangfd2e1152021-12-17 18:09:01 +080072mapExtraParams = {"": "",
73 "CRYPTO_OFF": ("-DTEST_S_CRYPTO=OFF "
74 "-DTEST_NS_CRYPTO=OFF "),
75 "NS_ATTEST_ON": ("-DTEST_S_CRYPTO=OFF "
76 "-DTEST_NS_CRYPTO=OFF "
77 "-DTEST_S_ITS=OFF "
78 "-DTEST_NS_ITS=OFF "
79 "-DTEST_S_PLATFORM=OFF "
80 "-DTEST_NS_PLATFORM=OFF "
81 "-DTEST_NS_ATTESTATION=ON "
82 "-DTEST_S_ATTESTATION=OFF "
83 "-DTEST_NS_QCBOR=OFF "
84 "-DTEST_S_QCBOR=OFF "
85 "-DTEST_NS_T_COSE=OFF "
86 "-DTEST_S_T_COSE=OFF "
87 "-DTEST_NS_PS=OFF "
Xinyu Zhang67612992021-12-20 14:11:27 +080088 "-DTEST_S_PS=OFF "),
89 "NSCE": "-DTFM_NS_MANAGE_NSID=ON "}
Xinyu Zhangfd2e1152021-12-17 18:09:01 +080090
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010091class TFM_Build_Manager(structuredTask):
92 """ Class that will load a configuration out of a json file, schedule
93 the builds, and produce a report """
94
95 def __init__(self,
96 tfm_dir, # TFM root directory
97 work_dir, # Current working directory(ie logs)
98 cfg_dict, # Input config dictionary of the following form
99 # input_dict = {"PROJ_CONFIG": "ConfigRegression",
100 # "TARGET_PLATFORM": "MUSCA_A",
101 # "COMPILER": "ARMCLANG",
102 # "CMAKE_BUILD_TYPE": "Debug"}
103 report=None, # File to produce report
104 parallel_builds=3, # Number of builds to run in parallel
Minos Galanakisea421232019-06-20 17:11:28 +0100105 build_threads=3, # Number of threads used per build
106 install=False, # Install libraries after build
107 img_sizes=False, # Use arm-none-eabi-size for size info
108 relative_paths=False): # Store relative paths in report
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100109 self._tbm_build_threads = build_threads
110 self._tbm_conc_builds = parallel_builds
111 self._tbm_install = install
Minos Galanakisea421232019-06-20 17:11:28 +0100112 self._tbm_img_sizes = img_sizes
113 self._tbm_relative_paths = relative_paths
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100114
115 # Required by other methods, always set working directory first
116 self._tbm_work_dir = os.path.abspath(os.path.expanduser(work_dir))
117
118 self._tbm_tfm_dir = os.path.abspath(os.path.expanduser(tfm_dir))
119
Karl Zhangaff558a2020-05-15 14:28:23 +0100120 print("bm param tfm_dir %s" % tfm_dir)
121 print("bm %s %s %s" % (work_dir, cfg_dict, self._tbm_work_dir))
Minos Galanakisea421232019-06-20 17:11:28 +0100122 # Internal flag to tag simple (non combination formatted configs)
123 self.simple_config = False
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100124 self._tbm_report = report
125
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100126 self._tbm_cfg = self.load_config(cfg_dict, self._tbm_work_dir)
Minos Galanakisea421232019-06-20 17:11:28 +0100127 self._tbm_build_cfg, \
128 self.tbm_common_cfg = self.parse_config(self._tbm_cfg)
Karl Zhangaff558a2020-05-15 14:28:23 +0100129 self._tfb_code_base_updated = False
130 self._tfb_log_f = "CodeBasePrepare.log"
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100131
132 super(TFM_Build_Manager, self).__init__(name="TFM_Build_Manager")
133
Dean Bircha6ede7e2020-03-13 14:00:33 +0000134 def get_config(self):
135 return list(self._tbm_build_cfg.keys())
Dean Birch5cb5a882020-01-24 11:37:13 +0000136
Dean Bircha6ede7e2020-03-13 14:00:33 +0000137 def print_config_environment(self, config, silence_stderr=False):
Dean Birch5cb5a882020-01-24 11:37:13 +0000138 """
139 For a given build configuration from output of print_config
140 method, print environment variables to build.
141 """
142 if config not in self._tbm_build_cfg:
Dean Bircha6ede7e2020-03-13 14:00:33 +0000143 if not silence_stderr:
144 print("Error: no such config {}".format(config), file=sys.stderr)
Dean Birch5cb5a882020-01-24 11:37:13 +0000145 sys.exit(1)
146 config_details = self._tbm_build_cfg[config]
147 argument_list = [
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000148 "CONFIG_NAME={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800149 "TFM_PLATFORM={}",
150 "TOOLCHAIN_FILE={}",
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800151 "LIB_MODEL={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800152 "ISOLATION_LEVEL={}",
153 "TEST_REGRESSION={}",
154 "TEST_PSA_API={}",
Dean Birch5cb5a882020-01-24 11:37:13 +0000155 "CMAKE_BUILD_TYPE={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800156 "OTP={}",
Dean Birch5cb5a882020-01-24 11:37:13 +0000157 "BL2={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800158 "NS={}",
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800159 "PROFILE={}",
Xinyu Zhang9bfe8a92021-10-28 16:27:12 +0800160 "PARTITION_PS={}",
Feder Liang567e8c22021-10-26 14:16:21 +0800161 "MMIO={}",
162 "FP={}",
Xinyu Zhangfd2e1152021-12-17 18:09:01 +0800163 "LAZY={}",
164 "EXTRA_PARAMS={}"
Dean Birch5cb5a882020-01-24 11:37:13 +0000165 ]
166 print(
167 "\n".join(argument_list)
168 .format(
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000169 config,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800170 config_details.tfm_platform,
171 config_details.toolchain_file,
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800172 config_details.lib_model,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800173 config_details.isolation_level,
174 config_details.test_regression,
175 config_details.test_psa_api,
Dean Birch5cb5a882020-01-24 11:37:13 +0000176 config_details.cmake_build_type,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800177 config_details.with_otp,
178 config_details.with_bl2,
179 config_details.with_ns,
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800180 "N.A" if not config_details.profile else config_details.profile,
Xinyu Zhang9bfe8a92021-10-28 16:27:12 +0800181 config_details.partition_ps,
Feder Liang567e8c22021-10-26 14:16:21 +0800182 config_details.mmio,
183 config_details.fp,
Xinyu Zhangfd2e1152021-12-17 18:09:01 +0800184 config_details.lazy,
185 "N.A" if not config_details.extra_params else config_details.extra_params,
Dean Birch5cb5a882020-01-24 11:37:13 +0000186 )
187 .strip()
188 )
189
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000190 def print_build_commands(self, config, silence_stderr=False):
191 config_details = self._tbm_build_cfg[config]
192 codebase_dir = os.path.join(os.getcwd(),"trusted-firmware-m")
Xinyu Zhangb708f572020-09-15 11:43:46 +0800193 build_dir=os.path.join(os.getcwd(),"trusted-firmware-m/build")
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000194 build_config = self.get_build_config(config_details, config, silence=silence_stderr, build_dir=build_dir, codebase_dir=codebase_dir)
Xinyu Zhang694eb492020-11-04 18:29:08 +0800195 build_commands = [build_config["config_template"]]
196 for command in build_config["build_cmds"]:
197 build_commands.append(command)
Xinyu Zhangb708f572020-09-15 11:43:46 +0800198 print(" ;\n".join(build_commands))
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000199
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100200 def pre_eval(self):
201 """ Tests that need to be run in set-up state """
202 return True
203
204 def pre_exec(self, eval_ret):
205 """ """
206
Minos Galanakisea421232019-06-20 17:11:28 +0100207 def override_tbm_cfg_params(self, config, override_keys, **params):
208 """ Using a dictionay as input, for each key defined in
209 override_keys it will replace the config[key] entries with
210 the key=value parameters provided """
211
212 for key in override_keys:
213 if isinstance(config[key], list):
214 config[key] = [n % params for n in config[key]]
215 elif isinstance(config[key], str):
216 config[key] = config[key] % params
217 else:
218 raise Exception("Config does not contain key %s "
219 "of type %s" % (key, config[key]))
220 return config
221
Karl Zhangaff558a2020-05-15 14:28:23 +0100222 def pre_build(self, build_cfg):
223 print("pre_build start %s \r\nself._tfb_cfg %s\r\n" %
224 (self, build_cfg))
225
226 try:
227 if self._tfb_code_base_updated:
228 print("Code base has been updated")
229 return True
230
231 self._tfb_code_base_updated = True
232
233 if "build_psa_api" in build_cfg:
234 # FF IPC build needs repo manifest update for TFM and PSA arch test
235 if "build_ff_ipc" in build_cfg:
236 print("Checkout to FF IPC code base")
237 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
238 _api_test_manifest = "git checkout . ; python3 tools/scripts/manifest_update.py"
239 if subprocess_log(_api_test_manifest,
240 self._tfb_log_f,
241 append=True,
242 prefix=_api_test_manifest):
243
244 raise Exception("Python Failed please check log: %s" %
245 self._tfb_log_f)
246
247 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py -m tools/tfm_psa_ff_test_manifest_list.yaml append"
248 os.chdir(build_cfg["codebase_root_dir"])
249 if subprocess_log(_api_test_manifest_tfm,
250 self._tfb_log_f,
251 append=True,
252 prefix=_api_test_manifest_tfm):
253
254 raise Exception("Python TFM Failed please check log: %s" %
255 self._tfb_log_f)
256 return True
257
258 print("Checkout to default code base")
259 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
260 _api_test_manifest = "git checkout ."
261 if subprocess_log(_api_test_manifest,
262 self._tfb_log_f,
263 append=True,
264 prefix=_api_test_manifest):
265
266 raise Exception("Python Failed please check log: %s" %
267 self._tfb_log_f)
268
269 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py"
270 os.chdir(build_cfg["codebase_root_dir"])
271 if subprocess_log(_api_test_manifest_tfm,
272 self._tfb_log_f,
273 append=True,
274 prefix=_api_test_manifest_tfm):
275
276 raise Exception("Python TFM Failed please check log: %s" %
277 self._tfb_log_f)
278 finally:
279 print("python pass after builder prepare")
280 os.chdir(build_cfg["codebase_root_dir"] + "/../")
281
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100282 def task_exec(self):
283 """ Create a build pool and execute them in parallel """
284
285 build_pool = []
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100286
Minos Galanakisea421232019-06-20 17:11:28 +0100287 # When a config is flagged as a single build config.
288 # Name is evaluated by config type
289 if self.simple_config:
290
291 build_cfg = deepcopy(self.tbm_common_cfg)
292
293 # Extract the common for all elements of config
294 for key in ["build_cmds", "required_artefacts"]:
295 try:
296 build_cfg[key] = build_cfg[key]["all"]
297 except KeyError:
298 build_cfg[key] = []
299 name = build_cfg["config_type"]
300
301 # Override _tbm_xxx paths in commands
302 # plafrom in not guaranteed without seeds so _tbm_target_platform
303 # is ignored
304 over_dict = {"_tbm_build_dir_": os.path.join(self._tbm_work_dir,
305 name),
306 "_tbm_code_dir_": build_cfg["codebase_root_dir"]}
307
308 build_cfg = self.override_tbm_cfg_params(build_cfg,
309 ["build_cmds",
310 "required_artefacts",
311 "artifact_capture_rex"],
312 **over_dict)
313
314 # Overrides path in expected artefacts
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100315 print("Loading config %s" % name)
Minos Galanakisea421232019-06-20 17:11:28 +0100316
317 build_pool.append(TFM_Builder(
318 name=name,
319 work_dir=self._tbm_work_dir,
320 cfg_dict=build_cfg,
321 build_threads=self._tbm_build_threads,
322 img_sizes=self._tbm_img_sizes,
323 relative_paths=self._tbm_relative_paths))
324 # When a seed pool is provided iterate through the entries
325 # and update platform spefific parameters
326 elif len(self._tbm_build_cfg):
Karl Zhangaff558a2020-05-15 14:28:23 +0100327 print("\r\n_tbm_build_cfg %s\r\n tbm_common_cfg %s\r\n" \
328 % (self._tbm_build_cfg, self.tbm_common_cfg))
Minos Galanakisea421232019-06-20 17:11:28 +0100329 for name, i in self._tbm_build_cfg.items():
330 # Do not modify the original config
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000331 build_cfg = self.get_build_config(i, name)
Karl Zhangaff558a2020-05-15 14:28:23 +0100332 self.pre_build(build_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100333 # Overrides path in expected artefacts
334 print("Loading config %s" % name)
335
336 build_pool.append(TFM_Builder(
337 name=name,
338 work_dir=self._tbm_work_dir,
339 cfg_dict=build_cfg,
340 build_threads=self._tbm_build_threads,
341 img_sizes=self._tbm_img_sizes,
342 relative_paths=self._tbm_relative_paths))
343 else:
344 print("Could not find any configuration. Check the rejection list")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100345
346 status_rep = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100347 build_rep = {}
348 completed_build_count = 0
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100349 print("Build: Running %d parallel build jobs" % self._tbm_conc_builds)
350 for build_pool_slice in list_chunks(build_pool, self._tbm_conc_builds):
351
352 # Start the builds
353 for build in build_pool_slice:
354 # Only produce output for the first build
355 if build_pool_slice.index(build) != 0:
356 build.mute()
357 print("Build: Starting %s" % build.get_name())
358 build.start()
359
360 # Wait for the builds to complete
361 for build in build_pool_slice:
362 # Wait for build to finish
363 build.join()
364 # Similarly print the logs of the other builds as they complete
365 if build_pool_slice.index(build) != 0:
366 build.log()
Minos Galanakisea421232019-06-20 17:11:28 +0100367 completed_build_count += 1
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100368 print("Build: Finished %s" % build.get_name())
Minos Galanakisea421232019-06-20 17:11:28 +0100369 print("Build Progress:")
370 show_progress(completed_build_count, len(build_pool))
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100371
372 # Store status in report
373 status_rep[build.get_name()] = build.get_status()
Minos Galanakisea421232019-06-20 17:11:28 +0100374 build_rep[build.get_name()] = build.report()
375
376 # Include the original input configuration in the report
377
378 metadata = {"input_build_cfg": self._tbm_cfg,
379 "build_dir": self._tbm_work_dir
380 if not self._tbm_relative_paths
381 else resolve_rel_path(self._tbm_work_dir),
382 "time": time()}
383
384 full_rep = {"report": build_rep,
385 "_metadata_": metadata}
386
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100387 # Store the report
388 self.stash("Build Status", status_rep)
389 self.stash("Build Report", full_rep)
390
391 if self._tbm_report:
392 print("Exported build report to file:", self._tbm_report)
393 save_json(self._tbm_report, full_rep)
394
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000395 def get_build_config(self, i, name, silence=False, build_dir=None, codebase_dir=None):
396 psa_build_dir = self._tbm_work_dir + "/" + name + "/BUILD"
397 if not build_dir:
398 build_dir = os.path.join(self._tbm_work_dir, name)
399 else:
400 psa_build_dir = os.path.join(build_dir, "../../psa-arch-tests/api-tests/build")
401 build_cfg = deepcopy(self.tbm_common_cfg)
402 if not codebase_dir:
403 codebase_dir = build_cfg["codebase_root_dir"]
404 else:
405 # Would prefer to do all with the new variable
406 # However, many things use this from build_cfg elsewhere
407 build_cfg["codebase_root_dir"] = codebase_dir
408 # Extract the common for all elements of config
409 for key in ["build_cmds", "required_artefacts"]:
410 try:
411 build_cfg[key] = deepcopy(self.tbm_common_cfg[key]
412 ["all"])
413 except KeyError as E:
414 build_cfg[key] = []
415 # Extract the platform specific elements of config
416 for key in ["build_cmds", "required_artefacts"]:
417 try:
Xinyu Zhang694eb492020-11-04 18:29:08 +0800418 if i.tfm_platform in self.tbm_common_cfg[key].keys() and i.with_ns:
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000419 build_cfg[key] += deepcopy(self.tbm_common_cfg[key]
Xinyu Zhangb708f572020-09-15 11:43:46 +0800420 [i.tfm_platform])
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000421 except Exception as E:
422 pass
Karl Zhang1eed6322020-07-01 15:38:10 +0800423
424 if os.cpu_count() >= 8:
425 #run in a serviver with scripts, parallel build will use CPU numbers
426 thread_no = " -j 2"
427 else:
428 #run in a docker, usually docker with CPUs less than 8
429 thread_no = " -j " + str(os.cpu_count())
Xinyu Zhangb708f572020-09-15 11:43:46 +0800430 build_cfg["build_cmds"][0] += thread_no
431 overwrite_params = {"codebase_root_dir": build_cfg["codebase_root_dir"],
432 "tfm_platform": i.tfm_platform,
433 "toolchain_file": i.toolchain_file,
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800434 "lib_model": i.lib_model,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800435 "isolation_level": i.isolation_level,
436 "test_regression": i.test_regression,
437 "test_psa_api": i.test_psa_api,
438 "cmake_build_type": i.cmake_build_type,
439 "with_otp": i.with_otp,
440 "with_bl2": i.with_bl2,
441 "with_ns": i.with_ns,
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800442 "profile": "" if i.profile=="N.A" else i.profile,
Xinyu Zhang9bfe8a92021-10-28 16:27:12 +0800443 "partition_ps": i.partition_ps,
Feder Liang567e8c22021-10-26 14:16:21 +0800444 "mmio": i.mmio,
445 "fp": i.fp,
Xinyu Zhangfd2e1152021-12-17 18:09:01 +0800446 "lazy": i.lazy,
447 "extra_params": mapExtraParams[i.extra_params]}
Xinyu Zhanga0086022020-11-10 18:11:12 +0800448 if i.test_psa_api == "IPC":
Xinyu Zhangcd1ed962020-11-11 16:00:52 +0800449 overwrite_params["test_psa_api"] += " -DINCLUDE_PANIC_TESTS=1"
Xinyu Zhang8cee3312021-11-12 11:06:39 +0800450 if i.tfm_platform == "arm/musca_b1/sse_200":
451 overwrite_params["test_psa_api"] += " -DITS_RAM_FS=ON -DPS_RAM_FS=ON"
Feder Liang567e8c22021-10-26 14:16:21 +0800452 if i.fp == "1" or i.fp == "2":
453 overwrite_params["test_psa_api"] += " -DTEST_S_FPU=ON -DTEST_NS_FPU=ON"
Xinyu Zhangb708f572020-09-15 11:43:46 +0800454 build_cfg["config_template"] %= overwrite_params
Xinyu Zhang694eb492020-11-04 18:29:08 +0800455 if len(build_cfg["build_cmds"]) > 1:
456 overwrite_build_dir = {"_tbm_build_dir_": build_dir}
457 build_cfg["build_cmds"][1] %= overwrite_build_dir
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000458 return build_cfg
459
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100460 def post_eval(self):
461 """ If a single build failed fail the test """
462 try:
Minos Galanakisea421232019-06-20 17:11:28 +0100463 status_dict = self.unstash("Build Status")
464 if not status_dict:
465 raise Exception()
466 retcode_sum = sum(status_dict.values())
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100467 if retcode_sum != 0:
468 raise Exception()
469 return True
470 except Exception as e:
471 return False
472
473 def post_exec(self, eval_ret):
474 """ Generate a report and fail the script if build == unsuccessfull"""
475
476 self.print_summary()
477 if not eval_ret:
478 print("ERROR: ====> Build Failed! %s" % self.get_name())
479 self.set_status(1)
480 else:
481 print("SUCCESS: ====> Build Complete!")
482 self.set_status(0)
483
484 def get_report(self):
485 """ Expose the internal report to a new object for external classes """
486 return deepcopy(self.unstash("Build Report"))
487
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100488 def load_config(self, config, work_dir):
489 try:
490 # passing config_name param supersseeds fileparam
491 if isinstance(config, dict):
492 ret_cfg = deepcopy(config)
493 elif isinstance(config, str):
494 # If the string does not descrive a file try to look for it in
495 # work directory
496 if not os.path.isfile(config):
497 # remove path from file
498 config_2 = os.path.split(config)[-1]
499 # look in the current working directory
500 config_2 = os.path.join(work_dir, config_2)
501 if not os.path.isfile(config_2):
502 m = "Could not find cfg in %s or %s " % (config,
503 config_2)
504 raise Exception(m)
505 # If fille exists in working directory
506 else:
507 config = config_2
508 ret_cfg = load_json(config)
509
510 else:
511 raise Exception("Need to provide a valid config name or file."
512 "Please use --config/--config-file parameter.")
513 except Exception as e:
514 print("Error:%s \nCould not load a valid config" % e)
515 sys.exit(1)
516
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100517 return ret_cfg
518
519 def parse_config(self, cfg):
520 """ Parse a valid configuration file into a set of build dicts """
521
Minos Galanakisea421232019-06-20 17:11:28 +0100522 ret_cfg = {}
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100523
Minos Galanakisea421232019-06-20 17:11:28 +0100524 # Config entries which are not subject to changes during combinations
525 static_cfg = cfg["common_params"]
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100526
Minos Galanakisea421232019-06-20 17:11:28 +0100527 # Converth the code path to absolute path
528 abs_code_dir = static_cfg["codebase_root_dir"]
529 abs_code_dir = os.path.abspath(os.path.expanduser(abs_code_dir))
530 static_cfg["codebase_root_dir"] = abs_code_dir
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100531
Minos Galanakisea421232019-06-20 17:11:28 +0100532 # seed_params is an optional field. Do not proccess if it is missing
533 if "seed_params" in cfg:
534 comb_cfg = cfg["seed_params"]
535 # Generate a list of all possible confugration combinations
536 ret_cfg = TFM_Build_Manager.generate_config_list(comb_cfg,
537 static_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100538
Xinyu Zhang2c63ce72021-07-23 14:01:59 +0800539 # valid is an optional field. Do not proccess if it is missing
540 if "valid" in cfg:
541 # Valid configurations(Need to build)
542 valid_cfg = cfg["valid"]
543 # Add valid configs to build list
544 ret_cfg.update(TFM_Build_Manager.generate_optional_list(
545 comb_cfg,
546 static_cfg,
547 valid_cfg))
548
Minos Galanakisea421232019-06-20 17:11:28 +0100549 # invalid is an optional field. Do not proccess if it is missing
550 if "invalid" in cfg:
551 # Invalid configurations(Do not build)
552 invalid_cfg = cfg["invalid"]
553 # Remove the rejected entries from the test list
Xinyu Zhang0581b082021-05-17 10:46:57 +0800554 rejection_cfg = TFM_Build_Manager.generate_optional_list(
Minos Galanakisea421232019-06-20 17:11:28 +0100555 comb_cfg,
556 static_cfg,
557 invalid_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100558
Minos Galanakisea421232019-06-20 17:11:28 +0100559 # Subtract the two configurations
560 ret_cfg = {k: v for k, v in ret_cfg.items()
561 if k not in rejection_cfg}
562 self.simple_config = False
563 else:
564 self.simple_config = True
565 return ret_cfg, static_cfg
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100566
Minos Galanakisea421232019-06-20 17:11:28 +0100567 # ----- Override bellow methods when subclassing for other projects ----- #
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100568
Minos Galanakisea421232019-06-20 17:11:28 +0100569 def print_summary(self):
570 """ Print an comprehensive list of the build jobs with their status """
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100571
Minos Galanakisea421232019-06-20 17:11:28 +0100572 try:
573 full_rep = self.unstash("Build Report")["report"]
574 fl = ([k for k, v in full_rep.items() if v['status'] == 'Failed'])
575 ps = ([k for k, v in full_rep.items() if v['status'] == 'Success'])
576 except Exception as E:
Karl Zhangaff558a2020-05-15 14:28:23 +0100577 print("No report generated", E)
Minos Galanakisea421232019-06-20 17:11:28 +0100578 return
579 if fl:
580 print_test(t_list=fl, status="failed", tname="Builds")
581 if ps:
582 print_test(t_list=ps, status="passed", tname="Builds")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100583
Minos Galanakisea421232019-06-20 17:11:28 +0100584 @staticmethod
585 def generate_config_list(seed_config, static_config):
586 """ Generate all possible configuration combinations from a group of
587 lists of compiler options"""
588 config_list = []
589
590 if static_config["config_type"] == "tf-m":
591 cfg_name = "TFM_Build_CFG"
592 # Ensure the fieds are sorted in the desired order
593 # seed_config can be a subset of sort order for configurations with
594 # optional parameters.
595 tags = [n for n in static_config["sort_order"]
596 if n in seed_config.keys()]
Karl Zhangaff558a2020-05-15 14:28:23 +0100597 print("!!!!!!!!!!!gen list %s\r\n" % tags)
Minos Galanakisea421232019-06-20 17:11:28 +0100598
599 data = []
600 for key in tags:
601 data.append(seed_config[key])
602 config_list = gen_cfg_combinations(cfg_name,
603 " ".join(tags),
604 *data)
605 else:
606 print("Not information for project type: %s."
607 " Please check config" % static_config["config_type"])
608
609 ret_cfg = {}
610 # Notify the user for the rejected configuations
611 for i in config_list:
Xinyu Zhang1078e812020-10-15 11:52:36 +0800612 # Convert named tuples to string in a brief format
613 config_param = []
614 config_param.append(mapPlatform[list(i)[0]])
615 config_param.append(mapCompiler[list(i)[1]])
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800616 if list(i)[2]: # LIB_MODEL
617 config_param.append("LIB")
618 else:
619 config_param.append("IPC")
Xinyu Zhang1078e812020-10-15 11:52:36 +0800620 config_param.append(list(i)[3]) # ISOLATION_LEVEL
621 if list(i)[4]: # TEST_REGRESSION
622 config_param.append("REG")
623 if list(i)[5] != "OFF": #TEST_PSA_API
624 config_param.append(mapTestPsaApi[list(i)[5]])
625 config_param.append(list(i)[6]) # BUILD_TYPE
Xinyu Zhanga50432e2020-10-23 18:00:18 +0800626 if list(i)[7] == "ENABLED": # OTP
Xinyu Zhang1078e812020-10-15 11:52:36 +0800627 config_param.append("OTP")
628 if list(i)[8]: # BL2
629 config_param.append("BL2")
630 if list(i)[9]: # NS
631 config_param.append("NS")
632 if list(i)[10]: # PROFILE
633 config_param.append(mapProfile[list(i)[10]])
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800634 if list(i)[11] == "OFF": #PARTITION_PS
635 config_param.append("PSOFF")
Xinyu Zhang9bfe8a92021-10-28 16:27:12 +0800636 if list(i)[12] == "ON":
Xinyu Zhanga1088e22021-11-11 18:02:45 +0800637 config_param.append("MMIO")
Xinyu Zhang67612992021-12-20 14:11:27 +0800638 if list(i)[13] == "1" or list(i)[13] == "2":
639 config_param.append(mapSFPOption[list(i)[13]]) #FP
640 if list(i)[14] == "ON": # LAZY
Feder Liang567e8c22021-10-26 14:16:21 +0800641 config_param.append("SLAZY")
Xinyu Zhang67612992021-12-20 14:11:27 +0800642 if list(i)[15]: # EXTRA_PARAMS
643 config_param.append(list(i)[15])
Xinyu Zhang1078e812020-10-15 11:52:36 +0800644 i_str = "_".join(config_param)
Karl Zhangaff558a2020-05-15 14:28:23 +0100645 ret_cfg[i_str] = i
Minos Galanakisea421232019-06-20 17:11:28 +0100646 return ret_cfg
647
648 @staticmethod
Xinyu Zhang0581b082021-05-17 10:46:57 +0800649 def generate_optional_list(seed_config,
650 static_config,
651 optional_list):
652 optional_cfg = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100653
654 if static_config["config_type"] == "tf-m":
655
Xinyu Zhang0581b082021-05-17 10:46:57 +0800656 # If optional list is empty do nothing
657 if not optional_list:
658 return optional_cfg
Minos Galanakisea421232019-06-20 17:11:28 +0100659
660 tags = [n for n in static_config["sort_order"]
661 if n in seed_config.keys()]
662 sorted_default_lst = [seed_config[k] for k in tags]
663
Xinyu Zhang0581b082021-05-17 10:46:57 +0800664 # If tags are not alligned with optional list entries quit
665 if len(tags) != len(optional_list[0]):
666 print(len(tags), len(optional_list[0]))
Minos Galanakisea421232019-06-20 17:11:28 +0100667 print("Error, tags should be assigned to each "
Xinyu Zhang0581b082021-05-17 10:46:57 +0800668 "of the optional inputs")
Minos Galanakisea421232019-06-20 17:11:28 +0100669 return []
670
671 # Replace wildcard ( "*") entries with every
672 # inluded in cfg variant
Xinyu Zhang0581b082021-05-17 10:46:57 +0800673 for k in optional_list:
Minos Galanakisea421232019-06-20 17:11:28 +0100674 # Pad the omitted values with wildcard char *
675 res_list = list(k) + ["*"] * (5 - len(k))
Xinyu Zhang0581b082021-05-17 10:46:57 +0800676 print("Working on optional input: %s" % (res_list))
Minos Galanakisea421232019-06-20 17:11:28 +0100677
678 for n in range(len(res_list)):
679
680 res_list[n] = [res_list[n]] if res_list[n] != "*" \
681 else sorted_default_lst[n]
682
683 # Generate a configuration and a name for the completed array
Xinyu Zhang0581b082021-05-17 10:46:57 +0800684 op_cfg = TFM_Build_Manager.generate_config_list(
Minos Galanakisea421232019-06-20 17:11:28 +0100685 dict(zip(tags, res_list)),
686 static_config)
687
688 # Append the configuration to the existing ones
Xinyu Zhang0581b082021-05-17 10:46:57 +0800689 optional_cfg = dict(optional_cfg, **op_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100690
Xinyu Zhang0581b082021-05-17 10:46:57 +0800691 # Notify the user for the optional configuations
692 for i in optional_cfg.keys():
693 print("Generating optional config %s" % i)
Minos Galanakisea421232019-06-20 17:11:28 +0100694 else:
695 print("Not information for project type: %s."
696 " Please check config" % static_config["config_type"])
Xinyu Zhang0581b082021-05-17 10:46:57 +0800697 return optional_cfg