blob: 099ff2e87504538e5f266ec6b327c45963e78f69 [file] [log] [blame]
Dean Birch62c4f082020-01-17 16:13:26 +00001#!/usr/bin/env groovy
2//-------------------------------------------------------------------------------
3// Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
4//
5// SPDX-License-Identifier: BSD-3-Clause
6//
7//-------------------------------------------------------------------------------
8
Dean Birchd0f9f8c2020-03-26 11:10:33 +00009@Library('trustedfirmware') _
10import org.trustedfirmware.Gerrit
11import org.trustedfirmware.Summary
Dean Bircha6ede7e2020-03-13 14:00:33 +000012
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080013mapPlatform = ["cypress/psoc64": "psoc64",
14 "mps2/an519": "AN519",
15 "mps2/an521": "AN521",
16 "mps2/an539": "AN539",
17 "mps2/sse-200_aws": "SSE-200_AWS",
18 "mps3/an524": "AN524",
19 "musca_a": "MUSCA_A",
20 "musca_b1": "MUSCA_B1",
21 "musca_s1": "MUSCA_S1"]
22
23mapCompiler = ["toolchain_GNUARM.cmake": "GNUARM",
24 "toolchain_ARMCLANG.cmake": "ARMCLANG"]
25
26mapBL2 = ["True": "--bl2",
27 "False": ""]
28
29mapTestPsaApi = ["OFF": "",
30 "INTERNAL_TRUSTED_STORAGE": "ITS",
31 "PROTECTED_STORAGE": "PS",
32 "CRYPTO": "Crypto",
33 "INITIAL_ATTESTATION": "Attest",
34 "IPC": "FF"]
35
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080036// BL2, NS, PSA_API, ISOLATION_LEVEL, TEST_REG, TEST_PSA_API, PROFILE, PARTITION_PS, OTP
37mapConfigs = [
38 ["True", "True", "False", "1", "False", "OFF", "N.A", "Default"],
39 ["True", "True", "True", "1", "False", "OFF", "N.A", "CoreIPC"],
40 ["True", "True", "True", "2", "False", "OFF", "N.A", "CoreIPCTfmLevel2"],
41 ["True", "True", "True", "3", "False", "OFF", "N.A", "CoreIPCTfmLevel3"],
42 ["True", "True", "False", "1", "False", "OFF", "profile_small", "DefaultProfileS"],
43 ["True", "True", "True", "2", "False", "OFF", "profile_medium", "DefaultProfileM"],
44 ["True", "True", "False", "1", "True", "OFF", "N.A", "Regression"],
45 ["True", "True", "True", "1", "True", "OFF", "N.A", "RegressionIPC"],
46 ["True", "True", "True", "2", "True", "OFF", "N.A", "RegressionIPCTfmLevel2"],
47 ["True", "True", "True", "3", "True", "OFF", "N.A", "RegressionIPCTfmLevel3"],
48 ["True", "True", "False", "1", "True", "OFF", "profile_small", "RegressionProfileS"],
49 ["True", "True", "True", "2", "True", "OFF", "profile_medium", "RegressionProfileM"],
50 ["True", "True", "False", "1", "False", "INTERNAL_TRUSTED_STORAGE", "N.A", "PsaApiTest (ITS)"],
51 ["True", "True", "False", "1", "False", "PROTECTED_STORAGE", "N.A", "PsaApiTest (PS)"],
52 ["True", "True", "False", "1", "False", "CRYPTO", "N.A", "PsaApiTest (Crypto)"],
53 ["True", "True", "False", "1", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTest (Attest)"],
54 ["True", "True", "False", "1", "False", "IPC", "N.A", "PsaApiTest (FF)"],
55 ["True", "True", "True", "1", "False", "INTERNAL_TRUSTED_STORAGE", "N.A", "PsaApiTestIPC (ITS)"],
56 ["True", "True", "True", "1", "False", "PROTECTED_STORAGE", "N.A", "PsaApiTestIPC (PS)"],
57 ["True", "True", "True", "1", "False", "CRYPTO", "N.A", "PsaApiTestIPC (Crypto)"],
58 ["True", "True", "True", "1", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPC (Attest)"],
59 ["True", "True", "True", "1", "False", "IPC", "N.A", "PsaApiTestIPC (FF)"],
60 ["True", "True", "True", "2", "False", "INTERNAL_TRUSTED_STORAGE", "N.A", "PsaApiTestIPCTfmLevel2 (ITS)"],
61 ["True", "True", "True", "2", "False", "PROTECTED_STORAGE", "N.A", "PsaApiTestIPCTfmLevel2 (PS)"],
62 ["True", "True", "True", "2", "False", "CRYPTO", "N.A", "PsaApiTestIPCTfmLevel2 (Crypto)"],
63 ["True", "True", "True", "2", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPCTfmLevel2 (Attest)"],
64 ["True", "True", "True", "2", "False", "IPC", "N.A", "PsaApiTestIPCTfmLevel2 (FF)"],
65 ["True", "True", "True", "3", "False", "INTERNAL_TRUSTED_STORAGE", "N.A", "PsaApiTestIPCTfmLevel3 (ITS)"],
66 ["True", "True", "True", "3", "False", "PROTECTED_STORAGE", "N.A", "PsaApiTestIPCTfmLevel3 (PS)"],
67 ["True", "True", "True", "3", "False", "CRYPTO", "N.A", "PsaApiTestIPCTfmLevel3 (Crypto)"],
68 ["True", "True", "True", "3", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPCTfmLevel3 (Attest)"],
69 ["True", "True", "True", "3", "False", "IPC", "N.A", "PsaApiTestIPCTfmLevel3 (FF)"],
70]
71
72cfgs = ["Default", "CoreIPC", "CoreIPCTfmLevel2", "CoreIPCTfmLevel3",
73 "Regression", "RegressionIPC",
74 "RegressionIPCTfmLevel2", "RegressionIPCTfmLevel3",
75 "DefaultProfileS", "RegressionProfileS",
76 "DefaultProfileM", "RegressionProfileM", "RegressionProfileM PSOFF",
77 "PsaApiTest (Attest)", "PsaApiTestIPC (Attest)",
78 "PsaApiTestIPCTfmLevel2 (Attest)",
79 "PsaApiTest (Crypto)", "PsaApiTestIPC (Crypto)",
80 "PsaApiTestIPCTfmLevel2 (Crypto)",
81 "PsaApiTest (PS)", "PsaApiTestIPC (PS)",
82 "PsaApiTestIPCTfmLevel2 (PS)",
83 "PsaApiTest (ITS)", "PsaApiTestIPC (ITS)",
84 "PsaApiTestIPCTfmLevel2 (ITS)",
85 "PsaApiTestIPC (FF)",
86 "PsaApiTestIPCTfmLevel2 (FF)",
87 "PsaApiTestIPCTfmLevel3 (ITS)", "PsaApiTestIPCTfmLevel3 (PS)",
88 "PsaApiTestIPCTfmLevel3 (Crypto)", "PsaApiTestIPCTfmLevel3 (Attest)",
89 "PsaApiTestIPCTfmLevel3 (FF)"]
90
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080091def generateLavaParam(build_params) {
92 def params = []
93 params += string(name: "TARGET_PLATFORM", \
94 value: mapPlatform[build_params["TFM_PLATFORM"]])
95 params += string(name: "COMPILER", \
96 value: mapCompiler[build_params["TOOLCHAIN_FILE"]])
97 params += string(name: "PSA_API_SUITE", \
98 value: mapTestPsaApi[build_params["TEST_PSA_API"]])
99
100 if (build_params["BL2"] == "True" && \
101 build_params["NS"] == "True" && \
102 build_params["PSA_API"] == "False" && \
103 build_params["ISOLATION_LEVEL"] == "1" && \
104 build_params["TEST_REGRESSION"] == "False" && \
105 build_params["TEST_PSA_API"] == "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800106 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800107 params += string(name: "PROJ_CONFIG", value: "ConfigDefault")
108 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800109 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800110 build_params["NS"] == "True" && \
111 build_params["PSA_API"] == "True" && \
112 build_params["ISOLATION_LEVEL"] == "1" && \
113 build_params["TEST_REGRESSION"] == "False" && \
114 build_params["TEST_PSA_API"] == "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800115 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800116 params += string(name: "PROJ_CONFIG", value: "ConfigCoreIPC")
117 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800118 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800119 build_params["NS"] == "True" && \
120 build_params["PSA_API"] == "True" && \
121 build_params["ISOLATION_LEVEL"] == "2" && \
122 build_params["TEST_REGRESSION"] == "False" && \
123 build_params["TEST_PSA_API"] == "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800124 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800125 params += string(name: "PROJ_CONFIG", value: "ConfigCoreIPCTfmLevel2")
126 }
Karl Zhang3b092ef2020-11-06 16:56:25 +0800127 else if (build_params["BL2"] == "True" && \
128 build_params["NS"] == "True" && \
129 build_params["PSA_API"] == "True" && \
130 build_params["ISOLATION_LEVEL"] == "3" && \
131 build_params["TEST_REGRESSION"] == "False" && \
132 build_params["TEST_PSA_API"] == "OFF" && \
133 build_params["PROFILE"] == "N.A") {
134 params += string(name: "PROJ_CONFIG", value: "ConfigCoreIPCTfmLevel3")
135 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800136 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800137 build_params["NS"] == "True" && \
138 build_params["PSA_API"] == "False" && \
139 build_params["ISOLATION_LEVEL"] == "1" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800140 build_params["PROFILE"] == "profile_small" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800141 build_params["TEST_REGRESSION"] == "False" && \
142 build_params["TEST_PSA_API"] == "OFF") {
143 params += string(name: "PROJ_CONFIG", value: "ConfigDefaultProfileS")
144 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800145 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800146 build_params["NS"] == "True" && \
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800147 build_params["PSA_API"] == "True" && \
148 build_params["ISOLATION_LEVEL"] == "2" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800149 build_params["PROFILE"] == "profile_medium"&& \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800150 build_params["TEST_REGRESSION"] == "False" && \
151 build_params["TEST_PSA_API"] == "OFF") {
152 params += string(name: "PROJ_CONFIG", value: "ConfigDefaultProfileM")
153 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800154 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800155 build_params["NS"] == "True" && \
156 build_params["PSA_API"] == "False" && \
157 build_params["ISOLATION_LEVEL"] == "1" && \
158 build_params["TEST_REGRESSION"] == "True" && \
159 build_params["TEST_PSA_API"] == "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800160 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800161 params += string(name: "PROJ_CONFIG", value: "ConfigRegression")
162 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800163 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800164 build_params["NS"] == "True" && \
165 build_params["PSA_API"] == "True" && \
166 build_params["ISOLATION_LEVEL"] == "1" && \
167 build_params["TEST_REGRESSION"] == "True" && \
168 build_params["TEST_PSA_API"] == "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800169 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800170 params += string(name: "PROJ_CONFIG", value: "ConfigRegressionIPC")
171 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800172 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800173 build_params["NS"] == "True" && \
174 build_params["PSA_API"] == "True" && \
175 build_params["ISOLATION_LEVEL"] == "2" && \
176 build_params["TEST_REGRESSION"] == "True" && \
177 build_params["TEST_PSA_API"] == "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800178 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800179 params += string(name: "PROJ_CONFIG", value: "ConfigRegressionIPCTfmLevel2")
180 }
Karl Zhang3b092ef2020-11-06 16:56:25 +0800181 else if (build_params["BL2"] == "True" && \
182 build_params["NS"] == "True" && \
183 build_params["PSA_API"] == "True" && \
184 build_params["ISOLATION_LEVEL"] == "3" && \
185 build_params["TEST_REGRESSION"] == "True" && \
186 build_params["TEST_PSA_API"] == "OFF" && \
187 build_params["PROFILE"] == "N.A") {
188 params += string(name: "PROJ_CONFIG", value: "ConfigRegressionIPCTfmLevel3")
189 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800190 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800191 build_params["NS"] == "True" && \
192 build_params["PSA_API"] == "False" && \
193 build_params["ISOLATION_LEVEL"] == "1" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800194 build_params["PROFILE"] == "profile_small" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800195 build_params["TEST_REGRESSION"] == "True" && \
196 build_params["TEST_PSA_API"] == "OFF") {
197 params += string(name: "PROJ_CONFIG", value: "ConfigRegressionProfileS")
198 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800199 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800200 build_params["NS"] == "True" && \
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800201 build_params["PSA_API"] == "True" && \
202 build_params["ISOLATION_LEVEL"] == "2" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800203 build_params["PROFILE"] == "profile_medium"&& \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800204 build_params["TEST_REGRESSION"] == "True" && \
205 build_params["TEST_PSA_API"] == "OFF") {
206 params += string(name: "PROJ_CONFIG", value: "ConfigRegressionProfileM")
207 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800208 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800209 build_params["NS"] == "True" && \
210 build_params["PSA_API"] == "False" && \
211 build_params["ISOLATION_LEVEL"] == "1" && \
212 build_params["TEST_REGRESSION"] == "False" && \
213 build_params["TEST_PSA_API"] != "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800214 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800215 params += string(name: "PROJ_CONFIG", value: "ConfigPsaApiTest")
216 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800217 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800218 build_params["NS"] == "True" && \
219 build_params["PSA_API"] == "True" && \
220 build_params["ISOLATION_LEVEL"] == "1" && \
221 build_params["TEST_REGRESSION"] == "False" && \
222 build_params["TEST_PSA_API"] != "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800223 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800224 params += string(name: "PROJ_CONFIG", value: "ConfigPsaApiTestIPC")
225 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800226 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800227 build_params["NS"] == "True" && \
228 build_params["PSA_API"] == "True" && \
229 build_params["ISOLATION_LEVEL"] == "2" && \
230 build_params["TEST_REGRESSION"] == "False" && \
231 build_params["TEST_PSA_API"] != "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800232 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800233 params += string(name: "PROJ_CONFIG", value: "ConfigPsaApiTestIPCTfmLevel2")
234 }
Karl Zhang3b092ef2020-11-06 16:56:25 +0800235 else if (build_params["BL2"] == "True" && \
236 build_params["NS"] == "True" && \
237 build_params["PSA_API"] == "True" && \
238 build_params["ISOLATION_LEVEL"] == "3" && \
239 build_params["TEST_REGRESSION"] == "False" && \
240 build_params["TEST_PSA_API"] != "OFF" && \
241 build_params["PROFILE"] == "N.A") {
242 params += string(name: "PROJ_CONFIG", value: "ConfigPsaApiTestIPCTfmLevel3")
243 }
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800244 else {
245 params += string(name: "PROJ_CONFIG", value: "ConfigDefault")
246 }
247 return params
248}
249
Dean Birch62c4f082020-01-17 16:13:26 +0000250def listConfigs(ci_scripts_dir, config_list, filter_group) {
251 dir(ci_scripts_dir) {
252 echo "Obtaining list of configs."
Matthew Hartfb6fd362020-03-04 21:03:59 +0000253 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}"
Dean Birch62c4f082020-01-17 16:13:26 +0000254 def build_config_list_raw = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +0000255python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}
Dean Birch62c4f082020-01-17 16:13:26 +0000256""", returnStdout: true).trim()
257 def build_config_list = build_config_list_raw.tokenize('\n')
258 config_list.addAll(build_config_list)
259 }
260}
261
Matthew Hartfb6fd362020-03-04 21:03:59 +0000262def buildConfig(ci_scripts_dir, config, filter_group, results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000263 def params = []
Matthew Hartfb6fd362020-03-04 21:03:59 +0000264 def params_collection = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000265 def build_config_params
266 dir(ci_scripts_dir) {
267 echo "Obtaining build configuration for config ${config}"
Matthew Hartfb6fd362020-03-04 21:03:59 +0000268 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}"
Dean Birch62c4f082020-01-17 16:13:26 +0000269 build_config_params = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +0000270python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}
Dean Birch62c4f082020-01-17 16:13:26 +0000271""", returnStdout: true).trim()
272 }
273 def lines = build_config_params.tokenize('\n')
274 for (String line : lines) {
275 def key, value
276 (key, value) = line.tokenize('=')
277 params += string(name: key, value: value)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000278 params_collection[key] = value
Dean Birch62c4f082020-01-17 16:13:26 +0000279 }
280 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000281 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
282 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
283 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000284 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800285 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000286 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Karl Zhangf6f467e2020-07-10 16:24:45 +0800287 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000288 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000289 return { -> results
290 def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false)
291 def build_info = [build_res, config, params_collection]
292 results['builds'][build_res.number] = build_info
293 def build_url = build_res.getAbsoluteUrl()
294 print("${build_res.number}: ${config} ${build_res.result} ${build_url}")
295 failure_states = ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]
296 if (build_res.result in failure_states) {
297 error("Build failed at ${build_url}")
298 }
Karl Zhang2b10b342020-11-09 14:50:11 +0800299 else if (params_collection["NS"] == "False" || \
300 (params_collection["PROFILE"] == "profile_medium" && \
301 params_collection["PARTITION_PS"] == "OFF")) {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800302 print("LAVA is not needed for ${build_url}")
303 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000304 else {
305 print("Doing LAVA stuff for ${build_url}")
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800306 params += generateLavaParam(params_collection)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000307 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
308 params += string(name: 'BUILD_URL', value: build_url)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000309 params += string(name: 'LAVA_URL', value: env.LAVA_URL)
Dean Birch956416f2020-08-12 10:36:16 +0100310 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
311 params += string(name: 'LAVA_CREDENTIALS', value: env.LAVA_CREDENTIALS)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000312 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000313 if (lava_res.result in failure_states) {
314 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
315 }
316 else {
317 results['lava_jobs'] += lava_res.getDescription()
318 }
Dean Birch62c4f082020-01-17 16:13:26 +0000319 }
320 }
321}
322
Matthew Hart06340d72020-06-15 16:08:20 +0100323def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000324 def params = []
325 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000326 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
327 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
328 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000329 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800330 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000331 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000332 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Matthew Hart06340d72020-06-15 16:08:20 +0100333 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +0000334 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
335 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +0100336 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +0000337 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +0000338 error("Build failed at ${res.getAbsoluteUrl()}")
339 }
340 }
341}
342
Xinyu Zhang38a18872020-11-23 16:45:28 +0800343def generateEmailBody(stage, failed_jobs) {
344 body = "Check console output at ${env.BUILD_URL} \n\n"
345
346 body += "Failed Jobs:\n"
347 failed_jobs.each { job ->
348 body += "${job.key} ${job.value}\n"
349 }
350
351 body += "\nFor detailed ${stage} results please refer to \
352 ${env.BUILD_URL}artifact/${stage}_results.csv \n"
353 return body
354}
355
356def emailNotification(results, stage, failed_jobs) {
Karl Zhang0413e972020-09-18 17:59:26 +0800357 script {
358 if (env.JOB_NAME.equals("tf-m-nightly") && !env.EMAIL_NOTIFICATION.equals('')) {
359 def result = "Fail."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800360 if (results == true) {
Karl Zhang0413e972020-09-18 17:59:26 +0800361 result = "Success."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800362 print("Skip sending as ${result} for ${stage}")
363 }
364 else {
365 emailext (
366 subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} ${result}"),
Xinyu Zhang38a18872020-11-23 16:45:28 +0800367 body: generateEmailBody(stage, failed_jobs),
Karl Zhang182ecdf2020-10-10 09:52:12 +0800368 to: "${EMAIL_NOTIFICATION}"
369 )
370 }
Karl Zhang0413e972020-09-18 17:59:26 +0800371 }
372 } /* script */
373}
374
Xinyu Zhang38a18872020-11-23 16:45:28 +0800375def filterFailedBuild(results) {
376 def failed_builds = [:]
377 results.each { result ->
378 if (result.value[0].getResult() == "FAILURE") {
379 failed_builds[result.value[1]] = result.value[0].getAbsoluteUrl()
380 }
381 }
382 return failed_builds
383}
384
385def filterFailedTest(string) {
386 def failed_tests = [:]
387 line = lineInString(string, "FAILURE_TESTS:")
388 a = line.split(' ')
389 if (a.size() > 1) {
390 a = line.split(' ')[1..-1]
391 a.each { fail_test ->
392 config_link = fail_test.split(':')
393 failed_tests[config_link[0]] = config_link[1..-1].join(':')
394 }
395 }
396 return failed_tests
397}
398
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800399@NonCPS
400def generateCsvContent(results) {
401 def resultsParam = []
402 results.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800403 if (result.value[2]['BL2'] == "True") {
404 resultsParam.add([result.value[1], \
405 result.value[0].getResult(), \
406 result.value[2]['TFM_PLATFORM'], \
407 result.value[2]['TOOLCHAIN_FILE'], \
408 result.value[2]['CMAKE_BUILD_TYPE'], \
409 result.value[2]['BL2'], \
410 result.value[2]['NS'], \
411 result.value[2]['PSA_API'], \
412 result.value[2]['ISOLATION_LEVEL'], \
413 result.value[2]['TEST_REGRESSION'], \
414 result.value[2]['TEST_PSA_API'], \
415 result.value[2]['PROFILE'], \
416 result.value[2]['PARTITION_PS'], \
417 result.value[2]['OTP']])
418 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800419 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800420 resultsParam.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800421 if (result[2] == 'musca_b1') {
422 if (result[13] != 'off') {
423 result[2] = 'musca_b1_OTP'
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800424 }
425 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800426 result[3] = mapCompiler[result[3]]
427 build_params = result[5..12]
428 configName = ""
429 for (map_cfg in mapConfigs) {
430 if (build_params[0..6] == map_cfg[0..6]) {
431 configName = map_cfg[7]
432 break
433 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800434 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800435 if (configName == "") {
436 configName = "Default"
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800437 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800438 else if (configName == "RegressionProfileM") {
439 if (build_params[7] == "OFF") {
440 configName = "RegressionProfileM PSOFF"
441 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800442 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800443 result.add(configName)
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800444 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800445 def csvContent = []
446 resultsParam.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800447 current_row = result[2..4]
448 cfgs.each {cfg ->
449 if (cfg == result[14]) {
450 current_row.add(cfg)
451 current_row.add(result[1])
452 }
453 }
454 csvContent.add(current_row)
455 }
456 csvContent.sort{a,b -> a[0] <=> b[0] ?: a[1] <=> b[1] ?: a[2] <=> b[2]}
457 build_summary = []
458 current_platform = ""
459 current_compiler = ""
460 current_build_type = ""
461 csvContent.each { build_cfg ->
462 if (current_platform != build_cfg[0] || \
463 current_compiler != build_cfg[1] || \
464 current_build_type != build_cfg[2]) {
465 current_platform = build_cfg[0]
466 current_compiler = build_cfg[1]
467 current_build_type = build_cfg[2]
468 csv_line = [current_platform, current_compiler, current_build_type]
469 cfgs.each {
470 csv_line.add("N.A.")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800471 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800472 build_summary.add(csv_line)
473 }
474 i = 0
475 cfgs.each { cfg ->
476 if (cfg == build_cfg[3]) {
477 build_summary[-1][3+i] = build_cfg[4]
478 }
479 i += 1
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800480 }
481 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800482 build_summary.add(0, ['Platform', 'Compiler', 'Cmake Build Type'])
483 build_summary[0] += cfgs
484 return build_summary
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800485}
486
487def generateBuildCsv(results) {
488 def csvContent = generateCsvContent(results)
489 node("master") {
490 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
491 archiveArtifacts 'build_results.csv'
492 }
493}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000494
495def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000496 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000497 def csvContent = summary.getBuildCsv(results)
498 node("master") {
499 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
500 archiveArtifacts 'build_results.csv'
501 }
502}
503
504def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000505 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000506 def buildLinks = summary.getLinks(results)
507 node("master") {
508 writeFile file: "build_links.html", text: buildLinks
509 archiveArtifacts 'build_links.html'
510 }
511}
512
Matthew Hartfb6fd362020-03-04 21:03:59 +0000513def lineInString(string, match) {
514 def lines = string.split("\n")
515 def result = lines.findAll { it.contains(match) }
516 return result[0]
517}
518
519def getResult(string, match) {
520 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100521 a = line.split(match)[1].split(' ')
522 score = a[0]
523 if (a.size() > 1)
524 {
525 fail_text = a[1..-1].join(" ")
526 return [score, fail_text]
527 }
528 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000529}
530
531def submitJobsToList(results) {
532 def all_jobs = []
533 for (String result : results){
534 jobs_s = result.split('JOBS: ')
535 if (jobs_s.size() > 1) {
536 all_jobs += jobs_s[1]
537 }
538 }
539 return(all_jobs)
540}
541
Dean Birch62c4f082020-01-17 16:13:26 +0000542def configs = []
543def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000544def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000545
Benjamin Copelandbe53b032020-10-30 19:57:59 +0000546node("docker-amd64-tf-m-bionic") {
Dean Birch62c4f082020-01-17 16:13:26 +0000547 stage("Init") {
548 cleanWs()
549 dir("tf-m-ci-scripts") {
Colin Thorbinson58703db2020-11-24 12:02:19 +0000550 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
Dean Birch62c4f082020-01-17 16:13:26 +0000551 }
552 }
553 stage("Configs") {
554 // Populate configs
555 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000556 results['builds'] = [:]
557 results['lava_jobs'] = []
Dean Birch62c4f082020-01-17 16:13:26 +0000558 for (config in configs) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000559 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
Dean Birch62c4f082020-01-17 16:13:26 +0000560 }
Matthew Hart06340d72020-06-15 16:08:20 +0100561 builds["docs"] = buildDocs(results)
Dean Birch62c4f082020-01-17 16:13:26 +0000562 }
563}
Karl Zhangfec84102020-06-24 09:56:36 +0800564
Dean Birch62c4f082020-01-17 16:13:26 +0000565stage("Builds") {
566 def verify = 1
Karl Zhang182ecdf2020-10-10 09:52:12 +0800567 def success = true
Dean Birch62c4f082020-01-17 16:13:26 +0000568 try {
569 parallel(builds)
570 } catch (Exception e) {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000571 print(e)
Dean Birch62c4f082020-01-17 16:13:26 +0000572 manager.buildFailure()
573 verify = -1
Karl Zhang182ecdf2020-10-10 09:52:12 +0800574 success = false
Dean Birch62c4f082020-01-17 16:13:26 +0000575 } finally {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000576 print("Verifying status")
Xinyu Zhang38a18872020-11-23 16:45:28 +0800577 def failed_builds = filterFailedBuild(results['builds'])
578 emailNotification(success, 'build', failed_builds)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000579 g = new Gerrit()
580 g.verifyStatus(verify, 'tf-m-build', 'build')
Dean Bircha6ede7e2020-03-13 14:00:33 +0000581 print("Building CSV")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800582 generateBuildCsv(results['builds'])
Dean Bircha6ede7e2020-03-13 14:00:33 +0000583 writeSummary(results['builds'])
Dean Birch62c4f082020-01-17 16:13:26 +0000584 }
585}
Matthew Hart06340d72020-06-15 16:08:20 +0100586
Benjamin Copelandbe53b032020-10-30 19:57:59 +0000587node("docker-amd64-tf-m-bionic") {
Matthew Hart06340d72020-06-15 16:08:20 +0100588 stage("Copy Docs") {
Karl Zhang32497972020-09-21 14:38:29 +0800589 if (env.JOB_NAME.equals("tf-m-build-and-test")) {
590 step([$class: 'CopyArtifact', projectName: 'tf-m-build-docs',
591 selector: specific("${results['docs'][0]}"), target: './docs/',
592 optional: true])
593 archiveArtifacts artifacts: 'docs/**', allowEmptyArchive: true
594 }
595 else {
596 print("No doc copy for job: ${env.JOB_NAME}")
597 }
Matthew Hart06340d72020-06-15 16:08:20 +0100598 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000599 stage("Tests") {
600 dir("tf-m-ci-scripts") {
Colin Thorbinson58703db2020-11-24 12:02:19 +0000601 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
Dean Bircha6ede7e2020-03-13 14:00:33 +0000602 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000603 def all_jobs = []
604 def success = true
Dean Bircha6ede7e2020-03-13 14:00:33 +0000605 print("Wait for LAVA results here...")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000606 try {
607 all_jobs = submitJobsToList(results['lava_jobs'])
608 if (all_jobs.size() > 0) {
609 dir("tf-m-ci-scripts") {
Dean Birch956416f2020-08-12 10:36:16 +0100610 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000611 output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
612 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
Matthew Hart05a59b52020-05-27 17:54:51 +0100613 --artifacts-path lava_artifacts --lava-timeout 7200 \
Matthew Hartfb6fd362020-03-04 21:03:59 +0000614 """, returnStdout: true).trim()
615 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
Xinyu Zhang1b8f5152020-11-13 16:10:58 +0800616 archiveArtifacts artifacts: 'test_results.csv', allowEmptyArchive: true
Matthew Hartfb6fd362020-03-04 21:03:59 +0000617 g = new Gerrit()
Dean Birch1d545c02020-05-29 14:09:21 +0100618 def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000619 if (boot_result) {
620 g.verifyStatus(boot_result, "lava_boot", "test")
621 }
Dean Birch1d545c02020-05-29 14:09:21 +0100622 def (test_result, test_output) = getResult(output, 'TEST_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000623 if (test_result) {
624 g.verifyStatus(test_result, "lava_test", "test")
625 }
626 if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) {
Dean Birch1d545c02020-05-29 14:09:21 +0100627 error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000628 }
629 }
630 }
631 }
632 else {
633 print("There were no LAVA jobs to test.")
634 }
635 }
636 catch (Exception e) {
637 print("ERROR: ${e}")
638 success = false
639 } finally {
640 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
Xinyu Zhang38a18872020-11-23 16:45:28 +0800641 emailNotification(success, 'test', filterFailedTest(output))
Matthew Hartfb6fd362020-03-04 21:03:59 +0000642 cleanWs()
643 if (!success) {
644 error("There was an Error waiting for LAVA jobs")
645 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000646 }
647 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000648}