blob: fc463bacc8bf779ff96632a12fba1e19526a2d7c [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/*
Feder Liang357b1602022-01-11 16:47:49 +080011 * Copyright (c) 2018-2022, 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
Xinyu Zhangfd2e1152021-12-17 18:09:01 +080068mapExtraParams = {"": "",
69 "CRYPTO_OFF": ("-DTEST_S_CRYPTO=OFF "
70 "-DTEST_NS_CRYPTO=OFF "),
Xinyu Zhang7c8d3372021-12-22 11:15:42 +080071 "CRYPTO_ON": ("-DTEST_S_CRYPTO=ON "
72 "-DTEST_NS_CRYPTO=ON "),
Xinyu Zhang3bb01af2021-12-20 14:45:49 +080073 "NSCE": "-DTFM_NS_MANAGE_NSID=ON ",
Feder Liang357b1602022-01-11 16:47:49 +080074 "MMIO": "-DPSA_FRAMEWORK_HAS_MM_IOVEC=ON ",
75 "FPSOFT": "-DCONFIG_TFM_FP=soft ",
76 "FPHARD": "-DCONFIG_TFM_FP=hard ",
77 "FPHARD_LOFF": ("-DCONFIG_TFM_FP=hard "
Xinyu Zhang6071f962022-02-07 15:56:39 +080078 "-DCONFIG_TFM_LAZY_STACKING=OFF "),
79 "FVP": "-DPLATFORM_IS_FVP=True",
Xinyu Zhang6d2dd7c2022-02-07 17:22:55 +080080 "FPGA": "-DPLATFORM_IS_FVP=False",
81 "CC_DRIVER_PSA": "-DCC312_LEGACY_DRIVER_API_ENABLED=OFF"
Feder Liang357b1602022-01-11 16:47:49 +080082 }
Xinyu Zhangfd2e1152021-12-17 18:09:01 +080083
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010084class TFM_Build_Manager(structuredTask):
85 """ Class that will load a configuration out of a json file, schedule
86 the builds, and produce a report """
87
88 def __init__(self,
89 tfm_dir, # TFM root directory
90 work_dir, # Current working directory(ie logs)
91 cfg_dict, # Input config dictionary of the following form
92 # input_dict = {"PROJ_CONFIG": "ConfigRegression",
93 # "TARGET_PLATFORM": "MUSCA_A",
94 # "COMPILER": "ARMCLANG",
95 # "CMAKE_BUILD_TYPE": "Debug"}
96 report=None, # File to produce report
97 parallel_builds=3, # Number of builds to run in parallel
Minos Galanakisea421232019-06-20 17:11:28 +010098 build_threads=3, # Number of threads used per build
99 install=False, # Install libraries after build
100 img_sizes=False, # Use arm-none-eabi-size for size info
101 relative_paths=False): # Store relative paths in report
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100102 self._tbm_build_threads = build_threads
103 self._tbm_conc_builds = parallel_builds
104 self._tbm_install = install
Minos Galanakisea421232019-06-20 17:11:28 +0100105 self._tbm_img_sizes = img_sizes
106 self._tbm_relative_paths = relative_paths
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100107
108 # Required by other methods, always set working directory first
109 self._tbm_work_dir = os.path.abspath(os.path.expanduser(work_dir))
110
111 self._tbm_tfm_dir = os.path.abspath(os.path.expanduser(tfm_dir))
112
Karl Zhangaff558a2020-05-15 14:28:23 +0100113 print("bm param tfm_dir %s" % tfm_dir)
114 print("bm %s %s %s" % (work_dir, cfg_dict, self._tbm_work_dir))
Minos Galanakisea421232019-06-20 17:11:28 +0100115 # Internal flag to tag simple (non combination formatted configs)
116 self.simple_config = False
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100117 self._tbm_report = report
118
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100119 self._tbm_cfg = self.load_config(cfg_dict, self._tbm_work_dir)
Minos Galanakisea421232019-06-20 17:11:28 +0100120 self._tbm_build_cfg, \
121 self.tbm_common_cfg = self.parse_config(self._tbm_cfg)
Karl Zhangaff558a2020-05-15 14:28:23 +0100122 self._tfb_code_base_updated = False
123 self._tfb_log_f = "CodeBasePrepare.log"
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100124
125 super(TFM_Build_Manager, self).__init__(name="TFM_Build_Manager")
126
Xinyu Zhangff5d7712022-01-14 13:48:59 +0800127 def set_compiler_version(self, config):
128 compiler_version = ""
129 # Set GCC version
130 if "GNUARM" in config.toolchain_file:
Feder Liang357b1602022-01-11 16:47:49 +0800131 if "FPHARD" in config.extra_params:
132 # TF-M FPU feature requires GCC v10.3
133 compiler_version = "GCC_10_3"
134 else:
135 # Use GCC v7.3.1 by default
136 compiler_version = "GCC_7_3_1"
Xinyu Zhangff5d7712022-01-14 13:48:59 +0800137 # Set ARMClang version
138 elif "ARMCLANG" in config.toolchain_file:
139 # Use ARMClang v6.13 by default
140 compiler_version = "ARMCLANG_6_13"
141
142 return compiler_version
143
Dean Bircha6ede7e2020-03-13 14:00:33 +0000144 def get_config(self):
145 return list(self._tbm_build_cfg.keys())
Dean Birch5cb5a882020-01-24 11:37:13 +0000146
Dean Bircha6ede7e2020-03-13 14:00:33 +0000147 def print_config_environment(self, config, silence_stderr=False):
Dean Birch5cb5a882020-01-24 11:37:13 +0000148 """
149 For a given build configuration from output of print_config
150 method, print environment variables to build.
151 """
152 if config not in self._tbm_build_cfg:
Dean Bircha6ede7e2020-03-13 14:00:33 +0000153 if not silence_stderr:
154 print("Error: no such config {}".format(config), file=sys.stderr)
Dean Birch5cb5a882020-01-24 11:37:13 +0000155 sys.exit(1)
156 config_details = self._tbm_build_cfg[config]
157 argument_list = [
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000158 "CONFIG_NAME={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800159 "TFM_PLATFORM={}",
160 "TOOLCHAIN_FILE={}",
Xinyu Zhangff5d7712022-01-14 13:48:59 +0800161 "COMPILER_VERSION={}",
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800162 "LIB_MODEL={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800163 "ISOLATION_LEVEL={}",
164 "TEST_REGRESSION={}",
165 "TEST_PSA_API={}",
Dean Birch5cb5a882020-01-24 11:37:13 +0000166 "CMAKE_BUILD_TYPE={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800167 "OTP={}",
Dean Birch5cb5a882020-01-24 11:37:13 +0000168 "BL2={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800169 "NS={}",
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800170 "PROFILE={}",
Xinyu Zhang9bfe8a92021-10-28 16:27:12 +0800171 "PARTITION_PS={}",
Xinyu Zhangfd2e1152021-12-17 18:09:01 +0800172 "EXTRA_PARAMS={}"
Dean Birch5cb5a882020-01-24 11:37:13 +0000173 ]
174 print(
175 "\n".join(argument_list)
176 .format(
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000177 config,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800178 config_details.tfm_platform,
179 config_details.toolchain_file,
Xinyu Zhangff5d7712022-01-14 13:48:59 +0800180 self.set_compiler_version(config_details),
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800181 config_details.lib_model,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800182 config_details.isolation_level,
183 config_details.test_regression,
184 config_details.test_psa_api,
Dean Birch5cb5a882020-01-24 11:37:13 +0000185 config_details.cmake_build_type,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800186 config_details.with_otp,
187 config_details.with_bl2,
188 config_details.with_ns,
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800189 "N.A" if not config_details.profile else config_details.profile,
Xinyu Zhang9bfe8a92021-10-28 16:27:12 +0800190 config_details.partition_ps,
Xinyu Zhangfd2e1152021-12-17 18:09:01 +0800191 "N.A" if not config_details.extra_params else config_details.extra_params,
Dean Birch5cb5a882020-01-24 11:37:13 +0000192 )
193 .strip()
194 )
195
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000196 def print_build_commands(self, config, silence_stderr=False):
197 config_details = self._tbm_build_cfg[config]
198 codebase_dir = os.path.join(os.getcwd(),"trusted-firmware-m")
Xinyu Zhangb708f572020-09-15 11:43:46 +0800199 build_dir=os.path.join(os.getcwd(),"trusted-firmware-m/build")
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000200 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 +0800201 build_commands = [build_config["config_template"]]
202 for command in build_config["build_cmds"]:
203 build_commands.append(command)
Xinyu Zhangb708f572020-09-15 11:43:46 +0800204 print(" ;\n".join(build_commands))
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000205
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100206 def pre_eval(self):
207 """ Tests that need to be run in set-up state """
208 return True
209
210 def pre_exec(self, eval_ret):
211 """ """
212
Minos Galanakisea421232019-06-20 17:11:28 +0100213 def override_tbm_cfg_params(self, config, override_keys, **params):
214 """ Using a dictionay as input, for each key defined in
215 override_keys it will replace the config[key] entries with
216 the key=value parameters provided """
217
218 for key in override_keys:
219 if isinstance(config[key], list):
220 config[key] = [n % params for n in config[key]]
221 elif isinstance(config[key], str):
222 config[key] = config[key] % params
223 else:
224 raise Exception("Config does not contain key %s "
225 "of type %s" % (key, config[key]))
226 return config
227
Karl Zhangaff558a2020-05-15 14:28:23 +0100228 def pre_build(self, build_cfg):
229 print("pre_build start %s \r\nself._tfb_cfg %s\r\n" %
230 (self, build_cfg))
231
232 try:
233 if self._tfb_code_base_updated:
234 print("Code base has been updated")
235 return True
236
237 self._tfb_code_base_updated = True
238
239 if "build_psa_api" in build_cfg:
240 # FF IPC build needs repo manifest update for TFM and PSA arch test
241 if "build_ff_ipc" in build_cfg:
242 print("Checkout to FF IPC code base")
243 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
244 _api_test_manifest = "git checkout . ; python3 tools/scripts/manifest_update.py"
245 if subprocess_log(_api_test_manifest,
246 self._tfb_log_f,
247 append=True,
248 prefix=_api_test_manifest):
249
250 raise Exception("Python Failed please check log: %s" %
251 self._tfb_log_f)
252
253 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py -m tools/tfm_psa_ff_test_manifest_list.yaml append"
254 os.chdir(build_cfg["codebase_root_dir"])
255 if subprocess_log(_api_test_manifest_tfm,
256 self._tfb_log_f,
257 append=True,
258 prefix=_api_test_manifest_tfm):
259
260 raise Exception("Python TFM Failed please check log: %s" %
261 self._tfb_log_f)
262 return True
263
264 print("Checkout to default code base")
265 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
266 _api_test_manifest = "git checkout ."
267 if subprocess_log(_api_test_manifest,
268 self._tfb_log_f,
269 append=True,
270 prefix=_api_test_manifest):
271
272 raise Exception("Python Failed please check log: %s" %
273 self._tfb_log_f)
274
275 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py"
276 os.chdir(build_cfg["codebase_root_dir"])
277 if subprocess_log(_api_test_manifest_tfm,
278 self._tfb_log_f,
279 append=True,
280 prefix=_api_test_manifest_tfm):
281
282 raise Exception("Python TFM Failed please check log: %s" %
283 self._tfb_log_f)
284 finally:
285 print("python pass after builder prepare")
286 os.chdir(build_cfg["codebase_root_dir"] + "/../")
287
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100288 def task_exec(self):
289 """ Create a build pool and execute them in parallel """
290
291 build_pool = []
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100292
Minos Galanakisea421232019-06-20 17:11:28 +0100293 # When a config is flagged as a single build config.
294 # Name is evaluated by config type
295 if self.simple_config:
296
297 build_cfg = deepcopy(self.tbm_common_cfg)
298
299 # Extract the common for all elements of config
300 for key in ["build_cmds", "required_artefacts"]:
301 try:
302 build_cfg[key] = build_cfg[key]["all"]
303 except KeyError:
304 build_cfg[key] = []
305 name = build_cfg["config_type"]
306
307 # Override _tbm_xxx paths in commands
308 # plafrom in not guaranteed without seeds so _tbm_target_platform
309 # is ignored
310 over_dict = {"_tbm_build_dir_": os.path.join(self._tbm_work_dir,
311 name),
312 "_tbm_code_dir_": build_cfg["codebase_root_dir"]}
313
314 build_cfg = self.override_tbm_cfg_params(build_cfg,
315 ["build_cmds",
316 "required_artefacts",
317 "artifact_capture_rex"],
318 **over_dict)
319
320 # Overrides path in expected artefacts
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100321 print("Loading config %s" % name)
Minos Galanakisea421232019-06-20 17:11:28 +0100322
323 build_pool.append(TFM_Builder(
324 name=name,
325 work_dir=self._tbm_work_dir,
326 cfg_dict=build_cfg,
327 build_threads=self._tbm_build_threads,
328 img_sizes=self._tbm_img_sizes,
329 relative_paths=self._tbm_relative_paths))
330 # When a seed pool is provided iterate through the entries
331 # and update platform spefific parameters
332 elif len(self._tbm_build_cfg):
Karl Zhangaff558a2020-05-15 14:28:23 +0100333 print("\r\n_tbm_build_cfg %s\r\n tbm_common_cfg %s\r\n" \
334 % (self._tbm_build_cfg, self.tbm_common_cfg))
Minos Galanakisea421232019-06-20 17:11:28 +0100335 for name, i in self._tbm_build_cfg.items():
336 # Do not modify the original config
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000337 build_cfg = self.get_build_config(i, name)
Karl Zhangaff558a2020-05-15 14:28:23 +0100338 self.pre_build(build_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100339 # Overrides path in expected artefacts
340 print("Loading config %s" % name)
341
342 build_pool.append(TFM_Builder(
343 name=name,
344 work_dir=self._tbm_work_dir,
345 cfg_dict=build_cfg,
346 build_threads=self._tbm_build_threads,
347 img_sizes=self._tbm_img_sizes,
348 relative_paths=self._tbm_relative_paths))
349 else:
350 print("Could not find any configuration. Check the rejection list")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100351
352 status_rep = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100353 build_rep = {}
354 completed_build_count = 0
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100355 print("Build: Running %d parallel build jobs" % self._tbm_conc_builds)
356 for build_pool_slice in list_chunks(build_pool, self._tbm_conc_builds):
357
358 # Start the builds
359 for build in build_pool_slice:
360 # Only produce output for the first build
361 if build_pool_slice.index(build) != 0:
362 build.mute()
363 print("Build: Starting %s" % build.get_name())
364 build.start()
365
366 # Wait for the builds to complete
367 for build in build_pool_slice:
368 # Wait for build to finish
369 build.join()
370 # Similarly print the logs of the other builds as they complete
371 if build_pool_slice.index(build) != 0:
372 build.log()
Minos Galanakisea421232019-06-20 17:11:28 +0100373 completed_build_count += 1
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100374 print("Build: Finished %s" % build.get_name())
Minos Galanakisea421232019-06-20 17:11:28 +0100375 print("Build Progress:")
376 show_progress(completed_build_count, len(build_pool))
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100377
378 # Store status in report
379 status_rep[build.get_name()] = build.get_status()
Minos Galanakisea421232019-06-20 17:11:28 +0100380 build_rep[build.get_name()] = build.report()
381
382 # Include the original input configuration in the report
383
384 metadata = {"input_build_cfg": self._tbm_cfg,
385 "build_dir": self._tbm_work_dir
386 if not self._tbm_relative_paths
387 else resolve_rel_path(self._tbm_work_dir),
388 "time": time()}
389
390 full_rep = {"report": build_rep,
391 "_metadata_": metadata}
392
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100393 # Store the report
394 self.stash("Build Status", status_rep)
395 self.stash("Build Report", full_rep)
396
397 if self._tbm_report:
398 print("Exported build report to file:", self._tbm_report)
399 save_json(self._tbm_report, full_rep)
400
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000401 def get_build_config(self, i, name, silence=False, build_dir=None, codebase_dir=None):
402 psa_build_dir = self._tbm_work_dir + "/" + name + "/BUILD"
403 if not build_dir:
404 build_dir = os.path.join(self._tbm_work_dir, name)
405 else:
406 psa_build_dir = os.path.join(build_dir, "../../psa-arch-tests/api-tests/build")
407 build_cfg = deepcopy(self.tbm_common_cfg)
408 if not codebase_dir:
409 codebase_dir = build_cfg["codebase_root_dir"]
410 else:
411 # Would prefer to do all with the new variable
412 # However, many things use this from build_cfg elsewhere
413 build_cfg["codebase_root_dir"] = codebase_dir
414 # Extract the common for all elements of config
415 for key in ["build_cmds", "required_artefacts"]:
416 try:
417 build_cfg[key] = deepcopy(self.tbm_common_cfg[key]
418 ["all"])
419 except KeyError as E:
420 build_cfg[key] = []
421 # Extract the platform specific elements of config
422 for key in ["build_cmds", "required_artefacts"]:
423 try:
Xinyu Zhang694eb492020-11-04 18:29:08 +0800424 if i.tfm_platform in self.tbm_common_cfg[key].keys() and i.with_ns:
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000425 build_cfg[key] += deepcopy(self.tbm_common_cfg[key]
Xinyu Zhangb708f572020-09-15 11:43:46 +0800426 [i.tfm_platform])
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000427 except Exception as E:
428 pass
Karl Zhang1eed6322020-07-01 15:38:10 +0800429
430 if os.cpu_count() >= 8:
431 #run in a serviver with scripts, parallel build will use CPU numbers
432 thread_no = " -j 2"
433 else:
434 #run in a docker, usually docker with CPUs less than 8
435 thread_no = " -j " + str(os.cpu_count())
Xinyu Zhangb708f572020-09-15 11:43:46 +0800436 build_cfg["build_cmds"][0] += thread_no
437 overwrite_params = {"codebase_root_dir": build_cfg["codebase_root_dir"],
438 "tfm_platform": i.tfm_platform,
439 "toolchain_file": i.toolchain_file,
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800440 "lib_model": i.lib_model,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800441 "isolation_level": i.isolation_level,
442 "test_regression": i.test_regression,
443 "test_psa_api": i.test_psa_api,
444 "cmake_build_type": i.cmake_build_type,
445 "with_otp": i.with_otp,
446 "with_bl2": i.with_bl2,
447 "with_ns": i.with_ns,
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800448 "profile": "" if i.profile=="N.A" else i.profile,
Xinyu Zhang9bfe8a92021-10-28 16:27:12 +0800449 "partition_ps": i.partition_ps,
Xinyu Zhangfd2e1152021-12-17 18:09:01 +0800450 "extra_params": mapExtraParams[i.extra_params]}
Xinyu Zhanga0086022020-11-10 18:11:12 +0800451 if i.test_psa_api == "IPC":
Xinyu Zhangcd1ed962020-11-11 16:00:52 +0800452 overwrite_params["test_psa_api"] += " -DINCLUDE_PANIC_TESTS=1"
Xinyu Zhang8cee3312021-11-12 11:06:39 +0800453 if i.tfm_platform == "arm/musca_b1/sse_200":
454 overwrite_params["test_psa_api"] += " -DITS_RAM_FS=ON -DPS_RAM_FS=ON"
Feder Liang357b1602022-01-11 16:47:49 +0800455 if i.extra_params == "FPHARD" or i.extra_params == "FPHARD_LOFF":
Feder Liang567e8c22021-10-26 14:16:21 +0800456 overwrite_params["test_psa_api"] += " -DTEST_S_FPU=ON -DTEST_NS_FPU=ON"
Xinyu Zhangb708f572020-09-15 11:43:46 +0800457 build_cfg["config_template"] %= overwrite_params
Xinyu Zhang694eb492020-11-04 18:29:08 +0800458 if len(build_cfg["build_cmds"]) > 1:
459 overwrite_build_dir = {"_tbm_build_dir_": build_dir}
460 build_cfg["build_cmds"][1] %= overwrite_build_dir
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000461 return build_cfg
462
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100463 def post_eval(self):
464 """ If a single build failed fail the test """
465 try:
Minos Galanakisea421232019-06-20 17:11:28 +0100466 status_dict = self.unstash("Build Status")
467 if not status_dict:
468 raise Exception()
469 retcode_sum = sum(status_dict.values())
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100470 if retcode_sum != 0:
471 raise Exception()
472 return True
473 except Exception as e:
474 return False
475
476 def post_exec(self, eval_ret):
477 """ Generate a report and fail the script if build == unsuccessfull"""
478
479 self.print_summary()
480 if not eval_ret:
481 print("ERROR: ====> Build Failed! %s" % self.get_name())
482 self.set_status(1)
483 else:
484 print("SUCCESS: ====> Build Complete!")
485 self.set_status(0)
486
487 def get_report(self):
488 """ Expose the internal report to a new object for external classes """
489 return deepcopy(self.unstash("Build Report"))
490
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100491 def load_config(self, config, work_dir):
492 try:
493 # passing config_name param supersseeds fileparam
494 if isinstance(config, dict):
495 ret_cfg = deepcopy(config)
496 elif isinstance(config, str):
497 # If the string does not descrive a file try to look for it in
498 # work directory
499 if not os.path.isfile(config):
500 # remove path from file
501 config_2 = os.path.split(config)[-1]
502 # look in the current working directory
503 config_2 = os.path.join(work_dir, config_2)
504 if not os.path.isfile(config_2):
505 m = "Could not find cfg in %s or %s " % (config,
506 config_2)
507 raise Exception(m)
508 # If fille exists in working directory
509 else:
510 config = config_2
511 ret_cfg = load_json(config)
512
513 else:
514 raise Exception("Need to provide a valid config name or file."
515 "Please use --config/--config-file parameter.")
516 except Exception as e:
517 print("Error:%s \nCould not load a valid config" % e)
518 sys.exit(1)
519
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100520 return ret_cfg
521
522 def parse_config(self, cfg):
523 """ Parse a valid configuration file into a set of build dicts """
524
Minos Galanakisea421232019-06-20 17:11:28 +0100525 ret_cfg = {}
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100526
Minos Galanakisea421232019-06-20 17:11:28 +0100527 # Config entries which are not subject to changes during combinations
528 static_cfg = cfg["common_params"]
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100529
Minos Galanakisea421232019-06-20 17:11:28 +0100530 # Converth the code path to absolute path
531 abs_code_dir = static_cfg["codebase_root_dir"]
532 abs_code_dir = os.path.abspath(os.path.expanduser(abs_code_dir))
533 static_cfg["codebase_root_dir"] = abs_code_dir
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100534
Minos Galanakisea421232019-06-20 17:11:28 +0100535 # seed_params is an optional field. Do not proccess if it is missing
536 if "seed_params" in cfg:
537 comb_cfg = cfg["seed_params"]
538 # Generate a list of all possible confugration combinations
539 ret_cfg = TFM_Build_Manager.generate_config_list(comb_cfg,
540 static_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100541
Xinyu Zhang2c63ce72021-07-23 14:01:59 +0800542 # valid is an optional field. Do not proccess if it is missing
543 if "valid" in cfg:
544 # Valid configurations(Need to build)
545 valid_cfg = cfg["valid"]
546 # Add valid configs to build list
547 ret_cfg.update(TFM_Build_Manager.generate_optional_list(
548 comb_cfg,
549 static_cfg,
550 valid_cfg))
551
Minos Galanakisea421232019-06-20 17:11:28 +0100552 # invalid is an optional field. Do not proccess if it is missing
553 if "invalid" in cfg:
554 # Invalid configurations(Do not build)
555 invalid_cfg = cfg["invalid"]
556 # Remove the rejected entries from the test list
Xinyu Zhang0581b082021-05-17 10:46:57 +0800557 rejection_cfg = TFM_Build_Manager.generate_optional_list(
Minos Galanakisea421232019-06-20 17:11:28 +0100558 comb_cfg,
559 static_cfg,
560 invalid_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100561
Minos Galanakisea421232019-06-20 17:11:28 +0100562 # Subtract the two configurations
563 ret_cfg = {k: v for k, v in ret_cfg.items()
564 if k not in rejection_cfg}
565 self.simple_config = False
566 else:
567 self.simple_config = True
568 return ret_cfg, static_cfg
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100569
Minos Galanakisea421232019-06-20 17:11:28 +0100570 # ----- Override bellow methods when subclassing for other projects ----- #
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100571
Minos Galanakisea421232019-06-20 17:11:28 +0100572 def print_summary(self):
573 """ Print an comprehensive list of the build jobs with their status """
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100574
Minos Galanakisea421232019-06-20 17:11:28 +0100575 try:
576 full_rep = self.unstash("Build Report")["report"]
577 fl = ([k for k, v in full_rep.items() if v['status'] == 'Failed'])
578 ps = ([k for k, v in full_rep.items() if v['status'] == 'Success'])
579 except Exception as E:
Karl Zhangaff558a2020-05-15 14:28:23 +0100580 print("No report generated", E)
Minos Galanakisea421232019-06-20 17:11:28 +0100581 return
582 if fl:
583 print_test(t_list=fl, status="failed", tname="Builds")
584 if ps:
585 print_test(t_list=ps, status="passed", tname="Builds")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100586
Minos Galanakisea421232019-06-20 17:11:28 +0100587 @staticmethod
588 def generate_config_list(seed_config, static_config):
589 """ Generate all possible configuration combinations from a group of
590 lists of compiler options"""
591 config_list = []
592
593 if static_config["config_type"] == "tf-m":
594 cfg_name = "TFM_Build_CFG"
595 # Ensure the fieds are sorted in the desired order
596 # seed_config can be a subset of sort order for configurations with
597 # optional parameters.
598 tags = [n for n in static_config["sort_order"]
599 if n in seed_config.keys()]
Karl Zhangaff558a2020-05-15 14:28:23 +0100600 print("!!!!!!!!!!!gen list %s\r\n" % tags)
Minos Galanakisea421232019-06-20 17:11:28 +0100601
602 data = []
603 for key in tags:
604 data.append(seed_config[key])
605 config_list = gen_cfg_combinations(cfg_name,
606 " ".join(tags),
607 *data)
608 else:
609 print("Not information for project type: %s."
610 " Please check config" % static_config["config_type"])
611
612 ret_cfg = {}
613 # Notify the user for the rejected configuations
614 for i in config_list:
Xinyu Zhang1078e812020-10-15 11:52:36 +0800615 # Convert named tuples to string in a brief format
616 config_param = []
617 config_param.append(mapPlatform[list(i)[0]])
618 config_param.append(mapCompiler[list(i)[1]])
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800619 if list(i)[2]: # LIB_MODEL
620 config_param.append("LIB")
621 else:
622 config_param.append("IPC")
Xinyu Zhang1078e812020-10-15 11:52:36 +0800623 config_param.append(list(i)[3]) # ISOLATION_LEVEL
624 if list(i)[4]: # TEST_REGRESSION
625 config_param.append("REG")
626 if list(i)[5] != "OFF": #TEST_PSA_API
627 config_param.append(mapTestPsaApi[list(i)[5]])
628 config_param.append(list(i)[6]) # BUILD_TYPE
Xinyu Zhanga50432e2020-10-23 18:00:18 +0800629 if list(i)[7] == "ENABLED": # OTP
Xinyu Zhang1078e812020-10-15 11:52:36 +0800630 config_param.append("OTP")
631 if list(i)[8]: # BL2
632 config_param.append("BL2")
633 if list(i)[9]: # NS
634 config_param.append("NS")
635 if list(i)[10]: # PROFILE
636 config_param.append(mapProfile[list(i)[10]])
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800637 if list(i)[11] == "OFF": #PARTITION_PS
638 config_param.append("PSOFF")
Feder Liang357b1602022-01-11 16:47:49 +0800639 if list(i)[12]: # EXTRA_PARAMS
640 config_param.append(list(i)[12])
Xinyu Zhang1078e812020-10-15 11:52:36 +0800641 i_str = "_".join(config_param)
Karl Zhangaff558a2020-05-15 14:28:23 +0100642 ret_cfg[i_str] = i
Minos Galanakisea421232019-06-20 17:11:28 +0100643 return ret_cfg
644
645 @staticmethod
Xinyu Zhang0581b082021-05-17 10:46:57 +0800646 def generate_optional_list(seed_config,
647 static_config,
648 optional_list):
649 optional_cfg = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100650
651 if static_config["config_type"] == "tf-m":
652
Xinyu Zhang0581b082021-05-17 10:46:57 +0800653 # If optional list is empty do nothing
654 if not optional_list:
655 return optional_cfg
Minos Galanakisea421232019-06-20 17:11:28 +0100656
657 tags = [n for n in static_config["sort_order"]
658 if n in seed_config.keys()]
659 sorted_default_lst = [seed_config[k] for k in tags]
660
Xinyu Zhang0581b082021-05-17 10:46:57 +0800661 # If tags are not alligned with optional list entries quit
662 if len(tags) != len(optional_list[0]):
663 print(len(tags), len(optional_list[0]))
Minos Galanakisea421232019-06-20 17:11:28 +0100664 print("Error, tags should be assigned to each "
Xinyu Zhang0581b082021-05-17 10:46:57 +0800665 "of the optional inputs")
Minos Galanakisea421232019-06-20 17:11:28 +0100666 return []
667
668 # Replace wildcard ( "*") entries with every
669 # inluded in cfg variant
Xinyu Zhang0581b082021-05-17 10:46:57 +0800670 for k in optional_list:
Minos Galanakisea421232019-06-20 17:11:28 +0100671 # Pad the omitted values with wildcard char *
672 res_list = list(k) + ["*"] * (5 - len(k))
Xinyu Zhang0581b082021-05-17 10:46:57 +0800673 print("Working on optional input: %s" % (res_list))
Minos Galanakisea421232019-06-20 17:11:28 +0100674
675 for n in range(len(res_list)):
676
677 res_list[n] = [res_list[n]] if res_list[n] != "*" \
678 else sorted_default_lst[n]
679
680 # Generate a configuration and a name for the completed array
Xinyu Zhang0581b082021-05-17 10:46:57 +0800681 op_cfg = TFM_Build_Manager.generate_config_list(
Minos Galanakisea421232019-06-20 17:11:28 +0100682 dict(zip(tags, res_list)),
683 static_config)
684
685 # Append the configuration to the existing ones
Xinyu Zhang0581b082021-05-17 10:46:57 +0800686 optional_cfg = dict(optional_cfg, **op_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100687
Xinyu Zhang0581b082021-05-17 10:46:57 +0800688 # Notify the user for the optional configuations
689 for i in optional_cfg.keys():
690 print("Generating optional config %s" % i)
Minos Galanakisea421232019-06-20 17:11:28 +0100691 else:
692 print("Not information for project type: %s."
693 " Please check config" % static_config["config_type"])
Xinyu Zhang0581b082021-05-17 10:46:57 +0800694 return optional_cfg