blob: dee4fd116d0e42c3f35d76da76bac2ee320e34a5 [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 }
Karl Zhang2b10b342020-11-09 14:50:11 +0800243 else if (params_collection["NS"] == "False" || \
244 (params_collection["PROFILE"] == "profile_medium" && \
245 params_collection["PARTITION_PS"] == "OFF")) {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800246 print("LAVA is not needed for ${build_url}")
247 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000248 else {
249 print("Doing LAVA stuff for ${build_url}")
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800250 params += generateLavaParam(params_collection)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000251 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
252 params += string(name: 'BUILD_URL', value: build_url)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000253 params += string(name: 'LAVA_URL', value: env.LAVA_URL)
Dean Birch956416f2020-08-12 10:36:16 +0100254 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
255 params += string(name: 'LAVA_CREDENTIALS', value: env.LAVA_CREDENTIALS)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000256 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000257 if (lava_res.result in failure_states) {
258 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
259 }
260 else {
261 results['lava_jobs'] += lava_res.getDescription()
262 }
Dean Birch62c4f082020-01-17 16:13:26 +0000263 }
264 }
265}
266
Matthew Hart06340d72020-06-15 16:08:20 +0100267def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000268 def params = []
269 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000270 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
271 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
272 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000273 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800274 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000275 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Matthew Hart06340d72020-06-15 16:08:20 +0100276 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +0000277 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
278 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +0100279 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +0000280 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +0000281 error("Build failed at ${res.getAbsoluteUrl()}")
282 }
283 }
284}
285
Karl Zhang182ecdf2020-10-10 09:52:12 +0800286def emailNotification(results, stage) {
Karl Zhang0413e972020-09-18 17:59:26 +0800287 script {
288 if (env.JOB_NAME.equals("tf-m-nightly") && !env.EMAIL_NOTIFICATION.equals('')) {
289 def result = "Fail."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800290 if (results == true) {
Karl Zhang0413e972020-09-18 17:59:26 +0800291 result = "Success."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800292 print("Skip sending as ${result} for ${stage}")
293 }
294 else {
295 emailext (
296 subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} ${result}"),
297 body: "Check console output at ${env.BUILD_URL}",
298 to: "${EMAIL_NOTIFICATION}"
299 )
300 }
Karl Zhang0413e972020-09-18 17:59:26 +0800301 }
302 } /* script */
303}
304
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800305@NonCPS
306def generateCsvContent(results) {
307 def resultsParam = []
308 results.each { result ->
309 resultsParam.add([result.value[1], \
310 result.value[0].getResult(), \
311 result.value[2]['TARGET_PLATFORM'], \
312 result.value[2]['COMPILER'], \
313 result.value[2]['PROJ_CONFIG'], \
314 result.value[2]['CMAKE_BUILD_TYPE'], \
315 result.value[2]['BL2'], \
316 result.value[2]['PSA_API_SUITE']])
317 }
318 def configs = [] as Set
319 resultsParam.each { result ->
320 if (result[2] == 'MUSCA_B1') {
321 if (result[0].contains('_OTP_')) {
322 result[2] += '_OTP'
323 }
324 }
325 if (result[6] == 'True') {
326 result[6] = 'BL2'
327 }
328 else {
329 result[6] = 'NOBL2'
330 }
331 config = result[4]
332 if (result[7] != "''") {
333 config += ' (' + result[7] + ') '
334 }
335 configs.add(config)
336 result.add(config)
337 }
338 configs.sort()
339 def csvContent = []
340 resultsParam.each { result ->
341 def configExists = false
342 for (csvLine in csvContent) {
343 if (csvLine[0] == result[2] && \
344 csvLine[1] == result[3] && \
345 csvLine[2] == result[5] && \
346 csvLine[3] == result[6]) {
347 csvLine[4][result[8]] = result[1]
348 configExists = true
349 break
350 }
351 }
352 if (!configExists) {
353 csvContent.add([result[2], result[3], result[5], result[6], [:]])
354 csvContent.last()[4][result[8]] = result[1]
355 }
356 }
357 csvContent.sort{a,b -> a[0] <=> b[0] ?: a[1] <=> b[1] ?: a[2] <=> b[2] ?: a[3] <=> b[3]}
358 def csvTable = [['Platform', 'Compiler', 'Cmake Build Type', 'BL2']]
359 csvTable[0] += configs
360 def currentPlatform = ''
361 def currentCompiler = ''
362 def currentBuild = ''
363 csvContent.each { csvLine ->
364 // Modify CSV output format for a better layout
365 if (currentPlatform == csvLine[0]) {
366 csvTable.add([''])
367 }
368 else {
369 csvTable.add([csvLine[0]])
370 currentPlatform = csvLine[0]
371 currentCompiler = ''
372 currentBuild = ''
373 }
374 if (currentCompiler == csvLine[1]) {
375 csvTable.last().add('')
376 }
377 else {
378 csvTable.last().add(csvLine[1])
379 currentCompiler = csvLine[1]
380 currentBuild = ''
381 }
382 if (currentBuild == csvLine[2]) {
383 csvTable.last().add('')
384 }
385 else {
386 csvTable.last().add(csvLine[2])
387 currentBuild = csvLine[2]
388 }
389 csvTable.last().add(csvLine[3])
390 configs.each { config ->
391 if (csvLine[4].containsKey(config)) {
392 csvTable.last().add(csvLine[4][config])
393 }
394 else {
395 csvTable.last().add('N/A')
396 }
397 }
398 }
399 return csvTable
400}
401
402def generateBuildCsv(results) {
403 def csvContent = generateCsvContent(results)
404 node("master") {
405 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
406 archiveArtifacts 'build_results.csv'
407 }
408}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000409
410def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000411 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000412 def csvContent = summary.getBuildCsv(results)
413 node("master") {
414 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
415 archiveArtifacts 'build_results.csv'
416 }
417}
418
419def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000420 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000421 def buildLinks = summary.getLinks(results)
422 node("master") {
423 writeFile file: "build_links.html", text: buildLinks
424 archiveArtifacts 'build_links.html'
425 }
426}
427
Matthew Hartfb6fd362020-03-04 21:03:59 +0000428def lineInString(string, match) {
429 def lines = string.split("\n")
430 def result = lines.findAll { it.contains(match) }
431 return result[0]
432}
433
434def getResult(string, match) {
435 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100436 a = line.split(match)[1].split(' ')
437 score = a[0]
438 if (a.size() > 1)
439 {
440 fail_text = a[1..-1].join(" ")
441 return [score, fail_text]
442 }
443 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000444}
445
446def submitJobsToList(results) {
447 def all_jobs = []
448 for (String result : results){
449 jobs_s = result.split('JOBS: ')
450 if (jobs_s.size() > 1) {
451 all_jobs += jobs_s[1]
452 }
453 }
454 return(all_jobs)
455}
456
Dean Birch62c4f082020-01-17 16:13:26 +0000457def configs = []
458def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000459def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000460
Karl Zhangfec84102020-06-24 09:56:36 +0800461node("docker-amd64-bionic") {
Dean Birch62c4f082020-01-17 16:13:26 +0000462 stage("Init") {
463 cleanWs()
464 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000465 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Birch62c4f082020-01-17 16:13:26 +0000466 }
467 }
468 stage("Configs") {
469 // Populate configs
470 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000471 results['builds'] = [:]
472 results['lava_jobs'] = []
Dean Birch62c4f082020-01-17 16:13:26 +0000473 for (config in configs) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000474 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
Dean Birch62c4f082020-01-17 16:13:26 +0000475 }
Matthew Hart06340d72020-06-15 16:08:20 +0100476 builds["docs"] = buildDocs(results)
Dean Birch62c4f082020-01-17 16:13:26 +0000477 }
478}
Karl Zhangfec84102020-06-24 09:56:36 +0800479
Dean Birch62c4f082020-01-17 16:13:26 +0000480stage("Builds") {
481 def verify = 1
Karl Zhang182ecdf2020-10-10 09:52:12 +0800482 def success = true
Dean Birch62c4f082020-01-17 16:13:26 +0000483 try {
484 parallel(builds)
485 } catch (Exception e) {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000486 print(e)
Dean Birch62c4f082020-01-17 16:13:26 +0000487 manager.buildFailure()
488 verify = -1
Karl Zhang182ecdf2020-10-10 09:52:12 +0800489 success = false
Dean Birch62c4f082020-01-17 16:13:26 +0000490 } finally {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000491 print("Verifying status")
Karl Zhang182ecdf2020-10-10 09:52:12 +0800492 emailNotification(success, 'Build')
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000493 g = new Gerrit()
494 g.verifyStatus(verify, 'tf-m-build', 'build')
Dean Bircha6ede7e2020-03-13 14:00:33 +0000495 print("Building CSV")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800496 generateBuildCsv(results['builds'])
Dean Bircha6ede7e2020-03-13 14:00:33 +0000497 writeSummary(results['builds'])
Dean Birch62c4f082020-01-17 16:13:26 +0000498 }
499}
Matthew Hart06340d72020-06-15 16:08:20 +0100500
Karl Zhangfec84102020-06-24 09:56:36 +0800501node("docker-amd64-bionic") {
Matthew Hart06340d72020-06-15 16:08:20 +0100502 stage("Copy Docs") {
Karl Zhang32497972020-09-21 14:38:29 +0800503 if (env.JOB_NAME.equals("tf-m-build-and-test")) {
504 step([$class: 'CopyArtifact', projectName: 'tf-m-build-docs',
505 selector: specific("${results['docs'][0]}"), target: './docs/',
506 optional: true])
507 archiveArtifacts artifacts: 'docs/**', allowEmptyArchive: true
508 }
509 else {
510 print("No doc copy for job: ${env.JOB_NAME}")
511 }
Matthew Hart06340d72020-06-15 16:08:20 +0100512 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000513 stage("Tests") {
514 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000515 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Bircha6ede7e2020-03-13 14:00:33 +0000516 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000517 def all_jobs = []
518 def success = true
Dean Bircha6ede7e2020-03-13 14:00:33 +0000519 print("Wait for LAVA results here...")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000520 try {
521 all_jobs = submitJobsToList(results['lava_jobs'])
522 if (all_jobs.size() > 0) {
523 dir("tf-m-ci-scripts") {
Dean Birch956416f2020-08-12 10:36:16 +0100524 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000525 output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
526 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
Matthew Hart05a59b52020-05-27 17:54:51 +0100527 --artifacts-path lava_artifacts --lava-timeout 7200 \
Matthew Hartfb6fd362020-03-04 21:03:59 +0000528 """, returnStdout: true).trim()
529 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
530 print(output)
531 g = new Gerrit()
Dean Birch1d545c02020-05-29 14:09:21 +0100532 def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000533 if (boot_result) {
534 g.verifyStatus(boot_result, "lava_boot", "test")
535 }
Dean Birch1d545c02020-05-29 14:09:21 +0100536 def (test_result, test_output) = getResult(output, 'TEST_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000537 if (test_result) {
538 g.verifyStatus(test_result, "lava_test", "test")
539 }
540 if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) {
Dean Birch1d545c02020-05-29 14:09:21 +0100541 error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000542 }
543 }
544 }
545 }
546 else {
547 print("There were no LAVA jobs to test.")
548 }
549 }
550 catch (Exception e) {
551 print("ERROR: ${e}")
552 success = false
553 } finally {
554 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
Karl Zhang182ecdf2020-10-10 09:52:12 +0800555 emailNotification(success, 'Test')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000556 cleanWs()
557 if (!success) {
558 error("There was an Error waiting for LAVA jobs")
559 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000560 }
561 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000562}