Skip to content

Commit

Permalink
Update new testing framework driver stub
Browse files Browse the repository at this point in the history
  • Loading branch information
William McLendon committed Nov 13, 2020
1 parent 2dc49f7 commit 321c7c9
Show file tree
Hide file tree
Showing 7 changed files with 334 additions and 23 deletions.
88 changes: 88 additions & 0 deletions unittest/SPiFI_test_core_Info.jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env groovy
/*
* SEMS Pipeline Framework Infrastructure (SPiFI)
*
* Copyright 2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
* Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains
* certain rights in this software.
*
* LICENSE (3-Clause BSD)
* ----------------------
* Copyright 2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
* Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains
* certain rights in this software.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Contact
* -------
* William C. McLendon III (wcmclen@sandia.gov)
*/

/**
* This test loads SPiFI using a specific version and accesses / prints out
* the version number.
*/
properties([
parameters([
string(name: 'SPiFI_VERSION',
defaultValue: 'SPiFI@master',
trim: true,
description: 'The SPiFI version to load')
]),
])


// Fail if required parameters are missing.
assert params.containsKey("SPiFI_VERSION"), "Missing required parameter: SPiFI_VERSION"

// Grab a handle to all of SPiFI
def libspifi = library(params.SPiFI_VERSION).gov.sandia.sems.spifi


node("master || RHEL6 || RHEL7 || OS_RHEL6 || OS_RHEL7")
{
stage("Get Version")
{
// Print out full version inside a println
println "Loaded SPiFI version : ${libspifi.Info.version()}"

// Grab individual version components
Integer version_major = libspifi.Info.version_major()
Integer version_minor = libspifi.Info.version_minor()
Integer version_patch = libspifi.Info.version_patch()

// Multi-line print
println "Version breakdown:\n" +
"- major: ${version_major}\n" +
"- minor: ${version_minor}\n" +
"- patch: ${version_patch}"
} // End Stage

} // End Node



File renamed without changes.
159 changes: 159 additions & 0 deletions unittest/SPiFI_test_driver_version.jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#!/usr/bin/env groovy
/*
* SEMS Pipeline Framework Infrastructure (SPiFI)
*
* Copyright 2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
* Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains
* certain rights in this software.
*
* LICENSE (3-Clause BSD)
* ----------------------
* Copyright 2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
* Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains
* certain rights in this software.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Contact
* -------
* William C. McLendon III (wcmclen@sandia.gov)
*/

/**
* Unittest: SPiFI_test_driver_version
*
* This test is the main driver test for a specified VERSION of SPiFI
* - This test will load in and use the JobLauncher as part of
* its core work, but will use minimal features from this tool. If
* something is broken with the minimal JobLauncher class we'll see
* this evidenced by just about everything failing.
*
*/
properties([
parameters([
string(name: 'SPiFI_VERSION',
defaultValue: 'SPiFI-DEV@master',
trim: true,
description: 'The SPiFI version to load')
]),
])

String param_spifi_version = "SPiFI@master"
if( params.containsKey("SPiFI_VERSION") )
{
param_spifi_version = params.SPiFI_VERSION
}


// Grab a handle to all of SPiFI
def libspifi = library(param_spifi_version).gov.sandia.sems.spifi


// Print timestamps to console log
timestamps()
{


node()
{

/**
* Executes 'helpers'
*
*/
stage("Test Helpers")
{
// Note: the `build` command returns a RunWrapper object. Information on RunWrapper's API
// is here: https://javadoc.jenkins.io/plugin/workflow-support/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.html

// Test the selectable_status helper.
def rval = null
rval = run_simple_job("SPiFI_test_helper_sample_job")
rval = run_simple_job("SPiFI_test_helper_selectable_status")

rval = run_simple_job("SPiFI_test_helper_pass_every_third")
rval = run_simple_job("SPiFI_test_helper_pass_every_third")
rval = run_simple_job("SPiFI_test_helper_pass_every_third")

} // End Stage


stage("Test SPiFI Core")
{
} // End Stage


stage("Test Examples")
{
} // End Stage


stage("Test Experimental")
{
} // End Stage


stage("Reporting")
{
} // End Stage

} // End Node
} // End Timestamps



////////////////////////////////////////////////////////////////////////////////
//
// H E L P E R F U N C T I O N S
//
////////////////////////////////////////////////////////////////////////////////


/**
*
*
*/
Map run_simple_job(String job_name)
{
Map output = [:]
output.raw = build(job: job_name, propagate: false, wait: true)

if( "SUCCESS" == output.raw.getResult() )
{
// TODO: handle job success
output.body = "Job `${job_name}` was successful (${output.raw.getResult()})"
}
else
{
// TODO: handle job failure
output.body = "Job `${job_name}` did not succeed (${output.raw.getResult()})"
}

return output
}



Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*/

/**
* SPiFI_test_pass_every_third.jenkinsfile
* SPiFI_test_helper_pass_every_third.jenkinsfile
*
* This jenkinsfile defines a pipeline job that is used for testing
* and debugging other pipelines.
Expand All @@ -57,6 +57,7 @@
*/
properties([
disableConcurrentBuilds(),
copyArtifactPermission("*"),
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '',
daysToKeepStr: '90', numToKeepStr: '90')),
parameters([
Expand All @@ -81,7 +82,7 @@ if(params.containsKey("NODE_RESTRICTION"))
}
if(params.containsKey("PARAM_THRESHOLD"))
{
try
try
{
threshold = params.PARAM_THRESHOLD.toInteger()
}
Expand Down Expand Up @@ -110,11 +111,21 @@ node(node_restriction)
"\u27A4 Stage: Load Artifact\n" +
"\u27A4"

copyArtifacts filter: 'counter.txt',
fingerprintArtifacts: true,
optional: true,
projectName: 'SPiFI_test_pass_every_third',
selector: lastCompleted()
try
{
copyArtifacts filter: "counter.txt",
projectName: "${JOB_NAME}",
selector: lastCompleted(),
optional: true

println("Artifact loaded successfully")
}
catch(ex)
{
println("Artifact was not loaded.")
//Integer counter = 0
//writeFile file: 'counter.txt', text: "${counter}"
}
}


Expand All @@ -135,7 +146,7 @@ node(node_restriction)
}
else
{
println ">>> counter.txt exists : YES"
println ">>> counter.txt exists : YES"
def text = readFile "counter.txt"
Integer counter = 1
try
Expand All @@ -146,7 +157,7 @@ node(node_restriction)
}
counter++
println ">>> counter value : ${counter}"

sh(script: 'rm counter.txt', returnStatus: true)
writeFile file: 'counter.txt', text: "${counter}"

Expand Down Expand Up @@ -180,7 +191,7 @@ node(node_restriction)
"\u27A4 Stage: Save Artifact\n" +
"\u27A4"

archiveArtifacts allowEmptyArchive: true,
archiveArtifacts allowEmptyArchive: true,
artifacts: 'counter.txt'
} // stage Save Artifact

Expand Down
66 changes: 66 additions & 0 deletions unittest/SPiFI_test_helper_sample_job.jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env groovy
/*
* SEMS Pipeline Framework Infrastructure (SPiFI)
*
* Copyright 2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
* Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains
* certain rights in this software.
*
* LICENSE (3-Clause BSD)
* ----------------------
* Copyright 2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
* Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains
* certain rights in this software.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Contact
* -------
* William C. McLendon III (wcmclen@sandia.gov)
*/

/**
* SPiFI_test_helper_sample_job
*
* This is a sample job that can be launched by the testing infrastructure.
* We would use this to test the Job Launcher or Examples
*
*/
timestamps()
{

node()
{

stage("A")
{
println("Stage A executed")
}

} // End stage node

} // End stage timestamps

Loading

0 comments on commit 321c7c9

Please sign in to comment.