blob: 25b73ebb38e542e451ff7ec28bd83727bba169cd [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",
Arthur Shef3657742021-09-07 14:23:18 -070023 "arm/diphda": "DIPHDA",
24 "nxp/lpcxpresso55s69": "lpcxpresso55s69"]
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080025
26mapCompiler = ["toolchain_GNUARM.cmake": "GNUARM",
27 "toolchain_ARMCLANG.cmake": "ARMCLANG"]
28
29mapBL2 = ["True": "--bl2",
30 "False": ""]
31
32mapTestPsaApi = ["OFF": "",
Xinyu Zhang39acb412021-07-09 20:35:19 +080033 "STORAGE": "STORAGE",
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080034 "CRYPTO": "Crypto",
35 "INITIAL_ATTESTATION": "Attest",
36 "IPC": "FF"]
37
Xinyu Zhangdbfadae2020-12-07 14:42:59 +080038// BL2, NS, PSA_API, ISOLATION_LEVEL, TEST_REG, TEST_PSA_API, PROFILE, CONFIG_NAME
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080039mapConfigs = [
40 ["True", "True", "False", "1", "False", "OFF", "N.A", "Default"],
41 ["True", "True", "True", "1", "False", "OFF", "N.A", "CoreIPC"],
42 ["True", "True", "True", "2", "False", "OFF", "N.A", "CoreIPCTfmLevel2"],
43 ["True", "True", "True", "3", "False", "OFF", "N.A", "CoreIPCTfmLevel3"],
44 ["True", "True", "False", "1", "False", "OFF", "profile_small", "DefaultProfileS"],
45 ["True", "True", "True", "2", "False", "OFF", "profile_medium", "DefaultProfileM"],
Xinyu Zhang9b1aef92021-03-12 15:36:44 +080046 ["True", "True", "True", "3", "False", "OFF", "profile_large", "DefaultProfileL"],
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080047 ["True", "True", "False", "1", "True", "OFF", "N.A", "Regression"],
48 ["True", "True", "True", "1", "True", "OFF", "N.A", "RegressionIPC"],
49 ["True", "True", "True", "2", "True", "OFF", "N.A", "RegressionIPCTfmLevel2"],
50 ["True", "True", "True", "3", "True", "OFF", "N.A", "RegressionIPCTfmLevel3"],
51 ["True", "True", "False", "1", "True", "OFF", "profile_small", "RegressionProfileS"],
52 ["True", "True", "True", "2", "True", "OFF", "profile_medium", "RegressionProfileM"],
Xinyu Zhang9b1aef92021-03-12 15:36:44 +080053 ["True", "True", "True", "3", "True", "OFF", "profile_large", "RegressionProfileL"],
Xinyu Zhang39acb412021-07-09 20:35:19 +080054 ["True", "True", "False", "1", "False", "STORAGE", "N.A", "PsaApiTest (STORAGE)"],
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080055 ["True", "True", "False", "1", "False", "CRYPTO", "N.A", "PsaApiTest (Crypto)"],
56 ["True", "True", "False", "1", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTest (Attest)"],
57 ["True", "True", "False", "1", "False", "IPC", "N.A", "PsaApiTest (FF)"],
Xinyu Zhang39acb412021-07-09 20:35:19 +080058 ["True", "True", "True", "1", "False", "STORAGE", "N.A", "PsaApiTestIPC (STORAGE)"],
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080059 ["True", "True", "True", "1", "False", "CRYPTO", "N.A", "PsaApiTestIPC (Crypto)"],
60 ["True", "True", "True", "1", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPC (Attest)"],
61 ["True", "True", "True", "1", "False", "IPC", "N.A", "PsaApiTestIPC (FF)"],
Xinyu Zhang39acb412021-07-09 20:35:19 +080062 ["True", "True", "True", "2", "False", "STORAGE", "N.A", "PsaApiTestIPCTfmLevel2 (STORAGE)"],
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080063 ["True", "True", "True", "2", "False", "CRYPTO", "N.A", "PsaApiTestIPCTfmLevel2 (Crypto)"],
64 ["True", "True", "True", "2", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPCTfmLevel2 (Attest)"],
65 ["True", "True", "True", "2", "False", "IPC", "N.A", "PsaApiTestIPCTfmLevel2 (FF)"],
Xinyu Zhang39acb412021-07-09 20:35:19 +080066 ["True", "True", "True", "3", "False", "STORAGE", "N.A", "PsaApiTestIPCTfmLevel3 (STORAGE)"],
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080067 ["True", "True", "True", "3", "False", "CRYPTO", "N.A", "PsaApiTestIPCTfmLevel3 (Crypto)"],
68 ["True", "True", "True", "3", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPCTfmLevel3 (Attest)"],
69 ["True", "True", "True", "3", "False", "IPC", "N.A", "PsaApiTestIPCTfmLevel3 (FF)"],
70]
71
72cfgs = ["Default", "CoreIPC", "CoreIPCTfmLevel2", "CoreIPCTfmLevel3",
73 "Regression", "RegressionIPC",
74 "RegressionIPCTfmLevel2", "RegressionIPCTfmLevel3",
75 "DefaultProfileS", "RegressionProfileS",
76 "DefaultProfileM", "RegressionProfileM", "RegressionProfileM PSOFF",
Xinyu Zhang9b1aef92021-03-12 15:36:44 +080077 "DefaultProfileL", "RegressionProfileL",
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080078 "PsaApiTest (Attest)", "PsaApiTestIPC (Attest)",
79 "PsaApiTestIPCTfmLevel2 (Attest)",
80 "PsaApiTest (Crypto)", "PsaApiTestIPC (Crypto)",
81 "PsaApiTestIPCTfmLevel2 (Crypto)",
Xinyu Zhang39acb412021-07-09 20:35:19 +080082 "PsaApiTest (STORAGE)", "PsaApiTestIPC (STORAGE)",
83 "PsaApiTestIPCTfmLevel2 (STORAGE)",
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080084 "PsaApiTestIPC (FF)",
85 "PsaApiTestIPCTfmLevel2 (FF)",
Xinyu Zhang39acb412021-07-09 20:35:19 +080086 "PsaApiTestIPCTfmLevel3 (STORAGE)", "PsaApiTestIPCTfmLevel3 (Crypto)",
87 "PsaApiTestIPCTfmLevel3 (Attest)", "PsaApiTestIPCTfmLevel3 (FF)"]
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080088
Xinyu Zhangaa3747f2020-12-24 16:27:06 +080089@NonCPS
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080090def generateLavaParam(build_params) {
91 def params = []
Summer Qin3c2b5722021-05-26 10:43:45 +080092 if (build_params["TFM_PLATFORM"] == "arm/musca_b1/sse_200" && \
Xinyu Zhang97114342021-01-21 14:08:03 +080093 build_params["OTP"] == "ENABLED") {
94 params += string(name: "TARGET_PLATFORM", value: "MUSCA_B1_OTP")
95 }
96 else {
97 params += string(name: "TARGET_PLATFORM", \
98 value: mapPlatform[build_params["TFM_PLATFORM"]])
99 }
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800100 params += string(name: "COMPILER", \
101 value: mapCompiler[build_params["TOOLCHAIN_FILE"]])
102 params += string(name: "PSA_API_SUITE", \
103 value: mapTestPsaApi[build_params["TEST_PSA_API"]])
104
Xinyu Zhangdbfadae2020-12-07 14:42:59 +0800105 configName = "Config"
106 config_params = [build_params["BL2"], build_params["NS"], \
107 build_params["PSA_API"], build_params["ISOLATION_LEVEL"], \
108 build_params["TEST_REGRESSION"], build_params["TEST_PSA_API"], \
109 build_params["PROFILE"]]
110 for (config in mapConfigs) {
111 if (config_params == config[0..6]) {
Xinyu Zhangfc1bacd2020-12-24 15:26:35 +0800112 configName += config[7].replace(' (', '_').replace(')', '')
Xinyu Zhangdbfadae2020-12-07 14:42:59 +0800113 break
114 }
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800115 }
Xinyu Zhangdbfadae2020-12-07 14:42:59 +0800116 if (configName == "Config") {
117 configName = "ConfigDefault"
118 }
119 params += string(name: "PROJ_CONFIG", value: configName)
Xinyu Zhangaa3747f2020-12-24 16:27:06 +0800120 print("Params of ${configName} :")
121 print(config_params)
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800122 return params
123}
124
Dean Birch62c4f082020-01-17 16:13:26 +0000125def listConfigs(ci_scripts_dir, config_list, filter_group) {
126 dir(ci_scripts_dir) {
127 echo "Obtaining list of configs."
Matthew Hartfb6fd362020-03-04 21:03:59 +0000128 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}"
Dean Birch62c4f082020-01-17 16:13:26 +0000129 def build_config_list_raw = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +0000130python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}
Dean Birch62c4f082020-01-17 16:13:26 +0000131""", returnStdout: true).trim()
132 def build_config_list = build_config_list_raw.tokenize('\n')
133 config_list.addAll(build_config_list)
134 }
135}
136
Matthew Hartfb6fd362020-03-04 21:03:59 +0000137def buildConfig(ci_scripts_dir, config, filter_group, results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000138 def params = []
Matthew Hartfb6fd362020-03-04 21:03:59 +0000139 def params_collection = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000140 def build_config_params
141 dir(ci_scripts_dir) {
142 echo "Obtaining build configuration for config ${config}"
Matthew Hartfb6fd362020-03-04 21:03:59 +0000143 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}"
Dean Birch62c4f082020-01-17 16:13:26 +0000144 build_config_params = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +0000145python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}
Dean Birch62c4f082020-01-17 16:13:26 +0000146""", returnStdout: true).trim()
147 }
148 def lines = build_config_params.tokenize('\n')
149 for (String line : lines) {
150 def key, value
151 (key, value) = line.tokenize('=')
152 params += string(name: key, value: value)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000153 params_collection[key] = value
Dean Birch62c4f082020-01-17 16:13:26 +0000154 }
155 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000156 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
157 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
158 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000159 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800160 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000161 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Karl Zhangf6f467e2020-07-10 16:24:45 +0800162 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000163 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Hugo L'Hostise55a2752021-01-27 11:09:08 +0000164 if (env.JOB_NAME.equals("tf-m-nightly")) { //Setting the Memory footprint gathering.
165 params += string(name: 'SQUAD_CONFIGURATIONS', value: env.SQUAD_CONFIGURATIONS)
166 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000167 return { -> results
168 def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false)
169 def build_info = [build_res, config, params_collection]
170 results['builds'][build_res.number] = build_info
171 def build_url = build_res.getAbsoluteUrl()
172 print("${build_res.number}: ${config} ${build_res.result} ${build_url}")
173 failure_states = ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]
Xinyu Zhangf2ba9112021-09-02 13:31:16 +0800174
175 // Filter out configs do not need LAVA tests
176
177 // Configs with build failure do not need LAVA tests
Dean Bircha6ede7e2020-03-13 14:00:33 +0000178 if (build_res.result in failure_states) {
179 error("Build failed at ${build_url}")
180 }
Xinyu Zhang372e8a12021-09-02 13:51:39 +0800181 // Configs without BL2 do not need LAVA tests
182 else if (params_collection["BL2"] == "False") {
183 print("LAVA is not needed for ${build_url}")
184 }
Xinyu Zhangf2ba9112021-09-02 13:31:16 +0800185 // Configs without building NS app do not need LAVA tests
186 else if (params_collection["NS"] == "False") {
187 print("LAVA is not needed for ${build_url}")
188 }
189 // LAVA tests on MUSCA_B1 are not needed in per-patch job
190 else if (params_collection["TFM_PLATFORM"].contains("musca_b1") && \
191 env.JOB_NAME.equals("tf-m-build-and-test")) {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800192 print("LAVA is not needed for ${build_url}")
193 }
Xinyu Zhang7bb69162021-07-01 03:40:53 +0100194 // Only submit LAVA test for a specified OTP enabled config in nightly or release job
195 else if (params_collection["OTP"] == "ENABLED" && \
Xinyu Zhangc4bb2e12021-07-21 22:40:35 +0800196 params_collection["CONFIG_NAME"] != "MUSCA_B1_GNUARM_PSA_3_REG_Debug_OTP_BL2_NS") {
Xinyu Zhang7bb69162021-07-01 03:40:53 +0100197 print("LAVA is not needed for ${build_url}")
198 }
Xinyu Zhangc4bb2e12021-07-21 22:40:35 +0800199 else if (params_collection["CONFIG_NAME"] == "MUSCA_B1_GNUARM_PSA_3_REG_Debug_OTP_BL2_NS" && \
Xinyu Zhang7bb69162021-07-01 03:40:53 +0100200 !(env.JOB_NAME.equals("tf-m-nightly") || env.JOB_NAME.equals("tf-m-release"))) {
Xinyu Zhang97114342021-01-21 14:08:03 +0800201 print("LAVA is not needed for ${build_url}")
202 }
Xinyu Zhangf2ba9112021-09-02 13:31:16 +0800203
204 // Submit LAVA tests
Dean Bircha6ede7e2020-03-13 14:00:33 +0000205 else {
206 print("Doing LAVA stuff for ${build_url}")
Xinyu Zhangaa3747f2020-12-24 16:27:06 +0800207 params += generateLavaParam(params_collection)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000208 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
209 params += string(name: 'BUILD_URL', value: build_url)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000210 params += string(name: 'LAVA_URL', value: env.LAVA_URL)
Dean Birch956416f2020-08-12 10:36:16 +0100211 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
212 params += string(name: 'LAVA_CREDENTIALS', value: env.LAVA_CREDENTIALS)
Leonardo Sandoval12fbb2f2021-04-15 14:36:09 -0500213 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000214 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
Xinyu Zhang32f8c1c2021-05-12 14:38:24 +0800215 def lava_resubmitted = false
Matthew Hartfb6fd362020-03-04 21:03:59 +0000216 if (lava_res.result in failure_states) {
217 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
218 }
219 else {
Xinyu Zhang32f8c1c2021-05-12 14:38:24 +0800220 lava_des = lava_res.getDescription()
221 if (lava_des.contains(" Submitted twice!")) {
222 lava_resubmitted = true
223 lava_des = lava_des - " Submitted twice!"
224 }
225 results['lava_jobs'] += lava_des
Matthew Hartfb6fd362020-03-04 21:03:59 +0000226 }
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800227 links = "Build Config: ${config}\n"
228 links += "Build URL: ${build_url}\n"
229 links += "LAVA Submit: ${lava_res.getAbsoluteUrl()}"
Xinyu Zhang32f8c1c2021-05-12 14:38:24 +0800230 if (lava_resubmitted) {
231 links += "\nLAVA Job Re-Submitted!"
232 }
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800233 print(links)
Dean Birch62c4f082020-01-17 16:13:26 +0000234 }
235 }
236}
237
Matthew Hart06340d72020-06-15 16:08:20 +0100238def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000239 def params = []
240 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000241 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
242 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
243 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000244 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800245 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000246 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000247 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Matthew Hart06340d72020-06-15 16:08:20 +0100248 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +0000249 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
250 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +0100251 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +0000252 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +0000253 error("Build failed at ${res.getAbsoluteUrl()}")
254 }
255 }
256}
257
Xinyu Zhang38a18872020-11-23 16:45:28 +0800258def generateEmailBody(stage, failed_jobs) {
259 body = "Check console output at ${env.BUILD_URL} \n\n"
260
261 body += "Failed Jobs:\n"
262 failed_jobs.each { job ->
263 body += "${job.key} ${job.value}\n"
264 }
265
266 body += "\nFor detailed ${stage} results please refer to \
267 ${env.BUILD_URL}artifact/${stage}_results.csv \n"
268 return body
269}
270
271def emailNotification(results, stage, failed_jobs) {
Karl Zhang0413e972020-09-18 17:59:26 +0800272 script {
273 if (env.JOB_NAME.equals("tf-m-nightly") && !env.EMAIL_NOTIFICATION.equals('')) {
274 def result = "Fail."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800275 if (results == true) {
Karl Zhang0413e972020-09-18 17:59:26 +0800276 result = "Success."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800277 print("Skip sending as ${result} for ${stage}")
278 }
279 else {
280 emailext (
281 subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} ${result}"),
Xinyu Zhang38a18872020-11-23 16:45:28 +0800282 body: generateEmailBody(stage, failed_jobs),
Karl Zhang182ecdf2020-10-10 09:52:12 +0800283 to: "${EMAIL_NOTIFICATION}"
284 )
285 }
Karl Zhang0413e972020-09-18 17:59:26 +0800286 }
287 } /* script */
288}
289
Xinyu Zhang38a18872020-11-23 16:45:28 +0800290def filterFailedBuild(results) {
291 def failed_builds = [:]
292 results.each { result ->
293 if (result.value[0].getResult() == "FAILURE") {
294 failed_builds[result.value[1]] = result.value[0].getAbsoluteUrl()
295 }
296 }
297 return failed_builds
298}
299
300def filterFailedTest(string) {
301 def failed_tests = [:]
302 line = lineInString(string, "FAILURE_TESTS:")
303 a = line.split(' ')
304 if (a.size() > 1) {
305 a = line.split(' ')[1..-1]
306 a.each { fail_test ->
307 config_link = fail_test.split(':')
308 failed_tests[config_link[0]] = config_link[1..-1].join(':')
309 }
310 }
311 return failed_tests
312}
313
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800314@NonCPS
315def generateCsvContent(results) {
316 def resultsParam = []
317 results.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800318 if (result.value[2]['BL2'] == "True") {
319 resultsParam.add([result.value[1], \
320 result.value[0].getResult(), \
321 result.value[2]['TFM_PLATFORM'], \
322 result.value[2]['TOOLCHAIN_FILE'], \
323 result.value[2]['CMAKE_BUILD_TYPE'], \
324 result.value[2]['BL2'], \
325 result.value[2]['NS'], \
326 result.value[2]['PSA_API'], \
327 result.value[2]['ISOLATION_LEVEL'], \
328 result.value[2]['TEST_REGRESSION'], \
329 result.value[2]['TEST_PSA_API'], \
330 result.value[2]['PROFILE'], \
331 result.value[2]['PARTITION_PS'], \
332 result.value[2]['OTP']])
333 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800334 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800335 resultsParam.each { result ->
Xinyu Zhang8d95fc12021-07-21 10:58:39 +0800336 if (result[2] == 'arm/musca_b1/sse_200') {
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800337 if (result[13] != 'off') {
Xinyu Zhang8d95fc12021-07-21 10:58:39 +0800338 result[2] = 'arm/musca_b1/sse_200_OTP'
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800339 }
340 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800341 result[3] = mapCompiler[result[3]]
342 build_params = result[5..12]
343 configName = ""
344 for (map_cfg in mapConfigs) {
345 if (build_params[0..6] == map_cfg[0..6]) {
346 configName = map_cfg[7]
347 break
348 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800349 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800350 if (configName == "") {
351 configName = "Default"
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800352 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800353 else if (configName == "RegressionProfileM") {
354 if (build_params[7] == "OFF") {
355 configName = "RegressionProfileM PSOFF"
356 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800357 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800358 result.add(configName)
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800359 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800360 def csvContent = []
361 resultsParam.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800362 current_row = result[2..4]
363 cfgs.each {cfg ->
364 if (cfg == result[14]) {
365 current_row.add(cfg)
366 current_row.add(result[1])
367 }
368 }
369 csvContent.add(current_row)
370 }
371 csvContent.sort{a,b -> a[0] <=> b[0] ?: a[1] <=> b[1] ?: a[2] <=> b[2]}
372 build_summary = []
373 current_platform = ""
374 current_compiler = ""
375 current_build_type = ""
376 csvContent.each { build_cfg ->
377 if (current_platform != build_cfg[0] || \
378 current_compiler != build_cfg[1] || \
379 current_build_type != build_cfg[2]) {
380 current_platform = build_cfg[0]
381 current_compiler = build_cfg[1]
382 current_build_type = build_cfg[2]
383 csv_line = [current_platform, current_compiler, current_build_type]
384 cfgs.each {
385 csv_line.add("N.A.")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800386 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800387 build_summary.add(csv_line)
388 }
389 i = 0
390 cfgs.each { cfg ->
391 if (cfg == build_cfg[3]) {
392 build_summary[-1][3+i] = build_cfg[4]
393 }
394 i += 1
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800395 }
396 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800397 build_summary.add(0, ['Platform', 'Compiler', 'Cmake Build Type'])
398 build_summary[0] += cfgs
399 return build_summary
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800400}
401
402def generateBuildCsv(results) {
403 def csvContent = generateCsvContent(results)
404 node("master") {
405 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
406 archiveArtifacts 'build_results.csv'
407 }
408}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000409
410def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000411 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000412 def csvContent = summary.getBuildCsv(results)
413 node("master") {
414 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
415 archiveArtifacts 'build_results.csv'
416 }
417}
418
419def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000420 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000421 def buildLinks = summary.getLinks(results)
422 node("master") {
423 writeFile file: "build_links.html", text: buildLinks
424 archiveArtifacts 'build_links.html'
425 }
426}
427
Matthew Hartfb6fd362020-03-04 21:03:59 +0000428def lineInString(string, match) {
429 def lines = string.split("\n")
430 def result = lines.findAll { it.contains(match) }
431 return result[0]
432}
433
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800434def showLinks(string) {
435 def lines = string.split("\n")
436 def result = lines.findAll { it.contains("Build Config: ")}
437 links = result.join("\n")
438 print(links)
439}
440
Matthew Hartfb6fd362020-03-04 21:03:59 +0000441def getResult(string, match) {
442 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100443 a = line.split(match)[1].split(' ')
444 score = a[0]
445 if (a.size() > 1)
446 {
447 fail_text = a[1..-1].join(" ")
448 return [score, fail_text]
449 }
450 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000451}
452
453def submitJobsToList(results) {
454 def all_jobs = []
455 for (String result : results){
456 jobs_s = result.split('JOBS: ')
457 if (jobs_s.size() > 1) {
458 all_jobs += jobs_s[1]
459 }
460 }
461 return(all_jobs)
462}
463
Dean Birch62c4f082020-01-17 16:13:26 +0000464def configs = []
465def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000466def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000467
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800468timestamps {
469 node("docker-amd64-tf-m-bionic") {
470 stage("Init") {
471 cleanWs()
472 dir("tf-m-ci-scripts") {
473 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
Xinyu Zhang8472b852021-09-04 00:13:34 +0800474 sh "git rev-parse --short HEAD"
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800475 }
476 }
477 stage("Configs") {
478 // Populate configs
479 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
480 results['builds'] = [:]
481 results['lava_jobs'] = []
482 for (config in configs) {
483 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
484 }
485 builds["docs"] = buildDocs(results)
Dean Birch62c4f082020-01-17 16:13:26 +0000486 }
487 }
Karl Zhangfec84102020-06-24 09:56:36 +0800488
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800489 stage("Builds") {
490 def verify = 1
Matthew Hartfb6fd362020-03-04 21:03:59 +0000491 def success = true
Matthew Hartfb6fd362020-03-04 21:03:59 +0000492 try {
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800493 parallel(builds)
494 } catch (Exception e) {
495 print(e)
496 manager.buildFailure()
497 verify = -1
498 success = false
499 } finally {
500 print("Verifying status")
501 def failed_builds = filterFailedBuild(results['builds'])
502 emailNotification(success, 'build', failed_builds)
503 g = new Gerrit()
504 g.verifyStatus(verify, 'tf-m-build', 'build')
505 print("Building CSV")
506 generateBuildCsv(results['builds'])
507 writeSummary(results['builds'])
508 }
509 }
510
511 node("docker-amd64-tf-m-bionic") {
512 stage("Tests") {
513 dir("tf-m-ci-scripts") {
514 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
515 }
516 def all_jobs = []
517 def success = true
518 print("Wait for LAVA results here...")
519 try {
520 all_jobs = submitJobsToList(results['lava_jobs'])
521 if (all_jobs.size() > 0) {
522 dir("tf-m-ci-scripts") {
523 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
524 output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
525 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
526 --artifacts-path lava_artifacts --lava-timeout 7200 \
527 """, returnStdout: true).trim()
528 showLinks(output)
529 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
530 archiveArtifacts artifacts: 'test_results.csv', allowEmptyArchive: true
531 g = new Gerrit()
532 def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ')
533 if (boot_result) {
534 g.verifyStatus(boot_result, "lava_boot", "test")
535 }
536 def (test_result, test_output) = getResult(output, 'TEST_RESULT: ')
537 if (test_result) {
538 g.verifyStatus(test_result, "lava_test", "test")
539 }
540 if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) {
541 error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}")
542 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000543 }
544 }
545 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800546 else {
547 print("There were no LAVA jobs to test.")
548 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000549 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800550 catch (Exception e) {
551 print("ERROR: ${e}")
552 success = false
553 } finally {
554 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
555 if (all_jobs.size() > 0) {
556 emailNotification(success, 'test', filterFailedTest(output))
557 }
558 cleanWs()
559 if (!success) {
560 error("There was an Error waiting for LAVA jobs")
561 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000562 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000563 }
564 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000565}