blob: 36714e27dc26d7ad3bb7a34c2169c65c4f42f289 [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 Zhang3f7e2f52021-09-02 13:43:57 +080038// PSA_API, ISOLATION_LEVEL, TEST_REG, TEST_PSA_API, PROFILE, CONFIG_NAME
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080039mapConfigs = [
Xinyu Zhang3f7e2f52021-09-02 13:43:57 +080040 ["False", "1", "False", "OFF", "N.A", "Default"],
41 ["True", "1", "False", "OFF", "N.A", "CoreIPC"],
42 ["True", "2", "False", "OFF", "N.A", "CoreIPCTfmLevel2"],
43 ["True", "3", "False", "OFF", "N.A", "CoreIPCTfmLevel3"],
44 ["False", "1", "False", "OFF", "profile_small", "DefaultProfileS"],
45 ["True", "2", "False", "OFF", "profile_medium", "DefaultProfileM"],
46 ["True", "3", "False", "OFF", "profile_large", "DefaultProfileL"],
47 ["False", "1", "True", "OFF", "N.A", "Regression"],
48 ["True", "1", "True", "OFF", "N.A", "RegressionIPC"],
49 ["True", "2", "True", "OFF", "N.A", "RegressionIPCTfmLevel2"],
50 ["True", "3", "True", "OFF", "N.A", "RegressionIPCTfmLevel3"],
51 ["False", "1", "True", "OFF", "profile_small", "RegressionProfileS"],
52 ["True", "2", "True", "OFF", "profile_medium", "RegressionProfileM"],
53 ["True", "3", "True", "OFF", "profile_large", "RegressionProfileL"],
54 ["False", "1", "False", "STORAGE", "N.A", "PsaApiTest (STORAGE)"],
55 ["False", "1", "False", "CRYPTO", "N.A", "PsaApiTest (Crypto)"],
56 ["False", "1", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTest (Attest)"],
57 ["False", "1", "False", "IPC", "N.A", "PsaApiTest (FF)"],
58 ["True", "1", "False", "STORAGE", "N.A", "PsaApiTestIPC (STORAGE)"],
59 ["True", "1", "False", "CRYPTO", "N.A", "PsaApiTestIPC (Crypto)"],
60 ["True", "1", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPC (Attest)"],
61 ["True", "1", "False", "IPC", "N.A", "PsaApiTestIPC (FF)"],
62 ["True", "2", "False", "STORAGE", "N.A", "PsaApiTestIPCTfmLevel2 (STORAGE)"],
63 ["True", "2", "False", "CRYPTO", "N.A", "PsaApiTestIPCTfmLevel2 (Crypto)"],
64 ["True", "2", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPCTfmLevel2 (Attest)"],
65 ["True", "2", "False", "IPC", "N.A", "PsaApiTestIPCTfmLevel2 (FF)"],
66 ["True", "3", "False", "STORAGE", "N.A", "PsaApiTestIPCTfmLevel3 (STORAGE)"],
67 ["True", "3", "False", "CRYPTO", "N.A", "PsaApiTestIPCTfmLevel3 (Crypto)"],
68 ["True", "3", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPCTfmLevel3 (Attest)"],
69 ["True", "3", "False", "IPC", "N.A", "PsaApiTestIPCTfmLevel3 (FF)"],
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080070]
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"
Xinyu Zhang3f7e2f52021-09-02 13:43:57 +0800106 config_params = [build_params["PSA_API"], build_params["ISOLATION_LEVEL"], \
Xinyu Zhangdbfadae2020-12-07 14:42:59 +0800107 build_params["TEST_REGRESSION"], build_params["TEST_PSA_API"], \
108 build_params["PROFILE"]]
109 for (config in mapConfigs) {
Xinyu Zhang3f7e2f52021-09-02 13:43:57 +0800110 if (config_params == config[0..4]) {
111 configName += config[5].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"]
Xinyu Zhangf2ba9112021-09-02 13:31:16 +0800173
174 // Filter out configs do not need LAVA tests
175
176 // Configs with build failure do not need LAVA tests
Dean Bircha6ede7e2020-03-13 14:00:33 +0000177 if (build_res.result in failure_states) {
178 error("Build failed at ${build_url}")
179 }
Xinyu Zhang372e8a12021-09-02 13:51:39 +0800180 // Configs without BL2 do not need LAVA tests
181 else if (params_collection["BL2"] == "False") {
182 print("LAVA is not needed for ${build_url}")
183 }
Xinyu Zhangf2ba9112021-09-02 13:31:16 +0800184 // Configs without building NS app do not need LAVA tests
185 else if (params_collection["NS"] == "False") {
186 print("LAVA is not needed for ${build_url}")
187 }
188 // LAVA tests on MUSCA_B1 are not needed in per-patch job
189 else if (params_collection["TFM_PLATFORM"].contains("musca_b1") && \
190 env.JOB_NAME.equals("tf-m-build-and-test")) {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800191 print("LAVA is not needed for ${build_url}")
192 }
Xinyu Zhang7bb69162021-07-01 03:40:53 +0100193 // Only submit LAVA test for a specified OTP enabled config in nightly or release job
194 else if (params_collection["OTP"] == "ENABLED" && \
Xinyu Zhangc4bb2e12021-07-21 22:40:35 +0800195 params_collection["CONFIG_NAME"] != "MUSCA_B1_GNUARM_PSA_3_REG_Debug_OTP_BL2_NS") {
Xinyu Zhang7bb69162021-07-01 03:40:53 +0100196 print("LAVA is not needed for ${build_url}")
197 }
Xinyu Zhangc4bb2e12021-07-21 22:40:35 +0800198 else if (params_collection["CONFIG_NAME"] == "MUSCA_B1_GNUARM_PSA_3_REG_Debug_OTP_BL2_NS" && \
Xinyu Zhang7bb69162021-07-01 03:40:53 +0100199 !(env.JOB_NAME.equals("tf-m-nightly") || env.JOB_NAME.equals("tf-m-release"))) {
Xinyu Zhang97114342021-01-21 14:08:03 +0800200 print("LAVA is not needed for ${build_url}")
201 }
Xinyu Zhangf2ba9112021-09-02 13:31:16 +0800202
203 // Submit LAVA tests
Dean Bircha6ede7e2020-03-13 14:00:33 +0000204 else {
205 print("Doing LAVA stuff for ${build_url}")
Xinyu Zhangaa3747f2020-12-24 16:27:06 +0800206 params += generateLavaParam(params_collection)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000207 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
208 params += string(name: 'BUILD_URL', value: build_url)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000209 params += string(name: 'LAVA_URL', value: env.LAVA_URL)
Dean Birch956416f2020-08-12 10:36:16 +0100210 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
211 params += string(name: 'LAVA_CREDENTIALS', value: env.LAVA_CREDENTIALS)
Leonardo Sandoval12fbb2f2021-04-15 14:36:09 -0500212 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000213 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
Xinyu Zhang32f8c1c2021-05-12 14:38:24 +0800214 def lava_resubmitted = false
Matthew Hartfb6fd362020-03-04 21:03:59 +0000215 if (lava_res.result in failure_states) {
216 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
217 }
218 else {
Xinyu Zhang32f8c1c2021-05-12 14:38:24 +0800219 lava_des = lava_res.getDescription()
220 if (lava_des.contains(" Submitted twice!")) {
221 lava_resubmitted = true
222 lava_des = lava_des - " Submitted twice!"
223 }
224 results['lava_jobs'] += lava_des
Matthew Hartfb6fd362020-03-04 21:03:59 +0000225 }
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800226 links = "Build Config: ${config}\n"
227 links += "Build URL: ${build_url}\n"
228 links += "LAVA Submit: ${lava_res.getAbsoluteUrl()}"
Xinyu Zhang32f8c1c2021-05-12 14:38:24 +0800229 if (lava_resubmitted) {
230 links += "\nLAVA Job Re-Submitted!"
231 }
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800232 print(links)
Dean Birch62c4f082020-01-17 16:13:26 +0000233 }
234 }
235}
236
Matthew Hart06340d72020-06-15 16:08:20 +0100237def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000238 def params = []
239 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000240 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
241 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
242 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000243 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800244 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000245 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000246 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Matthew Hart06340d72020-06-15 16:08:20 +0100247 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +0000248 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
249 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +0100250 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +0000251 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +0000252 error("Build failed at ${res.getAbsoluteUrl()}")
253 }
254 }
255}
256
Xinyu Zhang38a18872020-11-23 16:45:28 +0800257def generateEmailBody(stage, failed_jobs) {
258 body = "Check console output at ${env.BUILD_URL} \n\n"
259
260 body += "Failed Jobs:\n"
261 failed_jobs.each { job ->
262 body += "${job.key} ${job.value}\n"
263 }
264
265 body += "\nFor detailed ${stage} results please refer to \
266 ${env.BUILD_URL}artifact/${stage}_results.csv \n"
267 return body
268}
269
270def emailNotification(results, stage, failed_jobs) {
Karl Zhang0413e972020-09-18 17:59:26 +0800271 script {
272 if (env.JOB_NAME.equals("tf-m-nightly") && !env.EMAIL_NOTIFICATION.equals('')) {
273 def result = "Fail."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800274 if (results == true) {
Karl Zhang0413e972020-09-18 17:59:26 +0800275 result = "Success."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800276 print("Skip sending as ${result} for ${stage}")
277 }
278 else {
279 emailext (
280 subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} ${result}"),
Xinyu Zhang38a18872020-11-23 16:45:28 +0800281 body: generateEmailBody(stage, failed_jobs),
Karl Zhang182ecdf2020-10-10 09:52:12 +0800282 to: "${EMAIL_NOTIFICATION}"
283 )
284 }
Karl Zhang0413e972020-09-18 17:59:26 +0800285 }
286 } /* script */
287}
288
Xinyu Zhang38a18872020-11-23 16:45:28 +0800289def filterFailedBuild(results) {
290 def failed_builds = [:]
291 results.each { result ->
292 if (result.value[0].getResult() == "FAILURE") {
293 failed_builds[result.value[1]] = result.value[0].getAbsoluteUrl()
294 }
295 }
296 return failed_builds
297}
298
299def filterFailedTest(string) {
300 def failed_tests = [:]
301 line = lineInString(string, "FAILURE_TESTS:")
302 a = line.split(' ')
303 if (a.size() > 1) {
304 a = line.split(' ')[1..-1]
305 a.each { fail_test ->
306 config_link = fail_test.split(':')
307 failed_tests[config_link[0]] = config_link[1..-1].join(':')
308 }
309 }
310 return failed_tests
311}
312
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800313@NonCPS
314def generateCsvContent(results) {
315 def resultsParam = []
316 results.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800317 if (result.value[2]['BL2'] == "True") {
318 resultsParam.add([result.value[1], \
319 result.value[0].getResult(), \
320 result.value[2]['TFM_PLATFORM'], \
321 result.value[2]['TOOLCHAIN_FILE'], \
322 result.value[2]['CMAKE_BUILD_TYPE'], \
323 result.value[2]['BL2'], \
324 result.value[2]['NS'], \
325 result.value[2]['PSA_API'], \
326 result.value[2]['ISOLATION_LEVEL'], \
327 result.value[2]['TEST_REGRESSION'], \
328 result.value[2]['TEST_PSA_API'], \
329 result.value[2]['PROFILE'], \
330 result.value[2]['PARTITION_PS'], \
331 result.value[2]['OTP']])
332 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800333 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800334 resultsParam.each { result ->
Xinyu Zhang8d95fc12021-07-21 10:58:39 +0800335 if (result[2] == 'arm/musca_b1/sse_200') {
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800336 if (result[13] != 'off') {
Xinyu Zhang8d95fc12021-07-21 10:58:39 +0800337 result[2] = 'arm/musca_b1/sse_200_OTP'
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800338 }
339 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800340 result[3] = mapCompiler[result[3]]
Xinyu Zhang3f7e2f52021-09-02 13:43:57 +0800341 build_params = result[7..12]
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800342 configName = ""
343 for (map_cfg in mapConfigs) {
Xinyu Zhang3f7e2f52021-09-02 13:43:57 +0800344 if (build_params[0..4] == map_cfg[0..4]) {
345 configName = map_cfg[5]
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800346 break
347 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800348 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800349 if (configName == "") {
350 configName = "Default"
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800351 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800352 else if (configName == "RegressionProfileM") {
Xinyu Zhang3f7e2f52021-09-02 13:43:57 +0800353 if (build_params[5] == "OFF") {
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800354 configName = "RegressionProfileM PSOFF"
355 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800356 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800357 result.add(configName)
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800358 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800359 def csvContent = []
360 resultsParam.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800361 current_row = result[2..4]
362 cfgs.each {cfg ->
363 if (cfg == result[14]) {
364 current_row.add(cfg)
365 current_row.add(result[1])
366 }
367 }
368 csvContent.add(current_row)
369 }
370 csvContent.sort{a,b -> a[0] <=> b[0] ?: a[1] <=> b[1] ?: a[2] <=> b[2]}
371 build_summary = []
372 current_platform = ""
373 current_compiler = ""
374 current_build_type = ""
375 csvContent.each { build_cfg ->
376 if (current_platform != build_cfg[0] || \
377 current_compiler != build_cfg[1] || \
378 current_build_type != build_cfg[2]) {
379 current_platform = build_cfg[0]
380 current_compiler = build_cfg[1]
381 current_build_type = build_cfg[2]
382 csv_line = [current_platform, current_compiler, current_build_type]
383 cfgs.each {
384 csv_line.add("N.A.")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800385 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800386 build_summary.add(csv_line)
387 }
388 i = 0
389 cfgs.each { cfg ->
390 if (cfg == build_cfg[3]) {
391 build_summary[-1][3+i] = build_cfg[4]
392 }
393 i += 1
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800394 }
395 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800396 build_summary.add(0, ['Platform', 'Compiler', 'Cmake Build Type'])
397 build_summary[0] += cfgs
398 return build_summary
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800399}
400
401def generateBuildCsv(results) {
402 def csvContent = generateCsvContent(results)
403 node("master") {
404 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
405 archiveArtifacts 'build_results.csv'
406 }
407}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000408
409def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000410 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000411 def csvContent = summary.getBuildCsv(results)
412 node("master") {
413 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
414 archiveArtifacts 'build_results.csv'
415 }
416}
417
418def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000419 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000420 def buildLinks = summary.getLinks(results)
421 node("master") {
422 writeFile file: "build_links.html", text: buildLinks
423 archiveArtifacts 'build_links.html'
424 }
425}
426
Matthew Hartfb6fd362020-03-04 21:03:59 +0000427def lineInString(string, match) {
428 def lines = string.split("\n")
429 def result = lines.findAll { it.contains(match) }
430 return result[0]
431}
432
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800433def showLinks(string) {
434 def lines = string.split("\n")
435 def result = lines.findAll { it.contains("Build Config: ")}
436 links = result.join("\n")
437 print(links)
438}
439
Matthew Hartfb6fd362020-03-04 21:03:59 +0000440def getResult(string, match) {
441 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100442 a = line.split(match)[1].split(' ')
443 score = a[0]
444 if (a.size() > 1)
445 {
446 fail_text = a[1..-1].join(" ")
447 return [score, fail_text]
448 }
449 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000450}
451
452def submitJobsToList(results) {
453 def all_jobs = []
454 for (String result : results){
455 jobs_s = result.split('JOBS: ')
456 if (jobs_s.size() > 1) {
457 all_jobs += jobs_s[1]
458 }
459 }
460 return(all_jobs)
461}
462
Dean Birch62c4f082020-01-17 16:13:26 +0000463def configs = []
464def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000465def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000466
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800467timestamps {
468 node("docker-amd64-tf-m-bionic") {
469 stage("Init") {
470 cleanWs()
471 dir("tf-m-ci-scripts") {
472 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
Xinyu Zhang8472b852021-09-04 00:13:34 +0800473 sh "git rev-parse --short HEAD"
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800474 }
475 }
476 stage("Configs") {
477 // Populate configs
478 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
479 results['builds'] = [:]
480 results['lava_jobs'] = []
481 for (config in configs) {
482 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
483 }
484 builds["docs"] = buildDocs(results)
Dean Birch62c4f082020-01-17 16:13:26 +0000485 }
486 }
Karl Zhangfec84102020-06-24 09:56:36 +0800487
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800488 stage("Builds") {
489 def verify = 1
Matthew Hartfb6fd362020-03-04 21:03:59 +0000490 def success = true
Matthew Hartfb6fd362020-03-04 21:03:59 +0000491 try {
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800492 parallel(builds)
493 } catch (Exception e) {
494 print(e)
495 manager.buildFailure()
496 verify = -1
497 success = false
498 } finally {
499 print("Verifying status")
500 def failed_builds = filterFailedBuild(results['builds'])
501 emailNotification(success, 'build', failed_builds)
502 g = new Gerrit()
503 g.verifyStatus(verify, 'tf-m-build', 'build')
504 print("Building CSV")
505 generateBuildCsv(results['builds'])
506 writeSummary(results['builds'])
507 }
508 }
509
510 node("docker-amd64-tf-m-bionic") {
511 stage("Tests") {
512 dir("tf-m-ci-scripts") {
513 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
514 }
515 def all_jobs = []
516 def success = true
517 print("Wait for LAVA results here...")
518 try {
519 all_jobs = submitJobsToList(results['lava_jobs'])
520 if (all_jobs.size() > 0) {
521 dir("tf-m-ci-scripts") {
522 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
523 output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
524 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
525 --artifacts-path lava_artifacts --lava-timeout 7200 \
526 """, returnStdout: true).trim()
527 showLinks(output)
528 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
529 archiveArtifacts artifacts: 'test_results.csv', allowEmptyArchive: true
530 g = new Gerrit()
531 def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ')
532 if (boot_result) {
533 g.verifyStatus(boot_result, "lava_boot", "test")
534 }
535 def (test_result, test_output) = getResult(output, 'TEST_RESULT: ')
536 if (test_result) {
537 g.verifyStatus(test_result, "lava_test", "test")
538 }
539 if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) {
540 error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}")
541 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000542 }
543 }
544 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800545 else {
546 print("There were no LAVA jobs to test.")
547 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000548 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800549 catch (Exception e) {
550 print("ERROR: ${e}")
551 success = false
552 } finally {
553 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
554 if (all_jobs.size() > 0) {
555 emailNotification(success, 'test', filterFailedTest(output))
556 }
557 cleanWs()
558 if (!success) {
559 error("There was an Error waiting for LAVA jobs")
560 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000561 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000562 }
563 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000564}