blob: 89a114a05131da228707b42291192e930433b558 [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()) {
Xinyu Zhanga0644f72022-10-26 14:11:16 +080034 if (env.TFM_PLATFORM == "arm/mps2/an521") {
Xinyu Zhangefe03532022-09-07 18:14:44 +080035 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 Zhang22a12752022-10-10 17:21:21 +080043def submitJobs(device_type) {
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 Zhang22a12752022-10-10 17:21:21 +080046 --output-dir lava_jobs ${device_type} \
47 --jenkins-build-url ${env.BUILD_URL} \
Leonardo Sandoval12fbb2f2021-04-15 14:36:09 -050048 --docker-prefix ${env.DOCKER_PREFIX} --license-variable "${env.LICENSE_VARIABLE}" \
49 --enable-code-coverage "${env.CODE_COVERAGE_EN}"
Xinyu Zhang4c0e1402021-04-26 11:46:47 +080050 """, returnStdout: true).trim()
51 print(res)
52 job_ids = sh(script: """./lava_helper/lava_submit_jobs.py \
53 --lava-url ${env.LAVA_URL} --job-dir lava_jobs \
54 --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} | egrep "^JOBS"
55 """, returnStdout: true).trim()
Paul Sokolovsky79b9d372022-01-05 14:03:14 +030056 print("${job_ids}")
Xinyu Zhang4c0e1402021-04-26 11:46:47 +080057 currentBuild.setDescription(job_ids)
58 }
59}
60
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080061timestamps {
62 node("docker-amd64-tf-m-bionic") {
63 stage("Init") {
64 cleanWs()
65 dir("tf-m-ci-scripts") {
66 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
67 }
Dean Bircha6ede7e2020-03-13 14:00:33 +000068 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080069 stage("LAVA") {
Paul Sokolovsky64b7cc92022-03-28 20:55:43 +030070 // Workaround for Groovy CPS idiosyncrasies. See e.g.
71 // https://blog.thesparktree.com/you-dont-know-jenkins-part-3#solutions
72 upstream_job = null
73 gp_causes = null
Xinyu Zhangefe03532022-09-07 18:14:44 +080074 def device_type = filterTestDevice()
Xinyu Zhangbe224f62021-02-03 17:57:38 +080075
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080076 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
77 print("Generating LAVA jobs...")
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080078 try {
Xinyu Zhang22a12752022-10-10 17:21:21 +080079 submitJobs(device_type)
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080080 } catch (Exception ex) {
81 print("LAVA-Submit failed! Exception: ${ex}")
82 print("Try to submit again...")
Xinyu Zhang22a12752022-10-10 17:21:21 +080083 submitJobs(device_type)
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080084 currentBuild.setDescription(currentBuild.getDescription() + " Submitted twice!")
85 }
Dean Bircha6ede7e2020-03-13 14:00:33 +000086 }
87 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080088 stage("Post") {
89 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_jobs/**', allowEmptyArchive: true
90 cleanWs()
91 }
Dean Bircha6ede7e2020-03-13 14:00:33 +000092 }
93}