blob: 7f36282011f52a47b71236e6c53a084dc1f5790f [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 Zhang0413e972020-09-18 17:59:26 +0800257def emailNotification(results) {
258 script {
259 if (env.JOB_NAME.equals("tf-m-nightly") && !env.EMAIL_NOTIFICATION.equals('')) {
260 def result = "Fail."
261 if (results)
262 result = "Success."
263 emailext (
264 subject: ("Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} ${result}"),
265 body: "Check console output at ${env.BUILD_URL}",
266 to: "${EMAIL_NOTIFICATION}"
267 )
268 }
269 } /* script */
270}
271
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800272@NonCPS
273def generateCsvContent(results) {
274 def resultsParam = []
275 results.each { result ->
276 resultsParam.add([result.value[1], \
277 result.value[0].getResult(), \
278 result.value[2]['TARGET_PLATFORM'], \
279 result.value[2]['COMPILER'], \
280 result.value[2]['PROJ_CONFIG'], \
281 result.value[2]['CMAKE_BUILD_TYPE'], \
282 result.value[2]['BL2'], \
283 result.value[2]['PSA_API_SUITE']])
284 }
285 def configs = [] as Set
286 resultsParam.each { result ->
287 if (result[2] == 'MUSCA_B1') {
288 if (result[0].contains('_OTP_')) {
289 result[2] += '_OTP'
290 }
291 }
292 if (result[6] == 'True') {
293 result[6] = 'BL2'
294 }
295 else {
296 result[6] = 'NOBL2'
297 }
298 config = result[4]
299 if (result[7] != "''") {
300 config += ' (' + result[7] + ') '
301 }
302 configs.add(config)
303 result.add(config)
304 }
305 configs.sort()
306 def csvContent = []
307 resultsParam.each { result ->
308 def configExists = false
309 for (csvLine in csvContent) {
310 if (csvLine[0] == result[2] && \
311 csvLine[1] == result[3] && \
312 csvLine[2] == result[5] && \
313 csvLine[3] == result[6]) {
314 csvLine[4][result[8]] = result[1]
315 configExists = true
316 break
317 }
318 }
319 if (!configExists) {
320 csvContent.add([result[2], result[3], result[5], result[6], [:]])
321 csvContent.last()[4][result[8]] = result[1]
322 }
323 }
324 csvContent.sort{a,b -> a[0] <=> b[0] ?: a[1] <=> b[1] ?: a[2] <=> b[2] ?: a[3] <=> b[3]}
325 def csvTable = [['Platform', 'Compiler', 'Cmake Build Type', 'BL2']]
326 csvTable[0] += configs
327 def currentPlatform = ''
328 def currentCompiler = ''
329 def currentBuild = ''
330 csvContent.each { csvLine ->
331 // Modify CSV output format for a better layout
332 if (currentPlatform == csvLine[0]) {
333 csvTable.add([''])
334 }
335 else {
336 csvTable.add([csvLine[0]])
337 currentPlatform = csvLine[0]
338 currentCompiler = ''
339 currentBuild = ''
340 }
341 if (currentCompiler == csvLine[1]) {
342 csvTable.last().add('')
343 }
344 else {
345 csvTable.last().add(csvLine[1])
346 currentCompiler = csvLine[1]
347 currentBuild = ''
348 }
349 if (currentBuild == csvLine[2]) {
350 csvTable.last().add('')
351 }
352 else {
353 csvTable.last().add(csvLine[2])
354 currentBuild = csvLine[2]
355 }
356 csvTable.last().add(csvLine[3])
357 configs.each { config ->
358 if (csvLine[4].containsKey(config)) {
359 csvTable.last().add(csvLine[4][config])
360 }
361 else {
362 csvTable.last().add('N/A')
363 }
364 }
365 }
366 return csvTable
367}
368
369def generateBuildCsv(results) {
370 def csvContent = generateCsvContent(results)
371 node("master") {
372 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
373 archiveArtifacts 'build_results.csv'
374 }
375}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000376
377def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000378 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000379 def csvContent = summary.getBuildCsv(results)
380 node("master") {
381 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
382 archiveArtifacts 'build_results.csv'
383 }
384}
385
386def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000387 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000388 def buildLinks = summary.getLinks(results)
389 node("master") {
390 writeFile file: "build_links.html", text: buildLinks
391 archiveArtifacts 'build_links.html'
392 }
393}
394
Matthew Hartfb6fd362020-03-04 21:03:59 +0000395def lineInString(string, match) {
396 def lines = string.split("\n")
397 def result = lines.findAll { it.contains(match) }
398 return result[0]
399}
400
401def getResult(string, match) {
402 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100403 a = line.split(match)[1].split(' ')
404 score = a[0]
405 if (a.size() > 1)
406 {
407 fail_text = a[1..-1].join(" ")
408 return [score, fail_text]
409 }
410 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000411}
412
413def submitJobsToList(results) {
414 def all_jobs = []
415 for (String result : results){
416 jobs_s = result.split('JOBS: ')
417 if (jobs_s.size() > 1) {
418 all_jobs += jobs_s[1]
419 }
420 }
421 return(all_jobs)
422}
423
Dean Birch62c4f082020-01-17 16:13:26 +0000424def configs = []
425def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000426def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000427
Karl Zhangfec84102020-06-24 09:56:36 +0800428node("docker-amd64-bionic") {
Dean Birch62c4f082020-01-17 16:13:26 +0000429 stage("Init") {
430 cleanWs()
431 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000432 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Birch62c4f082020-01-17 16:13:26 +0000433 }
434 }
435 stage("Configs") {
436 // Populate configs
437 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000438 results['builds'] = [:]
439 results['lava_jobs'] = []
Dean Birch62c4f082020-01-17 16:13:26 +0000440 for (config in configs) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000441 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
Dean Birch62c4f082020-01-17 16:13:26 +0000442 }
Matthew Hart06340d72020-06-15 16:08:20 +0100443 builds["docs"] = buildDocs(results)
Dean Birch62c4f082020-01-17 16:13:26 +0000444 }
445}
Karl Zhangfec84102020-06-24 09:56:36 +0800446
Dean Birch62c4f082020-01-17 16:13:26 +0000447stage("Builds") {
448 def verify = 1
449 try {
450 parallel(builds)
451 } catch (Exception e) {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000452 print(e)
Dean Birch62c4f082020-01-17 16:13:26 +0000453 manager.buildFailure()
454 verify = -1
455 } finally {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000456 print("Verifying status")
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000457 g = new Gerrit()
458 g.verifyStatus(verify, 'tf-m-build', 'build')
Dean Bircha6ede7e2020-03-13 14:00:33 +0000459 print("Building CSV")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800460 generateBuildCsv(results['builds'])
Dean Bircha6ede7e2020-03-13 14:00:33 +0000461 writeSummary(results['builds'])
Dean Birch62c4f082020-01-17 16:13:26 +0000462 }
463}
Matthew Hart06340d72020-06-15 16:08:20 +0100464
Karl Zhangfec84102020-06-24 09:56:36 +0800465node("docker-amd64-bionic") {
Matthew Hart06340d72020-06-15 16:08:20 +0100466 stage("Copy Docs") {
Karl Zhang32497972020-09-21 14:38:29 +0800467 if (env.JOB_NAME.equals("tf-m-build-and-test")) {
468 step([$class: 'CopyArtifact', projectName: 'tf-m-build-docs',
469 selector: specific("${results['docs'][0]}"), target: './docs/',
470 optional: true])
471 archiveArtifacts artifacts: 'docs/**', allowEmptyArchive: true
472 }
473 else {
474 print("No doc copy for job: ${env.JOB_NAME}")
475 }
Matthew Hart06340d72020-06-15 16:08:20 +0100476 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000477 stage("Tests") {
478 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000479 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Bircha6ede7e2020-03-13 14:00:33 +0000480 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000481 def all_jobs = []
482 def success = true
Dean Bircha6ede7e2020-03-13 14:00:33 +0000483 print("Wait for LAVA results here...")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000484 try {
485 all_jobs = submitJobsToList(results['lava_jobs'])
486 if (all_jobs.size() > 0) {
487 dir("tf-m-ci-scripts") {
Dean Birch956416f2020-08-12 10:36:16 +0100488 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000489 output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
490 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
Matthew Hart05a59b52020-05-27 17:54:51 +0100491 --artifacts-path lava_artifacts --lava-timeout 7200 \
Matthew Hartfb6fd362020-03-04 21:03:59 +0000492 """, returnStdout: true).trim()
493 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
494 print(output)
495 g = new Gerrit()
Dean Birch1d545c02020-05-29 14:09:21 +0100496 def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000497 if (boot_result) {
498 g.verifyStatus(boot_result, "lava_boot", "test")
499 }
Dean Birch1d545c02020-05-29 14:09:21 +0100500 def (test_result, test_output) = getResult(output, 'TEST_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000501 if (test_result) {
502 g.verifyStatus(test_result, "lava_test", "test")
503 }
504 if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) {
Dean Birch1d545c02020-05-29 14:09:21 +0100505 error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000506 }
507 }
508 }
509 }
510 else {
511 print("There were no LAVA jobs to test.")
512 }
513 }
514 catch (Exception e) {
515 print("ERROR: ${e}")
516 success = false
517 } finally {
518 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
Karl Zhang0413e972020-09-18 17:59:26 +0800519 emailNotification(success);
Matthew Hartfb6fd362020-03-04 21:03:59 +0000520 cleanWs()
521 if (!success) {
522 error("There was an Error waiting for LAVA jobs")
523 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000524 }
525 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000526}