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 timeout_seconds=30 * 60): 32 """Creates jobspec for a task running under docker.""" 33 environ = environ.copy() 34 environ['RUN_COMMAND'] = shell_command 35 # the entire repo will be cloned if copy_rel_path is not set. 36 if copy_rel_path: 37 environ['RELATIVE_COPY_PATH'] = copy_rel_path 38 39 docker_args = [] 40 for k, v in environ.items(): 41 docker_args += ['-e', '%s=%s' % (k, v)] 42 docker_env = { 43 'DOCKERFILE_DIR': dockerfile_dir, 44 'DOCKER_RUN_SCRIPT': 'tools/run_tests/dockerize/docker_run.sh' 45 } 46 jobspec = jobset.JobSpec( 47 cmdline=['tools/run_tests/dockerize/build_and_run_docker.sh'] + 48 docker_args, 49 environ=docker_env, 50 shortname='distribtest.%s' % (name), 51 timeout_seconds=timeout_seconds, 52 flake_retries=flake_retries, 53 timeout_retries=timeout_retries) 54 return jobspec 55 56 57def create_jobspec(name, 58 cmdline, 59 environ=None, 60 shell=False, 61 flake_retries=0, 62 timeout_retries=0, 63 use_workspace=False, 64 timeout_seconds=10 * 60): 65 """Creates jobspec.""" 66 environ = environ.copy() 67 if use_workspace: 68 environ['WORKSPACE_NAME'] = 'workspace_%s' % name 69 cmdline = ['bash', 'tools/run_tests/artifacts/run_in_workspace.sh' 70 ] + cmdline 71 jobspec = jobset.JobSpec(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(self.name, [ 116 'test/distrib/csharp/run_distrib_test%s.sh' % self.script_suffix 117 ], 118 environ={'EXTERNAL_GIT_ROOT': '../../../..'}, 119 use_workspace=True) 120 elif self.platform == 'windows': 121 if self.arch == 'x64': 122 # Use double leading / as the first occurrence gets removed by msys bash 123 # when invoking the .bat file (side-effect of posix path conversion) 124 environ = { 125 'MSBUILD_EXTRA_ARGS': '//p:Platform=x64', 126 'DISTRIBTEST_OUTPATH': 'DistribTest\\bin\\x64\\Debug' 127 } 128 else: 129 environ = {'DISTRIBTEST_OUTPATH': 'DistribTest\\bin\\Debug'} 130 return create_jobspec(self.name, [ 131 'test\\distrib\\csharp\\run_distrib_test%s.bat' % 132 self.script_suffix 133 ], 134 environ=environ, 135 use_workspace=True) 136 else: 137 raise Exception("Not supported yet.") 138 139 def __str__(self): 140 return self.name 141 142 143class PythonDistribTest(object): 144 """Tests Python package""" 145 146 def __init__(self, platform, arch, docker_suffix, source=False): 147 self.source = source 148 if source: 149 self.name = 'python_dev_%s_%s_%s' % (platform, arch, docker_suffix) 150 else: 151 self.name = 'python_%s_%s_%s' % (platform, arch, docker_suffix) 152 self.platform = platform 153 self.arch = arch 154 self.docker_suffix = docker_suffix 155 self.labels = ['distribtest', 'python', platform, arch, docker_suffix] 156 157 def pre_build_jobspecs(self): 158 return [] 159 160 def build_jobspec(self): 161 if not self.platform == 'linux': 162 raise Exception("Not supported yet.") 163 164 if self.source: 165 return create_docker_jobspec( 166 self.name, 167 'tools/dockerfile/distribtest/python_dev_%s_%s' % 168 (self.docker_suffix, self.arch), 169 'test/distrib/python/run_source_distrib_test.sh', 170 copy_rel_path='test/distrib') 171 else: 172 return create_docker_jobspec( 173 self.name, 174 'tools/dockerfile/distribtest/python_%s_%s' % 175 (self.docker_suffix, self.arch), 176 'test/distrib/python/run_binary_distrib_test.sh', 177 copy_rel_path='test/distrib') 178 179 def __str__(self): 180 return self.name 181 182 183class RubyDistribTest(object): 184 """Tests Ruby package""" 185 186 def __init__(self, platform, arch, docker_suffix, ruby_version=None): 187 self.name = 'ruby_%s_%s_%s_version_%s' % (platform, arch, docker_suffix, 188 ruby_version or 'unspecified') 189 self.platform = platform 190 self.arch = arch 191 self.docker_suffix = docker_suffix 192 self.ruby_version = ruby_version 193 self.labels = ['distribtest', 'ruby', platform, arch, docker_suffix] 194 195 def pre_build_jobspecs(self): 196 return [] 197 198 def build_jobspec(self): 199 arch_to_gem_arch = { 200 'x64': 'x86_64', 201 'x86': 'x86', 202 } 203 if not self.platform == 'linux': 204 raise Exception("Not supported yet.") 205 206 dockerfile_name = 'tools/dockerfile/distribtest/ruby_%s_%s' % ( 207 self.docker_suffix, self.arch) 208 if self.ruby_version is not None: 209 dockerfile_name += '_%s' % self.ruby_version 210 return create_docker_jobspec( 211 self.name, 212 dockerfile_name, 213 'test/distrib/ruby/run_distrib_test.sh %s %s' % 214 (arch_to_gem_arch[self.arch], self.platform), 215 copy_rel_path='test/distrib') 216 217 def __str__(self): 218 return self.name 219 220 221class PHPDistribTest(object): 222 """Tests PHP package""" 223 224 def __init__(self, platform, arch, docker_suffix=None): 225 self.name = 'php_%s_%s_%s' % (platform, arch, docker_suffix) 226 self.platform = platform 227 self.arch = arch 228 self.docker_suffix = docker_suffix 229 self.labels = ['distribtest', 'php', platform, arch, docker_suffix] 230 231 def pre_build_jobspecs(self): 232 return [] 233 234 def build_jobspec(self): 235 if self.platform == 'linux': 236 return create_docker_jobspec( 237 self.name, 238 'tools/dockerfile/distribtest/php_%s_%s' % 239 (self.docker_suffix, self.arch), 240 'test/distrib/php/run_distrib_test.sh', 241 copy_rel_path='test/distrib') 242 elif self.platform == 'macos': 243 return create_jobspec( 244 self.name, ['test/distrib/php/run_distrib_test_macos.sh'], 245 environ={'EXTERNAL_GIT_ROOT': '../../../..'}, 246 timeout_seconds=15 * 60, 247 use_workspace=True) 248 else: 249 raise Exception("Not supported yet.") 250 251 def __str__(self): 252 return self.name 253 254 255class CppDistribTest(object): 256 """Tests Cpp make install by building examples.""" 257 258 def __init__(self, platform, arch, docker_suffix=None, testcase=None): 259 if platform == 'linux': 260 self.name = 'cpp_%s_%s_%s_%s' % (platform, arch, docker_suffix, 261 testcase) 262 else: 263 self.name = 'cpp_%s_%s_%s' % (platform, arch, testcase) 264 self.platform = platform 265 self.arch = arch 266 self.docker_suffix = docker_suffix 267 self.testcase = testcase 268 self.labels = [ 269 'distribtest', 'cpp', platform, arch, docker_suffix, testcase 270 ] 271 272 def pre_build_jobspecs(self): 273 return [] 274 275 def build_jobspec(self): 276 if self.platform == 'linux': 277 return create_docker_jobspec( 278 self.name, 279 'tools/dockerfile/distribtest/cpp_%s_%s' % 280 (self.docker_suffix, self.arch), 281 'test/distrib/cpp/run_distrib_test_%s.sh' % self.testcase, 282 timeout_seconds=45 * 60) 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', 'cmake_as_submodule'), 301 CppDistribTest('linux', 'x64', 'stretch', 'cmake'), 302 CppDistribTest('linux', 'x64', 'stretch', 'cmake_as_externalproject'), 303 CppDistribTest('linux', 'x64', 'stretch', 'cmake_fetchcontent'), 304 CppDistribTest('linux', 'x64', 'stretch', 'cmake_module_install'), 305 CppDistribTest('linux', 'x64', 'stretch', 306 'cmake_module_install_pkgconfig'), 307 CppDistribTest('linux', 'x64', 'stretch', 'cmake_pkgconfig'), 308 CppDistribTest('linux', 'x64', 'stretch', 'raspberry_pi'), 309 CppDistribTest('windows', 'x86', testcase='cmake'), 310 CppDistribTest('windows', 'x86', testcase='cmake_as_externalproject'), 311 CSharpDistribTest('linux', 'x64', 'jessie'), 312 CSharpDistribTest('linux', 'x86', 'jessie'), 313 CSharpDistribTest('linux', 'x64', 'stretch'), 314 CSharpDistribTest('linux', 'x64', 'stretch', use_dotnet_cli=True), 315 CSharpDistribTest('linux', 'x64', 'centos7'), 316 CSharpDistribTest('linux', 'x64', 'ubuntu1604'), 317 CSharpDistribTest('linux', 'x64', 'ubuntu1604', use_dotnet_cli=True), 318 CSharpDistribTest('linux', 'x64', 'alpine', use_dotnet_cli=True), 319 CSharpDistribTest('macos', 'x86'), 320 CSharpDistribTest('windows', 'x86'), 321 CSharpDistribTest('windows', 'x64'), 322 PythonDistribTest('linux', 'x64', 'jessie'), 323 PythonDistribTest('linux', 'x86', 'jessie'), 324 PythonDistribTest('linux', 'x64', 'centos6'), 325 PythonDistribTest('linux', 'x64', 'centos7'), 326 PythonDistribTest('linux', 'x64', 'fedora23'), 327 PythonDistribTest('linux', 'x64', 'opensuse'), 328 PythonDistribTest('linux', 'x64', 'arch'), 329 PythonDistribTest('linux', 'x64', 'ubuntu1404'), 330 PythonDistribTest('linux', 'x64', 'ubuntu1604'), 331 PythonDistribTest('linux', 'x64', 'alpine3.7', source=True), 332 PythonDistribTest('linux', 'x64', 'jessie', source=True), 333 PythonDistribTest('linux', 'x86', 'jessie', source=True), 334 PythonDistribTest('linux', 'x64', 'centos7', source=True), 335 PythonDistribTest('linux', 'x64', 'fedora23', source=True), 336 PythonDistribTest('linux', 'x64', 'arch', source=True), 337 PythonDistribTest('linux', 'x64', 'ubuntu1404', source=True), 338 PythonDistribTest('linux', 'x64', 'ubuntu1604', source=True), 339 RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_3'), 340 RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_4'), 341 RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_5'), 342 RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_6'), 343 RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_7'), 344 RubyDistribTest('linux', 'x64', 'centos6'), 345 RubyDistribTest('linux', 'x64', 'centos7'), 346 RubyDistribTest('linux', 'x64', 'fedora23'), 347 RubyDistribTest('linux', 'x64', 'opensuse'), 348 RubyDistribTest('linux', 'x64', 'ubuntu1404'), 349 RubyDistribTest('linux', 'x64', 'ubuntu1604'), 350 PHPDistribTest('linux', 'x64', 'jessie'), 351 PHPDistribTest('macos', 'x64'), 352 ] 353