blob: 436d0c870fc316eadb4ac8cd82306a07607759ba [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/*
Karl Zhang08681e62020-10-30 13:56:03 +080011 * Copyright (c) 2018-2020, 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"
Karl Zhang08681e62020-10-30 13:56:03 +080020__version__ = "1.2.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 Zhang1078e812020-10-15 11:52:36 +080034mapPlatform = {"cypress/psoc64": "psoc64",
35 "mps2/an519": "AN519",
36 "mps2/an521": "AN521",
37 "mps2/an539": "AN539",
38 "mps2/sse-200_aws": "SSE-200_AWS",
39 "mps3/an524": "AN524",
40 "musca_a": "MUSCA_A",
41 "musca_b1": "MUSCA_B1",
42 "musca_s1": "MUSCA_S1"}
43
44mapCompiler = {"toolchain_GNUARM.cmake": "GNUARM",
45 "toolchain_ARMCLANG.cmake": "ARMCLANG"}
46
Xinyu Zhangc371af62020-10-21 10:41:57 +080047mapTestPsaApi = {"IPC": "FF",
Xinyu Zhang1078e812020-10-15 11:52:36 +080048 "CRYPTO": "CRYPTO",
49 "PROTECTED_STORAGE": "PS",
50 "INITIAL_ATTESTATION": "ATTEST",
51 "INTERNAL_TRUSTED_STORAGE": "ITS"}
52
Xinyu Zhang9fd74242020-10-22 11:30:50 +080053mapProfile = {"profile_small": "SMALL",
54 "profile_medium": "MEDIUM"}
Xinyu Zhang1078e812020-10-15 11:52:36 +080055
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 Zhang9fd74242020-10-22 11:30:50 +0800125 "PROFILE={}",
126 "PARTITION_PS={}"
Dean Birch5cb5a882020-01-24 11:37:13 +0000127 ]
128 print(
129 "\n".join(argument_list)
130 .format(
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000131 config,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800132 config_details.tfm_platform,
133 config_details.toolchain_file,
134 config_details.psa_api,
135 config_details.isolation_level,
136 config_details.test_regression,
137 config_details.test_psa_api,
Dean Birch5cb5a882020-01-24 11:37:13 +0000138 config_details.cmake_build_type,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800139 config_details.with_otp,
140 config_details.with_bl2,
141 config_details.with_ns,
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800142 "N.A" if not config_details.profile else config_details.profile,
143 config_details.partition_ps
Dean Birch5cb5a882020-01-24 11:37:13 +0000144 )
145 .strip()
146 )
147
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000148 def print_build_commands(self, config, silence_stderr=False):
149 config_details = self._tbm_build_cfg[config]
150 codebase_dir = os.path.join(os.getcwd(),"trusted-firmware-m")
Xinyu Zhangb708f572020-09-15 11:43:46 +0800151 build_dir=os.path.join(os.getcwd(),"trusted-firmware-m/build")
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000152 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 +0800153 build_commands = [build_config["config_template"]]
154 for command in build_config["build_cmds"]:
155 build_commands.append(command)
Xinyu Zhangb708f572020-09-15 11:43:46 +0800156 print(" ;\n".join(build_commands))
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000157
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100158 def pre_eval(self):
159 """ Tests that need to be run in set-up state """
160 return True
161
162 def pre_exec(self, eval_ret):
163 """ """
164
Minos Galanakisea421232019-06-20 17:11:28 +0100165 def override_tbm_cfg_params(self, config, override_keys, **params):
166 """ Using a dictionay as input, for each key defined in
167 override_keys it will replace the config[key] entries with
168 the key=value parameters provided """
169
170 for key in override_keys:
171 if isinstance(config[key], list):
172 config[key] = [n % params for n in config[key]]
173 elif isinstance(config[key], str):
174 config[key] = config[key] % params
175 else:
176 raise Exception("Config does not contain key %s "
177 "of type %s" % (key, config[key]))
178 return config
179
Karl Zhangaff558a2020-05-15 14:28:23 +0100180 def pre_build(self, build_cfg):
181 print("pre_build start %s \r\nself._tfb_cfg %s\r\n" %
182 (self, build_cfg))
183
184 try:
185 if self._tfb_code_base_updated:
186 print("Code base has been updated")
187 return True
188
189 self._tfb_code_base_updated = True
190
191 if "build_psa_api" in build_cfg:
192 # FF IPC build needs repo manifest update for TFM and PSA arch test
193 if "build_ff_ipc" in build_cfg:
194 print("Checkout to FF IPC code base")
195 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
196 _api_test_manifest = "git checkout . ; python3 tools/scripts/manifest_update.py"
197 if subprocess_log(_api_test_manifest,
198 self._tfb_log_f,
199 append=True,
200 prefix=_api_test_manifest):
201
202 raise Exception("Python Failed please check log: %s" %
203 self._tfb_log_f)
204
205 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py -m tools/tfm_psa_ff_test_manifest_list.yaml append"
206 os.chdir(build_cfg["codebase_root_dir"])
207 if subprocess_log(_api_test_manifest_tfm,
208 self._tfb_log_f,
209 append=True,
210 prefix=_api_test_manifest_tfm):
211
212 raise Exception("Python TFM Failed please check log: %s" %
213 self._tfb_log_f)
214 return True
215
216 print("Checkout to default code base")
217 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
218 _api_test_manifest = "git checkout ."
219 if subprocess_log(_api_test_manifest,
220 self._tfb_log_f,
221 append=True,
222 prefix=_api_test_manifest):
223
224 raise Exception("Python Failed please check log: %s" %
225 self._tfb_log_f)
226
227 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py"
228 os.chdir(build_cfg["codebase_root_dir"])
229 if subprocess_log(_api_test_manifest_tfm,
230 self._tfb_log_f,
231 append=True,
232 prefix=_api_test_manifest_tfm):
233
234 raise Exception("Python TFM Failed please check log: %s" %
235 self._tfb_log_f)
236 finally:
237 print("python pass after builder prepare")
238 os.chdir(build_cfg["codebase_root_dir"] + "/../")
239
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100240 def task_exec(self):
241 """ Create a build pool and execute them in parallel """
242
243 build_pool = []
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100244
Minos Galanakisea421232019-06-20 17:11:28 +0100245 # When a config is flagged as a single build config.
246 # Name is evaluated by config type
247 if self.simple_config:
248
249 build_cfg = deepcopy(self.tbm_common_cfg)
250
251 # Extract the common for all elements of config
252 for key in ["build_cmds", "required_artefacts"]:
253 try:
254 build_cfg[key] = build_cfg[key]["all"]
255 except KeyError:
256 build_cfg[key] = []
257 name = build_cfg["config_type"]
258
259 # Override _tbm_xxx paths in commands
260 # plafrom in not guaranteed without seeds so _tbm_target_platform
261 # is ignored
262 over_dict = {"_tbm_build_dir_": os.path.join(self._tbm_work_dir,
263 name),
264 "_tbm_code_dir_": build_cfg["codebase_root_dir"]}
265
266 build_cfg = self.override_tbm_cfg_params(build_cfg,
267 ["build_cmds",
268 "required_artefacts",
269 "artifact_capture_rex"],
270 **over_dict)
271
272 # Overrides path in expected artefacts
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100273 print("Loading config %s" % name)
Minos Galanakisea421232019-06-20 17:11:28 +0100274
275 build_pool.append(TFM_Builder(
276 name=name,
277 work_dir=self._tbm_work_dir,
278 cfg_dict=build_cfg,
279 build_threads=self._tbm_build_threads,
280 img_sizes=self._tbm_img_sizes,
281 relative_paths=self._tbm_relative_paths))
282 # When a seed pool is provided iterate through the entries
283 # and update platform spefific parameters
284 elif len(self._tbm_build_cfg):
Karl Zhangaff558a2020-05-15 14:28:23 +0100285 print("\r\n_tbm_build_cfg %s\r\n tbm_common_cfg %s\r\n" \
286 % (self._tbm_build_cfg, self.tbm_common_cfg))
Minos Galanakisea421232019-06-20 17:11:28 +0100287 for name, i in self._tbm_build_cfg.items():
288 # Do not modify the original config
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000289 build_cfg = self.get_build_config(i, name)
Karl Zhangaff558a2020-05-15 14:28:23 +0100290 self.pre_build(build_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100291 # Overrides path in expected artefacts
292 print("Loading config %s" % name)
293
294 build_pool.append(TFM_Builder(
295 name=name,
296 work_dir=self._tbm_work_dir,
297 cfg_dict=build_cfg,
298 build_threads=self._tbm_build_threads,
299 img_sizes=self._tbm_img_sizes,
300 relative_paths=self._tbm_relative_paths))
301 else:
302 print("Could not find any configuration. Check the rejection list")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100303
304 status_rep = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100305 build_rep = {}
306 completed_build_count = 0
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100307 print("Build: Running %d parallel build jobs" % self._tbm_conc_builds)
308 for build_pool_slice in list_chunks(build_pool, self._tbm_conc_builds):
309
310 # Start the builds
311 for build in build_pool_slice:
312 # Only produce output for the first build
313 if build_pool_slice.index(build) != 0:
314 build.mute()
315 print("Build: Starting %s" % build.get_name())
316 build.start()
317
318 # Wait for the builds to complete
319 for build in build_pool_slice:
320 # Wait for build to finish
321 build.join()
322 # Similarly print the logs of the other builds as they complete
323 if build_pool_slice.index(build) != 0:
324 build.log()
Minos Galanakisea421232019-06-20 17:11:28 +0100325 completed_build_count += 1
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100326 print("Build: Finished %s" % build.get_name())
Minos Galanakisea421232019-06-20 17:11:28 +0100327 print("Build Progress:")
328 show_progress(completed_build_count, len(build_pool))
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100329
330 # Store status in report
331 status_rep[build.get_name()] = build.get_status()
Minos Galanakisea421232019-06-20 17:11:28 +0100332 build_rep[build.get_name()] = build.report()
333
334 # Include the original input configuration in the report
335
336 metadata = {"input_build_cfg": self._tbm_cfg,
337 "build_dir": self._tbm_work_dir
338 if not self._tbm_relative_paths
339 else resolve_rel_path(self._tbm_work_dir),
340 "time": time()}
341
342 full_rep = {"report": build_rep,
343 "_metadata_": metadata}
344
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100345 # Store the report
346 self.stash("Build Status", status_rep)
347 self.stash("Build Report", full_rep)
348
349 if self._tbm_report:
350 print("Exported build report to file:", self._tbm_report)
351 save_json(self._tbm_report, full_rep)
352
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000353 def get_build_config(self, i, name, silence=False, build_dir=None, codebase_dir=None):
354 psa_build_dir = self._tbm_work_dir + "/" + name + "/BUILD"
355 if not build_dir:
356 build_dir = os.path.join(self._tbm_work_dir, name)
357 else:
358 psa_build_dir = os.path.join(build_dir, "../../psa-arch-tests/api-tests/build")
359 build_cfg = deepcopy(self.tbm_common_cfg)
360 if not codebase_dir:
361 codebase_dir = build_cfg["codebase_root_dir"]
362 else:
363 # Would prefer to do all with the new variable
364 # However, many things use this from build_cfg elsewhere
365 build_cfg["codebase_root_dir"] = codebase_dir
366 # Extract the common for all elements of config
367 for key in ["build_cmds", "required_artefacts"]:
368 try:
369 build_cfg[key] = deepcopy(self.tbm_common_cfg[key]
370 ["all"])
371 except KeyError as E:
372 build_cfg[key] = []
373 # Extract the platform specific elements of config
374 for key in ["build_cmds", "required_artefacts"]:
375 try:
Xinyu Zhang694eb492020-11-04 18:29:08 +0800376 if i.tfm_platform in self.tbm_common_cfg[key].keys() and i.with_ns:
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000377 build_cfg[key] += deepcopy(self.tbm_common_cfg[key]
Xinyu Zhangb708f572020-09-15 11:43:46 +0800378 [i.tfm_platform])
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000379 except Exception as E:
380 pass
Karl Zhang1eed6322020-07-01 15:38:10 +0800381
382 if os.cpu_count() >= 8:
383 #run in a serviver with scripts, parallel build will use CPU numbers
384 thread_no = " -j 2"
385 else:
386 #run in a docker, usually docker with CPUs less than 8
387 thread_no = " -j " + str(os.cpu_count())
Xinyu Zhangb708f572020-09-15 11:43:46 +0800388 build_cfg["build_cmds"][0] += thread_no
389 overwrite_params = {"codebase_root_dir": build_cfg["codebase_root_dir"],
390 "tfm_platform": i.tfm_platform,
391 "toolchain_file": i.toolchain_file,
392 "psa_api": i.psa_api,
393 "isolation_level": i.isolation_level,
394 "test_regression": i.test_regression,
395 "test_psa_api": i.test_psa_api,
396 "cmake_build_type": i.cmake_build_type,
397 "with_otp": i.with_otp,
398 "with_bl2": i.with_bl2,
399 "with_ns": i.with_ns,
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800400 "profile": "" if i.profile=="N.A" else i.profile,
401 "partition_ps": i.partition_ps}
Xinyu Zhanga0086022020-11-10 18:11:12 +0800402 if i.test_psa_api == "IPC":
Xinyu Zhangcd1ed962020-11-11 16:00:52 +0800403 overwrite_params["test_psa_api"] += " -DINCLUDE_PANIC_TESTS=1"
404 if i.tfm_platform == "musca_b1":
405 overwrite_params["test_psa_api"] += " -DITS_RAM_FS=ON -DPS_RAM_FS=ON"
Xinyu Zhangb708f572020-09-15 11:43:46 +0800406 build_cfg["config_template"] %= overwrite_params
Xinyu Zhang694eb492020-11-04 18:29:08 +0800407 if len(build_cfg["build_cmds"]) > 1:
408 overwrite_build_dir = {"_tbm_build_dir_": build_dir}
409 build_cfg["build_cmds"][1] %= overwrite_build_dir
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000410 return build_cfg
411
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100412 def post_eval(self):
413 """ If a single build failed fail the test """
414 try:
Minos Galanakisea421232019-06-20 17:11:28 +0100415 status_dict = self.unstash("Build Status")
416 if not status_dict:
417 raise Exception()
418 retcode_sum = sum(status_dict.values())
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100419 if retcode_sum != 0:
420 raise Exception()
421 return True
422 except Exception as e:
423 return False
424
425 def post_exec(self, eval_ret):
426 """ Generate a report and fail the script if build == unsuccessfull"""
427
428 self.print_summary()
429 if not eval_ret:
430 print("ERROR: ====> Build Failed! %s" % self.get_name())
431 self.set_status(1)
432 else:
433 print("SUCCESS: ====> Build Complete!")
434 self.set_status(0)
435
436 def get_report(self):
437 """ Expose the internal report to a new object for external classes """
438 return deepcopy(self.unstash("Build Report"))
439
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100440 def load_config(self, config, work_dir):
441 try:
442 # passing config_name param supersseeds fileparam
443 if isinstance(config, dict):
444 ret_cfg = deepcopy(config)
445 elif isinstance(config, str):
446 # If the string does not descrive a file try to look for it in
447 # work directory
448 if not os.path.isfile(config):
449 # remove path from file
450 config_2 = os.path.split(config)[-1]
451 # look in the current working directory
452 config_2 = os.path.join(work_dir, config_2)
453 if not os.path.isfile(config_2):
454 m = "Could not find cfg in %s or %s " % (config,
455 config_2)
456 raise Exception(m)
457 # If fille exists in working directory
458 else:
459 config = config_2
460 ret_cfg = load_json(config)
461
462 else:
463 raise Exception("Need to provide a valid config name or file."
464 "Please use --config/--config-file parameter.")
465 except Exception as e:
466 print("Error:%s \nCould not load a valid config" % e)
467 sys.exit(1)
468
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100469 return ret_cfg
470
471 def parse_config(self, cfg):
472 """ Parse a valid configuration file into a set of build dicts """
473
Minos Galanakisea421232019-06-20 17:11:28 +0100474 ret_cfg = {}
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100475
Minos Galanakisea421232019-06-20 17:11:28 +0100476 # Config entries which are not subject to changes during combinations
477 static_cfg = cfg["common_params"]
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100478
Minos Galanakisea421232019-06-20 17:11:28 +0100479 # Converth the code path to absolute path
480 abs_code_dir = static_cfg["codebase_root_dir"]
481 abs_code_dir = os.path.abspath(os.path.expanduser(abs_code_dir))
482 static_cfg["codebase_root_dir"] = abs_code_dir
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100483
Minos Galanakisea421232019-06-20 17:11:28 +0100484 # seed_params is an optional field. Do not proccess if it is missing
485 if "seed_params" in cfg:
486 comb_cfg = cfg["seed_params"]
487 # Generate a list of all possible confugration combinations
488 ret_cfg = TFM_Build_Manager.generate_config_list(comb_cfg,
489 static_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100490
Minos Galanakisea421232019-06-20 17:11:28 +0100491 # invalid is an optional field. Do not proccess if it is missing
492 if "invalid" in cfg:
493 # Invalid configurations(Do not build)
494 invalid_cfg = cfg["invalid"]
495 # Remove the rejected entries from the test list
496 rejection_cfg = TFM_Build_Manager.generate_rejection_list(
497 comb_cfg,
498 static_cfg,
499 invalid_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100500
Minos Galanakisea421232019-06-20 17:11:28 +0100501 # Subtract the two configurations
502 ret_cfg = {k: v for k, v in ret_cfg.items()
503 if k not in rejection_cfg}
504 self.simple_config = False
505 else:
506 self.simple_config = True
507 return ret_cfg, static_cfg
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100508
Minos Galanakisea421232019-06-20 17:11:28 +0100509 # ----- Override bellow methods when subclassing for other projects ----- #
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100510
Minos Galanakisea421232019-06-20 17:11:28 +0100511 def print_summary(self):
512 """ Print an comprehensive list of the build jobs with their status """
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100513
Minos Galanakisea421232019-06-20 17:11:28 +0100514 try:
515 full_rep = self.unstash("Build Report")["report"]
516 fl = ([k for k, v in full_rep.items() if v['status'] == 'Failed'])
517 ps = ([k for k, v in full_rep.items() if v['status'] == 'Success'])
518 except Exception as E:
Karl Zhangaff558a2020-05-15 14:28:23 +0100519 print("No report generated", E)
Minos Galanakisea421232019-06-20 17:11:28 +0100520 return
521 if fl:
522 print_test(t_list=fl, status="failed", tname="Builds")
523 if ps:
524 print_test(t_list=ps, status="passed", tname="Builds")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100525
Minos Galanakisea421232019-06-20 17:11:28 +0100526 @staticmethod
527 def generate_config_list(seed_config, static_config):
528 """ Generate all possible configuration combinations from a group of
529 lists of compiler options"""
530 config_list = []
531
532 if static_config["config_type"] == "tf-m":
533 cfg_name = "TFM_Build_CFG"
534 # Ensure the fieds are sorted in the desired order
535 # seed_config can be a subset of sort order for configurations with
536 # optional parameters.
537 tags = [n for n in static_config["sort_order"]
538 if n in seed_config.keys()]
Karl Zhangaff558a2020-05-15 14:28:23 +0100539 print("!!!!!!!!!!!gen list %s\r\n" % tags)
Minos Galanakisea421232019-06-20 17:11:28 +0100540
541 data = []
542 for key in tags:
543 data.append(seed_config[key])
544 config_list = gen_cfg_combinations(cfg_name,
545 " ".join(tags),
546 *data)
547 else:
548 print("Not information for project type: %s."
549 " Please check config" % static_config["config_type"])
550
551 ret_cfg = {}
552 # Notify the user for the rejected configuations
553 for i in config_list:
Xinyu Zhang1078e812020-10-15 11:52:36 +0800554 # Convert named tuples to string in a brief format
555 config_param = []
556 config_param.append(mapPlatform[list(i)[0]])
557 config_param.append(mapCompiler[list(i)[1]])
558 if list(i)[2]: # PSA_API
559 config_param.append("PSA")
560 config_param.append(list(i)[3]) # ISOLATION_LEVEL
561 if list(i)[4]: # TEST_REGRESSION
562 config_param.append("REG")
563 if list(i)[5] != "OFF": #TEST_PSA_API
564 config_param.append(mapTestPsaApi[list(i)[5]])
565 config_param.append(list(i)[6]) # BUILD_TYPE
Xinyu Zhanga50432e2020-10-23 18:00:18 +0800566 if list(i)[7] == "ENABLED": # OTP
Xinyu Zhang1078e812020-10-15 11:52:36 +0800567 config_param.append("OTP")
568 if list(i)[8]: # BL2
569 config_param.append("BL2")
570 if list(i)[9]: # NS
571 config_param.append("NS")
572 if list(i)[10]: # PROFILE
573 config_param.append(mapProfile[list(i)[10]])
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800574 if list(i)[11] == "OFF": #PARTITION_PS
575 config_param.append("PSOFF")
Xinyu Zhang1078e812020-10-15 11:52:36 +0800576 i_str = "_".join(config_param)
Karl Zhangaff558a2020-05-15 14:28:23 +0100577 ret_cfg[i_str] = i
Minos Galanakisea421232019-06-20 17:11:28 +0100578 return ret_cfg
579
580 @staticmethod
581 def generate_rejection_list(seed_config,
582 static_config,
583 rejection_list):
584 rejection_cfg = {}
585
586 if static_config["config_type"] == "tf-m":
587
588 # If rejection list is empty do nothing
589 if not rejection_list:
590 return rejection_cfg
591
592 tags = [n for n in static_config["sort_order"]
593 if n in seed_config.keys()]
594 sorted_default_lst = [seed_config[k] for k in tags]
595
596 # If tags are not alligned with rejection list entries quit
597 if len(tags) != len(rejection_list[0]):
598 print(len(tags), len(rejection_list[0]))
599 print("Error, tags should be assigned to each "
600 "of the rejection inputs")
601 return []
602
603 # Replace wildcard ( "*") entries with every
604 # inluded in cfg variant
605 for k in rejection_list:
606 # Pad the omitted values with wildcard char *
607 res_list = list(k) + ["*"] * (5 - len(k))
608 print("Working on rejection input: %s" % (res_list))
609
610 for n in range(len(res_list)):
611
612 res_list[n] = [res_list[n]] if res_list[n] != "*" \
613 else sorted_default_lst[n]
614
615 # Generate a configuration and a name for the completed array
616 rj_cfg = TFM_Build_Manager.generate_config_list(
617 dict(zip(tags, res_list)),
618 static_config)
619
620 # Append the configuration to the existing ones
Dean Birchf6aa3da2020-01-24 12:29:38 +0000621 rejection_cfg = dict(rejection_cfg, **rj_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100622
623 # Notfy the user for the rejected configuations
624 for i in rejection_cfg.keys():
625 print("Rejecting config %s" % i)
626 else:
627 print("Not information for project type: %s."
628 " Please check config" % static_config["config_type"])
629 return rejection_cfg