blob: fbb77266bb0d8b32df4ef5e8718942b885a7aae8 [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" && \
Xinyu Zhang9fd74242020-10-22 11:30:50 +080083 build_params["PSA_API"] == "True" && \
84 build_params["ISOLATION_LEVEL"] == "2" && \
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" && \
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800128 build_params["PSA_API"] == "True" && \
129 build_params["ISOLATION_LEVEL"] == "2" && \
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 Zhang9fd74242020-10-22 11:30:50 +0800216 else if (params_collection["NS"] == "False" ||
217 params_collection["PARTITION_PS"] == "OFF") {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800218 print("LAVA is not needed for ${build_url}")
219 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000220 else {
221 print("Doing LAVA stuff for ${build_url}")
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800222 params += generateLavaParam(params_collection)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000223 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
224 params += string(name: 'BUILD_URL', value: build_url)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000225 params += string(name: 'LAVA_URL', value: env.LAVA_URL)
Dean Birch956416f2020-08-12 10:36:16 +0100226 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
227 params += string(name: 'LAVA_CREDENTIALS', value: env.LAVA_CREDENTIALS)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000228 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000229 if (lava_res.result in failure_states) {
230 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
231 }
232 else {
233 results['lava_jobs'] += lava_res.getDescription()
234 }
Dean Birch62c4f082020-01-17 16:13:26 +0000235 }
236 }
237}
238
Matthew Hart06340d72020-06-15 16:08:20 +0100239def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000240 def params = []
241 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000242 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
243 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
244 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000245 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800246 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000247 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Matthew Hart06340d72020-06-15 16:08:20 +0100248 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +0000249 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
250 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +0100251 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +0000252 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +0000253 error("Build failed at ${res.getAbsoluteUrl()}")
254 }
255 }
256}
257
Karl Zhang182ecdf2020-10-10 09:52:12 +0800258def emailNotification(results, stage) {
Karl Zhang0413e972020-09-18 17:59:26 +0800259 script {
260 if (env.JOB_NAME.equals("tf-m-nightly") && !env.EMAIL_NOTIFICATION.equals('')) {
261 def result = "Fail."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800262 if (results == true) {
Karl Zhang0413e972020-09-18 17:59:26 +0800263 result = "Success."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800264 print("Skip sending as ${result} for ${stage}")
265 }
266 else {
267 emailext (
268 subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} ${result}"),
269 body: "Check console output at ${env.BUILD_URL}",
270 to: "${EMAIL_NOTIFICATION}"
271 )
272 }
Karl Zhang0413e972020-09-18 17:59:26 +0800273 }
274 } /* script */
275}
276
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800277@NonCPS
278def generateCsvContent(results) {
279 def resultsParam = []
280 results.each { result ->
281 resultsParam.add([result.value[1], \
282 result.value[0].getResult(), \
283 result.value[2]['TARGET_PLATFORM'], \
284 result.value[2]['COMPILER'], \
285 result.value[2]['PROJ_CONFIG'], \
286 result.value[2]['CMAKE_BUILD_TYPE'], \
287 result.value[2]['BL2'], \
288 result.value[2]['PSA_API_SUITE']])
289 }
290 def configs = [] as Set
291 resultsParam.each { result ->
292 if (result[2] == 'MUSCA_B1') {
293 if (result[0].contains('_OTP_')) {
294 result[2] += '_OTP'
295 }
296 }
297 if (result[6] == 'True') {
298 result[6] = 'BL2'
299 }
300 else {
301 result[6] = 'NOBL2'
302 }
303 config = result[4]
304 if (result[7] != "''") {
305 config += ' (' + result[7] + ') '
306 }
307 configs.add(config)
308 result.add(config)
309 }
310 configs.sort()
311 def csvContent = []
312 resultsParam.each { result ->
313 def configExists = false
314 for (csvLine in csvContent) {
315 if (csvLine[0] == result[2] && \
316 csvLine[1] == result[3] && \
317 csvLine[2] == result[5] && \
318 csvLine[3] == result[6]) {
319 csvLine[4][result[8]] = result[1]
320 configExists = true
321 break
322 }
323 }
324 if (!configExists) {
325 csvContent.add([result[2], result[3], result[5], result[6], [:]])
326 csvContent.last()[4][result[8]] = result[1]
327 }
328 }
329 csvContent.sort{a,b -> a[0] <=> b[0] ?: a[1] <=> b[1] ?: a[2] <=> b[2] ?: a[3] <=> b[3]}
330 def csvTable = [['Platform', 'Compiler', 'Cmake Build Type', 'BL2']]
331 csvTable[0] += configs
332 def currentPlatform = ''
333 def currentCompiler = ''
334 def currentBuild = ''
335 csvContent.each { csvLine ->
336 // Modify CSV output format for a better layout
337 if (currentPlatform == csvLine[0]) {
338 csvTable.add([''])
339 }
340 else {
341 csvTable.add([csvLine[0]])
342 currentPlatform = csvLine[0]
343 currentCompiler = ''
344 currentBuild = ''
345 }
346 if (currentCompiler == csvLine[1]) {
347 csvTable.last().add('')
348 }
349 else {
350 csvTable.last().add(csvLine[1])
351 currentCompiler = csvLine[1]
352 currentBuild = ''
353 }
354 if (currentBuild == csvLine[2]) {
355 csvTable.last().add('')
356 }
357 else {
358 csvTable.last().add(csvLine[2])
359 currentBuild = csvLine[2]
360 }
361 csvTable.last().add(csvLine[3])
362 configs.each { config ->
363 if (csvLine[4].containsKey(config)) {
364 csvTable.last().add(csvLine[4][config])
365 }
366 else {
367 csvTable.last().add('N/A')
368 }
369 }
370 }
371 return csvTable
372}
373
374def generateBuildCsv(results) {
375 def csvContent = generateCsvContent(results)
376 node("master") {
377 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
378 archiveArtifacts 'build_results.csv'
379 }
380}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000381
382def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000383 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000384 def csvContent = summary.getBuildCsv(results)
385 node("master") {
386 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
387 archiveArtifacts 'build_results.csv'
388 }
389}
390
391def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000392 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000393 def buildLinks = summary.getLinks(results)
394 node("master") {
395 writeFile file: "build_links.html", text: buildLinks
396 archiveArtifacts 'build_links.html'
397 }
398}
399
Matthew Hartfb6fd362020-03-04 21:03:59 +0000400def lineInString(string, match) {
401 def lines = string.split("\n")
402 def result = lines.findAll { it.contains(match) }
403 return result[0]
404}
405
406def getResult(string, match) {
407 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100408 a = line.split(match)[1].split(' ')
409 score = a[0]
410 if (a.size() > 1)
411 {
412 fail_text = a[1..-1].join(" ")
413 return [score, fail_text]
414 }
415 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000416}
417
418def submitJobsToList(results) {
419 def all_jobs = []
420 for (String result : results){
421 jobs_s = result.split('JOBS: ')
422 if (jobs_s.size() > 1) {
423 all_jobs += jobs_s[1]
424 }
425 }
426 return(all_jobs)
427}
428
Dean Birch62c4f082020-01-17 16:13:26 +0000429def configs = []
430def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000431def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000432
Karl Zhangfec84102020-06-24 09:56:36 +0800433node("docker-amd64-bionic") {
Dean Birch62c4f082020-01-17 16:13:26 +0000434 stage("Init") {
435 cleanWs()
436 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000437 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Birch62c4f082020-01-17 16:13:26 +0000438 }
439 }
440 stage("Configs") {
441 // Populate configs
442 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000443 results['builds'] = [:]
444 results['lava_jobs'] = []
Dean Birch62c4f082020-01-17 16:13:26 +0000445 for (config in configs) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000446 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
Dean Birch62c4f082020-01-17 16:13:26 +0000447 }
Matthew Hart06340d72020-06-15 16:08:20 +0100448 builds["docs"] = buildDocs(results)
Dean Birch62c4f082020-01-17 16:13:26 +0000449 }
450}
Karl Zhangfec84102020-06-24 09:56:36 +0800451
Dean Birch62c4f082020-01-17 16:13:26 +0000452stage("Builds") {
453 def verify = 1
Karl Zhang182ecdf2020-10-10 09:52:12 +0800454 def success = true
Dean Birch62c4f082020-01-17 16:13:26 +0000455 try {
456 parallel(builds)
457 } catch (Exception e) {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000458 print(e)
Dean Birch62c4f082020-01-17 16:13:26 +0000459 manager.buildFailure()
460 verify = -1
Karl Zhang182ecdf2020-10-10 09:52:12 +0800461 success = false
Dean Birch62c4f082020-01-17 16:13:26 +0000462 } finally {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000463 print("Verifying status")
Karl Zhang182ecdf2020-10-10 09:52:12 +0800464 emailNotification(success, 'Build')
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000465 g = new Gerrit()
466 g.verifyStatus(verify, 'tf-m-build', 'build')
Dean Bircha6ede7e2020-03-13 14:00:33 +0000467 print("Building CSV")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800468 generateBuildCsv(results['builds'])
Dean Bircha6ede7e2020-03-13 14:00:33 +0000469 writeSummary(results['builds'])
Dean Birch62c4f082020-01-17 16:13:26 +0000470 }
471}
Matthew Hart06340d72020-06-15 16:08:20 +0100472
Karl Zhangfec84102020-06-24 09:56:36 +0800473node("docker-amd64-bionic") {
Matthew Hart06340d72020-06-15 16:08:20 +0100474 stage("Copy Docs") {
Karl Zhang32497972020-09-21 14:38:29 +0800475 if (env.JOB_NAME.equals("tf-m-build-and-test")) {
476 step([$class: 'CopyArtifact', projectName: 'tf-m-build-docs',
477 selector: specific("${results['docs'][0]}"), target: './docs/',
478 optional: true])
479 archiveArtifacts artifacts: 'docs/**', allowEmptyArchive: true
480 }
481 else {
482 print("No doc copy for job: ${env.JOB_NAME}")
483 }
Matthew Hart06340d72020-06-15 16:08:20 +0100484 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000485 stage("Tests") {
486 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000487 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Bircha6ede7e2020-03-13 14:00:33 +0000488 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000489 def all_jobs = []
490 def success = true
Dean Bircha6ede7e2020-03-13 14:00:33 +0000491 print("Wait for LAVA results here...")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000492 try {
493 all_jobs = submitJobsToList(results['lava_jobs'])
494 if (all_jobs.size() > 0) {
495 dir("tf-m-ci-scripts") {
Dean Birch956416f2020-08-12 10:36:16 +0100496 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000497 output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
498 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
Matthew Hart05a59b52020-05-27 17:54:51 +0100499 --artifacts-path lava_artifacts --lava-timeout 7200 \
Matthew Hartfb6fd362020-03-04 21:03:59 +0000500 """, returnStdout: true).trim()
501 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
502 print(output)
503 g = new Gerrit()
Dean Birch1d545c02020-05-29 14:09:21 +0100504 def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000505 if (boot_result) {
506 g.verifyStatus(boot_result, "lava_boot", "test")
507 }
Dean Birch1d545c02020-05-29 14:09:21 +0100508 def (test_result, test_output) = getResult(output, 'TEST_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000509 if (test_result) {
510 g.verifyStatus(test_result, "lava_test", "test")
511 }
512 if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) {
Dean Birch1d545c02020-05-29 14:09:21 +0100513 error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000514 }
515 }
516 }
517 }
518 else {
519 print("There were no LAVA jobs to test.")
520 }
521 }
522 catch (Exception e) {
523 print("ERROR: ${e}")
524 success = false
525 } finally {
526 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
Karl Zhang182ecdf2020-10-10 09:52:12 +0800527 emailNotification(success, 'Test')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000528 cleanWs()
529 if (!success) {
530 error("There was an Error waiting for LAVA jobs")
531 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000532 }
533 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000534}