blob: f804fc06b6eb8d3e2eb5f38a0d4be1072708082a [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",
Arthur Shef3657742021-09-07 14:23:18 -070044 "arm/diphda": "DIPHDA",
45 "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={}",
129 "PARTITION_PS={}"
Dean Birch5cb5a882020-01-24 11:37:13 +0000130 ]
131 print(
132 "\n".join(argument_list)
133 .format(
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000134 config,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800135 config_details.tfm_platform,
136 config_details.toolchain_file,
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800137 config_details.lib_model,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800138 config_details.isolation_level,
139 config_details.test_regression,
140 config_details.test_psa_api,
Dean Birch5cb5a882020-01-24 11:37:13 +0000141 config_details.cmake_build_type,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800142 config_details.with_otp,
143 config_details.with_bl2,
144 config_details.with_ns,
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800145 "N.A" if not config_details.profile else config_details.profile,
146 config_details.partition_ps
Dean Birch5cb5a882020-01-24 11:37:13 +0000147 )
148 .strip()
149 )
150
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000151 def print_build_commands(self, config, silence_stderr=False):
152 config_details = self._tbm_build_cfg[config]
153 codebase_dir = os.path.join(os.getcwd(),"trusted-firmware-m")
Xinyu Zhangb708f572020-09-15 11:43:46 +0800154 build_dir=os.path.join(os.getcwd(),"trusted-firmware-m/build")
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000155 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 +0800156 build_commands = [build_config["config_template"]]
157 for command in build_config["build_cmds"]:
158 build_commands.append(command)
Xinyu Zhangb708f572020-09-15 11:43:46 +0800159 print(" ;\n".join(build_commands))
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000160
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100161 def pre_eval(self):
162 """ Tests that need to be run in set-up state """
163 return True
164
165 def pre_exec(self, eval_ret):
166 """ """
167
Minos Galanakisea421232019-06-20 17:11:28 +0100168 def override_tbm_cfg_params(self, config, override_keys, **params):
169 """ Using a dictionay as input, for each key defined in
170 override_keys it will replace the config[key] entries with
171 the key=value parameters provided """
172
173 for key in override_keys:
174 if isinstance(config[key], list):
175 config[key] = [n % params for n in config[key]]
176 elif isinstance(config[key], str):
177 config[key] = config[key] % params
178 else:
179 raise Exception("Config does not contain key %s "
180 "of type %s" % (key, config[key]))
181 return config
182
Karl Zhangaff558a2020-05-15 14:28:23 +0100183 def pre_build(self, build_cfg):
184 print("pre_build start %s \r\nself._tfb_cfg %s\r\n" %
185 (self, build_cfg))
186
187 try:
188 if self._tfb_code_base_updated:
189 print("Code base has been updated")
190 return True
191
192 self._tfb_code_base_updated = True
193
194 if "build_psa_api" in build_cfg:
195 # FF IPC build needs repo manifest update for TFM and PSA arch test
196 if "build_ff_ipc" in build_cfg:
197 print("Checkout to FF IPC code base")
198 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
199 _api_test_manifest = "git checkout . ; python3 tools/scripts/manifest_update.py"
200 if subprocess_log(_api_test_manifest,
201 self._tfb_log_f,
202 append=True,
203 prefix=_api_test_manifest):
204
205 raise Exception("Python Failed please check log: %s" %
206 self._tfb_log_f)
207
208 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py -m tools/tfm_psa_ff_test_manifest_list.yaml append"
209 os.chdir(build_cfg["codebase_root_dir"])
210 if subprocess_log(_api_test_manifest_tfm,
211 self._tfb_log_f,
212 append=True,
213 prefix=_api_test_manifest_tfm):
214
215 raise Exception("Python TFM Failed please check log: %s" %
216 self._tfb_log_f)
217 return True
218
219 print("Checkout to default code base")
220 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
221 _api_test_manifest = "git checkout ."
222 if subprocess_log(_api_test_manifest,
223 self._tfb_log_f,
224 append=True,
225 prefix=_api_test_manifest):
226
227 raise Exception("Python Failed please check log: %s" %
228 self._tfb_log_f)
229
230 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py"
231 os.chdir(build_cfg["codebase_root_dir"])
232 if subprocess_log(_api_test_manifest_tfm,
233 self._tfb_log_f,
234 append=True,
235 prefix=_api_test_manifest_tfm):
236
237 raise Exception("Python TFM Failed please check log: %s" %
238 self._tfb_log_f)
239 finally:
240 print("python pass after builder prepare")
241 os.chdir(build_cfg["codebase_root_dir"] + "/../")
242
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100243 def task_exec(self):
244 """ Create a build pool and execute them in parallel """
245
246 build_pool = []
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100247
Minos Galanakisea421232019-06-20 17:11:28 +0100248 # When a config is flagged as a single build config.
249 # Name is evaluated by config type
250 if self.simple_config:
251
252 build_cfg = deepcopy(self.tbm_common_cfg)
253
254 # Extract the common for all elements of config
255 for key in ["build_cmds", "required_artefacts"]:
256 try:
257 build_cfg[key] = build_cfg[key]["all"]
258 except KeyError:
259 build_cfg[key] = []
260 name = build_cfg["config_type"]
261
262 # Override _tbm_xxx paths in commands
263 # plafrom in not guaranteed without seeds so _tbm_target_platform
264 # is ignored
265 over_dict = {"_tbm_build_dir_": os.path.join(self._tbm_work_dir,
266 name),
267 "_tbm_code_dir_": build_cfg["codebase_root_dir"]}
268
269 build_cfg = self.override_tbm_cfg_params(build_cfg,
270 ["build_cmds",
271 "required_artefacts",
272 "artifact_capture_rex"],
273 **over_dict)
274
275 # Overrides path in expected artefacts
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100276 print("Loading config %s" % name)
Minos Galanakisea421232019-06-20 17:11:28 +0100277
278 build_pool.append(TFM_Builder(
279 name=name,
280 work_dir=self._tbm_work_dir,
281 cfg_dict=build_cfg,
282 build_threads=self._tbm_build_threads,
283 img_sizes=self._tbm_img_sizes,
284 relative_paths=self._tbm_relative_paths))
285 # When a seed pool is provided iterate through the entries
286 # and update platform spefific parameters
287 elif len(self._tbm_build_cfg):
Karl Zhangaff558a2020-05-15 14:28:23 +0100288 print("\r\n_tbm_build_cfg %s\r\n tbm_common_cfg %s\r\n" \
289 % (self._tbm_build_cfg, self.tbm_common_cfg))
Minos Galanakisea421232019-06-20 17:11:28 +0100290 for name, i in self._tbm_build_cfg.items():
291 # Do not modify the original config
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000292 build_cfg = self.get_build_config(i, name)
Karl Zhangaff558a2020-05-15 14:28:23 +0100293 self.pre_build(build_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100294 # Overrides path in expected artefacts
295 print("Loading config %s" % name)
296
297 build_pool.append(TFM_Builder(
298 name=name,
299 work_dir=self._tbm_work_dir,
300 cfg_dict=build_cfg,
301 build_threads=self._tbm_build_threads,
302 img_sizes=self._tbm_img_sizes,
303 relative_paths=self._tbm_relative_paths))
304 else:
305 print("Could not find any configuration. Check the rejection list")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100306
307 status_rep = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100308 build_rep = {}
309 completed_build_count = 0
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100310 print("Build: Running %d parallel build jobs" % self._tbm_conc_builds)
311 for build_pool_slice in list_chunks(build_pool, self._tbm_conc_builds):
312
313 # Start the builds
314 for build in build_pool_slice:
315 # Only produce output for the first build
316 if build_pool_slice.index(build) != 0:
317 build.mute()
318 print("Build: Starting %s" % build.get_name())
319 build.start()
320
321 # Wait for the builds to complete
322 for build in build_pool_slice:
323 # Wait for build to finish
324 build.join()
325 # Similarly print the logs of the other builds as they complete
326 if build_pool_slice.index(build) != 0:
327 build.log()
Minos Galanakisea421232019-06-20 17:11:28 +0100328 completed_build_count += 1
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100329 print("Build: Finished %s" % build.get_name())
Minos Galanakisea421232019-06-20 17:11:28 +0100330 print("Build Progress:")
331 show_progress(completed_build_count, len(build_pool))
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100332
333 # Store status in report
334 status_rep[build.get_name()] = build.get_status()
Minos Galanakisea421232019-06-20 17:11:28 +0100335 build_rep[build.get_name()] = build.report()
336
337 # Include the original input configuration in the report
338
339 metadata = {"input_build_cfg": self._tbm_cfg,
340 "build_dir": self._tbm_work_dir
341 if not self._tbm_relative_paths
342 else resolve_rel_path(self._tbm_work_dir),
343 "time": time()}
344
345 full_rep = {"report": build_rep,
346 "_metadata_": metadata}
347
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100348 # Store the report
349 self.stash("Build Status", status_rep)
350 self.stash("Build Report", full_rep)
351
352 if self._tbm_report:
353 print("Exported build report to file:", self._tbm_report)
354 save_json(self._tbm_report, full_rep)
355
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000356 def get_build_config(self, i, name, silence=False, build_dir=None, codebase_dir=None):
357 psa_build_dir = self._tbm_work_dir + "/" + name + "/BUILD"
358 if not build_dir:
359 build_dir = os.path.join(self._tbm_work_dir, name)
360 else:
361 psa_build_dir = os.path.join(build_dir, "../../psa-arch-tests/api-tests/build")
362 build_cfg = deepcopy(self.tbm_common_cfg)
363 if not codebase_dir:
364 codebase_dir = build_cfg["codebase_root_dir"]
365 else:
366 # Would prefer to do all with the new variable
367 # However, many things use this from build_cfg elsewhere
368 build_cfg["codebase_root_dir"] = codebase_dir
369 # Extract the common for all elements of config
370 for key in ["build_cmds", "required_artefacts"]:
371 try:
372 build_cfg[key] = deepcopy(self.tbm_common_cfg[key]
373 ["all"])
374 except KeyError as E:
375 build_cfg[key] = []
376 # Extract the platform specific elements of config
377 for key in ["build_cmds", "required_artefacts"]:
378 try:
Xinyu Zhang694eb492020-11-04 18:29:08 +0800379 if i.tfm_platform in self.tbm_common_cfg[key].keys() and i.with_ns:
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000380 build_cfg[key] += deepcopy(self.tbm_common_cfg[key]
Xinyu Zhangb708f572020-09-15 11:43:46 +0800381 [i.tfm_platform])
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000382 except Exception as E:
383 pass
Karl Zhang1eed6322020-07-01 15:38:10 +0800384
385 if os.cpu_count() >= 8:
386 #run in a serviver with scripts, parallel build will use CPU numbers
387 thread_no = " -j 2"
388 else:
389 #run in a docker, usually docker with CPUs less than 8
390 thread_no = " -j " + str(os.cpu_count())
Xinyu Zhangb708f572020-09-15 11:43:46 +0800391 build_cfg["build_cmds"][0] += thread_no
392 overwrite_params = {"codebase_root_dir": build_cfg["codebase_root_dir"],
393 "tfm_platform": i.tfm_platform,
394 "toolchain_file": i.toolchain_file,
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800395 "lib_model": i.lib_model,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800396 "isolation_level": i.isolation_level,
397 "test_regression": i.test_regression,
398 "test_psa_api": i.test_psa_api,
399 "cmake_build_type": i.cmake_build_type,
400 "with_otp": i.with_otp,
401 "with_bl2": i.with_bl2,
402 "with_ns": i.with_ns,
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800403 "profile": "" if i.profile=="N.A" else i.profile,
404 "partition_ps": i.partition_ps}
Xinyu Zhanga0086022020-11-10 18:11:12 +0800405 if i.test_psa_api == "IPC":
Xinyu Zhangcd1ed962020-11-11 16:00:52 +0800406 overwrite_params["test_psa_api"] += " -DINCLUDE_PANIC_TESTS=1"
Summer Qin3c2b5722021-05-26 10:43:45 +0800407 if i.tfm_platform == "arm/musca_b1/sse_200":
Xinyu Zhangcd1ed962020-11-11 16:00:52 +0800408 overwrite_params["test_psa_api"] += " -DITS_RAM_FS=ON -DPS_RAM_FS=ON"
Xinyu Zhangb708f572020-09-15 11:43:46 +0800409 build_cfg["config_template"] %= overwrite_params
Xinyu Zhang694eb492020-11-04 18:29:08 +0800410 if len(build_cfg["build_cmds"]) > 1:
411 overwrite_build_dir = {"_tbm_build_dir_": build_dir}
412 build_cfg["build_cmds"][1] %= overwrite_build_dir
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000413 return build_cfg
414
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100415 def post_eval(self):
416 """ If a single build failed fail the test """
417 try:
Minos Galanakisea421232019-06-20 17:11:28 +0100418 status_dict = self.unstash("Build Status")
419 if not status_dict:
420 raise Exception()
421 retcode_sum = sum(status_dict.values())
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100422 if retcode_sum != 0:
423 raise Exception()
424 return True
425 except Exception as e:
426 return False
427
428 def post_exec(self, eval_ret):
429 """ Generate a report and fail the script if build == unsuccessfull"""
430
431 self.print_summary()
432 if not eval_ret:
433 print("ERROR: ====> Build Failed! %s" % self.get_name())
434 self.set_status(1)
435 else:
436 print("SUCCESS: ====> Build Complete!")
437 self.set_status(0)
438
439 def get_report(self):
440 """ Expose the internal report to a new object for external classes """
441 return deepcopy(self.unstash("Build Report"))
442
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100443 def load_config(self, config, work_dir):
444 try:
445 # passing config_name param supersseeds fileparam
446 if isinstance(config, dict):
447 ret_cfg = deepcopy(config)
448 elif isinstance(config, str):
449 # If the string does not descrive a file try to look for it in
450 # work directory
451 if not os.path.isfile(config):
452 # remove path from file
453 config_2 = os.path.split(config)[-1]
454 # look in the current working directory
455 config_2 = os.path.join(work_dir, config_2)
456 if not os.path.isfile(config_2):
457 m = "Could not find cfg in %s or %s " % (config,
458 config_2)
459 raise Exception(m)
460 # If fille exists in working directory
461 else:
462 config = config_2
463 ret_cfg = load_json(config)
464
465 else:
466 raise Exception("Need to provide a valid config name or file."
467 "Please use --config/--config-file parameter.")
468 except Exception as e:
469 print("Error:%s \nCould not load a valid config" % e)
470 sys.exit(1)
471
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100472 return ret_cfg
473
474 def parse_config(self, cfg):
475 """ Parse a valid configuration file into a set of build dicts """
476
Minos Galanakisea421232019-06-20 17:11:28 +0100477 ret_cfg = {}
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100478
Minos Galanakisea421232019-06-20 17:11:28 +0100479 # Config entries which are not subject to changes during combinations
480 static_cfg = cfg["common_params"]
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100481
Minos Galanakisea421232019-06-20 17:11:28 +0100482 # Converth the code path to absolute path
483 abs_code_dir = static_cfg["codebase_root_dir"]
484 abs_code_dir = os.path.abspath(os.path.expanduser(abs_code_dir))
485 static_cfg["codebase_root_dir"] = abs_code_dir
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100486
Minos Galanakisea421232019-06-20 17:11:28 +0100487 # seed_params is an optional field. Do not proccess if it is missing
488 if "seed_params" in cfg:
489 comb_cfg = cfg["seed_params"]
490 # Generate a list of all possible confugration combinations
491 ret_cfg = TFM_Build_Manager.generate_config_list(comb_cfg,
492 static_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100493
Xinyu Zhang2c63ce72021-07-23 14:01:59 +0800494 # valid is an optional field. Do not proccess if it is missing
495 if "valid" in cfg:
496 # Valid configurations(Need to build)
497 valid_cfg = cfg["valid"]
498 # Add valid configs to build list
499 ret_cfg.update(TFM_Build_Manager.generate_optional_list(
500 comb_cfg,
501 static_cfg,
502 valid_cfg))
503
Minos Galanakisea421232019-06-20 17:11:28 +0100504 # invalid is an optional field. Do not proccess if it is missing
505 if "invalid" in cfg:
506 # Invalid configurations(Do not build)
507 invalid_cfg = cfg["invalid"]
508 # Remove the rejected entries from the test list
Xinyu Zhang0581b082021-05-17 10:46:57 +0800509 rejection_cfg = TFM_Build_Manager.generate_optional_list(
Minos Galanakisea421232019-06-20 17:11:28 +0100510 comb_cfg,
511 static_cfg,
512 invalid_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100513
Minos Galanakisea421232019-06-20 17:11:28 +0100514 # Subtract the two configurations
515 ret_cfg = {k: v for k, v in ret_cfg.items()
516 if k not in rejection_cfg}
517 self.simple_config = False
518 else:
519 self.simple_config = True
520 return ret_cfg, static_cfg
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100521
Minos Galanakisea421232019-06-20 17:11:28 +0100522 # ----- Override bellow methods when subclassing for other projects ----- #
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100523
Minos Galanakisea421232019-06-20 17:11:28 +0100524 def print_summary(self):
525 """ Print an comprehensive list of the build jobs with their status """
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100526
Minos Galanakisea421232019-06-20 17:11:28 +0100527 try:
528 full_rep = self.unstash("Build Report")["report"]
529 fl = ([k for k, v in full_rep.items() if v['status'] == 'Failed'])
530 ps = ([k for k, v in full_rep.items() if v['status'] == 'Success'])
531 except Exception as E:
Karl Zhangaff558a2020-05-15 14:28:23 +0100532 print("No report generated", E)
Minos Galanakisea421232019-06-20 17:11:28 +0100533 return
534 if fl:
535 print_test(t_list=fl, status="failed", tname="Builds")
536 if ps:
537 print_test(t_list=ps, status="passed", tname="Builds")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100538
Minos Galanakisea421232019-06-20 17:11:28 +0100539 @staticmethod
540 def generate_config_list(seed_config, static_config):
541 """ Generate all possible configuration combinations from a group of
542 lists of compiler options"""
543 config_list = []
544
545 if static_config["config_type"] == "tf-m":
546 cfg_name = "TFM_Build_CFG"
547 # Ensure the fieds are sorted in the desired order
548 # seed_config can be a subset of sort order for configurations with
549 # optional parameters.
550 tags = [n for n in static_config["sort_order"]
551 if n in seed_config.keys()]
Karl Zhangaff558a2020-05-15 14:28:23 +0100552 print("!!!!!!!!!!!gen list %s\r\n" % tags)
Minos Galanakisea421232019-06-20 17:11:28 +0100553
554 data = []
555 for key in tags:
556 data.append(seed_config[key])
557 config_list = gen_cfg_combinations(cfg_name,
558 " ".join(tags),
559 *data)
560 else:
561 print("Not information for project type: %s."
562 " Please check config" % static_config["config_type"])
563
564 ret_cfg = {}
565 # Notify the user for the rejected configuations
566 for i in config_list:
Xinyu Zhang1078e812020-10-15 11:52:36 +0800567 # Convert named tuples to string in a brief format
568 config_param = []
569 config_param.append(mapPlatform[list(i)[0]])
570 config_param.append(mapCompiler[list(i)[1]])
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800571 if list(i)[2]: # LIB_MODEL
572 config_param.append("LIB")
573 else:
574 config_param.append("IPC")
Xinyu Zhang1078e812020-10-15 11:52:36 +0800575 config_param.append(list(i)[3]) # ISOLATION_LEVEL
576 if list(i)[4]: # TEST_REGRESSION
577 config_param.append("REG")
578 if list(i)[5] != "OFF": #TEST_PSA_API
579 config_param.append(mapTestPsaApi[list(i)[5]])
580 config_param.append(list(i)[6]) # BUILD_TYPE
Xinyu Zhanga50432e2020-10-23 18:00:18 +0800581 if list(i)[7] == "ENABLED": # OTP
Xinyu Zhang1078e812020-10-15 11:52:36 +0800582 config_param.append("OTP")
583 if list(i)[8]: # BL2
584 config_param.append("BL2")
585 if list(i)[9]: # NS
586 config_param.append("NS")
587 if list(i)[10]: # PROFILE
588 config_param.append(mapProfile[list(i)[10]])
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800589 if list(i)[11] == "OFF": #PARTITION_PS
590 config_param.append("PSOFF")
Xinyu Zhang1078e812020-10-15 11:52:36 +0800591 i_str = "_".join(config_param)
Karl Zhangaff558a2020-05-15 14:28:23 +0100592 ret_cfg[i_str] = i
Minos Galanakisea421232019-06-20 17:11:28 +0100593 return ret_cfg
594
595 @staticmethod
Xinyu Zhang0581b082021-05-17 10:46:57 +0800596 def generate_optional_list(seed_config,
597 static_config,
598 optional_list):
599 optional_cfg = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100600
601 if static_config["config_type"] == "tf-m":
602
Xinyu Zhang0581b082021-05-17 10:46:57 +0800603 # If optional list is empty do nothing
604 if not optional_list:
605 return optional_cfg
Minos Galanakisea421232019-06-20 17:11:28 +0100606
607 tags = [n for n in static_config["sort_order"]
608 if n in seed_config.keys()]
609 sorted_default_lst = [seed_config[k] for k in tags]
610
Xinyu Zhang0581b082021-05-17 10:46:57 +0800611 # If tags are not alligned with optional list entries quit
612 if len(tags) != len(optional_list[0]):
613 print(len(tags), len(optional_list[0]))
Minos Galanakisea421232019-06-20 17:11:28 +0100614 print("Error, tags should be assigned to each "
Xinyu Zhang0581b082021-05-17 10:46:57 +0800615 "of the optional inputs")
Minos Galanakisea421232019-06-20 17:11:28 +0100616 return []
617
618 # Replace wildcard ( "*") entries with every
619 # inluded in cfg variant
Xinyu Zhang0581b082021-05-17 10:46:57 +0800620 for k in optional_list:
Minos Galanakisea421232019-06-20 17:11:28 +0100621 # Pad the omitted values with wildcard char *
622 res_list = list(k) + ["*"] * (5 - len(k))
Xinyu Zhang0581b082021-05-17 10:46:57 +0800623 print("Working on optional input: %s" % (res_list))
Minos Galanakisea421232019-06-20 17:11:28 +0100624
625 for n in range(len(res_list)):
626
627 res_list[n] = [res_list[n]] if res_list[n] != "*" \
628 else sorted_default_lst[n]
629
630 # Generate a configuration and a name for the completed array
Xinyu Zhang0581b082021-05-17 10:46:57 +0800631 op_cfg = TFM_Build_Manager.generate_config_list(
Minos Galanakisea421232019-06-20 17:11:28 +0100632 dict(zip(tags, res_list)),
633 static_config)
634
635 # Append the configuration to the existing ones
Xinyu Zhang0581b082021-05-17 10:46:57 +0800636 optional_cfg = dict(optional_cfg, **op_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100637
Xinyu Zhang0581b082021-05-17 10:46:57 +0800638 # Notify the user for the optional configuations
639 for i in optional_cfg.keys():
640 print("Generating optional config %s" % i)
Minos Galanakisea421232019-06-20 17:11:28 +0100641 else:
642 print("Not information for project type: %s."
643 " Please check config" % static_config["config_type"])
Xinyu Zhang0581b082021-05-17 10:46:57 +0800644 return optional_cfg