blob: 81313261e9fe24bd66efa7678651117ce906c98c [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)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000207 if (lava_res.result in failure_states) {
208 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
209 }
210 else {
211 results['lava_jobs'] += lava_res.getDescription()
212 }
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800213 links = "Build Config: ${config}\n"
214 links += "Build URL: ${build_url}\n"
215 links += "LAVA Submit: ${lava_res.getAbsoluteUrl()}"
216 print(links)
Dean Birch62c4f082020-01-17 16:13:26 +0000217 }
218 }
219}
220
Matthew Hart06340d72020-06-15 16:08:20 +0100221def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000222 def params = []
223 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000224 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
225 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
226 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000227 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +0800228 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +0000229 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000230 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Matthew Hart06340d72020-06-15 16:08:20 +0100231 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +0000232 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
233 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +0100234 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +0000235 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +0000236 error("Build failed at ${res.getAbsoluteUrl()}")
237 }
238 }
239}
240
Xinyu Zhang38a18872020-11-23 16:45:28 +0800241def generateEmailBody(stage, failed_jobs) {
242 body = "Check console output at ${env.BUILD_URL} \n\n"
243
244 body += "Failed Jobs:\n"
245 failed_jobs.each { job ->
246 body += "${job.key} ${job.value}\n"
247 }
248
249 body += "\nFor detailed ${stage} results please refer to \
250 ${env.BUILD_URL}artifact/${stage}_results.csv \n"
251 return body
252}
253
254def emailNotification(results, stage, failed_jobs) {
Karl Zhang0413e972020-09-18 17:59:26 +0800255 script {
256 if (env.JOB_NAME.equals("tf-m-nightly") && !env.EMAIL_NOTIFICATION.equals('')) {
257 def result = "Fail."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800258 if (results == true) {
Karl Zhang0413e972020-09-18 17:59:26 +0800259 result = "Success."
Karl Zhang182ecdf2020-10-10 09:52:12 +0800260 print("Skip sending as ${result} for ${stage}")
261 }
262 else {
263 emailext (
264 subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} ${result}"),
Xinyu Zhang38a18872020-11-23 16:45:28 +0800265 body: generateEmailBody(stage, failed_jobs),
Karl Zhang182ecdf2020-10-10 09:52:12 +0800266 to: "${EMAIL_NOTIFICATION}"
267 )
268 }
Karl Zhang0413e972020-09-18 17:59:26 +0800269 }
270 } /* script */
271}
272
Xinyu Zhang38a18872020-11-23 16:45:28 +0800273def filterFailedBuild(results) {
274 def failed_builds = [:]
275 results.each { result ->
276 if (result.value[0].getResult() == "FAILURE") {
277 failed_builds[result.value[1]] = result.value[0].getAbsoluteUrl()
278 }
279 }
280 return failed_builds
281}
282
283def filterFailedTest(string) {
284 def failed_tests = [:]
285 line = lineInString(string, "FAILURE_TESTS:")
286 a = line.split(' ')
287 if (a.size() > 1) {
288 a = line.split(' ')[1..-1]
289 a.each { fail_test ->
290 config_link = fail_test.split(':')
291 failed_tests[config_link[0]] = config_link[1..-1].join(':')
292 }
293 }
294 return failed_tests
295}
296
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800297@NonCPS
298def generateCsvContent(results) {
299 def resultsParam = []
300 results.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800301 if (result.value[2]['BL2'] == "True") {
302 resultsParam.add([result.value[1], \
303 result.value[0].getResult(), \
304 result.value[2]['TFM_PLATFORM'], \
305 result.value[2]['TOOLCHAIN_FILE'], \
306 result.value[2]['CMAKE_BUILD_TYPE'], \
307 result.value[2]['BL2'], \
308 result.value[2]['NS'], \
309 result.value[2]['PSA_API'], \
310 result.value[2]['ISOLATION_LEVEL'], \
311 result.value[2]['TEST_REGRESSION'], \
312 result.value[2]['TEST_PSA_API'], \
313 result.value[2]['PROFILE'], \
314 result.value[2]['PARTITION_PS'], \
315 result.value[2]['OTP']])
316 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800317 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800318 resultsParam.each { result ->
Xinyu Zhang18a73542020-12-24 14:19:07 +0800319 if (result[2] == 'musca_b1/sse_200') {
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800320 if (result[13] != 'off') {
Xinyu Zhang18a73542020-12-24 14:19:07 +0800321 result[2] = 'musca_b1/sse_200_OTP'
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800322 }
323 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800324 result[3] = mapCompiler[result[3]]
325 build_params = result[5..12]
326 configName = ""
327 for (map_cfg in mapConfigs) {
328 if (build_params[0..6] == map_cfg[0..6]) {
329 configName = map_cfg[7]
330 break
331 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800332 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800333 if (configName == "") {
334 configName = "Default"
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800335 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800336 else if (configName == "RegressionProfileM") {
337 if (build_params[7] == "OFF") {
338 configName = "RegressionProfileM PSOFF"
339 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800340 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800341 result.add(configName)
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800342 }
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800343 def csvContent = []
344 resultsParam.each { result ->
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800345 current_row = result[2..4]
346 cfgs.each {cfg ->
347 if (cfg == result[14]) {
348 current_row.add(cfg)
349 current_row.add(result[1])
350 }
351 }
352 csvContent.add(current_row)
353 }
354 csvContent.sort{a,b -> a[0] <=> b[0] ?: a[1] <=> b[1] ?: a[2] <=> b[2]}
355 build_summary = []
356 current_platform = ""
357 current_compiler = ""
358 current_build_type = ""
359 csvContent.each { build_cfg ->
360 if (current_platform != build_cfg[0] || \
361 current_compiler != build_cfg[1] || \
362 current_build_type != build_cfg[2]) {
363 current_platform = build_cfg[0]
364 current_compiler = build_cfg[1]
365 current_build_type = build_cfg[2]
366 csv_line = [current_platform, current_compiler, current_build_type]
367 cfgs.each {
368 csv_line.add("N.A.")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800369 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800370 build_summary.add(csv_line)
371 }
372 i = 0
373 cfgs.each { cfg ->
374 if (cfg == build_cfg[3]) {
375 build_summary[-1][3+i] = build_cfg[4]
376 }
377 i += 1
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800378 }
379 }
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800380 build_summary.add(0, ['Platform', 'Compiler', 'Cmake Build Type'])
381 build_summary[0] += cfgs
382 return build_summary
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800383}
384
385def generateBuildCsv(results) {
386 def csvContent = generateCsvContent(results)
387 node("master") {
388 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
389 archiveArtifacts 'build_results.csv'
390 }
391}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000392
393def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000394 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000395 def csvContent = summary.getBuildCsv(results)
396 node("master") {
397 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
398 archiveArtifacts 'build_results.csv'
399 }
400}
401
402def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000403 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000404 def buildLinks = summary.getLinks(results)
405 node("master") {
406 writeFile file: "build_links.html", text: buildLinks
407 archiveArtifacts 'build_links.html'
408 }
409}
410
Matthew Hartfb6fd362020-03-04 21:03:59 +0000411def lineInString(string, match) {
412 def lines = string.split("\n")
413 def result = lines.findAll { it.contains(match) }
414 return result[0]
415}
416
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800417def showLinks(string) {
418 def lines = string.split("\n")
419 def result = lines.findAll { it.contains("Build Config: ")}
420 links = result.join("\n")
421 print(links)
422}
423
Matthew Hartfb6fd362020-03-04 21:03:59 +0000424def getResult(string, match) {
425 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100426 a = line.split(match)[1].split(' ')
427 score = a[0]
428 if (a.size() > 1)
429 {
430 fail_text = a[1..-1].join(" ")
431 return [score, fail_text]
432 }
433 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000434}
435
436def submitJobsToList(results) {
437 def all_jobs = []
438 for (String result : results){
439 jobs_s = result.split('JOBS: ')
440 if (jobs_s.size() > 1) {
441 all_jobs += jobs_s[1]
442 }
443 }
444 return(all_jobs)
445}
446
Dean Birch62c4f082020-01-17 16:13:26 +0000447def configs = []
448def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000449def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000450
Benjamin Copelandbe53b032020-10-30 19:57:59 +0000451node("docker-amd64-tf-m-bionic") {
Dean Birch62c4f082020-01-17 16:13:26 +0000452 stage("Init") {
453 cleanWs()
454 dir("tf-m-ci-scripts") {
Colin Thorbinson58703db2020-11-24 12:02:19 +0000455 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
Dean Birch62c4f082020-01-17 16:13:26 +0000456 }
457 }
458 stage("Configs") {
459 // Populate configs
460 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000461 results['builds'] = [:]
462 results['lava_jobs'] = []
Dean Birch62c4f082020-01-17 16:13:26 +0000463 for (config in configs) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000464 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results)
Dean Birch62c4f082020-01-17 16:13:26 +0000465 }
Matthew Hart06340d72020-06-15 16:08:20 +0100466 builds["docs"] = buildDocs(results)
Dean Birch62c4f082020-01-17 16:13:26 +0000467 }
468}
Karl Zhangfec84102020-06-24 09:56:36 +0800469
Dean Birch62c4f082020-01-17 16:13:26 +0000470stage("Builds") {
471 def verify = 1
Karl Zhang182ecdf2020-10-10 09:52:12 +0800472 def success = true
Dean Birch62c4f082020-01-17 16:13:26 +0000473 try {
474 parallel(builds)
475 } catch (Exception e) {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000476 print(e)
Dean Birch62c4f082020-01-17 16:13:26 +0000477 manager.buildFailure()
478 verify = -1
Karl Zhang182ecdf2020-10-10 09:52:12 +0800479 success = false
Dean Birch62c4f082020-01-17 16:13:26 +0000480 } finally {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000481 print("Verifying status")
Xinyu Zhang38a18872020-11-23 16:45:28 +0800482 def failed_builds = filterFailedBuild(results['builds'])
483 emailNotification(success, 'build', failed_builds)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000484 g = new Gerrit()
485 g.verifyStatus(verify, 'tf-m-build', 'build')
Dean Bircha6ede7e2020-03-13 14:00:33 +0000486 print("Building CSV")
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800487 generateBuildCsv(results['builds'])
Dean Bircha6ede7e2020-03-13 14:00:33 +0000488 writeSummary(results['builds'])
Dean Birch62c4f082020-01-17 16:13:26 +0000489 }
490}
Matthew Hart06340d72020-06-15 16:08:20 +0100491
Benjamin Copelandbe53b032020-10-30 19:57:59 +0000492node("docker-amd64-tf-m-bionic") {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000493 stage("Tests") {
494 dir("tf-m-ci-scripts") {
Colin Thorbinson58703db2020-11-24 12:02:19 +0000495 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
Dean Bircha6ede7e2020-03-13 14:00:33 +0000496 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000497 def all_jobs = []
498 def success = true
Dean Bircha6ede7e2020-03-13 14:00:33 +0000499 print("Wait for LAVA results here...")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000500 try {
501 all_jobs = submitJobsToList(results['lava_jobs'])
502 if (all_jobs.size() > 0) {
503 dir("tf-m-ci-scripts") {
Dean Birch956416f2020-08-12 10:36:16 +0100504 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Matthew Hartfb6fd362020-03-04 21:03:59 +0000505 output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
506 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
Matthew Hart05a59b52020-05-27 17:54:51 +0100507 --artifacts-path lava_artifacts --lava-timeout 7200 \
Matthew Hartfb6fd362020-03-04 21:03:59 +0000508 """, returnStdout: true).trim()
Xinyu Zhang97ee3fd2020-12-14 14:45:06 +0800509 showLinks(output)
Matthew Hartfb6fd362020-03-04 21:03:59 +0000510 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
Xinyu Zhang1b8f5152020-11-13 16:10:58 +0800511 archiveArtifacts artifacts: 'test_results.csv', allowEmptyArchive: true
Matthew Hartfb6fd362020-03-04 21:03:59 +0000512 g = new Gerrit()
Dean Birch1d545c02020-05-29 14:09:21 +0100513 def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000514 if (boot_result) {
515 g.verifyStatus(boot_result, "lava_boot", "test")
516 }
Dean Birch1d545c02020-05-29 14:09:21 +0100517 def (test_result, test_output) = getResult(output, 'TEST_RESULT: ')
Matthew Hartfb6fd362020-03-04 21:03:59 +0000518 if (test_result) {
519 g.verifyStatus(test_result, "lava_test", "test")
520 }
521 if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) {
Dean Birch1d545c02020-05-29 14:09:21 +0100522 error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}")
Matthew Hartfb6fd362020-03-04 21:03:59 +0000523 }
524 }
525 }
526 }
527 else {
528 print("There were no LAVA jobs to test.")
529 }
530 }
531 catch (Exception e) {
532 print("ERROR: ${e}")
533 success = false
534 } finally {
535 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
Xinyu Zhang91609012020-12-09 17:35:49 +0800536 if (all_jobs.size() > 0) {
537 emailNotification(success, 'test', filterFailedTest(output))
538 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000539 cleanWs()
540 if (!success) {
541 error("There was an Error waiting for LAVA jobs")
542 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000543 }
544 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000545}