blob: ddc1f6429fac1d6a57b372d00b0d6d155c4a1818 [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/*
Xinyu Zhang7c038b02021-04-20 10:27:49 +080011 * Copyright (c) 2018-2021, 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"
Xinyu Zhang06286a92021-07-22 14:00:51 +080020__version__ = "1.4.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
Summer Qin3c2b5722021-05-26 10:43:45 +080034mapPlatform = {"cypress/psoc64": "psoc64",
35 "arm/mps2/an519": "AN519",
36 "arm/mps2/an521": "AN521",
37 "arm/mps2/an539": "AN539",
38 "arm/mps2/sse-200_aws": "SSE-200_AWS",
39 "arm/mps3/an524": "AN524",
40 "arm/musca_b1/sse_200": "MUSCA_B1",
41 "arm/musca_b1/secure_enclave": "MUSCA_B1_SE",
Arthur She19c0e1a2021-06-02 11:06:19 -070042 "arm/musca_s1": "MUSCA_S1",
Xinyu Zhangfcb6aad2021-08-25 16:24:11 +080043 "stm/stm32l562e_dk": "stm32l562e_dk",
Xinyu Zhang6afdd612021-10-12 17:07:32 +080044 "arm/corstone1000": "corstone1000",
Arthur Shef3657742021-09-07 14:23:18 -070045 "nxp/lpcxpresso55s69": "lpcxpresso55s69"}
Xinyu Zhang1078e812020-10-15 11:52:36 +080046
47mapCompiler = {"toolchain_GNUARM.cmake": "GNUARM",
48 "toolchain_ARMCLANG.cmake": "ARMCLANG"}
49
Xinyu Zhangc371af62020-10-21 10:41:57 +080050mapTestPsaApi = {"IPC": "FF",
Xinyu Zhang1078e812020-10-15 11:52:36 +080051 "CRYPTO": "CRYPTO",
Xinyu Zhang1078e812020-10-15 11:52:36 +080052 "INITIAL_ATTESTATION": "ATTEST",
Xinyu Zhang39acb412021-07-09 20:35:19 +080053 "STORAGE": "STORAGE"}
Xinyu Zhang1078e812020-10-15 11:52:36 +080054
Xinyu Zhang9fd74242020-10-22 11:30:50 +080055mapProfile = {"profile_small": "SMALL",
Xinyu Zhang9b1aef92021-03-12 15:36:44 +080056 "profile_medium": "MEDIUM",
57 "profile_large": "LARGE"}
Xinyu Zhang1078e812020-10-15 11:52:36 +080058
59
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010060class TFM_Build_Manager(structuredTask):
61 """ Class that will load a configuration out of a json file, schedule
62 the builds, and produce a report """
63
64 def __init__(self,
65 tfm_dir, # TFM root directory
66 work_dir, # Current working directory(ie logs)
67 cfg_dict, # Input config dictionary of the following form
68 # input_dict = {"PROJ_CONFIG": "ConfigRegression",
69 # "TARGET_PLATFORM": "MUSCA_A",
70 # "COMPILER": "ARMCLANG",
71 # "CMAKE_BUILD_TYPE": "Debug"}
72 report=None, # File to produce report
73 parallel_builds=3, # Number of builds to run in parallel
Minos Galanakisea421232019-06-20 17:11:28 +010074 build_threads=3, # Number of threads used per build
75 install=False, # Install libraries after build
76 img_sizes=False, # Use arm-none-eabi-size for size info
77 relative_paths=False): # Store relative paths in report
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010078 self._tbm_build_threads = build_threads
79 self._tbm_conc_builds = parallel_builds
80 self._tbm_install = install
Minos Galanakisea421232019-06-20 17:11:28 +010081 self._tbm_img_sizes = img_sizes
82 self._tbm_relative_paths = relative_paths
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010083
84 # Required by other methods, always set working directory first
85 self._tbm_work_dir = os.path.abspath(os.path.expanduser(work_dir))
86
87 self._tbm_tfm_dir = os.path.abspath(os.path.expanduser(tfm_dir))
88
Karl Zhangaff558a2020-05-15 14:28:23 +010089 print("bm param tfm_dir %s" % tfm_dir)
90 print("bm %s %s %s" % (work_dir, cfg_dict, self._tbm_work_dir))
Minos Galanakisea421232019-06-20 17:11:28 +010091 # Internal flag to tag simple (non combination formatted configs)
92 self.simple_config = False
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010093 self._tbm_report = report
94
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010095 self._tbm_cfg = self.load_config(cfg_dict, self._tbm_work_dir)
Minos Galanakisea421232019-06-20 17:11:28 +010096 self._tbm_build_cfg, \
97 self.tbm_common_cfg = self.parse_config(self._tbm_cfg)
Karl Zhangaff558a2020-05-15 14:28:23 +010098 self._tfb_code_base_updated = False
99 self._tfb_log_f = "CodeBasePrepare.log"
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100100
101 super(TFM_Build_Manager, self).__init__(name="TFM_Build_Manager")
102
Dean Bircha6ede7e2020-03-13 14:00:33 +0000103 def get_config(self):
104 return list(self._tbm_build_cfg.keys())
Dean Birch5cb5a882020-01-24 11:37:13 +0000105
Dean Bircha6ede7e2020-03-13 14:00:33 +0000106 def print_config_environment(self, config, silence_stderr=False):
Dean Birch5cb5a882020-01-24 11:37:13 +0000107 """
108 For a given build configuration from output of print_config
109 method, print environment variables to build.
110 """
111 if config not in self._tbm_build_cfg:
Dean Bircha6ede7e2020-03-13 14:00:33 +0000112 if not silence_stderr:
113 print("Error: no such config {}".format(config), file=sys.stderr)
Dean Birch5cb5a882020-01-24 11:37:13 +0000114 sys.exit(1)
115 config_details = self._tbm_build_cfg[config]
116 argument_list = [
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000117 "CONFIG_NAME={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800118 "TFM_PLATFORM={}",
119 "TOOLCHAIN_FILE={}",
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800120 "LIB_MODEL={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800121 "ISOLATION_LEVEL={}",
122 "TEST_REGRESSION={}",
123 "TEST_PSA_API={}",
Dean Birch5cb5a882020-01-24 11:37:13 +0000124 "CMAKE_BUILD_TYPE={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800125 "OTP={}",
Dean Birch5cb5a882020-01-24 11:37:13 +0000126 "BL2={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800127 "NS={}",
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800128 "PROFILE={}",
Xinyu Zhang9bfe8a92021-10-28 16:27:12 +0800129 "PARTITION_PS={}",
Xinyu Zhanga1088e22021-11-11 18:02:45 +0800130 "NSCE={}",
131 "MMIO={}"
Dean Birch5cb5a882020-01-24 11:37:13 +0000132 ]
133 print(
134 "\n".join(argument_list)
135 .format(
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000136 config,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800137 config_details.tfm_platform,
138 config_details.toolchain_file,
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800139 config_details.lib_model,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800140 config_details.isolation_level,
141 config_details.test_regression,
142 config_details.test_psa_api,
Dean Birch5cb5a882020-01-24 11:37:13 +0000143 config_details.cmake_build_type,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800144 config_details.with_otp,
145 config_details.with_bl2,
146 config_details.with_ns,
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800147 "N.A" if not config_details.profile else config_details.profile,
Xinyu Zhang9bfe8a92021-10-28 16:27:12 +0800148 config_details.partition_ps,
Xinyu Zhanga1088e22021-11-11 18:02:45 +0800149 config_details.nsce,
150 config_details.mmio
Dean Birch5cb5a882020-01-24 11:37:13 +0000151 )
152 .strip()
153 )
154
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000155 def print_build_commands(self, config, silence_stderr=False):
156 config_details = self._tbm_build_cfg[config]
157 codebase_dir = os.path.join(os.getcwd(),"trusted-firmware-m")
Xinyu Zhangb708f572020-09-15 11:43:46 +0800158 build_dir=os.path.join(os.getcwd(),"trusted-firmware-m/build")
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000159 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 +0800160 build_commands = [build_config["config_template"]]
161 for command in build_config["build_cmds"]:
162 build_commands.append(command)
Xinyu Zhangb708f572020-09-15 11:43:46 +0800163 print(" ;\n".join(build_commands))
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000164
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100165 def pre_eval(self):
166 """ Tests that need to be run in set-up state """
167 return True
168
169 def pre_exec(self, eval_ret):
170 """ """
171
Minos Galanakisea421232019-06-20 17:11:28 +0100172 def override_tbm_cfg_params(self, config, override_keys, **params):
173 """ Using a dictionay as input, for each key defined in
174 override_keys it will replace the config[key] entries with
175 the key=value parameters provided """
176
177 for key in override_keys:
178 if isinstance(config[key], list):
179 config[key] = [n % params for n in config[key]]
180 elif isinstance(config[key], str):
181 config[key] = config[key] % params
182 else:
183 raise Exception("Config does not contain key %s "
184 "of type %s" % (key, config[key]))
185 return config
186
Karl Zhangaff558a2020-05-15 14:28:23 +0100187 def pre_build(self, build_cfg):
188 print("pre_build start %s \r\nself._tfb_cfg %s\r\n" %
189 (self, build_cfg))
190
191 try:
192 if self._tfb_code_base_updated:
193 print("Code base has been updated")
194 return True
195
196 self._tfb_code_base_updated = True
197
198 if "build_psa_api" in build_cfg:
199 # FF IPC build needs repo manifest update for TFM and PSA arch test
200 if "build_ff_ipc" in build_cfg:
201 print("Checkout to FF IPC code base")
202 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
203 _api_test_manifest = "git checkout . ; python3 tools/scripts/manifest_update.py"
204 if subprocess_log(_api_test_manifest,
205 self._tfb_log_f,
206 append=True,
207 prefix=_api_test_manifest):
208
209 raise Exception("Python Failed please check log: %s" %
210 self._tfb_log_f)
211
212 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py -m tools/tfm_psa_ff_test_manifest_list.yaml append"
213 os.chdir(build_cfg["codebase_root_dir"])
214 if subprocess_log(_api_test_manifest_tfm,
215 self._tfb_log_f,
216 append=True,
217 prefix=_api_test_manifest_tfm):
218
219 raise Exception("Python TFM Failed please check log: %s" %
220 self._tfb_log_f)
221 return True
222
223 print("Checkout to default code base")
224 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
225 _api_test_manifest = "git checkout ."
226 if subprocess_log(_api_test_manifest,
227 self._tfb_log_f,
228 append=True,
229 prefix=_api_test_manifest):
230
231 raise Exception("Python Failed please check log: %s" %
232 self._tfb_log_f)
233
234 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py"
235 os.chdir(build_cfg["codebase_root_dir"])
236 if subprocess_log(_api_test_manifest_tfm,
237 self._tfb_log_f,
238 append=True,
239 prefix=_api_test_manifest_tfm):
240
241 raise Exception("Python TFM Failed please check log: %s" %
242 self._tfb_log_f)
243 finally:
244 print("python pass after builder prepare")
245 os.chdir(build_cfg["codebase_root_dir"] + "/../")
246
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100247 def task_exec(self):
248 """ Create a build pool and execute them in parallel """
249
250 build_pool = []
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100251
Minos Galanakisea421232019-06-20 17:11:28 +0100252 # When a config is flagged as a single build config.
253 # Name is evaluated by config type
254 if self.simple_config:
255
256 build_cfg = deepcopy(self.tbm_common_cfg)
257
258 # Extract the common for all elements of config
259 for key in ["build_cmds", "required_artefacts"]:
260 try:
261 build_cfg[key] = build_cfg[key]["all"]
262 except KeyError:
263 build_cfg[key] = []
264 name = build_cfg["config_type"]
265
266 # Override _tbm_xxx paths in commands
267 # plafrom in not guaranteed without seeds so _tbm_target_platform
268 # is ignored
269 over_dict = {"_tbm_build_dir_": os.path.join(self._tbm_work_dir,
270 name),
271 "_tbm_code_dir_": build_cfg["codebase_root_dir"]}
272
273 build_cfg = self.override_tbm_cfg_params(build_cfg,
274 ["build_cmds",
275 "required_artefacts",
276 "artifact_capture_rex"],
277 **over_dict)
278
279 # Overrides path in expected artefacts
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100280 print("Loading config %s" % name)
Minos Galanakisea421232019-06-20 17:11:28 +0100281
282 build_pool.append(TFM_Builder(
283 name=name,
284 work_dir=self._tbm_work_dir,
285 cfg_dict=build_cfg,
286 build_threads=self._tbm_build_threads,
287 img_sizes=self._tbm_img_sizes,
288 relative_paths=self._tbm_relative_paths))
289 # When a seed pool is provided iterate through the entries
290 # and update platform spefific parameters
291 elif len(self._tbm_build_cfg):
Karl Zhangaff558a2020-05-15 14:28:23 +0100292 print("\r\n_tbm_build_cfg %s\r\n tbm_common_cfg %s\r\n" \
293 % (self._tbm_build_cfg, self.tbm_common_cfg))
Minos Galanakisea421232019-06-20 17:11:28 +0100294 for name, i in self._tbm_build_cfg.items():
295 # Do not modify the original config
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000296 build_cfg = self.get_build_config(i, name)
Karl Zhangaff558a2020-05-15 14:28:23 +0100297 self.pre_build(build_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100298 # Overrides path in expected artefacts
299 print("Loading config %s" % name)
300
301 build_pool.append(TFM_Builder(
302 name=name,
303 work_dir=self._tbm_work_dir,
304 cfg_dict=build_cfg,
305 build_threads=self._tbm_build_threads,
306 img_sizes=self._tbm_img_sizes,
307 relative_paths=self._tbm_relative_paths))
308 else:
309 print("Could not find any configuration. Check the rejection list")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100310
311 status_rep = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100312 build_rep = {}
313 completed_build_count = 0
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100314 print("Build: Running %d parallel build jobs" % self._tbm_conc_builds)
315 for build_pool_slice in list_chunks(build_pool, self._tbm_conc_builds):
316
317 # Start the builds
318 for build in build_pool_slice:
319 # Only produce output for the first build
320 if build_pool_slice.index(build) != 0:
321 build.mute()
322 print("Build: Starting %s" % build.get_name())
323 build.start()
324
325 # Wait for the builds to complete
326 for build in build_pool_slice:
327 # Wait for build to finish
328 build.join()
329 # Similarly print the logs of the other builds as they complete
330 if build_pool_slice.index(build) != 0:
331 build.log()
Minos Galanakisea421232019-06-20 17:11:28 +0100332 completed_build_count += 1
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100333 print("Build: Finished %s" % build.get_name())
Minos Galanakisea421232019-06-20 17:11:28 +0100334 print("Build Progress:")
335 show_progress(completed_build_count, len(build_pool))
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100336
337 # Store status in report
338 status_rep[build.get_name()] = build.get_status()
Minos Galanakisea421232019-06-20 17:11:28 +0100339 build_rep[build.get_name()] = build.report()
340
341 # Include the original input configuration in the report
342
343 metadata = {"input_build_cfg": self._tbm_cfg,
344 "build_dir": self._tbm_work_dir
345 if not self._tbm_relative_paths
346 else resolve_rel_path(self._tbm_work_dir),
347 "time": time()}
348
349 full_rep = {"report": build_rep,
350 "_metadata_": metadata}
351
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100352 # Store the report
353 self.stash("Build Status", status_rep)
354 self.stash("Build Report", full_rep)
355
356 if self._tbm_report:
357 print("Exported build report to file:", self._tbm_report)
358 save_json(self._tbm_report, full_rep)
359
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000360 def get_build_config(self, i, name, silence=False, build_dir=None, codebase_dir=None):
361 psa_build_dir = self._tbm_work_dir + "/" + name + "/BUILD"
362 if not build_dir:
363 build_dir = os.path.join(self._tbm_work_dir, name)
364 else:
365 psa_build_dir = os.path.join(build_dir, "../../psa-arch-tests/api-tests/build")
366 build_cfg = deepcopy(self.tbm_common_cfg)
367 if not codebase_dir:
368 codebase_dir = build_cfg["codebase_root_dir"]
369 else:
370 # Would prefer to do all with the new variable
371 # However, many things use this from build_cfg elsewhere
372 build_cfg["codebase_root_dir"] = codebase_dir
373 # Extract the common for all elements of config
374 for key in ["build_cmds", "required_artefacts"]:
375 try:
376 build_cfg[key] = deepcopy(self.tbm_common_cfg[key]
377 ["all"])
378 except KeyError as E:
379 build_cfg[key] = []
380 # Extract the platform specific elements of config
381 for key in ["build_cmds", "required_artefacts"]:
382 try:
Xinyu Zhang694eb492020-11-04 18:29:08 +0800383 if i.tfm_platform in self.tbm_common_cfg[key].keys() and i.with_ns:
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000384 build_cfg[key] += deepcopy(self.tbm_common_cfg[key]
Xinyu Zhangb708f572020-09-15 11:43:46 +0800385 [i.tfm_platform])
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000386 except Exception as E:
387 pass
Karl Zhang1eed6322020-07-01 15:38:10 +0800388
389 if os.cpu_count() >= 8:
390 #run in a serviver with scripts, parallel build will use CPU numbers
391 thread_no = " -j 2"
392 else:
393 #run in a docker, usually docker with CPUs less than 8
394 thread_no = " -j " + str(os.cpu_count())
Xinyu Zhangb708f572020-09-15 11:43:46 +0800395 build_cfg["build_cmds"][0] += thread_no
396 overwrite_params = {"codebase_root_dir": build_cfg["codebase_root_dir"],
397 "tfm_platform": i.tfm_platform,
398 "toolchain_file": i.toolchain_file,
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800399 "lib_model": i.lib_model,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800400 "isolation_level": i.isolation_level,
401 "test_regression": i.test_regression,
402 "test_psa_api": i.test_psa_api,
403 "cmake_build_type": i.cmake_build_type,
404 "with_otp": i.with_otp,
405 "with_bl2": i.with_bl2,
406 "with_ns": i.with_ns,
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800407 "profile": "" if i.profile=="N.A" else i.profile,
Xinyu Zhang9bfe8a92021-10-28 16:27:12 +0800408 "partition_ps": i.partition_ps,
Xinyu Zhanga1088e22021-11-11 18:02:45 +0800409 "nsce": i.nsce,
410 "mmio": i.mmio}
Xinyu Zhanga0086022020-11-10 18:11:12 +0800411 if i.test_psa_api == "IPC":
Xinyu Zhangcd1ed962020-11-11 16:00:52 +0800412 overwrite_params["test_psa_api"] += " -DINCLUDE_PANIC_TESTS=1"
Xinyu Zhang8cee3312021-11-12 11:06:39 +0800413 if i.tfm_platform == "arm/musca_b1/sse_200":
414 overwrite_params["test_psa_api"] += " -DITS_RAM_FS=ON -DPS_RAM_FS=ON"
Xinyu Zhangb708f572020-09-15 11:43:46 +0800415 build_cfg["config_template"] %= overwrite_params
Xinyu Zhang694eb492020-11-04 18:29:08 +0800416 if len(build_cfg["build_cmds"]) > 1:
417 overwrite_build_dir = {"_tbm_build_dir_": build_dir}
418 build_cfg["build_cmds"][1] %= overwrite_build_dir
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000419 return build_cfg
420
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100421 def post_eval(self):
422 """ If a single build failed fail the test """
423 try:
Minos Galanakisea421232019-06-20 17:11:28 +0100424 status_dict = self.unstash("Build Status")
425 if not status_dict:
426 raise Exception()
427 retcode_sum = sum(status_dict.values())
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100428 if retcode_sum != 0:
429 raise Exception()
430 return True
431 except Exception as e:
432 return False
433
434 def post_exec(self, eval_ret):
435 """ Generate a report and fail the script if build == unsuccessfull"""
436
437 self.print_summary()
438 if not eval_ret:
439 print("ERROR: ====> Build Failed! %s" % self.get_name())
440 self.set_status(1)
441 else:
442 print("SUCCESS: ====> Build Complete!")
443 self.set_status(0)
444
445 def get_report(self):
446 """ Expose the internal report to a new object for external classes """
447 return deepcopy(self.unstash("Build Report"))
448
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100449 def load_config(self, config, work_dir):
450 try:
451 # passing config_name param supersseeds fileparam
452 if isinstance(config, dict):
453 ret_cfg = deepcopy(config)
454 elif isinstance(config, str):
455 # If the string does not descrive a file try to look for it in
456 # work directory
457 if not os.path.isfile(config):
458 # remove path from file
459 config_2 = os.path.split(config)[-1]
460 # look in the current working directory
461 config_2 = os.path.join(work_dir, config_2)
462 if not os.path.isfile(config_2):
463 m = "Could not find cfg in %s or %s " % (config,
464 config_2)
465 raise Exception(m)
466 # If fille exists in working directory
467 else:
468 config = config_2
469 ret_cfg = load_json(config)
470
471 else:
472 raise Exception("Need to provide a valid config name or file."
473 "Please use --config/--config-file parameter.")
474 except Exception as e:
475 print("Error:%s \nCould not load a valid config" % e)
476 sys.exit(1)
477
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100478 return ret_cfg
479
480 def parse_config(self, cfg):
481 """ Parse a valid configuration file into a set of build dicts """
482
Minos Galanakisea421232019-06-20 17:11:28 +0100483 ret_cfg = {}
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100484
Minos Galanakisea421232019-06-20 17:11:28 +0100485 # Config entries which are not subject to changes during combinations
486 static_cfg = cfg["common_params"]
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100487
Minos Galanakisea421232019-06-20 17:11:28 +0100488 # Converth the code path to absolute path
489 abs_code_dir = static_cfg["codebase_root_dir"]
490 abs_code_dir = os.path.abspath(os.path.expanduser(abs_code_dir))
491 static_cfg["codebase_root_dir"] = abs_code_dir
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100492
Minos Galanakisea421232019-06-20 17:11:28 +0100493 # seed_params is an optional field. Do not proccess if it is missing
494 if "seed_params" in cfg:
495 comb_cfg = cfg["seed_params"]
496 # Generate a list of all possible confugration combinations
497 ret_cfg = TFM_Build_Manager.generate_config_list(comb_cfg,
498 static_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100499
Xinyu Zhang2c63ce72021-07-23 14:01:59 +0800500 # valid is an optional field. Do not proccess if it is missing
501 if "valid" in cfg:
502 # Valid configurations(Need to build)
503 valid_cfg = cfg["valid"]
504 # Add valid configs to build list
505 ret_cfg.update(TFM_Build_Manager.generate_optional_list(
506 comb_cfg,
507 static_cfg,
508 valid_cfg))
509
Minos Galanakisea421232019-06-20 17:11:28 +0100510 # invalid is an optional field. Do not proccess if it is missing
511 if "invalid" in cfg:
512 # Invalid configurations(Do not build)
513 invalid_cfg = cfg["invalid"]
514 # Remove the rejected entries from the test list
Xinyu Zhang0581b082021-05-17 10:46:57 +0800515 rejection_cfg = TFM_Build_Manager.generate_optional_list(
Minos Galanakisea421232019-06-20 17:11:28 +0100516 comb_cfg,
517 static_cfg,
518 invalid_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100519
Minos Galanakisea421232019-06-20 17:11:28 +0100520 # Subtract the two configurations
521 ret_cfg = {k: v for k, v in ret_cfg.items()
522 if k not in rejection_cfg}
523 self.simple_config = False
524 else:
525 self.simple_config = True
526 return ret_cfg, static_cfg
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100527
Minos Galanakisea421232019-06-20 17:11:28 +0100528 # ----- Override bellow methods when subclassing for other projects ----- #
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100529
Minos Galanakisea421232019-06-20 17:11:28 +0100530 def print_summary(self):
531 """ Print an comprehensive list of the build jobs with their status """
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100532
Minos Galanakisea421232019-06-20 17:11:28 +0100533 try:
534 full_rep = self.unstash("Build Report")["report"]
535 fl = ([k for k, v in full_rep.items() if v['status'] == 'Failed'])
536 ps = ([k for k, v in full_rep.items() if v['status'] == 'Success'])
537 except Exception as E:
Karl Zhangaff558a2020-05-15 14:28:23 +0100538 print("No report generated", E)
Minos Galanakisea421232019-06-20 17:11:28 +0100539 return
540 if fl:
541 print_test(t_list=fl, status="failed", tname="Builds")
542 if ps:
543 print_test(t_list=ps, status="passed", tname="Builds")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100544
Minos Galanakisea421232019-06-20 17:11:28 +0100545 @staticmethod
546 def generate_config_list(seed_config, static_config):
547 """ Generate all possible configuration combinations from a group of
548 lists of compiler options"""
549 config_list = []
550
551 if static_config["config_type"] == "tf-m":
552 cfg_name = "TFM_Build_CFG"
553 # Ensure the fieds are sorted in the desired order
554 # seed_config can be a subset of sort order for configurations with
555 # optional parameters.
556 tags = [n for n in static_config["sort_order"]
557 if n in seed_config.keys()]
Karl Zhangaff558a2020-05-15 14:28:23 +0100558 print("!!!!!!!!!!!gen list %s\r\n" % tags)
Minos Galanakisea421232019-06-20 17:11:28 +0100559
560 data = []
561 for key in tags:
562 data.append(seed_config[key])
563 config_list = gen_cfg_combinations(cfg_name,
564 " ".join(tags),
565 *data)
566 else:
567 print("Not information for project type: %s."
568 " Please check config" % static_config["config_type"])
569
570 ret_cfg = {}
571 # Notify the user for the rejected configuations
572 for i in config_list:
Xinyu Zhang1078e812020-10-15 11:52:36 +0800573 # Convert named tuples to string in a brief format
574 config_param = []
575 config_param.append(mapPlatform[list(i)[0]])
576 config_param.append(mapCompiler[list(i)[1]])
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800577 if list(i)[2]: # LIB_MODEL
578 config_param.append("LIB")
579 else:
580 config_param.append("IPC")
Xinyu Zhang1078e812020-10-15 11:52:36 +0800581 config_param.append(list(i)[3]) # ISOLATION_LEVEL
582 if list(i)[4]: # TEST_REGRESSION
583 config_param.append("REG")
584 if list(i)[5] != "OFF": #TEST_PSA_API
585 config_param.append(mapTestPsaApi[list(i)[5]])
586 config_param.append(list(i)[6]) # BUILD_TYPE
Xinyu Zhanga50432e2020-10-23 18:00:18 +0800587 if list(i)[7] == "ENABLED": # OTP
Xinyu Zhang1078e812020-10-15 11:52:36 +0800588 config_param.append("OTP")
589 if list(i)[8]: # BL2
590 config_param.append("BL2")
591 if list(i)[9]: # NS
592 config_param.append("NS")
593 if list(i)[10]: # PROFILE
594 config_param.append(mapProfile[list(i)[10]])
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800595 if list(i)[11] == "OFF": #PARTITION_PS
596 config_param.append("PSOFF")
Xinyu Zhang9bfe8a92021-10-28 16:27:12 +0800597 if list(i)[12] == "ON":
598 config_param.append("NSCE")
Xinyu Zhanga1088e22021-11-11 18:02:45 +0800599 if list(i)[13] == "ON":
600 config_param.append("MMIO")
Xinyu Zhang1078e812020-10-15 11:52:36 +0800601 i_str = "_".join(config_param)
Karl Zhangaff558a2020-05-15 14:28:23 +0100602 ret_cfg[i_str] = i
Minos Galanakisea421232019-06-20 17:11:28 +0100603 return ret_cfg
604
605 @staticmethod
Xinyu Zhang0581b082021-05-17 10:46:57 +0800606 def generate_optional_list(seed_config,
607 static_config,
608 optional_list):
609 optional_cfg = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100610
611 if static_config["config_type"] == "tf-m":
612
Xinyu Zhang0581b082021-05-17 10:46:57 +0800613 # If optional list is empty do nothing
614 if not optional_list:
615 return optional_cfg
Minos Galanakisea421232019-06-20 17:11:28 +0100616
617 tags = [n for n in static_config["sort_order"]
618 if n in seed_config.keys()]
619 sorted_default_lst = [seed_config[k] for k in tags]
620
Xinyu Zhang0581b082021-05-17 10:46:57 +0800621 # If tags are not alligned with optional list entries quit
622 if len(tags) != len(optional_list[0]):
623 print(len(tags), len(optional_list[0]))
Minos Galanakisea421232019-06-20 17:11:28 +0100624 print("Error, tags should be assigned to each "
Xinyu Zhang0581b082021-05-17 10:46:57 +0800625 "of the optional inputs")
Minos Galanakisea421232019-06-20 17:11:28 +0100626 return []
627
628 # Replace wildcard ( "*") entries with every
629 # inluded in cfg variant
Xinyu Zhang0581b082021-05-17 10:46:57 +0800630 for k in optional_list:
Minos Galanakisea421232019-06-20 17:11:28 +0100631 # Pad the omitted values with wildcard char *
632 res_list = list(k) + ["*"] * (5 - len(k))
Xinyu Zhang0581b082021-05-17 10:46:57 +0800633 print("Working on optional input: %s" % (res_list))
Minos Galanakisea421232019-06-20 17:11:28 +0100634
635 for n in range(len(res_list)):
636
637 res_list[n] = [res_list[n]] if res_list[n] != "*" \
638 else sorted_default_lst[n]
639
640 # Generate a configuration and a name for the completed array
Xinyu Zhang0581b082021-05-17 10:46:57 +0800641 op_cfg = TFM_Build_Manager.generate_config_list(
Minos Galanakisea421232019-06-20 17:11:28 +0100642 dict(zip(tags, res_list)),
643 static_config)
644
645 # Append the configuration to the existing ones
Xinyu Zhang0581b082021-05-17 10:46:57 +0800646 optional_cfg = dict(optional_cfg, **op_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100647
Xinyu Zhang0581b082021-05-17 10:46:57 +0800648 # Notify the user for the optional configuations
649 for i in optional_cfg.keys():
650 print("Generating optional config %s" % i)
Minos Galanakisea421232019-06-20 17:11:28 +0100651 else:
652 print("Not information for project type: %s."
653 " Please check config" % static_config["config_type"])
Xinyu Zhang0581b082021-05-17 10:46:57 +0800654 return optional_cfg