blob: 534bbe1359dfdf00a53ed4c75fdd7b68e7d774ce [file] [log] [blame]
Dean Birch62c4f082020-01-17 16:13:26 +00001#!/usr/bin/env groovy
2//-------------------------------------------------------------------------------
Xinyu Zhang97114342021-01-21 14:08:03 +08003// Copyright (c) 2020-2021, 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
Summer Qin3c2b5722021-05-26 10:43:45 +080015mapPlatform = ["cypress/psoc64": "psoc64",
16 "arm/mps2/an519": "AN519",
17 "arm/mps2/an521": "AN521",
18 "arm/mps2/an539": "AN539",
19 "arm/mps2/sse-200_aws": "SSE-200_AWS",
20 "arm/mps3/an524": "AN524",
21 "arm/musca_b1/sse_200": "MUSCA_B1",
22 "arm/musca_b1/secure_enclave": "MUSCA_B1_SE",
Arthur She19c0e1a2021-06-02 11:06:19 -070023 "arm/musca_s1": "MUSCA_S1",
Xinyu Zhangfcb6aad2021-08-25 16:24:11 +080024 "stm/stm32l562e_dk": "stm32l562e_dk",
Arthur Shef3657742021-09-07 14:23:18 -070025 "arm/diphda": "DIPHDA",
26 "nxp/lpcxpresso55s69": "lpcxpresso55s69"]
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080027
28mapCompiler = ["toolchain_GNUARM.cmake": "GNUARM",
29 "toolchain_ARMCLANG.cmake": "ARMCLANG"]
30
31mapBL2 = ["True": "--bl2",
32 "False": ""]
33
34mapTestPsaApi = ["OFF": "",
Xinyu Zhang39acb412021-07-09 20:35:19 +080035 "STORAGE": "STORAGE",
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080036 "CRYPTO": "Crypto",
37 "INITIAL_ATTESTATION": "Attest",
38 "IPC": "FF"]
39
Xinyu Zhang73ed2992021-09-15 11:38:23 +080040// LIB_MODEL, ISOLATION_LEVEL, TEST_REG, TEST_PSA_API, PROFILE, CONFIG_NAME
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080041mapConfigs = [
Xinyu Zhang73ed2992021-09-15 11:38:23 +080042 ["True", "1", "False", "OFF", "N.A", "Default"],
43 ["False", "1", "False", "OFF", "N.A", "CoreIPC"],
44 ["False", "2", "False", "OFF", "N.A", "CoreIPCTfmLevel2"],
45 ["False", "3", "False", "OFF", "N.A", "CoreIPCTfmLevel3"],
46 ["True", "1", "False", "OFF", "profile_small", "DefaultProfileS"],
47 ["False", "2", "False", "OFF", "profile_medium", "DefaultProfileM"],
48 ["False", "3", "False", "OFF", "profile_large", "DefaultProfileL"],
49 ["True", "1", "True", "OFF", "N.A", "Regression"],
50 ["False", "1", "True", "OFF", "N.A", "RegressionIPC"],
51 ["False", "2", "True", "OFF", "N.A", "RegressionIPCTfmLevel2"],
52 ["False", "3", "True", "OFF", "N.A", "RegressionIPCTfmLevel3"],
53 ["True", "1", "True", "OFF", "profile_small", "RegressionProfileS"],
54 ["False", "2", "True", "OFF", "profile_medium", "RegressionProfileM"],
55 ["False", "3", "True", "OFF", "profile_large", "RegressionProfileL"],
56 ["True", "1", "False", "STORAGE", "N.A", "PsaApiTest (STORAGE)"],
57 ["True", "1", "False", "CRYPTO", "N.A", "PsaApiTest (Crypto)"],
58 ["True", "1", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTest (Attest)"],
59 ["True", "1", "False", "IPC", "N.A", "PsaApiTest (FF)"],
60 ["False", "1", "False", "STORAGE", "N.A", "PsaApiTestIPC (STORAGE)"],
61 ["False", "1", "False", "CRYPTO", "N.A", "PsaApiTestIPC (Crypto)"],
62 ["False", "1", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPC (Attest)"],
63 ["False", "1", "False", "IPC", "N.A", "PsaApiTestIPC (FF)"],
64 ["False", "2", "False", "STORAGE", "N.A", "PsaApiTestIPCTfmLevel2 (STORAGE)"],
65 ["False", "2", "False", "CRYPTO", "N.A", "PsaApiTestIPCTfmLevel2 (Crypto)"],
66 ["False", "2", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPCTfmLevel2 (Attest)"],
67 ["False", "2", "False", "IPC", "N.A", "PsaApiTestIPCTfmLevel2 (FF)"],
68 ["False", "3", "False", "STORAGE", "N.A", "PsaApiTestIPCTfmLevel3 (STORAGE)"],
69 ["False", "3", "False", "CRYPTO", "N.A", "PsaApiTestIPCTfmLevel3 (Crypto)"],
70 ["False", "3", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPCTfmLevel3 (Attest)"],
71 ["False", "3", "False", "IPC", "N.A", "PsaApiTestIPCTfmLevel3 (FF)"],
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080072]
73
74cfgs = ["Default", "CoreIPC", "CoreIPCTfmLevel2", "CoreIPCTfmLevel3",
75 "Regression", "RegressionIPC",
76 "RegressionIPCTfmLevel2", "RegressionIPCTfmLevel3",
77 "DefaultProfileS", "RegressionProfileS",
78 "DefaultProfileM", "RegressionProfileM", "RegressionProfileM PSOFF",
Xinyu Zhang9b1aef92021-03-12 15:36:44 +080079 "DefaultProfileL", "RegressionProfileL",
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080080 "PsaApiTest (Attest)", "PsaApiTestIPC (Attest)",
81 "PsaApiTestIPCTfmLevel2 (Attest)",
82 "PsaApiTest (Crypto)", "PsaApiTestIPC (Crypto)",
83 "PsaApiTestIPCTfmLevel2 (Crypto)",
Xinyu Zhang39acb412021-07-09 20:35:19 +080084 "PsaApiTest (STORAGE)", "PsaApiTestIPC (STORAGE)",
85 "PsaApiTestIPCTfmLevel2 (STORAGE)",
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080086 "PsaApiTestIPC (FF)",
87 "PsaApiTestIPCTfmLevel2 (FF)",
Xinyu Zhang39acb412021-07-09 20:35:19 +080088 "PsaApiTestIPCTfmLevel3 (STORAGE)", "PsaApiTestIPCTfmLevel3 (Crypto)",
89 "PsaApiTestIPCTfmLevel3 (Attest)", "PsaApiTestIPCTfmLevel3 (FF)"]
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080090
Xinyu Zhangaa3747f2020-12-24 16:27:06 +080091@NonCPS
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080092def generateLavaParam(build_params) {
93 def params = []
Summer Qin3c2b5722021-05-26 10:43:45 +080094 if (build_params["TFM_PLATFORM"] == "arm/musca_b1/sse_200" && \
Xinyu Zhang97114342021-01-21 14:08:03 +080095 build_params["OTP"] == "ENABLED") {
96 params += string(name: "TARGET_PLATFORM", value: "MUSCA_B1_OTP")
97 }
98 else {
99 params += string(name: "TARGET_PLATFORM", \
100 value: mapPlatform[build_params["TFM_PLATFORM"]])
101 }
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800102 params += string(name: "COMPILER", \
103 value: mapCompiler[build_params["TOOLCHAIN_FILE"]])
104 params += string(name: "PSA_API_SUITE", \
105 value: mapTestPsaApi[build_params["TEST_PSA_API"]])
106
Xinyu Zhangdbfadae2020-12-07 14:42:59 +0800107 configName = "Config"
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800108 config_params = [build_params["LIB_MODEL"], build_params["ISOLATION_LEVEL"], \
Xinyu Zhangdbfadae2020-12-07 14:42:59 +0800109 build_params["TEST_REGRESSION"], build_params["TEST_PSA_API"], \
110 build_params["PROFILE"]]
111 for (config in mapConfigs) {
Xinyu Zhang3f7e2f52021-09-02 13:43:57 +0800112 if (config_params == config[0..4]) {
113 configName += config[5].replace(' (', '_').replace(')', '')
Xinyu Zhangdbfadae2020-12-07 14:42:59 +0800114 break
115 }
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800116 }
Xinyu Zhangdbfadae2020-12-07 14:42:59 +0800117 if (configName == "Config") {
118 configName = "ConfigDefault"
119 }
120 params += string(name: "PROJ_CONFIG", value: configName)
Xinyu Zhangaa3747f2020-12-24 16:27:06 +0800121 print("Params of ${configName} :")
122 print(config_params)
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800123 return params
124}
125
Xinyu Zhang0aced4c2021-09-03 17:06:21 +0800126def submit_lava_tests(config, results, build_res, params, params_collection) {
127 print("Doing LAVA stuff for ${build_res.getAbsoluteUrl()}")
128 params += generateLavaParam(params_collection)
129 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
130 params += string(name: 'BUILD_URL', value: build_res.getAbsoluteUrl())
131 params += string(name: 'LAVA_URL', value: env.LAVA_URL)
132 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
133 params += string(name: 'LAVA_CREDENTIALS', value: env.LAVA_CREDENTIALS)
134 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
135 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
136 def lava_resubmitted = false
137 if (lava_res.result in failure_states) {
138 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
139 } else {
140 lava_des = lava_res.getDescription()
141 if (lava_des.contains(" Submitted twice!")) {
142 lava_resubmitted = true
143 lava_des = lava_des - " Submitted twice!"
144 }
145 results['lava_jobs'] += lava_des
146 }
147 links = "Build Config: ${config}\n"
148 links += "Build URL: ${build_res.getAbsoluteUrl()}\n"
149 links += "LAVA Submit: ${lava_res.getAbsoluteUrl()}"
150 if (lava_resubmitted) {
151 links += "\nLAVA Job Re-Submitted!"
152 }
153 print(links)
154}
155
Dean Birch62c4f082020-01-17 16:13:26 +0000156def listConfigs(ci_scripts_dir, config_list, filter_group) {
157 dir(ci_scripts_dir) {
158 echo "Obtaining list of configs."
Matthew Hartfb6fd362020-03-04 21:03:59 +0000159 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}"
Dean Birch62c4f082020-01-17 16:13:26 +0000160 def build_config_list_raw = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +0000161python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}
Dean Birch62c4f082020-01-17 16:13:26 +0000162""", returnStdout: true).trim()
163 def build_config_list = build_config_list_raw.tokenize('\n')
164 config_list.addAll(build_config_list)
165 }
166}
167
Matthew Hartfb6fd362020-03-04 21:03:59 +0000168def buildConfig(ci_scripts_dir, config, filter_group, results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000169 def params = []
Matthew Hartfb6fd362020-03-04 21:03:59 +0000170 def params_collection = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000171 def build_config_params
172 dir(ci_scripts_dir) {
173 echo "Obtaining build configuration for config ${config}"
Matthew Hartfb6fd362020-03-04 21:03:59 +0000174 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}"
Dean Birch62c4f082020-01-17 16:13:26 +0000175 build_config_params = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +0000176python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}
Dean Birch62c4f082020-01-17 16:13:26 +0000177""", returnStdout: true).trim()
178 }
179 def lines = build_config_params.tokenize('\n')
180 for (String line : lines) {
181 def key, value
182 (key, value) = line.tokenize('=')
183 params += string(name: key, value: value)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000184 params_collection[key] = value
Dean Birch62c4f082020-01-17 16:13:26 +0000185 }
186 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000187 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
188 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
189 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000190 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800191 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000192 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Karl Zhangf6f467e2020-07-10 16:24:45 +0800193 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000194 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Hugo L'Hostise55a2752021-01-27 11:09:08 +0000195 if (env.JOB_NAME.equals("tf-m-nightly")) { //Setting the Memory footprint gathering.
196 params += string(name: 'SQUAD_CONFIGURATIONS', value: env.SQUAD_CONFIGURATIONS)
197 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000198 return { -> results
199 def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000200 def build_url = build_res.getAbsoluteUrl()
Xinyu Zhang0aced4c2021-09-03 17:06:21 +0800201 results['builds'][build_res.number] = [build_res, config, params_collection]
202
Dean Bircha6ede7e2020-03-13 14:00:33 +0000203 print("${build_res.number}: ${config} ${build_res.result} ${build_url}")
Xinyu Zhangf2ba9112021-09-02 13:31:16 +0800204
205 // Filter out configs do not need LAVA tests
206
207 // Configs with build failure do not need LAVA tests
Dean Bircha6ede7e2020-03-13 14:00:33 +0000208 if (build_res.result in failure_states) {
209 error("Build failed at ${build_url}")
210 }
Xinyu Zhang372e8a12021-09-02 13:51:39 +0800211 // Configs without BL2 do not need LAVA tests
212 else if (params_collection["BL2"] == "False") {
213 print("LAVA is not needed for ${build_url}")
214 }
Xinyu Zhangf2ba9112021-09-02 13:31:16 +0800215 // Configs without building NS app do not need LAVA tests
216 else if (params_collection["NS"] == "False") {
217 print("LAVA is not needed for ${build_url}")
218 }
219 // LAVA tests on MUSCA_B1 are not needed in per-patch job
220 else if (params_collection["TFM_PLATFORM"].contains("musca_b1") && \
221 env.JOB_NAME.equals("tf-m-build-and-test")) {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800222 print("LAVA is not needed for ${build_url}")
223 }
Xinyu Zhang7bb69162021-07-01 03:40:53 +0100224 // Only submit LAVA test for a specified OTP enabled config in nightly or release job
225 else if (params_collection["OTP"] == "ENABLED" && \
Xinyu Zhangc4bb2e12021-07-21 22:40:35 +0800226 params_collection["CONFIG_NAME"] != "MUSCA_B1_GNUARM_PSA_3_REG_Debug_OTP_BL2_NS") {
Xinyu Zhang7bb69162021-07-01 03:40:53 +0100227 print("LAVA is not needed for ${build_url}")
228 }
Xinyu Zhangc4bb2e12021-07-21 22:40:35 +0800229 else if (params_collection["CONFIG_NAME"] == "MUSCA_B1_GNUARM_PSA_3_REG_Debug_OTP_BL2_NS" && \
Xinyu Zhang7bb69162021-07-01 03:40:53 +0100230 !(env.JOB_NAME.equals("tf-m-nightly") || env.JOB_NAME.equals("tf-m-release"))) {
Xinyu Zhang97114342021-01-21 14:08:03 +0800231 print("LAVA is not needed for ${build_url}")
232 }
Xinyu Zhangf2ba9112021-09-02 13:31:16 +0800233
234 // Submit LAVA tests
Dean Bircha6ede7e2020-03-13 14:00:33 +0000235 else {
Xinyu Zhang0aced4c2021-09-03 17:06:21 +0800236 submit_lava_tests(config, results, build_res, params, params_collection)
Dean Birch62c4f082020-01-17 16:13:26 +0000237 }
238 }
239}
240
Matthew Hart06340d72020-06-15 16:08:20 +0100241def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000242 def params = []
243 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000244 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
245 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
246 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000247 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800248 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000249 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000250 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Matthew Hart06340d72020-06-15 16:08:20 +0100251 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +0000252 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
253 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +0100254 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +0000255 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +0000256 error("Build failed at ${res.getAbsoluteUrl()}")
257 }
258 }
259}
260
Xinyu Zhang38a18872020-11-23 16:45:28 +0800261def generateEmailBody(stage, failed_jobs) {
262 body = "Check console output at ${env.BUILD_URL} \n\n"
263
264 body += "Failed Jobs:\n"
265 failed_jobs.each { job ->
266 body += "${job.key} ${job.value}\n"
267 }
268
269 body += "\nFor detailed ${stage} results please refer to \
270 ${env.BUILD_URL}artifact/${stage}_results.csv \n"
271 return body
272}
273
274def emailNotification(results, stage, failed_jobs) {
Karl Zhang0413e972020-09-18 17:59:26 +0800275 script {
276 if (env.JOB_NAME.equals("tf-m-nightly") && !env.EMAIL_NOTIFICATION.equals('')) {
277 def result = "Fail."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800278 if (results == true) {
Karl Zhang0413e972020-09-18 17:59:26 +0800279 result = "Success."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800280 print("Skip sending as ${result} for ${stage}")
281 }
282 else {
283 emailext (
284 subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} ${result}"),
Xinyu Zhang38a18872020-11-23 16:45:28 +0800285 body: generateEmailBody(stage, failed_jobs),
Karl Zhang182ecdf2020-10-10 09:52:12 +0800286 to: "${EMAIL_NOTIFICATION}"
287 )
288 }
Karl Zhang0413e972020-09-18 17:59:26 +0800289 }
290 } /* script */
291}
292
Xinyu Zhang38a18872020-11-23 16:45:28 +0800293def filterFailedBuild(results) {
294 def failed_builds = [:]
295 results.each { result ->
296 if (result.value[0].getResult() == "FAILURE") {
297 failed_builds[result.value[1]] = result.value[0].getAbsoluteUrl()
298 }
299 }
300 return failed_builds
301}
302
303def filterFailedTest(string) {
304 def failed_tests = [:]
305 line = lineInString(string, "FAILURE_TESTS:")
306 a = line.split(' ')
307 if (a.size() > 1) {
308 a = line.split(' ')[1..-1]
309 a.each { fail_test ->
310 config_link = fail_test.split(':')
311 failed_tests[config_link[0]] = config_link[1..-1].join(':')
312 }
313 }
314 return failed_tests
315}
316
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800317@NonCPS
318def generateCsvContent(results) {
319 def resultsParam = []
320 results.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800321 if (result.value[2]['BL2'] == "True") {
322 resultsParam.add([result.value[1], \
323 result.value[0].getResult(), \
324 result.value[2]['TFM_PLATFORM'], \
325 result.value[2]['TOOLCHAIN_FILE'], \
326 result.value[2]['CMAKE_BUILD_TYPE'], \
327 result.value[2]['BL2'], \
328 result.value[2]['NS'], \
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800329 result.value[2]['LIB_MODEL'], \
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800330 result.value[2]['ISOLATION_LEVEL'], \
331 result.value[2]['TEST_REGRESSION'], \
332 result.value[2]['TEST_PSA_API'], \
333 result.value[2]['PROFILE'], \
334 result.value[2]['PARTITION_PS'], \
335 result.value[2]['OTP']])
336 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800337 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800338 resultsParam.each { result ->
Xinyu Zhang8d95fc12021-07-21 10:58:39 +0800339 if (result[2] == 'arm/musca_b1/sse_200') {
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800340 if (result[13] != 'off') {
Xinyu Zhang8d95fc12021-07-21 10:58:39 +0800341 result[2] = 'arm/musca_b1/sse_200_OTP'
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800342 }
343 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800344 result[3] = mapCompiler[result[3]]
Xinyu Zhang3f7e2f52021-09-02 13:43:57 +0800345 build_params = result[7..12]
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800346 configName = ""
347 for (map_cfg in mapConfigs) {
Xinyu Zhang3f7e2f52021-09-02 13:43:57 +0800348 if (build_params[0..4] == map_cfg[0..4]) {
349 configName = map_cfg[5]
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800350 break
351 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800352 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800353 if (configName == "") {
354 configName = "Default"
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800355 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800356 else if (configName == "RegressionProfileM") {
Xinyu Zhang3f7e2f52021-09-02 13:43:57 +0800357 if (build_params[5] == "OFF") {
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800358 configName = "RegressionProfileM PSOFF"
359 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800360 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800361 result.add(configName)
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800362 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800363 def csvContent = []
364 resultsParam.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800365 current_row = result[2..4]
366 cfgs.each {cfg ->
367 if (cfg == result[14]) {
368 current_row.add(cfg)
369 current_row.add(result[1])
370 }
371 }
372 csvContent.add(current_row)
373 }
374 csvContent.sort{a,b -> a[0] <=> b[0] ?: a[1] <=> b[1] ?: a[2] <=> b[2]}
375 build_summary = []
376 current_platform = ""
377 current_compiler = ""
378 current_build_type = ""
379 csvContent.each { build_cfg ->
380 if (current_platform != build_cfg[0] || \
381 current_compiler != build_cfg[1] || \
382 current_build_type != build_cfg[2]) {
383 current_platform = build_cfg[0]
384 current_compiler = build_cfg[1]
385 current_build_type = build_cfg[2]
386 csv_line = [current_platform, current_compiler, current_build_type]
387 cfgs.each {
388 csv_line.add("N.A.")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800389 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800390 build_summary.add(csv_line)
391 }
392 i = 0
393 cfgs.each { cfg ->
394 if (cfg == build_cfg[3]) {
395 build_summary[-1][3+i] = build_cfg[4]
396 }
397 i += 1
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800398 }
399 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800400 build_summary.add(0, ['Platform', 'Compiler', 'Cmake Build Type'])
401 build_summary[0] += cfgs
402 return build_summary
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800403}
404
405def generateBuildCsv(results) {
406 def csvContent = generateCsvContent(results)
407 node("master") {
408 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
409 archiveArtifacts 'build_results.csv'
410 }
411}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000412
413def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000414 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000415 def csvContent = summary.getBuildCsv(results)
416 node("master") {
417 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
418 archiveArtifacts 'build_results.csv'
419 }
420}
421
422def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000423 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000424 def buildLinks = summary.getLinks(results)
425 node("master") {
426 writeFile file: "build_links.html", text: buildLinks
427 archiveArtifacts 'build_links.html'
428 }
429}
430
Matthew Hartfb6fd362020-03-04 21:03:59 +0000431def lineInString(string, match) {
432 def lines = string.split("\n")
433 def result = lines.findAll { it.contains(match) }
434 return result[0]
435}
436
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800437def showLinks(string) {
438 def lines = string.split("\n")
439 def result = lines.findAll { it.contains("Build Config: ")}
440 links = result.join("\n")
441 print(links)
442}
443
Matthew Hartfb6fd362020-03-04 21:03:59 +0000444def getResult(string, match) {
445 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100446 a = line.split(match)[1].split(' ')
447 score = a[0]
448 if (a.size() > 1)
449 {
450 fail_text = a[1..-1].join(" ")
451 return [score, fail_text]
452 }
453 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000454}
455
456def submitJobsToList(results) {
457 def all_jobs = []
458 for (String result : results){
459 jobs_s = result.split('JOBS: ')
460 if (jobs_s.size() > 1) {
461 all_jobs += jobs_s[1]
462 }
463 }
464 return(all_jobs)
465}
466
Dean Birch62c4f082020-01-17 16:13:26 +0000467def configs = []
468def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000469def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000470
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800471timestamps {
472 node("docker-amd64-tf-m-bionic") {
473 stage("Init") {
474 cleanWs()
475 dir("tf-m-ci-scripts") {
476 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
Xinyu Zhang8472b852021-09-04 00:13:34 +0800477 sh "git rev-parse --short HEAD"
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800478 }
479 }
480 stage("Configs") {
481 // Populate configs
482 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
483 results['builds'] = [:]
484 results['lava_jobs'] = []
485 for (config in configs) {
486 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
487 }
488 builds["docs"] = buildDocs(results)
Dean Birch62c4f082020-01-17 16:13:26 +0000489 }
490 }
Karl Zhangfec84102020-06-24 09:56:36 +0800491
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800492 stage("Builds") {
493 def verify = 1
Matthew Hartfb6fd362020-03-04 21:03:59 +0000494 def success = true
Matthew Hartfb6fd362020-03-04 21:03:59 +0000495 try {
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800496 parallel(builds)
497 } catch (Exception e) {
498 print(e)
499 manager.buildFailure()
500 verify = -1
501 success = false
502 } finally {
503 print("Verifying status")
504 def failed_builds = filterFailedBuild(results['builds'])
505 emailNotification(success, 'build', failed_builds)
506 g = new Gerrit()
507 g.verifyStatus(verify, 'tf-m-build', 'build')
508 print("Building CSV")
509 generateBuildCsv(results['builds'])
510 writeSummary(results['builds'])
511 }
512 }
513
514 node("docker-amd64-tf-m-bionic") {
515 stage("Tests") {
516 dir("tf-m-ci-scripts") {
517 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
518 }
519 def all_jobs = []
520 def success = true
521 print("Wait for LAVA results here...")
522 try {
523 all_jobs = submitJobsToList(results['lava_jobs'])
524 if (all_jobs.size() > 0) {
525 dir("tf-m-ci-scripts") {
526 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
527 output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
528 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
529 --artifacts-path lava_artifacts --lava-timeout 7200 \
530 """, returnStdout: true).trim()
531 showLinks(output)
532 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
533 archiveArtifacts artifacts: 'test_results.csv', allowEmptyArchive: true
534 g = new Gerrit()
535 def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ')
536 if (boot_result) {
537 g.verifyStatus(boot_result, "lava_boot", "test")
538 }
539 def (test_result, test_output) = getResult(output, 'TEST_RESULT: ')
540 if (test_result) {
541 g.verifyStatus(test_result, "lava_test", "test")
542 }
543 if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) {
544 error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}")
545 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000546 }
547 }
548 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800549 else {
550 print("There were no LAVA jobs to test.")
551 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000552 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800553 catch (Exception e) {
554 print("ERROR: ${e}")
555 success = false
556 } finally {
557 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
558 if (all_jobs.size() > 0) {
559 emailNotification(success, 'test', filterFailedTest(output))
560 }
561 cleanWs()
562 if (!success) {
563 error("There was an Error waiting for LAVA jobs")
564 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000565 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000566 }
567 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000568}