blob: 2cd739714c9d9a609f0d915e5d98151b8371800d [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/*
11 * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
12 *
13 * SPDX-License-Identifier: BSD-3-Clause
14 *
15 */
16 """
17__author__ = "Minos Galanakis"
18__email__ = "minos.galanakis@linaro.org"
19__project__ = "Trusted Firmware-M Open CI"
20__status__ = "stable"
Minos Galanakisea421232019-06-20 17:11:28 +010021__version__ = "1.1"
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010022
23import os
24import sys
Karl Zhangaff558a2020-05-15 14:28:23 +010025from .utils import *
Minos Galanakisea421232019-06-20 17:11:28 +010026from time import time
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010027from copy import deepcopy
28from .utils import gen_cfg_combinations, list_chunks, load_json,\
Minos Galanakisea421232019-06-20 17:11:28 +010029 save_json, print_test, show_progress, \
30 resolve_rel_path
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010031from .structured_task import structuredTask
32from .tfm_builder import TFM_Builder
33
34
35class TFM_Build_Manager(structuredTask):
36 """ Class that will load a configuration out of a json file, schedule
37 the builds, and produce a report """
38
39 def __init__(self,
40 tfm_dir, # TFM root directory
41 work_dir, # Current working directory(ie logs)
42 cfg_dict, # Input config dictionary of the following form
43 # input_dict = {"PROJ_CONFIG": "ConfigRegression",
44 # "TARGET_PLATFORM": "MUSCA_A",
45 # "COMPILER": "ARMCLANG",
46 # "CMAKE_BUILD_TYPE": "Debug"}
47 report=None, # File to produce report
48 parallel_builds=3, # Number of builds to run in parallel
Minos Galanakisea421232019-06-20 17:11:28 +010049 build_threads=3, # Number of threads used per build
50 install=False, # Install libraries after build
51 img_sizes=False, # Use arm-none-eabi-size for size info
52 relative_paths=False): # Store relative paths in report
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010053 self._tbm_build_threads = build_threads
54 self._tbm_conc_builds = parallel_builds
55 self._tbm_install = install
Minos Galanakisea421232019-06-20 17:11:28 +010056 self._tbm_img_sizes = img_sizes
57 self._tbm_relative_paths = relative_paths
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010058
59 # Required by other methods, always set working directory first
60 self._tbm_work_dir = os.path.abspath(os.path.expanduser(work_dir))
61
62 self._tbm_tfm_dir = os.path.abspath(os.path.expanduser(tfm_dir))
63
Karl Zhangaff558a2020-05-15 14:28:23 +010064 print("bm param tfm_dir %s" % tfm_dir)
65 print("bm %s %s %s" % (work_dir, cfg_dict, self._tbm_work_dir))
Minos Galanakisea421232019-06-20 17:11:28 +010066 # Internal flag to tag simple (non combination formatted configs)
67 self.simple_config = False
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010068 self._tbm_report = report
69
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010070 self._tbm_cfg = self.load_config(cfg_dict, self._tbm_work_dir)
Minos Galanakisea421232019-06-20 17:11:28 +010071 self._tbm_build_cfg, \
72 self.tbm_common_cfg = self.parse_config(self._tbm_cfg)
Karl Zhangaff558a2020-05-15 14:28:23 +010073 self._tfb_code_base_updated = False
74 self._tfb_log_f = "CodeBasePrepare.log"
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010075
76 super(TFM_Build_Manager, self).__init__(name="TFM_Build_Manager")
77
Dean Bircha6ede7e2020-03-13 14:00:33 +000078 def get_config(self):
79 return list(self._tbm_build_cfg.keys())
Dean Birch5cb5a882020-01-24 11:37:13 +000080
Dean Bircha6ede7e2020-03-13 14:00:33 +000081 def print_config_environment(self, config, silence_stderr=False):
Dean Birch5cb5a882020-01-24 11:37:13 +000082 """
83 For a given build configuration from output of print_config
84 method, print environment variables to build.
85 """
86 if config not in self._tbm_build_cfg:
Dean Bircha6ede7e2020-03-13 14:00:33 +000087 if not silence_stderr:
88 print("Error: no such config {}".format(config), file=sys.stderr)
Dean Birch5cb5a882020-01-24 11:37:13 +000089 sys.exit(1)
90 config_details = self._tbm_build_cfg[config]
91 argument_list = [
Dean Birchd0f9f8c2020-03-26 11:10:33 +000092 "CONFIG_NAME={}",
Dean Birch5cb5a882020-01-24 11:37:13 +000093 "TARGET_PLATFORM={}",
94 "COMPILER={}",
95 "PROJ_CONFIG={}",
96 "CMAKE_BUILD_TYPE={}",
97 "BL2={}",
Dean Birchd0f9f8c2020-03-26 11:10:33 +000098 "PSA_API_SUITE={}"
Dean Birch5cb5a882020-01-24 11:37:13 +000099 ]
100 print(
101 "\n".join(argument_list)
102 .format(
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000103 config,
Dean Birch5cb5a882020-01-24 11:37:13 +0000104 config_details.target_platform,
105 config_details.compiler,
106 config_details.proj_config,
107 config_details.cmake_build_type,
108 config_details.with_mcuboot,
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000109 getattr(config_details, 'psa_api_suit', "''")
Dean Birch5cb5a882020-01-24 11:37:13 +0000110 )
111 .strip()
112 )
113
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000114 def print_build_commands(self, config, silence_stderr=False):
115 config_details = self._tbm_build_cfg[config]
116 codebase_dir = os.path.join(os.getcwd(),"trusted-firmware-m")
117 build_dir=os.path.join(os.getcwd(),'trusted-firmware-m/build')
118 build_config = self.get_build_config(config_details, config, silence=silence_stderr, build_dir=build_dir, codebase_dir=codebase_dir)
119 build_commands = build_config['build_cmds']
120 psa_commands = build_config.get('build_psa_api', None)
121 if psa_commands:
122 manifest_command_list = []
123 # Also need manifest commands
124 if 'build_ff_ipc' in build_config:
125 manifest_command_list += [
126 "pushd ../../psa-arch-tests/api-tests",
127 "python3 tools/scripts/manifest_update.py",
128 "popd",
129 "pushd ../",
130 "python3 tools/tfm_parse_manifest_list.py -m tools/tfm_psa_ff_test_manifest_list.yaml append",
131 "popd",
132 ]
133 else:
134 manifest_command_list += [
135 "pushd ..",
136 "python3 tools/tfm_parse_manifest_list.py",
137 "popd"
138 ]
139 psa_command_list = psa_commands.split(" ; ")
140 build_commands = manifest_command_list + ["mkdir ../../psa-arch-tests/api-tests/build","pushd ../../psa-arch-tests/api-tests/build"] + psa_command_list + ["popd"] + build_commands
141 print(" ;\n".join(build_commands))
142
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100143 def pre_eval(self):
144 """ Tests that need to be run in set-up state """
145 return True
146
147 def pre_exec(self, eval_ret):
148 """ """
149
Minos Galanakisea421232019-06-20 17:11:28 +0100150 def override_tbm_cfg_params(self, config, override_keys, **params):
151 """ Using a dictionay as input, for each key defined in
152 override_keys it will replace the config[key] entries with
153 the key=value parameters provided """
154
155 for key in override_keys:
156 if isinstance(config[key], list):
157 config[key] = [n % params for n in config[key]]
158 elif isinstance(config[key], str):
159 config[key] = config[key] % params
160 else:
161 raise Exception("Config does not contain key %s "
162 "of type %s" % (key, config[key]))
163 return config
164
Karl Zhangaff558a2020-05-15 14:28:23 +0100165 def pre_build(self, build_cfg):
166 print("pre_build start %s \r\nself._tfb_cfg %s\r\n" %
167 (self, build_cfg))
168
169 try:
170 if self._tfb_code_base_updated:
171 print("Code base has been updated")
172 return True
173
174 self._tfb_code_base_updated = True
175
176 if "build_psa_api" in build_cfg:
177 # FF IPC build needs repo manifest update for TFM and PSA arch test
178 if "build_ff_ipc" in build_cfg:
179 print("Checkout to FF IPC code base")
180 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
181 _api_test_manifest = "git checkout . ; python3 tools/scripts/manifest_update.py"
182 if subprocess_log(_api_test_manifest,
183 self._tfb_log_f,
184 append=True,
185 prefix=_api_test_manifest):
186
187 raise Exception("Python Failed please check log: %s" %
188 self._tfb_log_f)
189
190 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py -m tools/tfm_psa_ff_test_manifest_list.yaml append"
191 os.chdir(build_cfg["codebase_root_dir"])
192 if subprocess_log(_api_test_manifest_tfm,
193 self._tfb_log_f,
194 append=True,
195 prefix=_api_test_manifest_tfm):
196
197 raise Exception("Python TFM Failed please check log: %s" %
198 self._tfb_log_f)
199 return True
200
201 print("Checkout to default code base")
202 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
203 _api_test_manifest = "git checkout ."
204 if subprocess_log(_api_test_manifest,
205 self._tfb_log_f,
206 append=True,
207 prefix=_api_test_manifest):
208
209 raise Exception("Python Failed please check log: %s" %
210 self._tfb_log_f)
211
212 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py"
213 os.chdir(build_cfg["codebase_root_dir"])
214 if subprocess_log(_api_test_manifest_tfm,
215 self._tfb_log_f,
216 append=True,
217 prefix=_api_test_manifest_tfm):
218
219 raise Exception("Python TFM Failed please check log: %s" %
220 self._tfb_log_f)
221 finally:
222 print("python pass after builder prepare")
223 os.chdir(build_cfg["codebase_root_dir"] + "/../")
224
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100225 def task_exec(self):
226 """ Create a build pool and execute them in parallel """
227
228 build_pool = []
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100229
Minos Galanakisea421232019-06-20 17:11:28 +0100230 # When a config is flagged as a single build config.
231 # Name is evaluated by config type
232 if self.simple_config:
233
234 build_cfg = deepcopy(self.tbm_common_cfg)
235
236 # Extract the common for all elements of config
237 for key in ["build_cmds", "required_artefacts"]:
238 try:
239 build_cfg[key] = build_cfg[key]["all"]
240 except KeyError:
241 build_cfg[key] = []
242 name = build_cfg["config_type"]
243
244 # Override _tbm_xxx paths in commands
245 # plafrom in not guaranteed without seeds so _tbm_target_platform
246 # is ignored
247 over_dict = {"_tbm_build_dir_": os.path.join(self._tbm_work_dir,
248 name),
249 "_tbm_code_dir_": build_cfg["codebase_root_dir"]}
250
251 build_cfg = self.override_tbm_cfg_params(build_cfg,
252 ["build_cmds",
253 "required_artefacts",
254 "artifact_capture_rex"],
255 **over_dict)
256
257 # Overrides path in expected artefacts
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100258 print("Loading config %s" % name)
Minos Galanakisea421232019-06-20 17:11:28 +0100259
260 build_pool.append(TFM_Builder(
261 name=name,
262 work_dir=self._tbm_work_dir,
263 cfg_dict=build_cfg,
264 build_threads=self._tbm_build_threads,
265 img_sizes=self._tbm_img_sizes,
266 relative_paths=self._tbm_relative_paths))
267 # When a seed pool is provided iterate through the entries
268 # and update platform spefific parameters
269 elif len(self._tbm_build_cfg):
Karl Zhangaff558a2020-05-15 14:28:23 +0100270 print("\r\n_tbm_build_cfg %s\r\n tbm_common_cfg %s\r\n" \
271 % (self._tbm_build_cfg, self.tbm_common_cfg))
Minos Galanakisea421232019-06-20 17:11:28 +0100272 for name, i in self._tbm_build_cfg.items():
273 # Do not modify the original config
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000274 build_cfg = self.get_build_config(i, name)
Karl Zhangaff558a2020-05-15 14:28:23 +0100275 self.pre_build(build_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100276 # Overrides path in expected artefacts
277 print("Loading config %s" % name)
278
279 build_pool.append(TFM_Builder(
280 name=name,
281 work_dir=self._tbm_work_dir,
282 cfg_dict=build_cfg,
283 build_threads=self._tbm_build_threads,
284 img_sizes=self._tbm_img_sizes,
285 relative_paths=self._tbm_relative_paths))
286 else:
287 print("Could not find any configuration. Check the rejection list")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100288
289 status_rep = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100290 build_rep = {}
291 completed_build_count = 0
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100292 print("Build: Running %d parallel build jobs" % self._tbm_conc_builds)
293 for build_pool_slice in list_chunks(build_pool, self._tbm_conc_builds):
294
295 # Start the builds
296 for build in build_pool_slice:
297 # Only produce output for the first build
298 if build_pool_slice.index(build) != 0:
299 build.mute()
300 print("Build: Starting %s" % build.get_name())
301 build.start()
302
303 # Wait for the builds to complete
304 for build in build_pool_slice:
305 # Wait for build to finish
306 build.join()
307 # Similarly print the logs of the other builds as they complete
308 if build_pool_slice.index(build) != 0:
309 build.log()
Minos Galanakisea421232019-06-20 17:11:28 +0100310 completed_build_count += 1
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100311 print("Build: Finished %s" % build.get_name())
Minos Galanakisea421232019-06-20 17:11:28 +0100312 print("Build Progress:")
313 show_progress(completed_build_count, len(build_pool))
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100314
315 # Store status in report
316 status_rep[build.get_name()] = build.get_status()
Minos Galanakisea421232019-06-20 17:11:28 +0100317 build_rep[build.get_name()] = build.report()
318
319 # Include the original input configuration in the report
320
321 metadata = {"input_build_cfg": self._tbm_cfg,
322 "build_dir": self._tbm_work_dir
323 if not self._tbm_relative_paths
324 else resolve_rel_path(self._tbm_work_dir),
325 "time": time()}
326
327 full_rep = {"report": build_rep,
328 "_metadata_": metadata}
329
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100330 # Store the report
331 self.stash("Build Status", status_rep)
332 self.stash("Build Report", full_rep)
333
334 if self._tbm_report:
335 print("Exported build report to file:", self._tbm_report)
336 save_json(self._tbm_report, full_rep)
337
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000338 def get_build_config(self, i, name, silence=False, build_dir=None, codebase_dir=None):
339 psa_build_dir = self._tbm_work_dir + "/" + name + "/BUILD"
340 if not build_dir:
341 build_dir = os.path.join(self._tbm_work_dir, name)
342 else:
343 psa_build_dir = os.path.join(build_dir, "../../psa-arch-tests/api-tests/build")
344 build_cfg = deepcopy(self.tbm_common_cfg)
345 if not codebase_dir:
346 codebase_dir = build_cfg["codebase_root_dir"]
347 else:
348 # Would prefer to do all with the new variable
349 # However, many things use this from build_cfg elsewhere
350 build_cfg["codebase_root_dir"] = codebase_dir
351 # Extract the common for all elements of config
352 for key in ["build_cmds", "required_artefacts"]:
353 try:
354 build_cfg[key] = deepcopy(self.tbm_common_cfg[key]
355 ["all"])
356 except KeyError as E:
357 build_cfg[key] = []
358 # Extract the platform specific elements of config
359 for key in ["build_cmds", "required_artefacts"]:
360 try:
361 if i.target_platform in self.tbm_common_cfg[key].keys():
362 build_cfg[key] += deepcopy(self.tbm_common_cfg[key]
363 [i.target_platform])
364 except Exception as E:
365 pass
Karl Zhang1eed6322020-07-01 15:38:10 +0800366
367 if os.cpu_count() >= 8:
368 #run in a serviver with scripts, parallel build will use CPU numbers
369 thread_no = " -j 2"
370 else:
371 #run in a docker, usually docker with CPUs less than 8
372 thread_no = " -j " + str(os.cpu_count())
373
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000374 # Merge the two dictionaries since the template may contain
375 # fixed and combinations seed parameters
376 if i.proj_config.startswith("ConfigPsaApiTest"):
377 # PSA API tests only
378 # TODO i._asdict()["tfm_build_dir"] = self._tbm_work_dir
379 cmd0 = build_cfg["config_template_psa_api"] % \
380 dict(dict(i._asdict()), **build_cfg)
381 cmd0 += " -DPSA_API_TEST_BUILD_PATH=" + psa_build_dir
382
383 if i.psa_api_suit == "FF":
384 cmd0 += " -DPSA_API_TEST_IPC=ON"
385 cmd2 = "cmake " + codebase_dir + "/../psa-arch-tests/api-tests/ " + \
386 "-G\"Unix Makefiles\" -DTARGET=tgt_ff_tfm_" + \
387 i.target_platform.lower() + " -DCPU_ARCH=armv8m_ml -DTOOLCHAIN=" + \
388 i.compiler + " -DSUITE=IPC -DPSA_INCLUDE_PATHS=\"" + \
389 codebase_dir + "/interface/include/"
390
391 cmd2 += ";" + codebase_dir + \
392 "/../psa-arch-tests/api-tests/platform/manifests\"" + \
393 " -DINCLUDE_PANIC_TESTS=1 -DPLATFORM_PSA_ISOLATION_LEVEL=" + \
394 (("2") if i.proj_config.find("TfmLevel2") > 0 else "1") + \
395 " -DSP_HEAP_MEM_SUPP=0"
396 if i.target_platform == "MUSCA_B1":
397 cmd0 += " -DSST_RAM_FS=ON"
398 build_cfg["build_ff_ipc"] = "IPC"
399 else:
400 cmd0 += " -DPSA_API_TEST_" + i.psa_api_suit + "=ON"
401 cmd2 = "cmake " + codebase_dir + "/../psa-arch-tests/api-tests/ " + \
402 "-G\"Unix Makefiles\" -DTARGET=tgt_dev_apis_tfm_" + \
403 i.target_platform.lower() + " -DCPU_ARCH=armv8m_ml -DTOOLCHAIN=" + \
404 i.compiler + " -DSUITE=" + i.psa_api_suit + " -DPSA_INCLUDE_PATHS=\"" + \
405 codebase_dir + "/interface/include/\""
406
407 cmd2 += " -DCMAKE_BUILD_TYPE=" + i.cmake_build_type
408
Karl Zhang1eed6322020-07-01 15:38:10 +0800409 cmd3 = "cmake --build ." + thread_no
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000410 build_cfg["build_psa_api"] = cmd2 + " ; " + cmd3
411
412 else:
413 cmd0 = build_cfg["config_template"] % \
414 dict(dict(i._asdict()), **build_cfg)
415 try:
416 if i.__str__().find("with_OTP") > 0:
417 cmd0 += " -DCRYPTO_HW_ACCELERATOR_OTP_STATE=ENABLED"
Karl Zhang1eed6322020-07-01 15:38:10 +0800418
419 build_cfg["build_cmds"][0] += thread_no
420
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000421 if cmd0.find("SST_RAM_FS=ON") < 0 and i.target_platform == "MUSCA_B1":
422 cmd0 += " -DSST_RAM_FS=OFF -DITS_RAM_FS=OFF"
423 except Exception as E:
424 pass
425 # Prepend configuration commoand as the first cmd [cmd1] + [cmd2] + [cmd3] +
426 build_cfg["build_cmds"] = [cmd0] + build_cfg["build_cmds"]
427 if not silence:
428 print("cmd0 %s\r\n" % (build_cfg["build_cmds"]))
429 if "build_psa_api" in build_cfg:
430 if not silence:
431 print("cmd build_psa_api %s\r\n" % build_cfg["build_psa_api"])
432 # Set the overrid params
433 over_dict = {"_tbm_build_dir_": build_dir,
434 "_tbm_code_dir_": codebase_dir,
435 "_tbm_target_platform_": i.target_platform}
436 over_params = ["build_cmds",
437 "required_artefacts",
438 "artifact_capture_rex"]
439 build_cfg = self.override_tbm_cfg_params(build_cfg,
440 over_params,
441 **over_dict)
442 return build_cfg
443
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100444 def post_eval(self):
445 """ If a single build failed fail the test """
446 try:
Minos Galanakisea421232019-06-20 17:11:28 +0100447 status_dict = self.unstash("Build Status")
448 if not status_dict:
449 raise Exception()
450 retcode_sum = sum(status_dict.values())
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100451 if retcode_sum != 0:
452 raise Exception()
453 return True
454 except Exception as e:
455 return False
456
457 def post_exec(self, eval_ret):
458 """ Generate a report and fail the script if build == unsuccessfull"""
459
460 self.print_summary()
461 if not eval_ret:
462 print("ERROR: ====> Build Failed! %s" % self.get_name())
463 self.set_status(1)
464 else:
465 print("SUCCESS: ====> Build Complete!")
466 self.set_status(0)
467
468 def get_report(self):
469 """ Expose the internal report to a new object for external classes """
470 return deepcopy(self.unstash("Build Report"))
471
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100472 def load_config(self, config, work_dir):
473 try:
474 # passing config_name param supersseeds fileparam
475 if isinstance(config, dict):
476 ret_cfg = deepcopy(config)
477 elif isinstance(config, str):
478 # If the string does not descrive a file try to look for it in
479 # work directory
480 if not os.path.isfile(config):
481 # remove path from file
482 config_2 = os.path.split(config)[-1]
483 # look in the current working directory
484 config_2 = os.path.join(work_dir, config_2)
485 if not os.path.isfile(config_2):
486 m = "Could not find cfg in %s or %s " % (config,
487 config_2)
488 raise Exception(m)
489 # If fille exists in working directory
490 else:
491 config = config_2
492 ret_cfg = load_json(config)
493
494 else:
495 raise Exception("Need to provide a valid config name or file."
496 "Please use --config/--config-file parameter.")
497 except Exception as e:
498 print("Error:%s \nCould not load a valid config" % e)
499 sys.exit(1)
500
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100501 return ret_cfg
502
503 def parse_config(self, cfg):
504 """ Parse a valid configuration file into a set of build dicts """
505
Minos Galanakisea421232019-06-20 17:11:28 +0100506 ret_cfg = {}
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100507
Minos Galanakisea421232019-06-20 17:11:28 +0100508 # Config entries which are not subject to changes during combinations
509 static_cfg = cfg["common_params"]
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100510
Minos Galanakisea421232019-06-20 17:11:28 +0100511 # Converth the code path to absolute path
512 abs_code_dir = static_cfg["codebase_root_dir"]
513 abs_code_dir = os.path.abspath(os.path.expanduser(abs_code_dir))
514 static_cfg["codebase_root_dir"] = abs_code_dir
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100515
Minos Galanakisea421232019-06-20 17:11:28 +0100516 # seed_params is an optional field. Do not proccess if it is missing
517 if "seed_params" in cfg:
518 comb_cfg = cfg["seed_params"]
519 # Generate a list of all possible confugration combinations
520 ret_cfg = TFM_Build_Manager.generate_config_list(comb_cfg,
521 static_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100522
Minos Galanakisea421232019-06-20 17:11:28 +0100523 # invalid is an optional field. Do not proccess if it is missing
524 if "invalid" in cfg:
525 # Invalid configurations(Do not build)
526 invalid_cfg = cfg["invalid"]
527 # Remove the rejected entries from the test list
528 rejection_cfg = TFM_Build_Manager.generate_rejection_list(
529 comb_cfg,
530 static_cfg,
531 invalid_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100532
Minos Galanakisea421232019-06-20 17:11:28 +0100533 # Subtract the two configurations
534 ret_cfg = {k: v for k, v in ret_cfg.items()
535 if k not in rejection_cfg}
536 self.simple_config = False
537 else:
538 self.simple_config = True
539 return ret_cfg, static_cfg
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100540
Minos Galanakisea421232019-06-20 17:11:28 +0100541 # ----- Override bellow methods when subclassing for other projects ----- #
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100542
Minos Galanakisea421232019-06-20 17:11:28 +0100543 def print_summary(self):
544 """ Print an comprehensive list of the build jobs with their status """
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100545
Minos Galanakisea421232019-06-20 17:11:28 +0100546 try:
547 full_rep = self.unstash("Build Report")["report"]
548 fl = ([k for k, v in full_rep.items() if v['status'] == 'Failed'])
549 ps = ([k for k, v in full_rep.items() if v['status'] == 'Success'])
550 except Exception as E:
Karl Zhangaff558a2020-05-15 14:28:23 +0100551 print("No report generated", E)
Minos Galanakisea421232019-06-20 17:11:28 +0100552 return
553 if fl:
554 print_test(t_list=fl, status="failed", tname="Builds")
555 if ps:
556 print_test(t_list=ps, status="passed", tname="Builds")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100557
Minos Galanakisea421232019-06-20 17:11:28 +0100558 @staticmethod
559 def generate_config_list(seed_config, static_config):
560 """ Generate all possible configuration combinations from a group of
561 lists of compiler options"""
562 config_list = []
563
564 if static_config["config_type"] == "tf-m":
565 cfg_name = "TFM_Build_CFG"
566 # Ensure the fieds are sorted in the desired order
567 # seed_config can be a subset of sort order for configurations with
568 # optional parameters.
569 tags = [n for n in static_config["sort_order"]
570 if n in seed_config.keys()]
Karl Zhangaff558a2020-05-15 14:28:23 +0100571 print("!!!!!!!!!!!gen list %s\r\n" % tags)
Minos Galanakisea421232019-06-20 17:11:28 +0100572
573 data = []
574 for key in tags:
575 data.append(seed_config[key])
576 config_list = gen_cfg_combinations(cfg_name,
577 " ".join(tags),
578 *data)
579 else:
580 print("Not information for project type: %s."
581 " Please check config" % static_config["config_type"])
582
583 ret_cfg = {}
584 # Notify the user for the rejected configuations
585 for i in config_list:
586 # Convert named tuples to string with boolean support
587 i_str = "_".join(map(lambda x: repr(x)
588 if isinstance(x, bool) else x, list(i)))
589
590 # Replace bollean vaiables with more BL2/NOBL2 and use it as"
591 # configuration name.
Karl Zhangaff558a2020-05-15 14:28:23 +0100592 i_str = i_str.replace("True", "BL2").replace("False", "NOBL2")
593 i_str = i_str.replace("CRYPTO", "Crypto")
594 i_str = i_str.replace("PROTECTED_STORAGE", "PS")
595 i_str = i_str.replace("INITIAL_ATTESTATION", "Attest")
596 i_str = i_str.replace("INTERNAL_TRUSTED_STORAGE", "ITS")
597 ret_cfg[i_str] = i
Minos Galanakisea421232019-06-20 17:11:28 +0100598
599 return ret_cfg
600
601 @staticmethod
602 def generate_rejection_list(seed_config,
603 static_config,
604 rejection_list):
605 rejection_cfg = {}
606
607 if static_config["config_type"] == "tf-m":
608
609 # If rejection list is empty do nothing
610 if not rejection_list:
611 return rejection_cfg
612
613 tags = [n for n in static_config["sort_order"]
614 if n in seed_config.keys()]
615 sorted_default_lst = [seed_config[k] for k in tags]
616
617 # If tags are not alligned with rejection list entries quit
618 if len(tags) != len(rejection_list[0]):
619 print(len(tags), len(rejection_list[0]))
620 print("Error, tags should be assigned to each "
621 "of the rejection inputs")
622 return []
623
624 # Replace wildcard ( "*") entries with every
625 # inluded in cfg variant
626 for k in rejection_list:
627 # Pad the omitted values with wildcard char *
628 res_list = list(k) + ["*"] * (5 - len(k))
629 print("Working on rejection input: %s" % (res_list))
630
631 for n in range(len(res_list)):
632
633 res_list[n] = [res_list[n]] if res_list[n] != "*" \
634 else sorted_default_lst[n]
635
636 # Generate a configuration and a name for the completed array
637 rj_cfg = TFM_Build_Manager.generate_config_list(
638 dict(zip(tags, res_list)),
639 static_config)
640
641 # Append the configuration to the existing ones
Dean Birchf6aa3da2020-01-24 12:29:38 +0000642 rejection_cfg = dict(rejection_cfg, **rj_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100643
644 # Notfy the user for the rejected configuations
645 for i in rejection_cfg.keys():
646 print("Rejecting config %s" % i)
647 else:
648 print("Not information for project type: %s."
649 " Please check config" % static_config["config_type"])
650 return rejection_cfg