blob: 88d1af3db2694830f9ca674573ddd2af62ba4ec8 [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.
Xinyu Zhang1b3cbea2022-12-22 12:33:40 +080033 // Skip tests on MUSCA B1 in per-patch for better performance.
Xinyu Zhangefe03532022-09-07 18:14:44 +080034 if (isPerPatchJob()) {
Xinyu Zhang1b3cbea2022-12-22 12:33:40 +080035 if (env.TFM_PLATFORM == "arm/mps2/an521" || env.TFM_PLATFORM == "arm/musca_b1") {
Xinyu Zhangefe03532022-09-07 18:14:44 +080036 device_type = "--fvp-only "
37 print("Run test cases only on FVP in tf-m-static.")
38 }
39 }
40
41 return device_type
Xinyu Zhangbe224f62021-02-03 17:57:38 +080042}
43
Xinyu Zhang22a12752022-10-10 17:21:21 +080044def submitJobs(device_type) {
Xinyu Zhang4c0e1402021-04-26 11:46:47 +080045 dir("tf-m-ci-scripts") {
46 def res = sh(script: """./lava_helper/lava_create_jobs.py \
Xinyu Zhang22a12752022-10-10 17:21:21 +080047 --output-dir lava_jobs ${device_type} \
48 --jenkins-build-url ${env.BUILD_URL} \
Leonardo Sandoval12fbb2f2021-04-15 14:36:09 -050049 --docker-prefix ${env.DOCKER_PREFIX} --license-variable "${env.LICENSE_VARIABLE}" \
50 --enable-code-coverage "${env.CODE_COVERAGE_EN}"
Xinyu Zhang4c0e1402021-04-26 11:46:47 +080051 """, returnStdout: true).trim()
52 print(res)
53 job_ids = sh(script: """./lava_helper/lava_submit_jobs.py \
54 --lava-url ${env.LAVA_URL} --job-dir lava_jobs \
55 --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} | egrep "^JOBS"
56 """, returnStdout: true).trim()
Paul Sokolovsky79b9d372022-01-05 14:03:14 +030057 print("${job_ids}")
Xinyu Zhang4c0e1402021-04-26 11:46:47 +080058 currentBuild.setDescription(job_ids)
59 }
60}
61
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080062timestamps {
63 node("docker-amd64-tf-m-bionic") {
64 stage("Init") {
65 cleanWs()
66 dir("tf-m-ci-scripts") {
67 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
68 }
Dean Bircha6ede7e2020-03-13 14:00:33 +000069 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080070 stage("LAVA") {
Paul Sokolovsky64b7cc92022-03-28 20:55:43 +030071 // Workaround for Groovy CPS idiosyncrasies. See e.g.
72 // https://blog.thesparktree.com/you-dont-know-jenkins-part-3#solutions
73 upstream_job = null
74 gp_causes = null
Xinyu Zhangefe03532022-09-07 18:14:44 +080075 def device_type = filterTestDevice()
Xinyu Zhangbe224f62021-02-03 17:57:38 +080076
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080077 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
78 print("Generating LAVA jobs...")
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080079 try {
Xinyu Zhang22a12752022-10-10 17:21:21 +080080 submitJobs(device_type)
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080081 } catch (Exception ex) {
82 print("LAVA-Submit failed! Exception: ${ex}")
83 print("Try to submit again...")
Xinyu Zhang22a12752022-10-10 17:21:21 +080084 submitJobs(device_type)
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080085 currentBuild.setDescription(currentBuild.getDescription() + " Submitted twice!")
86 }
Dean Bircha6ede7e2020-03-13 14:00:33 +000087 }
88 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080089 stage("Post") {
90 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_jobs/**', allowEmptyArchive: true
91 cleanWs()
92 }
Dean Bircha6ede7e2020-03-13 14:00:33 +000093 }
94}