blob: 5a015eac7dfbe3c3d93952f16b85d2d9d7f8c2ad [file] [log] [blame]
Roger Meier40cc2322014-06-11 11:09:14 +02001#!/usr/bin/env python
Roger Meier40cc2322014-06-11 11:09:14 +02002#
3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements. See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership. The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance
9# with the License. You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing,
14# software distributed under the License is distributed on an
15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16# KIND, either express or implied. See the License for the
17# specific language governing permissions and limitations
18# under the License.
19#
20
Roger Meier41ad4342015-03-24 22:30:40 +010021# Apache Thrift - integration test suite
22#
23# tests different server-client, protocol and transport combinations
24#
25# This script supports python 2.7 and later.
26# python 3.x is recommended for better stability.
27#
Roger Meier41ad4342015-03-24 22:30:40 +010028
Nobuaki Sukegawa378b7272016-01-03 17:04:50 +090029from __future__ import print_function
30from itertools import chain
Roger Meier40cc2322014-06-11 11:09:14 +020031import json
Roger Meier41ad4342015-03-24 22:30:40 +010032import logging
33import multiprocessing
Nobuaki Sukegawa378b7272016-01-03 17:04:50 +090034import argparse
Roger Meier41ad4342015-03-24 22:30:40 +010035import os
36import sys
Roger Meier40cc2322014-06-11 11:09:14 +020037
Roger Meier41ad4342015-03-24 22:30:40 +010038import crossrunner
Nobuaki Sukegawa378b7272016-01-03 17:04:50 +090039from crossrunner.compat import path_join
Roger Meier40cc2322014-06-11 11:09:14 +020040
Nobuaki Sukegawabd165302016-01-19 11:10:07 +090041ROOT_DIR = os.path.dirname(os.path.realpath(os.path.dirname(__file__)))
42TEST_DIR_RELATIVE = 'test'
43TEST_DIR = path_join(ROOT_DIR, TEST_DIR_RELATIVE)
44FEATURE_DIR_RELATIVE = path_join(TEST_DIR_RELATIVE, 'features')
Nobuaki Sukegawa378b7272016-01-03 17:04:50 +090045CONFIG_FILE = 'tests.json'
cdwijayarathnad1041652014-08-15 23:42:20 +053046
Roger Meier40cc2322014-06-11 11:09:14 +020047
Nobuaki Sukegawa144bbef2016-02-11 13:15:40 +090048def run_cross_tests(server_match, client_match, jobs, skip_known_failures, retry_count, regex):
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090049 logger = multiprocessing.get_logger()
50 logger.debug('Collecting tests')
51 with open(path_join(TEST_DIR, CONFIG_FILE), 'r') as fp:
52 j = json.load(fp)
Nobuaki Sukegawa144bbef2016-02-11 13:15:40 +090053 tests = crossrunner.collect_cross_tests(j, server_match, client_match, regex)
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090054 if not tests:
55 print('No test found that matches the criteria', file=sys.stderr)
56 print(' servers: %s' % server_match, file=sys.stderr)
57 print(' clients: %s' % client_match, file=sys.stderr)
58 return False
59 if skip_known_failures:
60 logger.debug('Skipping known failures')
61 known = crossrunner.load_known_failures(TEST_DIR)
62 tests = list(filter(lambda t: crossrunner.test_name(**t) not in known, tests))
Roger Meier41ad4342015-03-24 22:30:40 +010063
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090064 dispatcher = crossrunner.TestDispatcher(TEST_DIR, ROOT_DIR, TEST_DIR_RELATIVE, jobs)
65 logger.debug('Executing %d tests' % len(tests))
66 try:
67 for r in [dispatcher.dispatch(test, retry_count) for test in tests]:
68 r.wait()
69 logger.debug('Waiting for completion')
70 return dispatcher.wait()
71 except (KeyboardInterrupt, SystemExit):
72 logger.debug('Interrupted, shutting down')
73 dispatcher.terminate()
74 return False
Nobuaki Sukegawa378b7272016-01-03 17:04:50 +090075
76
Nobuaki Sukegawa144bbef2016-02-11 13:15:40 +090077def run_feature_tests(server_match, feature_match, jobs, skip_known_failures, retry_count, regex):
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090078 basedir = path_join(ROOT_DIR, FEATURE_DIR_RELATIVE)
79 logger = multiprocessing.get_logger()
80 logger.debug('Collecting tests')
81 with open(path_join(TEST_DIR, CONFIG_FILE), 'r') as fp:
82 j = json.load(fp)
83 with open(path_join(basedir, CONFIG_FILE), 'r') as fp:
84 j2 = json.load(fp)
Nobuaki Sukegawa144bbef2016-02-11 13:15:40 +090085 tests = crossrunner.collect_feature_tests(j, j2, server_match, feature_match, regex)
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090086 if not tests:
87 print('No test found that matches the criteria', file=sys.stderr)
88 print(' servers: %s' % server_match, file=sys.stderr)
89 print(' features: %s' % feature_match, file=sys.stderr)
90 return False
91 if skip_known_failures:
92 logger.debug('Skipping known failures')
93 known = crossrunner.load_known_failures(basedir)
94 tests = list(filter(lambda t: crossrunner.test_name(**t) not in known, tests))
Nobuaki Sukegawa378b7272016-01-03 17:04:50 +090095
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090096 dispatcher = crossrunner.TestDispatcher(TEST_DIR, ROOT_DIR, FEATURE_DIR_RELATIVE, jobs)
97 logger.debug('Executing %d tests' % len(tests))
98 try:
99 for r in [dispatcher.dispatch(test, retry_count) for test in tests]:
100 r.wait()
101 logger.debug('Waiting for completion')
102 return dispatcher.wait()
103 except (KeyboardInterrupt, SystemExit):
104 logger.debug('Interrupted, shutting down')
105 dispatcher.terminate()
106 return False
Roger Meier41ad4342015-03-24 22:30:40 +0100107
108
109def default_concurrenty():
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900110 try:
111 return int(os.environ.get('THRIFT_CROSSTEST_CONCURRENCY'))
112 except (TypeError, ValueError):
113 # Since much time is spent sleeping, use many threads
114 return int(multiprocessing.cpu_count() * 1.25) + 1
Roger Meier41ad4342015-03-24 22:30:40 +0100115
116
117def main(argv):
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900118 parser = argparse.ArgumentParser()
119 parser.add_argument('--server', default='', nargs='*',
120 help='list of servers to test')
121 parser.add_argument('--client', default='', nargs='*',
122 help='list of clients to test')
123 parser.add_argument('-F', '--features', nargs='*', default=None,
124 help='run server feature tests instead of cross language tests')
Nobuaki Sukegawa144bbef2016-02-11 13:15:40 +0900125 parser.add_argument('-R', '--regex', help='test name pattern to run')
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900126 parser.add_argument('-s', '--skip-known-failures', action='store_true', dest='skip_known_failures',
127 help='do not execute tests that are known to fail')
128 parser.add_argument('-r', '--retry-count', type=int,
129 default=0, help='maximum retry on failure')
130 parser.add_argument('-j', '--jobs', type=int,
131 default=default_concurrenty(),
132 help='number of concurrent test executions')
Nobuaki Sukegawa378b7272016-01-03 17:04:50 +0900133
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900134 g = parser.add_argument_group(title='Advanced')
135 g.add_argument('-v', '--verbose', action='store_const',
136 dest='log_level', const=logging.DEBUG, default=logging.WARNING,
137 help='show debug output for test runner')
138 g.add_argument('-P', '--print-expected-failures', choices=['merge', 'overwrite'],
139 dest='print_failures',
140 help="generate expected failures based on last result and print to stdout")
141 g.add_argument('-U', '--update-expected-failures', choices=['merge', 'overwrite'],
142 dest='update_failures',
143 help="generate expected failures based on last result and save to default file location")
144 options = parser.parse_args(argv)
Nobuaki Sukegawa378b7272016-01-03 17:04:50 +0900145
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900146 logger = multiprocessing.log_to_stderr()
147 logger.setLevel(options.log_level)
Roger Meier41ad4342015-03-24 22:30:40 +0100148
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900149 if options.features is not None and options.client:
150 print('Cannot specify both --features and --client ', file=sys.stderr)
151 return 1
Nobuaki Sukegawa85650612016-01-08 03:26:44 +0900152
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900153 # Allow multiple args separated with ',' for backward compatibility
154 server_match = list(chain(*[x.split(',') for x in options.server]))
155 client_match = list(chain(*[x.split(',') for x in options.client]))
Nobuaki Sukegawa378b7272016-01-03 17:04:50 +0900156
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900157 if options.update_failures or options.print_failures:
158 dire = path_join(ROOT_DIR, FEATURE_DIR_RELATIVE) if options.features is not None else TEST_DIR
159 res = crossrunner.generate_known_failures(
160 dire, options.update_failures == 'overwrite',
161 options.update_failures, options.print_failures)
162 elif options.features is not None:
163 features = options.features or ['.*']
Nobuaki Sukegawa144bbef2016-02-11 13:15:40 +0900164 res = run_feature_tests(server_match, features, options.jobs, options.skip_known_failures, options.retry_count, options.regex)
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900165 else:
Nobuaki Sukegawa144bbef2016-02-11 13:15:40 +0900166 res = run_cross_tests(server_match, client_match, options.jobs, options.skip_known_failures, options.retry_count, options.regex)
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900167 return 0 if res else 1
Roger Meiere8bafb62014-08-01 23:39:32 +0200168
James E. King, III0ad20bd2017-09-30 15:44:16 -0700169
Roger Meier41ad4342015-03-24 22:30:40 +0100170if __name__ == '__main__':
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900171 sys.exit(main(sys.argv[1:]))