blob: 533acbef6178edd73bbb719aad825042a0537a8e [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
Summer Qin3c2b5722021-05-26 10:43:45 +080013mapPlatform = ["cypress/psoc64": "psoc64",
14 "arm/mps2/an519": "AN519",
15 "arm/mps2/an521": "AN521",
16 "arm/mps2/an539": "AN539",
17 "arm/mps2/sse-200_aws": "SSE-200_AWS",
18 "arm/mps3/an524": "AN524",
19 "arm/musca_b1/sse_200": "MUSCA_B1",
20 "arm/musca_b1/secure_enclave": "MUSCA_B1_SE",
Arthur She19c0e1a2021-06-02 11:06:19 -070021 "arm/musca_s1": "MUSCA_S1",
Xinyu Zhangfcb6aad2021-08-25 16:24:11 +080022 "stm/stm32l562e_dk": "stm32l562e_dk",
23 "arm/diphda": "DIPHDA"]
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080024
25mapCompiler = ["toolchain_GNUARM.cmake": "GNUARM",
26 "toolchain_ARMCLANG.cmake": "ARMCLANG"]
27
28mapBL2 = ["True": "--bl2",
29 "False": ""]
30
31mapTestPsaApi = ["OFF": "",
Xinyu Zhang39acb412021-07-09 20:35:19 +080032 "STORAGE": "STORAGE",
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080033 "CRYPTO": "Crypto",
34 "INITIAL_ATTESTATION": "Attest",
35 "IPC": "FF"]
36
Xinyu Zhangdbfadae2020-12-07 14:42:59 +080037// BL2, NS, PSA_API, ISOLATION_LEVEL, TEST_REG, TEST_PSA_API, PROFILE, CONFIG_NAME
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080038mapConfigs = [
39 ["True", "True", "False", "1", "False", "OFF", "N.A", "Default"],
40 ["True", "True", "True", "1", "False", "OFF", "N.A", "CoreIPC"],
41 ["True", "True", "True", "2", "False", "OFF", "N.A", "CoreIPCTfmLevel2"],
42 ["True", "True", "True", "3", "False", "OFF", "N.A", "CoreIPCTfmLevel3"],
43 ["True", "True", "False", "1", "False", "OFF", "profile_small", "DefaultProfileS"],
44 ["True", "True", "True", "2", "False", "OFF", "profile_medium", "DefaultProfileM"],
Xinyu Zhang9b1aef92021-03-12 15:36:44 +080045 ["True", "True", "True", "3", "False", "OFF", "profile_large", "DefaultProfileL"],
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080046 ["True", "True", "False", "1", "True", "OFF", "N.A", "Regression"],
47 ["True", "True", "True", "1", "True", "OFF", "N.A", "RegressionIPC"],
48 ["True", "True", "True", "2", "True", "OFF", "N.A", "RegressionIPCTfmLevel2"],
49 ["True", "True", "True", "3", "True", "OFF", "N.A", "RegressionIPCTfmLevel3"],
50 ["True", "True", "False", "1", "True", "OFF", "profile_small", "RegressionProfileS"],
51 ["True", "True", "True", "2", "True", "OFF", "profile_medium", "RegressionProfileM"],
Xinyu Zhang9b1aef92021-03-12 15:36:44 +080052 ["True", "True", "True", "3", "True", "OFF", "profile_large", "RegressionProfileL"],
Xinyu Zhang39acb412021-07-09 20:35:19 +080053 ["True", "True", "False", "1", "False", "STORAGE", "N.A", "PsaApiTest (STORAGE)"],
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080054 ["True", "True", "False", "1", "False", "CRYPTO", "N.A", "PsaApiTest (Crypto)"],
55 ["True", "True", "False", "1", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTest (Attest)"],
56 ["True", "True", "False", "1", "False", "IPC", "N.A", "PsaApiTest (FF)"],
Xinyu Zhang39acb412021-07-09 20:35:19 +080057 ["True", "True", "True", "1", "False", "STORAGE", "N.A", "PsaApiTestIPC (STORAGE)"],
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080058 ["True", "True", "True", "1", "False", "CRYPTO", "N.A", "PsaApiTestIPC (Crypto)"],
59 ["True", "True", "True", "1", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPC (Attest)"],
60 ["True", "True", "True", "1", "False", "IPC", "N.A", "PsaApiTestIPC (FF)"],
Xinyu Zhang39acb412021-07-09 20:35:19 +080061 ["True", "True", "True", "2", "False", "STORAGE", "N.A", "PsaApiTestIPCTfmLevel2 (STORAGE)"],
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080062 ["True", "True", "True", "2", "False", "CRYPTO", "N.A", "PsaApiTestIPCTfmLevel2 (Crypto)"],
63 ["True", "True", "True", "2", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPCTfmLevel2 (Attest)"],
64 ["True", "True", "True", "2", "False", "IPC", "N.A", "PsaApiTestIPCTfmLevel2 (FF)"],
Xinyu Zhang39acb412021-07-09 20:35:19 +080065 ["True", "True", "True", "3", "False", "STORAGE", "N.A", "PsaApiTestIPCTfmLevel3 (STORAGE)"],
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080066 ["True", "True", "True", "3", "False", "CRYPTO", "N.A", "PsaApiTestIPCTfmLevel3 (Crypto)"],
67 ["True", "True", "True", "3", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPCTfmLevel3 (Attest)"],
68 ["True", "True", "True", "3", "False", "IPC", "N.A", "PsaApiTestIPCTfmLevel3 (FF)"],
69]
70
71cfgs = ["Default", "CoreIPC", "CoreIPCTfmLevel2", "CoreIPCTfmLevel3",
72 "Regression", "RegressionIPC",
73 "RegressionIPCTfmLevel2", "RegressionIPCTfmLevel3",
74 "DefaultProfileS", "RegressionProfileS",
75 "DefaultProfileM", "RegressionProfileM", "RegressionProfileM PSOFF",
Xinyu Zhang9b1aef92021-03-12 15:36:44 +080076 "DefaultProfileL", "RegressionProfileL",
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080077 "PsaApiTest (Attest)", "PsaApiTestIPC (Attest)",
78 "PsaApiTestIPCTfmLevel2 (Attest)",
79 "PsaApiTest (Crypto)", "PsaApiTestIPC (Crypto)",
80 "PsaApiTestIPCTfmLevel2 (Crypto)",
Xinyu Zhang39acb412021-07-09 20:35:19 +080081 "PsaApiTest (STORAGE)", "PsaApiTestIPC (STORAGE)",
82 "PsaApiTestIPCTfmLevel2 (STORAGE)",
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080083 "PsaApiTestIPC (FF)",
84 "PsaApiTestIPCTfmLevel2 (FF)",
Xinyu Zhang39acb412021-07-09 20:35:19 +080085 "PsaApiTestIPCTfmLevel3 (STORAGE)", "PsaApiTestIPCTfmLevel3 (Crypto)",
86 "PsaApiTestIPCTfmLevel3 (Attest)", "PsaApiTestIPCTfmLevel3 (FF)"]
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080087
Xinyu Zhangaa3747f2020-12-24 16:27:06 +080088@NonCPS
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080089def generateLavaParam(build_params) {
90 def params = []
Summer Qin3c2b5722021-05-26 10:43:45 +080091 if (build_params["TFM_PLATFORM"] == "arm/musca_b1/sse_200" && \
Xinyu Zhang97114342021-01-21 14:08:03 +080092 build_params["OTP"] == "ENABLED") {
93 params += string(name: "TARGET_PLATFORM", value: "MUSCA_B1_OTP")
94 }
95 else {
96 params += string(name: "TARGET_PLATFORM", \
97 value: mapPlatform[build_params["TFM_PLATFORM"]])
98 }
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080099 params += string(name: "COMPILER", \
100 value: mapCompiler[build_params["TOOLCHAIN_FILE"]])
101 params += string(name: "PSA_API_SUITE", \
102 value: mapTestPsaApi[build_params["TEST_PSA_API"]])
103
Xinyu Zhangdbfadae2020-12-07 14:42:59 +0800104 configName = "Config"
105 config_params = [build_params["BL2"], build_params["NS"], \
106 build_params["PSA_API"], build_params["ISOLATION_LEVEL"], \
107 build_params["TEST_REGRESSION"], build_params["TEST_PSA_API"], \
108 build_params["PROFILE"]]
109 for (config in mapConfigs) {
110 if (config_params == config[0..6]) {
Xinyu Zhangfc1bacd2020-12-24 15:26:35 +0800111 configName += config[7].replace(' (', '_').replace(')', '')
Xinyu Zhangdbfadae2020-12-07 14:42:59 +0800112 break
113 }
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800114 }
Xinyu Zhangdbfadae2020-12-07 14:42:59 +0800115 if (configName == "Config") {
116 configName = "ConfigDefault"
117 }
118 params += string(name: "PROJ_CONFIG", value: configName)
Xinyu Zhangaa3747f2020-12-24 16:27:06 +0800119 print("Params of ${configName} :")
120 print(config_params)
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800121 return params
122}
123
Dean Birch62c4f082020-01-17 16:13:26 +0000124def listConfigs(ci_scripts_dir, config_list, filter_group) {
125 dir(ci_scripts_dir) {
126 echo "Obtaining list of configs."
Matthew Hartfb6fd362020-03-04 21:03:59 +0000127 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}"
Dean Birch62c4f082020-01-17 16:13:26 +0000128 def build_config_list_raw = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +0000129python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}
Dean Birch62c4f082020-01-17 16:13:26 +0000130""", returnStdout: true).trim()
131 def build_config_list = build_config_list_raw.tokenize('\n')
132 config_list.addAll(build_config_list)
133 }
134}
135
Matthew Hartfb6fd362020-03-04 21:03:59 +0000136def buildConfig(ci_scripts_dir, config, filter_group, results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000137 def params = []
Matthew Hartfb6fd362020-03-04 21:03:59 +0000138 def params_collection = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000139 def build_config_params
140 dir(ci_scripts_dir) {
141 echo "Obtaining build configuration for config ${config}"
Matthew Hartfb6fd362020-03-04 21:03:59 +0000142 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}"
Dean Birch62c4f082020-01-17 16:13:26 +0000143 build_config_params = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +0000144python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}
Dean Birch62c4f082020-01-17 16:13:26 +0000145""", returnStdout: true).trim()
146 }
147 def lines = build_config_params.tokenize('\n')
148 for (String line : lines) {
149 def key, value
150 (key, value) = line.tokenize('=')
151 params += string(name: key, value: value)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000152 params_collection[key] = value
Dean Birch62c4f082020-01-17 16:13:26 +0000153 }
154 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000155 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
156 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
157 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000158 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800159 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000160 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Karl Zhangf6f467e2020-07-10 16:24:45 +0800161 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000162 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Hugo L'Hostise55a2752021-01-27 11:09:08 +0000163 if (env.JOB_NAME.equals("tf-m-nightly")) { //Setting the Memory footprint gathering.
164 params += string(name: 'SQUAD_CONFIGURATIONS', value: env.SQUAD_CONFIGURATIONS)
165 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000166 return { -> results
167 def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false)
168 def build_info = [build_res, config, params_collection]
169 results['builds'][build_res.number] = build_info
170 def build_url = build_res.getAbsoluteUrl()
171 print("${build_res.number}: ${config} ${build_res.result} ${build_url}")
172 failure_states = ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]
173 if (build_res.result in failure_states) {
174 error("Build failed at ${build_url}")
175 }
Karl Zhang2b10b342020-11-09 14:50:11 +0800176 else if (params_collection["NS"] == "False" || \
Karl Zhang0b7bb4a2021-01-18 16:22:08 +0800177 (params_collection["TFM_PLATFORM"].contains("musca_b1") && \
Xinyu Zhang5565e3d2021-09-02 11:42:27 +0800178 env.JOB_NAME.equals("tf-m-build-and-test"))) {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800179 print("LAVA is not needed for ${build_url}")
180 }
Xinyu Zhang7bb69162021-07-01 03:40:53 +0100181 // Only submit LAVA test for a specified OTP enabled config in nightly or release job
182 else if (params_collection["OTP"] == "ENABLED" && \
Xinyu Zhangc4bb2e12021-07-21 22:40:35 +0800183 params_collection["CONFIG_NAME"] != "MUSCA_B1_GNUARM_PSA_3_REG_Debug_OTP_BL2_NS") {
Xinyu Zhang7bb69162021-07-01 03:40:53 +0100184 print("LAVA is not needed for ${build_url}")
185 }
Xinyu Zhangc4bb2e12021-07-21 22:40:35 +0800186 else if (params_collection["CONFIG_NAME"] == "MUSCA_B1_GNUARM_PSA_3_REG_Debug_OTP_BL2_NS" && \
Xinyu Zhang7bb69162021-07-01 03:40:53 +0100187 !(env.JOB_NAME.equals("tf-m-nightly") || env.JOB_NAME.equals("tf-m-release"))) {
Xinyu Zhang97114342021-01-21 14:08:03 +0800188 print("LAVA is not needed for ${build_url}")
189 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000190 else {
191 print("Doing LAVA stuff for ${build_url}")
Xinyu Zhangaa3747f2020-12-24 16:27:06 +0800192 params += generateLavaParam(params_collection)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000193 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
194 params += string(name: 'BUILD_URL', value: build_url)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000195 params += string(name: 'LAVA_URL', value: env.LAVA_URL)
Dean Birch956416f2020-08-12 10:36:16 +0100196 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
197 params += string(name: 'LAVA_CREDENTIALS', value: env.LAVA_CREDENTIALS)
Leonardo Sandoval12fbb2f2021-04-15 14:36:09 -0500198 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000199 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
Xinyu Zhang32f8c1c2021-05-12 14:38:24 +0800200 def lava_resubmitted = false
Matthew Hartfb6fd362020-03-04 21:03:59 +0000201 if (lava_res.result in failure_states) {
202 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
203 }
204 else {
Xinyu Zhang32f8c1c2021-05-12 14:38:24 +0800205 lava_des = lava_res.getDescription()
206 if (lava_des.contains(" Submitted twice!")) {
207 lava_resubmitted = true
208 lava_des = lava_des - " Submitted twice!"
209 }
210 results['lava_jobs'] += lava_des
Matthew Hartfb6fd362020-03-04 21:03:59 +0000211 }
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800212 links = "Build Config: ${config}\n"
213 links += "Build URL: ${build_url}\n"
214 links += "LAVA Submit: ${lava_res.getAbsoluteUrl()}"
Xinyu Zhang32f8c1c2021-05-12 14:38:24 +0800215 if (lava_resubmitted) {
216 links += "\nLAVA Job Re-Submitted!"
217 }
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800218 print(links)
Dean Birch62c4f082020-01-17 16:13:26 +0000219 }
220 }
221}
222
Matthew Hart06340d72020-06-15 16:08:20 +0100223def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000224 def params = []
225 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000226 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
227 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
228 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000229 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800230 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000231 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000232 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Matthew Hart06340d72020-06-15 16:08:20 +0100233 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +0000234 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
235 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +0100236 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +0000237 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +0000238 error("Build failed at ${res.getAbsoluteUrl()}")
239 }
240 }
241}
242
Xinyu Zhang38a18872020-11-23 16:45:28 +0800243def generateEmailBody(stage, failed_jobs) {
244 body = "Check console output at ${env.BUILD_URL} \n\n"
245
246 body += "Failed Jobs:\n"
247 failed_jobs.each { job ->
248 body += "${job.key} ${job.value}\n"
249 }
250
251 body += "\nFor detailed ${stage} results please refer to \
252 ${env.BUILD_URL}artifact/${stage}_results.csv \n"
253 return body
254}
255
256def emailNotification(results, stage, failed_jobs) {
Karl Zhang0413e972020-09-18 17:59:26 +0800257 script {
258 if (env.JOB_NAME.equals("tf-m-nightly") && !env.EMAIL_NOTIFICATION.equals('')) {
259 def result = "Fail."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800260 if (results == true) {
Karl Zhang0413e972020-09-18 17:59:26 +0800261 result = "Success."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800262 print("Skip sending as ${result} for ${stage}")
263 }
264 else {
265 emailext (
266 subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} ${result}"),
Xinyu Zhang38a18872020-11-23 16:45:28 +0800267 body: generateEmailBody(stage, failed_jobs),
Karl Zhang182ecdf2020-10-10 09:52:12 +0800268 to: "${EMAIL_NOTIFICATION}"
269 )
270 }
Karl Zhang0413e972020-09-18 17:59:26 +0800271 }
272 } /* script */
273}
274
Xinyu Zhang38a18872020-11-23 16:45:28 +0800275def filterFailedBuild(results) {
276 def failed_builds = [:]
277 results.each { result ->
278 if (result.value[0].getResult() == "FAILURE") {
279 failed_builds[result.value[1]] = result.value[0].getAbsoluteUrl()
280 }
281 }
282 return failed_builds
283}
284
285def filterFailedTest(string) {
286 def failed_tests = [:]
287 line = lineInString(string, "FAILURE_TESTS:")
288 a = line.split(' ')
289 if (a.size() > 1) {
290 a = line.split(' ')[1..-1]
291 a.each { fail_test ->
292 config_link = fail_test.split(':')
293 failed_tests[config_link[0]] = config_link[1..-1].join(':')
294 }
295 }
296 return failed_tests
297}
298
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800299@NonCPS
300def generateCsvContent(results) {
301 def resultsParam = []
302 results.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800303 if (result.value[2]['BL2'] == "True") {
304 resultsParam.add([result.value[1], \
305 result.value[0].getResult(), \
306 result.value[2]['TFM_PLATFORM'], \
307 result.value[2]['TOOLCHAIN_FILE'], \
308 result.value[2]['CMAKE_BUILD_TYPE'], \
309 result.value[2]['BL2'], \
310 result.value[2]['NS'], \
311 result.value[2]['PSA_API'], \
312 result.value[2]['ISOLATION_LEVEL'], \
313 result.value[2]['TEST_REGRESSION'], \
314 result.value[2]['TEST_PSA_API'], \
315 result.value[2]['PROFILE'], \
316 result.value[2]['PARTITION_PS'], \
317 result.value[2]['OTP']])
318 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800319 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800320 resultsParam.each { result ->
Xinyu Zhang8d95fc12021-07-21 10:58:39 +0800321 if (result[2] == 'arm/musca_b1/sse_200') {
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800322 if (result[13] != 'off') {
Xinyu Zhang8d95fc12021-07-21 10:58:39 +0800323 result[2] = 'arm/musca_b1/sse_200_OTP'
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800324 }
325 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800326 result[3] = mapCompiler[result[3]]
327 build_params = result[5..12]
328 configName = ""
329 for (map_cfg in mapConfigs) {
330 if (build_params[0..6] == map_cfg[0..6]) {
331 configName = map_cfg[7]
332 break
333 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800334 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800335 if (configName == "") {
336 configName = "Default"
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800337 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800338 else if (configName == "RegressionProfileM") {
339 if (build_params[7] == "OFF") {
340 configName = "RegressionProfileM PSOFF"
341 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800342 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800343 result.add(configName)
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800344 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800345 def csvContent = []
346 resultsParam.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800347 current_row = result[2..4]
348 cfgs.each {cfg ->
349 if (cfg == result[14]) {
350 current_row.add(cfg)
351 current_row.add(result[1])
352 }
353 }
354 csvContent.add(current_row)
355 }
356 csvContent.sort{a,b -> a[0] <=> b[0] ?: a[1] <=> b[1] ?: a[2] <=> b[2]}
357 build_summary = []
358 current_platform = ""
359 current_compiler = ""
360 current_build_type = ""
361 csvContent.each { build_cfg ->
362 if (current_platform != build_cfg[0] || \
363 current_compiler != build_cfg[1] || \
364 current_build_type != build_cfg[2]) {
365 current_platform = build_cfg[0]
366 current_compiler = build_cfg[1]
367 current_build_type = build_cfg[2]
368 csv_line = [current_platform, current_compiler, current_build_type]
369 cfgs.each {
370 csv_line.add("N.A.")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800371 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800372 build_summary.add(csv_line)
373 }
374 i = 0
375 cfgs.each { cfg ->
376 if (cfg == build_cfg[3]) {
377 build_summary[-1][3+i] = build_cfg[4]
378 }
379 i += 1
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800380 }
381 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800382 build_summary.add(0, ['Platform', 'Compiler', 'Cmake Build Type'])
383 build_summary[0] += cfgs
384 return build_summary
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800385}
386
387def generateBuildCsv(results) {
388 def csvContent = generateCsvContent(results)
389 node("master") {
390 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
391 archiveArtifacts 'build_results.csv'
392 }
393}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000394
395def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000396 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000397 def csvContent = summary.getBuildCsv(results)
398 node("master") {
399 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
400 archiveArtifacts 'build_results.csv'
401 }
402}
403
404def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000405 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000406 def buildLinks = summary.getLinks(results)
407 node("master") {
408 writeFile file: "build_links.html", text: buildLinks
409 archiveArtifacts 'build_links.html'
410 }
411}
412
Matthew Hartfb6fd362020-03-04 21:03:59 +0000413def lineInString(string, match) {
414 def lines = string.split("\n")
415 def result = lines.findAll { it.contains(match) }
416 return result[0]
417}
418
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800419def showLinks(string) {
420 def lines = string.split("\n")
421 def result = lines.findAll { it.contains("Build Config: ")}
422 links = result.join("\n")
423 print(links)
424}
425
Matthew Hartfb6fd362020-03-04 21:03:59 +0000426def getResult(string, match) {
427 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100428 a = line.split(match)[1].split(' ')
429 score = a[0]
430 if (a.size() > 1)
431 {
432 fail_text = a[1..-1].join(" ")
433 return [score, fail_text]
434 }
435 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000436}
437
438def submitJobsToList(results) {
439 def all_jobs = []
440 for (String result : results){
441 jobs_s = result.split('JOBS: ')
442 if (jobs_s.size() > 1) {
443 all_jobs += jobs_s[1]
444 }
445 }
446 return(all_jobs)
447}
448
Dean Birch62c4f082020-01-17 16:13:26 +0000449def configs = []
450def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000451def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000452
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800453timestamps {
454 node("docker-amd64-tf-m-bionic") {
455 stage("Init") {
456 cleanWs()
457 dir("tf-m-ci-scripts") {
458 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
Xinyu Zhang8472b852021-09-04 00:13:34 +0800459 sh "git rev-parse --short HEAD"
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800460 }
461 }
462 stage("Configs") {
463 // Populate configs
464 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
465 results['builds'] = [:]
466 results['lava_jobs'] = []
467 for (config in configs) {
468 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
469 }
470 builds["docs"] = buildDocs(results)
Dean Birch62c4f082020-01-17 16:13:26 +0000471 }
472 }
Karl Zhangfec84102020-06-24 09:56:36 +0800473
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800474 stage("Builds") {
475 def verify = 1
Matthew Hartfb6fd362020-03-04 21:03:59 +0000476 def success = true
Matthew Hartfb6fd362020-03-04 21:03:59 +0000477 try {
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800478 parallel(builds)
479 } catch (Exception e) {
480 print(e)
481 manager.buildFailure()
482 verify = -1
483 success = false
484 } finally {
485 print("Verifying status")
486 def failed_builds = filterFailedBuild(results['builds'])
487 emailNotification(success, 'build', failed_builds)
488 g = new Gerrit()
489 g.verifyStatus(verify, 'tf-m-build', 'build')
490 print("Building CSV")
491 generateBuildCsv(results['builds'])
492 writeSummary(results['builds'])
493 }
494 }
495
496 node("docker-amd64-tf-m-bionic") {
497 stage("Tests") {
498 dir("tf-m-ci-scripts") {
499 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
500 }
501 def all_jobs = []
502 def success = true
503 print("Wait for LAVA results here...")
504 try {
505 all_jobs = submitJobsToList(results['lava_jobs'])
506 if (all_jobs.size() > 0) {
507 dir("tf-m-ci-scripts") {
508 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
509 output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
510 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
511 --artifacts-path lava_artifacts --lava-timeout 7200 \
512 """, returnStdout: true).trim()
513 showLinks(output)
514 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
515 archiveArtifacts artifacts: 'test_results.csv', allowEmptyArchive: true
516 g = new Gerrit()
517 def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ')
518 if (boot_result) {
519 g.verifyStatus(boot_result, "lava_boot", "test")
520 }
521 def (test_result, test_output) = getResult(output, 'TEST_RESULT: ')
522 if (test_result) {
523 g.verifyStatus(test_result, "lava_test", "test")
524 }
525 if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) {
526 error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}")
527 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000528 }
529 }
530 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800531 else {
532 print("There were no LAVA jobs to test.")
533 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000534 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800535 catch (Exception e) {
536 print("ERROR: ${e}")
537 success = false
538 } finally {
539 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
540 if (all_jobs.size() > 0) {
541 emailNotification(success, 'test', filterFailedTest(output))
542 }
543 cleanWs()
544 if (!success) {
545 error("There was an Error waiting for LAVA jobs")
546 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000547 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000548 }
549 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000550}