blob: 631a6c8f80e2c79dc0f4a95436b40025de38033f [file] [log] [blame]
Dean Bircha6ede7e2020-03-13 14:00:33 +00001#!/usr/bin/env groovy
2//-------------------------------------------------------------------------------
Paul Sokolovskye1ad4772024-03-07 00:08:27 +07003// Copyright (c) 2020-2024, 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)
Paul Sokolovskyd13db152023-12-06 20:48:34 +030053 job_ids = sh(script: '''./lava_helper/lava_submit_jobs.py \
54 --lava-url ${LAVA_URL} --job-dir lava_jobs \
Xinyu Zhang4c0e1402021-04-26 11:46:47 +080055 --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} | egrep "^JOBS"
Paul Sokolovskyd13db152023-12-06 20:48:34 +030056 ''', 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 {
Paul Sokolovskye1ad4772024-03-07 00:08:27 +070063 node("docker-amd64-tf-m-jammy") {
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080064 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']]])
Paul Sokolovsky556ec482024-03-11 13:28:23 +070068 withCredentials([string(credentialsId: 'TUXSUITE_TOKEN', variable: 'TUXSUITE_TOKEN')]) {
69 sh "jenkins/tuxsuite-setup.sh"
70 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080071 }
Dean Bircha6ede7e2020-03-13 14:00:33 +000072 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080073 stage("LAVA") {
Paul Sokolovsky64b7cc92022-03-28 20:55:43 +030074 // Workaround for Groovy CPS idiosyncrasies. See e.g.
75 // https://blog.thesparktree.com/you-dont-know-jenkins-part-3#solutions
76 upstream_job = null
77 gp_causes = null
Xinyu Zhangefe03532022-09-07 18:14:44 +080078 def device_type = filterTestDevice()
Xinyu Zhangbe224f62021-02-03 17:57:38 +080079
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080080 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Paul Sokolovsky1eeaaae2023-12-06 20:11:49 +030081 print("Submitting LAVA jobs...")
82 def success = false
83 for (i = 0; i < 5; i++) {
84 try {
85 submitJobs(device_type)
86 success = true
87 break
88 } catch (Exception ex) {
89 print("LAVA-Submit failed! Exception: ${ex}")
90 print("Try to submit again...")
Paul Sokolovsky95d48422024-03-06 12:41:26 +070091 sleep(i * 10)
Paul Sokolovsky1eeaaae2023-12-06 20:11:49 +030092 }
93 }
94 if (!success) {
95 throw new Exception("LAVA submission failed")
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080096 }
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}