blob: f7bdc9cf80b9d6a943c59911535c77ea3123cee5 [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
Dean Birch62c4f082020-01-17 16:13:26 +000013def listConfigs(ci_scripts_dir, config_list, filter_group) {
14 dir(ci_scripts_dir) {
15 echo "Obtaining list of configs."
Matthew Hartfb6fd362020-03-04 21:03:59 +000016 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}"
Dean Birch62c4f082020-01-17 16:13:26 +000017 def build_config_list_raw = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +000018python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}
Dean Birch62c4f082020-01-17 16:13:26 +000019""", returnStdout: true).trim()
20 def build_config_list = build_config_list_raw.tokenize('\n')
21 config_list.addAll(build_config_list)
22 }
23}
24
Matthew Hartfb6fd362020-03-04 21:03:59 +000025def buildConfig(ci_scripts_dir, config, filter_group, results) {
Dean Birch62c4f082020-01-17 16:13:26 +000026 def params = []
Matthew Hartfb6fd362020-03-04 21:03:59 +000027 def params_collection = [:]
Dean Birch62c4f082020-01-17 16:13:26 +000028 def build_config_params
29 dir(ci_scripts_dir) {
30 echo "Obtaining build configuration for config ${config}"
Matthew Hartfb6fd362020-03-04 21:03:59 +000031 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}"
Dean Birch62c4f082020-01-17 16:13:26 +000032 build_config_params = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +000033python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}
Dean Birch62c4f082020-01-17 16:13:26 +000034""", returnStdout: true).trim()
35 }
36 def lines = build_config_params.tokenize('\n')
37 for (String line : lines) {
38 def key, value
39 (key, value) = line.tokenize('=')
40 params += string(name: key, value: value)
Matthew Hartfb6fd362020-03-04 21:03:59 +000041 params_collection[key] = value
Dean Birch62c4f082020-01-17 16:13:26 +000042 }
43 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +000044 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
45 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
46 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +000047 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +080048 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +000049 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Karl Zhangf6f467e2020-07-10 16:24:45 +080050 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Dean Bircha6ede7e2020-03-13 14:00:33 +000051 return { -> results
52 def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false)
53 def build_info = [build_res, config, params_collection]
54 results['builds'][build_res.number] = build_info
55 def build_url = build_res.getAbsoluteUrl()
56 print("${build_res.number}: ${config} ${build_res.result} ${build_url}")
57 failure_states = ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]
58 if (build_res.result in failure_states) {
59 error("Build failed at ${build_url}")
60 }
61 else {
62 print("Doing LAVA stuff for ${build_url}")
63 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
64 params += string(name: 'BUILD_URL', value: build_url)
Matthew Hartfb6fd362020-03-04 21:03:59 +000065 params += string(name: 'LAVA_URL', value: env.LAVA_URL)
Dean Birch956416f2020-08-12 10:36:16 +010066 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
67 params += string(name: 'LAVA_CREDENTIALS', value: env.LAVA_CREDENTIALS)
Dean Bircha6ede7e2020-03-13 14:00:33 +000068 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
Matthew Hartfb6fd362020-03-04 21:03:59 +000069 if (lava_res.result in failure_states) {
70 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
71 }
72 else {
73 results['lava_jobs'] += lava_res.getDescription()
74 }
Dean Birch62c4f082020-01-17 16:13:26 +000075 }
76 }
77}
78
Matthew Hart06340d72020-06-15 16:08:20 +010079def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +000080 def params = []
81 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +000082 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
83 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
84 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +000085 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +080086 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +000087 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Matthew Hart06340d72020-06-15 16:08:20 +010088 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +000089 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
90 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +010091 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +000092 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +000093 error("Build failed at ${res.getAbsoluteUrl()}")
94 }
95 }
96}
97
xinyu-tfmb4fc0412020-08-19 10:49:51 +080098@NonCPS
99def generateCsvContent(results) {
100 def resultsParam = []
101 results.each { result ->
102 resultsParam.add([result.value[1], \
103 result.value[0].getResult(), \
104 result.value[2]['TARGET_PLATFORM'], \
105 result.value[2]['COMPILER'], \
106 result.value[2]['PROJ_CONFIG'], \
107 result.value[2]['CMAKE_BUILD_TYPE'], \
108 result.value[2]['BL2'], \
109 result.value[2]['PSA_API_SUITE']])
110 }
111 def configs = [] as Set
112 resultsParam.each { result ->
113 if (result[2] == 'MUSCA_B1') {
114 if (result[0].contains('_OTP_')) {
115 result[2] += '_OTP'
116 }
117 }
118 if (result[6] == 'True') {
119 result[6] = 'BL2'
120 }
121 else {
122 result[6] = 'NOBL2'
123 }
124 config = result[4]
125 if (result[7] != "''") {
126 config += ' (' + result[7] + ') '
127 }
128 configs.add(config)
129 result.add(config)
130 }
131 configs.sort()
132 def csvContent = []
133 resultsParam.each { result ->
134 def configExists = false
135 for (csvLine in csvContent) {
136 if (csvLine[0] == result[2] && \
137 csvLine[1] == result[3] && \
138 csvLine[2] == result[5] && \
139 csvLine[3] == result[6]) {
140 csvLine[4][result[8]] = result[1]
141 configExists = true
142 break
143 }
144 }
145 if (!configExists) {
146 csvContent.add([result[2], result[3], result[5], result[6], [:]])
147 csvContent.last()[4][result[8]] = result[1]
148 }
149 }
150 csvContent.sort{a,b -> a[0] <=> b[0] ?: a[1] <=> b[1] ?: a[2] <=> b[2] ?: a[3] <=> b[3]}
151 def csvTable = [['Platform', 'Compiler', 'Cmake Build Type', 'BL2']]
152 csvTable[0] += configs
153 def currentPlatform = ''
154 def currentCompiler = ''
155 def currentBuild = ''
156 csvContent.each { csvLine ->
157 // Modify CSV output format for a better layout
158 if (currentPlatform == csvLine[0]) {
159 csvTable.add([''])
160 }
161 else {
162 csvTable.add([csvLine[0]])
163 currentPlatform = csvLine[0]
164 currentCompiler = ''
165 currentBuild = ''
166 }
167 if (currentCompiler == csvLine[1]) {
168 csvTable.last().add('')
169 }
170 else {
171 csvTable.last().add(csvLine[1])
172 currentCompiler = csvLine[1]
173 currentBuild = ''
174 }
175 if (currentBuild == csvLine[2]) {
176 csvTable.last().add('')
177 }
178 else {
179 csvTable.last().add(csvLine[2])
180 currentBuild = csvLine[2]
181 }
182 csvTable.last().add(csvLine[3])
183 configs.each { config ->
184 if (csvLine[4].containsKey(config)) {
185 csvTable.last().add(csvLine[4][config])
186 }
187 else {
188 csvTable.last().add('N/A')
189 }
190 }
191 }
192 return csvTable
193}
194
195def generateBuildCsv(results) {
196 def csvContent = generateCsvContent(results)
197 node("master") {
198 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
199 archiveArtifacts 'build_results.csv'
200 }
201}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000202
203def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000204 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000205 def csvContent = summary.getBuildCsv(results)
206 node("master") {
207 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
208 archiveArtifacts 'build_results.csv'
209 }
210}
211
212def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000213 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000214 def buildLinks = summary.getLinks(results)
215 node("master") {
216 writeFile file: "build_links.html", text: buildLinks
217 archiveArtifacts 'build_links.html'
218 }
219}
220
Matthew Hartfb6fd362020-03-04 21:03:59 +0000221def lineInString(string, match) {
222 def lines = string.split("\n")
223 def result = lines.findAll { it.contains(match) }
224 return result[0]
225}
226
227def getResult(string, match) {
228 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100229 a = line.split(match)[1].split(' ')
230 score = a[0]
231 if (a.size() > 1)
232 {
233 fail_text = a[1..-1].join(" ")
234 return [score, fail_text]
235 }
236 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000237}
238
239def submitJobsToList(results) {
240 def all_jobs = []
241 for (String result : results){
242 jobs_s = result.split('JOBS: ')
243 if (jobs_s.size() > 1) {
244 all_jobs += jobs_s[1]
245 }
246 }
247 return(all_jobs)
248}
249
Dean Birch62c4f082020-01-17 16:13:26 +0000250def configs = []
251def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000252def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000253
Karl Zhangfec84102020-06-24 09:56:36 +0800254node("docker-amd64-bionic") {
Dean Birch62c4f082020-01-17 16:13:26 +0000255 stage("Init") {
256 cleanWs()
257 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000258 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Birch62c4f082020-01-17 16:13:26 +0000259 }
260 }
261 stage("Configs") {
262 // Populate configs
263 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000264 results['builds'] = [:]
265 results['lava_jobs'] = []
Dean Birch62c4f082020-01-17 16:13:26 +0000266 for (config in configs) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000267 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
Dean Birch62c4f082020-01-17 16:13:26 +0000268 }
Matthew Hart06340d72020-06-15 16:08:20 +0100269 builds["docs"] = buildDocs(results)
Dean Birch62c4f082020-01-17 16:13:26 +0000270 }
271}
Karl Zhangfec84102020-06-24 09:56:36 +0800272
Dean Birch62c4f082020-01-17 16:13:26 +0000273stage("Builds") {
274 def verify = 1
275 try {
276 parallel(builds)
277 } catch (Exception e) {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000278 print(e)
Dean Birch62c4f082020-01-17 16:13:26 +0000279 manager.buildFailure()
280 verify = -1
281 } finally {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000282 print("Verifying status")
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000283 g = new Gerrit()
284 g.verifyStatus(verify, 'tf-m-build', 'build')
Dean Bircha6ede7e2020-03-13 14:00:33 +0000285 print("Building CSV")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800286 generateBuildCsv(results['builds'])
Dean Bircha6ede7e2020-03-13 14:00:33 +0000287 writeSummary(results['builds'])
Dean Birch62c4f082020-01-17 16:13:26 +0000288 }
289}
Matthew Hart06340d72020-06-15 16:08:20 +0100290
Karl Zhangfec84102020-06-24 09:56:36 +0800291node("docker-amd64-bionic") {
Matthew Hart06340d72020-06-15 16:08:20 +0100292 stage("Copy Docs") {
293 step([$class: 'CopyArtifact', projectName: 'tf-m-build-docs',
294 selector: specific("${results['docs'][0]}"), target: './docs/',
295 optional: true])
296 archiveArtifacts artifacts: 'docs/**', allowEmptyArchive: true
297 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000298 stage("Tests") {
299 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000300 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Bircha6ede7e2020-03-13 14:00:33 +0000301 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000302 def all_jobs = []
303 def success = true
Dean Bircha6ede7e2020-03-13 14:00:33 +0000304 print("Wait for LAVA results here...")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000305 try {
306 all_jobs = submitJobsToList(results['lava_jobs'])
307 if (all_jobs.size() > 0) {
308 dir("tf-m-ci-scripts") {
Dean Birch956416f2020-08-12 10:36:16 +0100309 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000310 output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
311 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
Matthew Hart05a59b52020-05-27 17:54:51 +0100312 --artifacts-path lava_artifacts --lava-timeout 7200 \
Matthew Hartfb6fd362020-03-04 21:03:59 +0000313 """, returnStdout: true).trim()
314 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
315 print(output)
316 g = new Gerrit()
Dean Birch1d545c02020-05-29 14:09:21 +0100317 def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000318 if (boot_result) {
319 g.verifyStatus(boot_result, "lava_boot", "test")
320 }
Dean Birch1d545c02020-05-29 14:09:21 +0100321 def (test_result, test_output) = getResult(output, 'TEST_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000322 if (test_result) {
323 g.verifyStatus(test_result, "lava_test", "test")
324 }
325 if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) {
Dean Birch1d545c02020-05-29 14:09:21 +0100326 error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000327 }
328 }
329 }
330 }
331 else {
332 print("There were no LAVA jobs to test.")
333 }
334 }
335 catch (Exception e) {
336 print("ERROR: ${e}")
337 success = false
338 } finally {
339 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
340 cleanWs()
341 if (!success) {
342 error("There was an Error waiting for LAVA jobs")
343 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000344 }
345 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000346}