blob: 207a9a53baf62082b05d272a0281e36712889e82 [file] [log] [blame]
Matthew Hartfb6fd362020-03-04 21:03:59 +00001#!/usr/bin/env python3
2
3from __future__ import print_function
4
5__copyright__ = """
6/*
Xinyu Zhang28d61b42022-03-21 16:46:35 +08007 * Copyright (c) 2020-2022, Arm Limited. All rights reserved.
Matthew Hartfb6fd362020-03-04 21:03:59 +00008 *
9 * SPDX-License-Identifier: BSD-3-Clause
10 *
11 */
12 """
13
14"""
Fathi Boudra13b7eba2020-11-26 10:29:53 +010015Script to create LAVA definitions from a single tf-m-build-config Jenkins Job
Matthew Hartfb6fd362020-03-04 21:03:59 +000016"""
17
18import os
19import sys
Matthew Hartfb6fd362020-03-04 21:03:59 +000020import argparse
Matthew Hartfb6fd362020-03-04 21:03:59 +000021from jinja2 import Environment, FileSystemLoader
22from lava_helper_configs import *
23
Matthew Hartfb6fd362020-03-04 21:03:59 +000024
25def get_artifact_url(artifact_store_url, params, filename):
Fathi Boudrae9accbc2020-11-25 10:32:31 +010026 platform = params["platform"]
27 if params["device_type"] == "fvp":
28 platform = "fvp"
29
Fathi Boudracaa90bd2020-12-04 22:00:14 +010030 url = "{}/artifact/trusted-firmware-m/build/bin/{}".format(artifact_store_url.rstrip("/"), filename)
Fathi Boudrae9accbc2020-11-25 10:32:31 +010031 return url
Matthew Hartfb6fd362020-03-04 21:03:59 +000032
33
34def get_recovery_url(recovery_store_url, recovery):
Dean Birch5d2dc572020-05-29 13:15:59 +010035 return "{}/{}".format(recovery_store_url.rstrip('/'), recovery)
Matthew Hartfb6fd362020-03-04 21:03:59 +000036
37
38def get_job_name(name, params, job):
39 return "{}_{}_{}_{}_{}_{}_{}_{}".format(
40 name,
41 job,
42 params["platform"],
43 params["build_no"],
44 params["compiler"],
45 params["build_type"],
46 params["boot_type"],
47 params["name"],
48 )
49
50
Xinyu Zhangc918b6e2022-10-08 17:13:17 +080051def load_config_overrides(user_args, config_key):
52 """Load a configuration from multiple locations and override it with user provided
53 arguments"""
54
55 print("Using built-in config: %s" % config_key)
56 try:
57 config = lava_gen_config_map[config_key]
58 except KeyError:
59 print("No template found for config: %s" % config_key)
60 sys.exit(1)
61
62 config["build_no"] = user_args.build_no
63 config["artifact_store_url"] = user_args.jenkins_build_url
64
65 # Add the template folder
66 config["templ"] = os.path.join(user_args.template_dir, config["templ"])
67 return config
68
69
Matthew Hartfb6fd362020-03-04 21:03:59 +000070def generate_test_definitions(config, work_dir, user_args):
Fathi Boudra13b7eba2020-11-26 10:29:53 +010071 """Get a dictionary configuration and an existing jinja2 template to generate
72 a LAVA compatible yaml definition"""
Matthew Hartfb6fd362020-03-04 21:03:59 +000073
74 template_loader = FileSystemLoader(searchpath=work_dir)
75 template_env = Environment(loader=template_loader)
Dean Birch5d2dc572020-05-29 13:15:59 +010076 recovery_store_url = config.get('recovery_store_url', '')
Matthew Hartfb6fd362020-03-04 21:03:59 +000077 build_no = user_args.build_no
Dean Birch5d2dc572020-05-29 13:15:59 +010078 artifact_store_url = config["artifact_store_url"]
Matthew Hartfb6fd362020-03-04 21:03:59 +000079 template_file = config.pop("templ")
80
81 definitions = {}
82
83 for platform, recovery in config["platforms"].items():
84 if platform != user_args.platform:
85 continue
86 recovery_image_url = get_recovery_url(recovery_store_url, recovery)
87 for compiler in config["compilers"]:
88 if compiler != user_args.compiler:
89 continue
90 for build_type in config["build_types"]:
91 if build_type != user_args.build_type:
92 continue
93 for boot_type in config["boot_types"]:
94 bl2_string = "BL2" if user_args.bl2 else "NOBL2"
95 if boot_type != bl2_string:
96 continue
97 for test_name, test_dict in config["tests"].items():
98 if "Config{}".format(test_name) != user_args.proj_config:
99 continue
100 params = {
101 "device_type": config["device_type"],
102 "job_timeout": config["job_timeout"],
Fathi Boudra7454c552020-11-25 13:40:28 +0100103 "action_timeout": config.get("action_timeout", ''),
104 "monitor_timeout": config.get("monitor_timeout", ''),
105 "poweroff_timeout": config.get("poweroff_timeout", ''),
Matthew Hartfb6fd362020-03-04 21:03:59 +0000106 "compiler": compiler,
107 "build_type": build_type,
108 "build_no": build_no,
109 "boot_type": boot_type,
110 "name": test_name,
111 "test": test_dict,
112 "platform": platform,
113 "recovery_image_url": recovery_image_url,
114 "data_bin_offset": config.get('data_bin_offset', ''),
115 "docker_prefix": vars(user_args).get('docker_prefix', ''),
116 "license_variable": vars(user_args).get('license_variable', ''),
Leonardo Sandoval66386a22021-04-15 14:35:08 -0500117 "enable_code_coverage": user_args.enable_code_coverage == "TRUE",
118 "coverage_trace_plugin": coverage_trace_plugin,
Matthew Hartfb6fd362020-03-04 21:03:59 +0000119 "build_job_url": artifact_store_url,
Matthew Hart2c2688f2020-05-26 13:09:20 +0100120 "cpu0_baseline": config.get("cpu0_baseline", 0),
Paul Sokolovsky6302e1f2022-06-01 15:25:08 +0300121 "cpu0_initvtor_s": config.get("cpu0_initvtor_s", "0x10000000"),
122 "psa_api_suite": user_args.psa_suite,
Matthew Hartfb6fd362020-03-04 21:03:59 +0000123 }
Xinyu Zhang28d61b42022-03-21 16:46:35 +0800124 for binary_type, binary_name in config["binaries"].items():
125 params.update(
126 {
127 "{}_url".format(binary_type): get_artifact_url(
128 artifact_store_url,
129 params,
130 binary_name
131 )
132 }
133 )
Matthew Hartfb6fd362020-03-04 21:03:59 +0000134 params.update(
135 {
136 "job_name": get_job_name(
137 config["job_name"], params, user_args.jenkins_job,
138 ),
Xinyu Zhangd6638b72022-10-09 10:32:54 +0800139 "build_name": os.getenv('CONFIG_NAME')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000140 }
141 )
142
143 definition = template_env.get_template(template_file).render(
144 params
145 )
146 definitions.update({params["job_name"]: definition})
147 return definitions
148
149
150def generate_lava_job_defs(user_args, config):
Fathi Boudra13b7eba2020-11-26 10:29:53 +0100151 """Create a LAVA test job definition file"""
Matthew Hartfb6fd362020-03-04 21:03:59 +0000152
153 # Evaluate current directory
154 work_dir = os.path.abspath(os.path.dirname(__file__))
155
156 # If a single platform is requested and it exists in the platform
157 if user_args.platform and user_args.platform in config["platforms"]:
158 # Only test this platform
159 platform = user_args.platform
160 config["platforms"] = {platform: config["platforms"][platform]}
Fathi Boudra13b7eba2020-11-26 10:29:53 +0100161 # Generate the output definition
Matthew Hartfb6fd362020-03-04 21:03:59 +0000162 definitions = generate_test_definitions(config, work_dir, user_args)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000163 # Write it into a file
164 out_dir = os.path.abspath(user_args.lava_def_output)
165 os.makedirs(out_dir, exist_ok=True)
166 for name, definition in definitions.items():
167 out_file = os.path.join(out_dir, "{}{}".format(name, ".yaml"))
168 with open(out_file, "w") as F:
169 F.write(definition)
170 print("Definition created at %s" % out_file)
171
172
173def main(user_args):
174 user_args.template_dir = "jinja2_templates"
Xinyu Zhangbe224f62021-02-03 17:57:38 +0800175 config_keys = list(lava_gen_config_map.keys())
176 if user_args.fvp_only:
Xinyu Zhangd7616fc2022-07-06 16:14:36 +0800177 config_keys = [key for key in config_keys if "fvp" in key]
Xinyu Zhang302b74d2021-11-03 14:53:44 +0800178 if user_args.physical_board_only:
Xinyu Zhangd7616fc2022-07-06 16:14:36 +0800179 config_keys = [key for key in config_keys
180 if "fvp" not in key and "qemu" not in key]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000181 if user_args.config_key:
182 config_keys = [user_args.config_key]
183 for config_key in config_keys:
184 config = load_config_overrides(user_args, config_key)
185 generate_lava_job_defs(user_args, config)
186
187
188def get_cmd_args():
Fathi Boudra13b7eba2020-11-26 10:29:53 +0100189 """Parse command line arguments"""
Matthew Hartfb6fd362020-03-04 21:03:59 +0000190
191 # Parse command line arguments to override config
192 parser = argparse.ArgumentParser(description="Lava Create Jobs")
193 cmdargs = parser.add_argument_group("Create LAVA Jobs")
Xinyu Zhang302b74d2021-11-03 14:53:44 +0800194 device_type = parser.add_mutually_exclusive_group()
Matthew Hartfb6fd362020-03-04 21:03:59 +0000195
196 # Configuration control
197 cmdargs.add_argument(
198 "--config-name",
199 dest="config_key",
200 action="store",
201 help="Select built-in configuration by name",
202 )
203 cmdargs.add_argument(
204 "--build-number",
205 dest="build_no",
206 action="store",
207 default="lastSuccessfulBuild",
208 help="JENKINS Build number selector. " "Default: lastSuccessfulBuild",
209 )
210 cmdargs.add_argument(
211 "--output-dir",
212 dest="lava_def_output",
213 action="store",
214 default="job_results",
215 help="Set LAVA compatible .yaml output file",
216 )
217 cmdargs.add_argument(
218 "--platform",
219 dest="platform",
220 action="store",
221 help="Override platform.Only the provided one " "will be tested",
222 )
223 cmdargs.add_argument(
224 "--compiler",
225 dest="compiler",
226 action="store",
227 help="Compiler to build definitions for",
228 )
229 cmdargs.add_argument(
230 "--jenkins-build-url",
231 dest="jenkins_build_url",
232 action="store",
233 help="Set the Jenkins URL",
234 )
235 cmdargs.add_argument(
236 "--jenkins-job",
237 dest="jenkins_job",
238 action="store",
239 default="tf-m-build-config",
240 help="Set the jenkins job name",
241 )
242 cmdargs.add_argument(
243 "--proj-config", dest="proj_config", action="store", help="Proj config"
244 )
245 cmdargs.add_argument(
246 "--build-type", dest="build_type", action="store", help="Build type"
247 )
248 cmdargs.add_argument(
249 "--docker-prefix", dest="docker_prefix", action="store", help="Prefix string for the FVP docker registry location"
250 )
251 cmdargs.add_argument(
252 "--license-variable", dest="license_variable", action="store", help="License string for Fastmodels"
253 )
Leonardo Sandoval66386a22021-04-15 14:35:08 -0500254 cmdargs.add_argument(
255 "--enable-code-coverage", dest="enable_code_coverage", action="store", default="FALSE", help="Enable trace-base code coverage"
256 )
Matthew Hartfb6fd362020-03-04 21:03:59 +0000257 cmdargs.add_argument("--bl2", dest="bl2", action="store_true", help="BL2")
Matthew Hart2c2688f2020-05-26 13:09:20 +0100258 cmdargs.add_argument(
259 "--psa-api-suite", dest="psa_suite", action="store", help="PSA API Suite name"
260 )
Matthew Hartfb6fd362020-03-04 21:03:59 +0000261
Xinyu Zhang302b74d2021-11-03 14:53:44 +0800262 device_type.add_argument(
263 "--fvp-only",
264 dest="fvp_only",
265 action="store_true",
266 help="Run test cases on FVP only",
267 )
268 device_type.add_argument(
269 "--physical-board-only",
270 dest="physical_board_only",
271 action="store_true",
272 help="Run test cases on physical boards only",
273 )
274
275 return parser.parse_args()
Matthew Hartfb6fd362020-03-04 21:03:59 +0000276
277if __name__ == "__main__":
278 main(get_cmd_args())