blob: 74626321c48475ded4860fdd260bad7c77beef39 [file] [log] [blame]
Dean Birch62c4f082020-01-17 16:13:26 +00001#!/usr/bin/env groovy
2//-------------------------------------------------------------------------------
Xinyu Zhang29a57cc2023-02-03 10:08:48 +08003// Copyright (c) 2020-2023, 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)
Xinyu Zhang0aced4c2021-09-03 17:06:21 +080037 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
38 def lava_resubmitted = false
39 if (lava_res.result in failure_states) {
40 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
41 } else {
42 lava_des = lava_res.getDescription()
43 if (lava_des.contains(" Submitted twice!")) {
44 lava_resubmitted = true
45 lava_des = lava_des - " Submitted twice!"
46 }
47 results['lava_jobs'] += lava_des
48 }
49 links = "Build Config: ${config}\n"
50 links += "Build URL: ${build_res.getAbsoluteUrl()}\n"
51 links += "LAVA Submit: ${lava_res.getAbsoluteUrl()}"
52 if (lava_resubmitted) {
53 links += "\nLAVA Job Re-Submitted!"
54 }
55 print(links)
56}
57
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +080058def listConfigs(config_list, filter_group) {
Xinyu Zhang9c1006e2023-09-11 11:05:49 +080059 // In case filter group starts with spaces
60 config_groups = filter_group.replaceAll(/^\s+/, '')
61 // In case filter group ends with spaces
62 config_groups = config_groups.replaceAll(/\s+$/, '')
63 // Replace spaces between config group names with ' -g '
64 config_groups = config_groups.replaceAll(/\s+/, " -g ")
65
Xinyu Zhang4b109802022-10-18 17:22:07 +080066 def build_config_list_raw = sh(script:
67 """
Xinyu Zhang9c1006e2023-09-11 11:05:49 +080068 python3 ./tf-m-ci-scripts/configs.py -g ${config_groups}\n
Xinyu Zhang4b109802022-10-18 17:22:07 +080069 """, returnStdout: true).trim()
70 def build_config_list = build_config_list_raw.tokenize('\n')
71 config_list.addAll(build_config_list)
Dean Birch62c4f082020-01-17 16:13:26 +000072}
73
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +080074def obtainBuildParams(config) {
75 def build_params = [:]
Xinyu Zhang4b109802022-10-18 17:22:07 +080076 build_config_params = sh(script:
77 """
Xinyu Zhang46b37182023-06-30 15:36:44 +080078 python3 ./tf-m-ci-scripts/configs.py --config_params ${config}\n
Xinyu Zhang4b109802022-10-18 17:22:07 +080079 """, returnStdout: true).trim()
Dean Birch62c4f082020-01-17 16:13:26 +000080 def lines = build_config_params.tokenize('\n')
81 for (String line : lines) {
82 def key, value
83 (key, value) = line.tokenize('=')
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +080084 build_params[key] = value
85 }
86 return build_params
87}
88
89def buildConfig(config, results) {
90 def params = []
91 params_collection = obtainBuildParams(config)
92 params_collection.each { param ->
93 params += string(name: param.key, value:param.value)
Dean Birch62c4f082020-01-17 16:13:26 +000094 }
95 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +000096 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
97 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
98 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +000099 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800100 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000101 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Karl Zhangf6f467e2020-07-10 16:24:45 +0800102 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Paul Sokolovskydaa430a2022-01-06 09:59:16 +0300103 params += string(name: 'CI_SCRIPTS_REPO', value: env.CI_SCRIPTS_REPO)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000104 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500105 params += string(name: 'MCUBOOT_REFSPEC', value: env.MCUBOOT_REFSPEC)
106 params += string(name: 'MCUBOOT_URL', value: env.MCUBOOT_URL)
107 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Paul Sokolovsky8d288712022-01-13 00:53:03 +0300108 params += string(name: 'MBEDTLS_URL', value: env.MBEDTLS_URL)
Bence Balogh79fda442022-10-14 18:01:37 +0200109 params += string(name: 'TFM_EXTRAS_REFSPEC', value: env.TFM_EXTRAS_REFSPEC)
110 params += string(name: 'TFM_EXTRAS_URL', value: env.TFM_EXTRAS_URL)
Jianliang Shen5492f752023-07-27 15:59:01 +0800111 params += string(name: 'TFM_TOOLS_REFSPEC', value: env.TFM_TOOLS_REFSPEC)
112 params += string(name: 'TFM_TOOLS_URL', value: env.TFM_TOOLS_URL)
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500113 params += string(name: 'TFM_TESTS_REFSPEC', value: env.TFM_TESTS_REFSPEC)
114 params += string(name: 'TFM_TESTS_URL', value: env.TFM_TESTS_URL)
115 params += string(name: 'PSA_ARCH_TESTS_VERSION', value: env.PSA_ARCH_TESTS_VERSION)
116 params += string(name: 'PSA_ARCH_TESTS_URL', value: env.PSA_ARCH_TESTS_URL)
Xinyu Zhangc7ad0822022-11-23 17:54:26 +0800117 params += string(name: 'QCBOR_VERSION', value: env.QCBOR_VERSION)
118 params += string(name: 'QCBOR_URL', value: env.QCBOR_URL)
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500119 params += string(name: 'SHARE_FOLDER', value: env.SHARE_FOLDER)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000120 return { -> results
121 def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000122 def build_url = build_res.getAbsoluteUrl()
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800123 results['builds'][config] = build_res
Xinyu Zhang0aced4c2021-09-03 17:06:21 +0800124
Dean Bircha6ede7e2020-03-13 14:00:33 +0000125 print("${build_res.number}: ${config} ${build_res.result} ${build_url}")
Xinyu Zhangf2ba9112021-09-02 13:31:16 +0800126
127 // Filter out configs do not need LAVA tests
128
129 // Configs with build failure do not need LAVA tests
Xinyu Zhang6aa579a2022-04-20 11:36:27 +0800130 if (build_res.result in failure_states) {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000131 error("Build failed at ${build_url}")
Arthur She3c0dadd2021-11-18 21:17:48 -0800132 } else {
133 // Build successful
Xinyu Zhang6aa579a2022-04-20 11:36:27 +0800134 // Job tf-m-extra-build does not need LAVA tests
135 if (env.JOB_NAME.equals("tf-m-extra-build")) {
136 print("LAVA is not needed in tf-m-extra-build job.")
137 }
Xinyu Zhang22a12752022-10-10 17:21:21 +0800138 // Submit LAVA tests
139 else {
Arthur She3c0dadd2021-11-18 21:17:48 -0800140 submit_lava_tests(config, results, build_res, params, params_collection)
Arthur She3c0dadd2021-11-18 21:17:48 -0800141 }
Dean Birch62c4f082020-01-17 16:13:26 +0000142 }
143 }
144}
145
Matthew Hart06340d72020-06-15 16:08:20 +0100146def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000147 def params = []
148 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000149 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
150 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
151 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000152 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Dean Birch62c4f082020-01-17 16:13:26 +0000153 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Paul Sokolovskydaa430a2022-01-06 09:59:16 +0300154 params += string(name: 'CI_SCRIPTS_REPO', value: env.CI_SCRIPTS_REPO)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000155 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500156 params += string(name: 'SHARE_FOLDER', value: env.SHARE_FOLDER)
Matthew Hart06340d72020-06-15 16:08:20 +0100157 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +0000158 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
159 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +0100160 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +0000161 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +0000162 error("Build failed at ${res.getAbsoluteUrl()}")
163 }
164 }
165}
166
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800167def generateEmailBody(stage, results) {
168 // Results format: [CONFIG_NAME: [URL: "", RESULT: "", ...]]
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800169 failed_jobs = ""
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800170 results.each { job ->
171 if (job.value['RESULT'] == 'FAILURE') {
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800172 failed_jobs += "${job.key} ${job.value['URL']}\n"
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800173 }
Xinyu Zhang38a18872020-11-23 16:45:28 +0800174 }
175
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800176 if (failed_jobs == "") {
177 return ""
178 }
179
180 body = "Check console output at ${env.BUILD_URL} \n\n"
181 body += "Failed Jobs:\n${failed_jobs}"
Xinyu Zhang38a18872020-11-23 16:45:28 +0800182 body += "\nFor detailed ${stage} results please refer to \
183 ${env.BUILD_URL}artifact/${stage}_results.csv \n"
184 return body
185}
186
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800187def emailNotification(stage, results) {
Karl Zhang0413e972020-09-18 17:59:26 +0800188 script {
Xinyu Zhang953dc232022-09-07 18:27:35 +0800189 if (env.EMAIL_NOTIFICATION) {
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800190 email_body = generateEmailBody(stage, results)
191 if (email_body == "") {
192 print("Skip sending email notification as no failed jobs for ${stage}")
Karl Zhang182ecdf2020-10-10 09:52:12 +0800193 }
194 else {
195 emailext (
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800196 subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} fail"),
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800197 body: email_body,
Karl Zhang182ecdf2020-10-10 09:52:12 +0800198 to: "${EMAIL_NOTIFICATION}"
199 )
200 }
Karl Zhang0413e972020-09-18 17:59:26 +0800201 }
202 } /* script */
203}
204
Xinyu Zhang82dab282022-10-09 16:33:19 +0800205def parseTestResults(output) {
Xinyu Zhang82dab282022-10-09 16:33:19 +0800206 def test_results = [:]
207 records = output.split('\nLAVA Test Config:\n')
208 if (records.size() < 2) {
209 return test_results
210 }
211 records[1..-1].each { record ->
212 config_name = ""
213 metadata = [:]
214 record.split('\n').each { line ->
215 record_metadata = line.split(': ')
Paul Sokolovsky412d62a2022-12-02 21:35:22 +0300216 // Skip lines which are not "metadata"
217 if (record_metadata.size() < 2) {
218 return
219 }
Xinyu Zhang82dab282022-10-09 16:33:19 +0800220 if (record_metadata[0] == 'Config Name') {
221 config_name = record_metadata[1]
222 } else {
223 metadata[record_metadata[0]] = record_metadata[1]
224 }
225 }
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800226 test_results[config_name] = ['URL': metadata['LAVA link'],
227 'RESULT': metadata['Test Result']]
Xinyu Zhang82dab282022-10-09 16:33:19 +0800228 }
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800229
230 writeCsv(test_results, "test_results.csv")
231
Xinyu Zhang82dab282022-10-09 16:33:19 +0800232 return test_results
233}
234
Xinyu Zhang57d2d8c2022-10-24 14:27:30 +0800235def verifyTestStatus(output) {
236 g = new Gerrit()
237 if (output.contains('FAILURE')) {
238 score = -1
239 } else {
240 score = 1
241 }
242 g.verifyStatus(score, "lava_test", "test")
243 if (score < 0) {
244 error("Marking job as failed due to failed tests.")
245 }
246}
247
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800248def generateCsvContent(results) {
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800249 // Results format: [CONFIG_NAME: [URL: "", RESULT: "", ...]]
250 // CSV format: CONFIG_NAME, RESULT
251 csv_header = obtainBuildParams(results.keySet()[0]).keySet().toList()
252 csv_header.add('RESULT')
253 csv_content = [csv_header]
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800254 results.each { result ->
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800255 build_params = []
256 obtainBuildParams(result.key).each { config ->
257 build_params.add(config.value)
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800258 }
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800259 build_params.add(result.value['RESULT'])
260 csv_content.add(build_params)
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800261 }
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800262 return csv_content
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800263}
264
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800265def generateHtmlContent(results) {
266 // Results format: [CONFIG_NAME: [URL: "", RESULT: "", ...]]
267 // HTML format: CONFIG_NAME: Job/Logs/Artifacts RESULT
268 htmlContent = []
269 results.each { result ->
270 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/>")
271 }
272 htmlContent.sort()
273 return htmlContent.join("\n")
274}
275
276def writeCsv(results, file_name) {
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800277 def csvContent = generateCsvContent(results)
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800278 writeCSV file: file_name, records: csvContent, format: CSVFormat.EXCEL
279 sh(script: """./tf-m-ci-scripts/report_parser/report_csv_helper.py \
280 --input-file ${file_name} --output-file ${file_name} \
281 """, returnStdout: true)
282 archiveArtifacts file_name
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800283}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000284
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800285def writeHTML(results, file_name) {
286def buildLinks = generateHtmlContent(results)
287 writeFile file: file_name, text: buildLinks
288 archiveArtifacts file_name
Dean Bircha6ede7e2020-03-13 14:00:33 +0000289}
290
Matthew Hartfb6fd362020-03-04 21:03:59 +0000291def lineInString(string, match) {
292 def lines = string.split("\n")
293 def result = lines.findAll { it.contains(match) }
294 return result[0]
295}
296
297def getResult(string, match) {
298 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100299 a = line.split(match)[1].split(' ')
300 score = a[0]
301 if (a.size() > 1)
302 {
303 fail_text = a[1..-1].join(" ")
304 return [score, fail_text]
305 }
306 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000307}
308
309def submitJobsToList(results) {
310 def all_jobs = []
311 for (String result : results){
312 jobs_s = result.split('JOBS: ')
313 if (jobs_s.size() > 1) {
314 all_jobs += jobs_s[1]
315 }
316 }
317 return(all_jobs)
318}
319
Dean Birch62c4f082020-01-17 16:13:26 +0000320def configs = []
321def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000322def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000323
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800324timestamps {
325 node("docker-amd64-tf-m-bionic") {
326 stage("Init") {
327 cleanWs()
328 dir("tf-m-ci-scripts") {
329 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
Xinyu Zhang8472b852021-09-04 00:13:34 +0800330 sh "git rev-parse --short HEAD"
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500331 // Clone TF-M repositories so share folder can be reused by downstream jobs
332 sh "./clone.sh"
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800333 }
334 }
Xinyu Zhang6b456c22022-10-13 15:48:58 +0800335
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800336 stage("Configs") {
Xinyu Zhang4b109802022-10-18 17:22:07 +0800337 dir(".") {
338 // Populate configs
339 listConfigs(configs, env.FILTER_GROUP)
340 results['builds'] = [:]
341 results['lava_jobs'] = []
342 for (config in configs) {
343 builds[config] = buildConfig(config, results)
344 }
345 if (!env.JOB_NAME.equals("tf-m-extra-build")) {
346 builds["docs"] = buildDocs(results)
347 }
Xinyu Zhang351f14c2021-11-15 14:30:09 +0800348 }
Dean Birch62c4f082020-01-17 16:13:26 +0000349 }
Karl Zhangfec84102020-06-24 09:56:36 +0800350
Xinyu Zhang6b456c22022-10-13 15:48:58 +0800351 stage("Builds") {
352 def verify = 1
353 def success = true
Xinyu Zhang4b109802022-10-18 17:22:07 +0800354 dir(".") {
355 try {
356 parallel(builds)
357 } catch (Exception e) {
358 print(e)
359 manager.buildFailure()
360 verify = -1
361 success = false
362 } finally {
363 print("Verifying status")
364 g = new Gerrit()
365 g.verifyStatus(verify, 'tf-m-build', 'build')
366 print("Generating build results summary.")
367 def build_results_for_summary = [:]
368 results['builds'].each { build ->
Xinyu Zhang0d85cc32022-10-19 17:58:32 +0800369 build_results_for_summary[build.key] = ['URL': build.value.getAbsoluteUrl(),
370 'RESULT': build.value.result]
Xinyu Zhang4b109802022-10-18 17:22:07 +0800371 }
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800372 emailNotification('build', build_results_for_summary)
Xinyu Zhang4b109802022-10-18 17:22:07 +0800373 writeCsv(build_results_for_summary, "build_results.csv")
374 writeHTML(build_results_for_summary, "build_links.html")
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800375 }
Xinyu Zhang6b456c22022-10-13 15:48:58 +0800376 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800377 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800378
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800379 stage("Tests") {
380 dir("tf-m-ci-scripts") {
381 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
382 }
383 def all_jobs = []
384 def success = true
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800385 def test_results = [:]
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800386 print("Wait for LAVA results here...")
387 try {
388 all_jobs = submitJobsToList(results['lava_jobs'])
Paul Sokolovsky437bc422022-02-01 17:57:13 +0300389 output = ""
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800390 if (all_jobs.size() > 0) {
Paul Sokolovsky3d522f72022-04-13 11:17:00 +0300391 dir(".") {
Xinyu Zhang29a57cc2023-02-03 10:08:48 +0800392 if (isPerPatchJob()) {
393 lava_timeout = 2700 // 45min
394 } else {
Paul Sokolovsky288799c2023-03-20 21:19:58 +0700395 lava_timeout = 19800 // 5.5h
Xinyu Zhang29a57cc2023-02-03 10:08:48 +0800396 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800397 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Xinyu Zhang0b84b632023-02-08 14:15:08 +0800398 sh(script: """./tf-m-ci-scripts/lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
399 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
400 --artifacts-path cfgs --lava-timeout ${lava_timeout} > output.log
401 """)
Paul Sokolovsky0136de02022-04-19 20:21:47 +0300402 if (env.CODE_COVERAGE_EN == "TRUE") {
403 println("Producing merged report")
404 sh(script: """./tf-m-ci-scripts/lava_helper/codecov_merge.sh""")
405 archiveArtifacts artifacts: 'merged_report/**', allowEmptyArchive: true
406 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000407 }
Xinyu Zhang6fd6d332023-10-19 10:12:22 +0800408 if (env.JOB_NAME.equals("tf-m-nightly-performance")) {
409 withCredentials([string(credentialsId: 'QA_REPORTS_TOKEN', variable: 'TOKEN')]) {
410 sh(script: """./tf-m-ci-scripts/performance.py --send-squad --squad-token ${TOKEN} > SQUAD.log""")
411 }
Jianliang Shen48704152023-10-17 17:06:00 +0800412 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000413 }
414 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800415 else {
416 print("There were no LAVA jobs to test.")
417 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000418 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800419 catch (Exception e) {
Paul Sokolovsky2cf562a2022-12-02 15:10:58 +0300420 println("ERROR: ${e}")
421 // We don't print stacktrace, because Jenkins pipeline use CPS conversion
422 // of the Groovy code, which leads to incomprehensible stacktraces.
423 //print(hudson.Functions.printThrowable(org.codehaus.groovy.runtime.StackTraceUtils.sanitize(e)))
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800424 success = false
425 } finally {
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800426 if (all_jobs.size() > 0) {
Xinyu Zhang68858312023-02-23 11:11:09 +0800427 output = readFile("output.log")
428 println("--- output from lava_wait_jobs.py ---")
429 println(output)
430 println("--- end of output from lava_wait_jobs.py ---")
Xinyu Zhang808f9772023-10-19 10:57:40 +0800431 test_results = parseTestResults(output)
432
433 if (env.JOB_NAME.equals("tf-m-nightly-performance")) {
434 performance_output = readFile("SQUAD.log")
435 println("--- output from performance.py ---")
436 println(performance_output)
437 println("--- end of output from performance.py ---")
438 }
439
Xinyu Zhang68858312023-02-23 11:11:09 +0800440 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
441 archiveArtifacts artifacts: 'cfgs/**', allowEmptyArchive: true
442 if (all_jobs.size() > 0) {
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800443 emailNotification('test', test_results)
Xinyu Zhang68858312023-02-23 11:11:09 +0800444 }
445 verifyTestStatus(output)
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800446 }
447 cleanWs()
448 if (!success) {
449 error("There was an Error waiting for LAVA jobs")
450 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000451 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000452 }
453 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000454}