blob: 0c4d5f37258958cf71bcad776d087ec1bc10e1c6 [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)
Dean Birch62c4f082020-01-17 16:13:26 +000048 params += string(name: 'MBEDCRYPTO_VERSION', value: env.MBEDCRYPTO_VERSION)
Karl Zhang02d30352020-08-20 13:48:52 +080049 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +000050 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Karl Zhangf6f467e2020-07-10 16:24:45 +080051 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Dean Bircha6ede7e2020-03-13 14:00:33 +000052 return { -> results
53 def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false)
54 def build_info = [build_res, config, params_collection]
55 results['builds'][build_res.number] = build_info
56 def build_url = build_res.getAbsoluteUrl()
57 print("${build_res.number}: ${config} ${build_res.result} ${build_url}")
58 failure_states = ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]
59 if (build_res.result in failure_states) {
60 error("Build failed at ${build_url}")
61 }
62 else {
63 print("Doing LAVA stuff for ${build_url}")
64 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
65 params += string(name: 'BUILD_URL', value: build_url)
Matthew Hartfb6fd362020-03-04 21:03:59 +000066 params += string(name: 'LAVA_URL', value: env.LAVA_URL)
Dean Birch956416f2020-08-12 10:36:16 +010067 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
68 params += string(name: 'LAVA_CREDENTIALS', value: env.LAVA_CREDENTIALS)
Dean Bircha6ede7e2020-03-13 14:00:33 +000069 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
Matthew Hartfb6fd362020-03-04 21:03:59 +000070 if (lava_res.result in failure_states) {
71 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
72 }
73 else {
74 results['lava_jobs'] += lava_res.getDescription()
75 }
Dean Birch62c4f082020-01-17 16:13:26 +000076 }
77 }
78}
79
Matthew Hart06340d72020-06-15 16:08:20 +010080def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +000081 def params = []
82 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +000083 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
84 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
85 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +000086 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Dean Birch62c4f082020-01-17 16:13:26 +000087 params += string(name: 'MBEDCRYPTO_VERSION', value: env.MBEDCRYPTO_VERSION)
Karl Zhang02d30352020-08-20 13:48:52 +080088 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +000089 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Matthew Hart06340d72020-06-15 16:08:20 +010090 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +000091 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
92 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +010093 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +000094 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +000095 error("Build failed at ${res.getAbsoluteUrl()}")
96 }
97 }
98}
99
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800100@NonCPS
101def generateCsvContent(results) {
102 def resultsParam = []
103 results.each { result ->
104 resultsParam.add([result.value[1], \
105 result.value[0].getResult(), \
106 result.value[2]['TARGET_PLATFORM'], \
107 result.value[2]['COMPILER'], \
108 result.value[2]['PROJ_CONFIG'], \
109 result.value[2]['CMAKE_BUILD_TYPE'], \
110 result.value[2]['BL2'], \
111 result.value[2]['PSA_API_SUITE']])
112 }
113 def configs = [] as Set
114 resultsParam.each { result ->
115 if (result[2] == 'MUSCA_B1') {
116 if (result[0].contains('_OTP_')) {
117 result[2] += '_OTP'
118 }
119 }
120 if (result[6] == 'True') {
121 result[6] = 'BL2'
122 }
123 else {
124 result[6] = 'NOBL2'
125 }
126 config = result[4]
127 if (result[7] != "''") {
128 config += ' (' + result[7] + ') '
129 }
130 configs.add(config)
131 result.add(config)
132 }
133 configs.sort()
134 def csvContent = []
135 resultsParam.each { result ->
136 def configExists = false
137 for (csvLine in csvContent) {
138 if (csvLine[0] == result[2] && \
139 csvLine[1] == result[3] && \
140 csvLine[2] == result[5] && \
141 csvLine[3] == result[6]) {
142 csvLine[4][result[8]] = result[1]
143 configExists = true
144 break
145 }
146 }
147 if (!configExists) {
148 csvContent.add([result[2], result[3], result[5], result[6], [:]])
149 csvContent.last()[4][result[8]] = result[1]
150 }
151 }
152 csvContent.sort{a,b -> a[0] <=> b[0] ?: a[1] <=> b[1] ?: a[2] <=> b[2] ?: a[3] <=> b[3]}
153 def csvTable = [['Platform', 'Compiler', 'Cmake Build Type', 'BL2']]
154 csvTable[0] += configs
155 def currentPlatform = ''
156 def currentCompiler = ''
157 def currentBuild = ''
158 csvContent.each { csvLine ->
159 // Modify CSV output format for a better layout
160 if (currentPlatform == csvLine[0]) {
161 csvTable.add([''])
162 }
163 else {
164 csvTable.add([csvLine[0]])
165 currentPlatform = csvLine[0]
166 currentCompiler = ''
167 currentBuild = ''
168 }
169 if (currentCompiler == csvLine[1]) {
170 csvTable.last().add('')
171 }
172 else {
173 csvTable.last().add(csvLine[1])
174 currentCompiler = csvLine[1]
175 currentBuild = ''
176 }
177 if (currentBuild == csvLine[2]) {
178 csvTable.last().add('')
179 }
180 else {
181 csvTable.last().add(csvLine[2])
182 currentBuild = csvLine[2]
183 }
184 csvTable.last().add(csvLine[3])
185 configs.each { config ->
186 if (csvLine[4].containsKey(config)) {
187 csvTable.last().add(csvLine[4][config])
188 }
189 else {
190 csvTable.last().add('N/A')
191 }
192 }
193 }
194 return csvTable
195}
196
197def generateBuildCsv(results) {
198 def csvContent = generateCsvContent(results)
199 node("master") {
200 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
201 archiveArtifacts 'build_results.csv'
202 }
203}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000204
205def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000206 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000207 def csvContent = summary.getBuildCsv(results)
208 node("master") {
209 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
210 archiveArtifacts 'build_results.csv'
211 }
212}
213
214def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000215 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000216 def buildLinks = summary.getLinks(results)
217 node("master") {
218 writeFile file: "build_links.html", text: buildLinks
219 archiveArtifacts 'build_links.html'
220 }
221}
222
Matthew Hartfb6fd362020-03-04 21:03:59 +0000223def lineInString(string, match) {
224 def lines = string.split("\n")
225 def result = lines.findAll { it.contains(match) }
226 return result[0]
227}
228
229def getResult(string, match) {
230 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100231 a = line.split(match)[1].split(' ')
232 score = a[0]
233 if (a.size() > 1)
234 {
235 fail_text = a[1..-1].join(" ")
236 return [score, fail_text]
237 }
238 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000239}
240
241def submitJobsToList(results) {
242 def all_jobs = []
243 for (String result : results){
244 jobs_s = result.split('JOBS: ')
245 if (jobs_s.size() > 1) {
246 all_jobs += jobs_s[1]
247 }
248 }
249 return(all_jobs)
250}
251
Dean Birch62c4f082020-01-17 16:13:26 +0000252def configs = []
253def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000254def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000255
Karl Zhangfec84102020-06-24 09:56:36 +0800256node("docker-amd64-bionic") {
Dean Birch62c4f082020-01-17 16:13:26 +0000257 stage("Init") {
258 cleanWs()
259 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000260 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Birch62c4f082020-01-17 16:13:26 +0000261 }
262 }
263 stage("Configs") {
264 // Populate configs
265 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000266 results['builds'] = [:]
267 results['lava_jobs'] = []
Dean Birch62c4f082020-01-17 16:13:26 +0000268 for (config in configs) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000269 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
Dean Birch62c4f082020-01-17 16:13:26 +0000270 }
Matthew Hart06340d72020-06-15 16:08:20 +0100271 builds["docs"] = buildDocs(results)
Dean Birch62c4f082020-01-17 16:13:26 +0000272 }
273}
Karl Zhangfec84102020-06-24 09:56:36 +0800274
Dean Birch62c4f082020-01-17 16:13:26 +0000275stage("Builds") {
276 def verify = 1
277 try {
278 parallel(builds)
279 } catch (Exception e) {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000280 print(e)
Dean Birch62c4f082020-01-17 16:13:26 +0000281 manager.buildFailure()
282 verify = -1
283 } finally {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000284 print("Verifying status")
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000285 g = new Gerrit()
286 g.verifyStatus(verify, 'tf-m-build', 'build')
Dean Bircha6ede7e2020-03-13 14:00:33 +0000287 print("Building CSV")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800288 generateBuildCsv(results['builds'])
Dean Bircha6ede7e2020-03-13 14:00:33 +0000289 writeSummary(results['builds'])
Dean Birch62c4f082020-01-17 16:13:26 +0000290 }
291}
Matthew Hart06340d72020-06-15 16:08:20 +0100292
Karl Zhangfec84102020-06-24 09:56:36 +0800293node("docker-amd64-bionic") {
Matthew Hart06340d72020-06-15 16:08:20 +0100294 stage("Copy Docs") {
295 step([$class: 'CopyArtifact', projectName: 'tf-m-build-docs',
296 selector: specific("${results['docs'][0]}"), target: './docs/',
297 optional: true])
298 archiveArtifacts artifacts: 'docs/**', allowEmptyArchive: true
299 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000300 stage("Tests") {
301 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000302 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Bircha6ede7e2020-03-13 14:00:33 +0000303 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000304 def all_jobs = []
305 def success = true
Dean Bircha6ede7e2020-03-13 14:00:33 +0000306 print("Wait for LAVA results here...")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000307 try {
308 all_jobs = submitJobsToList(results['lava_jobs'])
309 if (all_jobs.size() > 0) {
310 dir("tf-m-ci-scripts") {
Dean Birch956416f2020-08-12 10:36:16 +0100311 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000312 output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
313 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
Matthew Hart05a59b52020-05-27 17:54:51 +0100314 --artifacts-path lava_artifacts --lava-timeout 7200 \
Matthew Hartfb6fd362020-03-04 21:03:59 +0000315 """, returnStdout: true).trim()
316 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
317 print(output)
318 g = new Gerrit()
Dean Birch1d545c02020-05-29 14:09:21 +0100319 def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000320 if (boot_result) {
321 g.verifyStatus(boot_result, "lava_boot", "test")
322 }
Dean Birch1d545c02020-05-29 14:09:21 +0100323 def (test_result, test_output) = getResult(output, 'TEST_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000324 if (test_result) {
325 g.verifyStatus(test_result, "lava_test", "test")
326 }
327 if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) {
Dean Birch1d545c02020-05-29 14:09:21 +0100328 error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000329 }
330 }
331 }
332 }
333 else {
334 print("There were no LAVA jobs to test.")
335 }
336 }
337 catch (Exception e) {
338 print("ERROR: ${e}")
339 success = false
340 } finally {
341 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
342 cleanWs()
343 if (!success) {
344 error("There was an Error waiting for LAVA jobs")
345 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000346 }
347 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000348}