blob: 87723415ac120b5dbd51cd7bfa778c00cd3c851b [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
Mark Horvath8d281cd2020-12-07 15:20:26 +010013mapPlatform = ["cypress/psoc64": "psoc64",
14 "mps2/an519": "AN519",
15 "mps2/an521": "AN521",
16 "mps2/an539": "AN539",
17 "mps2/sse-200_aws": "SSE-200_AWS",
18 "mps3/an524": "AN524",
Mark Horvath8d281cd2020-12-07 15:20:26 +010019 "musca_b1/sse_200": "MUSCA_B1",
20 "musca_b1/secure_enclave": "MUSCA_B1_SE",
21 "musca_s1": "MUSCA_S1"]
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080022
23mapCompiler = ["toolchain_GNUARM.cmake": "GNUARM",
24 "toolchain_ARMCLANG.cmake": "ARMCLANG"]
25
26mapBL2 = ["True": "--bl2",
27 "False": ""]
28
29mapTestPsaApi = ["OFF": "",
30 "INTERNAL_TRUSTED_STORAGE": "ITS",
31 "PROTECTED_STORAGE": "PS",
32 "CRYPTO": "Crypto",
33 "INITIAL_ATTESTATION": "Attest",
34 "IPC": "FF"]
35
Xinyu Zhangdbfadae2020-12-07 14:42:59 +080036// BL2, NS, PSA_API, ISOLATION_LEVEL, TEST_REG, TEST_PSA_API, PROFILE, CONFIG_NAME
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080037mapConfigs = [
38 ["True", "True", "False", "1", "False", "OFF", "N.A", "Default"],
39 ["True", "True", "True", "1", "False", "OFF", "N.A", "CoreIPC"],
40 ["True", "True", "True", "2", "False", "OFF", "N.A", "CoreIPCTfmLevel2"],
41 ["True", "True", "True", "3", "False", "OFF", "N.A", "CoreIPCTfmLevel3"],
42 ["True", "True", "False", "1", "False", "OFF", "profile_small", "DefaultProfileS"],
43 ["True", "True", "True", "2", "False", "OFF", "profile_medium", "DefaultProfileM"],
Xinyu Zhang9b1aef92021-03-12 15:36:44 +080044 ["True", "True", "True", "3", "False", "OFF", "profile_large", "DefaultProfileL"],
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080045 ["True", "True", "False", "1", "True", "OFF", "N.A", "Regression"],
46 ["True", "True", "True", "1", "True", "OFF", "N.A", "RegressionIPC"],
47 ["True", "True", "True", "2", "True", "OFF", "N.A", "RegressionIPCTfmLevel2"],
48 ["True", "True", "True", "3", "True", "OFF", "N.A", "RegressionIPCTfmLevel3"],
49 ["True", "True", "False", "1", "True", "OFF", "profile_small", "RegressionProfileS"],
50 ["True", "True", "True", "2", "True", "OFF", "profile_medium", "RegressionProfileM"],
Xinyu Zhang9b1aef92021-03-12 15:36:44 +080051 ["True", "True", "True", "3", "True", "OFF", "profile_large", "RegressionProfileL"],
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080052 ["True", "True", "False", "1", "False", "INTERNAL_TRUSTED_STORAGE", "N.A", "PsaApiTest (ITS)"],
53 ["True", "True", "False", "1", "False", "PROTECTED_STORAGE", "N.A", "PsaApiTest (PS)"],
54 ["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)"],
57 ["True", "True", "True", "1", "False", "INTERNAL_TRUSTED_STORAGE", "N.A", "PsaApiTestIPC (ITS)"],
58 ["True", "True", "True", "1", "False", "PROTECTED_STORAGE", "N.A", "PsaApiTestIPC (PS)"],
59 ["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)"],
62 ["True", "True", "True", "2", "False", "INTERNAL_TRUSTED_STORAGE", "N.A", "PsaApiTestIPCTfmLevel2 (ITS)"],
63 ["True", "True", "True", "2", "False", "PROTECTED_STORAGE", "N.A", "PsaApiTestIPCTfmLevel2 (PS)"],
64 ["True", "True", "True", "2", "False", "CRYPTO", "N.A", "PsaApiTestIPCTfmLevel2 (Crypto)"],
65 ["True", "True", "True", "2", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPCTfmLevel2 (Attest)"],
66 ["True", "True", "True", "2", "False", "IPC", "N.A", "PsaApiTestIPCTfmLevel2 (FF)"],
67 ["True", "True", "True", "3", "False", "INTERNAL_TRUSTED_STORAGE", "N.A", "PsaApiTestIPCTfmLevel3 (ITS)"],
68 ["True", "True", "True", "3", "False", "PROTECTED_STORAGE", "N.A", "PsaApiTestIPCTfmLevel3 (PS)"],
69 ["True", "True", "True", "3", "False", "CRYPTO", "N.A", "PsaApiTestIPCTfmLevel3 (Crypto)"],
70 ["True", "True", "True", "3", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPCTfmLevel3 (Attest)"],
71 ["True", "True", "True", "3", "False", "IPC", "N.A", "PsaApiTestIPCTfmLevel3 (FF)"],
72]
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)",
84 "PsaApiTest (PS)", "PsaApiTestIPC (PS)",
85 "PsaApiTestIPCTfmLevel2 (PS)",
86 "PsaApiTest (ITS)", "PsaApiTestIPC (ITS)",
87 "PsaApiTestIPCTfmLevel2 (ITS)",
88 "PsaApiTestIPC (FF)",
89 "PsaApiTestIPCTfmLevel2 (FF)",
90 "PsaApiTestIPCTfmLevel3 (ITS)", "PsaApiTestIPCTfmLevel3 (PS)",
91 "PsaApiTestIPCTfmLevel3 (Crypto)", "PsaApiTestIPCTfmLevel3 (Attest)",
92 "PsaApiTestIPCTfmLevel3 (FF)"]
93
Xinyu Zhangaa3747f2020-12-24 16:27:06 +080094@NonCPS
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080095def generateLavaParam(build_params) {
96 def params = []
Xinyu Zhang97114342021-01-21 14:08:03 +080097 if (build_params["TFM_PLATFORM"] == "musca_b1/sse_200" && \
98 build_params["OTP"] == "ENABLED") {
99 params += string(name: "TARGET_PLATFORM", value: "MUSCA_B1_OTP")
100 }
101 else {
102 params += string(name: "TARGET_PLATFORM", \
103 value: mapPlatform[build_params["TFM_PLATFORM"]])
104 }
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800105 params += string(name: "COMPILER", \
106 value: mapCompiler[build_params["TOOLCHAIN_FILE"]])
107 params += string(name: "PSA_API_SUITE", \
108 value: mapTestPsaApi[build_params["TEST_PSA_API"]])
109
Xinyu Zhangdbfadae2020-12-07 14:42:59 +0800110 configName = "Config"
111 config_params = [build_params["BL2"], build_params["NS"], \
112 build_params["PSA_API"], build_params["ISOLATION_LEVEL"], \
113 build_params["TEST_REGRESSION"], build_params["TEST_PSA_API"], \
114 build_params["PROFILE"]]
115 for (config in mapConfigs) {
116 if (config_params == config[0..6]) {
Xinyu Zhangfc1bacd2020-12-24 15:26:35 +0800117 configName += config[7].replace(' (', '_').replace(')', '')
Xinyu Zhangdbfadae2020-12-07 14:42:59 +0800118 break
119 }
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800120 }
Xinyu Zhangdbfadae2020-12-07 14:42:59 +0800121 if (configName == "Config") {
122 configName = "ConfigDefault"
123 }
124 params += string(name: "PROJ_CONFIG", value: configName)
Xinyu Zhangaa3747f2020-12-24 16:27:06 +0800125 print("Params of ${configName} :")
126 print(config_params)
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800127 return params
128}
129
Dean Birch62c4f082020-01-17 16:13:26 +0000130def listConfigs(ci_scripts_dir, config_list, filter_group) {
131 dir(ci_scripts_dir) {
132 echo "Obtaining list of configs."
Matthew Hartfb6fd362020-03-04 21:03:59 +0000133 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}"
Dean Birch62c4f082020-01-17 16:13:26 +0000134 def build_config_list_raw = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +0000135python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}
Dean Birch62c4f082020-01-17 16:13:26 +0000136""", returnStdout: true).trim()
137 def build_config_list = build_config_list_raw.tokenize('\n')
138 config_list.addAll(build_config_list)
139 }
140}
141
Matthew Hartfb6fd362020-03-04 21:03:59 +0000142def buildConfig(ci_scripts_dir, config, filter_group, results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000143 def params = []
Matthew Hartfb6fd362020-03-04 21:03:59 +0000144 def params_collection = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000145 def build_config_params
146 dir(ci_scripts_dir) {
147 echo "Obtaining build configuration for config ${config}"
Matthew Hartfb6fd362020-03-04 21:03:59 +0000148 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}"
Dean Birch62c4f082020-01-17 16:13:26 +0000149 build_config_params = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +0000150python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}
Dean Birch62c4f082020-01-17 16:13:26 +0000151""", returnStdout: true).trim()
152 }
153 def lines = build_config_params.tokenize('\n')
154 for (String line : lines) {
155 def key, value
156 (key, value) = line.tokenize('=')
157 params += string(name: key, value: value)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000158 params_collection[key] = value
Dean Birch62c4f082020-01-17 16:13:26 +0000159 }
160 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000161 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
162 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
163 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000164 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800165 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000166 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Karl Zhangf6f467e2020-07-10 16:24:45 +0800167 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000168 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Hugo L'Hostise55a2752021-01-27 11:09:08 +0000169 if (env.JOB_NAME.equals("tf-m-nightly")) { //Setting the Memory footprint gathering.
170 params += string(name: 'SQUAD_CONFIGURATIONS', value: env.SQUAD_CONFIGURATIONS)
171 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000172 return { -> results
173 def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false)
174 def build_info = [build_res, config, params_collection]
175 results['builds'][build_res.number] = build_info
176 def build_url = build_res.getAbsoluteUrl()
177 print("${build_res.number}: ${config} ${build_res.result} ${build_url}")
178 failure_states = ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]
179 if (build_res.result in failure_states) {
180 error("Build failed at ${build_url}")
181 }
Karl Zhang2b10b342020-11-09 14:50:11 +0800182 else if (params_collection["NS"] == "False" || \
Karl Zhang0b7bb4a2021-01-18 16:22:08 +0800183 (params_collection["TFM_PLATFORM"].contains("musca_b1") && \
184 env.JOB_NAME.equals("tf-m-build-and-test")) || \
Xinyu Zhang661a17a2021-01-05 19:24:40 +0800185 (params_collection["PROFILE"] == "profile_medium" && \
186 params_collection["PARTITION_PS"] == "OFF")) {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800187 print("LAVA is not needed for ${build_url}")
188 }
Xinyu Zhang97114342021-01-21 14:08:03 +0800189 // Only submit LAVA test for a specified OTP enabled config in nightly or release job
190 else if (params_collection["OTP"] == "ENABLED" && \
191 params_collection["CONFIG_NAME"] != "MUSCA_B1_ARMCLANG_PSA_3_REG_Debug_OTP_BL2_NS") {
192 print("LAVA is not needed for ${build_url}")
193 }
194 else if (params_collection["CONFIG_NAME"] == "MUSCA_B1_ARMCLANG_PSA_3_REG_Debug_OTP_BL2_NS" && \
195 !(env.JOB_NAME.equals("tf-m-nightly") || env.JOB_NAME.equals("tf-m-release"))) {
196 print("LAVA is not needed for ${build_url}")
197 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000198 else {
199 print("Doing LAVA stuff for ${build_url}")
Xinyu Zhangaa3747f2020-12-24 16:27:06 +0800200 params += generateLavaParam(params_collection)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000201 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
202 params += string(name: 'BUILD_URL', value: build_url)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000203 params += string(name: 'LAVA_URL', value: env.LAVA_URL)
Dean Birch956416f2020-08-12 10:36:16 +0100204 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
205 params += string(name: 'LAVA_CREDENTIALS', value: env.LAVA_CREDENTIALS)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000206 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
Xinyu Zhang32f8c1c2021-05-12 14:38:24 +0800207 def lava_resubmitted = false
Matthew Hartfb6fd362020-03-04 21:03:59 +0000208 if (lava_res.result in failure_states) {
209 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
210 }
211 else {
Xinyu Zhang32f8c1c2021-05-12 14:38:24 +0800212 lava_des = lava_res.getDescription()
213 if (lava_des.contains(" Submitted twice!")) {
214 lava_resubmitted = true
215 lava_des = lava_des - " Submitted twice!"
216 }
217 results['lava_jobs'] += lava_des
Matthew Hartfb6fd362020-03-04 21:03:59 +0000218 }
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800219 links = "Build Config: ${config}\n"
220 links += "Build URL: ${build_url}\n"
221 links += "LAVA Submit: ${lava_res.getAbsoluteUrl()}"
Xinyu Zhang32f8c1c2021-05-12 14:38:24 +0800222 if (lava_resubmitted) {
223 links += "\nLAVA Job Re-Submitted!"
224 }
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800225 print(links)
Dean Birch62c4f082020-01-17 16:13:26 +0000226 }
227 }
228}
229
Matthew Hart06340d72020-06-15 16:08:20 +0100230def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000231 def params = []
232 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000233 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
234 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
235 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000236 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800237 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000238 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000239 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Matthew Hart06340d72020-06-15 16:08:20 +0100240 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +0000241 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
242 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +0100243 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +0000244 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +0000245 error("Build failed at ${res.getAbsoluteUrl()}")
246 }
247 }
248}
249
Xinyu Zhang38a18872020-11-23 16:45:28 +0800250def generateEmailBody(stage, failed_jobs) {
251 body = "Check console output at ${env.BUILD_URL} \n\n"
252
253 body += "Failed Jobs:\n"
254 failed_jobs.each { job ->
255 body += "${job.key} ${job.value}\n"
256 }
257
258 body += "\nFor detailed ${stage} results please refer to \
259 ${env.BUILD_URL}artifact/${stage}_results.csv \n"
260 return body
261}
262
263def emailNotification(results, stage, failed_jobs) {
Karl Zhang0413e972020-09-18 17:59:26 +0800264 script {
265 if (env.JOB_NAME.equals("tf-m-nightly") && !env.EMAIL_NOTIFICATION.equals('')) {
266 def result = "Fail."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800267 if (results == true) {
Karl Zhang0413e972020-09-18 17:59:26 +0800268 result = "Success."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800269 print("Skip sending as ${result} for ${stage}")
270 }
271 else {
272 emailext (
273 subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} ${result}"),
Xinyu Zhang38a18872020-11-23 16:45:28 +0800274 body: generateEmailBody(stage, failed_jobs),
Karl Zhang182ecdf2020-10-10 09:52:12 +0800275 to: "${EMAIL_NOTIFICATION}"
276 )
277 }
Karl Zhang0413e972020-09-18 17:59:26 +0800278 }
279 } /* script */
280}
281
Xinyu Zhang38a18872020-11-23 16:45:28 +0800282def filterFailedBuild(results) {
283 def failed_builds = [:]
284 results.each { result ->
285 if (result.value[0].getResult() == "FAILURE") {
286 failed_builds[result.value[1]] = result.value[0].getAbsoluteUrl()
287 }
288 }
289 return failed_builds
290}
291
292def filterFailedTest(string) {
293 def failed_tests = [:]
294 line = lineInString(string, "FAILURE_TESTS:")
295 a = line.split(' ')
296 if (a.size() > 1) {
297 a = line.split(' ')[1..-1]
298 a.each { fail_test ->
299 config_link = fail_test.split(':')
300 failed_tests[config_link[0]] = config_link[1..-1].join(':')
301 }
302 }
303 return failed_tests
304}
305
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800306@NonCPS
307def generateCsvContent(results) {
308 def resultsParam = []
309 results.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800310 if (result.value[2]['BL2'] == "True") {
311 resultsParam.add([result.value[1], \
312 result.value[0].getResult(), \
313 result.value[2]['TFM_PLATFORM'], \
314 result.value[2]['TOOLCHAIN_FILE'], \
315 result.value[2]['CMAKE_BUILD_TYPE'], \
316 result.value[2]['BL2'], \
317 result.value[2]['NS'], \
318 result.value[2]['PSA_API'], \
319 result.value[2]['ISOLATION_LEVEL'], \
320 result.value[2]['TEST_REGRESSION'], \
321 result.value[2]['TEST_PSA_API'], \
322 result.value[2]['PROFILE'], \
323 result.value[2]['PARTITION_PS'], \
324 result.value[2]['OTP']])
325 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800326 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800327 resultsParam.each { result ->
Xinyu Zhang18a73542020-12-24 14:19:07 +0800328 if (result[2] == 'musca_b1/sse_200') {
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800329 if (result[13] != 'off') {
Xinyu Zhang18a73542020-12-24 14:19:07 +0800330 result[2] = 'musca_b1/sse_200_OTP'
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800331 }
332 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800333 result[3] = mapCompiler[result[3]]
334 build_params = result[5..12]
335 configName = ""
336 for (map_cfg in mapConfigs) {
337 if (build_params[0..6] == map_cfg[0..6]) {
338 configName = map_cfg[7]
339 break
340 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800341 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800342 if (configName == "") {
343 configName = "Default"
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800344 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800345 else if (configName == "RegressionProfileM") {
346 if (build_params[7] == "OFF") {
347 configName = "RegressionProfileM PSOFF"
348 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800349 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800350 result.add(configName)
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800351 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800352 def csvContent = []
353 resultsParam.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800354 current_row = result[2..4]
355 cfgs.each {cfg ->
356 if (cfg == result[14]) {
357 current_row.add(cfg)
358 current_row.add(result[1])
359 }
360 }
361 csvContent.add(current_row)
362 }
363 csvContent.sort{a,b -> a[0] <=> b[0] ?: a[1] <=> b[1] ?: a[2] <=> b[2]}
364 build_summary = []
365 current_platform = ""
366 current_compiler = ""
367 current_build_type = ""
368 csvContent.each { build_cfg ->
369 if (current_platform != build_cfg[0] || \
370 current_compiler != build_cfg[1] || \
371 current_build_type != build_cfg[2]) {
372 current_platform = build_cfg[0]
373 current_compiler = build_cfg[1]
374 current_build_type = build_cfg[2]
375 csv_line = [current_platform, current_compiler, current_build_type]
376 cfgs.each {
377 csv_line.add("N.A.")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800378 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800379 build_summary.add(csv_line)
380 }
381 i = 0
382 cfgs.each { cfg ->
383 if (cfg == build_cfg[3]) {
384 build_summary[-1][3+i] = build_cfg[4]
385 }
386 i += 1
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800387 }
388 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800389 build_summary.add(0, ['Platform', 'Compiler', 'Cmake Build Type'])
390 build_summary[0] += cfgs
391 return build_summary
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800392}
393
394def generateBuildCsv(results) {
395 def csvContent = generateCsvContent(results)
396 node("master") {
397 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
398 archiveArtifacts 'build_results.csv'
399 }
400}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000401
402def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000403 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000404 def csvContent = summary.getBuildCsv(results)
405 node("master") {
406 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
407 archiveArtifacts 'build_results.csv'
408 }
409}
410
411def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000412 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000413 def buildLinks = summary.getLinks(results)
414 node("master") {
415 writeFile file: "build_links.html", text: buildLinks
416 archiveArtifacts 'build_links.html'
417 }
418}
419
Matthew Hartfb6fd362020-03-04 21:03:59 +0000420def lineInString(string, match) {
421 def lines = string.split("\n")
422 def result = lines.findAll { it.contains(match) }
423 return result[0]
424}
425
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800426def showLinks(string) {
427 def lines = string.split("\n")
428 def result = lines.findAll { it.contains("Build Config: ")}
429 links = result.join("\n")
430 print(links)
431}
432
Matthew Hartfb6fd362020-03-04 21:03:59 +0000433def getResult(string, match) {
434 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100435 a = line.split(match)[1].split(' ')
436 score = a[0]
437 if (a.size() > 1)
438 {
439 fail_text = a[1..-1].join(" ")
440 return [score, fail_text]
441 }
442 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000443}
444
445def submitJobsToList(results) {
446 def all_jobs = []
447 for (String result : results){
448 jobs_s = result.split('JOBS: ')
449 if (jobs_s.size() > 1) {
450 all_jobs += jobs_s[1]
451 }
452 }
453 return(all_jobs)
454}
455
Dean Birch62c4f082020-01-17 16:13:26 +0000456def configs = []
457def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000458def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000459
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800460timestamps {
461 node("docker-amd64-tf-m-bionic") {
462 stage("Init") {
463 cleanWs()
464 dir("tf-m-ci-scripts") {
465 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
466 }
467 }
468 stage("Configs") {
469 // Populate configs
470 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
471 results['builds'] = [:]
472 results['lava_jobs'] = []
473 for (config in configs) {
474 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
475 }
476 builds["docs"] = buildDocs(results)
Dean Birch62c4f082020-01-17 16:13:26 +0000477 }
478 }
Karl Zhangfec84102020-06-24 09:56:36 +0800479
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800480 stage("Builds") {
481 def verify = 1
Matthew Hartfb6fd362020-03-04 21:03:59 +0000482 def success = true
Matthew Hartfb6fd362020-03-04 21:03:59 +0000483 try {
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800484 parallel(builds)
485 } catch (Exception e) {
486 print(e)
487 manager.buildFailure()
488 verify = -1
489 success = false
490 } finally {
491 print("Verifying status")
492 def failed_builds = filterFailedBuild(results['builds'])
493 emailNotification(success, 'build', failed_builds)
494 g = new Gerrit()
495 g.verifyStatus(verify, 'tf-m-build', 'build')
496 print("Building CSV")
497 generateBuildCsv(results['builds'])
498 writeSummary(results['builds'])
499 }
500 }
501
502 node("docker-amd64-tf-m-bionic") {
503 stage("Tests") {
504 dir("tf-m-ci-scripts") {
505 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
506 }
507 def all_jobs = []
508 def success = true
509 print("Wait for LAVA results here...")
510 try {
511 all_jobs = submitJobsToList(results['lava_jobs'])
512 if (all_jobs.size() > 0) {
513 dir("tf-m-ci-scripts") {
514 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
515 output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
516 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
517 --artifacts-path lava_artifacts --lava-timeout 7200 \
518 """, returnStdout: true).trim()
519 showLinks(output)
520 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
521 archiveArtifacts artifacts: 'test_results.csv', allowEmptyArchive: true
522 g = new Gerrit()
523 def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ')
524 if (boot_result) {
525 g.verifyStatus(boot_result, "lava_boot", "test")
526 }
527 def (test_result, test_output) = getResult(output, 'TEST_RESULT: ')
528 if (test_result) {
529 g.verifyStatus(test_result, "lava_test", "test")
530 }
531 if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) {
532 error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}")
533 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000534 }
535 }
536 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800537 else {
538 print("There were no LAVA jobs to test.")
539 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000540 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800541 catch (Exception e) {
542 print("ERROR: ${e}")
543 success = false
544 } finally {
545 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
546 if (all_jobs.size() > 0) {
547 emailNotification(success, 'test', filterFailedTest(output))
548 }
549 cleanWs()
550 if (!success) {
551 error("There was an Error waiting for LAVA jobs")
552 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000553 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000554 }
555 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000556}