1#!/usr/bin/env python 2# Copyright 2016 gRPC authors. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15"""Definition of targets run distribution package tests.""" 16 17import os.path 18import sys 19 20sys.path.insert(0, os.path.abspath('..')) 21import python_utils.jobset as jobset 22 23 24def create_docker_jobspec(name, 25 dockerfile_dir, 26 shell_command, 27 environ={}, 28 flake_retries=0, 29 timeout_retries=0, 30 copy_rel_path=None): 31 """Creates jobspec for a task running under docker.""" 32 environ = environ.copy() 33 environ['RUN_COMMAND'] = shell_command 34 # the entire repo will be cloned if copy_rel_path is not set. 35 if copy_rel_path: 36 environ['RELATIVE_COPY_PATH'] = copy_rel_path 37 38 docker_args = [] 39 for k, v in environ.items(): 40 docker_args += ['-e', '%s=%s' % (k, v)] 41 docker_env = { 42 'DOCKERFILE_DIR': dockerfile_dir, 43 'DOCKER_RUN_SCRIPT': 'tools/run_tests/dockerize/docker_run.sh' 44 } 45 jobspec = jobset.JobSpec( 46 cmdline=['tools/run_tests/dockerize/build_and_run_docker.sh'] + 47 docker_args, 48 environ=docker_env, 49 shortname='distribtest.%s' % (name), 50 timeout_seconds=30 * 60, 51 flake_retries=flake_retries, 52 timeout_retries=timeout_retries) 53 return jobspec 54 55 56def create_jobspec(name, 57 cmdline, 58 environ=None, 59 shell=False, 60 flake_retries=0, 61 timeout_retries=0, 62 use_workspace=False, 63 timeout_seconds=10 * 60): 64 """Creates jobspec.""" 65 environ = environ.copy() 66 if use_workspace: 67 environ['WORKSPACE_NAME'] = 'workspace_%s' % name 68 cmdline = ['bash', 'tools/run_tests/artifacts/run_in_workspace.sh' 69 ] + cmdline 70 jobspec = jobset.JobSpec( 71 cmdline=cmdline, 72 environ=environ, 73 shortname='distribtest.%s' % (name), 74 timeout_seconds=timeout_seconds, 75 flake_retries=flake_retries, 76 timeout_retries=timeout_retries, 77 shell=shell) 78 return jobspec 79 80 81class CSharpDistribTest(object): 82 """Tests C# NuGet package""" 83 84 def __init__(self, platform, arch, docker_suffix=None, 85 use_dotnet_cli=False): 86 self.name = 'csharp_%s_%s' % (platform, arch) 87 self.platform = platform 88 self.arch = arch 89 self.docker_suffix = docker_suffix 90 self.labels = ['distribtest', 'csharp', platform, arch] 91 self.script_suffix = '' 92 if docker_suffix: 93 self.name += '_%s' % docker_suffix 94 self.labels.append(docker_suffix) 95 if use_dotnet_cli: 96 self.name += '_dotnetcli' 97 self.script_suffix = '_dotnetcli' 98 self.labels.append('dotnetcli') 99 else: 100 self.labels.append('olddotnet') 101 102 def pre_build_jobspecs(self): 103 return [] 104 105 def build_jobspec(self): 106 if self.platform == 'linux': 107 return create_docker_jobspec( 108 self.name, 109 'tools/dockerfile/distribtest/csharp_%s_%s' % 110 (self.docker_suffix, self.arch), 111 'test/distrib/csharp/run_distrib_test%s.sh' % 112 self.script_suffix, 113 copy_rel_path='test/distrib') 114 elif self.platform == 'macos': 115 return create_jobspec( 116 self.name, [ 117 'test/distrib/csharp/run_distrib_test%s.sh' % 118 self.script_suffix 119 ], 120 environ={'EXTERNAL_GIT_ROOT': '../../../..'}, 121 use_workspace=True) 122 elif self.platform == 'windows': 123 if self.arch == 'x64': 124 # Use double leading / as the first occurence gets removed by msys bash 125 # when invoking the .bat file (side-effect of posix path conversion) 126 environ = { 127 'MSBUILD_EXTRA_ARGS': '//p:Platform=x64', 128 'DISTRIBTEST_OUTPATH': 'DistribTest\\bin\\x64\\Debug' 129 } 130 else: 131 environ = {'DISTRIBTEST_OUTPATH': 'DistribTest\\bin\\Debug'} 132 return create_jobspec( 133 self.name, [ 134 'test\\distrib\\csharp\\run_distrib_test%s.bat' % 135 self.script_suffix 136 ], 137 environ=environ, 138 use_workspace=True) 139 else: 140 raise Exception("Not supported yet.") 141 142 def __str__(self): 143 return self.name 144 145 146class PythonDistribTest(object): 147 """Tests Python package""" 148 149 def __init__(self, platform, arch, docker_suffix, source=False): 150 self.source = source 151 if source: 152 self.name = 'python_dev_%s_%s_%s' % (platform, arch, docker_suffix) 153 else: 154 self.name = 'python_%s_%s_%s' % (platform, arch, docker_suffix) 155 self.platform = platform 156 self.arch = arch 157 self.docker_suffix = docker_suffix 158 self.labels = ['distribtest', 'python', platform, arch, docker_suffix] 159 160 def pre_build_jobspecs(self): 161 return [] 162 163 def build_jobspec(self): 164 if not self.platform == 'linux': 165 raise Exception("Not supported yet.") 166 167 if self.source: 168 return create_docker_jobspec( 169 self.name, 170 'tools/dockerfile/distribtest/python_dev_%s_%s' % 171 (self.docker_suffix, self.arch), 172 'test/distrib/python/run_source_distrib_test.sh', 173 copy_rel_path='test/distrib') 174 else: 175 return create_docker_jobspec( 176 self.name, 177 'tools/dockerfile/distribtest/python_%s_%s' % 178 (self.docker_suffix, self.arch), 179 'test/distrib/python/run_binary_distrib_test.sh', 180 copy_rel_path='test/distrib') 181 182 def __str__(self): 183 return self.name 184 185 186class RubyDistribTest(object): 187 """Tests Ruby package""" 188 189 def __init__(self, platform, arch, docker_suffix, ruby_version=None): 190 self.name = 'ruby_%s_%s_%s_version_%s' % (platform, arch, docker_suffix, 191 ruby_version or 'unspecified') 192 self.platform = platform 193 self.arch = arch 194 self.docker_suffix = docker_suffix 195 self.ruby_version = ruby_version 196 self.labels = ['distribtest', 'ruby', platform, arch, docker_suffix] 197 198 def pre_build_jobspecs(self): 199 return [] 200 201 def build_jobspec(self): 202 arch_to_gem_arch = { 203 'x64': 'x86_64', 204 'x86': 'x86', 205 } 206 if not self.platform == 'linux': 207 raise Exception("Not supported yet.") 208 209 dockerfile_name = 'tools/dockerfile/distribtest/ruby_%s_%s' % ( 210 self.docker_suffix, self.arch) 211 if self.ruby_version is not None: 212 dockerfile_name += '_%s' % self.ruby_version 213 return create_docker_jobspec( 214 self.name, 215 dockerfile_name, 216 'test/distrib/ruby/run_distrib_test.sh %s %s' % 217 (arch_to_gem_arch[self.arch], self.platform), 218 copy_rel_path='test/distrib') 219 220 def __str__(self): 221 return self.name 222 223 224class PHPDistribTest(object): 225 """Tests PHP package""" 226 227 def __init__(self, platform, arch, docker_suffix=None): 228 self.name = 'php_%s_%s_%s' % (platform, arch, docker_suffix) 229 self.platform = platform 230 self.arch = arch 231 self.docker_suffix = docker_suffix 232 self.labels = ['distribtest', 'php', platform, arch, docker_suffix] 233 234 def pre_build_jobspecs(self): 235 return [] 236 237 def build_jobspec(self): 238 if self.platform == 'linux': 239 return create_docker_jobspec( 240 self.name, 241 'tools/dockerfile/distribtest/php_%s_%s' % (self.docker_suffix, 242 self.arch), 243 'test/distrib/php/run_distrib_test.sh', 244 copy_rel_path='test/distrib') 245 elif self.platform == 'macos': 246 return create_jobspec( 247 self.name, ['test/distrib/php/run_distrib_test_macos.sh'], 248 environ={'EXTERNAL_GIT_ROOT': '../../../..'}, 249 use_workspace=True) 250 else: 251 raise Exception("Not supported yet.") 252 253 def __str__(self): 254 return self.name 255 256 257class CppDistribTest(object): 258 """Tests Cpp make intall by building examples.""" 259 260 def __init__(self, platform, arch, docker_suffix=None, testcase=None): 261 if platform == 'linux': 262 self.name = 'cpp_%s_%s_%s_%s' % (platform, arch, docker_suffix, 263 testcase) 264 else: 265 self.name = 'cpp_%s_%s_%s' % (platform, arch, testcase) 266 self.platform = platform 267 self.arch = arch 268 self.docker_suffix = docker_suffix 269 self.testcase = testcase 270 self.labels = [ 271 'distribtest', 'cpp', platform, arch, docker_suffix, testcase 272 ] 273 274 def pre_build_jobspecs(self): 275 return [] 276 277 def build_jobspec(self): 278 if self.platform == 'linux': 279 return create_docker_jobspec( 280 self.name, 'tools/dockerfile/distribtest/cpp_%s_%s' % 281 (self.docker_suffix, self.arch), 282 'test/distrib/cpp/run_distrib_test_%s.sh' % self.testcase) 283 elif self.platform == 'windows': 284 return create_jobspec( 285 self.name, 286 ['test\\distrib\\cpp\\run_distrib_test_%s.bat' % self.testcase], 287 environ={}, 288 timeout_seconds=30 * 60, 289 use_workspace=True) 290 else: 291 raise Exception("Not supported yet.") 292 293 def __str__(self): 294 return self.name 295 296 297def targets(): 298 """Gets list of supported targets""" 299 return [ 300 CppDistribTest('linux', 'x64', 'jessie', 'routeguide'), 301 CppDistribTest('linux', 'x64', 'jessie', 'cmake'), 302 CppDistribTest('linux', 'x64', 'jessie', 'cmake_as_externalproject'), 303 CppDistribTest('linux', 'x64', 'jessie', 'cmake_as_submodule'), 304 CppDistribTest('windows', 'x86', testcase='cmake'), 305 CppDistribTest('windows', 'x86', testcase='cmake_as_externalproject'), 306 CSharpDistribTest('linux', 'x64', 'jessie'), 307 CSharpDistribTest('linux', 'x86', 'jessie'), 308 CSharpDistribTest('linux', 'x64', 'centos7'), 309 CSharpDistribTest('linux', 'x64', 'ubuntu1404'), 310 CSharpDistribTest('linux', 'x64', 'ubuntu1604'), 311 CSharpDistribTest('linux', 'x64', 'ubuntu1404', use_dotnet_cli=True), 312 CSharpDistribTest('macos', 'x86'), 313 CSharpDistribTest('windows', 'x86'), 314 CSharpDistribTest('windows', 'x64'), 315 PythonDistribTest('linux', 'x64', 'wheezy'), 316 PythonDistribTest('linux', 'x64', 'jessie'), 317 PythonDistribTest('linux', 'x86', 'jessie'), 318 PythonDistribTest('linux', 'x64', 'centos6'), 319 PythonDistribTest('linux', 'x64', 'centos7'), 320 PythonDistribTest('linux', 'x64', 'fedora20'), 321 PythonDistribTest('linux', 'x64', 'fedora21'), 322 PythonDistribTest('linux', 'x64', 'fedora22'), 323 PythonDistribTest('linux', 'x64', 'fedora23'), 324 PythonDistribTest('linux', 'x64', 'opensuse'), 325 PythonDistribTest('linux', 'x64', 'arch'), 326 PythonDistribTest('linux', 'x64', 'ubuntu1204'), 327 PythonDistribTest('linux', 'x64', 'ubuntu1404'), 328 PythonDistribTest('linux', 'x64', 'ubuntu1604'), 329 PythonDistribTest('linux', 'x64', 'alpine3.7', source=True), 330 PythonDistribTest('linux', 'x64', 'jessie', source=True), 331 PythonDistribTest('linux', 'x86', 'jessie', source=True), 332 PythonDistribTest('linux', 'x64', 'centos7', source=True), 333 PythonDistribTest('linux', 'x64', 'fedora22', source=True), 334 PythonDistribTest('linux', 'x64', 'fedora23', source=True), 335 PythonDistribTest('linux', 'x64', 'arch', source=True), 336 PythonDistribTest('linux', 'x64', 'ubuntu1404', source=True), 337 PythonDistribTest('linux', 'x64', 'ubuntu1604', source=True), 338 RubyDistribTest('linux', 'x64', 'wheezy'), 339 RubyDistribTest('linux', 'x64', 'jessie'), 340 RubyDistribTest('linux', 'x86', 'jessie'), 341 RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_0_0'), 342 RubyDistribTest('linux', 'x64', 'centos6'), 343 RubyDistribTest('linux', 'x64', 'centos7'), 344 RubyDistribTest('linux', 'x64', 'fedora20'), 345 RubyDistribTest('linux', 'x64', 'fedora21'), 346 RubyDistribTest('linux', 'x64', 'fedora22'), 347 RubyDistribTest('linux', 'x64', 'fedora23'), 348 RubyDistribTest('linux', 'x64', 'opensuse'), 349 RubyDistribTest('linux', 'x64', 'ubuntu1204'), 350 RubyDistribTest('linux', 'x64', 'ubuntu1404'), 351 RubyDistribTest('linux', 'x64', 'ubuntu1604'), 352 PHPDistribTest('linux', 'x64', 'jessie'), 353 PHPDistribTest('macos', 'x64'), 354 ] 355