blob: ce14d24d9038401f4c98b0e1b8045eed293873d9 [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
Xinyu Zhangc918b6e2022-10-08 17:13:17 +080038def load_config_overrides(user_args, config_key):
39 """Load a configuration from multiple locations and override it with user provided
40 arguments"""
41
42 print("Using built-in config: %s" % config_key)
43 try:
44 config = lava_gen_config_map[config_key]
45 except KeyError:
46 print("No template found for config: %s" % config_key)
47 sys.exit(1)
48
49 config["build_no"] = user_args.build_no
50 config["artifact_store_url"] = user_args.jenkins_build_url
51
52 # Add the template folder
53 config["templ"] = os.path.join(user_args.template_dir, config["templ"])
54 return config
55
56
Matthew Hartfb6fd362020-03-04 21:03:59 +000057def generate_test_definitions(config, work_dir, user_args):
Fathi Boudra13b7eba2020-11-26 10:29:53 +010058 """Get a dictionary configuration and an existing jinja2 template to generate
59 a LAVA compatible yaml definition"""
Matthew Hartfb6fd362020-03-04 21:03:59 +000060
61 template_loader = FileSystemLoader(searchpath=work_dir)
62 template_env = Environment(loader=template_loader)
Dean Birch5d2dc572020-05-29 13:15:59 +010063 recovery_store_url = config.get('recovery_store_url', '')
Matthew Hartfb6fd362020-03-04 21:03:59 +000064 build_no = user_args.build_no
Dean Birch5d2dc572020-05-29 13:15:59 +010065 artifact_store_url = config["artifact_store_url"]
Matthew Hartfb6fd362020-03-04 21:03:59 +000066 template_file = config.pop("templ")
67
68 definitions = {}
69
70 for platform, recovery in config["platforms"].items():
71 if platform != user_args.platform:
72 continue
73 recovery_image_url = get_recovery_url(recovery_store_url, recovery)
74 for compiler in config["compilers"]:
75 if compiler != user_args.compiler:
76 continue
77 for build_type in config["build_types"]:
78 if build_type != user_args.build_type:
79 continue
80 for boot_type in config["boot_types"]:
81 bl2_string = "BL2" if user_args.bl2 else "NOBL2"
82 if boot_type != bl2_string:
83 continue
84 for test_name, test_dict in config["tests"].items():
85 if "Config{}".format(test_name) != user_args.proj_config:
86 continue
87 params = {
88 "device_type": config["device_type"],
89 "job_timeout": config["job_timeout"],
Fathi Boudra7454c552020-11-25 13:40:28 +010090 "action_timeout": config.get("action_timeout", ''),
91 "monitor_timeout": config.get("monitor_timeout", ''),
92 "poweroff_timeout": config.get("poweroff_timeout", ''),
Matthew Hartfb6fd362020-03-04 21:03:59 +000093 "compiler": compiler,
94 "build_type": build_type,
95 "build_no": build_no,
96 "boot_type": boot_type,
97 "name": test_name,
98 "test": test_dict,
99 "platform": platform,
100 "recovery_image_url": recovery_image_url,
101 "data_bin_offset": config.get('data_bin_offset', ''),
102 "docker_prefix": vars(user_args).get('docker_prefix', ''),
103 "license_variable": vars(user_args).get('license_variable', ''),
Leonardo Sandoval66386a22021-04-15 14:35:08 -0500104 "enable_code_coverage": user_args.enable_code_coverage == "TRUE",
105 "coverage_trace_plugin": coverage_trace_plugin,
Matthew Hartfb6fd362020-03-04 21:03:59 +0000106 "build_job_url": artifact_store_url,
Matthew Hart2c2688f2020-05-26 13:09:20 +0100107 "cpu0_baseline": config.get("cpu0_baseline", 0),
Paul Sokolovsky6302e1f2022-06-01 15:25:08 +0300108 "cpu0_initvtor_s": config.get("cpu0_initvtor_s", "0x10000000"),
109 "psa_api_suite": user_args.psa_suite,
Matthew Hartfb6fd362020-03-04 21:03:59 +0000110 }
Xinyu Zhang28d61b42022-03-21 16:46:35 +0800111 for binary_type, binary_name in config["binaries"].items():
112 params.update(
113 {
114 "{}_url".format(binary_type): get_artifact_url(
115 artifact_store_url,
116 params,
117 binary_name
118 )
119 }
120 )
Matthew Hartfb6fd362020-03-04 21:03:59 +0000121 params.update(
122 {
Xinyu Zhang82dab282022-10-09 16:33:19 +0800123 "job_name": "{}_{}_{}".format(os.getenv('CONFIG_NAME'), params['build_no'], params["device_type"]),
Xinyu Zhangd6638b72022-10-09 10:32:54 +0800124 "build_name": os.getenv('CONFIG_NAME')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000125 }
126 )
127
128 definition = template_env.get_template(template_file).render(
129 params
130 )
131 definitions.update({params["job_name"]: definition})
132 return definitions
133
134
135def generate_lava_job_defs(user_args, config):
Fathi Boudra13b7eba2020-11-26 10:29:53 +0100136 """Create a LAVA test job definition file"""
Matthew Hartfb6fd362020-03-04 21:03:59 +0000137
138 # Evaluate current directory
139 work_dir = os.path.abspath(os.path.dirname(__file__))
140
141 # If a single platform is requested and it exists in the platform
142 if user_args.platform and user_args.platform in config["platforms"]:
143 # Only test this platform
144 platform = user_args.platform
145 config["platforms"] = {platform: config["platforms"][platform]}
Fathi Boudra13b7eba2020-11-26 10:29:53 +0100146 # Generate the output definition
Matthew Hartfb6fd362020-03-04 21:03:59 +0000147 definitions = generate_test_definitions(config, work_dir, user_args)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000148 # Write it into a file
149 out_dir = os.path.abspath(user_args.lava_def_output)
150 os.makedirs(out_dir, exist_ok=True)
151 for name, definition in definitions.items():
152 out_file = os.path.join(out_dir, "{}{}".format(name, ".yaml"))
153 with open(out_file, "w") as F:
154 F.write(definition)
155 print("Definition created at %s" % out_file)
156
157
158def main(user_args):
159 user_args.template_dir = "jinja2_templates"
Xinyu Zhangbe224f62021-02-03 17:57:38 +0800160 config_keys = list(lava_gen_config_map.keys())
161 if user_args.fvp_only:
Xinyu Zhangd7616fc2022-07-06 16:14:36 +0800162 config_keys = [key for key in config_keys if "fvp" in key]
Xinyu Zhang302b74d2021-11-03 14:53:44 +0800163 if user_args.physical_board_only:
Xinyu Zhangd7616fc2022-07-06 16:14:36 +0800164 config_keys = [key for key in config_keys
165 if "fvp" not in key and "qemu" not in key]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000166 if user_args.config_key:
167 config_keys = [user_args.config_key]
168 for config_key in config_keys:
169 config = load_config_overrides(user_args, config_key)
170 generate_lava_job_defs(user_args, config)
171
172
173def get_cmd_args():
Fathi Boudra13b7eba2020-11-26 10:29:53 +0100174 """Parse command line arguments"""
Matthew Hartfb6fd362020-03-04 21:03:59 +0000175
176 # Parse command line arguments to override config
177 parser = argparse.ArgumentParser(description="Lava Create Jobs")
178 cmdargs = parser.add_argument_group("Create LAVA Jobs")
Xinyu Zhang302b74d2021-11-03 14:53:44 +0800179 device_type = parser.add_mutually_exclusive_group()
Matthew Hartfb6fd362020-03-04 21:03:59 +0000180
181 # Configuration control
182 cmdargs.add_argument(
183 "--config-name",
184 dest="config_key",
185 action="store",
186 help="Select built-in configuration by name",
187 )
188 cmdargs.add_argument(
189 "--build-number",
190 dest="build_no",
191 action="store",
192 default="lastSuccessfulBuild",
193 help="JENKINS Build number selector. " "Default: lastSuccessfulBuild",
194 )
195 cmdargs.add_argument(
196 "--output-dir",
197 dest="lava_def_output",
198 action="store",
199 default="job_results",
200 help="Set LAVA compatible .yaml output file",
201 )
202 cmdargs.add_argument(
203 "--platform",
204 dest="platform",
205 action="store",
206 help="Override platform.Only the provided one " "will be tested",
207 )
208 cmdargs.add_argument(
209 "--compiler",
210 dest="compiler",
211 action="store",
212 help="Compiler to build definitions for",
213 )
214 cmdargs.add_argument(
215 "--jenkins-build-url",
216 dest="jenkins_build_url",
217 action="store",
218 help="Set the Jenkins URL",
219 )
220 cmdargs.add_argument(
221 "--jenkins-job",
222 dest="jenkins_job",
223 action="store",
224 default="tf-m-build-config",
225 help="Set the jenkins job name",
226 )
227 cmdargs.add_argument(
228 "--proj-config", dest="proj_config", action="store", help="Proj config"
229 )
230 cmdargs.add_argument(
231 "--build-type", dest="build_type", action="store", help="Build type"
232 )
233 cmdargs.add_argument(
234 "--docker-prefix", dest="docker_prefix", action="store", help="Prefix string for the FVP docker registry location"
235 )
236 cmdargs.add_argument(
237 "--license-variable", dest="license_variable", action="store", help="License string for Fastmodels"
238 )
Leonardo Sandoval66386a22021-04-15 14:35:08 -0500239 cmdargs.add_argument(
240 "--enable-code-coverage", dest="enable_code_coverage", action="store", default="FALSE", help="Enable trace-base code coverage"
241 )
Matthew Hartfb6fd362020-03-04 21:03:59 +0000242 cmdargs.add_argument("--bl2", dest="bl2", action="store_true", help="BL2")
Matthew Hart2c2688f2020-05-26 13:09:20 +0100243 cmdargs.add_argument(
244 "--psa-api-suite", dest="psa_suite", action="store", help="PSA API Suite name"
245 )
Matthew Hartfb6fd362020-03-04 21:03:59 +0000246
Xinyu Zhang302b74d2021-11-03 14:53:44 +0800247 device_type.add_argument(
248 "--fvp-only",
249 dest="fvp_only",
250 action="store_true",
251 help="Run test cases on FVP only",
252 )
253 device_type.add_argument(
254 "--physical-board-only",
255 dest="physical_board_only",
256 action="store_true",
257 help="Run test cases on physical boards only",
258 )
259
260 return parser.parse_args()
Matthew Hartfb6fd362020-03-04 21:03:59 +0000261
262if __name__ == "__main__":
263 main(get_cmd_args())