blob: 9d4a43406aae06e6091c76e7e2ff77600d614084 [file] [log] [blame]
Dean Birch62c4f082020-01-17 16:13:26 +00001#!/usr/bin/env groovy
2//-------------------------------------------------------------------------------
Xinyu Zhang433771e2022-04-01 16:49:17 +08003// Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
Dean Birch62c4f082020-01-17 16:13:26 +00004//
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 Zhang0aced4c2021-09-03 17:06:21 +080013failure_states = ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]
14
Xinyu Zhangda895572022-07-18 17:52:46 +080015cfgSkipFVP = [
Xinyu Zhangfb80b5d2022-07-26 15:42:26 +080016 "AN519_GCC_IPC_2_REG_Debug_BL2",
17 "AN519_GCC_IPC_2_REG_Debug_BL2_MEDIUM",
18 "AN519_GCC_IPC_2_REG_Debug_BL2_MEDIUM_PSOFF",
19 "AN519_ARMCLANG_IPC_2_REG_Debug_BL2",
20 "AN519_ARMCLANG_IPC_2_REG_Debug_BL2_MEDIUM",
21 "AN521_ARMCLANG_IPC_2_REG_Debug_BL2",
22 "AN521_ARMCLANG_IPC_2_REG_Debug_BL2_NSCE",
23 "AN521_ARMCLANG_IPC_2_REG_Debug_BL2_MEDIUM",
Xinyu Zhangda895572022-07-18 17:52:46 +080024]
25
Xinyu Zhang0aced4c2021-09-03 17:06:21 +080026def submit_lava_tests(config, results, build_res, params, params_collection) {
27 print("Doing LAVA stuff for ${build_res.getAbsoluteUrl()}")
Xinyu Zhang0aced4c2021-09-03 17:06:21 +080028 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
29 params += string(name: 'BUILD_URL', value: build_res.getAbsoluteUrl())
30 params += string(name: 'LAVA_URL', value: env.LAVA_URL)
Paul Sokolovskydaa430a2022-01-06 09:59:16 +030031 params += string(name: 'CI_SCRIPTS_REPO', value: env.CI_SCRIPTS_REPO)
Xinyu Zhang0aced4c2021-09-03 17:06:21 +080032 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
33 params += string(name: 'LAVA_CREDENTIALS', value: env.LAVA_CREDENTIALS)
34 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Xinyu Zhangda895572022-07-18 17:52:46 +080035 // Workaround: Configs in cfgSkipFVP fail on FVP but pass on physical boards
36 if (params_collection['CONFIG_NAME'] in cfgSkipFVP) {
37 params += string(name: 'DEVICE_FILTER', value: "--physical-board-only")
38 } else {
39 params += string(name: 'DEVICE_FILTER', value: env.DEVICE_FILTER)
40 }
Xinyu Zhang0aced4c2021-09-03 17:06:21 +080041 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
42 def lava_resubmitted = false
43 if (lava_res.result in failure_states) {
44 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
45 } else {
46 lava_des = lava_res.getDescription()
47 if (lava_des.contains(" Submitted twice!")) {
48 lava_resubmitted = true
49 lava_des = lava_des - " Submitted twice!"
50 }
51 results['lava_jobs'] += lava_des
52 }
53 links = "Build Config: ${config}\n"
54 links += "Build URL: ${build_res.getAbsoluteUrl()}\n"
55 links += "LAVA Submit: ${lava_res.getAbsoluteUrl()}"
56 if (lava_resubmitted) {
57 links += "\nLAVA Job Re-Submitted!"
58 }
59 print(links)
60}
61
Dean Birch62c4f082020-01-17 16:13:26 +000062def listConfigs(ci_scripts_dir, config_list, filter_group) {
63 dir(ci_scripts_dir) {
64 echo "Obtaining list of configs."
Matthew Hartfb6fd362020-03-04 21:03:59 +000065 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}"
Dean Birch62c4f082020-01-17 16:13:26 +000066 def build_config_list_raw = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +000067python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}
Dean Birch62c4f082020-01-17 16:13:26 +000068""", returnStdout: true).trim()
69 def build_config_list = build_config_list_raw.tokenize('\n')
70 config_list.addAll(build_config_list)
71 }
72}
73
Matthew Hartfb6fd362020-03-04 21:03:59 +000074def buildConfig(ci_scripts_dir, config, filter_group, results) {
Dean Birch62c4f082020-01-17 16:13:26 +000075 def params = []
Matthew Hartfb6fd362020-03-04 21:03:59 +000076 def params_collection = [:]
Dean Birch62c4f082020-01-17 16:13:26 +000077 def build_config_params
78 dir(ci_scripts_dir) {
79 echo "Obtaining build configuration for config ${config}"
Matthew Hartfb6fd362020-03-04 21:03:59 +000080 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}"
Dean Birch62c4f082020-01-17 16:13:26 +000081 build_config_params = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +000082python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}
Dean Birch62c4f082020-01-17 16:13:26 +000083""", returnStdout: true).trim()
84 }
85 def lines = build_config_params.tokenize('\n')
86 for (String line : lines) {
87 def key, value
88 (key, value) = line.tokenize('=')
89 params += string(name: key, value: value)
Matthew Hartfb6fd362020-03-04 21:03:59 +000090 params_collection[key] = value
Dean Birch62c4f082020-01-17 16:13:26 +000091 }
92 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +000093 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
94 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
95 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +000096 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +080097 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +000098 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Karl Zhangf6f467e2020-07-10 16:24:45 +080099 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Paul Sokolovskydaa430a2022-01-06 09:59:16 +0300100 params += string(name: 'CI_SCRIPTS_REPO', value: env.CI_SCRIPTS_REPO)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000101 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500102 params += string(name: 'MCUBOOT_REFSPEC', value: env.MCUBOOT_REFSPEC)
103 params += string(name: 'MCUBOOT_URL', value: env.MCUBOOT_URL)
104 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Paul Sokolovsky8d288712022-01-13 00:53:03 +0300105 params += string(name: 'MBEDTLS_URL', value: env.MBEDTLS_URL)
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500106 params += string(name: 'TFM_TESTS_REFSPEC', value: env.TFM_TESTS_REFSPEC)
107 params += string(name: 'TFM_TESTS_URL', value: env.TFM_TESTS_URL)
108 params += string(name: 'PSA_ARCH_TESTS_VERSION', value: env.PSA_ARCH_TESTS_VERSION)
109 params += string(name: 'PSA_ARCH_TESTS_URL', value: env.PSA_ARCH_TESTS_URL)
110 params += string(name: 'SHARE_FOLDER', value: env.SHARE_FOLDER)
Hugo L'Hostise55a2752021-01-27 11:09:08 +0000111 if (env.JOB_NAME.equals("tf-m-nightly")) { //Setting the Memory footprint gathering.
112 params += string(name: 'SQUAD_CONFIGURATIONS', value: env.SQUAD_CONFIGURATIONS)
113 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000114 return { -> results
115 def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000116 def build_url = build_res.getAbsoluteUrl()
Xinyu Zhang0aced4c2021-09-03 17:06:21 +0800117 results['builds'][build_res.number] = [build_res, config, params_collection]
118
Dean Bircha6ede7e2020-03-13 14:00:33 +0000119 print("${build_res.number}: ${config} ${build_res.result} ${build_url}")
Xinyu Zhangf2ba9112021-09-02 13:31:16 +0800120
121 // Filter out configs do not need LAVA tests
122
123 // Configs with build failure do not need LAVA tests
Xinyu Zhang6aa579a2022-04-20 11:36:27 +0800124 if (build_res.result in failure_states) {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000125 error("Build failed at ${build_url}")
Arthur She3c0dadd2021-11-18 21:17:48 -0800126 } else {
127 // Build successful
Xinyu Zhang6aa579a2022-04-20 11:36:27 +0800128 // Job tf-m-extra-build does not need LAVA tests
129 if (env.JOB_NAME.equals("tf-m-extra-build")) {
130 print("LAVA is not needed in tf-m-extra-build job.")
131 }
Xinyu Zhang22a12752022-10-10 17:21:21 +0800132 // Submit LAVA tests
133 else {
Arthur She3c0dadd2021-11-18 21:17:48 -0800134 submit_lava_tests(config, results, build_res, params, params_collection)
Arthur She3c0dadd2021-11-18 21:17:48 -0800135 }
Dean Birch62c4f082020-01-17 16:13:26 +0000136 }
137 }
138}
139
Matthew Hart06340d72020-06-15 16:08:20 +0100140def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000141 def params = []
142 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000143 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
144 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
145 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000146 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Dean Birch62c4f082020-01-17 16:13:26 +0000147 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Paul Sokolovskydaa430a2022-01-06 09:59:16 +0300148 params += string(name: 'CI_SCRIPTS_REPO', value: env.CI_SCRIPTS_REPO)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000149 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500150 params += string(name: 'SHARE_FOLDER', value: env.SHARE_FOLDER)
Matthew Hart06340d72020-06-15 16:08:20 +0100151 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +0000152 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
153 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +0100154 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +0000155 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +0000156 error("Build failed at ${res.getAbsoluteUrl()}")
157 }
158 }
159}
160
Xinyu Zhang38a18872020-11-23 16:45:28 +0800161def generateEmailBody(stage, failed_jobs) {
162 body = "Check console output at ${env.BUILD_URL} \n\n"
163
164 body += "Failed Jobs:\n"
165 failed_jobs.each { job ->
166 body += "${job.key} ${job.value}\n"
167 }
168
169 body += "\nFor detailed ${stage} results please refer to \
170 ${env.BUILD_URL}artifact/${stage}_results.csv \n"
171 return body
172}
173
174def emailNotification(results, stage, failed_jobs) {
Karl Zhang0413e972020-09-18 17:59:26 +0800175 script {
Xinyu Zhang953dc232022-09-07 18:27:35 +0800176 if (env.EMAIL_NOTIFICATION) {
Karl Zhang0413e972020-09-18 17:59:26 +0800177 def result = "Fail."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800178 if (results == true) {
Karl Zhang0413e972020-09-18 17:59:26 +0800179 result = "Success."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800180 print("Skip sending as ${result} for ${stage}")
181 }
182 else {
183 emailext (
184 subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} ${result}"),
Xinyu Zhang38a18872020-11-23 16:45:28 +0800185 body: generateEmailBody(stage, failed_jobs),
Karl Zhang182ecdf2020-10-10 09:52:12 +0800186 to: "${EMAIL_NOTIFICATION}"
187 )
188 }
Karl Zhang0413e972020-09-18 17:59:26 +0800189 }
190 } /* script */
191}
192
Xinyu Zhang38a18872020-11-23 16:45:28 +0800193def filterFailedBuild(results) {
194 def failed_builds = [:]
195 results.each { result ->
196 if (result.value[0].getResult() == "FAILURE") {
197 failed_builds[result.value[1]] = result.value[0].getAbsoluteUrl()
198 }
199 }
200 return failed_builds
201}
202
Xinyu Zhang82dab282022-10-09 16:33:19 +0800203def parseTestResults(output) {
204 // Verify test status
205 g = new Gerrit()
206 if (output.contains('FAILURE')) {
207 score = -1
208 } else {
209 score = 1
210 }
211 g.verifyStatus(score, "lava_test", "test")
212 if (score < 0) {
213 error("Marking job as failed due to failed boots: \"${boot_output}\" or tests: \"${test_output}\"")
214 }
215
216 // Generate test results summary
217 def test_results = [:]
218 records = output.split('\nLAVA Test Config:\n')
219 if (records.size() < 2) {
220 return test_results
221 }
222 records[1..-1].each { record ->
223 config_name = ""
224 metadata = [:]
225 record.split('\n').each { line ->
226 record_metadata = line.split(': ')
227 if (record_metadata[0] == 'Config Name') {
228 config_name = record_metadata[1]
229 } else {
230 metadata[record_metadata[0]] = record_metadata[1]
231 }
232 }
233 test_results[config_name] = metadata
234 }
235 return test_results
236}
237
Xinyu Zhang38a18872020-11-23 16:45:28 +0800238def filterFailedTest(string) {
239 def failed_tests = [:]
240 line = lineInString(string, "FAILURE_TESTS:")
Paul Sokolovskyc5cf9e62022-04-26 22:03:23 +0300241 if (line == null) {
242 return ["???"];
243 }
Xinyu Zhang38a18872020-11-23 16:45:28 +0800244 a = line.split(' ')
245 if (a.size() > 1) {
246 a = line.split(' ')[1..-1]
247 a.each { fail_test ->
248 config_link = fail_test.split(':')
249 failed_tests[config_link[0]] = config_link[1..-1].join(':')
250 }
251 }
252 return failed_tests
253}
254
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800255@NonCPS
256def generateCsvContent(results) {
257 def resultsParam = []
258 results.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800259 if (result.value[2]['BL2'] == "True") {
260 resultsParam.add([result.value[1], \
261 result.value[0].getResult(), \
262 result.value[2]['TFM_PLATFORM'], \
Xinyu Zhang433771e2022-04-01 16:49:17 +0800263 result.value[2]['COMPILER'].split('_')[0], \
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800264 result.value[2]['CMAKE_BUILD_TYPE'], \
265 result.value[2]['BL2'], \
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800266 result.value[2]['LIB_MODEL'], \
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800267 result.value[2]['ISOLATION_LEVEL'], \
268 result.value[2]['TEST_REGRESSION'], \
269 result.value[2]['TEST_PSA_API'], \
Xinyu Zhang589fd052022-04-19 17:54:16 +0800270 result.value[2]['PROFILE']])
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800271 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800272 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800273 resultsParam.each { result ->
Xinyu Zhang433771e2022-04-01 16:49:17 +0800274 result[3] = result[3].split('_')[0]
Xinyu Zhangfb80b5d2022-07-26 15:42:26 +0800275 build_params = result[6..10]
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800276 configName = ""
277 for (map_cfg in mapConfigs) {
Xinyu Zhang3f7e2f52021-09-02 13:43:57 +0800278 if (build_params[0..4] == map_cfg[0..4]) {
279 configName = map_cfg[5]
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800280 break
281 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800282 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800283 if (configName == "") {
284 configName = "Default"
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800285 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800286 else if (configName == "RegressionProfileM") {
Xinyu Zhang3f7e2f52021-09-02 13:43:57 +0800287 if (build_params[5] == "OFF") {
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800288 configName = "RegressionProfileM PSOFF"
289 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800290 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800291 result.add(configName)
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800292 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800293 def csvContent = []
294 resultsParam.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800295 current_row = result[2..4]
296 cfgs.each {cfg ->
Xinyu Zhangfb80b5d2022-07-26 15:42:26 +0800297 if (cfg == result[11]) {
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800298 current_row.add(cfg)
299 current_row.add(result[1])
300 }
301 }
302 csvContent.add(current_row)
303 }
304 csvContent.sort{a,b -> a[0] <=> b[0] ?: a[1] <=> b[1] ?: a[2] <=> b[2]}
305 build_summary = []
306 current_platform = ""
307 current_compiler = ""
308 current_build_type = ""
309 csvContent.each { build_cfg ->
310 if (current_platform != build_cfg[0] || \
311 current_compiler != build_cfg[1] || \
312 current_build_type != build_cfg[2]) {
313 current_platform = build_cfg[0]
314 current_compiler = build_cfg[1]
315 current_build_type = build_cfg[2]
316 csv_line = [current_platform, current_compiler, current_build_type]
317 cfgs.each {
318 csv_line.add("N.A.")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800319 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800320 build_summary.add(csv_line)
321 }
322 i = 0
323 cfgs.each { cfg ->
324 if (cfg == build_cfg[3]) {
325 build_summary[-1][3+i] = build_cfg[4]
326 }
327 i += 1
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800328 }
329 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800330 build_summary.add(0, ['Platform', 'Compiler', 'Cmake Build Type'])
331 build_summary[0] += cfgs
332 return build_summary
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800333}
334
335def generateBuildCsv(results) {
336 def csvContent = generateCsvContent(results)
337 node("master") {
338 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
339 archiveArtifacts 'build_results.csv'
340 }
341}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000342
343def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000344 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000345 def csvContent = summary.getBuildCsv(results)
346 node("master") {
347 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
348 archiveArtifacts 'build_results.csv'
349 }
350}
351
352def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000353 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000354 def buildLinks = summary.getLinks(results)
355 node("master") {
356 writeFile file: "build_links.html", text: buildLinks
357 archiveArtifacts 'build_links.html'
358 }
359}
360
Matthew Hartfb6fd362020-03-04 21:03:59 +0000361def lineInString(string, match) {
362 def lines = string.split("\n")
363 def result = lines.findAll { it.contains(match) }
364 return result[0]
365}
366
367def getResult(string, match) {
368 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100369 a = line.split(match)[1].split(' ')
370 score = a[0]
371 if (a.size() > 1)
372 {
373 fail_text = a[1..-1].join(" ")
374 return [score, fail_text]
375 }
376 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000377}
378
379def submitJobsToList(results) {
380 def all_jobs = []
381 for (String result : results){
382 jobs_s = result.split('JOBS: ')
383 if (jobs_s.size() > 1) {
384 all_jobs += jobs_s[1]
385 }
386 }
387 return(all_jobs)
388}
389
Dean Birch62c4f082020-01-17 16:13:26 +0000390def configs = []
391def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000392def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000393
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800394timestamps {
395 node("docker-amd64-tf-m-bionic") {
396 stage("Init") {
397 cleanWs()
398 dir("tf-m-ci-scripts") {
399 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
Xinyu Zhang8472b852021-09-04 00:13:34 +0800400 sh "git rev-parse --short HEAD"
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500401 // Clone TF-M repositories so share folder can be reused by downstream jobs
402 sh "./clone.sh"
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800403 }
404 }
Xinyu Zhang6b456c22022-10-13 15:48:58 +0800405
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800406 stage("Configs") {
407 // Populate configs
408 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
409 results['builds'] = [:]
410 results['lava_jobs'] = []
411 for (config in configs) {
412 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
413 }
Xinyu Zhang351f14c2021-11-15 14:30:09 +0800414 if (!env.JOB_NAME.equals("tf-m-extra-build")) {
415 builds["docs"] = buildDocs(results)
416 }
Dean Birch62c4f082020-01-17 16:13:26 +0000417 }
Karl Zhangfec84102020-06-24 09:56:36 +0800418
Xinyu Zhang6b456c22022-10-13 15:48:58 +0800419 stage("Builds") {
420 def verify = 1
421 def success = true
422 try {
423 parallel(builds)
424 } catch (Exception e) {
425 print(e)
426 manager.buildFailure()
427 verify = -1
428 success = false
429 } finally {
430 print("Verifying status")
431 def failed_builds = filterFailedBuild(results['builds'])
432 emailNotification(success, 'build', failed_builds)
433 g = new Gerrit()
434 g.verifyStatus(verify, 'tf-m-build', 'build')
435 print("Building CSV")
436 generateBuildCsv(results['builds'])
437 writeSummary(results['builds'])
438 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800439 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800440
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800441 stage("Tests") {
442 dir("tf-m-ci-scripts") {
443 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
444 }
445 def all_jobs = []
446 def success = true
447 print("Wait for LAVA results here...")
448 try {
449 all_jobs = submitJobsToList(results['lava_jobs'])
Paul Sokolovsky437bc422022-02-01 17:57:13 +0300450 output = ""
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800451 if (all_jobs.size() > 0) {
Paul Sokolovsky3d522f72022-04-13 11:17:00 +0300452 dir(".") {
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800453 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Paul Sokolovsky3d522f72022-04-13 11:17:00 +0300454 output = sh(script: """./tf-m-ci-scripts/lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
Xinyu Zhang6b456c22022-10-13 15:48:58 +0800455 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
456 --artifacts-path cfgs --lava-timeout 12000 \
457 """, returnStdout: true).trim()
Paul Sokolovsky1b024ac2022-02-01 22:26:23 +0300458 println("--- output from lava_wait_jobs.py ---")
Xinyu Zhange9033f62022-10-08 11:15:27 +0800459 println(output)
Paul Sokolovsky1b024ac2022-02-01 22:26:23 +0300460 println("--- end of output from lava_wait_jobs.py ---")
Xinyu Zhang82dab282022-10-09 16:33:19 +0800461 parseTestResults(output)
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800462 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
463 archiveArtifacts artifacts: 'test_results.csv', allowEmptyArchive: true
Paul Sokolovsky0136de02022-04-19 20:21:47 +0300464
465 if (env.CODE_COVERAGE_EN == "TRUE") {
466 println("Producing merged report")
467 sh(script: """./tf-m-ci-scripts/lava_helper/codecov_merge.sh""")
468 archiveArtifacts artifacts: 'merged_report/**', allowEmptyArchive: true
469 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000470 }
471 }
472 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800473 else {
474 print("There were no LAVA jobs to test.")
475 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000476 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800477 catch (Exception e) {
478 print("ERROR: ${e}")
479 success = false
480 } finally {
Paul Sokolovsky3d522f72022-04-13 11:17:00 +0300481 archiveArtifacts artifacts: 'cfgs/**', allowEmptyArchive: true
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800482 if (all_jobs.size() > 0) {
483 emailNotification(success, 'test', filterFailedTest(output))
484 }
485 cleanWs()
486 if (!success) {
487 error("There was an Error waiting for LAVA jobs")
488 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000489 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000490 }
491 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000492}