blob: c403babffcece0ad78d485c0b45a28ba92d49a94 [file] [log] [blame]
Dean Bircha6ede7e2020-03-13 14:00:33 +00001#!/usr/bin/env groovy
2//-------------------------------------------------------------------------------
Xinyu Zhangefe03532022-09-07 18:14:44 +08003// Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
Dean Bircha6ede7e2020-03-13 14:00:33 +00004//
5// SPDX-License-Identifier: BSD-3-Clause
6//
7//-------------------------------------------------------------------------------
8
Xinyu Zhangbe224f62021-02-03 17:57:38 +08009@NonCPS
Xinyu Zhangefe03532022-09-07 18:14:44 +080010def isPerPatchJob() {
11 def upstream_job = manager.build.getAction(hudson.model.CauseAction.class).getCauses()[0]
12 if (upstream_job instanceof hudson.model.Cause.UpstreamCause) {
13 def gp_causes = upstream_job.getUpstreamCauses()
14 if (gp_causes.size() > 0 && gp_causes[0] instanceof hudson.model.Cause.UpstreamCause) {
15 print("Grand-parent project cause: ")
16 println(gp_causes[0].upstreamProject)
17 if (gp_causes[0].upstreamProject.endsWith("tf-m-static")) {
18 return true
19 }
20 }
21 }
22 return false
23}
24
25def filterTestDevice() {
26 def device_type = env.DEVICE_FILTER
27
28 if (env.DEVICE_FILTER != "") {
29 return device_type
30 }
31 // For AN521 builds running per-patch (started by the tf-m-static job),
32 // run tests only on FVP to improve turnaround/performance.
33 if (isPerPatchJob()) {
34 if (env.TARGET_PLATFORM == "AN521") {
35 device_type = "--fvp-only "
36 print("Run test cases only on FVP in tf-m-static.")
37 }
38 }
39
40 return device_type
Xinyu Zhangbe224f62021-02-03 17:57:38 +080041}
42
Xinyu Zhang302b74d2021-11-03 14:53:44 +080043def submitJobs(device_type, bl2_string, psa_string) {
Xinyu Zhang4c0e1402021-04-26 11:46:47 +080044 dir("tf-m-ci-scripts") {
45 def res = sh(script: """./lava_helper/lava_create_jobs.py \
Xinyu Zhang302b74d2021-11-03 14:53:44 +080046 --build-number ${env.BUILD_NUMBER} --output-dir lava_jobs ${device_type}\
Xinyu Zhang4c0e1402021-04-26 11:46:47 +080047 --compiler ${env.COMPILER} --platform ${env.TARGET_PLATFORM} \
48 ${bl2_string} ${psa_string} --build-type ${env.CMAKE_BUILD_TYPE} \
49 --jenkins-build-url ${env.BUILD_URL} --proj-config ${env.PROJ_CONFIG} \
Leonardo Sandoval12fbb2f2021-04-15 14:36:09 -050050 --docker-prefix ${env.DOCKER_PREFIX} --license-variable "${env.LICENSE_VARIABLE}" \
51 --enable-code-coverage "${env.CODE_COVERAGE_EN}"
Xinyu Zhang4c0e1402021-04-26 11:46:47 +080052 """, returnStdout: true).trim()
53 print(res)
54 job_ids = sh(script: """./lava_helper/lava_submit_jobs.py \
55 --lava-url ${env.LAVA_URL} --job-dir lava_jobs \
56 --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} | egrep "^JOBS"
57 """, returnStdout: true).trim()
Paul Sokolovsky79b9d372022-01-05 14:03:14 +030058 print("${job_ids}")
Xinyu Zhang4c0e1402021-04-26 11:46:47 +080059 currentBuild.setDescription(job_ids)
60 }
61}
62
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080063timestamps {
64 node("docker-amd64-tf-m-bionic") {
65 stage("Init") {
66 cleanWs()
67 dir("tf-m-ci-scripts") {
68 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
69 }
Dean Bircha6ede7e2020-03-13 14:00:33 +000070 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080071 stage("LAVA") {
Paul Sokolovsky64b7cc92022-03-28 20:55:43 +030072 // Workaround for Groovy CPS idiosyncrasies. See e.g.
73 // https://blog.thesparktree.com/you-dont-know-jenkins-part-3#solutions
74 upstream_job = null
75 gp_causes = null
Xinyu Zhangefe03532022-09-07 18:14:44 +080076 def device_type = filterTestDevice()
Xinyu Zhangbe224f62021-02-03 17:57:38 +080077
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080078 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
79 print("Generating LAVA jobs...")
80 def bl2_string = ""
81 def psa_string = ""
82 if (env.BL2.equals("True")) {
83 bl2_string = "--bl2"
84 }
85 // work around this string containing quotes?
86 if (env.PSA_API_SUITE != "") {
87 psa_string = "--psa-api-suite ${env.PSA_API_SUITE}"
88 }
89 try {
Xinyu Zhang302b74d2021-11-03 14:53:44 +080090 submitJobs(device_type, bl2_string, psa_string)
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080091 } catch (Exception ex) {
92 print("LAVA-Submit failed! Exception: ${ex}")
93 print("Try to submit again...")
Xinyu Zhang302b74d2021-11-03 14:53:44 +080094 submitJobs(device_type, bl2_string, psa_string)
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080095 currentBuild.setDescription(currentBuild.getDescription() + " Submitted twice!")
96 }
Dean Bircha6ede7e2020-03-13 14:00:33 +000097 }
98 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080099 stage("Post") {
100 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_jobs/**', allowEmptyArchive: true
101 cleanWs()
102 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000103 }
104}