blob: 3504d1b96a0a3d3b7dae70b9481428bb33bdd4c6 [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 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +080072 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080073 build_params["NS"] == "True" && \
74 build_params["PSA_API"] == "False" && \
75 build_params["ISOLATION_LEVEL"] == "1" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +080076 build_params["PROFILE"] == "profile_small" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080077 build_params["TEST_REGRESSION"] == "False" && \
78 build_params["TEST_PSA_API"] == "OFF") {
79 params += string(name: "PROJ_CONFIG", value: "ConfigDefaultProfileS")
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_medium"&& \
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: "ConfigDefaultProfileM")
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" && \
92 build_params["PSA_API"] == "False" && \
93 build_params["ISOLATION_LEVEL"] == "1" && \
94 build_params["TEST_REGRESSION"] == "True" && \
95 build_params["TEST_PSA_API"] == "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +080096 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080097 params += string(name: "PROJ_CONFIG", value: "ConfigRegression")
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"] == "True" && \
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: "ConfigRegressionIPC")
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"] == "2" && \
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: "ConfigRegressionIPCTfmLevel2")
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"] == "False" && \
120 build_params["ISOLATION_LEVEL"] == "1" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800121 build_params["PROFILE"] == "profile_small" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800122 build_params["TEST_REGRESSION"] == "True" && \
123 build_params["TEST_PSA_API"] == "OFF") {
124 params += string(name: "PROJ_CONFIG", value: "ConfigRegressionProfileS")
125 }
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800126 else if (build_params["BL2"] == "True" && \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800127 build_params["NS"] == "True" && \
128 build_params["PSA_API"] == "False" && \
129 build_params["ISOLATION_LEVEL"] == "1" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800130 build_params["PROFILE"] == "profile_medium"&& \
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800131 build_params["TEST_REGRESSION"] == "True" && \
132 build_params["TEST_PSA_API"] == "OFF") {
133 params += string(name: "PROJ_CONFIG", value: "ConfigRegressionProfileM")
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" && \
139 build_params["TEST_REGRESSION"] == "False" && \
140 build_params["TEST_PSA_API"] != "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800141 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800142 params += string(name: "PROJ_CONFIG", value: "ConfigPsaApiTest")
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" && \
146 build_params["PSA_API"] == "True" && \
147 build_params["ISOLATION_LEVEL"] == "1" && \
148 build_params["TEST_REGRESSION"] == "False" && \
149 build_params["TEST_PSA_API"] != "OFF" && \
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800150 build_params["PROFILE"] == "N.A") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800151 params += string(name: "PROJ_CONFIG", value: "ConfigPsaApiTestIPC")
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"] == "True" && \
156 build_params["ISOLATION_LEVEL"] == "2" && \
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: "ConfigPsaApiTestIPCTfmLevel2")
161 }
162 else {
163 params += string(name: "PROJ_CONFIG", value: "ConfigDefault")
164 }
165 return params
166}
167
Dean Birch62c4f082020-01-17 16:13:26 +0000168def listConfigs(ci_scripts_dir, config_list, filter_group) {
169 dir(ci_scripts_dir) {
170 echo "Obtaining list of configs."
Matthew Hartfb6fd362020-03-04 21:03:59 +0000171 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}"
Dean Birch62c4f082020-01-17 16:13:26 +0000172 def build_config_list_raw = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +0000173python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}
Dean Birch62c4f082020-01-17 16:13:26 +0000174""", returnStdout: true).trim()
175 def build_config_list = build_config_list_raw.tokenize('\n')
176 config_list.addAll(build_config_list)
177 }
178}
179
Matthew Hartfb6fd362020-03-04 21:03:59 +0000180def buildConfig(ci_scripts_dir, config, filter_group, results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000181 def params = []
Matthew Hartfb6fd362020-03-04 21:03:59 +0000182 def params_collection = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000183 def build_config_params
184 dir(ci_scripts_dir) {
185 echo "Obtaining build configuration for config ${config}"
Matthew Hartfb6fd362020-03-04 21:03:59 +0000186 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}"
Dean Birch62c4f082020-01-17 16:13:26 +0000187 build_config_params = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +0000188python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}
Dean Birch62c4f082020-01-17 16:13:26 +0000189""", returnStdout: true).trim()
190 }
191 def lines = build_config_params.tokenize('\n')
192 for (String line : lines) {
193 def key, value
194 (key, value) = line.tokenize('=')
195 params += string(name: key, value: value)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000196 params_collection[key] = value
Dean Birch62c4f082020-01-17 16:13:26 +0000197 }
198 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000199 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
200 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
201 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000202 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800203 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000204 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Karl Zhangf6f467e2020-07-10 16:24:45 +0800205 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000206 return { -> results
207 def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false)
208 def build_info = [build_res, config, params_collection]
209 results['builds'][build_res.number] = build_info
210 def build_url = build_res.getAbsoluteUrl()
211 print("${build_res.number}: ${config} ${build_res.result} ${build_url}")
212 failure_states = ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]
213 if (build_res.result in failure_states) {
214 error("Build failed at ${build_url}")
215 }
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800216 else if (params_collection["NS"] == "False") {
217 print("LAVA is not needed for ${build_url}")
218 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000219 else {
220 print("Doing LAVA stuff for ${build_url}")
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800221 params += generateLavaParam(params_collection)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000222 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
223 params += string(name: 'BUILD_URL', value: build_url)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000224 params += string(name: 'LAVA_URL', value: env.LAVA_URL)
Dean Birch956416f2020-08-12 10:36:16 +0100225 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
226 params += string(name: 'LAVA_CREDENTIALS', value: env.LAVA_CREDENTIALS)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000227 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000228 if (lava_res.result in failure_states) {
229 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
230 }
231 else {
232 results['lava_jobs'] += lava_res.getDescription()
233 }
Dean Birch62c4f082020-01-17 16:13:26 +0000234 }
235 }
236}
237
Matthew Hart06340d72020-06-15 16:08:20 +0100238def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000239 def params = []
240 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000241 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
242 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
243 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000244 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800245 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000246 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Matthew Hart06340d72020-06-15 16:08:20 +0100247 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +0000248 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
249 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +0100250 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +0000251 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +0000252 error("Build failed at ${res.getAbsoluteUrl()}")
253 }
254 }
255}
256
Karl Zhang182ecdf2020-10-10 09:52:12 +0800257def emailNotification(results, stage) {
Karl Zhang0413e972020-09-18 17:59:26 +0800258 script {
259 if (env.JOB_NAME.equals("tf-m-nightly") && !env.EMAIL_NOTIFICATION.equals('')) {
260 def result = "Fail."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800261 if (results == true) {
Karl Zhang0413e972020-09-18 17:59:26 +0800262 result = "Success."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800263 print("Skip sending as ${result} for ${stage}")
264 }
265 else {
266 emailext (
267 subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} ${result}"),
268 body: "Check console output at ${env.BUILD_URL}",
269 to: "${EMAIL_NOTIFICATION}"
270 )
271 }
Karl Zhang0413e972020-09-18 17:59:26 +0800272 }
273 } /* script */
274}
275
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800276@NonCPS
277def generateCsvContent(results) {
278 def resultsParam = []
279 results.each { result ->
280 resultsParam.add([result.value[1], \
281 result.value[0].getResult(), \
282 result.value[2]['TARGET_PLATFORM'], \
283 result.value[2]['COMPILER'], \
284 result.value[2]['PROJ_CONFIG'], \
285 result.value[2]['CMAKE_BUILD_TYPE'], \
286 result.value[2]['BL2'], \
287 result.value[2]['PSA_API_SUITE']])
288 }
289 def configs = [] as Set
290 resultsParam.each { result ->
291 if (result[2] == 'MUSCA_B1') {
292 if (result[0].contains('_OTP_')) {
293 result[2] += '_OTP'
294 }
295 }
296 if (result[6] == 'True') {
297 result[6] = 'BL2'
298 }
299 else {
300 result[6] = 'NOBL2'
301 }
302 config = result[4]
303 if (result[7] != "''") {
304 config += ' (' + result[7] + ') '
305 }
306 configs.add(config)
307 result.add(config)
308 }
309 configs.sort()
310 def csvContent = []
311 resultsParam.each { result ->
312 def configExists = false
313 for (csvLine in csvContent) {
314 if (csvLine[0] == result[2] && \
315 csvLine[1] == result[3] && \
316 csvLine[2] == result[5] && \
317 csvLine[3] == result[6]) {
318 csvLine[4][result[8]] = result[1]
319 configExists = true
320 break
321 }
322 }
323 if (!configExists) {
324 csvContent.add([result[2], result[3], result[5], result[6], [:]])
325 csvContent.last()[4][result[8]] = result[1]
326 }
327 }
328 csvContent.sort{a,b -> a[0] <=> b[0] ?: a[1] <=> b[1] ?: a[2] <=> b[2] ?: a[3] <=> b[3]}
329 def csvTable = [['Platform', 'Compiler', 'Cmake Build Type', 'BL2']]
330 csvTable[0] += configs
331 def currentPlatform = ''
332 def currentCompiler = ''
333 def currentBuild = ''
334 csvContent.each { csvLine ->
335 // Modify CSV output format for a better layout
336 if (currentPlatform == csvLine[0]) {
337 csvTable.add([''])
338 }
339 else {
340 csvTable.add([csvLine[0]])
341 currentPlatform = csvLine[0]
342 currentCompiler = ''
343 currentBuild = ''
344 }
345 if (currentCompiler == csvLine[1]) {
346 csvTable.last().add('')
347 }
348 else {
349 csvTable.last().add(csvLine[1])
350 currentCompiler = csvLine[1]
351 currentBuild = ''
352 }
353 if (currentBuild == csvLine[2]) {
354 csvTable.last().add('')
355 }
356 else {
357 csvTable.last().add(csvLine[2])
358 currentBuild = csvLine[2]
359 }
360 csvTable.last().add(csvLine[3])
361 configs.each { config ->
362 if (csvLine[4].containsKey(config)) {
363 csvTable.last().add(csvLine[4][config])
364 }
365 else {
366 csvTable.last().add('N/A')
367 }
368 }
369 }
370 return csvTable
371}
372
373def generateBuildCsv(results) {
374 def csvContent = generateCsvContent(results)
375 node("master") {
376 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
377 archiveArtifacts 'build_results.csv'
378 }
379}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000380
381def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000382 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000383 def csvContent = summary.getBuildCsv(results)
384 node("master") {
385 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
386 archiveArtifacts 'build_results.csv'
387 }
388}
389
390def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000391 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000392 def buildLinks = summary.getLinks(results)
393 node("master") {
394 writeFile file: "build_links.html", text: buildLinks
395 archiveArtifacts 'build_links.html'
396 }
397}
398
Matthew Hartfb6fd362020-03-04 21:03:59 +0000399def lineInString(string, match) {
400 def lines = string.split("\n")
401 def result = lines.findAll { it.contains(match) }
402 return result[0]
403}
404
405def getResult(string, match) {
406 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100407 a = line.split(match)[1].split(' ')
408 score = a[0]
409 if (a.size() > 1)
410 {
411 fail_text = a[1..-1].join(" ")
412 return [score, fail_text]
413 }
414 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000415}
416
417def submitJobsToList(results) {
418 def all_jobs = []
419 for (String result : results){
420 jobs_s = result.split('JOBS: ')
421 if (jobs_s.size() > 1) {
422 all_jobs += jobs_s[1]
423 }
424 }
425 return(all_jobs)
426}
427
Dean Birch62c4f082020-01-17 16:13:26 +0000428def configs = []
429def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000430def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000431
Karl Zhangfec84102020-06-24 09:56:36 +0800432node("docker-amd64-bionic") {
Dean Birch62c4f082020-01-17 16:13:26 +0000433 stage("Init") {
434 cleanWs()
435 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000436 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Birch62c4f082020-01-17 16:13:26 +0000437 }
438 }
439 stage("Configs") {
440 // Populate configs
441 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000442 results['builds'] = [:]
443 results['lava_jobs'] = []
Dean Birch62c4f082020-01-17 16:13:26 +0000444 for (config in configs) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000445 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
Dean Birch62c4f082020-01-17 16:13:26 +0000446 }
Matthew Hart06340d72020-06-15 16:08:20 +0100447 builds["docs"] = buildDocs(results)
Dean Birch62c4f082020-01-17 16:13:26 +0000448 }
449}
Karl Zhangfec84102020-06-24 09:56:36 +0800450
Dean Birch62c4f082020-01-17 16:13:26 +0000451stage("Builds") {
452 def verify = 1
Karl Zhang182ecdf2020-10-10 09:52:12 +0800453 def success = true
Dean Birch62c4f082020-01-17 16:13:26 +0000454 try {
455 parallel(builds)
456 } catch (Exception e) {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000457 print(e)
Dean Birch62c4f082020-01-17 16:13:26 +0000458 manager.buildFailure()
459 verify = -1
Karl Zhang182ecdf2020-10-10 09:52:12 +0800460 success = false
Dean Birch62c4f082020-01-17 16:13:26 +0000461 } finally {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000462 print("Verifying status")
Karl Zhang182ecdf2020-10-10 09:52:12 +0800463 emailNotification(success, 'Build')
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000464 g = new Gerrit()
465 g.verifyStatus(verify, 'tf-m-build', 'build')
Dean Bircha6ede7e2020-03-13 14:00:33 +0000466 print("Building CSV")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800467 generateBuildCsv(results['builds'])
Dean Bircha6ede7e2020-03-13 14:00:33 +0000468 writeSummary(results['builds'])
Dean Birch62c4f082020-01-17 16:13:26 +0000469 }
470}
Matthew Hart06340d72020-06-15 16:08:20 +0100471
Karl Zhangfec84102020-06-24 09:56:36 +0800472node("docker-amd64-bionic") {
Matthew Hart06340d72020-06-15 16:08:20 +0100473 stage("Copy Docs") {
Karl Zhang32497972020-09-21 14:38:29 +0800474 if (env.JOB_NAME.equals("tf-m-build-and-test")) {
475 step([$class: 'CopyArtifact', projectName: 'tf-m-build-docs',
476 selector: specific("${results['docs'][0]}"), target: './docs/',
477 optional: true])
478 archiveArtifacts artifacts: 'docs/**', allowEmptyArchive: true
479 }
480 else {
481 print("No doc copy for job: ${env.JOB_NAME}")
482 }
Matthew Hart06340d72020-06-15 16:08:20 +0100483 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000484 stage("Tests") {
485 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000486 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Bircha6ede7e2020-03-13 14:00:33 +0000487 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000488 def all_jobs = []
489 def success = true
Dean Bircha6ede7e2020-03-13 14:00:33 +0000490 print("Wait for LAVA results here...")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000491 try {
492 all_jobs = submitJobsToList(results['lava_jobs'])
493 if (all_jobs.size() > 0) {
494 dir("tf-m-ci-scripts") {
Dean Birch956416f2020-08-12 10:36:16 +0100495 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000496 output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
497 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
Matthew Hart05a59b52020-05-27 17:54:51 +0100498 --artifacts-path lava_artifacts --lava-timeout 7200 \
Matthew Hartfb6fd362020-03-04 21:03:59 +0000499 """, returnStdout: true).trim()
500 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
501 print(output)
502 g = new Gerrit()
Dean Birch1d545c02020-05-29 14:09:21 +0100503 def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000504 if (boot_result) {
505 g.verifyStatus(boot_result, "lava_boot", "test")
506 }
Dean Birch1d545c02020-05-29 14:09:21 +0100507 def (test_result, test_output) = getResult(output, 'TEST_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000508 if (test_result) {
509 g.verifyStatus(test_result, "lava_test", "test")
510 }
511 if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) {
Dean Birch1d545c02020-05-29 14:09:21 +0100512 error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000513 }
514 }
515 }
516 }
517 else {
518 print("There were no LAVA jobs to test.")
519 }
520 }
521 catch (Exception e) {
522 print("ERROR: ${e}")
523 success = false
524 } finally {
525 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
Karl Zhang182ecdf2020-10-10 09:52:12 +0800526 emailNotification(success, 'Test')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000527 cleanWs()
528 if (!success) {
529 error("There was an Error waiting for LAVA jobs")
530 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000531 }
532 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000533}