blob: ffd8ed814cb5a1a07bfd7df09e40e1e75820201d [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 Copeland1d6aecb2025-01-08 11:03:06 +000060 job_id = job_ids.split(":")[1].trim()
61 job_url = "${LAVA_URL}/scheduler/job/${job_id}"
62 print("LAVA Job URL: ${job_url}")
63 currentBuild.setDescription(job_url)
Xinyu Zhang4c0e1402021-04-26 11:46:47 +080064 }
65}
66
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080067timestamps {
Paul Sokolovskye1ad4772024-03-07 00:08:27 +070068 node("docker-amd64-tf-m-jammy") {
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080069 stage("Init") {
70 cleanWs()
71 dir("tf-m-ci-scripts") {
Paul Sokolovsky9517ed42024-07-04 15:52:57 +030072 tfgit.checkout_ci_scripts()
Paul Sokolovsky556ec482024-03-11 13:28:23 +070073 withCredentials([string(credentialsId: 'TUXSUITE_TOKEN', variable: 'TUXSUITE_TOKEN')]) {
74 sh "jenkins/tuxsuite-setup.sh"
75 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080076 }
Dean Bircha6ede7e2020-03-13 14:00:33 +000077 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080078 stage("LAVA") {
Paul Sokolovsky64b7cc92022-03-28 20:55:43 +030079 // Workaround for Groovy CPS idiosyncrasies. See e.g.
80 // https://blog.thesparktree.com/you-dont-know-jenkins-part-3#solutions
81 upstream_job = null
82 gp_causes = null
Xinyu Zhangefe03532022-09-07 18:14:44 +080083 def device_type = filterTestDevice()
Xinyu Zhangbe224f62021-02-03 17:57:38 +080084
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +080085 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Paul Sokolovsky1eeaaae2023-12-06 20:11:49 +030086 print("Submitting LAVA jobs...")
87 def success = false
88 for (i = 0; i < 5; i++) {
89 try {
90 submitJobs(device_type)
91 success = true
92 break
93 } catch (Exception ex) {
94 print("LAVA-Submit failed! Exception: ${ex}")
95 print("Try to submit again...")
Paul Sokolovsky95d48422024-03-06 12:41:26 +070096 sleep(i * 10)
Paul Sokolovsky1eeaaae2023-12-06 20:11:49 +030097 }
98 }
99 if (!success) {
100 throw new Exception("LAVA submission failed")
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800101 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000102 }
103 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800104 stage("Post") {
105 archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_jobs/**', allowEmptyArchive: true
106 cleanWs()
107 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000108 }
109}