blob: a1c7c453acc24c63e81f11fa6b55213a58f8dcbd [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
Mark Horvath8d281cd2020-12-07 15:20:26 +010034mapPlatform = {"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/sse_200": "MUSCA_B1",
42 "musca_b1/secure_enclave": "MUSCA_B1_SE",
43 "musca_s1": "MUSCA_S1"}
Xinyu Zhang1078e812020-10-15 11:52:36 +080044
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",
Xinyu Zhang9b1aef92021-03-12 15:36:44 +080055 "profile_medium": "MEDIUM",
56 "profile_large": "LARGE"}
Xinyu Zhang1078e812020-10-15 11:52:36 +080057
58
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010059class TFM_Build_Manager(structuredTask):
60 """ Class that will load a configuration out of a json file, schedule
61 the builds, and produce a report """
62
63 def __init__(self,
64 tfm_dir, # TFM root directory
65 work_dir, # Current working directory(ie logs)
66 cfg_dict, # Input config dictionary of the following form
67 # input_dict = {"PROJ_CONFIG": "ConfigRegression",
68 # "TARGET_PLATFORM": "MUSCA_A",
69 # "COMPILER": "ARMCLANG",
70 # "CMAKE_BUILD_TYPE": "Debug"}
71 report=None, # File to produce report
72 parallel_builds=3, # Number of builds to run in parallel
Minos Galanakisea421232019-06-20 17:11:28 +010073 build_threads=3, # Number of threads used per build
74 install=False, # Install libraries after build
75 img_sizes=False, # Use arm-none-eabi-size for size info
76 relative_paths=False): # Store relative paths in report
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010077 self._tbm_build_threads = build_threads
78 self._tbm_conc_builds = parallel_builds
79 self._tbm_install = install
Minos Galanakisea421232019-06-20 17:11:28 +010080 self._tbm_img_sizes = img_sizes
81 self._tbm_relative_paths = relative_paths
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010082
83 # Required by other methods, always set working directory first
84 self._tbm_work_dir = os.path.abspath(os.path.expanduser(work_dir))
85
86 self._tbm_tfm_dir = os.path.abspath(os.path.expanduser(tfm_dir))
87
Karl Zhangaff558a2020-05-15 14:28:23 +010088 print("bm param tfm_dir %s" % tfm_dir)
89 print("bm %s %s %s" % (work_dir, cfg_dict, self._tbm_work_dir))
Minos Galanakisea421232019-06-20 17:11:28 +010090 # Internal flag to tag simple (non combination formatted configs)
91 self.simple_config = False
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010092 self._tbm_report = report
93
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010094 self._tbm_cfg = self.load_config(cfg_dict, self._tbm_work_dir)
Minos Galanakisea421232019-06-20 17:11:28 +010095 self._tbm_build_cfg, \
96 self.tbm_common_cfg = self.parse_config(self._tbm_cfg)
Karl Zhangaff558a2020-05-15 14:28:23 +010097 self._tfb_code_base_updated = False
98 self._tfb_log_f = "CodeBasePrepare.log"
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010099
100 super(TFM_Build_Manager, self).__init__(name="TFM_Build_Manager")
101
Dean Bircha6ede7e2020-03-13 14:00:33 +0000102 def get_config(self):
103 return list(self._tbm_build_cfg.keys())
Dean Birch5cb5a882020-01-24 11:37:13 +0000104
Dean Bircha6ede7e2020-03-13 14:00:33 +0000105 def print_config_environment(self, config, silence_stderr=False):
Dean Birch5cb5a882020-01-24 11:37:13 +0000106 """
107 For a given build configuration from output of print_config
108 method, print environment variables to build.
109 """
110 if config not in self._tbm_build_cfg:
Dean Bircha6ede7e2020-03-13 14:00:33 +0000111 if not silence_stderr:
112 print("Error: no such config {}".format(config), file=sys.stderr)
Dean Birch5cb5a882020-01-24 11:37:13 +0000113 sys.exit(1)
114 config_details = self._tbm_build_cfg[config]
115 argument_list = [
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000116 "CONFIG_NAME={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800117 "TFM_PLATFORM={}",
118 "TOOLCHAIN_FILE={}",
119 "PSA_API={}",
120 "ISOLATION_LEVEL={}",
121 "TEST_REGRESSION={}",
122 "TEST_PSA_API={}",
Dean Birch5cb5a882020-01-24 11:37:13 +0000123 "CMAKE_BUILD_TYPE={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800124 "OTP={}",
Dean Birch5cb5a882020-01-24 11:37:13 +0000125 "BL2={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800126 "NS={}",
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800127 "PROFILE={}",
128 "PARTITION_PS={}"
Dean Birch5cb5a882020-01-24 11:37:13 +0000129 ]
130 print(
131 "\n".join(argument_list)
132 .format(
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000133 config,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800134 config_details.tfm_platform,
135 config_details.toolchain_file,
136 config_details.psa_api,
137 config_details.isolation_level,
138 config_details.test_regression,
139 config_details.test_psa_api,
Dean Birch5cb5a882020-01-24 11:37:13 +0000140 config_details.cmake_build_type,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800141 config_details.with_otp,
142 config_details.with_bl2,
143 config_details.with_ns,
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800144 "N.A" if not config_details.profile else config_details.profile,
145 config_details.partition_ps
Dean Birch5cb5a882020-01-24 11:37:13 +0000146 )
147 .strip()
148 )
149
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000150 def print_build_commands(self, config, silence_stderr=False):
151 config_details = self._tbm_build_cfg[config]
152 codebase_dir = os.path.join(os.getcwd(),"trusted-firmware-m")
Xinyu Zhangb708f572020-09-15 11:43:46 +0800153 build_dir=os.path.join(os.getcwd(),"trusted-firmware-m/build")
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000154 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 +0800155 build_commands = [build_config["config_template"]]
156 for command in build_config["build_cmds"]:
157 build_commands.append(command)
Xinyu Zhangb708f572020-09-15 11:43:46 +0800158 print(" ;\n".join(build_commands))
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000159
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100160 def pre_eval(self):
161 """ Tests that need to be run in set-up state """
162 return True
163
164 def pre_exec(self, eval_ret):
165 """ """
166
Minos Galanakisea421232019-06-20 17:11:28 +0100167 def override_tbm_cfg_params(self, config, override_keys, **params):
168 """ Using a dictionay as input, for each key defined in
169 override_keys it will replace the config[key] entries with
170 the key=value parameters provided """
171
172 for key in override_keys:
173 if isinstance(config[key], list):
174 config[key] = [n % params for n in config[key]]
175 elif isinstance(config[key], str):
176 config[key] = config[key] % params
177 else:
178 raise Exception("Config does not contain key %s "
179 "of type %s" % (key, config[key]))
180 return config
181
Karl Zhangaff558a2020-05-15 14:28:23 +0100182 def pre_build(self, build_cfg):
183 print("pre_build start %s \r\nself._tfb_cfg %s\r\n" %
184 (self, build_cfg))
185
186 try:
187 if self._tfb_code_base_updated:
188 print("Code base has been updated")
189 return True
190
191 self._tfb_code_base_updated = True
192
193 if "build_psa_api" in build_cfg:
194 # FF IPC build needs repo manifest update for TFM and PSA arch test
195 if "build_ff_ipc" in build_cfg:
196 print("Checkout to FF IPC code base")
197 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
198 _api_test_manifest = "git checkout . ; python3 tools/scripts/manifest_update.py"
199 if subprocess_log(_api_test_manifest,
200 self._tfb_log_f,
201 append=True,
202 prefix=_api_test_manifest):
203
204 raise Exception("Python Failed please check log: %s" %
205 self._tfb_log_f)
206
207 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py -m tools/tfm_psa_ff_test_manifest_list.yaml append"
208 os.chdir(build_cfg["codebase_root_dir"])
209 if subprocess_log(_api_test_manifest_tfm,
210 self._tfb_log_f,
211 append=True,
212 prefix=_api_test_manifest_tfm):
213
214 raise Exception("Python TFM Failed please check log: %s" %
215 self._tfb_log_f)
216 return True
217
218 print("Checkout to default code base")
219 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
220 _api_test_manifest = "git checkout ."
221 if subprocess_log(_api_test_manifest,
222 self._tfb_log_f,
223 append=True,
224 prefix=_api_test_manifest):
225
226 raise Exception("Python Failed please check log: %s" %
227 self._tfb_log_f)
228
229 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py"
230 os.chdir(build_cfg["codebase_root_dir"])
231 if subprocess_log(_api_test_manifest_tfm,
232 self._tfb_log_f,
233 append=True,
234 prefix=_api_test_manifest_tfm):
235
236 raise Exception("Python TFM Failed please check log: %s" %
237 self._tfb_log_f)
238 finally:
239 print("python pass after builder prepare")
240 os.chdir(build_cfg["codebase_root_dir"] + "/../")
241
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100242 def task_exec(self):
243 """ Create a build pool and execute them in parallel """
244
245 build_pool = []
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100246
Minos Galanakisea421232019-06-20 17:11:28 +0100247 # When a config is flagged as a single build config.
248 # Name is evaluated by config type
249 if self.simple_config:
250
251 build_cfg = deepcopy(self.tbm_common_cfg)
252
253 # Extract the common for all elements of config
254 for key in ["build_cmds", "required_artefacts"]:
255 try:
256 build_cfg[key] = build_cfg[key]["all"]
257 except KeyError:
258 build_cfg[key] = []
259 name = build_cfg["config_type"]
260
261 # Override _tbm_xxx paths in commands
262 # plafrom in not guaranteed without seeds so _tbm_target_platform
263 # is ignored
264 over_dict = {"_tbm_build_dir_": os.path.join(self._tbm_work_dir,
265 name),
266 "_tbm_code_dir_": build_cfg["codebase_root_dir"]}
267
268 build_cfg = self.override_tbm_cfg_params(build_cfg,
269 ["build_cmds",
270 "required_artefacts",
271 "artifact_capture_rex"],
272 **over_dict)
273
274 # Overrides path in expected artefacts
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100275 print("Loading config %s" % name)
Minos Galanakisea421232019-06-20 17:11:28 +0100276
277 build_pool.append(TFM_Builder(
278 name=name,
279 work_dir=self._tbm_work_dir,
280 cfg_dict=build_cfg,
281 build_threads=self._tbm_build_threads,
282 img_sizes=self._tbm_img_sizes,
283 relative_paths=self._tbm_relative_paths))
284 # When a seed pool is provided iterate through the entries
285 # and update platform spefific parameters
286 elif len(self._tbm_build_cfg):
Karl Zhangaff558a2020-05-15 14:28:23 +0100287 print("\r\n_tbm_build_cfg %s\r\n tbm_common_cfg %s\r\n" \
288 % (self._tbm_build_cfg, self.tbm_common_cfg))
Minos Galanakisea421232019-06-20 17:11:28 +0100289 for name, i in self._tbm_build_cfg.items():
290 # Do not modify the original config
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000291 build_cfg = self.get_build_config(i, name)
Karl Zhangaff558a2020-05-15 14:28:23 +0100292 self.pre_build(build_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100293 # Overrides path in expected artefacts
294 print("Loading config %s" % name)
295
296 build_pool.append(TFM_Builder(
297 name=name,
298 work_dir=self._tbm_work_dir,
299 cfg_dict=build_cfg,
300 build_threads=self._tbm_build_threads,
301 img_sizes=self._tbm_img_sizes,
302 relative_paths=self._tbm_relative_paths))
303 else:
304 print("Could not find any configuration. Check the rejection list")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100305
306 status_rep = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100307 build_rep = {}
308 completed_build_count = 0
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100309 print("Build: Running %d parallel build jobs" % self._tbm_conc_builds)
310 for build_pool_slice in list_chunks(build_pool, self._tbm_conc_builds):
311
312 # Start the builds
313 for build in build_pool_slice:
314 # Only produce output for the first build
315 if build_pool_slice.index(build) != 0:
316 build.mute()
317 print("Build: Starting %s" % build.get_name())
318 build.start()
319
320 # Wait for the builds to complete
321 for build in build_pool_slice:
322 # Wait for build to finish
323 build.join()
324 # Similarly print the logs of the other builds as they complete
325 if build_pool_slice.index(build) != 0:
326 build.log()
Minos Galanakisea421232019-06-20 17:11:28 +0100327 completed_build_count += 1
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100328 print("Build: Finished %s" % build.get_name())
Minos Galanakisea421232019-06-20 17:11:28 +0100329 print("Build Progress:")
330 show_progress(completed_build_count, len(build_pool))
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100331
332 # Store status in report
333 status_rep[build.get_name()] = build.get_status()
Minos Galanakisea421232019-06-20 17:11:28 +0100334 build_rep[build.get_name()] = build.report()
335
336 # Include the original input configuration in the report
337
338 metadata = {"input_build_cfg": self._tbm_cfg,
339 "build_dir": self._tbm_work_dir
340 if not self._tbm_relative_paths
341 else resolve_rel_path(self._tbm_work_dir),
342 "time": time()}
343
344 full_rep = {"report": build_rep,
345 "_metadata_": metadata}
346
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100347 # Store the report
348 self.stash("Build Status", status_rep)
349 self.stash("Build Report", full_rep)
350
351 if self._tbm_report:
352 print("Exported build report to file:", self._tbm_report)
353 save_json(self._tbm_report, full_rep)
354
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000355 def get_build_config(self, i, name, silence=False, build_dir=None, codebase_dir=None):
356 psa_build_dir = self._tbm_work_dir + "/" + name + "/BUILD"
357 if not build_dir:
358 build_dir = os.path.join(self._tbm_work_dir, name)
359 else:
360 psa_build_dir = os.path.join(build_dir, "../../psa-arch-tests/api-tests/build")
361 build_cfg = deepcopy(self.tbm_common_cfg)
362 if not codebase_dir:
363 codebase_dir = build_cfg["codebase_root_dir"]
364 else:
365 # Would prefer to do all with the new variable
366 # However, many things use this from build_cfg elsewhere
367 build_cfg["codebase_root_dir"] = codebase_dir
368 # Extract the common for all elements of config
369 for key in ["build_cmds", "required_artefacts"]:
370 try:
371 build_cfg[key] = deepcopy(self.tbm_common_cfg[key]
372 ["all"])
373 except KeyError as E:
374 build_cfg[key] = []
375 # Extract the platform specific elements of config
376 for key in ["build_cmds", "required_artefacts"]:
377 try:
Xinyu Zhang694eb492020-11-04 18:29:08 +0800378 if i.tfm_platform in self.tbm_common_cfg[key].keys() and i.with_ns:
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000379 build_cfg[key] += deepcopy(self.tbm_common_cfg[key]
Xinyu Zhangb708f572020-09-15 11:43:46 +0800380 [i.tfm_platform])
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000381 except Exception as E:
382 pass
Karl Zhang1eed6322020-07-01 15:38:10 +0800383
384 if os.cpu_count() >= 8:
385 #run in a serviver with scripts, parallel build will use CPU numbers
386 thread_no = " -j 2"
387 else:
388 #run in a docker, usually docker with CPUs less than 8
389 thread_no = " -j " + str(os.cpu_count())
Xinyu Zhangb708f572020-09-15 11:43:46 +0800390 build_cfg["build_cmds"][0] += thread_no
391 overwrite_params = {"codebase_root_dir": build_cfg["codebase_root_dir"],
392 "tfm_platform": i.tfm_platform,
393 "toolchain_file": i.toolchain_file,
394 "psa_api": i.psa_api,
395 "isolation_level": i.isolation_level,
396 "test_regression": i.test_regression,
397 "test_psa_api": i.test_psa_api,
398 "cmake_build_type": i.cmake_build_type,
399 "with_otp": i.with_otp,
400 "with_bl2": i.with_bl2,
401 "with_ns": i.with_ns,
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800402 "profile": "" if i.profile=="N.A" else i.profile,
403 "partition_ps": i.partition_ps}
Xinyu Zhanga0086022020-11-10 18:11:12 +0800404 if i.test_psa_api == "IPC":
Xinyu Zhangcd1ed962020-11-11 16:00:52 +0800405 overwrite_params["test_psa_api"] += " -DINCLUDE_PANIC_TESTS=1"
Mark Horvath8d281cd2020-12-07 15:20:26 +0100406 if i.tfm_platform == "musca_b1/sse_200":
Xinyu Zhangcd1ed962020-11-11 16:00:52 +0800407 overwrite_params["test_psa_api"] += " -DITS_RAM_FS=ON -DPS_RAM_FS=ON"
Xinyu Zhangb708f572020-09-15 11:43:46 +0800408 build_cfg["config_template"] %= overwrite_params
Xinyu Zhang694eb492020-11-04 18:29:08 +0800409 if len(build_cfg["build_cmds"]) > 1:
410 overwrite_build_dir = {"_tbm_build_dir_": build_dir}
411 build_cfg["build_cmds"][1] %= overwrite_build_dir
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000412 return build_cfg
413
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100414 def post_eval(self):
415 """ If a single build failed fail the test """
416 try:
Minos Galanakisea421232019-06-20 17:11:28 +0100417 status_dict = self.unstash("Build Status")
418 if not status_dict:
419 raise Exception()
420 retcode_sum = sum(status_dict.values())
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100421 if retcode_sum != 0:
422 raise Exception()
423 return True
424 except Exception as e:
425 return False
426
427 def post_exec(self, eval_ret):
428 """ Generate a report and fail the script if build == unsuccessfull"""
429
430 self.print_summary()
431 if not eval_ret:
432 print("ERROR: ====> Build Failed! %s" % self.get_name())
433 self.set_status(1)
434 else:
435 print("SUCCESS: ====> Build Complete!")
436 self.set_status(0)
437
438 def get_report(self):
439 """ Expose the internal report to a new object for external classes """
440 return deepcopy(self.unstash("Build Report"))
441
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100442 def load_config(self, config, work_dir):
443 try:
444 # passing config_name param supersseeds fileparam
445 if isinstance(config, dict):
446 ret_cfg = deepcopy(config)
447 elif isinstance(config, str):
448 # If the string does not descrive a file try to look for it in
449 # work directory
450 if not os.path.isfile(config):
451 # remove path from file
452 config_2 = os.path.split(config)[-1]
453 # look in the current working directory
454 config_2 = os.path.join(work_dir, config_2)
455 if not os.path.isfile(config_2):
456 m = "Could not find cfg in %s or %s " % (config,
457 config_2)
458 raise Exception(m)
459 # If fille exists in working directory
460 else:
461 config = config_2
462 ret_cfg = load_json(config)
463
464 else:
465 raise Exception("Need to provide a valid config name or file."
466 "Please use --config/--config-file parameter.")
467 except Exception as e:
468 print("Error:%s \nCould not load a valid config" % e)
469 sys.exit(1)
470
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100471 return ret_cfg
472
473 def parse_config(self, cfg):
474 """ Parse a valid configuration file into a set of build dicts """
475
Minos Galanakisea421232019-06-20 17:11:28 +0100476 ret_cfg = {}
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100477
Minos Galanakisea421232019-06-20 17:11:28 +0100478 # Config entries which are not subject to changes during combinations
479 static_cfg = cfg["common_params"]
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100480
Minos Galanakisea421232019-06-20 17:11:28 +0100481 # Converth the code path to absolute path
482 abs_code_dir = static_cfg["codebase_root_dir"]
483 abs_code_dir = os.path.abspath(os.path.expanduser(abs_code_dir))
484 static_cfg["codebase_root_dir"] = abs_code_dir
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100485
Minos Galanakisea421232019-06-20 17:11:28 +0100486 # seed_params is an optional field. Do not proccess if it is missing
487 if "seed_params" in cfg:
488 comb_cfg = cfg["seed_params"]
489 # Generate a list of all possible confugration combinations
490 ret_cfg = TFM_Build_Manager.generate_config_list(comb_cfg,
491 static_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100492
Minos Galanakisea421232019-06-20 17:11:28 +0100493 # invalid is an optional field. Do not proccess if it is missing
494 if "invalid" in cfg:
495 # Invalid configurations(Do not build)
496 invalid_cfg = cfg["invalid"]
497 # Remove the rejected entries from the test list
498 rejection_cfg = TFM_Build_Manager.generate_rejection_list(
499 comb_cfg,
500 static_cfg,
501 invalid_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100502
Minos Galanakisea421232019-06-20 17:11:28 +0100503 # Subtract the two configurations
504 ret_cfg = {k: v for k, v in ret_cfg.items()
505 if k not in rejection_cfg}
506 self.simple_config = False
507 else:
508 self.simple_config = True
509 return ret_cfg, static_cfg
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100510
Minos Galanakisea421232019-06-20 17:11:28 +0100511 # ----- Override bellow methods when subclassing for other projects ----- #
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100512
Minos Galanakisea421232019-06-20 17:11:28 +0100513 def print_summary(self):
514 """ Print an comprehensive list of the build jobs with their status """
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100515
Minos Galanakisea421232019-06-20 17:11:28 +0100516 try:
517 full_rep = self.unstash("Build Report")["report"]
518 fl = ([k for k, v in full_rep.items() if v['status'] == 'Failed'])
519 ps = ([k for k, v in full_rep.items() if v['status'] == 'Success'])
520 except Exception as E:
Karl Zhangaff558a2020-05-15 14:28:23 +0100521 print("No report generated", E)
Minos Galanakisea421232019-06-20 17:11:28 +0100522 return
523 if fl:
524 print_test(t_list=fl, status="failed", tname="Builds")
525 if ps:
526 print_test(t_list=ps, status="passed", tname="Builds")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100527
Minos Galanakisea421232019-06-20 17:11:28 +0100528 @staticmethod
529 def generate_config_list(seed_config, static_config):
530 """ Generate all possible configuration combinations from a group of
531 lists of compiler options"""
532 config_list = []
533
534 if static_config["config_type"] == "tf-m":
535 cfg_name = "TFM_Build_CFG"
536 # Ensure the fieds are sorted in the desired order
537 # seed_config can be a subset of sort order for configurations with
538 # optional parameters.
539 tags = [n for n in static_config["sort_order"]
540 if n in seed_config.keys()]
Karl Zhangaff558a2020-05-15 14:28:23 +0100541 print("!!!!!!!!!!!gen list %s\r\n" % tags)
Minos Galanakisea421232019-06-20 17:11:28 +0100542
543 data = []
544 for key in tags:
545 data.append(seed_config[key])
546 config_list = gen_cfg_combinations(cfg_name,
547 " ".join(tags),
548 *data)
549 else:
550 print("Not information for project type: %s."
551 " Please check config" % static_config["config_type"])
552
553 ret_cfg = {}
554 # Notify the user for the rejected configuations
555 for i in config_list:
Xinyu Zhang1078e812020-10-15 11:52:36 +0800556 # Convert named tuples to string in a brief format
557 config_param = []
558 config_param.append(mapPlatform[list(i)[0]])
559 config_param.append(mapCompiler[list(i)[1]])
560 if list(i)[2]: # PSA_API
561 config_param.append("PSA")
562 config_param.append(list(i)[3]) # ISOLATION_LEVEL
563 if list(i)[4]: # TEST_REGRESSION
564 config_param.append("REG")
565 if list(i)[5] != "OFF": #TEST_PSA_API
566 config_param.append(mapTestPsaApi[list(i)[5]])
567 config_param.append(list(i)[6]) # BUILD_TYPE
Xinyu Zhanga50432e2020-10-23 18:00:18 +0800568 if list(i)[7] == "ENABLED": # OTP
Xinyu Zhang1078e812020-10-15 11:52:36 +0800569 config_param.append("OTP")
570 if list(i)[8]: # BL2
571 config_param.append("BL2")
572 if list(i)[9]: # NS
573 config_param.append("NS")
574 if list(i)[10]: # PROFILE
575 config_param.append(mapProfile[list(i)[10]])
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800576 if list(i)[11] == "OFF": #PARTITION_PS
577 config_param.append("PSOFF")
Xinyu Zhang1078e812020-10-15 11:52:36 +0800578 i_str = "_".join(config_param)
Karl Zhangaff558a2020-05-15 14:28:23 +0100579 ret_cfg[i_str] = i
Minos Galanakisea421232019-06-20 17:11:28 +0100580 return ret_cfg
581
582 @staticmethod
583 def generate_rejection_list(seed_config,
584 static_config,
585 rejection_list):
586 rejection_cfg = {}
587
588 if static_config["config_type"] == "tf-m":
589
590 # If rejection list is empty do nothing
591 if not rejection_list:
592 return rejection_cfg
593
594 tags = [n for n in static_config["sort_order"]
595 if n in seed_config.keys()]
596 sorted_default_lst = [seed_config[k] for k in tags]
597
598 # If tags are not alligned with rejection list entries quit
599 if len(tags) != len(rejection_list[0]):
600 print(len(tags), len(rejection_list[0]))
601 print("Error, tags should be assigned to each "
602 "of the rejection inputs")
603 return []
604
605 # Replace wildcard ( "*") entries with every
606 # inluded in cfg variant
607 for k in rejection_list:
608 # Pad the omitted values with wildcard char *
609 res_list = list(k) + ["*"] * (5 - len(k))
610 print("Working on rejection input: %s" % (res_list))
611
612 for n in range(len(res_list)):
613
614 res_list[n] = [res_list[n]] if res_list[n] != "*" \
615 else sorted_default_lst[n]
616
617 # Generate a configuration and a name for the completed array
618 rj_cfg = TFM_Build_Manager.generate_config_list(
619 dict(zip(tags, res_list)),
620 static_config)
621
622 # Append the configuration to the existing ones
Dean Birchf6aa3da2020-01-24 12:29:38 +0000623 rejection_cfg = dict(rejection_cfg, **rj_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100624
625 # Notfy the user for the rejected configuations
626 for i in rejection_cfg.keys():
627 print("Rejecting config %s" % i)
628 else:
629 print("Not information for project type: %s."
630 " Please check config" % static_config["config_type"])
631 return rejection_cfg