blob: 7275866c1328a7a7fb0b0a6c09ffbd197827944f [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 "),
Xinyu Zhang3bb01af2021-12-20 14:45:49 +080089 "NSCE": "-DTFM_NS_MANAGE_NSID=ON ",
90 "MMIO": "-DPSA_FRAMEWORK_HAS_MM_IOVEC=ON "}
Xinyu Zhangfd2e1152021-12-17 18:09:01 +080091
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010092class TFM_Build_Manager(structuredTask):
93 """ Class that will load a configuration out of a json file, schedule
94 the builds, and produce a report """
95
96 def __init__(self,
97 tfm_dir, # TFM root directory
98 work_dir, # Current working directory(ie logs)
99 cfg_dict, # Input config dictionary of the following form
100 # input_dict = {"PROJ_CONFIG": "ConfigRegression",
101 # "TARGET_PLATFORM": "MUSCA_A",
102 # "COMPILER": "ARMCLANG",
103 # "CMAKE_BUILD_TYPE": "Debug"}
104 report=None, # File to produce report
105 parallel_builds=3, # Number of builds to run in parallel
Minos Galanakisea421232019-06-20 17:11:28 +0100106 build_threads=3, # Number of threads used per build
107 install=False, # Install libraries after build
108 img_sizes=False, # Use arm-none-eabi-size for size info
109 relative_paths=False): # Store relative paths in report
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100110 self._tbm_build_threads = build_threads
111 self._tbm_conc_builds = parallel_builds
112 self._tbm_install = install
Minos Galanakisea421232019-06-20 17:11:28 +0100113 self._tbm_img_sizes = img_sizes
114 self._tbm_relative_paths = relative_paths
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100115
116 # Required by other methods, always set working directory first
117 self._tbm_work_dir = os.path.abspath(os.path.expanduser(work_dir))
118
119 self._tbm_tfm_dir = os.path.abspath(os.path.expanduser(tfm_dir))
120
Karl Zhangaff558a2020-05-15 14:28:23 +0100121 print("bm param tfm_dir %s" % tfm_dir)
122 print("bm %s %s %s" % (work_dir, cfg_dict, self._tbm_work_dir))
Minos Galanakisea421232019-06-20 17:11:28 +0100123 # Internal flag to tag simple (non combination formatted configs)
124 self.simple_config = False
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100125 self._tbm_report = report
126
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100127 self._tbm_cfg = self.load_config(cfg_dict, self._tbm_work_dir)
Minos Galanakisea421232019-06-20 17:11:28 +0100128 self._tbm_build_cfg, \
129 self.tbm_common_cfg = self.parse_config(self._tbm_cfg)
Karl Zhangaff558a2020-05-15 14:28:23 +0100130 self._tfb_code_base_updated = False
131 self._tfb_log_f = "CodeBasePrepare.log"
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100132
133 super(TFM_Build_Manager, self).__init__(name="TFM_Build_Manager")
134
Dean Bircha6ede7e2020-03-13 14:00:33 +0000135 def get_config(self):
136 return list(self._tbm_build_cfg.keys())
Dean Birch5cb5a882020-01-24 11:37:13 +0000137
Dean Bircha6ede7e2020-03-13 14:00:33 +0000138 def print_config_environment(self, config, silence_stderr=False):
Dean Birch5cb5a882020-01-24 11:37:13 +0000139 """
140 For a given build configuration from output of print_config
141 method, print environment variables to build.
142 """
143 if config not in self._tbm_build_cfg:
Dean Bircha6ede7e2020-03-13 14:00:33 +0000144 if not silence_stderr:
145 print("Error: no such config {}".format(config), file=sys.stderr)
Dean Birch5cb5a882020-01-24 11:37:13 +0000146 sys.exit(1)
147 config_details = self._tbm_build_cfg[config]
148 argument_list = [
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000149 "CONFIG_NAME={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800150 "TFM_PLATFORM={}",
151 "TOOLCHAIN_FILE={}",
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800152 "LIB_MODEL={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800153 "ISOLATION_LEVEL={}",
154 "TEST_REGRESSION={}",
155 "TEST_PSA_API={}",
Dean Birch5cb5a882020-01-24 11:37:13 +0000156 "CMAKE_BUILD_TYPE={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800157 "OTP={}",
Dean Birch5cb5a882020-01-24 11:37:13 +0000158 "BL2={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800159 "NS={}",
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800160 "PROFILE={}",
Xinyu Zhang9bfe8a92021-10-28 16:27:12 +0800161 "PARTITION_PS={}",
Feder Liang567e8c22021-10-26 14:16:21 +0800162 "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.fp,
Xinyu Zhangfd2e1152021-12-17 18:09:01 +0800183 config_details.lazy,
184 "N.A" if not config_details.extra_params else config_details.extra_params,
Dean Birch5cb5a882020-01-24 11:37:13 +0000185 )
186 .strip()
187 )
188
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000189 def print_build_commands(self, config, silence_stderr=False):
190 config_details = self._tbm_build_cfg[config]
191 codebase_dir = os.path.join(os.getcwd(),"trusted-firmware-m")
Xinyu Zhangb708f572020-09-15 11:43:46 +0800192 build_dir=os.path.join(os.getcwd(),"trusted-firmware-m/build")
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000193 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 +0800194 build_commands = [build_config["config_template"]]
195 for command in build_config["build_cmds"]:
196 build_commands.append(command)
Xinyu Zhangb708f572020-09-15 11:43:46 +0800197 print(" ;\n".join(build_commands))
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000198
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100199 def pre_eval(self):
200 """ Tests that need to be run in set-up state """
201 return True
202
203 def pre_exec(self, eval_ret):
204 """ """
205
Minos Galanakisea421232019-06-20 17:11:28 +0100206 def override_tbm_cfg_params(self, config, override_keys, **params):
207 """ Using a dictionay as input, for each key defined in
208 override_keys it will replace the config[key] entries with
209 the key=value parameters provided """
210
211 for key in override_keys:
212 if isinstance(config[key], list):
213 config[key] = [n % params for n in config[key]]
214 elif isinstance(config[key], str):
215 config[key] = config[key] % params
216 else:
217 raise Exception("Config does not contain key %s "
218 "of type %s" % (key, config[key]))
219 return config
220
Karl Zhangaff558a2020-05-15 14:28:23 +0100221 def pre_build(self, build_cfg):
222 print("pre_build start %s \r\nself._tfb_cfg %s\r\n" %
223 (self, build_cfg))
224
225 try:
226 if self._tfb_code_base_updated:
227 print("Code base has been updated")
228 return True
229
230 self._tfb_code_base_updated = True
231
232 if "build_psa_api" in build_cfg:
233 # FF IPC build needs repo manifest update for TFM and PSA arch test
234 if "build_ff_ipc" in build_cfg:
235 print("Checkout to FF IPC code base")
236 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
237 _api_test_manifest = "git checkout . ; python3 tools/scripts/manifest_update.py"
238 if subprocess_log(_api_test_manifest,
239 self._tfb_log_f,
240 append=True,
241 prefix=_api_test_manifest):
242
243 raise Exception("Python Failed please check log: %s" %
244 self._tfb_log_f)
245
246 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py -m tools/tfm_psa_ff_test_manifest_list.yaml append"
247 os.chdir(build_cfg["codebase_root_dir"])
248 if subprocess_log(_api_test_manifest_tfm,
249 self._tfb_log_f,
250 append=True,
251 prefix=_api_test_manifest_tfm):
252
253 raise Exception("Python TFM Failed please check log: %s" %
254 self._tfb_log_f)
255 return True
256
257 print("Checkout to default code base")
258 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
259 _api_test_manifest = "git checkout ."
260 if subprocess_log(_api_test_manifest,
261 self._tfb_log_f,
262 append=True,
263 prefix=_api_test_manifest):
264
265 raise Exception("Python Failed please check log: %s" %
266 self._tfb_log_f)
267
268 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py"
269 os.chdir(build_cfg["codebase_root_dir"])
270 if subprocess_log(_api_test_manifest_tfm,
271 self._tfb_log_f,
272 append=True,
273 prefix=_api_test_manifest_tfm):
274
275 raise Exception("Python TFM Failed please check log: %s" %
276 self._tfb_log_f)
277 finally:
278 print("python pass after builder prepare")
279 os.chdir(build_cfg["codebase_root_dir"] + "/../")
280
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100281 def task_exec(self):
282 """ Create a build pool and execute them in parallel """
283
284 build_pool = []
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100285
Minos Galanakisea421232019-06-20 17:11:28 +0100286 # When a config is flagged as a single build config.
287 # Name is evaluated by config type
288 if self.simple_config:
289
290 build_cfg = deepcopy(self.tbm_common_cfg)
291
292 # Extract the common for all elements of config
293 for key in ["build_cmds", "required_artefacts"]:
294 try:
295 build_cfg[key] = build_cfg[key]["all"]
296 except KeyError:
297 build_cfg[key] = []
298 name = build_cfg["config_type"]
299
300 # Override _tbm_xxx paths in commands
301 # plafrom in not guaranteed without seeds so _tbm_target_platform
302 # is ignored
303 over_dict = {"_tbm_build_dir_": os.path.join(self._tbm_work_dir,
304 name),
305 "_tbm_code_dir_": build_cfg["codebase_root_dir"]}
306
307 build_cfg = self.override_tbm_cfg_params(build_cfg,
308 ["build_cmds",
309 "required_artefacts",
310 "artifact_capture_rex"],
311 **over_dict)
312
313 # Overrides path in expected artefacts
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100314 print("Loading config %s" % name)
Minos Galanakisea421232019-06-20 17:11:28 +0100315
316 build_pool.append(TFM_Builder(
317 name=name,
318 work_dir=self._tbm_work_dir,
319 cfg_dict=build_cfg,
320 build_threads=self._tbm_build_threads,
321 img_sizes=self._tbm_img_sizes,
322 relative_paths=self._tbm_relative_paths))
323 # When a seed pool is provided iterate through the entries
324 # and update platform spefific parameters
325 elif len(self._tbm_build_cfg):
Karl Zhangaff558a2020-05-15 14:28:23 +0100326 print("\r\n_tbm_build_cfg %s\r\n tbm_common_cfg %s\r\n" \
327 % (self._tbm_build_cfg, self.tbm_common_cfg))
Minos Galanakisea421232019-06-20 17:11:28 +0100328 for name, i in self._tbm_build_cfg.items():
329 # Do not modify the original config
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000330 build_cfg = self.get_build_config(i, name)
Karl Zhangaff558a2020-05-15 14:28:23 +0100331 self.pre_build(build_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100332 # Overrides path in expected artefacts
333 print("Loading config %s" % name)
334
335 build_pool.append(TFM_Builder(
336 name=name,
337 work_dir=self._tbm_work_dir,
338 cfg_dict=build_cfg,
339 build_threads=self._tbm_build_threads,
340 img_sizes=self._tbm_img_sizes,
341 relative_paths=self._tbm_relative_paths))
342 else:
343 print("Could not find any configuration. Check the rejection list")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100344
345 status_rep = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100346 build_rep = {}
347 completed_build_count = 0
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100348 print("Build: Running %d parallel build jobs" % self._tbm_conc_builds)
349 for build_pool_slice in list_chunks(build_pool, self._tbm_conc_builds):
350
351 # Start the builds
352 for build in build_pool_slice:
353 # Only produce output for the first build
354 if build_pool_slice.index(build) != 0:
355 build.mute()
356 print("Build: Starting %s" % build.get_name())
357 build.start()
358
359 # Wait for the builds to complete
360 for build in build_pool_slice:
361 # Wait for build to finish
362 build.join()
363 # Similarly print the logs of the other builds as they complete
364 if build_pool_slice.index(build) != 0:
365 build.log()
Minos Galanakisea421232019-06-20 17:11:28 +0100366 completed_build_count += 1
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100367 print("Build: Finished %s" % build.get_name())
Minos Galanakisea421232019-06-20 17:11:28 +0100368 print("Build Progress:")
369 show_progress(completed_build_count, len(build_pool))
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100370
371 # Store status in report
372 status_rep[build.get_name()] = build.get_status()
Minos Galanakisea421232019-06-20 17:11:28 +0100373 build_rep[build.get_name()] = build.report()
374
375 # Include the original input configuration in the report
376
377 metadata = {"input_build_cfg": self._tbm_cfg,
378 "build_dir": self._tbm_work_dir
379 if not self._tbm_relative_paths
380 else resolve_rel_path(self._tbm_work_dir),
381 "time": time()}
382
383 full_rep = {"report": build_rep,
384 "_metadata_": metadata}
385
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100386 # Store the report
387 self.stash("Build Status", status_rep)
388 self.stash("Build Report", full_rep)
389
390 if self._tbm_report:
391 print("Exported build report to file:", self._tbm_report)
392 save_json(self._tbm_report, full_rep)
393
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000394 def get_build_config(self, i, name, silence=False, build_dir=None, codebase_dir=None):
395 psa_build_dir = self._tbm_work_dir + "/" + name + "/BUILD"
396 if not build_dir:
397 build_dir = os.path.join(self._tbm_work_dir, name)
398 else:
399 psa_build_dir = os.path.join(build_dir, "../../psa-arch-tests/api-tests/build")
400 build_cfg = deepcopy(self.tbm_common_cfg)
401 if not codebase_dir:
402 codebase_dir = build_cfg["codebase_root_dir"]
403 else:
404 # Would prefer to do all with the new variable
405 # However, many things use this from build_cfg elsewhere
406 build_cfg["codebase_root_dir"] = codebase_dir
407 # Extract the common for all elements of config
408 for key in ["build_cmds", "required_artefacts"]:
409 try:
410 build_cfg[key] = deepcopy(self.tbm_common_cfg[key]
411 ["all"])
412 except KeyError as E:
413 build_cfg[key] = []
414 # Extract the platform specific elements of config
415 for key in ["build_cmds", "required_artefacts"]:
416 try:
Xinyu Zhang694eb492020-11-04 18:29:08 +0800417 if i.tfm_platform in self.tbm_common_cfg[key].keys() and i.with_ns:
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000418 build_cfg[key] += deepcopy(self.tbm_common_cfg[key]
Xinyu Zhangb708f572020-09-15 11:43:46 +0800419 [i.tfm_platform])
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000420 except Exception as E:
421 pass
Karl Zhang1eed6322020-07-01 15:38:10 +0800422
423 if os.cpu_count() >= 8:
424 #run in a serviver with scripts, parallel build will use CPU numbers
425 thread_no = " -j 2"
426 else:
427 #run in a docker, usually docker with CPUs less than 8
428 thread_no = " -j " + str(os.cpu_count())
Xinyu Zhangb708f572020-09-15 11:43:46 +0800429 build_cfg["build_cmds"][0] += thread_no
430 overwrite_params = {"codebase_root_dir": build_cfg["codebase_root_dir"],
431 "tfm_platform": i.tfm_platform,
432 "toolchain_file": i.toolchain_file,
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800433 "lib_model": i.lib_model,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800434 "isolation_level": i.isolation_level,
435 "test_regression": i.test_regression,
436 "test_psa_api": i.test_psa_api,
437 "cmake_build_type": i.cmake_build_type,
438 "with_otp": i.with_otp,
439 "with_bl2": i.with_bl2,
440 "with_ns": i.with_ns,
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800441 "profile": "" if i.profile=="N.A" else i.profile,
Xinyu Zhang9bfe8a92021-10-28 16:27:12 +0800442 "partition_ps": i.partition_ps,
Feder Liang567e8c22021-10-26 14:16:21 +0800443 "fp": i.fp,
Xinyu Zhangfd2e1152021-12-17 18:09:01 +0800444 "lazy": i.lazy,
445 "extra_params": mapExtraParams[i.extra_params]}
Xinyu Zhanga0086022020-11-10 18:11:12 +0800446 if i.test_psa_api == "IPC":
Xinyu Zhangcd1ed962020-11-11 16:00:52 +0800447 overwrite_params["test_psa_api"] += " -DINCLUDE_PANIC_TESTS=1"
Xinyu Zhang8cee3312021-11-12 11:06:39 +0800448 if i.tfm_platform == "arm/musca_b1/sse_200":
449 overwrite_params["test_psa_api"] += " -DITS_RAM_FS=ON -DPS_RAM_FS=ON"
Feder Liang567e8c22021-10-26 14:16:21 +0800450 if i.fp == "1" or i.fp == "2":
451 overwrite_params["test_psa_api"] += " -DTEST_S_FPU=ON -DTEST_NS_FPU=ON"
Xinyu Zhangb708f572020-09-15 11:43:46 +0800452 build_cfg["config_template"] %= overwrite_params
Xinyu Zhang694eb492020-11-04 18:29:08 +0800453 if len(build_cfg["build_cmds"]) > 1:
454 overwrite_build_dir = {"_tbm_build_dir_": build_dir}
455 build_cfg["build_cmds"][1] %= overwrite_build_dir
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000456 return build_cfg
457
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100458 def post_eval(self):
459 """ If a single build failed fail the test """
460 try:
Minos Galanakisea421232019-06-20 17:11:28 +0100461 status_dict = self.unstash("Build Status")
462 if not status_dict:
463 raise Exception()
464 retcode_sum = sum(status_dict.values())
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100465 if retcode_sum != 0:
466 raise Exception()
467 return True
468 except Exception as e:
469 return False
470
471 def post_exec(self, eval_ret):
472 """ Generate a report and fail the script if build == unsuccessfull"""
473
474 self.print_summary()
475 if not eval_ret:
476 print("ERROR: ====> Build Failed! %s" % self.get_name())
477 self.set_status(1)
478 else:
479 print("SUCCESS: ====> Build Complete!")
480 self.set_status(0)
481
482 def get_report(self):
483 """ Expose the internal report to a new object for external classes """
484 return deepcopy(self.unstash("Build Report"))
485
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100486 def load_config(self, config, work_dir):
487 try:
488 # passing config_name param supersseeds fileparam
489 if isinstance(config, dict):
490 ret_cfg = deepcopy(config)
491 elif isinstance(config, str):
492 # If the string does not descrive a file try to look for it in
493 # work directory
494 if not os.path.isfile(config):
495 # remove path from file
496 config_2 = os.path.split(config)[-1]
497 # look in the current working directory
498 config_2 = os.path.join(work_dir, config_2)
499 if not os.path.isfile(config_2):
500 m = "Could not find cfg in %s or %s " % (config,
501 config_2)
502 raise Exception(m)
503 # If fille exists in working directory
504 else:
505 config = config_2
506 ret_cfg = load_json(config)
507
508 else:
509 raise Exception("Need to provide a valid config name or file."
510 "Please use --config/--config-file parameter.")
511 except Exception as e:
512 print("Error:%s \nCould not load a valid config" % e)
513 sys.exit(1)
514
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100515 return ret_cfg
516
517 def parse_config(self, cfg):
518 """ Parse a valid configuration file into a set of build dicts """
519
Minos Galanakisea421232019-06-20 17:11:28 +0100520 ret_cfg = {}
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100521
Minos Galanakisea421232019-06-20 17:11:28 +0100522 # Config entries which are not subject to changes during combinations
523 static_cfg = cfg["common_params"]
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100524
Minos Galanakisea421232019-06-20 17:11:28 +0100525 # Converth the code path to absolute path
526 abs_code_dir = static_cfg["codebase_root_dir"]
527 abs_code_dir = os.path.abspath(os.path.expanduser(abs_code_dir))
528 static_cfg["codebase_root_dir"] = abs_code_dir
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100529
Minos Galanakisea421232019-06-20 17:11:28 +0100530 # seed_params is an optional field. Do not proccess if it is missing
531 if "seed_params" in cfg:
532 comb_cfg = cfg["seed_params"]
533 # Generate a list of all possible confugration combinations
534 ret_cfg = TFM_Build_Manager.generate_config_list(comb_cfg,
535 static_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100536
Xinyu Zhang2c63ce72021-07-23 14:01:59 +0800537 # valid is an optional field. Do not proccess if it is missing
538 if "valid" in cfg:
539 # Valid configurations(Need to build)
540 valid_cfg = cfg["valid"]
541 # Add valid configs to build list
542 ret_cfg.update(TFM_Build_Manager.generate_optional_list(
543 comb_cfg,
544 static_cfg,
545 valid_cfg))
546
Minos Galanakisea421232019-06-20 17:11:28 +0100547 # invalid is an optional field. Do not proccess if it is missing
548 if "invalid" in cfg:
549 # Invalid configurations(Do not build)
550 invalid_cfg = cfg["invalid"]
551 # Remove the rejected entries from the test list
Xinyu Zhang0581b082021-05-17 10:46:57 +0800552 rejection_cfg = TFM_Build_Manager.generate_optional_list(
Minos Galanakisea421232019-06-20 17:11:28 +0100553 comb_cfg,
554 static_cfg,
555 invalid_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100556
Minos Galanakisea421232019-06-20 17:11:28 +0100557 # Subtract the two configurations
558 ret_cfg = {k: v for k, v in ret_cfg.items()
559 if k not in rejection_cfg}
560 self.simple_config = False
561 else:
562 self.simple_config = True
563 return ret_cfg, static_cfg
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100564
Minos Galanakisea421232019-06-20 17:11:28 +0100565 # ----- Override bellow methods when subclassing for other projects ----- #
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100566
Minos Galanakisea421232019-06-20 17:11:28 +0100567 def print_summary(self):
568 """ Print an comprehensive list of the build jobs with their status """
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100569
Minos Galanakisea421232019-06-20 17:11:28 +0100570 try:
571 full_rep = self.unstash("Build Report")["report"]
572 fl = ([k for k, v in full_rep.items() if v['status'] == 'Failed'])
573 ps = ([k for k, v in full_rep.items() if v['status'] == 'Success'])
574 except Exception as E:
Karl Zhangaff558a2020-05-15 14:28:23 +0100575 print("No report generated", E)
Minos Galanakisea421232019-06-20 17:11:28 +0100576 return
577 if fl:
578 print_test(t_list=fl, status="failed", tname="Builds")
579 if ps:
580 print_test(t_list=ps, status="passed", tname="Builds")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100581
Minos Galanakisea421232019-06-20 17:11:28 +0100582 @staticmethod
583 def generate_config_list(seed_config, static_config):
584 """ Generate all possible configuration combinations from a group of
585 lists of compiler options"""
586 config_list = []
587
588 if static_config["config_type"] == "tf-m":
589 cfg_name = "TFM_Build_CFG"
590 # Ensure the fieds are sorted in the desired order
591 # seed_config can be a subset of sort order for configurations with
592 # optional parameters.
593 tags = [n for n in static_config["sort_order"]
594 if n in seed_config.keys()]
Karl Zhangaff558a2020-05-15 14:28:23 +0100595 print("!!!!!!!!!!!gen list %s\r\n" % tags)
Minos Galanakisea421232019-06-20 17:11:28 +0100596
597 data = []
598 for key in tags:
599 data.append(seed_config[key])
600 config_list = gen_cfg_combinations(cfg_name,
601 " ".join(tags),
602 *data)
603 else:
604 print("Not information for project type: %s."
605 " Please check config" % static_config["config_type"])
606
607 ret_cfg = {}
608 # Notify the user for the rejected configuations
609 for i in config_list:
Xinyu Zhang1078e812020-10-15 11:52:36 +0800610 # Convert named tuples to string in a brief format
611 config_param = []
612 config_param.append(mapPlatform[list(i)[0]])
613 config_param.append(mapCompiler[list(i)[1]])
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800614 if list(i)[2]: # LIB_MODEL
615 config_param.append("LIB")
616 else:
617 config_param.append("IPC")
Xinyu Zhang1078e812020-10-15 11:52:36 +0800618 config_param.append(list(i)[3]) # ISOLATION_LEVEL
619 if list(i)[4]: # TEST_REGRESSION
620 config_param.append("REG")
621 if list(i)[5] != "OFF": #TEST_PSA_API
622 config_param.append(mapTestPsaApi[list(i)[5]])
623 config_param.append(list(i)[6]) # BUILD_TYPE
Xinyu Zhanga50432e2020-10-23 18:00:18 +0800624 if list(i)[7] == "ENABLED": # OTP
Xinyu Zhang1078e812020-10-15 11:52:36 +0800625 config_param.append("OTP")
626 if list(i)[8]: # BL2
627 config_param.append("BL2")
628 if list(i)[9]: # NS
629 config_param.append("NS")
630 if list(i)[10]: # PROFILE
631 config_param.append(mapProfile[list(i)[10]])
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800632 if list(i)[11] == "OFF": #PARTITION_PS
633 config_param.append("PSOFF")
Xinyu Zhang3bb01af2021-12-20 14:45:49 +0800634 if list(i)[12] == "1" or list(i)[12] == "2":
635 config_param.append(mapSFPOption[list(i)[12]]) #FP
636 if list(i)[13] == "ON": # LAZY
Feder Liang567e8c22021-10-26 14:16:21 +0800637 config_param.append("SLAZY")
Xinyu Zhang3bb01af2021-12-20 14:45:49 +0800638 if list(i)[14]: # EXTRA_PARAMS
639 config_param.append(list(i)[14])
Xinyu Zhang1078e812020-10-15 11:52:36 +0800640 i_str = "_".join(config_param)
Karl Zhangaff558a2020-05-15 14:28:23 +0100641 ret_cfg[i_str] = i
Minos Galanakisea421232019-06-20 17:11:28 +0100642 return ret_cfg
643
644 @staticmethod
Xinyu Zhang0581b082021-05-17 10:46:57 +0800645 def generate_optional_list(seed_config,
646 static_config,
647 optional_list):
648 optional_cfg = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100649
650 if static_config["config_type"] == "tf-m":
651
Xinyu Zhang0581b082021-05-17 10:46:57 +0800652 # If optional list is empty do nothing
653 if not optional_list:
654 return optional_cfg
Minos Galanakisea421232019-06-20 17:11:28 +0100655
656 tags = [n for n in static_config["sort_order"]
657 if n in seed_config.keys()]
658 sorted_default_lst = [seed_config[k] for k in tags]
659
Xinyu Zhang0581b082021-05-17 10:46:57 +0800660 # If tags are not alligned with optional list entries quit
661 if len(tags) != len(optional_list[0]):
662 print(len(tags), len(optional_list[0]))
Minos Galanakisea421232019-06-20 17:11:28 +0100663 print("Error, tags should be assigned to each "
Xinyu Zhang0581b082021-05-17 10:46:57 +0800664 "of the optional inputs")
Minos Galanakisea421232019-06-20 17:11:28 +0100665 return []
666
667 # Replace wildcard ( "*") entries with every
668 # inluded in cfg variant
Xinyu Zhang0581b082021-05-17 10:46:57 +0800669 for k in optional_list:
Minos Galanakisea421232019-06-20 17:11:28 +0100670 # Pad the omitted values with wildcard char *
671 res_list = list(k) + ["*"] * (5 - len(k))
Xinyu Zhang0581b082021-05-17 10:46:57 +0800672 print("Working on optional input: %s" % (res_list))
Minos Galanakisea421232019-06-20 17:11:28 +0100673
674 for n in range(len(res_list)):
675
676 res_list[n] = [res_list[n]] if res_list[n] != "*" \
677 else sorted_default_lst[n]
678
679 # Generate a configuration and a name for the completed array
Xinyu Zhang0581b082021-05-17 10:46:57 +0800680 op_cfg = TFM_Build_Manager.generate_config_list(
Minos Galanakisea421232019-06-20 17:11:28 +0100681 dict(zip(tags, res_list)),
682 static_config)
683
684 # Append the configuration to the existing ones
Xinyu Zhang0581b082021-05-17 10:46:57 +0800685 optional_cfg = dict(optional_cfg, **op_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100686
Xinyu Zhang0581b082021-05-17 10:46:57 +0800687 # Notify the user for the optional configuations
688 for i in optional_cfg.keys():
689 print("Generating optional config %s" % i)
Minos Galanakisea421232019-06-20 17:11:28 +0100690 else:
691 print("Not information for project type: %s."
692 " Please check config" % static_config["config_type"])
Xinyu Zhang0581b082021-05-17 10:46:57 +0800693 return optional_cfg