blob: 05c7c9cea42194a2f7db7147f3c1b8985e83af53 [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
Xinyu Zhang1078e812020-10-15 11:52:36 +080035mapPlatform = {"cypress/psoc64": "psoc64",
36 "mps2/an519": "AN519",
37 "mps2/an521": "AN521",
38 "mps2/an539": "AN539",
39 "mps2/sse-200_aws": "SSE-200_AWS",
40 "mps3/an524": "AN524",
41 "musca_a": "MUSCA_A",
42 "musca_b1": "MUSCA_B1",
43 "musca_s1": "MUSCA_S1"}
44
45mapCompiler = {"toolchain_GNUARM.cmake": "GNUARM",
46 "toolchain_ARMCLANG.cmake": "ARMCLANG"}
47
Xinyu Zhangc371af62020-10-21 10:41:57 +080048mapTestPsaApi = {"IPC": "FF",
Xinyu Zhang1078e812020-10-15 11:52:36 +080049 "CRYPTO": "CRYPTO",
50 "PROTECTED_STORAGE": "PS",
51 "INITIAL_ATTESTATION": "ATTEST",
52 "INTERNAL_TRUSTED_STORAGE": "ITS"}
53
54mapProfile = {"profile_small": "SMALL"}
55
56
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010057class TFM_Build_Manager(structuredTask):
58 """ Class that will load a configuration out of a json file, schedule
59 the builds, and produce a report """
60
61 def __init__(self,
62 tfm_dir, # TFM root directory
63 work_dir, # Current working directory(ie logs)
64 cfg_dict, # Input config dictionary of the following form
65 # input_dict = {"PROJ_CONFIG": "ConfigRegression",
66 # "TARGET_PLATFORM": "MUSCA_A",
67 # "COMPILER": "ARMCLANG",
68 # "CMAKE_BUILD_TYPE": "Debug"}
69 report=None, # File to produce report
70 parallel_builds=3, # Number of builds to run in parallel
Minos Galanakisea421232019-06-20 17:11:28 +010071 build_threads=3, # Number of threads used per build
72 install=False, # Install libraries after build
73 img_sizes=False, # Use arm-none-eabi-size for size info
74 relative_paths=False): # Store relative paths in report
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010075 self._tbm_build_threads = build_threads
76 self._tbm_conc_builds = parallel_builds
77 self._tbm_install = install
Minos Galanakisea421232019-06-20 17:11:28 +010078 self._tbm_img_sizes = img_sizes
79 self._tbm_relative_paths = relative_paths
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010080
81 # Required by other methods, always set working directory first
82 self._tbm_work_dir = os.path.abspath(os.path.expanduser(work_dir))
83
84 self._tbm_tfm_dir = os.path.abspath(os.path.expanduser(tfm_dir))
85
Karl Zhangaff558a2020-05-15 14:28:23 +010086 print("bm param tfm_dir %s" % tfm_dir)
87 print("bm %s %s %s" % (work_dir, cfg_dict, self._tbm_work_dir))
Minos Galanakisea421232019-06-20 17:11:28 +010088 # Internal flag to tag simple (non combination formatted configs)
89 self.simple_config = False
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010090 self._tbm_report = report
91
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010092 self._tbm_cfg = self.load_config(cfg_dict, self._tbm_work_dir)
Minos Galanakisea421232019-06-20 17:11:28 +010093 self._tbm_build_cfg, \
94 self.tbm_common_cfg = self.parse_config(self._tbm_cfg)
Karl Zhangaff558a2020-05-15 14:28:23 +010095 self._tfb_code_base_updated = False
96 self._tfb_log_f = "CodeBasePrepare.log"
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010097
98 super(TFM_Build_Manager, self).__init__(name="TFM_Build_Manager")
99
Dean Bircha6ede7e2020-03-13 14:00:33 +0000100 def get_config(self):
101 return list(self._tbm_build_cfg.keys())
Dean Birch5cb5a882020-01-24 11:37:13 +0000102
Dean Bircha6ede7e2020-03-13 14:00:33 +0000103 def print_config_environment(self, config, silence_stderr=False):
Dean Birch5cb5a882020-01-24 11:37:13 +0000104 """
105 For a given build configuration from output of print_config
106 method, print environment variables to build.
107 """
108 if config not in self._tbm_build_cfg:
Dean Bircha6ede7e2020-03-13 14:00:33 +0000109 if not silence_stderr:
110 print("Error: no such config {}".format(config), file=sys.stderr)
Dean Birch5cb5a882020-01-24 11:37:13 +0000111 sys.exit(1)
112 config_details = self._tbm_build_cfg[config]
113 argument_list = [
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000114 "CONFIG_NAME={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800115 "TFM_PLATFORM={}",
116 "TOOLCHAIN_FILE={}",
117 "PSA_API={}",
118 "ISOLATION_LEVEL={}",
119 "TEST_REGRESSION={}",
120 "TEST_PSA_API={}",
Dean Birch5cb5a882020-01-24 11:37:13 +0000121 "CMAKE_BUILD_TYPE={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800122 "OTP={}",
Dean Birch5cb5a882020-01-24 11:37:13 +0000123 "BL2={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800124 "NS={}",
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800125 "PROFILE={}"
Dean Birch5cb5a882020-01-24 11:37:13 +0000126 ]
127 print(
128 "\n".join(argument_list)
129 .format(
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000130 config,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800131 config_details.tfm_platform,
132 config_details.toolchain_file,
133 config_details.psa_api,
134 config_details.isolation_level,
135 config_details.test_regression,
136 config_details.test_psa_api,
Dean Birch5cb5a882020-01-24 11:37:13 +0000137 config_details.cmake_build_type,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800138 config_details.with_otp,
139 config_details.with_bl2,
140 config_details.with_ns,
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800141 "N.A" if not config_details.profile else config_details.profile
Dean Birch5cb5a882020-01-24 11:37:13 +0000142 )
143 .strip()
144 )
145
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000146 def print_build_commands(self, config, silence_stderr=False):
147 config_details = self._tbm_build_cfg[config]
148 codebase_dir = os.path.join(os.getcwd(),"trusted-firmware-m")
Xinyu Zhangb708f572020-09-15 11:43:46 +0800149 build_dir=os.path.join(os.getcwd(),"trusted-firmware-m/build")
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000150 build_config = self.get_build_config(config_details, config, silence=silence_stderr, build_dir=build_dir, codebase_dir=codebase_dir)
Xinyu Zhangb708f572020-09-15 11:43:46 +0800151 build_commands = [build_config["config_template"], build_config["build_cmds"][0]]
152 print(" ;\n".join(build_commands))
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000153
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100154 def pre_eval(self):
155 """ Tests that need to be run in set-up state """
156 return True
157
158 def pre_exec(self, eval_ret):
159 """ """
160
Minos Galanakisea421232019-06-20 17:11:28 +0100161 def override_tbm_cfg_params(self, config, override_keys, **params):
162 """ Using a dictionay as input, for each key defined in
163 override_keys it will replace the config[key] entries with
164 the key=value parameters provided """
165
166 for key in override_keys:
167 if isinstance(config[key], list):
168 config[key] = [n % params for n in config[key]]
169 elif isinstance(config[key], str):
170 config[key] = config[key] % params
171 else:
172 raise Exception("Config does not contain key %s "
173 "of type %s" % (key, config[key]))
174 return config
175
Karl Zhangaff558a2020-05-15 14:28:23 +0100176 def pre_build(self, build_cfg):
177 print("pre_build start %s \r\nself._tfb_cfg %s\r\n" %
178 (self, build_cfg))
179
180 try:
181 if self._tfb_code_base_updated:
182 print("Code base has been updated")
183 return True
184
185 self._tfb_code_base_updated = True
186
187 if "build_psa_api" in build_cfg:
188 # FF IPC build needs repo manifest update for TFM and PSA arch test
189 if "build_ff_ipc" in build_cfg:
190 print("Checkout to FF IPC code base")
191 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
192 _api_test_manifest = "git checkout . ; python3 tools/scripts/manifest_update.py"
193 if subprocess_log(_api_test_manifest,
194 self._tfb_log_f,
195 append=True,
196 prefix=_api_test_manifest):
197
198 raise Exception("Python Failed please check log: %s" %
199 self._tfb_log_f)
200
201 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py -m tools/tfm_psa_ff_test_manifest_list.yaml append"
202 os.chdir(build_cfg["codebase_root_dir"])
203 if subprocess_log(_api_test_manifest_tfm,
204 self._tfb_log_f,
205 append=True,
206 prefix=_api_test_manifest_tfm):
207
208 raise Exception("Python TFM Failed please check log: %s" %
209 self._tfb_log_f)
210 return True
211
212 print("Checkout to default code base")
213 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
214 _api_test_manifest = "git checkout ."
215 if subprocess_log(_api_test_manifest,
216 self._tfb_log_f,
217 append=True,
218 prefix=_api_test_manifest):
219
220 raise Exception("Python Failed please check log: %s" %
221 self._tfb_log_f)
222
223 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py"
224 os.chdir(build_cfg["codebase_root_dir"])
225 if subprocess_log(_api_test_manifest_tfm,
226 self._tfb_log_f,
227 append=True,
228 prefix=_api_test_manifest_tfm):
229
230 raise Exception("Python TFM Failed please check log: %s" %
231 self._tfb_log_f)
232 finally:
233 print("python pass after builder prepare")
234 os.chdir(build_cfg["codebase_root_dir"] + "/../")
235
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100236 def task_exec(self):
237 """ Create a build pool and execute them in parallel """
238
239 build_pool = []
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100240
Minos Galanakisea421232019-06-20 17:11:28 +0100241 # When a config is flagged as a single build config.
242 # Name is evaluated by config type
243 if self.simple_config:
244
245 build_cfg = deepcopy(self.tbm_common_cfg)
246
247 # Extract the common for all elements of config
248 for key in ["build_cmds", "required_artefacts"]:
249 try:
250 build_cfg[key] = build_cfg[key]["all"]
251 except KeyError:
252 build_cfg[key] = []
253 name = build_cfg["config_type"]
254
255 # Override _tbm_xxx paths in commands
256 # plafrom in not guaranteed without seeds so _tbm_target_platform
257 # is ignored
258 over_dict = {"_tbm_build_dir_": os.path.join(self._tbm_work_dir,
259 name),
260 "_tbm_code_dir_": build_cfg["codebase_root_dir"]}
261
262 build_cfg = self.override_tbm_cfg_params(build_cfg,
263 ["build_cmds",
264 "required_artefacts",
265 "artifact_capture_rex"],
266 **over_dict)
267
268 # Overrides path in expected artefacts
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100269 print("Loading config %s" % name)
Minos Galanakisea421232019-06-20 17:11:28 +0100270
271 build_pool.append(TFM_Builder(
272 name=name,
273 work_dir=self._tbm_work_dir,
274 cfg_dict=build_cfg,
275 build_threads=self._tbm_build_threads,
276 img_sizes=self._tbm_img_sizes,
277 relative_paths=self._tbm_relative_paths))
278 # When a seed pool is provided iterate through the entries
279 # and update platform spefific parameters
280 elif len(self._tbm_build_cfg):
Karl Zhangaff558a2020-05-15 14:28:23 +0100281 print("\r\n_tbm_build_cfg %s\r\n tbm_common_cfg %s\r\n" \
282 % (self._tbm_build_cfg, self.tbm_common_cfg))
Minos Galanakisea421232019-06-20 17:11:28 +0100283 for name, i in self._tbm_build_cfg.items():
284 # Do not modify the original config
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000285 build_cfg = self.get_build_config(i, name)
Karl Zhangaff558a2020-05-15 14:28:23 +0100286 self.pre_build(build_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100287 # Overrides path in expected artefacts
288 print("Loading config %s" % name)
289
290 build_pool.append(TFM_Builder(
291 name=name,
292 work_dir=self._tbm_work_dir,
293 cfg_dict=build_cfg,
294 build_threads=self._tbm_build_threads,
295 img_sizes=self._tbm_img_sizes,
296 relative_paths=self._tbm_relative_paths))
297 else:
298 print("Could not find any configuration. Check the rejection list")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100299
300 status_rep = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100301 build_rep = {}
302 completed_build_count = 0
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100303 print("Build: Running %d parallel build jobs" % self._tbm_conc_builds)
304 for build_pool_slice in list_chunks(build_pool, self._tbm_conc_builds):
305
306 # Start the builds
307 for build in build_pool_slice:
308 # Only produce output for the first build
309 if build_pool_slice.index(build) != 0:
310 build.mute()
311 print("Build: Starting %s" % build.get_name())
312 build.start()
313
314 # Wait for the builds to complete
315 for build in build_pool_slice:
316 # Wait for build to finish
317 build.join()
318 # Similarly print the logs of the other builds as they complete
319 if build_pool_slice.index(build) != 0:
320 build.log()
Minos Galanakisea421232019-06-20 17:11:28 +0100321 completed_build_count += 1
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100322 print("Build: Finished %s" % build.get_name())
Minos Galanakisea421232019-06-20 17:11:28 +0100323 print("Build Progress:")
324 show_progress(completed_build_count, len(build_pool))
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100325
326 # Store status in report
327 status_rep[build.get_name()] = build.get_status()
Minos Galanakisea421232019-06-20 17:11:28 +0100328 build_rep[build.get_name()] = build.report()
329
330 # Include the original input configuration in the report
331
332 metadata = {"input_build_cfg": self._tbm_cfg,
333 "build_dir": self._tbm_work_dir
334 if not self._tbm_relative_paths
335 else resolve_rel_path(self._tbm_work_dir),
336 "time": time()}
337
338 full_rep = {"report": build_rep,
339 "_metadata_": metadata}
340
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100341 # Store the report
342 self.stash("Build Status", status_rep)
343 self.stash("Build Report", full_rep)
344
345 if self._tbm_report:
346 print("Exported build report to file:", self._tbm_report)
347 save_json(self._tbm_report, full_rep)
348
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000349 def get_build_config(self, i, name, silence=False, build_dir=None, codebase_dir=None):
350 psa_build_dir = self._tbm_work_dir + "/" + name + "/BUILD"
351 if not build_dir:
352 build_dir = os.path.join(self._tbm_work_dir, name)
353 else:
354 psa_build_dir = os.path.join(build_dir, "../../psa-arch-tests/api-tests/build")
355 build_cfg = deepcopy(self.tbm_common_cfg)
356 if not codebase_dir:
357 codebase_dir = build_cfg["codebase_root_dir"]
358 else:
359 # Would prefer to do all with the new variable
360 # However, many things use this from build_cfg elsewhere
361 build_cfg["codebase_root_dir"] = codebase_dir
362 # Extract the common for all elements of config
363 for key in ["build_cmds", "required_artefacts"]:
364 try:
365 build_cfg[key] = deepcopy(self.tbm_common_cfg[key]
366 ["all"])
367 except KeyError as E:
368 build_cfg[key] = []
369 # Extract the platform specific elements of config
370 for key in ["build_cmds", "required_artefacts"]:
371 try:
Xinyu Zhangb708f572020-09-15 11:43:46 +0800372 if i.tfm_platform in self.tbm_common_cfg[key].keys():
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000373 build_cfg[key] += deepcopy(self.tbm_common_cfg[key]
Xinyu Zhangb708f572020-09-15 11:43:46 +0800374 [i.tfm_platform])
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000375 except Exception as E:
376 pass
Karl Zhang1eed6322020-07-01 15:38:10 +0800377
378 if os.cpu_count() >= 8:
379 #run in a serviver with scripts, parallel build will use CPU numbers
380 thread_no = " -j 2"
381 else:
382 #run in a docker, usually docker with CPUs less than 8
383 thread_no = " -j " + str(os.cpu_count())
Xinyu Zhangb708f572020-09-15 11:43:46 +0800384 build_cfg["build_cmds"][0] += thread_no
385 overwrite_params = {"codebase_root_dir": build_cfg["codebase_root_dir"],
386 "tfm_platform": i.tfm_platform,
387 "toolchain_file": i.toolchain_file,
388 "psa_api": i.psa_api,
389 "isolation_level": i.isolation_level,
390 "test_regression": i.test_regression,
391 "test_psa_api": i.test_psa_api,
392 "cmake_build_type": i.cmake_build_type,
393 "with_otp": i.with_otp,
394 "with_bl2": i.with_bl2,
395 "with_ns": i.with_ns,
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800396 "profile": "" if i.profile=="N.A" else i.profile}
Xinyu Zhangb708f572020-09-15 11:43:46 +0800397 build_cfg["config_template"] %= overwrite_params
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000398 return build_cfg
399
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100400 def post_eval(self):
401 """ If a single build failed fail the test """
402 try:
Minos Galanakisea421232019-06-20 17:11:28 +0100403 status_dict = self.unstash("Build Status")
404 if not status_dict:
405 raise Exception()
406 retcode_sum = sum(status_dict.values())
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100407 if retcode_sum != 0:
408 raise Exception()
409 return True
410 except Exception as e:
411 return False
412
413 def post_exec(self, eval_ret):
414 """ Generate a report and fail the script if build == unsuccessfull"""
415
416 self.print_summary()
417 if not eval_ret:
418 print("ERROR: ====> Build Failed! %s" % self.get_name())
419 self.set_status(1)
420 else:
421 print("SUCCESS: ====> Build Complete!")
422 self.set_status(0)
423
424 def get_report(self):
425 """ Expose the internal report to a new object for external classes """
426 return deepcopy(self.unstash("Build Report"))
427
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100428 def load_config(self, config, work_dir):
429 try:
430 # passing config_name param supersseeds fileparam
431 if isinstance(config, dict):
432 ret_cfg = deepcopy(config)
433 elif isinstance(config, str):
434 # If the string does not descrive a file try to look for it in
435 # work directory
436 if not os.path.isfile(config):
437 # remove path from file
438 config_2 = os.path.split(config)[-1]
439 # look in the current working directory
440 config_2 = os.path.join(work_dir, config_2)
441 if not os.path.isfile(config_2):
442 m = "Could not find cfg in %s or %s " % (config,
443 config_2)
444 raise Exception(m)
445 # If fille exists in working directory
446 else:
447 config = config_2
448 ret_cfg = load_json(config)
449
450 else:
451 raise Exception("Need to provide a valid config name or file."
452 "Please use --config/--config-file parameter.")
453 except Exception as e:
454 print("Error:%s \nCould not load a valid config" % e)
455 sys.exit(1)
456
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100457 return ret_cfg
458
459 def parse_config(self, cfg):
460 """ Parse a valid configuration file into a set of build dicts """
461
Minos Galanakisea421232019-06-20 17:11:28 +0100462 ret_cfg = {}
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100463
Minos Galanakisea421232019-06-20 17:11:28 +0100464 # Config entries which are not subject to changes during combinations
465 static_cfg = cfg["common_params"]
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100466
Minos Galanakisea421232019-06-20 17:11:28 +0100467 # Converth the code path to absolute path
468 abs_code_dir = static_cfg["codebase_root_dir"]
469 abs_code_dir = os.path.abspath(os.path.expanduser(abs_code_dir))
470 static_cfg["codebase_root_dir"] = abs_code_dir
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100471
Minos Galanakisea421232019-06-20 17:11:28 +0100472 # seed_params is an optional field. Do not proccess if it is missing
473 if "seed_params" in cfg:
474 comb_cfg = cfg["seed_params"]
475 # Generate a list of all possible confugration combinations
476 ret_cfg = TFM_Build_Manager.generate_config_list(comb_cfg,
477 static_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100478
Minos Galanakisea421232019-06-20 17:11:28 +0100479 # invalid is an optional field. Do not proccess if it is missing
480 if "invalid" in cfg:
481 # Invalid configurations(Do not build)
482 invalid_cfg = cfg["invalid"]
483 # Remove the rejected entries from the test list
484 rejection_cfg = TFM_Build_Manager.generate_rejection_list(
485 comb_cfg,
486 static_cfg,
487 invalid_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100488
Minos Galanakisea421232019-06-20 17:11:28 +0100489 # Subtract the two configurations
490 ret_cfg = {k: v for k, v in ret_cfg.items()
491 if k not in rejection_cfg}
492 self.simple_config = False
493 else:
494 self.simple_config = True
495 return ret_cfg, static_cfg
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100496
Minos Galanakisea421232019-06-20 17:11:28 +0100497 # ----- Override bellow methods when subclassing for other projects ----- #
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100498
Minos Galanakisea421232019-06-20 17:11:28 +0100499 def print_summary(self):
500 """ Print an comprehensive list of the build jobs with their status """
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100501
Minos Galanakisea421232019-06-20 17:11:28 +0100502 try:
503 full_rep = self.unstash("Build Report")["report"]
504 fl = ([k for k, v in full_rep.items() if v['status'] == 'Failed'])
505 ps = ([k for k, v in full_rep.items() if v['status'] == 'Success'])
506 except Exception as E:
Karl Zhangaff558a2020-05-15 14:28:23 +0100507 print("No report generated", E)
Minos Galanakisea421232019-06-20 17:11:28 +0100508 return
509 if fl:
510 print_test(t_list=fl, status="failed", tname="Builds")
511 if ps:
512 print_test(t_list=ps, status="passed", tname="Builds")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100513
Minos Galanakisea421232019-06-20 17:11:28 +0100514 @staticmethod
515 def generate_config_list(seed_config, static_config):
516 """ Generate all possible configuration combinations from a group of
517 lists of compiler options"""
518 config_list = []
519
520 if static_config["config_type"] == "tf-m":
521 cfg_name = "TFM_Build_CFG"
522 # Ensure the fieds are sorted in the desired order
523 # seed_config can be a subset of sort order for configurations with
524 # optional parameters.
525 tags = [n for n in static_config["sort_order"]
526 if n in seed_config.keys()]
Karl Zhangaff558a2020-05-15 14:28:23 +0100527 print("!!!!!!!!!!!gen list %s\r\n" % tags)
Minos Galanakisea421232019-06-20 17:11:28 +0100528
529 data = []
530 for key in tags:
531 data.append(seed_config[key])
532 config_list = gen_cfg_combinations(cfg_name,
533 " ".join(tags),
534 *data)
535 else:
536 print("Not information for project type: %s."
537 " Please check config" % static_config["config_type"])
538
539 ret_cfg = {}
540 # Notify the user for the rejected configuations
541 for i in config_list:
Xinyu Zhang1078e812020-10-15 11:52:36 +0800542 # Convert named tuples to string in a brief format
543 config_param = []
544 config_param.append(mapPlatform[list(i)[0]])
545 config_param.append(mapCompiler[list(i)[1]])
546 if list(i)[2]: # PSA_API
547 config_param.append("PSA")
548 config_param.append(list(i)[3]) # ISOLATION_LEVEL
549 if list(i)[4]: # TEST_REGRESSION
550 config_param.append("REG")
551 if list(i)[5] != "OFF": #TEST_PSA_API
552 config_param.append(mapTestPsaApi[list(i)[5]])
553 config_param.append(list(i)[6]) # BUILD_TYPE
554 if list(i)[7]: # OTP
555 config_param.append("OTP")
556 if list(i)[8]: # BL2
557 config_param.append("BL2")
558 if list(i)[9]: # NS
559 config_param.append("NS")
560 if list(i)[10]: # PROFILE
561 config_param.append(mapProfile[list(i)[10]])
562 i_str = "_".join(config_param)
Karl Zhangaff558a2020-05-15 14:28:23 +0100563 ret_cfg[i_str] = i
Minos Galanakisea421232019-06-20 17:11:28 +0100564 return ret_cfg
565
566 @staticmethod
567 def generate_rejection_list(seed_config,
568 static_config,
569 rejection_list):
570 rejection_cfg = {}
571
572 if static_config["config_type"] == "tf-m":
573
574 # If rejection list is empty do nothing
575 if not rejection_list:
576 return rejection_cfg
577
578 tags = [n for n in static_config["sort_order"]
579 if n in seed_config.keys()]
580 sorted_default_lst = [seed_config[k] for k in tags]
581
582 # If tags are not alligned with rejection list entries quit
583 if len(tags) != len(rejection_list[0]):
584 print(len(tags), len(rejection_list[0]))
585 print("Error, tags should be assigned to each "
586 "of the rejection inputs")
587 return []
588
589 # Replace wildcard ( "*") entries with every
590 # inluded in cfg variant
591 for k in rejection_list:
592 # Pad the omitted values with wildcard char *
593 res_list = list(k) + ["*"] * (5 - len(k))
594 print("Working on rejection input: %s" % (res_list))
595
596 for n in range(len(res_list)):
597
598 res_list[n] = [res_list[n]] if res_list[n] != "*" \
599 else sorted_default_lst[n]
600
601 # Generate a configuration and a name for the completed array
602 rj_cfg = TFM_Build_Manager.generate_config_list(
603 dict(zip(tags, res_list)),
604 static_config)
605
606 # Append the configuration to the existing ones
Dean Birchf6aa3da2020-01-24 12:29:38 +0000607 rejection_cfg = dict(rejection_cfg, **rj_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100608
609 # Notfy the user for the rejected configuations
610 for i in rejection_cfg.keys():
611 print("Rejecting config %s" % i)
612 else:
613 print("Not information for project type: %s."
614 " Please check config" % static_config["config_type"])
615 return rejection_cfg