Imported Upstream version 1.27.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, 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
143 class 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
183 class 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
221 class 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                 use_workspace=True)
247         else:
248             raise Exception("Not supported yet.")
249
250     def __str__(self):
251         return self.name
252
253
254 class CppDistribTest(object):
255     """Tests Cpp make install by building examples."""
256
257     def __init__(self, platform, arch, docker_suffix=None, testcase=None):
258         if platform == 'linux':
259             self.name = 'cpp_%s_%s_%s_%s' % (platform, arch, docker_suffix,
260                                              testcase)
261         else:
262             self.name = 'cpp_%s_%s_%s' % (platform, arch, testcase)
263         self.platform = platform
264         self.arch = arch
265         self.docker_suffix = docker_suffix
266         self.testcase = testcase
267         self.labels = [
268             'distribtest', 'cpp', platform, arch, docker_suffix, testcase
269         ]
270
271     def pre_build_jobspecs(self):
272         return []
273
274     def build_jobspec(self):
275         if self.platform == 'linux':
276             return create_docker_jobspec(
277                 self.name,
278                 'tools/dockerfile/distribtest/cpp_%s_%s' %
279                 (self.docker_suffix, self.arch),
280                 'test/distrib/cpp/run_distrib_test_%s.sh' % self.testcase,
281                 timeout_seconds=45 * 60)
282         elif self.platform == 'windows':
283             return create_jobspec(
284                 self.name,
285                 ['test\\distrib\\cpp\\run_distrib_test_%s.bat' % self.testcase],
286                 environ={},
287                 timeout_seconds=30 * 60,
288                 use_workspace=True)
289         else:
290             raise Exception("Not supported yet.")
291
292     def __str__(self):
293         return self.name
294
295
296 def targets():
297     """Gets list of supported targets"""
298     return [
299         CppDistribTest('linux', 'x64', 'jessie', 'routeguide'),
300         CppDistribTest('linux', 'x64', 'jessie', 'cmake'),
301         CppDistribTest('linux', 'x64', 'jessie', 'cmake_as_externalproject'),
302         CppDistribTest('linux', 'x64', 'jessie', 'cmake_as_submodule'),
303         CppDistribTest('linux', 'x64', 'jessie', 'cmake_fetchcontent'),
304         CppDistribTest('linux', 'x64', 'jessie', 'cmake_module_install'),
305         CppDistribTest('linux', 'x64', 'jessie', 'cmake_pkgconfig'),
306         CppDistribTest('linux', 'x64', 'jessie', 'raspberry_pi'),
307         CppDistribTest('windows', 'x86', testcase='cmake'),
308         CppDistribTest('windows', 'x86', testcase='cmake_as_externalproject'),
309         CSharpDistribTest('linux', 'x64', 'jessie'),
310         CSharpDistribTest('linux', 'x86', 'jessie'),
311         CSharpDistribTest('linux', 'x64', 'stretch'),
312         CSharpDistribTest('linux', 'x64', 'stretch', use_dotnet_cli=True),
313         CSharpDistribTest('linux', 'x64', 'centos7'),
314         CSharpDistribTest('linux', 'x64', 'ubuntu1604'),
315         CSharpDistribTest('linux', 'x64', 'ubuntu1604', use_dotnet_cli=True),
316         CSharpDistribTest('linux', 'x64', 'alpine', use_dotnet_cli=True),
317         CSharpDistribTest('macos', 'x86'),
318         CSharpDistribTest('windows', 'x86'),
319         CSharpDistribTest('windows', 'x64'),
320         PythonDistribTest('linux', 'x64', 'jessie'),
321         PythonDistribTest('linux', 'x86', 'jessie'),
322         PythonDistribTest('linux', 'x64', 'centos6'),
323         PythonDistribTest('linux', 'x64', 'centos7'),
324         PythonDistribTest('linux', 'x64', 'fedora23'),
325         PythonDistribTest('linux', 'x64', 'opensuse'),
326         PythonDistribTest('linux', 'x64', 'arch'),
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', 'fedora23', source=True),
334         PythonDistribTest('linux', 'x64', 'arch', source=True),
335         PythonDistribTest('linux', 'x64', 'ubuntu1404', source=True),
336         PythonDistribTest('linux', 'x64', 'ubuntu1604', source=True),
337         RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_3'),
338         RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_4'),
339         RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_5'),
340         RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_6'),
341         RubyDistribTest('linux', 'x64', 'centos6'),
342         RubyDistribTest('linux', 'x64', 'centos7'),
343         RubyDistribTest('linux', 'x64', 'fedora23'),
344         RubyDistribTest('linux', 'x64', 'opensuse'),
345         RubyDistribTest('linux', 'x64', 'ubuntu1404'),
346         RubyDistribTest('linux', 'x64', 'ubuntu1604'),
347         PHPDistribTest('linux', 'x64', 'jessie'),
348         PHPDistribTest('macos', 'x64'),
349     ]