Skip to content

Commit

Permalink
Add Smoke Tests
Browse files Browse the repository at this point in the history
Signed-off-by: Sophia Guo <sophia.gwf@gmail.com>
  • Loading branch information
sophia-guo committed Mar 7, 2021
1 parent 1a4acb8 commit 6beb5de
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 16 deletions.
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ci-jenkins-pipelines</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
97 changes: 81 additions & 16 deletions pipelines/build/common/openjdk_build_pipeline.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,36 @@ class Build {
The test jobs all follow the same name naming pattern that is defined in the openjdk-tests repository.
E.g. Test_openjdk11_hs_sanity.system_ppc64_aix
*/
def getTestJobParams(testType) {
def jobParams = [:]
def getSmokeTestJobParams() {
def jobParams = getCommonTestJobParams()
jobParams.put('LEVELS', "extend")
jobParams.put('GROUPS', "functional")
jobParams.put('TEST_JOB_NAME', "${env.JOB_NAME}_SmokeTests")
jobParams.put("VENDOR_TEST_REPOS", ((String)ADOPT_DEFAULTS_JSON['repository']['build_url']).minus(".git"))
jobParams.put("VENDOR_TEST_BRANCHES","${ADOPT_DEFAULTS_JSON['repository']['build_branch']}")
jobParams.put("VENDOR_TEST_DIRS", "${ADOPT_DEFAULTS_JSON['repository']['test_dirs']}")
return jobParams
}

def getAQATestJobParams(testType) {
def jobParams = getCommonTestJobParams()
def (level, group) = testType.tokenize('.')
jobParams.put('LEVELS', level)
jobParams.put('GROUPS', group)
def jobName = "Test_openjdk${jobParams['JDK_VERSIONS']}_${jobParams['JDK_IMPL']}_${testType}_${jobParams['ARCH_OS_LIST']}"
if (buildConfig.ADDITIONAL_FILE_NAME_TAG) {
switch (buildConfig.ADDITIONAL_FILE_NAME_TAG) {
case ~/.*XL.*/:
jobName += "_xl";
break
}
}
jobParams.put('TEST_JOB_NAME', jobName)
return jobParams
}

def getCommonTestJobParams() {
def commonJobParams = [:]
def number = getJavaVersionNumber()
jobParams.put('JDK_VERSIONS', number)
def variant
Expand All @@ -152,22 +177,18 @@ class Build {
if (arch == "x64") {
arch = "x86-64"
}
def arch_os = "${arch}_${buildConfig.TARGET_OS}"
def jobName = "Test_openjdk${number}_${variant}_${testType}_${arch_os}"
def arch_os = "${arch}_${buildConfig.TARGET_OS}"
if (buildConfig.ADDITIONAL_FILE_NAME_TAG) {
switch (buildConfig.ADDITIONAL_FILE_NAME_TAG) {
case ~/.*XL.*/:
jobName += "_xl";
arch_os += "_xl";
break
}
}
jobParams.put('TEST_JOB_NAME', jobName)
jobParams.put('ARCH_OS_LIST', arch_os)
jobParams.put('LIGHT_WEIGHT_CHECKOUT', true)
return jobParams
}

/*
Retrieve the corresponding OpenJDK source code repository branch. This is used the downstream tests to determine what source code branch the tests should run against.
*/
Expand Down Expand Up @@ -236,13 +257,51 @@ class Build {

return jdkRepo
}
/*
Run smoke tests, which should block the running downstream test jobs should there are failures.
If we try to call a test job that doesn't exist, the pipeline will not fail but it will print out a warning.
If you need more test jobs added, please request so in #testing on Slack.
*/
def runSmokeTests() {
def additionalTestLabel = buildConfig.ADDITIONAL_TEST_LABEL

try {
context.println "Running smoke test"
context.stage("smoke test") {
def jobParams = getSmokeTestJobParams()
def jobName = jobParams.TEST_JOB_NAME
def JobHelper = context.library(identifier: 'openjdk-jenkins-helper@master').JobHelper
if (!JobHelper.jobIsRunnable(jobName as String)) {
context.sh('curl -Os https://raw.githubusercontent.com/AdoptOpenJDK/openjdk-tests/master/buildenv/jenkins/testJobTemplate')
def templatePath = 'testJobTemplate'
context.println "Smoke test job doesn't exist, create test job: ${jobName}"
jobDsl targets: templatePath, ignoreExisting: false, additionalParameters: jobParams
}

context.catchError {
context.build job: jobName,
propagate: false,
parameters: [
context.string(name: 'UPSTREAM_JOB_NUMBER', value: "${env.BUILD_NUMBER}"),
context.string(name: 'UPSTREAM_JOB_NAME', value: "${env.JOB_NAME}"),
context.string(name: 'RELEASE_TAG', value: "${buildConfig.SCM_REF}"),
context.string(name: 'LABEL_ADDITION', value: additionalTestLabel),
context.string(name: 'KEEP_REPORTDIR', value: "${keep_test_reportdir}"),
context.string(name: 'ACTIVE_NODE_TIMEOUT', value: "${buildConfig.ACTIVE_NODE_TIMEOUT}")]
}
}
} catch (Exception e) {
context.println "Failed to execute test: ${e.getLocalizedMessage()}"
throw new Exception("[ERROR] Smoke Tests failed. Tests Stop. ")
}
}
/*
Run the downstream test jobs based off the configuration passed down from the top level pipeline jobs.
If we try to call a test job that doesn't exist, the pipeline will not fail but it will print out a warning.
If you need more test jobs added, please request so in #testing on Slack.
*/
def runTests() {
// def runDownStreamTests()
def runAQATests() {
def testStages = [:]
List testList = []
def jdkBranch = getJDKBranch()
Expand All @@ -264,7 +323,7 @@ class Build {
keep_test_reportdir = "true"
}

def jobParams = getTestJobParams(testType)
def jobParams = getAQATestJobParams(testType)
def jobName = jobParams.TEST_JOB_NAME
def JobHelper = context.library(identifier: 'openjdk-jenkins-helper@master').JobHelper

Expand Down Expand Up @@ -1322,15 +1381,21 @@ class Build {
throw new Exception("[ERROR] Sign job timeout (${buildTimeouts.SIGN_JOB_TIMEOUT} HOURS) has been reached OR the downstream sign job failed. Exiting...")
}
}

if (enableTests && buildConfig.TEST_LIST.size() > 0) {
try {
// Run tests if we have a test list, don't use timeouts as the jobs have their own
def testStages = runTests()
context.parallel testStages
} catch (Exception e) {

// Run Smoke Tests and AQA Tests
try {
runSmokeTests()
if (enableTests && buildConfig.TEST_LIST.size() > 0) {
try {
// Run tests if we have a test list, don't use timeouts as the jobs have their own
def testStages = runAQATests()
context.parallel testStages
} catch (Exception e) {
context.println "Failed test: ${e}"
}
}
} catch (Exception e) {
context.println(e.message)
}

//buildInstaller if needed
Expand Down
1 change: 1 addition & 0 deletions pipelines/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"repository" : {
"build_url" : "https://github.com/AdoptOpenJDK/openjdk-build.git",
"build_branch" : "master",
"test_dirs" : "/test/functional",
"pipeline_url" : "https://github.com/AdoptOpenJDK/ci-jenkins-pipelines.git",
"pipeline_branch" : "master"
},
Expand Down

0 comments on commit 6beb5de

Please sign in to comment.