blob: 44b4d580725b427a2c9727d93155dfda5922cf32 [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
Xinyu Zhang9fd74242020-10-22 11:30:50 +080054mapProfile = {"profile_small": "SMALL",
55 "profile_medium": "MEDIUM"}
Xinyu Zhang1078e812020-10-15 11:52:36 +080056
57
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010058class TFM_Build_Manager(structuredTask):
59 """ Class that will load a configuration out of a json file, schedule
60 the builds, and produce a report """
61
62 def __init__(self,
63 tfm_dir, # TFM root directory
64 work_dir, # Current working directory(ie logs)
65 cfg_dict, # Input config dictionary of the following form
66 # input_dict = {"PROJ_CONFIG": "ConfigRegression",
67 # "TARGET_PLATFORM": "MUSCA_A",
68 # "COMPILER": "ARMCLANG",
69 # "CMAKE_BUILD_TYPE": "Debug"}
70 report=None, # File to produce report
71 parallel_builds=3, # Number of builds to run in parallel
Minos Galanakisea421232019-06-20 17:11:28 +010072 build_threads=3, # Number of threads used per build
73 install=False, # Install libraries after build
74 img_sizes=False, # Use arm-none-eabi-size for size info
75 relative_paths=False): # Store relative paths in report
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010076 self._tbm_build_threads = build_threads
77 self._tbm_conc_builds = parallel_builds
78 self._tbm_install = install
Minos Galanakisea421232019-06-20 17:11:28 +010079 self._tbm_img_sizes = img_sizes
80 self._tbm_relative_paths = relative_paths
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010081
82 # Required by other methods, always set working directory first
83 self._tbm_work_dir = os.path.abspath(os.path.expanduser(work_dir))
84
85 self._tbm_tfm_dir = os.path.abspath(os.path.expanduser(tfm_dir))
86
Karl Zhangaff558a2020-05-15 14:28:23 +010087 print("bm param tfm_dir %s" % tfm_dir)
88 print("bm %s %s %s" % (work_dir, cfg_dict, self._tbm_work_dir))
Minos Galanakisea421232019-06-20 17:11:28 +010089 # Internal flag to tag simple (non combination formatted configs)
90 self.simple_config = False
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010091 self._tbm_report = report
92
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010093 self._tbm_cfg = self.load_config(cfg_dict, self._tbm_work_dir)
Minos Galanakisea421232019-06-20 17:11:28 +010094 self._tbm_build_cfg, \
95 self.tbm_common_cfg = self.parse_config(self._tbm_cfg)
Karl Zhangaff558a2020-05-15 14:28:23 +010096 self._tfb_code_base_updated = False
97 self._tfb_log_f = "CodeBasePrepare.log"
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010098
99 super(TFM_Build_Manager, self).__init__(name="TFM_Build_Manager")
100
Dean Bircha6ede7e2020-03-13 14:00:33 +0000101 def get_config(self):
102 return list(self._tbm_build_cfg.keys())
Dean Birch5cb5a882020-01-24 11:37:13 +0000103
Dean Bircha6ede7e2020-03-13 14:00:33 +0000104 def print_config_environment(self, config, silence_stderr=False):
Dean Birch5cb5a882020-01-24 11:37:13 +0000105 """
106 For a given build configuration from output of print_config
107 method, print environment variables to build.
108 """
109 if config not in self._tbm_build_cfg:
Dean Bircha6ede7e2020-03-13 14:00:33 +0000110 if not silence_stderr:
111 print("Error: no such config {}".format(config), file=sys.stderr)
Dean Birch5cb5a882020-01-24 11:37:13 +0000112 sys.exit(1)
113 config_details = self._tbm_build_cfg[config]
114 argument_list = [
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000115 "CONFIG_NAME={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800116 "TFM_PLATFORM={}",
117 "TOOLCHAIN_FILE={}",
118 "PSA_API={}",
119 "ISOLATION_LEVEL={}",
120 "TEST_REGRESSION={}",
121 "TEST_PSA_API={}",
Dean Birch5cb5a882020-01-24 11:37:13 +0000122 "CMAKE_BUILD_TYPE={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800123 "OTP={}",
Dean Birch5cb5a882020-01-24 11:37:13 +0000124 "BL2={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800125 "NS={}",
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800126 "PROFILE={}",
127 "PARTITION_PS={}"
Dean Birch5cb5a882020-01-24 11:37:13 +0000128 ]
129 print(
130 "\n".join(argument_list)
131 .format(
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000132 config,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800133 config_details.tfm_platform,
134 config_details.toolchain_file,
135 config_details.psa_api,
136 config_details.isolation_level,
137 config_details.test_regression,
138 config_details.test_psa_api,
Dean Birch5cb5a882020-01-24 11:37:13 +0000139 config_details.cmake_build_type,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800140 config_details.with_otp,
141 config_details.with_bl2,
142 config_details.with_ns,
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800143 "N.A" if not config_details.profile else config_details.profile,
144 config_details.partition_ps
Dean Birch5cb5a882020-01-24 11:37:13 +0000145 )
146 .strip()
147 )
148
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000149 def print_build_commands(self, config, silence_stderr=False):
150 config_details = self._tbm_build_cfg[config]
151 codebase_dir = os.path.join(os.getcwd(),"trusted-firmware-m")
Xinyu Zhangb708f572020-09-15 11:43:46 +0800152 build_dir=os.path.join(os.getcwd(),"trusted-firmware-m/build")
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000153 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 +0800154 build_commands = [build_config["config_template"]]
155 for command in build_config["build_cmds"]:
156 build_commands.append(command)
Xinyu Zhangb708f572020-09-15 11:43:46 +0800157 print(" ;\n".join(build_commands))
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000158
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100159 def pre_eval(self):
160 """ Tests that need to be run in set-up state """
161 return True
162
163 def pre_exec(self, eval_ret):
164 """ """
165
Minos Galanakisea421232019-06-20 17:11:28 +0100166 def override_tbm_cfg_params(self, config, override_keys, **params):
167 """ Using a dictionay as input, for each key defined in
168 override_keys it will replace the config[key] entries with
169 the key=value parameters provided """
170
171 for key in override_keys:
172 if isinstance(config[key], list):
173 config[key] = [n % params for n in config[key]]
174 elif isinstance(config[key], str):
175 config[key] = config[key] % params
176 else:
177 raise Exception("Config does not contain key %s "
178 "of type %s" % (key, config[key]))
179 return config
180
Karl Zhangaff558a2020-05-15 14:28:23 +0100181 def pre_build(self, build_cfg):
182 print("pre_build start %s \r\nself._tfb_cfg %s\r\n" %
183 (self, build_cfg))
184
185 try:
186 if self._tfb_code_base_updated:
187 print("Code base has been updated")
188 return True
189
190 self._tfb_code_base_updated = True
191
192 if "build_psa_api" in build_cfg:
193 # FF IPC build needs repo manifest update for TFM and PSA arch test
194 if "build_ff_ipc" in build_cfg:
195 print("Checkout to FF IPC code base")
196 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
197 _api_test_manifest = "git checkout . ; python3 tools/scripts/manifest_update.py"
198 if subprocess_log(_api_test_manifest,
199 self._tfb_log_f,
200 append=True,
201 prefix=_api_test_manifest):
202
203 raise Exception("Python Failed please check log: %s" %
204 self._tfb_log_f)
205
206 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py -m tools/tfm_psa_ff_test_manifest_list.yaml append"
207 os.chdir(build_cfg["codebase_root_dir"])
208 if subprocess_log(_api_test_manifest_tfm,
209 self._tfb_log_f,
210 append=True,
211 prefix=_api_test_manifest_tfm):
212
213 raise Exception("Python TFM Failed please check log: %s" %
214 self._tfb_log_f)
215 return True
216
217 print("Checkout to default code base")
218 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
219 _api_test_manifest = "git checkout ."
220 if subprocess_log(_api_test_manifest,
221 self._tfb_log_f,
222 append=True,
223 prefix=_api_test_manifest):
224
225 raise Exception("Python Failed please check log: %s" %
226 self._tfb_log_f)
227
228 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py"
229 os.chdir(build_cfg["codebase_root_dir"])
230 if subprocess_log(_api_test_manifest_tfm,
231 self._tfb_log_f,
232 append=True,
233 prefix=_api_test_manifest_tfm):
234
235 raise Exception("Python TFM Failed please check log: %s" %
236 self._tfb_log_f)
237 finally:
238 print("python pass after builder prepare")
239 os.chdir(build_cfg["codebase_root_dir"] + "/../")
240
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100241 def task_exec(self):
242 """ Create a build pool and execute them in parallel """
243
244 build_pool = []
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100245
Minos Galanakisea421232019-06-20 17:11:28 +0100246 # When a config is flagged as a single build config.
247 # Name is evaluated by config type
248 if self.simple_config:
249
250 build_cfg = deepcopy(self.tbm_common_cfg)
251
252 # Extract the common for all elements of config
253 for key in ["build_cmds", "required_artefacts"]:
254 try:
255 build_cfg[key] = build_cfg[key]["all"]
256 except KeyError:
257 build_cfg[key] = []
258 name = build_cfg["config_type"]
259
260 # Override _tbm_xxx paths in commands
261 # plafrom in not guaranteed without seeds so _tbm_target_platform
262 # is ignored
263 over_dict = {"_tbm_build_dir_": os.path.join(self._tbm_work_dir,
264 name),
265 "_tbm_code_dir_": build_cfg["codebase_root_dir"]}
266
267 build_cfg = self.override_tbm_cfg_params(build_cfg,
268 ["build_cmds",
269 "required_artefacts",
270 "artifact_capture_rex"],
271 **over_dict)
272
273 # Overrides path in expected artefacts
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100274 print("Loading config %s" % name)
Minos Galanakisea421232019-06-20 17:11:28 +0100275
276 build_pool.append(TFM_Builder(
277 name=name,
278 work_dir=self._tbm_work_dir,
279 cfg_dict=build_cfg,
280 build_threads=self._tbm_build_threads,
281 img_sizes=self._tbm_img_sizes,
282 relative_paths=self._tbm_relative_paths))
283 # When a seed pool is provided iterate through the entries
284 # and update platform spefific parameters
285 elif len(self._tbm_build_cfg):
Karl Zhangaff558a2020-05-15 14:28:23 +0100286 print("\r\n_tbm_build_cfg %s\r\n tbm_common_cfg %s\r\n" \
287 % (self._tbm_build_cfg, self.tbm_common_cfg))
Minos Galanakisea421232019-06-20 17:11:28 +0100288 for name, i in self._tbm_build_cfg.items():
289 # Do not modify the original config
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000290 build_cfg = self.get_build_config(i, name)
Karl Zhangaff558a2020-05-15 14:28:23 +0100291 self.pre_build(build_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100292 # Overrides path in expected artefacts
293 print("Loading config %s" % name)
294
295 build_pool.append(TFM_Builder(
296 name=name,
297 work_dir=self._tbm_work_dir,
298 cfg_dict=build_cfg,
299 build_threads=self._tbm_build_threads,
300 img_sizes=self._tbm_img_sizes,
301 relative_paths=self._tbm_relative_paths))
302 else:
303 print("Could not find any configuration. Check the rejection list")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100304
305 status_rep = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100306 build_rep = {}
307 completed_build_count = 0
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100308 print("Build: Running %d parallel build jobs" % self._tbm_conc_builds)
309 for build_pool_slice in list_chunks(build_pool, self._tbm_conc_builds):
310
311 # Start the builds
312 for build in build_pool_slice:
313 # Only produce output for the first build
314 if build_pool_slice.index(build) != 0:
315 build.mute()
316 print("Build: Starting %s" % build.get_name())
317 build.start()
318
319 # Wait for the builds to complete
320 for build in build_pool_slice:
321 # Wait for build to finish
322 build.join()
323 # Similarly print the logs of the other builds as they complete
324 if build_pool_slice.index(build) != 0:
325 build.log()
Minos Galanakisea421232019-06-20 17:11:28 +0100326 completed_build_count += 1
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100327 print("Build: Finished %s" % build.get_name())
Minos Galanakisea421232019-06-20 17:11:28 +0100328 print("Build Progress:")
329 show_progress(completed_build_count, len(build_pool))
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100330
331 # Store status in report
332 status_rep[build.get_name()] = build.get_status()
Minos Galanakisea421232019-06-20 17:11:28 +0100333 build_rep[build.get_name()] = build.report()
334
335 # Include the original input configuration in the report
336
337 metadata = {"input_build_cfg": self._tbm_cfg,
338 "build_dir": self._tbm_work_dir
339 if not self._tbm_relative_paths
340 else resolve_rel_path(self._tbm_work_dir),
341 "time": time()}
342
343 full_rep = {"report": build_rep,
344 "_metadata_": metadata}
345
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100346 # Store the report
347 self.stash("Build Status", status_rep)
348 self.stash("Build Report", full_rep)
349
350 if self._tbm_report:
351 print("Exported build report to file:", self._tbm_report)
352 save_json(self._tbm_report, full_rep)
353
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000354 def get_build_config(self, i, name, silence=False, build_dir=None, codebase_dir=None):
355 psa_build_dir = self._tbm_work_dir + "/" + name + "/BUILD"
356 if not build_dir:
357 build_dir = os.path.join(self._tbm_work_dir, name)
358 else:
359 psa_build_dir = os.path.join(build_dir, "../../psa-arch-tests/api-tests/build")
360 build_cfg = deepcopy(self.tbm_common_cfg)
361 if not codebase_dir:
362 codebase_dir = build_cfg["codebase_root_dir"]
363 else:
364 # Would prefer to do all with the new variable
365 # However, many things use this from build_cfg elsewhere
366 build_cfg["codebase_root_dir"] = codebase_dir
367 # Extract the common for all elements of config
368 for key in ["build_cmds", "required_artefacts"]:
369 try:
370 build_cfg[key] = deepcopy(self.tbm_common_cfg[key]
371 ["all"])
372 except KeyError as E:
373 build_cfg[key] = []
374 # Extract the platform specific elements of config
375 for key in ["build_cmds", "required_artefacts"]:
376 try:
Xinyu Zhang694eb492020-11-04 18:29:08 +0800377 if i.tfm_platform in self.tbm_common_cfg[key].keys() and i.with_ns:
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000378 build_cfg[key] += deepcopy(self.tbm_common_cfg[key]
Xinyu Zhangb708f572020-09-15 11:43:46 +0800379 [i.tfm_platform])
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000380 except Exception as E:
381 pass
Karl Zhang1eed6322020-07-01 15:38:10 +0800382
383 if os.cpu_count() >= 8:
384 #run in a serviver with scripts, parallel build will use CPU numbers
385 thread_no = " -j 2"
386 else:
387 #run in a docker, usually docker with CPUs less than 8
388 thread_no = " -j " + str(os.cpu_count())
Xinyu Zhangb708f572020-09-15 11:43:46 +0800389 build_cfg["build_cmds"][0] += thread_no
390 overwrite_params = {"codebase_root_dir": build_cfg["codebase_root_dir"],
391 "tfm_platform": i.tfm_platform,
392 "toolchain_file": i.toolchain_file,
393 "psa_api": i.psa_api,
394 "isolation_level": i.isolation_level,
395 "test_regression": i.test_regression,
396 "test_psa_api": i.test_psa_api,
397 "cmake_build_type": i.cmake_build_type,
398 "with_otp": i.with_otp,
399 "with_bl2": i.with_bl2,
400 "with_ns": i.with_ns,
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800401 "profile": "" if i.profile=="N.A" else i.profile,
402 "partition_ps": i.partition_ps}
Xinyu Zhanga0086022020-11-10 18:11:12 +0800403 if i.test_psa_api == "IPC":
Xinyu Zhangcd1ed962020-11-11 16:00:52 +0800404 overwrite_params["test_psa_api"] += " -DINCLUDE_PANIC_TESTS=1"
405 if i.tfm_platform == "musca_b1":
406 overwrite_params["test_psa_api"] += " -DITS_RAM_FS=ON -DPS_RAM_FS=ON"
Xinyu Zhangb708f572020-09-15 11:43:46 +0800407 build_cfg["config_template"] %= overwrite_params
Xinyu Zhang694eb492020-11-04 18:29:08 +0800408 if len(build_cfg["build_cmds"]) > 1:
409 overwrite_build_dir = {"_tbm_build_dir_": build_dir}
410 build_cfg["build_cmds"][1] %= overwrite_build_dir
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000411 return build_cfg
412
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100413 def post_eval(self):
414 """ If a single build failed fail the test """
415 try:
Minos Galanakisea421232019-06-20 17:11:28 +0100416 status_dict = self.unstash("Build Status")
417 if not status_dict:
418 raise Exception()
419 retcode_sum = sum(status_dict.values())
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100420 if retcode_sum != 0:
421 raise Exception()
422 return True
423 except Exception as e:
424 return False
425
426 def post_exec(self, eval_ret):
427 """ Generate a report and fail the script if build == unsuccessfull"""
428
429 self.print_summary()
430 if not eval_ret:
431 print("ERROR: ====> Build Failed! %s" % self.get_name())
432 self.set_status(1)
433 else:
434 print("SUCCESS: ====> Build Complete!")
435 self.set_status(0)
436
437 def get_report(self):
438 """ Expose the internal report to a new object for external classes """
439 return deepcopy(self.unstash("Build Report"))
440
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100441 def load_config(self, config, work_dir):
442 try:
443 # passing config_name param supersseeds fileparam
444 if isinstance(config, dict):
445 ret_cfg = deepcopy(config)
446 elif isinstance(config, str):
447 # If the string does not descrive a file try to look for it in
448 # work directory
449 if not os.path.isfile(config):
450 # remove path from file
451 config_2 = os.path.split(config)[-1]
452 # look in the current working directory
453 config_2 = os.path.join(work_dir, config_2)
454 if not os.path.isfile(config_2):
455 m = "Could not find cfg in %s or %s " % (config,
456 config_2)
457 raise Exception(m)
458 # If fille exists in working directory
459 else:
460 config = config_2
461 ret_cfg = load_json(config)
462
463 else:
464 raise Exception("Need to provide a valid config name or file."
465 "Please use --config/--config-file parameter.")
466 except Exception as e:
467 print("Error:%s \nCould not load a valid config" % e)
468 sys.exit(1)
469
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100470 return ret_cfg
471
472 def parse_config(self, cfg):
473 """ Parse a valid configuration file into a set of build dicts """
474
Minos Galanakisea421232019-06-20 17:11:28 +0100475 ret_cfg = {}
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100476
Minos Galanakisea421232019-06-20 17:11:28 +0100477 # Config entries which are not subject to changes during combinations
478 static_cfg = cfg["common_params"]
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100479
Minos Galanakisea421232019-06-20 17:11:28 +0100480 # Converth the code path to absolute path
481 abs_code_dir = static_cfg["codebase_root_dir"]
482 abs_code_dir = os.path.abspath(os.path.expanduser(abs_code_dir))
483 static_cfg["codebase_root_dir"] = abs_code_dir
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100484
Minos Galanakisea421232019-06-20 17:11:28 +0100485 # seed_params is an optional field. Do not proccess if it is missing
486 if "seed_params" in cfg:
487 comb_cfg = cfg["seed_params"]
488 # Generate a list of all possible confugration combinations
489 ret_cfg = TFM_Build_Manager.generate_config_list(comb_cfg,
490 static_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100491
Minos Galanakisea421232019-06-20 17:11:28 +0100492 # invalid is an optional field. Do not proccess if it is missing
493 if "invalid" in cfg:
494 # Invalid configurations(Do not build)
495 invalid_cfg = cfg["invalid"]
496 # Remove the rejected entries from the test list
497 rejection_cfg = TFM_Build_Manager.generate_rejection_list(
498 comb_cfg,
499 static_cfg,
500 invalid_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100501
Minos Galanakisea421232019-06-20 17:11:28 +0100502 # Subtract the two configurations
503 ret_cfg = {k: v for k, v in ret_cfg.items()
504 if k not in rejection_cfg}
505 self.simple_config = False
506 else:
507 self.simple_config = True
508 return ret_cfg, static_cfg
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100509
Minos Galanakisea421232019-06-20 17:11:28 +0100510 # ----- Override bellow methods when subclassing for other projects ----- #
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100511
Minos Galanakisea421232019-06-20 17:11:28 +0100512 def print_summary(self):
513 """ Print an comprehensive list of the build jobs with their status """
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100514
Minos Galanakisea421232019-06-20 17:11:28 +0100515 try:
516 full_rep = self.unstash("Build Report")["report"]
517 fl = ([k for k, v in full_rep.items() if v['status'] == 'Failed'])
518 ps = ([k for k, v in full_rep.items() if v['status'] == 'Success'])
519 except Exception as E:
Karl Zhangaff558a2020-05-15 14:28:23 +0100520 print("No report generated", E)
Minos Galanakisea421232019-06-20 17:11:28 +0100521 return
522 if fl:
523 print_test(t_list=fl, status="failed", tname="Builds")
524 if ps:
525 print_test(t_list=ps, status="passed", tname="Builds")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100526
Minos Galanakisea421232019-06-20 17:11:28 +0100527 @staticmethod
528 def generate_config_list(seed_config, static_config):
529 """ Generate all possible configuration combinations from a group of
530 lists of compiler options"""
531 config_list = []
532
533 if static_config["config_type"] == "tf-m":
534 cfg_name = "TFM_Build_CFG"
535 # Ensure the fieds are sorted in the desired order
536 # seed_config can be a subset of sort order for configurations with
537 # optional parameters.
538 tags = [n for n in static_config["sort_order"]
539 if n in seed_config.keys()]
Karl Zhangaff558a2020-05-15 14:28:23 +0100540 print("!!!!!!!!!!!gen list %s\r\n" % tags)
Minos Galanakisea421232019-06-20 17:11:28 +0100541
542 data = []
543 for key in tags:
544 data.append(seed_config[key])
545 config_list = gen_cfg_combinations(cfg_name,
546 " ".join(tags),
547 *data)
548 else:
549 print("Not information for project type: %s."
550 " Please check config" % static_config["config_type"])
551
552 ret_cfg = {}
553 # Notify the user for the rejected configuations
554 for i in config_list:
Xinyu Zhang1078e812020-10-15 11:52:36 +0800555 # Convert named tuples to string in a brief format
556 config_param = []
557 config_param.append(mapPlatform[list(i)[0]])
558 config_param.append(mapCompiler[list(i)[1]])
559 if list(i)[2]: # PSA_API
560 config_param.append("PSA")
561 config_param.append(list(i)[3]) # ISOLATION_LEVEL
562 if list(i)[4]: # TEST_REGRESSION
563 config_param.append("REG")
564 if list(i)[5] != "OFF": #TEST_PSA_API
565 config_param.append(mapTestPsaApi[list(i)[5]])
566 config_param.append(list(i)[6]) # BUILD_TYPE
Xinyu Zhanga50432e2020-10-23 18:00:18 +0800567 if list(i)[7] == "ENABLED": # OTP
Xinyu Zhang1078e812020-10-15 11:52:36 +0800568 config_param.append("OTP")
569 if list(i)[8]: # BL2
570 config_param.append("BL2")
571 if list(i)[9]: # NS
572 config_param.append("NS")
573 if list(i)[10]: # PROFILE
574 config_param.append(mapProfile[list(i)[10]])
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800575 if list(i)[11] == "OFF": #PARTITION_PS
576 config_param.append("PSOFF")
Xinyu Zhang1078e812020-10-15 11:52:36 +0800577 i_str = "_".join(config_param)
Karl Zhangaff558a2020-05-15 14:28:23 +0100578 ret_cfg[i_str] = i
Minos Galanakisea421232019-06-20 17:11:28 +0100579 return ret_cfg
580
581 @staticmethod
582 def generate_rejection_list(seed_config,
583 static_config,
584 rejection_list):
585 rejection_cfg = {}
586
587 if static_config["config_type"] == "tf-m":
588
589 # If rejection list is empty do nothing
590 if not rejection_list:
591 return rejection_cfg
592
593 tags = [n for n in static_config["sort_order"]
594 if n in seed_config.keys()]
595 sorted_default_lst = [seed_config[k] for k in tags]
596
597 # If tags are not alligned with rejection list entries quit
598 if len(tags) != len(rejection_list[0]):
599 print(len(tags), len(rejection_list[0]))
600 print("Error, tags should be assigned to each "
601 "of the rejection inputs")
602 return []
603
604 # Replace wildcard ( "*") entries with every
605 # inluded in cfg variant
606 for k in rejection_list:
607 # Pad the omitted values with wildcard char *
608 res_list = list(k) + ["*"] * (5 - len(k))
609 print("Working on rejection input: %s" % (res_list))
610
611 for n in range(len(res_list)):
612
613 res_list[n] = [res_list[n]] if res_list[n] != "*" \
614 else sorted_default_lst[n]
615
616 # Generate a configuration and a name for the completed array
617 rj_cfg = TFM_Build_Manager.generate_config_list(
618 dict(zip(tags, res_list)),
619 static_config)
620
621 # Append the configuration to the existing ones
Dean Birchf6aa3da2020-01-24 12:29:38 +0000622 rejection_cfg = dict(rejection_cfg, **rj_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100623
624 # Notfy the user for the rejected configuations
625 for i in rejection_cfg.keys():
626 print("Rejecting config %s" % i)
627 else:
628 print("Not information for project type: %s."
629 " Please check config" % static_config["config_type"])
630 return rejection_cfg