Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
| 2 | //------------------------------------------------------------------------------- |
Xinyu Zhang | efe0353 | 2022-09-07 18:14:44 +0800 | [diff] [blame] | 3 | // Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved. |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 4 | // |
| 5 | // SPDX-License-Identifier: BSD-3-Clause |
| 6 | // |
| 7 | //------------------------------------------------------------------------------- |
| 8 | |
Xinyu Zhang | be224f6 | 2021-02-03 17:57:38 +0800 | [diff] [blame] | 9 | @NonCPS |
Xinyu Zhang | efe0353 | 2022-09-07 18:14:44 +0800 | [diff] [blame] | 10 | def 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 | |
| 25 | def 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()) { |
| 34 | if (env.TARGET_PLATFORM == "AN521") { |
| 35 | device_type = "--fvp-only " |
| 36 | print("Run test cases only on FVP in tf-m-static.") |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | return device_type |
Xinyu Zhang | be224f6 | 2021-02-03 17:57:38 +0800 | [diff] [blame] | 41 | } |
| 42 | |
Xinyu Zhang | 302b74d | 2021-11-03 14:53:44 +0800 | [diff] [blame] | 43 | def submitJobs(device_type, bl2_string, psa_string) { |
Xinyu Zhang | 4c0e140 | 2021-04-26 11:46:47 +0800 | [diff] [blame] | 44 | dir("tf-m-ci-scripts") { |
| 45 | def res = sh(script: """./lava_helper/lava_create_jobs.py \ |
Xinyu Zhang | 302b74d | 2021-11-03 14:53:44 +0800 | [diff] [blame] | 46 | --build-number ${env.BUILD_NUMBER} --output-dir lava_jobs ${device_type}\ |
Xinyu Zhang | 4c0e140 | 2021-04-26 11:46:47 +0800 | [diff] [blame] | 47 | --compiler ${env.COMPILER} --platform ${env.TARGET_PLATFORM} \ |
| 48 | ${bl2_string} ${psa_string} --build-type ${env.CMAKE_BUILD_TYPE} \ |
| 49 | --jenkins-build-url ${env.BUILD_URL} --proj-config ${env.PROJ_CONFIG} \ |
Leonardo Sandoval | 12fbb2f | 2021-04-15 14:36:09 -0500 | [diff] [blame] | 50 | --docker-prefix ${env.DOCKER_PREFIX} --license-variable "${env.LICENSE_VARIABLE}" \ |
| 51 | --enable-code-coverage "${env.CODE_COVERAGE_EN}" |
Xinyu Zhang | 4c0e140 | 2021-04-26 11:46:47 +0800 | [diff] [blame] | 52 | """, returnStdout: true).trim() |
| 53 | print(res) |
| 54 | job_ids = sh(script: """./lava_helper/lava_submit_jobs.py \ |
| 55 | --lava-url ${env.LAVA_URL} --job-dir lava_jobs \ |
| 56 | --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} | egrep "^JOBS" |
| 57 | """, returnStdout: true).trim() |
Paul Sokolovsky | 79b9d37 | 2022-01-05 14:03:14 +0300 | [diff] [blame] | 58 | print("${job_ids}") |
Xinyu Zhang | 4c0e140 | 2021-04-26 11:46:47 +0800 | [diff] [blame] | 59 | currentBuild.setDescription(job_ids) |
| 60 | } |
| 61 | } |
| 62 | |
Xinyu Zhang | 4cdfd1b | 2021-05-21 15:10:49 +0800 | [diff] [blame] | 63 | timestamps { |
| 64 | node("docker-amd64-tf-m-bionic") { |
| 65 | stage("Init") { |
| 66 | cleanWs() |
| 67 | dir("tf-m-ci-scripts") { |
| 68 | checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]]) |
| 69 | } |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 70 | } |
Xinyu Zhang | 4cdfd1b | 2021-05-21 15:10:49 +0800 | [diff] [blame] | 71 | stage("LAVA") { |
Paul Sokolovsky | 64b7cc9 | 2022-03-28 20:55:43 +0300 | [diff] [blame] | 72 | // Workaround for Groovy CPS idiosyncrasies. See e.g. |
| 73 | // https://blog.thesparktree.com/you-dont-know-jenkins-part-3#solutions |
| 74 | upstream_job = null |
| 75 | gp_causes = null |
Xinyu Zhang | efe0353 | 2022-09-07 18:14:44 +0800 | [diff] [blame] | 76 | def device_type = filterTestDevice() |
Xinyu Zhang | be224f6 | 2021-02-03 17:57:38 +0800 | [diff] [blame] | 77 | |
Xinyu Zhang | 4cdfd1b | 2021-05-21 15:10:49 +0800 | [diff] [blame] | 78 | withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) { |
| 79 | print("Generating LAVA jobs...") |
| 80 | def bl2_string = "" |
| 81 | def psa_string = "" |
| 82 | if (env.BL2.equals("True")) { |
| 83 | bl2_string = "--bl2" |
| 84 | } |
| 85 | // work around this string containing quotes? |
| 86 | if (env.PSA_API_SUITE != "") { |
| 87 | psa_string = "--psa-api-suite ${env.PSA_API_SUITE}" |
| 88 | } |
| 89 | try { |
Xinyu Zhang | 302b74d | 2021-11-03 14:53:44 +0800 | [diff] [blame] | 90 | submitJobs(device_type, bl2_string, psa_string) |
Xinyu Zhang | 4cdfd1b | 2021-05-21 15:10:49 +0800 | [diff] [blame] | 91 | } catch (Exception ex) { |
| 92 | print("LAVA-Submit failed! Exception: ${ex}") |
| 93 | print("Try to submit again...") |
Xinyu Zhang | 302b74d | 2021-11-03 14:53:44 +0800 | [diff] [blame] | 94 | submitJobs(device_type, bl2_string, psa_string) |
Xinyu Zhang | 4cdfd1b | 2021-05-21 15:10:49 +0800 | [diff] [blame] | 95 | currentBuild.setDescription(currentBuild.getDescription() + " Submitted twice!") |
| 96 | } |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 97 | } |
| 98 | } |
Xinyu Zhang | 4cdfd1b | 2021-05-21 15:10:49 +0800 | [diff] [blame] | 99 | stage("Post") { |
| 100 | archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_jobs/**', allowEmptyArchive: true |
| 101 | cleanWs() |
| 102 | } |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 103 | } |
| 104 | } |