blob: 8744842abbca9c69a5e7136321abd1b66b2fc468 [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)
50 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
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 Bircha6ede7e2020-03-13 14:00:33 +000066 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
Matthew Hartfb6fd362020-03-04 21:03:59 +000067 if (lava_res.result in failure_states) {
68 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
69 }
70 else {
71 results['lava_jobs'] += lava_res.getDescription()
72 }
Dean Birch62c4f082020-01-17 16:13:26 +000073 }
74 }
75}
76
77def buildDocs() {
78 def params = []
79 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +000080 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
81 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
82 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +000083 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
84 params += string(name: 'CMSIS_VERSION', value: env.CMSIS_VERSION)
85 params += string(name: 'MBEDCRYPTO_VERSION', value: env.MBEDCRYPTO_VERSION)
86 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
87 return {
88 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
89 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Dean Bircha6ede7e2020-03-13 14:00:33 +000090 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +000091 error("Build failed at ${res.getAbsoluteUrl()}")
92 }
93 }
94}
95
Dean Bircha6ede7e2020-03-13 14:00:33 +000096
97def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +000098 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +000099 def csvContent = summary.getBuildCsv(results)
100 node("master") {
101 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
102 archiveArtifacts 'build_results.csv'
103 }
104}
105
106def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000107 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000108 def buildLinks = summary.getLinks(results)
109 node("master") {
110 writeFile file: "build_links.html", text: buildLinks
111 archiveArtifacts 'build_links.html'
112 }
113}
114
Matthew Hartfb6fd362020-03-04 21:03:59 +0000115def lineInString(string, match) {
116 def lines = string.split("\n")
117 def result = lines.findAll { it.contains(match) }
118 return result[0]
119}
120
121def getResult(string, match) {
122 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100123 a = line.split(match)[1].split(' ')
124 score = a[0]
125 if (a.size() > 1)
126 {
127 fail_text = a[1..-1].join(" ")
128 return [score, fail_text]
129 }
130 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000131}
132
133def submitJobsToList(results) {
134 def all_jobs = []
135 for (String result : results){
136 jobs_s = result.split('JOBS: ')
137 if (jobs_s.size() > 1) {
138 all_jobs += jobs_s[1]
139 }
140 }
141 return(all_jobs)
142}
143
Dean Birch62c4f082020-01-17 16:13:26 +0000144def configs = []
145def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000146def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000147
Matthew Hartfb6fd362020-03-04 21:03:59 +0000148node("docker-amd64-xenial") {
Dean Birch62c4f082020-01-17 16:13:26 +0000149 stage("Init") {
150 cleanWs()
151 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000152 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Birch62c4f082020-01-17 16:13:26 +0000153 }
154 }
155 stage("Configs") {
156 // Populate configs
157 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000158 results['builds'] = [:]
159 results['lava_jobs'] = []
Dean Birch62c4f082020-01-17 16:13:26 +0000160 for (config in configs) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000161 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
Dean Birch62c4f082020-01-17 16:13:26 +0000162 }
163 builds["docs"] = buildDocs()
164 }
165}
166stage("Builds") {
167 def verify = 1
168 try {
169 parallel(builds)
170 } catch (Exception e) {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000171 print(e)
Dean Birch62c4f082020-01-17 16:13:26 +0000172 manager.buildFailure()
173 verify = -1
174 } finally {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000175 print("Verifying status")
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000176 g = new Gerrit()
177 g.verifyStatus(verify, 'tf-m-build', 'build')
Dean Bircha6ede7e2020-03-13 14:00:33 +0000178 print("Building CSV")
179 buildCsv(results['builds'])
180 writeSummary(results['builds'])
Dean Birch62c4f082020-01-17 16:13:26 +0000181 }
182}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000183node("docker-amd64-xenial") {
184 stage("Tests") {
185 dir("tf-m-ci-scripts") {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000186 git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY'
Dean Bircha6ede7e2020-03-13 14:00:33 +0000187 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000188 def all_jobs = []
189 def success = true
Dean Bircha6ede7e2020-03-13 14:00:33 +0000190 print("Wait for LAVA results here...")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000191 try {
192 all_jobs = submitJobsToList(results['lava_jobs'])
193 if (all_jobs.size() > 0) {
194 dir("tf-m-ci-scripts") {
195 withCredentials([usernamePassword(credentialsId: 'LAVA_CREDENTIALS', passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
196 output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
197 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
Matthew Hart05a59b52020-05-27 17:54:51 +0100198 --artifacts-path lava_artifacts --lava-timeout 7200 \
Matthew Hartfb6fd362020-03-04 21:03:59 +0000199 """, returnStdout: true).trim()
200 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
201 print(output)
202 g = new Gerrit()
Dean Birch1d545c02020-05-29 14:09:21 +0100203 def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000204 if (boot_result) {
205 g.verifyStatus(boot_result, "lava_boot", "test")
206 }
Dean Birch1d545c02020-05-29 14:09:21 +0100207 def (test_result, test_output) = getResult(output, 'TEST_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000208 if (test_result) {
209 g.verifyStatus(test_result, "lava_test", "test")
210 }
211 if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) {
Dean Birch1d545c02020-05-29 14:09:21 +0100212 error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000213 }
214 }
215 }
216 }
217 else {
218 print("There were no LAVA jobs to test.")
219 }
220 }
221 catch (Exception e) {
222 print("ERROR: ${e}")
223 success = false
224 } finally {
225 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
226 cleanWs()
227 if (!success) {
228 error("There was an Error waiting for LAVA jobs")
229 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000230 }
231 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000232}