blob: 5103d31fdf2d91265f7e6fb516379698e299b437 [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
Paul Sokolovsky9517ed42024-07-04 15:52:57 +03009@Library('trustedfirmware') _
10
11
Xinyu Zhangbe224f62021-02-03 17:57:38 +080012@NonCPS
Xinyu Zhangefe03532022-09-07 18:14:44 +080013def isPerPatchJob() {
14 def upstream_job = manager.build.getAction(hudson.model.CauseAction.class).getCauses()[0]
15 if (upstream_job instanceof hudson.model.Cause.UpstreamCause) {
16 def gp_causes = upstream_job.getUpstreamCauses()
17 if (gp_causes.size() > 0 && gp_causes[0] instanceof hudson.model.Cause.UpstreamCause) {
18 print("Grand-parent project cause: ")
19 println(gp_causes[0].upstreamProject)
20 if (gp_causes[0].upstreamProject.endsWith("tf-m-static")) {
21 return true
22 }
23 }
24 }
25 return false
26}
27
28def filterTestDevice() {
29 def device_type = env.DEVICE_FILTER
30
31 if (env.DEVICE_FILTER != "") {
32 return device_type
33 }
34 // For AN521 builds running per-patch (started by the tf-m-static job),
35 // run tests only on FVP to improve turnaround/performance.
Xinyu Zhang1b3cbea2022-12-22 12:33:40 +080036 // Skip tests on MUSCA B1 in per-patch for better performance.
Xinyu Zhangefe03532022-09-07 18:14:44 +080037 if (isPerPatchJob()) {
Xinyu Zhang1b3cbea2022-12-22 12:33:40 +080038 if (env.TFM_PLATFORM == "arm/mps2/an521" || env.TFM_PLATFORM == "arm/musca_b1") {
Xinyu Zhangefe03532022-09-07 18:14:44 +080039 device_type = "--fvp-only "
40 print("Run test cases only on FVP in tf-m-static.")
41 }
42 }
43
44 return device_type
Xinyu Zhangbe224f62021-02-03 17:57:38 +080045}
46
Xinyu Zhang22a12752022-10-10 17:21:21 +080047def submitJobs(device_type) {
Xinyu Zhang4c0e1402021-04-26 11:46:47 +080048 dir("tf-m-ci-scripts") {
49 def res = sh(script: """./lava_helper/lava_create_jobs.py \
Xinyu Zhang22a12752022-10-10 17:21:21 +080050 --output-dir lava_jobs ${device_type} \
51 --jenkins-build-url ${env.BUILD_URL} \
Leonardo Sandoval12fbb2f2021-04-15 14:36:09 -050052 --docker-prefix ${env.DOCKER_PREFIX} --license-variable "${env.LICENSE_VARIABLE}" \
53 --enable-code-coverage "${env.CODE_COVERAGE_EN}"
Xinyu Zhang4c0e1402021-04-26 11:46:47 +080054 """, returnStdout: true).trim()
55 print(res)
Paul Sokolovskyd13db152023-12-06 20:48:34 +030056 job_ids = sh(script: '''./lava_helper/lava_submit_jobs.py \
57 --lava-url ${LAVA_URL} --job-dir lava_jobs \
Xinyu Zhang4c0e1402021-04-26 11:46:47 +080058 --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} | egrep "^JOBS"
Paul Sokolovskyd13db152023-12-06 20:48:34 +030059 ''', returnStdout: true).trim()
Benjamin Copelandbc3c2d82025-01-09 18:10:20 +000060 print("${job_ids}")
Benjamin Copeland8f7c50c2025-01-31 14:11:13 +000061 currentBuild.setDescription(job_ids)
Xinyu Zhang4c0e1402021-04-26 11:46:47 +080062 }
63}
64
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080065timestamps {
Paul Sokolovskye1ad4772024-03-07 00:08:27 +070066 node("docker-amd64-tf-m-jammy") {
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080067 stage("Init") {
68 cleanWs()
69 dir("tf-m-ci-scripts") {
Paul Sokolovsky9517ed42024-07-04 15:52:57 +030070 tfgit.checkout_ci_scripts()
Paul Sokolovsky556ec482024-03-11 13:28:23 +070071 withCredentials([string(credentialsId: 'TUXSUITE_TOKEN', variable: 'TUXSUITE_TOKEN')]) {
72 sh "jenkins/tuxsuite-setup.sh"
73 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080074 }
Dean Bircha6ede7e2020-03-13 14:00:33 +000075 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080076 stage("LAVA") {
Paul Sokolovsky64b7cc92022-03-28 20:55:43 +030077 // Workaround for Groovy CPS idiosyncrasies. See e.g.
78 // https://blog.thesparktree.com/you-dont-know-jenkins-part-3#solutions
79 upstream_job = null
80 gp_causes = null
Xinyu Zhangefe03532022-09-07 18:14:44 +080081 def device_type = filterTestDevice()
Xinyu Zhangbe224f62021-02-03 17:57:38 +080082
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080083 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Paul Sokolovsky1eeaaae2023-12-06 20:11:49 +030084 print("Submitting LAVA jobs...")
85 def success = false
86 for (i = 0; i < 5; i++) {
87 try {
88 submitJobs(device_type)
89 success = true
90 break
91 } catch (Exception ex) {
92 print("LAVA-Submit failed! Exception: ${ex}")
93 print("Try to submit again...")
Paul Sokolovsky95d48422024-03-06 12:41:26 +070094 sleep(i * 10)
Paul Sokolovsky1eeaaae2023-12-06 20:11:49 +030095 }
96 }
97 if (!success) {
98 throw new Exception("LAVA submission failed")
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080099 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000100 }
101 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800102 stage("Post") {
103 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_jobs/**', allowEmptyArchive: true
104 cleanWs()
105 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000106 }
107}