blob: 8b9fcb9360ead12155b92accbd50fdd10f290630 [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)
48 params += string(name: 'CMSIS_VERSION', value: env.CMSIS_VERSION)
49 params += string(name: 'MBEDCRYPTO_VERSION', value: env.MBEDCRYPTO_VERSION)
Karl Zhang02d30352020-08-20 13:48:52 +080050 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +000051 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Karl Zhangf6f467e2020-07-10 16:24:45 +080052 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Dean Bircha6ede7e2020-03-13 14:00:33 +000053 return { -> results
54 def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false)
55 def build_info = [build_res, config, params_collection]
56 results['builds'][build_res.number] = build_info
57 def build_url = build_res.getAbsoluteUrl()
58 print("${build_res.number}: ${config} ${build_res.result} ${build_url}")
59 failure_states = ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]
60 if (build_res.result in failure_states) {
61 error("Build failed at ${build_url}")
62 }
63 else {
64 print("Doing LAVA stuff for ${build_url}")
65 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
66 params += string(name: 'BUILD_URL', value: build_url)
Matthew Hartfb6fd362020-03-04 21:03:59 +000067 params += string(name: 'LAVA_URL', value: env.LAVA_URL)
Dean Birch956416f2020-08-12 10:36:16 +010068 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
69 params += string(name: 'LAVA_CREDENTIALS', value: env.LAVA_CREDENTIALS)
Dean Bircha6ede7e2020-03-13 14:00:33 +000070 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
Matthew Hartfb6fd362020-03-04 21:03:59 +000071 if (lava_res.result in failure_states) {
72 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
73 }
74 else {
75 results['lava_jobs'] += lava_res.getDescription()
76 }
Dean Birch62c4f082020-01-17 16:13:26 +000077 }
78 }
79}
80
Matthew Hart06340d72020-06-15 16:08:20 +010081def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +000082 def params = []
83 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +000084 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
85 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
86 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +000087 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
88 params += string(name: 'CMSIS_VERSION', value: env.CMSIS_VERSION)
89 params += string(name: 'MBEDCRYPTO_VERSION', value: env.MBEDCRYPTO_VERSION)
Karl Zhang02d30352020-08-20 13:48:52 +080090 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +000091 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Matthew Hart06340d72020-06-15 16:08:20 +010092 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +000093 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
94 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +010095 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +000096 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +000097 error("Build failed at ${res.getAbsoluteUrl()}")
98 }
99 }
100}
101
Dean Bircha6ede7e2020-03-13 14:00:33 +0000102
103def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000104 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000105 def csvContent = summary.getBuildCsv(results)
106 node("master") {
107 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
108 archiveArtifacts 'build_results.csv'
109 }
110}
111
112def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000113 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000114 def buildLinks = summary.getLinks(results)
115 node("master") {
116 writeFile file: "build_links.html", text: buildLinks
117 archiveArtifacts 'build_links.html'
118 }
119}
120
Matthew Hartfb6fd362020-03-04 21:03:59 +0000121def lineInString(string, match) {
122 def lines = string.split("\n")
123 def result = lines.findAll { it.contains(match) }
124 return result[0]
125}
126
127def getResult(string, match) {
128 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100129 a = line.split(match)[1].split(' ')
130 score = a[0]
131 if (a.size() > 1)
132 {
133 fail_text = a[1..-1].join(" ")
134 return [score, fail_text]
135 }
136 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000137}
138
139def submitJobsToList(results) {
140 def all_jobs = []
141 for (String result : results){
142 jobs_s = result.split('JOBS: ')
143 if (jobs_s.size() > 1) {
144 all_jobs += jobs_s[1]
145 }
146 }
147 return(all_jobs)
148}
149
Dean Birch62c4f082020-01-17 16:13:26 +0000150def configs = []
151def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000152def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000153
Karl Zhangfec84102020-06-24 09:56:36 +0800154node("docker-amd64-bionic") {
Dean Birch62c4f082020-01-17 16:13:26 +0000155 stage("Init") {
156 cleanWs()
157 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000158 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Birch62c4f082020-01-17 16:13:26 +0000159 }
160 }
161 stage("Configs") {
162 // Populate configs
163 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000164 results['builds'] = [:]
165 results['lava_jobs'] = []
Dean Birch62c4f082020-01-17 16:13:26 +0000166 for (config in configs) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000167 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
Dean Birch62c4f082020-01-17 16:13:26 +0000168 }
Matthew Hart06340d72020-06-15 16:08:20 +0100169 builds["docs"] = buildDocs(results)
Dean Birch62c4f082020-01-17 16:13:26 +0000170 }
171}
Karl Zhangfec84102020-06-24 09:56:36 +0800172
Dean Birch62c4f082020-01-17 16:13:26 +0000173stage("Builds") {
174 def verify = 1
175 try {
176 parallel(builds)
177 } catch (Exception e) {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000178 print(e)
Dean Birch62c4f082020-01-17 16:13:26 +0000179 manager.buildFailure()
180 verify = -1
181 } finally {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000182 print("Verifying status")
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000183 g = new Gerrit()
184 g.verifyStatus(verify, 'tf-m-build', 'build')
Dean Bircha6ede7e2020-03-13 14:00:33 +0000185 print("Building CSV")
186 buildCsv(results['builds'])
187 writeSummary(results['builds'])
Dean Birch62c4f082020-01-17 16:13:26 +0000188 }
189}
Matthew Hart06340d72020-06-15 16:08:20 +0100190
Karl Zhangfec84102020-06-24 09:56:36 +0800191node("docker-amd64-bionic") {
Matthew Hart06340d72020-06-15 16:08:20 +0100192 stage("Copy Docs") {
193 step([$class: 'CopyArtifact', projectName: 'tf-m-build-docs',
194 selector: specific("${results['docs'][0]}"), target: './docs/',
195 optional: true])
196 archiveArtifacts artifacts: 'docs/**', allowEmptyArchive: true
197 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000198 stage("Tests") {
199 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000200 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Bircha6ede7e2020-03-13 14:00:33 +0000201 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000202 def all_jobs = []
203 def success = true
Dean Bircha6ede7e2020-03-13 14:00:33 +0000204 print("Wait for LAVA results here...")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000205 try {
206 all_jobs = submitJobsToList(results['lava_jobs'])
207 if (all_jobs.size() > 0) {
208 dir("tf-m-ci-scripts") {
Dean Birch956416f2020-08-12 10:36:16 +0100209 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000210 output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
211 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
Matthew Hart05a59b52020-05-27 17:54:51 +0100212 --artifacts-path lava_artifacts --lava-timeout 7200 \
Matthew Hartfb6fd362020-03-04 21:03:59 +0000213 """, returnStdout: true).trim()
214 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
215 print(output)
216 g = new Gerrit()
Dean Birch1d545c02020-05-29 14:09:21 +0100217 def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000218 if (boot_result) {
219 g.verifyStatus(boot_result, "lava_boot", "test")
220 }
Dean Birch1d545c02020-05-29 14:09:21 +0100221 def (test_result, test_output) = getResult(output, 'TEST_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000222 if (test_result) {
223 g.verifyStatus(test_result, "lava_test", "test")
224 }
225 if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) {
Dean Birch1d545c02020-05-29 14:09:21 +0100226 error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000227 }
228 }
229 }
230 }
231 else {
232 print("There were no LAVA jobs to test.")
233 }
234 }
235 catch (Exception e) {
236 print("ERROR: ${e}")
237 success = false
238 } finally {
239 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
240 cleanWs()
241 if (!success) {
242 error("There was an Error waiting for LAVA jobs")
243 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000244 }
245 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000246}