Imported Upstream version 1.36.0
[platform/upstream/grpc.git] / tools / run_tests / artifacts / distribtest_targets.py
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
17 import os.path
18 import sys
19
20 sys.path.insert(0, os.path.abspath('..'))
21 import python_utils.jobset as jobset
22
23
24 def 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
57 def 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
81 class CSharpDistribTest(object):
82     """Tests C# NuGet package"""
83
84     def __init__(self,
85                  platform,
86                  arch,
87                  docker_suffix=None,
88                  use_dotnet_cli=False):
89         self.name = 'csharp_%s_%s' % (platform, arch)
90         self.platform = platform
91         self.arch = arch
92         self.docker_suffix = docker_suffix
93         self.labels = ['distribtest', 'csharp', platform, arch]
94         self.script_suffix = ''
95         if docker_suffix:
96             self.name += '_%s' % docker_suffix
97             self.labels.append(docker_suffix)
98         if use_dotnet_cli:
99             self.name += '_dotnetcli'
100             self.script_suffix = '_dotnetcli'
101             self.labels.append('dotnetcli')
102         else:
103             self.labels.append('olddotnet')
104
105     def pre_build_jobspecs(self):
106         return []
107
108     def build_jobspec(self):
109         if self.platform == 'linux':
110             return create_docker_jobspec(
111                 self.name,
112                 'tools/dockerfile/distribtest/csharp_%s_%s' %
113                 (self.docker_suffix, self.arch),
114                 'test/distrib/csharp/run_distrib_test%s.sh' %
115                 self.script_suffix,
116                 copy_rel_path='test/distrib')
117         elif self.platform == 'macos':
118             return create_jobspec(self.name, [
119                 'test/distrib/csharp/run_distrib_test%s.sh' % self.script_suffix
120             ],
121                                   environ={'EXTERNAL_GIT_ROOT': '../../../..'},
122                                   use_workspace=True)
123         elif self.platform == 'windows':
124             if self.arch == 'x64':
125                 # Use double leading / as the first occurrence gets removed by msys bash
126                 # when invoking the .bat file (side-effect of posix path conversion)
127                 environ = {
128                     'MSBUILD_EXTRA_ARGS': '//p:Platform=x64',
129                     'DISTRIBTEST_OUTPATH': 'DistribTest\\bin\\x64\\Debug'
130                 }
131             else:
132                 environ = {'DISTRIBTEST_OUTPATH': 'DistribTest\\bin\\Debug'}
133             return create_jobspec(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
146 class 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
186 class RubyDistribTest(object):
187     """Tests Ruby package"""
188
189     def __init__(self,
190                  platform,
191                  arch,
192                  docker_suffix,
193                  ruby_version=None,
194                  source=False):
195         self.package_type = 'binary'
196         if source:
197             self.package_type = 'source'
198         self.name = 'ruby_%s_%s_%s_version_%s_package_type_%s' % (
199             platform, arch, docker_suffix, ruby_version or
200             'unspecified', self.package_type)
201         self.platform = platform
202         self.arch = arch
203         self.docker_suffix = docker_suffix
204         self.ruby_version = ruby_version
205         self.labels = ['distribtest', 'ruby', platform, arch, docker_suffix]
206
207     def pre_build_jobspecs(self):
208         return []
209
210     def build_jobspec(self):
211         arch_to_gem_arch = {
212             'x64': 'x86_64',
213             'x86': 'x86',
214         }
215         if not self.platform == 'linux':
216             raise Exception("Not supported yet.")
217
218         dockerfile_name = 'tools/dockerfile/distribtest/ruby_%s_%s' % (
219             self.docker_suffix, self.arch)
220         if self.ruby_version is not None:
221             dockerfile_name += '_%s' % self.ruby_version
222         return create_docker_jobspec(
223             self.name,
224             dockerfile_name,
225             'test/distrib/ruby/run_distrib_test.sh %s %s %s' %
226             (arch_to_gem_arch[self.arch], self.platform, self.package_type),
227             copy_rel_path='test/distrib')
228
229     def __str__(self):
230         return self.name
231
232
233 class PHP7DistribTest(object):
234     """Tests PHP7 package"""
235
236     def __init__(self, platform, arch, docker_suffix=None):
237         self.name = 'php7_%s_%s_%s' % (platform, arch, docker_suffix)
238         self.platform = platform
239         self.arch = arch
240         self.docker_suffix = docker_suffix
241         self.labels = ['distribtest', 'php7', platform, arch]
242         if docker_suffix:
243             self.labels.append(docker_suffix)
244
245     def pre_build_jobspecs(self):
246         return []
247
248     def build_jobspec(self):
249         if self.platform == 'linux':
250             return create_docker_jobspec(
251                 self.name,
252                 'tools/dockerfile/distribtest/php7_%s_%s' %
253                 (self.docker_suffix, self.arch),
254                 'test/distrib/php/run_distrib_test.sh',
255                 copy_rel_path='test/distrib')
256         elif self.platform == 'macos':
257             return create_jobspec(
258                 self.name, ['test/distrib/php/run_distrib_test_macos.sh'],
259                 environ={'EXTERNAL_GIT_ROOT': '../../../..'},
260                 timeout_seconds=15 * 60,
261                 use_workspace=True)
262         else:
263             raise Exception("Not supported yet.")
264
265     def __str__(self):
266         return self.name
267
268
269 class CppDistribTest(object):
270     """Tests Cpp make install by building examples."""
271
272     def __init__(self, platform, arch, docker_suffix=None, testcase=None):
273         if platform == 'linux':
274             self.name = 'cpp_%s_%s_%s_%s' % (platform, arch, docker_suffix,
275                                              testcase)
276         else:
277             self.name = 'cpp_%s_%s_%s' % (platform, arch, testcase)
278         self.platform = platform
279         self.arch = arch
280         self.docker_suffix = docker_suffix
281         self.testcase = testcase
282         self.labels = [
283             'distribtest',
284             'cpp',
285             platform,
286             arch,
287             testcase,
288         ]
289         if docker_suffix:
290             self.labels.append(docker_suffix)
291
292     def pre_build_jobspecs(self):
293         return []
294
295     def build_jobspec(self):
296         if self.platform == 'linux':
297             return create_docker_jobspec(
298                 self.name,
299                 'tools/dockerfile/distribtest/cpp_%s_%s' %
300                 (self.docker_suffix, self.arch),
301                 'test/distrib/cpp/run_distrib_test_%s.sh' % self.testcase,
302                 timeout_seconds=45 * 60)
303         elif self.platform == 'windows':
304             return create_jobspec(
305                 self.name,
306                 ['test\\distrib\\cpp\\run_distrib_test_%s.bat' % self.testcase],
307                 environ={},
308                 timeout_seconds=30 * 60,
309                 use_workspace=True)
310         else:
311             raise Exception("Not supported yet.")
312
313     def __str__(self):
314         return self.name
315
316
317 def targets():
318     """Gets list of supported targets"""
319     return [
320         # C++
321         CppDistribTest('linux', 'x64', 'jessie', 'cmake_as_submodule'),
322         CppDistribTest('linux', 'x64', 'stretch', 'cmake'),
323         CppDistribTest('linux', 'x64', 'stretch', 'cmake_as_externalproject'),
324         CppDistribTest('linux', 'x64', 'stretch', 'cmake_fetchcontent'),
325         CppDistribTest('linux', 'x64', 'stretch', 'cmake_module_install'),
326         CppDistribTest('linux', 'x64', 'stretch',
327                        'cmake_module_install_pkgconfig'),
328         CppDistribTest('linux', 'x64', 'stretch', 'cmake_pkgconfig'),
329         CppDistribTest('linux', 'x64', 'stretch', 'raspberry_pi'),
330         CppDistribTest('windows', 'x86', testcase='cmake'),
331         CppDistribTest('windows', 'x86', testcase='cmake_as_externalproject'),
332         # C#
333         CSharpDistribTest('linux', 'x64', 'jessie'),
334         CSharpDistribTest('linux', 'x64', 'stretch'),
335         CSharpDistribTest('linux', 'x64', 'stretch', use_dotnet_cli=True),
336         CSharpDistribTest('linux', 'x64', 'centos7'),
337         CSharpDistribTest('linux', 'x64', 'ubuntu1604'),
338         CSharpDistribTest('linux', 'x64', 'ubuntu1604', use_dotnet_cli=True),
339         CSharpDistribTest('linux', 'x64', 'alpine', use_dotnet_cli=True),
340         CSharpDistribTest('linux', 'x64', 'dotnet31', use_dotnet_cli=True),
341         CSharpDistribTest('linux', 'x64', 'dotnet5', use_dotnet_cli=True),
342         CSharpDistribTest('macos', 'x64'),
343         CSharpDistribTest('windows', 'x86'),
344         CSharpDistribTest('windows', 'x64'),
345         # Python
346         PythonDistribTest('linux', 'x64', 'jessie'),
347         PythonDistribTest('linux', 'x86', 'jessie'),
348         PythonDistribTest('linux', 'x64', 'centos6'),
349         PythonDistribTest('linux', 'x64', 'centos7'),
350         PythonDistribTest('linux', 'x64', 'fedora23'),
351         PythonDistribTest('linux', 'x64', 'opensuse'),
352         PythonDistribTest('linux', 'x64', 'arch'),
353         PythonDistribTest('linux', 'x64', 'ubuntu1604'),
354         PythonDistribTest('linux', 'x64', 'ubuntu1804'),
355         PythonDistribTest('linux', 'x64', 'alpine3.7', source=True),
356         PythonDistribTest('linux', 'x64', 'jessie', source=True),
357         PythonDistribTest('linux', 'x86', 'jessie', source=True),
358         PythonDistribTest('linux', 'x64', 'centos7', source=True),
359         PythonDistribTest('linux', 'x64', 'fedora23', source=True),
360         PythonDistribTest('linux', 'x64', 'arch', source=True),
361         PythonDistribTest('linux', 'x64', 'ubuntu1604', source=True),
362         PythonDistribTest('linux', 'x64', 'ubuntu1804', source=True),
363         # Ruby
364         RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_4'),
365         RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_5'),
366         RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_6'),
367         RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_7'),
368         # TODO(apolcyn): add a ruby 3.0 test once protobuf adds support
369         RubyDistribTest('linux',
370                         'x64',
371                         'jessie',
372                         ruby_version='ruby_2_4',
373                         source=True),
374         RubyDistribTest('linux', 'x64', 'centos7'),
375         RubyDistribTest('linux', 'x64', 'fedora23'),
376         RubyDistribTest('linux', 'x64', 'opensuse'),
377         RubyDistribTest('linux', 'x64', 'ubuntu1604'),
378         RubyDistribTest('linux', 'x64', 'ubuntu1804'),
379         # PHP7
380         PHP7DistribTest('linux', 'x64', 'stretch'),
381         PHP7DistribTest('macos', 'x64'),
382     ]