blob: 33388c13073dff3e6377fde8e83a825c9ff2b8ba [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/*
Gergely Korcsákac2d0f02024-05-28 08:23:04 +02007 * Copyright (c) 2020-2024, 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
Matthew Hartfb6fd362020-03-04 21:03:59 +000025def get_recovery_url(recovery_store_url, recovery):
Dean Birch5d2dc572020-05-29 13:15:59 +010026 return "{}/{}".format(recovery_store_url.rstrip('/'), recovery)
Matthew Hartfb6fd362020-03-04 21:03:59 +000027
28
Xinyu Zhangc918b6e2022-10-08 17:13:17 +080029def load_config_overrides(user_args, config_key):
30 """Load a configuration from multiple locations and override it with user provided
31 arguments"""
32
33 print("Using built-in config: %s" % config_key)
34 try:
Xinyu Zhang426c7252023-10-12 17:43:53 +080035 config = lava_gen_config_map_bl2[config_key] if os.getenv("BL2") == "True" \
36 else lava_gen_config_map_nobl2[config_key]
Xinyu Zhangc918b6e2022-10-08 17:13:17 +080037 except KeyError:
38 print("No template found for config: %s" % config_key)
39 sys.exit(1)
40
Xinyu Zhangc918b6e2022-10-08 17:13:17 +080041 # Add the template folder
42 config["templ"] = os.path.join(user_args.template_dir, config["templ"])
43 return config
44
45
Matthew Hartfb6fd362020-03-04 21:03:59 +000046def generate_test_definitions(config, work_dir, user_args):
Fathi Boudra13b7eba2020-11-26 10:29:53 +010047 """Get a dictionary configuration and an existing jinja2 template to generate
48 a LAVA compatible yaml definition"""
Matthew Hartfb6fd362020-03-04 21:03:59 +000049
50 template_loader = FileSystemLoader(searchpath=work_dir)
51 template_env = Environment(loader=template_loader)
Dean Birch5d2dc572020-05-29 13:15:59 +010052 recovery_store_url = config.get('recovery_store_url', '')
Matthew Hartfb6fd362020-03-04 21:03:59 +000053 template_file = config.pop("templ")
54
55 definitions = {}
56
57 for platform, recovery in config["platforms"].items():
Xinyu Zhang22a12752022-10-10 17:21:21 +080058 if platform != os.getenv('TFM_PLATFORM'):
Matthew Hartfb6fd362020-03-04 21:03:59 +000059 continue
60 recovery_image_url = get_recovery_url(recovery_store_url, recovery)
Xinyu Zhang32355382023-04-25 17:49:06 +080061 if os.getenv("TEST_PSA_API") != "OFF":
Xinyu Zhang22a12752022-10-10 17:21:21 +080062 monitor_name = "arch_tests"
Xinyu Zhang32355382023-04-25 17:49:06 +080063 elif os.getenv("TEST_REGRESSION") == "OFF":
Xinyu Zhang22a12752022-10-10 17:21:21 +080064 monitor_name = "no_reg_tests"
Xinyu Zhang32355382023-04-25 17:49:06 +080065 else:
66 monitor_name = "reg_tests"
Xinyu Zhang22a12752022-10-10 17:21:21 +080067 params = {
68 "job_name": "{}_{}_{}".format(os.getenv('CONFIG_NAME'), os.getenv("BUILD_NUMBER"), config["device_type"]),
69 "build_name": os.getenv('CONFIG_NAME'),
70 "device_type": config["device_type"],
71 "job_timeout": config["job_timeout"],
72 "action_timeout": config.get("action_timeout", ''),
73 "monitor_timeout": config.get("monitor_timeout", ''),
74 "poweroff_timeout": config.get("poweroff_timeout", ''),
75 "build_no": os.getenv("BUILD_NUMBER"),
76 "name": monitor_name,
77 "monitors": config['monitors'].get(monitor_name, []),
78 "platform": platform,
79 "recovery_image_url": recovery_image_url,
Xinyu Zhang22a12752022-10-10 17:21:21 +080080 "docker_prefix": vars(user_args).get('docker_prefix', ''),
81 "license_variable": vars(user_args).get('license_variable', ''),
82 "enable_code_coverage": user_args.enable_code_coverage == "TRUE",
83 "coverage_trace_plugin": coverage_trace_plugin,
Paul Sokolovskyf08e08e2024-07-02 18:59:43 +030084 "build_job_url": os.getenv("BUILD_URL"),
Xinyu Zhang22a12752022-10-10 17:21:21 +080085 "cpu0_baseline": config.get("cpu0_baseline", 0),
86 "cpu0_initvtor_s": config.get("cpu0_initvtor_s", "0x10000000"),
87 "psa_api_suite": os.getenv("TEST_PSA_API") if os.getenv("TEST_PSA_API") == "IPC" else "",
Gergely Korcsákac2d0f02024-05-28 08:23:04 +020088 "binaries": config.get('binaries', []),
Nicola Mazzucatoe12c1b52024-12-16 09:56:26 +000089 "data_url_prefix": "{}/artifact/ci_build".format(os.getenv("BUILD_URL")),
90 "build_type": os.getenv("CMAKE_BUILD_TYPE"),
Xinyu Zhang22a12752022-10-10 17:21:21 +080091 }
Matthew Hartfb6fd362020-03-04 21:03:59 +000092
Xinyu Zhang22a12752022-10-10 17:21:21 +080093 if len(params["monitors"]) == 0:
94 break
95
96 definition = template_env.get_template(template_file).render(
97 params
98 )
99 definitions.update({params["job_name"]: definition})
100
Matthew Hartfb6fd362020-03-04 21:03:59 +0000101 return definitions
102
103
104def generate_lava_job_defs(user_args, config):
Fathi Boudra13b7eba2020-11-26 10:29:53 +0100105 """Create a LAVA test job definition file"""
Matthew Hartfb6fd362020-03-04 21:03:59 +0000106
107 # Evaluate current directory
108 work_dir = os.path.abspath(os.path.dirname(__file__))
109
Xinyu Zhang22a12752022-10-10 17:21:21 +0800110 # If platform exists in the LAVA platforms
111 if os.getenv("TFM_PLATFORM") in config["platforms"]:
Matthew Hartfb6fd362020-03-04 21:03:59 +0000112 # Only test this platform
Xinyu Zhang22a12752022-10-10 17:21:21 +0800113 platform = os.getenv("TFM_PLATFORM")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000114 config["platforms"] = {platform: config["platforms"][platform]}
Fathi Boudra13b7eba2020-11-26 10:29:53 +0100115 # Generate the output definition
Matthew Hartfb6fd362020-03-04 21:03:59 +0000116 definitions = generate_test_definitions(config, work_dir, user_args)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000117 # Write it into a file
118 out_dir = os.path.abspath(user_args.lava_def_output)
119 os.makedirs(out_dir, exist_ok=True)
120 for name, definition in definitions.items():
121 out_file = os.path.join(out_dir, "{}{}".format(name, ".yaml"))
122 with open(out_file, "w") as F:
123 F.write(definition)
124 print("Definition created at %s" % out_file)
125
126
127def main(user_args):
128 user_args.template_dir = "jinja2_templates"
Xinyu Zhang426c7252023-10-12 17:43:53 +0800129 config_keys = list(lava_gen_config_map_bl2.keys()) if os.getenv("BL2") == "True" \
130 else list(lava_gen_config_map_nobl2.keys())
Xinyu Zhangbe224f62021-02-03 17:57:38 +0800131 if user_args.fvp_only:
Xinyu Zhangd7616fc2022-07-06 16:14:36 +0800132 config_keys = [key for key in config_keys if "fvp" in key]
Xinyu Zhang302b74d2021-11-03 14:53:44 +0800133 if user_args.physical_board_only:
Xinyu Zhangd7616fc2022-07-06 16:14:36 +0800134 config_keys = [key for key in config_keys
135 if "fvp" not in key and "qemu" not in key]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000136 if user_args.config_key:
137 config_keys = [user_args.config_key]
138 for config_key in config_keys:
139 config = load_config_overrides(user_args, config_key)
140 generate_lava_job_defs(user_args, config)
141
142
143def get_cmd_args():
Fathi Boudra13b7eba2020-11-26 10:29:53 +0100144 """Parse command line arguments"""
Matthew Hartfb6fd362020-03-04 21:03:59 +0000145
146 # Parse command line arguments to override config
147 parser = argparse.ArgumentParser(description="Lava Create Jobs")
148 cmdargs = parser.add_argument_group("Create LAVA Jobs")
Xinyu Zhang302b74d2021-11-03 14:53:44 +0800149 device_type = parser.add_mutually_exclusive_group()
Matthew Hartfb6fd362020-03-04 21:03:59 +0000150
151 # Configuration control
152 cmdargs.add_argument(
153 "--config-name",
154 dest="config_key",
155 action="store",
156 help="Select built-in configuration by name",
157 )
158 cmdargs.add_argument(
Matthew Hartfb6fd362020-03-04 21:03:59 +0000159 "--output-dir",
160 dest="lava_def_output",
161 action="store",
162 default="job_results",
163 help="Set LAVA compatible .yaml output file",
164 )
165 cmdargs.add_argument(
Matthew Hartfb6fd362020-03-04 21:03:59 +0000166 "--jenkins-build-url",
167 dest="jenkins_build_url",
168 action="store",
169 help="Set the Jenkins URL",
170 )
171 cmdargs.add_argument(
172 "--jenkins-job",
173 dest="jenkins_job",
174 action="store",
175 default="tf-m-build-config",
176 help="Set the jenkins job name",
177 )
178 cmdargs.add_argument(
Matthew Hartfb6fd362020-03-04 21:03:59 +0000179 "--docker-prefix", dest="docker_prefix", action="store", help="Prefix string for the FVP docker registry location"
180 )
181 cmdargs.add_argument(
182 "--license-variable", dest="license_variable", action="store", help="License string for Fastmodels"
183 )
Leonardo Sandoval66386a22021-04-15 14:35:08 -0500184 cmdargs.add_argument(
185 "--enable-code-coverage", dest="enable_code_coverage", action="store", default="FALSE", help="Enable trace-base code coverage"
186 )
Matthew Hartfb6fd362020-03-04 21:03:59 +0000187
Xinyu Zhang302b74d2021-11-03 14:53:44 +0800188 device_type.add_argument(
189 "--fvp-only",
190 dest="fvp_only",
191 action="store_true",
192 help="Run test cases on FVP only",
193 )
194 device_type.add_argument(
195 "--physical-board-only",
196 dest="physical_board_only",
197 action="store_true",
198 help="Run test cases on physical boards only",
199 )
200
201 return parser.parse_args()
Matthew Hartfb6fd362020-03-04 21:03:59 +0000202
203if __name__ == "__main__":
204 main(get_cmd_args())