Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add call to get-changed-trilinos-packages.sh #5803

Merged
merged 2 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions cmake/std/PullRequestLinuxDriverTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,43 @@ def compute_n():
'Trilinos_pullrequest_python_3': 'PullRequestLinuxPython3.cmake'}


def createPackageEnables(arguments):
enable_map = {'Trilinos_pullrequest_python_2': 'TrilinosFrameworkTests',
'Trilinos_pullrequest_python_3': 'TrilinosFrameworkTests'}

try:
if arguments.job_base_name not in enable_map:
subprocess.check_call([os.path.join(arguments.workspaceDir,
'Trilinos',
'commonTools',
'framework',
'get-changed-trilinos-packages.sh'),
os.path.join('origin', arguments.targetBranch),
'HEAD',
'packageEnables.cmake'])
else:
with open('packageEnables.cmake', 'w') as f_out:
f_out.write('''
MACRO(PR_ENABLE_BOOL VAR_NAME VAR_VAL)
MESSAGE("-- Setting ${VAR_NAME} = ${VAR_VAL}")
SET(${VAR_NAME} ${VAR_VAL} CACHE BOOL "Set in $CMAKE_PACKAGE_ENABLES_OUT")
ENDMACRO()

PR_ENABLE_BOOL(Trilinos_ENABLE_''' + enable_map[arguments.job_base_name] + ''' ON)
''')
print('Enabled packages:')
cmake_rstring = subprocess.check_output(['cmake',
'-P',
'packageEnables.cmake'],
stderr=subprocess.STDOUT)
if sys.version_info.major is not 3:
print(cmake_rstring)
else:
print(str(cmake_rstring, 'ASCII'))
except subprocess.CalledProcessError as cpe:
print('There was an issue generating packageEnables.cmake. '
'The error code was: {}'.format(cpe.returncode))

def run():
return_value = True
arguments = parse_args()
Expand Down Expand Up @@ -448,6 +485,8 @@ def run():

CDash_Track = getCDashTrack()

createPackageEnables(arguments)

parallel_level = compute_n()

build_name = "PR-{PULLREQUESTNUM}-test-{JOB_BASE_NAME}-{BUILD_NUMBER}". \
Expand Down
122 changes: 101 additions & 21 deletions cmake/std/unittests/TestPullRequestLinuxDriverTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import unittest.mock as mock

from argparse import Namespace
# from subprocess import CalledProcessError
from subprocess import CalledProcessError

import PullRequestLinuxDriverTest

Expand Down Expand Up @@ -79,34 +79,27 @@ def test_verifyGit_fails_with_old_version(self):
else:
with self.assertRaisesRegex(SystemExit, bad_git_string):
PullRequestLinuxDriverTest.confirmGitVersion()
m_check_out.assert_called_once_with(['git', '--version'])

m_check_out.assert_called_once_with(['git', '--version'])


def test_verifyGit_passes_with_2_10(self):
"""Check to see that git is in path"""
with self.m_check_out as m_check_out:
m_check_out.return_value='git version 2.10.1'

if sys.version_info.major is not 3:
with self.IOredirect:
PullRequestLinuxDriverTest.confirmGitVersion()
else:
with self.IOredirect:
PullRequestLinuxDriverTest.confirmGitVersion()
m_check_out.assert_called_once_with(['git', '--version'])
with self.IOredirect:
PullRequestLinuxDriverTest.confirmGitVersion()
m_check_out.assert_called_once_with(['git', '--version'])


def test_verifyGit_passes_with_2_12(self):
"""Check to see that git is in path"""
with self.m_check_out as m_check_out:
m_check_out.return_value='git version 2.12.4'

if sys.version_info.major is not 3:
with self.IOredirect:
PullRequestLinuxDriverTest.confirmGitVersion()
else:
with self.IOredirect:
PullRequestLinuxDriverTest.confirmGitVersion()
with self.IOredirect:
PullRequestLinuxDriverTest.confirmGitVersion()
m_check_out.assert_called_once_with(['git', '--version'])


Expand All @@ -115,12 +108,8 @@ def test_verifyGit_passes_with_3_x(self):
with self.m_check_out as m_check_out:
m_check_out.return_value='git version 3.6.1'

if sys.version_info.major is not 3:
with self.IOredirect:
PullRequestLinuxDriverTest.confirmGitVersion()
else:
with self.IOredirect:
PullRequestLinuxDriverTest.confirmGitVersion()
with self.IOredirect:
PullRequestLinuxDriverTest.confirmGitVersion()
m_check_out.assert_called_once_with(['git', '--version'])


Expand Down Expand Up @@ -202,6 +191,7 @@ def test_verifyTargetBranch_passes_with_master_target_mm_source(self):
self.m_check_call as m_call, \
l_argv, \
self.m_environ, \
mock.patch('PullRequestLinuxDriverTest.createPackageEnables'), \
mock.patch('PullRequestLinuxDriverTest.setBuildEnviron'), \
mock.patch('PullRequestLinuxDriverTest.getCDashTrack'):
PullRequestLinuxDriverTest.run()
Expand Down Expand Up @@ -258,6 +248,7 @@ def test_verifyTargetBranch_passes_with_develop_target(self):
self.m_check_call as m_call, \
l_argv, \
self.m_environ, \
mock.patch('PullRequestLinuxDriverTest.createPackageEnables'), \
mock.patch('PullRequestLinuxDriverTest.setBuildEnviron'), \
mock.patch('PullRequestLinuxDriverTest.getCDashTrack',
return_value='testTrack'):
Expand All @@ -277,6 +268,95 @@ def test_verifyTargetBranch_passes_with_develop_target(self):
'-Dsubprojects_file=../TFW_single_configure_support_scripts/package_subproject_list.cmake'])


class Test_createPackageEnables(unittest.TestCase):

def setUp(self):
self.source_branch = 'incoming_branch'
self.source_url = '/dev/null/source/Trilinos.git'
self.target_branch = 'base_branch'
self.target_url = '/dev/null/target/Trilinos.git'
self.job_base_name = 'JenkinsBaseName'
self.github_pr_number = '8888'
self.jenkins_build_number = '7777'
self.jenkins_workspace='/dev/null/workspace'

self.arguments = Namespace()
setattr(self.arguments, 'sourceBranch', self.source_branch)
setattr(self.arguments, 'sourceRepo', self.source_url)
setattr(self.arguments, 'targetBranch', self.target_branch)
setattr(self.arguments, 'targetRepo', self.target_url)
setattr(self.arguments, 'job_base_name', self.job_base_name)
setattr(self.arguments, 'github_pr_number', self.github_pr_number)
setattr(self.arguments, 'workspaceDir', self.jenkins_workspace)


def success_side_effect(self):
with open('packageEnables.cmake', 'w') as f_out:
f_out.write('''
MACRO(PR_ENABLE_BOOL VAR_NAME VAR_VAL)
MESSAGE("-- Setting ${VAR_NAME} = ${VAR_VAL}")
SET(${VAR_NAME} ${VAR_VAL} CACHE BOOL "Set in $CMAKE_PACKAGE_ENABLES_OUT")
ENDMACRO()
''')
f_out.write("PR_ENABLE_BOOL(Trilinos_ENABLE_FooPackageBar ON)")

def test_call_success(self):
expected_output = '''Enabled packages:
-- Setting Trilinos_ENABLE_FooPackageBar = ON

'''
with mock.patch('subprocess.check_call',
side_effect=self.success_side_effect()) as m_out, \
mock.patch('sys.stdout',
new_callable=StringIO) as m_stdout:
PullRequestLinuxDriverTest.createPackageEnables(self.arguments)
m_out.assert_called_once_with([os.path.join(self.jenkins_workspace,
'Trilinos',
'commonTools',
'framework',
'get-changed-trilinos-packages.sh'),
os.path.join('origin',
self.target_branch),
'HEAD', 'packageEnables.cmake'])
self.assertEqual(expected_output, m_stdout.getvalue())
os.unlink('packageEnables.cmake')

def test_call_python2(self):
expected_output = '''Enabled packages:
-- Setting Trilinos_ENABLE_TrilinosFrameworkTests = ON

'''

l_arguments = self.arguments
l_arguments.job_base_name = 'Trilinos_pullrequest_python_2'
with mock.patch('subprocess.check_call',
side_effect=self.success_side_effect()) as m_out, \
mock.patch('sys.stdout', new_callable=StringIO) as m_stdout:
PullRequestLinuxDriverTest.createPackageEnables(l_arguments)
m_out.assert_not_called()
self.assertEqual(expected_output, m_stdout.getvalue())
os.unlink('packageEnables.cmake')

def test_call_failure(self):
expected_output = '''There was an issue generating packageEnables.cmake. The error code was: 39
'''
with mock.patch('subprocess.check_call',
side_effect=CalledProcessError(cmd='cmake',
returncode=39)) as m_out, \
mock.patch('sys.stdout',
new_callable=StringIO) as m_stdout:
PullRequestLinuxDriverTest.createPackageEnables(self.arguments)
m_out.assert_called_once_with([os.path.join(self.jenkins_workspace,
'Trilinos',
'commonTools',
'framework',
'get-changed-trilinos-packages.sh'),
os.path.join('origin',
self.target_branch),
'HEAD', 'packageEnables.cmake'])
self.assertEqual(expected_output, m_stdout.getvalue())


class Test_setEnviron(unittest.TestCase):
"""Does the script exist?"""

Expand Down