blob: e779acd28ce89370fb05238d39b455b9e6a695cb [file] [log] [blame]
Dean Birch62c4f082020-01-17 16:13:26 +00001#!/usr/bin/env groovy
2//-------------------------------------------------------------------------------
Paul Sokolovskye1ad4772024-03-07 00:08:27 +07003// Copyright (c) 2020-2024, 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
Dean Bircha6ede7e2020-03-13 14:00:33 +000011
Xinyu Zhang0aced4c2021-09-03 17:06:21 +080012failure_states = ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]
13
Xinyu Zhang29a57cc2023-02-03 10:08:48 +080014@NonCPS
15def isPerPatchJob() {
16 def upstream_jobs = manager.build.getAction(hudson.model.CauseAction.class).getCauses()
17 if (upstream_jobs.size() > 0 && upstream_jobs[0] instanceof hudson.model.Cause.UpstreamCause) {
18 print("Parent project cause: ")
19 println(upstream_jobs[0].upstreamProject)
20 if (upstream_jobs[0].upstreamProject.endsWith("tf-m-static")) {
21 return true
22 }
23 }
24 return false
25}
26
Xinyu Zhang0aced4c2021-09-03 17:06:21 +080027def submit_lava_tests(config, results, build_res, params, params_collection) {
28 print("Doing LAVA stuff for ${build_res.getAbsoluteUrl()}")
Xinyu Zhang0aced4c2021-09-03 17:06:21 +080029 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
30 params += string(name: 'BUILD_URL', value: build_res.getAbsoluteUrl())
31 params += string(name: 'LAVA_URL', value: env.LAVA_URL)
Paul Sokolovskydaa430a2022-01-06 09:59:16 +030032 params += string(name: 'CI_SCRIPTS_REPO', value: env.CI_SCRIPTS_REPO)
Xinyu Zhang0aced4c2021-09-03 17:06:21 +080033 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
34 params += string(name: 'LAVA_CREDENTIALS', value: env.LAVA_CREDENTIALS)
35 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Xinyu Zhang0c8d3202022-10-19 14:42:47 +080036 params += string(name: 'DEVICE_FILTER', value: env.DEVICE_FILTER)
Paul Sokolovskyfb0c6ad2024-03-11 12:53:17 +070037 params += string(name: 'USE_TUXSUITE_FVP', value: env.USE_TUXSUITE_FVP)
Xinyu Zhang0aced4c2021-09-03 17:06:21 +080038 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
39 def lava_resubmitted = false
40 if (lava_res.result in failure_states) {
41 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
42 } else {
43 lava_des = lava_res.getDescription()
44 if (lava_des.contains(" Submitted twice!")) {
45 lava_resubmitted = true
46 lava_des = lava_des - " Submitted twice!"
47 }
48 results['lava_jobs'] += lava_des
49 }
50 links = "Build Config: ${config}\n"
51 links += "Build URL: ${build_res.getAbsoluteUrl()}\n"
52 links += "LAVA Submit: ${lava_res.getAbsoluteUrl()}"
53 if (lava_resubmitted) {
54 links += "\nLAVA Job Re-Submitted!"
55 }
56 print(links)
57}
58
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +080059def listConfigs(config_list, filter_group) {
Xinyu Zhang9c1006e2023-09-11 11:05:49 +080060 // In case filter group starts with spaces
61 config_groups = filter_group.replaceAll(/^\s+/, '')
62 // In case filter group ends with spaces
63 config_groups = config_groups.replaceAll(/\s+$/, '')
64 // Replace spaces between config group names with ' -g '
65 config_groups = config_groups.replaceAll(/\s+/, " -g ")
66
Xinyu Zhang4b109802022-10-18 17:22:07 +080067 def build_config_list_raw = sh(script:
68 """
Xinyu Zhang9c1006e2023-09-11 11:05:49 +080069 python3 ./tf-m-ci-scripts/configs.py -g ${config_groups}\n
Xinyu Zhang4b109802022-10-18 17:22:07 +080070 """, returnStdout: true).trim()
71 def build_config_list = build_config_list_raw.tokenize('\n')
72 config_list.addAll(build_config_list)
Dean Birch62c4f082020-01-17 16:13:26 +000073}
74
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +080075def obtainBuildParams(config) {
76 def build_params = [:]
Xinyu Zhang4b109802022-10-18 17:22:07 +080077 build_config_params = sh(script:
78 """
Xinyu Zhang46b37182023-06-30 15:36:44 +080079 python3 ./tf-m-ci-scripts/configs.py --config_params ${config}\n
Xinyu Zhang4b109802022-10-18 17:22:07 +080080 """, returnStdout: true).trim()
Dean Birch62c4f082020-01-17 16:13:26 +000081 def lines = build_config_params.tokenize('\n')
82 for (String line : lines) {
83 def key, value
84 (key, value) = line.tokenize('=')
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +080085 build_params[key] = value
86 }
87 return build_params
88}
89
90def buildConfig(config, results) {
91 def params = []
92 params_collection = obtainBuildParams(config)
93 params_collection.each { param ->
94 params += string(name: param.key, value:param.value)
Dean Birch62c4f082020-01-17 16:13:26 +000095 }
96 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +000097 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
98 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
99 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000100 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800101 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000102 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Karl Zhangf6f467e2020-07-10 16:24:45 +0800103 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Paul Sokolovskydaa430a2022-01-06 09:59:16 +0300104 params += string(name: 'CI_SCRIPTS_REPO', value: env.CI_SCRIPTS_REPO)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000105 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500106 params += string(name: 'MCUBOOT_REFSPEC', value: env.MCUBOOT_REFSPEC)
107 params += string(name: 'MCUBOOT_URL', value: env.MCUBOOT_URL)
108 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Paul Sokolovsky8d288712022-01-13 00:53:03 +0300109 params += string(name: 'MBEDTLS_URL', value: env.MBEDTLS_URL)
Bence Balogh79fda442022-10-14 18:01:37 +0200110 params += string(name: 'TFM_EXTRAS_REFSPEC', value: env.TFM_EXTRAS_REFSPEC)
111 params += string(name: 'TFM_EXTRAS_URL', value: env.TFM_EXTRAS_URL)
Jianliang Shen5492f752023-07-27 15:59:01 +0800112 params += string(name: 'TFM_TOOLS_REFSPEC', value: env.TFM_TOOLS_REFSPEC)
113 params += string(name: 'TFM_TOOLS_URL', value: env.TFM_TOOLS_URL)
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500114 params += string(name: 'TFM_TESTS_REFSPEC', value: env.TFM_TESTS_REFSPEC)
115 params += string(name: 'TFM_TESTS_URL', value: env.TFM_TESTS_URL)
116 params += string(name: 'PSA_ARCH_TESTS_VERSION', value: env.PSA_ARCH_TESTS_VERSION)
117 params += string(name: 'PSA_ARCH_TESTS_URL', value: env.PSA_ARCH_TESTS_URL)
Xinyu Zhangc7ad0822022-11-23 17:54:26 +0800118 params += string(name: 'QCBOR_VERSION', value: env.QCBOR_VERSION)
119 params += string(name: 'QCBOR_URL', value: env.QCBOR_URL)
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500120 params += string(name: 'SHARE_FOLDER', value: env.SHARE_FOLDER)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000121 return { -> results
122 def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000123 def build_url = build_res.getAbsoluteUrl()
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800124 results['builds'][config] = build_res
Xinyu Zhang0aced4c2021-09-03 17:06:21 +0800125
Dean Bircha6ede7e2020-03-13 14:00:33 +0000126 print("${build_res.number}: ${config} ${build_res.result} ${build_url}")
Xinyu Zhangf2ba9112021-09-02 13:31:16 +0800127
128 // Filter out configs do not need LAVA tests
129
130 // Configs with build failure do not need LAVA tests
Xinyu Zhang6aa579a2022-04-20 11:36:27 +0800131 if (build_res.result in failure_states) {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000132 error("Build failed at ${build_url}")
Arthur She3c0dadd2021-11-18 21:17:48 -0800133 } else {
134 // Build successful
Xinyu Zhang6aa579a2022-04-20 11:36:27 +0800135 // Job tf-m-extra-build does not need LAVA tests
136 if (env.JOB_NAME.equals("tf-m-extra-build")) {
137 print("LAVA is not needed in tf-m-extra-build job.")
138 }
Xinyu Zhang22a12752022-10-10 17:21:21 +0800139 // Submit LAVA tests
140 else {
Arthur She3c0dadd2021-11-18 21:17:48 -0800141 submit_lava_tests(config, results, build_res, params, params_collection)
Arthur She3c0dadd2021-11-18 21:17:48 -0800142 }
Dean Birch62c4f082020-01-17 16:13:26 +0000143 }
144 }
145}
146
Matthew Hart06340d72020-06-15 16:08:20 +0100147def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000148 def params = []
149 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000150 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
151 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
152 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000153 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Dean Birch62c4f082020-01-17 16:13:26 +0000154 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Paul Sokolovskydaa430a2022-01-06 09:59:16 +0300155 params += string(name: 'CI_SCRIPTS_REPO', value: env.CI_SCRIPTS_REPO)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000156 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500157 params += string(name: 'SHARE_FOLDER', value: env.SHARE_FOLDER)
Matthew Hart06340d72020-06-15 16:08:20 +0100158 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +0000159 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
160 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +0100161 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +0000162 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +0000163 error("Build failed at ${res.getAbsoluteUrl()}")
164 }
165 }
166}
167
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800168def generateEmailBody(stage, results) {
169 // Results format: [CONFIG_NAME: [URL: "", RESULT: "", ...]]
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800170 failed_jobs = ""
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800171 results.each { job ->
172 if (job.value['RESULT'] == 'FAILURE') {
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800173 failed_jobs += "${job.key} ${job.value['URL']}\n"
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800174 }
Xinyu Zhang38a18872020-11-23 16:45:28 +0800175 }
176
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800177 if (failed_jobs == "") {
178 return ""
179 }
180
181 body = "Check console output at ${env.BUILD_URL} \n\n"
182 body += "Failed Jobs:\n${failed_jobs}"
Xinyu Zhang38a18872020-11-23 16:45:28 +0800183 body += "\nFor detailed ${stage} results please refer to \
184 ${env.BUILD_URL}artifact/${stage}_results.csv \n"
185 return body
186}
187
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800188def emailNotification(stage, results) {
Karl Zhang0413e972020-09-18 17:59:26 +0800189 script {
Xinyu Zhang953dc232022-09-07 18:27:35 +0800190 if (env.EMAIL_NOTIFICATION) {
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800191 email_body = generateEmailBody(stage, results)
192 if (email_body == "") {
193 print("Skip sending email notification as no failed jobs for ${stage}")
Karl Zhang182ecdf2020-10-10 09:52:12 +0800194 }
195 else {
196 emailext (
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800197 subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} fail"),
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800198 body: email_body,
Karl Zhang182ecdf2020-10-10 09:52:12 +0800199 to: "${EMAIL_NOTIFICATION}"
200 )
201 }
Karl Zhang0413e972020-09-18 17:59:26 +0800202 }
203 } /* script */
204}
205
Xinyu Zhang82dab282022-10-09 16:33:19 +0800206def parseTestResults(output) {
Xinyu Zhang82dab282022-10-09 16:33:19 +0800207 def test_results = [:]
208 records = output.split('\nLAVA Test Config:\n')
209 if (records.size() < 2) {
210 return test_results
211 }
212 records[1..-1].each { record ->
213 config_name = ""
214 metadata = [:]
215 record.split('\n').each { line ->
216 record_metadata = line.split(': ')
Paul Sokolovsky412d62a2022-12-02 21:35:22 +0300217 // Skip lines which are not "metadata"
218 if (record_metadata.size() < 2) {
219 return
220 }
Xinyu Zhang82dab282022-10-09 16:33:19 +0800221 if (record_metadata[0] == 'Config Name') {
222 config_name = record_metadata[1]
223 } else {
224 metadata[record_metadata[0]] = record_metadata[1]
225 }
226 }
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800227 test_results[config_name] = ['URL': metadata['LAVA link'],
228 'RESULT': metadata['Test Result']]
Xinyu Zhang82dab282022-10-09 16:33:19 +0800229 }
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800230
231 writeCsv(test_results, "test_results.csv")
232
Xinyu Zhang82dab282022-10-09 16:33:19 +0800233 return test_results
234}
235
Xinyu Zhang57d2d8c2022-10-24 14:27:30 +0800236def verifyTestStatus(output) {
237 g = new Gerrit()
238 if (output.contains('FAILURE')) {
239 score = -1
240 } else {
241 score = 1
242 }
243 g.verifyStatus(score, "lava_test", "test")
244 if (score < 0) {
245 error("Marking job as failed due to failed tests.")
246 }
247}
248
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800249def generateCsvContent(results) {
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800250 // Results format: [CONFIG_NAME: [URL: "", RESULT: "", ...]]
251 // CSV format: CONFIG_NAME, RESULT
252 csv_header = obtainBuildParams(results.keySet()[0]).keySet().toList()
253 csv_header.add('RESULT')
254 csv_content = [csv_header]
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800255 results.each { result ->
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800256 build_params = []
257 obtainBuildParams(result.key).each { config ->
258 build_params.add(config.value)
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800259 }
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800260 build_params.add(result.value['RESULT'])
261 csv_content.add(build_params)
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800262 }
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800263 return csv_content
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800264}
265
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800266def generateHtmlContent(results) {
267 // Results format: [CONFIG_NAME: [URL: "", RESULT: "", ...]]
268 // HTML format: CONFIG_NAME: Job/Logs/Artifacts RESULT
269 htmlContent = []
270 results.each { result ->
271 htmlContent.add("${result.key}: <a href=\"${result.value['URL']}\">Job</a>/<a href=\"${result.value['URL']}/consoleText\">Logs</a>/<a href=\"${result.value['URL']}/artifact/\">Artifacts</a> ${result.value['RESULT']}<br/>")
272 }
273 htmlContent.sort()
274 return htmlContent.join("\n")
275}
276
277def writeCsv(results, file_name) {
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800278 def csvContent = generateCsvContent(results)
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800279 writeCSV file: file_name, records: csvContent, format: CSVFormat.EXCEL
280 sh(script: """./tf-m-ci-scripts/report_parser/report_csv_helper.py \
281 --input-file ${file_name} --output-file ${file_name} \
282 """, returnStdout: true)
283 archiveArtifacts file_name
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800284}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000285
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800286def writeHTML(results, file_name) {
287def buildLinks = generateHtmlContent(results)
288 writeFile file: file_name, text: buildLinks
289 archiveArtifacts file_name
Dean Bircha6ede7e2020-03-13 14:00:33 +0000290}
291
Matthew Hartfb6fd362020-03-04 21:03:59 +0000292def lineInString(string, match) {
293 def lines = string.split("\n")
294 def result = lines.findAll { it.contains(match) }
295 return result[0]
296}
297
298def getResult(string, match) {
299 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100300 a = line.split(match)[1].split(' ')
301 score = a[0]
302 if (a.size() > 1)
303 {
304 fail_text = a[1..-1].join(" ")
305 return [score, fail_text]
306 }
307 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000308}
309
310def submitJobsToList(results) {
311 def all_jobs = []
312 for (String result : results){
313 jobs_s = result.split('JOBS: ')
314 if (jobs_s.size() > 1) {
315 all_jobs += jobs_s[1]
316 }
317 }
318 return(all_jobs)
319}
320
Dean Birch62c4f082020-01-17 16:13:26 +0000321def configs = []
322def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000323def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000324
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800325timestamps {
Paul Sokolovskye1ad4772024-03-07 00:08:27 +0700326 node("docker-amd64-tf-m-jammy") {
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800327 stage("Init") {
328 cleanWs()
329 dir("tf-m-ci-scripts") {
330 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
Xinyu Zhang8472b852021-09-04 00:13:34 +0800331 sh "git rev-parse --short HEAD"
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500332 // Clone TF-M repositories so share folder can be reused by downstream jobs
333 sh "./clone.sh"
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800334 }
335 }
Xinyu Zhang6b456c22022-10-13 15:48:58 +0800336
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800337 stage("Configs") {
Xinyu Zhang4b109802022-10-18 17:22:07 +0800338 dir(".") {
339 // Populate configs
340 listConfigs(configs, env.FILTER_GROUP)
341 results['builds'] = [:]
342 results['lava_jobs'] = []
343 for (config in configs) {
344 builds[config] = buildConfig(config, results)
345 }
346 if (!env.JOB_NAME.equals("tf-m-extra-build")) {
347 builds["docs"] = buildDocs(results)
348 }
Xinyu Zhang351f14c2021-11-15 14:30:09 +0800349 }
Dean Birch62c4f082020-01-17 16:13:26 +0000350 }
Karl Zhangfec84102020-06-24 09:56:36 +0800351
Xinyu Zhang6b456c22022-10-13 15:48:58 +0800352 stage("Builds") {
353 def verify = 1
354 def success = true
Xinyu Zhang4b109802022-10-18 17:22:07 +0800355 dir(".") {
356 try {
357 parallel(builds)
358 } catch (Exception e) {
359 print(e)
360 manager.buildFailure()
361 verify = -1
362 success = false
363 } finally {
364 print("Verifying status")
365 g = new Gerrit()
366 g.verifyStatus(verify, 'tf-m-build', 'build')
367 print("Generating build results summary.")
368 def build_results_for_summary = [:]
369 results['builds'].each { build ->
Xinyu Zhang0d85cc32022-10-19 17:58:32 +0800370 build_results_for_summary[build.key] = ['URL': build.value.getAbsoluteUrl(),
371 'RESULT': build.value.result]
Xinyu Zhang4b109802022-10-18 17:22:07 +0800372 }
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800373 emailNotification('build', build_results_for_summary)
Xinyu Zhang4b109802022-10-18 17:22:07 +0800374 writeCsv(build_results_for_summary, "build_results.csv")
375 writeHTML(build_results_for_summary, "build_links.html")
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800376 }
Xinyu Zhang6b456c22022-10-13 15:48:58 +0800377 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800378 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800379
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800380 stage("Tests") {
381 dir("tf-m-ci-scripts") {
382 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
383 }
384 def all_jobs = []
385 def success = true
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800386 def test_results = [:]
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800387 print("Wait for LAVA results here...")
388 try {
389 all_jobs = submitJobsToList(results['lava_jobs'])
Paul Sokolovsky437bc422022-02-01 17:57:13 +0300390 output = ""
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800391 if (all_jobs.size() > 0) {
Paul Sokolovsky3d522f72022-04-13 11:17:00 +0300392 dir(".") {
Xinyu Zhang29a57cc2023-02-03 10:08:48 +0800393 if (isPerPatchJob()) {
394 lava_timeout = 2700 // 45min
395 } else {
Paul Sokolovsky288799c2023-03-20 21:19:58 +0700396 lava_timeout = 19800 // 5.5h
Xinyu Zhang29a57cc2023-02-03 10:08:48 +0800397 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800398 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Xinyu Zhang0b84b632023-02-08 14:15:08 +0800399 sh(script: """./tf-m-ci-scripts/lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
Paul Sokolovsky7dc8bdf2024-03-25 12:25:29 +0700400 --lava-url ${env.LAVA_URL} --lava-user \${LAVA_USER} --lava-token \${LAVA_TOKEN} \
Xinyu Zhang0b84b632023-02-08 14:15:08 +0800401 --artifacts-path cfgs --lava-timeout ${lava_timeout} > output.log
402 """)
Paul Sokolovsky0136de02022-04-19 20:21:47 +0300403 if (env.CODE_COVERAGE_EN == "TRUE") {
404 println("Producing merged report")
405 sh(script: """./tf-m-ci-scripts/lava_helper/codecov_merge.sh""")
406 archiveArtifacts artifacts: 'merged_report/**', allowEmptyArchive: true
407 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000408 }
Xinyu Zhang6fd6d332023-10-19 10:12:22 +0800409 if (env.JOB_NAME.equals("tf-m-nightly-performance")) {
410 withCredentials([string(credentialsId: 'QA_REPORTS_TOKEN', variable: 'TOKEN')]) {
411 sh(script: """./tf-m-ci-scripts/performance.py --send-squad --squad-token ${TOKEN} > SQUAD.log""")
412 }
Jianliang Shen48704152023-10-17 17:06:00 +0800413 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000414 }
415 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800416 else {
417 print("There were no LAVA jobs to test.")
418 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000419 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800420 catch (Exception e) {
Paul Sokolovsky2cf562a2022-12-02 15:10:58 +0300421 println("ERROR: ${e}")
422 // We don't print stacktrace, because Jenkins pipeline use CPS conversion
423 // of the Groovy code, which leads to incomprehensible stacktraces.
424 //print(hudson.Functions.printThrowable(org.codehaus.groovy.runtime.StackTraceUtils.sanitize(e)))
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800425 success = false
426 } finally {
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800427 if (all_jobs.size() > 0) {
Xinyu Zhang68858312023-02-23 11:11:09 +0800428 output = readFile("output.log")
429 println("--- output from lava_wait_jobs.py ---")
430 println(output)
431 println("--- end of output from lava_wait_jobs.py ---")
Xinyu Zhang808f9772023-10-19 10:57:40 +0800432 test_results = parseTestResults(output)
433
434 if (env.JOB_NAME.equals("tf-m-nightly-performance")) {
435 performance_output = readFile("SQUAD.log")
436 println("--- output from performance.py ---")
437 println(performance_output)
438 println("--- end of output from performance.py ---")
439 }
440
Xinyu Zhang68858312023-02-23 11:11:09 +0800441 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
442 archiveArtifacts artifacts: 'cfgs/**', allowEmptyArchive: true
443 if (all_jobs.size() > 0) {
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800444 emailNotification('test', test_results)
Xinyu Zhang68858312023-02-23 11:11:09 +0800445 }
446 verifyTestStatus(output)
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800447 }
448 cleanWs()
449 if (!success) {
450 error("There was an Error waiting for LAVA jobs")
451 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000452 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000453 }
454 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000455}