blob: 13f927d20841e6e3b8479dba240b1522d6a38b6d [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
36def generateLavaParam(build_params) {
37 def params = []
38 params += string(name: "TARGET_PLATFORM", \
39 value: mapPlatform[build_params["TFM_PLATFORM"]])
40 params += string(name: "COMPILER", \
41 value: mapCompiler[build_params["TOOLCHAIN_FILE"]])
42 params += string(name: "PSA_API_SUITE", \
43 value: mapTestPsaApi[build_params["TEST_PSA_API"]])
44
45 if (build_params["BL2"] == "True" && \
46 build_params["NS"] == "True" && \
47 build_params["PSA_API"] == "False" && \
48 build_params["ISOLATION_LEVEL"] == "1" && \
49 build_params["TEST_REGRESSION"] == "False" && \
50 build_params["TEST_PSA_API"] == "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +080051 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080052 params += string(name: "PROJ_CONFIG", value: "ConfigDefault")
53 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +080054 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080055 build_params["NS"] == "True" && \
56 build_params["PSA_API"] == "True" && \
57 build_params["ISOLATION_LEVEL"] == "1" && \
58 build_params["TEST_REGRESSION"] == "False" && \
59 build_params["TEST_PSA_API"] == "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +080060 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080061 params += string(name: "PROJ_CONFIG", value: "ConfigCoreIPC")
62 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +080063 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080064 build_params["NS"] == "True" && \
65 build_params["PSA_API"] == "True" && \
66 build_params["ISOLATION_LEVEL"] == "2" && \
67 build_params["TEST_REGRESSION"] == "False" && \
68 build_params["TEST_PSA_API"] == "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +080069 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080070 params += string(name: "PROJ_CONFIG", value: "ConfigCoreIPCTfmLevel2")
71 }
Karl Zhang3b092ef2020-11-06 16:56:25 +080072 else if (build_params["BL2"] == "True" && \
73 build_params["NS"] == "True" && \
74 build_params["PSA_API"] == "True" && \
75 build_params["ISOLATION_LEVEL"] == "3" && \
76 build_params["TEST_REGRESSION"] == "False" && \
77 build_params["TEST_PSA_API"] == "OFF" && \
78 build_params["PROFILE"] == "N.A") {
79 params += string(name: "PROJ_CONFIG", value: "ConfigCoreIPCTfmLevel3")
80 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +080081 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080082 build_params["NS"] == "True" && \
83 build_params["PSA_API"] == "False" && \
84 build_params["ISOLATION_LEVEL"] == "1" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +080085 build_params["PROFILE"] == "profile_small" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080086 build_params["TEST_REGRESSION"] == "False" && \
87 build_params["TEST_PSA_API"] == "OFF") {
88 params += string(name: "PROJ_CONFIG", value: "ConfigDefaultProfileS")
89 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +080090 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080091 build_params["NS"] == "True" && \
Xinyu Zhang9fd74242020-10-22 11:30:50 +080092 build_params["PSA_API"] == "True" && \
93 build_params["ISOLATION_LEVEL"] == "2" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +080094 build_params["PROFILE"] == "profile_medium"&& \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080095 build_params["TEST_REGRESSION"] == "False" && \
96 build_params["TEST_PSA_API"] == "OFF") {
97 params += string(name: "PROJ_CONFIG", value: "ConfigDefaultProfileM")
98 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +080099 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800100 build_params["NS"] == "True" && \
101 build_params["PSA_API"] == "False" && \
102 build_params["ISOLATION_LEVEL"] == "1" && \
103 build_params["TEST_REGRESSION"] == "True" && \
104 build_params["TEST_PSA_API"] == "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800105 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800106 params += string(name: "PROJ_CONFIG", value: "ConfigRegression")
107 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800108 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800109 build_params["NS"] == "True" && \
110 build_params["PSA_API"] == "True" && \
111 build_params["ISOLATION_LEVEL"] == "1" && \
112 build_params["TEST_REGRESSION"] == "True" && \
113 build_params["TEST_PSA_API"] == "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800114 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800115 params += string(name: "PROJ_CONFIG", value: "ConfigRegressionIPC")
116 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800117 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800118 build_params["NS"] == "True" && \
119 build_params["PSA_API"] == "True" && \
120 build_params["ISOLATION_LEVEL"] == "2" && \
121 build_params["TEST_REGRESSION"] == "True" && \
122 build_params["TEST_PSA_API"] == "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800123 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800124 params += string(name: "PROJ_CONFIG", value: "ConfigRegressionIPCTfmLevel2")
125 }
Karl Zhang3b092ef2020-11-06 16:56:25 +0800126 else if (build_params["BL2"] == "True" && \
127 build_params["NS"] == "True" && \
128 build_params["PSA_API"] == "True" && \
129 build_params["ISOLATION_LEVEL"] == "3" && \
130 build_params["TEST_REGRESSION"] == "True" && \
131 build_params["TEST_PSA_API"] == "OFF" && \
132 build_params["PROFILE"] == "N.A") {
133 params += string(name: "PROJ_CONFIG", value: "ConfigRegressionIPCTfmLevel3")
134 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800135 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800136 build_params["NS"] == "True" && \
137 build_params["PSA_API"] == "False" && \
138 build_params["ISOLATION_LEVEL"] == "1" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800139 build_params["PROFILE"] == "profile_small" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800140 build_params["TEST_REGRESSION"] == "True" && \
141 build_params["TEST_PSA_API"] == "OFF") {
142 params += string(name: "PROJ_CONFIG", value: "ConfigRegressionProfileS")
143 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800144 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800145 build_params["NS"] == "True" && \
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800146 build_params["PSA_API"] == "True" && \
147 build_params["ISOLATION_LEVEL"] == "2" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800148 build_params["PROFILE"] == "profile_medium"&& \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800149 build_params["TEST_REGRESSION"] == "True" && \
150 build_params["TEST_PSA_API"] == "OFF") {
151 params += string(name: "PROJ_CONFIG", value: "ConfigRegressionProfileM")
152 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800153 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800154 build_params["NS"] == "True" && \
155 build_params["PSA_API"] == "False" && \
156 build_params["ISOLATION_LEVEL"] == "1" && \
157 build_params["TEST_REGRESSION"] == "False" && \
158 build_params["TEST_PSA_API"] != "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800159 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800160 params += string(name: "PROJ_CONFIG", value: "ConfigPsaApiTest")
161 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800162 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800163 build_params["NS"] == "True" && \
164 build_params["PSA_API"] == "True" && \
165 build_params["ISOLATION_LEVEL"] == "1" && \
166 build_params["TEST_REGRESSION"] == "False" && \
167 build_params["TEST_PSA_API"] != "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800168 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800169 params += string(name: "PROJ_CONFIG", value: "ConfigPsaApiTestIPC")
170 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800171 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800172 build_params["NS"] == "True" && \
173 build_params["PSA_API"] == "True" && \
174 build_params["ISOLATION_LEVEL"] == "2" && \
175 build_params["TEST_REGRESSION"] == "False" && \
176 build_params["TEST_PSA_API"] != "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800177 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800178 params += string(name: "PROJ_CONFIG", value: "ConfigPsaApiTestIPCTfmLevel2")
179 }
Karl Zhang3b092ef2020-11-06 16:56:25 +0800180 else if (build_params["BL2"] == "True" && \
181 build_params["NS"] == "True" && \
182 build_params["PSA_API"] == "True" && \
183 build_params["ISOLATION_LEVEL"] == "3" && \
184 build_params["TEST_REGRESSION"] == "False" && \
185 build_params["TEST_PSA_API"] != "OFF" && \
186 build_params["PROFILE"] == "N.A") {
187 params += string(name: "PROJ_CONFIG", value: "ConfigPsaApiTestIPCTfmLevel3")
188 }
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800189 else {
190 params += string(name: "PROJ_CONFIG", value: "ConfigDefault")
191 }
192 return params
193}
194
Dean Birch62c4f082020-01-17 16:13:26 +0000195def listConfigs(ci_scripts_dir, config_list, filter_group) {
196 dir(ci_scripts_dir) {
197 echo "Obtaining list of configs."
Matthew Hartfb6fd362020-03-04 21:03:59 +0000198 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}"
Dean Birch62c4f082020-01-17 16:13:26 +0000199 def build_config_list_raw = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +0000200python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}
Dean Birch62c4f082020-01-17 16:13:26 +0000201""", returnStdout: true).trim()
202 def build_config_list = build_config_list_raw.tokenize('\n')
203 config_list.addAll(build_config_list)
204 }
205}
206
Matthew Hartfb6fd362020-03-04 21:03:59 +0000207def buildConfig(ci_scripts_dir, config, filter_group, results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000208 def params = []
Matthew Hartfb6fd362020-03-04 21:03:59 +0000209 def params_collection = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000210 def build_config_params
211 dir(ci_scripts_dir) {
212 echo "Obtaining build configuration for config ${config}"
Matthew Hartfb6fd362020-03-04 21:03:59 +0000213 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}"
Dean Birch62c4f082020-01-17 16:13:26 +0000214 build_config_params = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +0000215python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}
Dean Birch62c4f082020-01-17 16:13:26 +0000216""", returnStdout: true).trim()
217 }
218 def lines = build_config_params.tokenize('\n')
219 for (String line : lines) {
220 def key, value
221 (key, value) = line.tokenize('=')
222 params += string(name: key, value: value)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000223 params_collection[key] = value
Dean Birch62c4f082020-01-17 16:13:26 +0000224 }
225 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000226 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
227 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
228 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000229 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800230 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000231 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Karl Zhangf6f467e2020-07-10 16:24:45 +0800232 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000233 return { -> results
234 def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false)
235 def build_info = [build_res, config, params_collection]
236 results['builds'][build_res.number] = build_info
237 def build_url = build_res.getAbsoluteUrl()
238 print("${build_res.number}: ${config} ${build_res.result} ${build_url}")
239 failure_states = ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]
240 if (build_res.result in failure_states) {
241 error("Build failed at ${build_url}")
242 }
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800243 else if (params_collection["NS"] == "False" ||
244 params_collection["PARTITION_PS"] == "OFF") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800245 print("LAVA is not needed for ${build_url}")
246 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000247 else {
248 print("Doing LAVA stuff for ${build_url}")
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800249 params += generateLavaParam(params_collection)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000250 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
251 params += string(name: 'BUILD_URL', value: build_url)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000252 params += string(name: 'LAVA_URL', value: env.LAVA_URL)
Dean Birch956416f2020-08-12 10:36:16 +0100253 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
254 params += string(name: 'LAVA_CREDENTIALS', value: env.LAVA_CREDENTIALS)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000255 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000256 if (lava_res.result in failure_states) {
257 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
258 }
259 else {
260 results['lava_jobs'] += lava_res.getDescription()
261 }
Dean Birch62c4f082020-01-17 16:13:26 +0000262 }
263 }
264}
265
Matthew Hart06340d72020-06-15 16:08:20 +0100266def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000267 def params = []
268 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000269 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
270 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
271 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000272 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800273 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000274 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Matthew Hart06340d72020-06-15 16:08:20 +0100275 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +0000276 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
277 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +0100278 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +0000279 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +0000280 error("Build failed at ${res.getAbsoluteUrl()}")
281 }
282 }
283}
284
Karl Zhang182ecdf2020-10-10 09:52:12 +0800285def emailNotification(results, stage) {
Karl Zhang0413e972020-09-18 17:59:26 +0800286 script {
287 if (env.JOB_NAME.equals("tf-m-nightly") && !env.EMAIL_NOTIFICATION.equals('')) {
288 def result = "Fail."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800289 if (results == true) {
Karl Zhang0413e972020-09-18 17:59:26 +0800290 result = "Success."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800291 print("Skip sending as ${result} for ${stage}")
292 }
293 else {
294 emailext (
295 subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} ${result}"),
296 body: "Check console output at ${env.BUILD_URL}",
297 to: "${EMAIL_NOTIFICATION}"
298 )
299 }
Karl Zhang0413e972020-09-18 17:59:26 +0800300 }
301 } /* script */
302}
303
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800304@NonCPS
305def generateCsvContent(results) {
306 def resultsParam = []
307 results.each { result ->
308 resultsParam.add([result.value[1], \
309 result.value[0].getResult(), \
310 result.value[2]['TARGET_PLATFORM'], \
311 result.value[2]['COMPILER'], \
312 result.value[2]['PROJ_CONFIG'], \
313 result.value[2]['CMAKE_BUILD_TYPE'], \
314 result.value[2]['BL2'], \
315 result.value[2]['PSA_API_SUITE']])
316 }
317 def configs = [] as Set
318 resultsParam.each { result ->
319 if (result[2] == 'MUSCA_B1') {
320 if (result[0].contains('_OTP_')) {
321 result[2] += '_OTP'
322 }
323 }
324 if (result[6] == 'True') {
325 result[6] = 'BL2'
326 }
327 else {
328 result[6] = 'NOBL2'
329 }
330 config = result[4]
331 if (result[7] != "''") {
332 config += ' (' + result[7] + ') '
333 }
334 configs.add(config)
335 result.add(config)
336 }
337 configs.sort()
338 def csvContent = []
339 resultsParam.each { result ->
340 def configExists = false
341 for (csvLine in csvContent) {
342 if (csvLine[0] == result[2] && \
343 csvLine[1] == result[3] && \
344 csvLine[2] == result[5] && \
345 csvLine[3] == result[6]) {
346 csvLine[4][result[8]] = result[1]
347 configExists = true
348 break
349 }
350 }
351 if (!configExists) {
352 csvContent.add([result[2], result[3], result[5], result[6], [:]])
353 csvContent.last()[4][result[8]] = result[1]
354 }
355 }
356 csvContent.sort{a,b -> a[0] <=> b[0] ?: a[1] <=> b[1] ?: a[2] <=> b[2] ?: a[3] <=> b[3]}
357 def csvTable = [['Platform', 'Compiler', 'Cmake Build Type', 'BL2']]
358 csvTable[0] += configs
359 def currentPlatform = ''
360 def currentCompiler = ''
361 def currentBuild = ''
362 csvContent.each { csvLine ->
363 // Modify CSV output format for a better layout
364 if (currentPlatform == csvLine[0]) {
365 csvTable.add([''])
366 }
367 else {
368 csvTable.add([csvLine[0]])
369 currentPlatform = csvLine[0]
370 currentCompiler = ''
371 currentBuild = ''
372 }
373 if (currentCompiler == csvLine[1]) {
374 csvTable.last().add('')
375 }
376 else {
377 csvTable.last().add(csvLine[1])
378 currentCompiler = csvLine[1]
379 currentBuild = ''
380 }
381 if (currentBuild == csvLine[2]) {
382 csvTable.last().add('')
383 }
384 else {
385 csvTable.last().add(csvLine[2])
386 currentBuild = csvLine[2]
387 }
388 csvTable.last().add(csvLine[3])
389 configs.each { config ->
390 if (csvLine[4].containsKey(config)) {
391 csvTable.last().add(csvLine[4][config])
392 }
393 else {
394 csvTable.last().add('N/A')
395 }
396 }
397 }
398 return csvTable
399}
400
401def generateBuildCsv(results) {
402 def csvContent = generateCsvContent(results)
403 node("master") {
404 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
405 archiveArtifacts 'build_results.csv'
406 }
407}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000408
409def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000410 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000411 def csvContent = summary.getBuildCsv(results)
412 node("master") {
413 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
414 archiveArtifacts 'build_results.csv'
415 }
416}
417
418def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000419 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000420 def buildLinks = summary.getLinks(results)
421 node("master") {
422 writeFile file: "build_links.html", text: buildLinks
423 archiveArtifacts 'build_links.html'
424 }
425}
426
Matthew Hartfb6fd362020-03-04 21:03:59 +0000427def lineInString(string, match) {
428 def lines = string.split("\n")
429 def result = lines.findAll { it.contains(match) }
430 return result[0]
431}
432
433def getResult(string, match) {
434 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100435 a = line.split(match)[1].split(' ')
436 score = a[0]
437 if (a.size() > 1)
438 {
439 fail_text = a[1..-1].join(" ")
440 return [score, fail_text]
441 }
442 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000443}
444
445def submitJobsToList(results) {
446 def all_jobs = []
447 for (String result : results){
448 jobs_s = result.split('JOBS: ')
449 if (jobs_s.size() > 1) {
450 all_jobs += jobs_s[1]
451 }
452 }
453 return(all_jobs)
454}
455
Dean Birch62c4f082020-01-17 16:13:26 +0000456def configs = []
457def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000458def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000459
Karl Zhangfec84102020-06-24 09:56:36 +0800460node("docker-amd64-bionic") {
Dean Birch62c4f082020-01-17 16:13:26 +0000461 stage("Init") {
462 cleanWs()
463 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000464 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Birch62c4f082020-01-17 16:13:26 +0000465 }
466 }
467 stage("Configs") {
468 // Populate configs
469 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000470 results['builds'] = [:]
471 results['lava_jobs'] = []
Dean Birch62c4f082020-01-17 16:13:26 +0000472 for (config in configs) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000473 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
Dean Birch62c4f082020-01-17 16:13:26 +0000474 }
Matthew Hart06340d72020-06-15 16:08:20 +0100475 builds["docs"] = buildDocs(results)
Dean Birch62c4f082020-01-17 16:13:26 +0000476 }
477}
Karl Zhangfec84102020-06-24 09:56:36 +0800478
Dean Birch62c4f082020-01-17 16:13:26 +0000479stage("Builds") {
480 def verify = 1
Karl Zhang182ecdf2020-10-10 09:52:12 +0800481 def success = true
Dean Birch62c4f082020-01-17 16:13:26 +0000482 try {
483 parallel(builds)
484 } catch (Exception e) {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000485 print(e)
Dean Birch62c4f082020-01-17 16:13:26 +0000486 manager.buildFailure()
487 verify = -1
Karl Zhang182ecdf2020-10-10 09:52:12 +0800488 success = false
Dean Birch62c4f082020-01-17 16:13:26 +0000489 } finally {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000490 print("Verifying status")
Karl Zhang182ecdf2020-10-10 09:52:12 +0800491 emailNotification(success, 'Build')
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000492 g = new Gerrit()
493 g.verifyStatus(verify, 'tf-m-build', 'build')
Dean Bircha6ede7e2020-03-13 14:00:33 +0000494 print("Building CSV")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800495 generateBuildCsv(results['builds'])
Dean Bircha6ede7e2020-03-13 14:00:33 +0000496 writeSummary(results['builds'])
Dean Birch62c4f082020-01-17 16:13:26 +0000497 }
498}
Matthew Hart06340d72020-06-15 16:08:20 +0100499
Karl Zhangfec84102020-06-24 09:56:36 +0800500node("docker-amd64-bionic") {
Matthew Hart06340d72020-06-15 16:08:20 +0100501 stage("Copy Docs") {
Karl Zhang32497972020-09-21 14:38:29 +0800502 if (env.JOB_NAME.equals("tf-m-build-and-test")) {
503 step([$class: 'CopyArtifact', projectName: 'tf-m-build-docs',
504 selector: specific("${results['docs'][0]}"), target: './docs/',
505 optional: true])
506 archiveArtifacts artifacts: 'docs/**', allowEmptyArchive: true
507 }
508 else {
509 print("No doc copy for job: ${env.JOB_NAME}")
510 }
Matthew Hart06340d72020-06-15 16:08:20 +0100511 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000512 stage("Tests") {
513 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000514 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Bircha6ede7e2020-03-13 14:00:33 +0000515 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000516 def all_jobs = []
517 def success = true
Dean Bircha6ede7e2020-03-13 14:00:33 +0000518 print("Wait for LAVA results here...")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000519 try {
520 all_jobs = submitJobsToList(results['lava_jobs'])
521 if (all_jobs.size() > 0) {
522 dir("tf-m-ci-scripts") {
Dean Birch956416f2020-08-12 10:36:16 +0100523 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000524 output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
525 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
Matthew Hart05a59b52020-05-27 17:54:51 +0100526 --artifacts-path lava_artifacts --lava-timeout 7200 \
Matthew Hartfb6fd362020-03-04 21:03:59 +0000527 """, returnStdout: true).trim()
528 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
529 print(output)
530 g = new Gerrit()
Dean Birch1d545c02020-05-29 14:09:21 +0100531 def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000532 if (boot_result) {
533 g.verifyStatus(boot_result, "lava_boot", "test")
534 }
Dean Birch1d545c02020-05-29 14:09:21 +0100535 def (test_result, test_output) = getResult(output, 'TEST_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000536 if (test_result) {
537 g.verifyStatus(test_result, "lava_test", "test")
538 }
539 if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) {
Dean Birch1d545c02020-05-29 14:09:21 +0100540 error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000541 }
542 }
543 }
544 }
545 else {
546 print("There were no LAVA jobs to test.")
547 }
548 }
549 catch (Exception e) {
550 print("ERROR: ${e}")
551 success = false
552 } finally {
553 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
Karl Zhang182ecdf2020-10-10 09:52:12 +0800554 emailNotification(success, 'Test')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000555 cleanWs()
556 if (!success) {
557 error("There was an Error waiting for LAVA jobs")
558 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000559 }
560 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000561}