blob: e9c4ce0a0f946d3b74b39ec850fab1e50fe15141 [file] [log] [blame]
Jan Tattermusch320bd612015-09-15 12:44:35 -07001#!/usr/bin/env python
2# Copyright 2015, Google Inc.
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8#
9# * Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# * Redistributions in binary form must reproduce the above
12# copyright notice, this list of conditions and the following disclaimer
13# in the documentation and/or other materials provided with the
14# distribution.
15# * Neither the name of Google Inc. nor the names of its
16# contributors may be used to endorse or promote products derived from
17# this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31"""Run interop (cross-language) tests in parallel."""
32
33import argparse
34import itertools
35import xml.etree.cElementTree as ET
36import jobset
37
Jan Tattermuschf49936a2015-09-16 15:44:26 -070038
39_CLOUD_TO_PROD_BASE_ARGS = [
40 '--server_host_override=grpc-test.sandbox.google.com',
41 '--server_host=grpc-test.sandbox.google.com',
42 '--server_port=443']
43
44# TOOD(jtattermusch) wrapped languages use this variable for location
45# of roots.pem. We might want to use GRPC_DEFAULT_SSL_ROOTS_FILE_PATH
46# supported by C core SslCredentials instead.
47_SSL_CERT_ENV = { 'SSL_CERT_FILE':'/usr/local/share/grpc/roots.pem' }
48
49# TODO(jtatttermusch) unify usage of --enable_ssl, --use_tls and --use_tls=true
50
51class CXXLanguage:
52
53 def __init__(self):
54 self.client_cmdline_base = ['bins/opt/interop_client']
55 self.client_cwd = None
56
57 def cloud_to_prod_args(self):
58 return (self.client_cmdline_base + _CLOUD_TO_PROD_BASE_ARGS +
59 ['--enable_ssl','--use_prod_roots'])
60
61 def cloud_to_prod_env(self):
62 return None
63
64 def __str__(self):
65 return 'c++'
66
67
68class CSharpLanguage:
69
70 def __init__(self):
71 self.client_cmdline_base = ['mono', 'Grpc.IntegrationTesting.Client.exe']
72 self.client_cwd = 'src/csharp/Grpc.IntegrationTesting.Client/bin/Debug'
73
74 def cloud_to_prod_args(self):
75 return (self.client_cmdline_base + _CLOUD_TO_PROD_BASE_ARGS +
76 ['--use_tls'])
77
78 def cloud_to_prod_env(self):
79 return _SSL_CERT_ENV
80
81 def __str__(self):
82 return 'csharp'
83
84
85class NodeLanguage:
86
87 def __init__(self):
88 self.client_cmdline_base = ['node', 'src/node/interop/interop_client.js']
89 self.client_cwd = None
90
91 def cloud_to_prod_args(self):
92 return (self.client_cmdline_base + _CLOUD_TO_PROD_BASE_ARGS +
93 ['--use_tls=true'])
94
95 def cloud_to_prod_env(self):
96 return _SSL_CERT_ENV
97
98 def __str__(self):
99 return 'node'
100
Jan Tattermuschf88f3e22015-09-16 17:50:45 -0700101
102class PHPLanguage:
103
104 def __init__(self):
105 self.client_cmdline_base = ['src/php/bin/interop_client.sh']
106 self.client_cwd = None
107
108 def cloud_to_prod_args(self):
109 return (self.client_cmdline_base + _CLOUD_TO_PROD_BASE_ARGS +
110 ['--use_tls'])
111
112 def cloud_to_prod_env(self):
113 return _SSL_CERT_ENV
114
115 def __str__(self):
116 return 'php'
117
118
Jan Tattermuschf49936a2015-09-16 15:44:26 -0700119class RubyLanguage:
120
121 def __init__(self):
122 self.client_cmdline_base = ['ruby', 'src/ruby/bin/interop/interop_client.rb']
123 self.client_cwd = None
124
125 def cloud_to_prod_args(self):
126 return (self.client_cmdline_base + _CLOUD_TO_PROD_BASE_ARGS +
127 ['--use_tls'])
128
129 def cloud_to_prod_env(self):
130 return _SSL_CERT_ENV
131
132 def __str__(self):
133 return 'ruby'
134
135
Jan Tattermusch320bd612015-09-15 12:44:35 -0700136# TODO(jtattermusch): add php and python once we get them working
Jan Tattermuschf49936a2015-09-16 15:44:26 -0700137_LANGUAGES = {
138 'c++' : CXXLanguage(),
139 'csharp' : CSharpLanguage(),
140 'node' : NodeLanguage(),
Jan Tattermuschf88f3e22015-09-16 17:50:45 -0700141 'php' : PHPLanguage(),
Jan Tattermuschf49936a2015-09-16 15:44:26 -0700142 'ruby' : RubyLanguage(),
143}
Jan Tattermusch320bd612015-09-15 12:44:35 -0700144
145# TODO(jtattermusch): add empty_stream once C++ start supporting it.
146# TODO(jtattermusch): add support for auth tests.
147_TEST_CASES = ['large_unary', 'empty_unary', 'ping_pong',
148 'client_streaming', 'server_streaming',
149 'cancel_after_begin', 'cancel_after_first_response',
150 'timeout_on_sleeping_server']
151
Jan Tattermuschf49936a2015-09-16 15:44:26 -0700152def cloud_to_prod_jobspec(language, test_case):
153 """Creates jobspec for cloud-to-prod interop test"""
154 cmdline = language.cloud_to_prod_args() + ['--test_case=%s' % test_case]
155 test_job = jobset.JobSpec(
156 cmdline=cmdline,
157 cwd=language.client_cwd,
158 shortname="cloud_to_prod:%s:%s" % (language, test_case),
159 environ=language.cloud_to_prod_env(),
160 timeout_seconds=60)
161 return test_job
162
Jan Tattermusch320bd612015-09-15 12:44:35 -0700163argp = argparse.ArgumentParser(description='Run interop tests.')
164argp.add_argument('-l', '--language',
165 choices=['all'] + sorted(_LANGUAGES),
166 nargs='+',
167 default=['all'])
168args = argp.parse_args()
169
Jan Tattermuschf49936a2015-09-16 15:44:26 -0700170languages = set(_LANGUAGES[l]
171 for l in itertools.chain.from_iterable(
172 _LANGUAGES.iterkeys() if x == 'all' else [x]
173 for x in args.language))
Jan Tattermusch320bd612015-09-15 12:44:35 -0700174
Jan Tattermuschf49936a2015-09-16 15:44:26 -0700175# TODO(jtattermusch): make python script generate cmdline params for interop
176# tests. It's easier to manage than in a shell script.
Jan Tattermusch320bd612015-09-15 12:44:35 -0700177jobs = []
178jobNumber = 0
179for language in languages:
Jan Tattermuschf49936a2015-09-16 15:44:26 -0700180 for test_case in _TEST_CASES:
181 test_job = cloud_to_prod_jobspec(language, test_case)
Jan Tattermusch320bd612015-09-15 12:44:35 -0700182 jobs.append(test_job)
183 jobNumber+=1
184
185root = ET.Element('testsuites')
186testsuite = ET.SubElement(root, 'testsuite', id='1', package='grpc', name='tests')
187
188jobset.run(jobs, maxjobs=jobNumber, xml_report=testsuite)
189
190tree = ET.ElementTree(root)
191tree.write('report.xml', encoding='UTF-8')
192
193