distribtest_targets.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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. import os.path
  17. import sys
  18. sys.path.insert(0, os.path.abspath('..'))
  19. import python_utils.jobset as jobset
  20. def create_docker_jobspec(name,
  21. dockerfile_dir,
  22. shell_command,
  23. environ={},
  24. flake_retries=0,
  25. timeout_retries=0,
  26. copy_rel_path=None,
  27. timeout_seconds=30 * 60):
  28. """Creates jobspec for a task running under docker."""
  29. environ = environ.copy()
  30. # the entire repo will be cloned if copy_rel_path is not set.
  31. if copy_rel_path:
  32. environ['RELATIVE_COPY_PATH'] = copy_rel_path
  33. docker_args = []
  34. for k, v in list(environ.items()):
  35. docker_args += ['-e', '%s=%s' % (k, v)]
  36. docker_env = {
  37. 'DOCKERFILE_DIR': dockerfile_dir,
  38. 'DOCKER_RUN_SCRIPT': 'tools/run_tests/dockerize/docker_run.sh',
  39. 'DOCKER_RUN_SCRIPT_COMMAND': shell_command,
  40. }
  41. jobspec = jobset.JobSpec(
  42. cmdline=['tools/run_tests/dockerize/build_and_run_docker.sh'] +
  43. docker_args,
  44. environ=docker_env,
  45. shortname='distribtest.%s' % (name),
  46. timeout_seconds=timeout_seconds,
  47. flake_retries=flake_retries,
  48. timeout_retries=timeout_retries)
  49. return jobspec
  50. def create_jobspec(name,
  51. cmdline,
  52. environ=None,
  53. shell=False,
  54. flake_retries=0,
  55. timeout_retries=0,
  56. use_workspace=False,
  57. timeout_seconds=10 * 60):
  58. """Creates jobspec."""
  59. environ = environ.copy()
  60. if use_workspace:
  61. environ['WORKSPACE_NAME'] = 'workspace_%s' % name
  62. cmdline = ['bash', 'tools/run_tests/artifacts/run_in_workspace.sh'
  63. ] + cmdline
  64. jobspec = jobset.JobSpec(cmdline=cmdline,
  65. environ=environ,
  66. shortname='distribtest.%s' % (name),
  67. timeout_seconds=timeout_seconds,
  68. flake_retries=flake_retries,
  69. timeout_retries=timeout_retries,
  70. shell=shell)
  71. return jobspec
  72. class CSharpDistribTest(object):
  73. """Tests C# NuGet package"""
  74. def __init__(self,
  75. platform,
  76. arch,
  77. docker_suffix=None,
  78. use_dotnet_cli=False,
  79. presubmit=False):
  80. self.name = 'csharp_%s_%s' % (platform, arch)
  81. self.platform = platform
  82. self.arch = arch
  83. self.docker_suffix = docker_suffix
  84. self.labels = ['distribtest', 'csharp', platform, arch]
  85. if presubmit:
  86. self.labels.append('presubmit')
  87. self.script_suffix = ''
  88. if docker_suffix:
  89. self.name += '_%s' % docker_suffix
  90. self.labels.append(docker_suffix)
  91. if use_dotnet_cli:
  92. self.name += '_dotnetcli'
  93. self.script_suffix = '_dotnetcli'
  94. self.labels.append('dotnetcli')
  95. else:
  96. self.labels.append('olddotnet')
  97. def pre_build_jobspecs(self):
  98. return []
  99. def build_jobspec(self, inner_jobs=None):
  100. del inner_jobs # arg unused as there is little opportunity for parallelizing whats inside the distribtests
  101. if self.platform == 'linux':
  102. return create_docker_jobspec(
  103. self.name,
  104. 'tools/dockerfile/distribtest/csharp_%s_%s' %
  105. (self.docker_suffix, self.arch),
  106. 'test/distrib/csharp/run_distrib_test%s.sh' %
  107. self.script_suffix,
  108. copy_rel_path='test/distrib')
  109. elif self.platform == 'macos':
  110. return create_jobspec(self.name, [
  111. 'test/distrib/csharp/run_distrib_test%s.sh' % self.script_suffix
  112. ],
  113. environ={'EXTERNAL_GIT_ROOT': '../../../..'},
  114. use_workspace=True)
  115. elif self.platform == 'windows':
  116. if self.arch == 'x64':
  117. # Use double leading / as the first occurrence gets removed by msys bash
  118. # when invoking the .bat file (side-effect of posix path conversion)
  119. environ = {
  120. 'MSBUILD_EXTRA_ARGS': '//p:Platform=x64',
  121. 'DISTRIBTEST_OUTPATH': 'DistribTest\\bin\\x64\\Debug'
  122. }
  123. else:
  124. environ = {'DISTRIBTEST_OUTPATH': 'DistribTest\\bin\\Debug'}
  125. return create_jobspec(self.name, [
  126. 'test\\distrib\\csharp\\run_distrib_test%s.bat' %
  127. self.script_suffix
  128. ],
  129. environ=environ,
  130. use_workspace=True)
  131. else:
  132. raise Exception("Not supported yet.")
  133. def __str__(self):
  134. return self.name
  135. class PythonDistribTest(object):
  136. """Tests Python package"""
  137. def __init__(self,
  138. platform,
  139. arch,
  140. docker_suffix,
  141. source=False,
  142. presubmit=False):
  143. self.source = source
  144. if source:
  145. self.name = 'python_dev_%s_%s_%s' % (platform, arch, docker_suffix)
  146. else:
  147. self.name = 'python_%s_%s_%s' % (platform, arch, docker_suffix)
  148. self.platform = platform
  149. self.arch = arch
  150. self.docker_suffix = docker_suffix
  151. self.labels = ['distribtest', 'python', platform, arch, docker_suffix]
  152. if presubmit:
  153. self.labels.append('presubmit')
  154. def pre_build_jobspecs(self):
  155. return []
  156. def build_jobspec(self, inner_jobs=None):
  157. # TODO(jtattermusch): honor inner_jobs arg for this task.
  158. del inner_jobs
  159. if not self.platform == 'linux':
  160. raise Exception("Not supported yet.")
  161. if self.source:
  162. return create_docker_jobspec(
  163. self.name,
  164. 'tools/dockerfile/distribtest/python_dev_%s_%s' %
  165. (self.docker_suffix, self.arch),
  166. 'test/distrib/python/run_source_distrib_test.sh',
  167. copy_rel_path='test/distrib')
  168. else:
  169. return create_docker_jobspec(
  170. self.name,
  171. 'tools/dockerfile/distribtest/python_%s_%s' %
  172. (self.docker_suffix, self.arch),
  173. 'test/distrib/python/run_binary_distrib_test.sh',
  174. copy_rel_path='test/distrib')
  175. def __str__(self):
  176. return self.name
  177. class RubyDistribTest(object):
  178. """Tests Ruby package"""
  179. def __init__(self,
  180. platform,
  181. arch,
  182. docker_suffix,
  183. ruby_version=None,
  184. source=False,
  185. presubmit=False):
  186. self.package_type = 'binary'
  187. if source:
  188. self.package_type = 'source'
  189. self.name = 'ruby_%s_%s_%s_version_%s_package_type_%s' % (
  190. platform, arch, docker_suffix, ruby_version or
  191. 'unspecified', self.package_type)
  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. if presubmit:
  198. self.labels.append('presubmit')
  199. def pre_build_jobspecs(self):
  200. return []
  201. def build_jobspec(self, inner_jobs=None):
  202. # TODO(jtattermusch): honor inner_jobs arg for this task.
  203. del inner_jobs
  204. arch_to_gem_arch = {
  205. 'x64': 'x86_64',
  206. 'x86': 'x86',
  207. }
  208. if not self.platform == 'linux':
  209. raise Exception("Not supported yet.")
  210. dockerfile_name = 'tools/dockerfile/distribtest/ruby_%s_%s' % (
  211. self.docker_suffix, self.arch)
  212. if self.ruby_version is not None:
  213. dockerfile_name += '_%s' % self.ruby_version
  214. return create_docker_jobspec(
  215. self.name,
  216. dockerfile_name,
  217. 'test/distrib/ruby/run_distrib_test.sh %s %s %s' %
  218. (arch_to_gem_arch[self.arch], self.platform, self.package_type),
  219. copy_rel_path='test/distrib')
  220. def __str__(self):
  221. return self.name
  222. class PHP7DistribTest(object):
  223. """Tests PHP7 package"""
  224. def __init__(self, platform, arch, docker_suffix=None, presubmit=False):
  225. self.name = 'php7_%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', 'php7', platform, arch]
  230. if presubmit:
  231. self.labels.append('presubmit')
  232. if docker_suffix:
  233. self.labels.append(docker_suffix)
  234. def pre_build_jobspecs(self):
  235. return []
  236. def build_jobspec(self, inner_jobs=None):
  237. # TODO(jtattermusch): honor inner_jobs arg for this task.
  238. del inner_jobs
  239. if self.platform == 'linux':
  240. return create_docker_jobspec(
  241. self.name,
  242. 'tools/dockerfile/distribtest/php7_%s_%s' %
  243. (self.docker_suffix, self.arch),
  244. 'test/distrib/php/run_distrib_test.sh',
  245. copy_rel_path='test/distrib')
  246. elif self.platform == 'macos':
  247. return create_jobspec(
  248. self.name, ['test/distrib/php/run_distrib_test_macos.sh'],
  249. environ={'EXTERNAL_GIT_ROOT': '../../../..'},
  250. timeout_seconds=15 * 60,
  251. use_workspace=True)
  252. else:
  253. raise Exception("Not supported yet.")
  254. def __str__(self):
  255. return self.name
  256. class CppDistribTest(object):
  257. """Tests Cpp make install by building examples."""
  258. def __init__(self,
  259. platform,
  260. arch,
  261. docker_suffix=None,
  262. testcase=None,
  263. presubmit=False):
  264. if platform == 'linux':
  265. self.name = 'cpp_%s_%s_%s_%s' % (platform, arch, docker_suffix,
  266. testcase)
  267. else:
  268. self.name = 'cpp_%s_%s_%s' % (platform, arch, testcase)
  269. self.platform = platform
  270. self.arch = arch
  271. self.docker_suffix = docker_suffix
  272. self.testcase = testcase
  273. self.labels = [
  274. 'distribtest',
  275. 'cpp',
  276. platform,
  277. arch,
  278. testcase,
  279. ]
  280. if presubmit:
  281. self.labels.append('presubmit')
  282. if docker_suffix:
  283. self.labels.append(docker_suffix)
  284. def pre_build_jobspecs(self):
  285. return []
  286. def build_jobspec(self, inner_jobs=None):
  287. environ = {}
  288. if inner_jobs is not None:
  289. # set number of parallel jobs for the C++ build
  290. environ['GRPC_CPP_DISTRIBTEST_BUILD_COMPILER_JOBS'] = str(
  291. inner_jobs)
  292. if self.platform == 'linux':
  293. return create_docker_jobspec(
  294. self.name,
  295. 'tools/dockerfile/distribtest/cpp_%s_%s' %
  296. (self.docker_suffix, self.arch),
  297. 'test/distrib/cpp/run_distrib_test_%s.sh' % self.testcase,
  298. timeout_seconds=45 * 60)
  299. elif self.platform == 'windows':
  300. return create_jobspec(
  301. self.name,
  302. ['test\\distrib\\cpp\\run_distrib_test_%s.bat' % self.testcase],
  303. environ={},
  304. timeout_seconds=30 * 60,
  305. use_workspace=True)
  306. else:
  307. raise Exception("Not supported yet.")
  308. def __str__(self):
  309. return self.name
  310. def targets():
  311. """Gets list of supported targets"""
  312. return [
  313. # C++
  314. CppDistribTest('linux',
  315. 'x64',
  316. 'jessie',
  317. 'cmake_as_submodule',
  318. presubmit=True),
  319. CppDistribTest('linux', 'x64', 'stretch', 'cmake', presubmit=True),
  320. CppDistribTest('linux',
  321. 'x64',
  322. 'stretch',
  323. 'cmake_as_externalproject',
  324. presubmit=True),
  325. CppDistribTest('linux',
  326. 'x64',
  327. 'stretch',
  328. 'cmake_fetchcontent',
  329. presubmit=True),
  330. CppDistribTest('linux',
  331. 'x64',
  332. 'stretch',
  333. 'cmake_module_install',
  334. presubmit=True),
  335. CppDistribTest('linux',
  336. 'x64',
  337. 'stretch',
  338. 'cmake_module_install_pkgconfig',
  339. presubmit=True),
  340. CppDistribTest('linux',
  341. 'x64',
  342. 'stretch',
  343. 'cmake_pkgconfig',
  344. presubmit=True),
  345. CppDistribTest('linux',
  346. 'x64',
  347. 'stretch_aarch64_cross',
  348. 'cmake_aarch64_cross',
  349. presubmit=True),
  350. CppDistribTest('windows', 'x86', testcase='cmake', presubmit=True),
  351. CppDistribTest('windows',
  352. 'x86',
  353. testcase='cmake_as_externalproject',
  354. presubmit=True),
  355. # C#
  356. CSharpDistribTest('linux', 'x64', 'jessie', presubmit=True),
  357. CSharpDistribTest('linux', 'x64', 'stretch'),
  358. CSharpDistribTest('linux',
  359. 'x64',
  360. 'stretch',
  361. use_dotnet_cli=True,
  362. presubmit=True),
  363. CSharpDistribTest('linux', 'x64', 'centos7'),
  364. CSharpDistribTest('linux', 'x64', 'ubuntu1604'),
  365. CSharpDistribTest('linux', 'x64', 'ubuntu1604', use_dotnet_cli=True),
  366. CSharpDistribTest('linux',
  367. 'x64',
  368. 'alpine',
  369. use_dotnet_cli=True,
  370. presubmit=True),
  371. CSharpDistribTest('linux',
  372. 'x64',
  373. 'dotnet31',
  374. use_dotnet_cli=True,
  375. presubmit=True),
  376. CSharpDistribTest('linux',
  377. 'x64',
  378. 'dotnet5',
  379. use_dotnet_cli=True,
  380. presubmit=True),
  381. CSharpDistribTest('macos', 'x64', presubmit=True),
  382. CSharpDistribTest('windows', 'x86', presubmit=True),
  383. CSharpDistribTest('windows', 'x64', presubmit=True),
  384. # Python
  385. PythonDistribTest('linux', 'x64', 'buster', presubmit=True),
  386. PythonDistribTest('linux', 'x86', 'buster', presubmit=True),
  387. PythonDistribTest('linux', 'x64', 'centos7'),
  388. PythonDistribTest('linux', 'x64', 'fedora34'),
  389. PythonDistribTest('linux', 'x64', 'opensuse'),
  390. PythonDistribTest('linux', 'x64', 'arch'),
  391. PythonDistribTest('linux', 'x64', 'alpine'),
  392. PythonDistribTest('linux', 'x64', 'ubuntu1804'),
  393. PythonDistribTest('linux', 'aarch64', 'python38_buster',
  394. presubmit=True),
  395. PythonDistribTest('linux',
  396. 'x64',
  397. 'alpine3.7',
  398. source=True,
  399. presubmit=True),
  400. PythonDistribTest('linux', 'x64', 'buster', source=True,
  401. presubmit=True),
  402. PythonDistribTest('linux', 'x86', 'buster', source=True,
  403. presubmit=True),
  404. PythonDistribTest('linux', 'x64', 'centos7', source=True),
  405. PythonDistribTest('linux', 'x64', 'fedora34', source=True),
  406. PythonDistribTest('linux', 'x64', 'arch', source=True),
  407. PythonDistribTest('linux', 'x64', 'ubuntu1804', source=True),
  408. # Ruby
  409. RubyDistribTest('linux', 'x64', 'stretch', ruby_version='ruby_2_5'),
  410. RubyDistribTest('linux', 'x64', 'stretch', ruby_version='ruby_2_6'),
  411. RubyDistribTest('linux',
  412. 'x64',
  413. 'stretch',
  414. ruby_version='ruby_2_7',
  415. presubmit=True),
  416. # TODO(apolcyn): add a ruby 3.0 test once protobuf adds support
  417. RubyDistribTest('linux',
  418. 'x64',
  419. 'stretch',
  420. ruby_version='ruby_2_5',
  421. source=True,
  422. presubmit=True),
  423. RubyDistribTest('linux', 'x64', 'centos7'),
  424. RubyDistribTest('linux', 'x64', 'ubuntu1604'),
  425. RubyDistribTest('linux', 'x64', 'ubuntu1804', presubmit=True),
  426. # PHP7
  427. PHP7DistribTest('linux', 'x64', 'stretch', presubmit=True),
  428. PHP7DistribTest('macos', 'x64', presubmit=True),
  429. ]