blob: e67eeaeb166817cf3d62c64dfbfc484bd907fbe8 [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",
19 "musca_a": "MUSCA_A",
20 "musca_b1/sse_200": "MUSCA_B1",
21 "musca_b1/secure_enclave": "MUSCA_B1_SE",
22 "musca_s1": "MUSCA_S1"]
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080023
24mapCompiler = ["toolchain_GNUARM.cmake": "GNUARM",
25 "toolchain_ARMCLANG.cmake": "ARMCLANG"]
26
27mapBL2 = ["True": "--bl2",
28 "False": ""]
29
30mapTestPsaApi = ["OFF": "",
31 "INTERNAL_TRUSTED_STORAGE": "ITS",
32 "PROTECTED_STORAGE": "PS",
33 "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 Zhang4f2ef5a2020-11-09 18:11:43 +080053 ["True", "True", "False", "1", "False", "INTERNAL_TRUSTED_STORAGE", "N.A", "PsaApiTest (ITS)"],
54 ["True", "True", "False", "1", "False", "PROTECTED_STORAGE", "N.A", "PsaApiTest (PS)"],
55 ["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)"],
58 ["True", "True", "True", "1", "False", "INTERNAL_TRUSTED_STORAGE", "N.A", "PsaApiTestIPC (ITS)"],
59 ["True", "True", "True", "1", "False", "PROTECTED_STORAGE", "N.A", "PsaApiTestIPC (PS)"],
60 ["True", "True", "True", "1", "False", "CRYPTO", "N.A", "PsaApiTestIPC (Crypto)"],
61 ["True", "True", "True", "1", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPC (Attest)"],
62 ["True", "True", "True", "1", "False", "IPC", "N.A", "PsaApiTestIPC (FF)"],
63 ["True", "True", "True", "2", "False", "INTERNAL_TRUSTED_STORAGE", "N.A", "PsaApiTestIPCTfmLevel2 (ITS)"],
64 ["True", "True", "True", "2", "False", "PROTECTED_STORAGE", "N.A", "PsaApiTestIPCTfmLevel2 (PS)"],
65 ["True", "True", "True", "2", "False", "CRYPTO", "N.A", "PsaApiTestIPCTfmLevel2 (Crypto)"],
66 ["True", "True", "True", "2", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPCTfmLevel2 (Attest)"],
67 ["True", "True", "True", "2", "False", "IPC", "N.A", "PsaApiTestIPCTfmLevel2 (FF)"],
68 ["True", "True", "True", "3", "False", "INTERNAL_TRUSTED_STORAGE", "N.A", "PsaApiTestIPCTfmLevel3 (ITS)"],
69 ["True", "True", "True", "3", "False", "PROTECTED_STORAGE", "N.A", "PsaApiTestIPCTfmLevel3 (PS)"],
70 ["True", "True", "True", "3", "False", "CRYPTO", "N.A", "PsaApiTestIPCTfmLevel3 (Crypto)"],
71 ["True", "True", "True", "3", "False", "INITIAL_ATTESTATION", "N.A", "PsaApiTestIPCTfmLevel3 (Attest)"],
72 ["True", "True", "True", "3", "False", "IPC", "N.A", "PsaApiTestIPCTfmLevel3 (FF)"],
73]
74
75cfgs = ["Default", "CoreIPC", "CoreIPCTfmLevel2", "CoreIPCTfmLevel3",
76 "Regression", "RegressionIPC",
77 "RegressionIPCTfmLevel2", "RegressionIPCTfmLevel3",
78 "DefaultProfileS", "RegressionProfileS",
79 "DefaultProfileM", "RegressionProfileM", "RegressionProfileM PSOFF",
Xinyu Zhang9b1aef92021-03-12 15:36:44 +080080 "DefaultProfileL", "RegressionProfileL",
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +080081 "PsaApiTest (Attest)", "PsaApiTestIPC (Attest)",
82 "PsaApiTestIPCTfmLevel2 (Attest)",
83 "PsaApiTest (Crypto)", "PsaApiTestIPC (Crypto)",
84 "PsaApiTestIPCTfmLevel2 (Crypto)",
85 "PsaApiTest (PS)", "PsaApiTestIPC (PS)",
86 "PsaApiTestIPCTfmLevel2 (PS)",
87 "PsaApiTest (ITS)", "PsaApiTestIPC (ITS)",
88 "PsaApiTestIPCTfmLevel2 (ITS)",
89 "PsaApiTestIPC (FF)",
90 "PsaApiTestIPCTfmLevel2 (FF)",
91 "PsaApiTestIPCTfmLevel3 (ITS)", "PsaApiTestIPCTfmLevel3 (PS)",
92 "PsaApiTestIPCTfmLevel3 (Crypto)", "PsaApiTestIPCTfmLevel3 (Attest)",
93 "PsaApiTestIPCTfmLevel3 (FF)"]
94
Xinyu Zhangaa3747f2020-12-24 16:27:06 +080095@NonCPS
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +080096def generateLavaParam(build_params) {
97 def params = []
Xinyu Zhang97114342021-01-21 14:08:03 +080098 if (build_params["TFM_PLATFORM"] == "musca_b1/sse_200" && \
99 build_params["OTP"] == "ENABLED") {
100 params += string(name: "TARGET_PLATFORM", value: "MUSCA_B1_OTP")
101 }
102 else {
103 params += string(name: "TARGET_PLATFORM", \
104 value: mapPlatform[build_params["TFM_PLATFORM"]])
105 }
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800106 params += string(name: "COMPILER", \
107 value: mapCompiler[build_params["TOOLCHAIN_FILE"]])
108 params += string(name: "PSA_API_SUITE", \
109 value: mapTestPsaApi[build_params["TEST_PSA_API"]])
110
Xinyu Zhangdbfadae2020-12-07 14:42:59 +0800111 configName = "Config"
112 config_params = [build_params["BL2"], build_params["NS"], \
113 build_params["PSA_API"], build_params["ISOLATION_LEVEL"], \
114 build_params["TEST_REGRESSION"], build_params["TEST_PSA_API"], \
115 build_params["PROFILE"]]
116 for (config in mapConfigs) {
117 if (config_params == config[0..6]) {
Xinyu Zhangfc1bacd2020-12-24 15:26:35 +0800118 configName += config[7].replace(' (', '_').replace(')', '')
Xinyu Zhangdbfadae2020-12-07 14:42:59 +0800119 break
120 }
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800121 }
Xinyu Zhangdbfadae2020-12-07 14:42:59 +0800122 if (configName == "Config") {
123 configName = "ConfigDefault"
124 }
125 params += string(name: "PROJ_CONFIG", value: configName)
Xinyu Zhangaa3747f2020-12-24 16:27:06 +0800126 print("Params of ${configName} :")
127 print(config_params)
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800128 return params
129}
130
Dean Birch62c4f082020-01-17 16:13:26 +0000131def listConfigs(ci_scripts_dir, config_list, filter_group) {
132 dir(ci_scripts_dir) {
133 echo "Obtaining list of configs."
Matthew Hartfb6fd362020-03-04 21:03:59 +0000134 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}"
Dean Birch62c4f082020-01-17 16:13:26 +0000135 def build_config_list_raw = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +0000136python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}
Dean Birch62c4f082020-01-17 16:13:26 +0000137""", returnStdout: true).trim()
138 def build_config_list = build_config_list_raw.tokenize('\n')
139 config_list.addAll(build_config_list)
140 }
141}
142
Matthew Hartfb6fd362020-03-04 21:03:59 +0000143def buildConfig(ci_scripts_dir, config, filter_group, results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000144 def params = []
Matthew Hartfb6fd362020-03-04 21:03:59 +0000145 def params_collection = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000146 def build_config_params
147 dir(ci_scripts_dir) {
148 echo "Obtaining build configuration for config ${config}"
Matthew Hartfb6fd362020-03-04 21:03:59 +0000149 echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}"
Dean Birch62c4f082020-01-17 16:13:26 +0000150 build_config_params = sh(script: """\
Matthew Hartfb6fd362020-03-04 21:03:59 +0000151python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}
Dean Birch62c4f082020-01-17 16:13:26 +0000152""", returnStdout: true).trim()
153 }
154 def lines = build_config_params.tokenize('\n')
155 for (String line : lines) {
156 def key, value
157 (key, value) = line.tokenize('=')
158 params += string(name: key, value: value)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000159 params_collection[key] = value
Dean Birch62c4f082020-01-17 16:13:26 +0000160 }
161 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000162 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
163 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
164 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000165 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800166 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000167 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Karl Zhangf6f467e2020-07-10 16:24:45 +0800168 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000169 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Hugo L'Hostise55a2752021-01-27 11:09:08 +0000170 if (env.JOB_NAME.equals("tf-m-nightly")) { //Setting the Memory footprint gathering.
171 params += string(name: 'SQUAD_CONFIGURATIONS', value: env.SQUAD_CONFIGURATIONS)
172 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000173 return { -> results
174 def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false)
175 def build_info = [build_res, config, params_collection]
176 results['builds'][build_res.number] = build_info
177 def build_url = build_res.getAbsoluteUrl()
178 print("${build_res.number}: ${config} ${build_res.result} ${build_url}")
179 failure_states = ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]
180 if (build_res.result in failure_states) {
181 error("Build failed at ${build_url}")
182 }
Karl Zhang2b10b342020-11-09 14:50:11 +0800183 else if (params_collection["NS"] == "False" || \
Karl Zhang0b7bb4a2021-01-18 16:22:08 +0800184 (params_collection["TFM_PLATFORM"].contains("musca_b1") && \
185 env.JOB_NAME.equals("tf-m-build-and-test")) || \
Xinyu Zhang661a17a2021-01-05 19:24:40 +0800186 (params_collection["PROFILE"] == "profile_medium" && \
187 params_collection["PARTITION_PS"] == "OFF")) {
Xinyu Zhang5c4bbca2020-09-24 16:36:03 +0800188 print("LAVA is not needed for ${build_url}")
189 }
Xinyu Zhang97114342021-01-21 14:08:03 +0800190 // Only submit LAVA test for a specified OTP enabled config in nightly or release job
191 else if (params_collection["OTP"] == "ENABLED" && \
192 params_collection["CONFIG_NAME"] != "MUSCA_B1_ARMCLANG_PSA_3_REG_Debug_OTP_BL2_NS") {
193 print("LAVA is not needed for ${build_url}")
194 }
195 else if (params_collection["CONFIG_NAME"] == "MUSCA_B1_ARMCLANG_PSA_3_REG_Debug_OTP_BL2_NS" && \
196 !(env.JOB_NAME.equals("tf-m-nightly") || env.JOB_NAME.equals("tf-m-release"))) {
197 print("LAVA is not needed for ${build_url}")
198 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000199 else {
200 print("Doing LAVA stuff for ${build_url}")
Xinyu Zhangaa3747f2020-12-24 16:27:06 +0800201 params += generateLavaParam(params_collection)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000202 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
203 params += string(name: 'BUILD_URL', value: build_url)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000204 params += string(name: 'LAVA_URL', value: env.LAVA_URL)
Dean Birch956416f2020-08-12 10:36:16 +0100205 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
206 params += string(name: 'LAVA_CREDENTIALS', value: env.LAVA_CREDENTIALS)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000207 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: 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 {
212 results['lava_jobs'] += lava_res.getDescription()
213 }
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800214 links = "Build Config: ${config}\n"
215 links += "Build URL: ${build_url}\n"
216 links += "LAVA Submit: ${lava_res.getAbsoluteUrl()}"
217 print(links)
Dean Birch62c4f082020-01-17 16:13:26 +0000218 }
219 }
220}
221
Matthew Hart06340d72020-06-15 16:08:20 +0100222def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000223 def params = []
224 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000225 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
226 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
227 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000228 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800229 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000230 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000231 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Matthew Hart06340d72020-06-15 16:08:20 +0100232 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +0000233 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
234 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +0100235 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +0000236 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +0000237 error("Build failed at ${res.getAbsoluteUrl()}")
238 }
239 }
240}
241
Xinyu Zhang38a18872020-11-23 16:45:28 +0800242def generateEmailBody(stage, failed_jobs) {
243 body = "Check console output at ${env.BUILD_URL} \n\n"
244
245 body += "Failed Jobs:\n"
246 failed_jobs.each { job ->
247 body += "${job.key} ${job.value}\n"
248 }
249
250 body += "\nFor detailed ${stage} results please refer to \
251 ${env.BUILD_URL}artifact/${stage}_results.csv \n"
252 return body
253}
254
255def emailNotification(results, stage, failed_jobs) {
Karl Zhang0413e972020-09-18 17:59:26 +0800256 script {
257 if (env.JOB_NAME.equals("tf-m-nightly") && !env.EMAIL_NOTIFICATION.equals('')) {
258 def result = "Fail."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800259 if (results == true) {
Karl Zhang0413e972020-09-18 17:59:26 +0800260 result = "Success."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800261 print("Skip sending as ${result} for ${stage}")
262 }
263 else {
264 emailext (
265 subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} ${result}"),
Xinyu Zhang38a18872020-11-23 16:45:28 +0800266 body: generateEmailBody(stage, failed_jobs),
Karl Zhang182ecdf2020-10-10 09:52:12 +0800267 to: "${EMAIL_NOTIFICATION}"
268 )
269 }
Karl Zhang0413e972020-09-18 17:59:26 +0800270 }
271 } /* script */
272}
273
Xinyu Zhang38a18872020-11-23 16:45:28 +0800274def filterFailedBuild(results) {
275 def failed_builds = [:]
276 results.each { result ->
277 if (result.value[0].getResult() == "FAILURE") {
278 failed_builds[result.value[1]] = result.value[0].getAbsoluteUrl()
279 }
280 }
281 return failed_builds
282}
283
284def filterFailedTest(string) {
285 def failed_tests = [:]
286 line = lineInString(string, "FAILURE_TESTS:")
287 a = line.split(' ')
288 if (a.size() > 1) {
289 a = line.split(' ')[1..-1]
290 a.each { fail_test ->
291 config_link = fail_test.split(':')
292 failed_tests[config_link[0]] = config_link[1..-1].join(':')
293 }
294 }
295 return failed_tests
296}
297
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800298@NonCPS
299def generateCsvContent(results) {
300 def resultsParam = []
301 results.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800302 if (result.value[2]['BL2'] == "True") {
303 resultsParam.add([result.value[1], \
304 result.value[0].getResult(), \
305 result.value[2]['TFM_PLATFORM'], \
306 result.value[2]['TOOLCHAIN_FILE'], \
307 result.value[2]['CMAKE_BUILD_TYPE'], \
308 result.value[2]['BL2'], \
309 result.value[2]['NS'], \
310 result.value[2]['PSA_API'], \
311 result.value[2]['ISOLATION_LEVEL'], \
312 result.value[2]['TEST_REGRESSION'], \
313 result.value[2]['TEST_PSA_API'], \
314 result.value[2]['PROFILE'], \
315 result.value[2]['PARTITION_PS'], \
316 result.value[2]['OTP']])
317 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800318 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800319 resultsParam.each { result ->
Xinyu Zhang18a73542020-12-24 14:19:07 +0800320 if (result[2] == 'musca_b1/sse_200') {
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800321 if (result[13] != 'off') {
Xinyu Zhang18a73542020-12-24 14:19:07 +0800322 result[2] = 'musca_b1/sse_200_OTP'
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800323 }
324 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800325 result[3] = mapCompiler[result[3]]
326 build_params = result[5..12]
327 configName = ""
328 for (map_cfg in mapConfigs) {
329 if (build_params[0..6] == map_cfg[0..6]) {
330 configName = map_cfg[7]
331 break
332 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800333 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800334 if (configName == "") {
335 configName = "Default"
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800336 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800337 else if (configName == "RegressionProfileM") {
338 if (build_params[7] == "OFF") {
339 configName = "RegressionProfileM PSOFF"
340 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800341 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800342 result.add(configName)
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800343 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800344 def csvContent = []
345 resultsParam.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800346 current_row = result[2..4]
347 cfgs.each {cfg ->
348 if (cfg == result[14]) {
349 current_row.add(cfg)
350 current_row.add(result[1])
351 }
352 }
353 csvContent.add(current_row)
354 }
355 csvContent.sort{a,b -> a[0] <=> b[0] ?: a[1] <=> b[1] ?: a[2] <=> b[2]}
356 build_summary = []
357 current_platform = ""
358 current_compiler = ""
359 current_build_type = ""
360 csvContent.each { build_cfg ->
361 if (current_platform != build_cfg[0] || \
362 current_compiler != build_cfg[1] || \
363 current_build_type != build_cfg[2]) {
364 current_platform = build_cfg[0]
365 current_compiler = build_cfg[1]
366 current_build_type = build_cfg[2]
367 csv_line = [current_platform, current_compiler, current_build_type]
368 cfgs.each {
369 csv_line.add("N.A.")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800370 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800371 build_summary.add(csv_line)
372 }
373 i = 0
374 cfgs.each { cfg ->
375 if (cfg == build_cfg[3]) {
376 build_summary[-1][3+i] = build_cfg[4]
377 }
378 i += 1
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800379 }
380 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800381 build_summary.add(0, ['Platform', 'Compiler', 'Cmake Build Type'])
382 build_summary[0] += cfgs
383 return build_summary
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800384}
385
386def generateBuildCsv(results) {
387 def csvContent = generateCsvContent(results)
388 node("master") {
389 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
390 archiveArtifacts 'build_results.csv'
391 }
392}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000393
394def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000395 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000396 def csvContent = summary.getBuildCsv(results)
397 node("master") {
398 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
399 archiveArtifacts 'build_results.csv'
400 }
401}
402
403def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000404 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000405 def buildLinks = summary.getLinks(results)
406 node("master") {
407 writeFile file: "build_links.html", text: buildLinks
408 archiveArtifacts 'build_links.html'
409 }
410}
411
Matthew Hartfb6fd362020-03-04 21:03:59 +0000412def lineInString(string, match) {
413 def lines = string.split("\n")
414 def result = lines.findAll { it.contains(match) }
415 return result[0]
416}
417
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800418def showLinks(string) {
419 def lines = string.split("\n")
420 def result = lines.findAll { it.contains("Build Config: ")}
421 links = result.join("\n")
422 print(links)
423}
424
Matthew Hartfb6fd362020-03-04 21:03:59 +0000425def getResult(string, match) {
426 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100427 a = line.split(match)[1].split(' ')
428 score = a[0]
429 if (a.size() > 1)
430 {
431 fail_text = a[1..-1].join(" ")
432 return [score, fail_text]
433 }
434 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000435}
436
437def submitJobsToList(results) {
438 def all_jobs = []
439 for (String result : results){
440 jobs_s = result.split('JOBS: ')
441 if (jobs_s.size() > 1) {
442 all_jobs += jobs_s[1]
443 }
444 }
445 return(all_jobs)
446}
447
Dean Birch62c4f082020-01-17 16:13:26 +0000448def configs = []
449def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000450def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000451
Benjamin Copelandbe53b032020-10-30 19:57:59 +0000452node("docker-amd64-tf-m-bionic") {
Dean Birch62c4f082020-01-17 16:13:26 +0000453 stage("Init") {
454 cleanWs()
455 dir("tf-m-ci-scripts") {
Colin Thorbinson58703db2020-11-24 12:02:19 +0000456 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
Dean Birch62c4f082020-01-17 16:13:26 +0000457 }
458 }
459 stage("Configs") {
460 // Populate configs
461 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000462 results['builds'] = [:]
463 results['lava_jobs'] = []
Dean Birch62c4f082020-01-17 16:13:26 +0000464 for (config in configs) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000465 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
Dean Birch62c4f082020-01-17 16:13:26 +0000466 }
Matthew Hart06340d72020-06-15 16:08:20 +0100467 builds["docs"] = buildDocs(results)
Dean Birch62c4f082020-01-17 16:13:26 +0000468 }
469}
Karl Zhangfec84102020-06-24 09:56:36 +0800470
Dean Birch62c4f082020-01-17 16:13:26 +0000471stage("Builds") {
472 def verify = 1
Karl Zhang182ecdf2020-10-10 09:52:12 +0800473 def success = true
Dean Birch62c4f082020-01-17 16:13:26 +0000474 try {
475 parallel(builds)
476 } catch (Exception e) {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000477 print(e)
Dean Birch62c4f082020-01-17 16:13:26 +0000478 manager.buildFailure()
479 verify = -1
Karl Zhang182ecdf2020-10-10 09:52:12 +0800480 success = false
Dean Birch62c4f082020-01-17 16:13:26 +0000481 } finally {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000482 print("Verifying status")
Xinyu Zhang38a18872020-11-23 16:45:28 +0800483 def failed_builds = filterFailedBuild(results['builds'])
484 emailNotification(success, 'build', failed_builds)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000485 g = new Gerrit()
486 g.verifyStatus(verify, 'tf-m-build', 'build')
Dean Bircha6ede7e2020-03-13 14:00:33 +0000487 print("Building CSV")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800488 generateBuildCsv(results['builds'])
Dean Bircha6ede7e2020-03-13 14:00:33 +0000489 writeSummary(results['builds'])
Dean Birch62c4f082020-01-17 16:13:26 +0000490 }
491}
Matthew Hart06340d72020-06-15 16:08:20 +0100492
Benjamin Copelandbe53b032020-10-30 19:57:59 +0000493node("docker-amd64-tf-m-bionic") {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000494 stage("Tests") {
495 dir("tf-m-ci-scripts") {
Colin Thorbinson58703db2020-11-24 12:02:19 +0000496 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
Dean Bircha6ede7e2020-03-13 14:00:33 +0000497 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000498 def all_jobs = []
499 def success = true
Dean Bircha6ede7e2020-03-13 14:00:33 +0000500 print("Wait for LAVA results here...")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000501 try {
502 all_jobs = submitJobsToList(results['lava_jobs'])
503 if (all_jobs.size() > 0) {
504 dir("tf-m-ci-scripts") {
Dean Birch956416f2020-08-12 10:36:16 +0100505 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000506 output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
507 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
Matthew Hart05a59b52020-05-27 17:54:51 +0100508 --artifacts-path lava_artifacts --lava-timeout 7200 \
Matthew Hartfb6fd362020-03-04 21:03:59 +0000509 """, returnStdout: true).trim()
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800510 showLinks(output)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000511 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
Xinyu Zhang1b8f5152020-11-13 16:10:58 +0800512 archiveArtifacts artifacts: 'test_results.csv', allowEmptyArchive: true
Matthew Hartfb6fd362020-03-04 21:03:59 +0000513 g = new Gerrit()
Dean Birch1d545c02020-05-29 14:09:21 +0100514 def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000515 if (boot_result) {
516 g.verifyStatus(boot_result, "lava_boot", "test")
517 }
Dean Birch1d545c02020-05-29 14:09:21 +0100518 def (test_result, test_output) = getResult(output, 'TEST_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000519 if (test_result) {
520 g.verifyStatus(test_result, "lava_test", "test")
521 }
522 if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) {
Dean Birch1d545c02020-05-29 14:09:21 +0100523 error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000524 }
525 }
526 }
527 }
528 else {
529 print("There were no LAVA jobs to test.")
530 }
531 }
532 catch (Exception e) {
533 print("ERROR: ${e}")
534 success = false
535 } finally {
536 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
Xinyu Zhang91609012020-12-09 17:35:49 +0800537 if (all_jobs.size() > 0) {
538 emailNotification(success, 'test', filterFailedTest(output))
539 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000540 cleanWs()
541 if (!success) {
542 error("There was an Error waiting for LAVA jobs")
543 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000544 }
545 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000546}