Roger Meier | 40cc232 | 2014-06-11 11:09:14 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
Roger Meier | 40cc232 | 2014-06-11 11:09:14 +0200 | [diff] [blame] | 2 | # |
| 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 Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 21 | # 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 Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 28 | |
Nobuaki Sukegawa | 378b727 | 2016-01-03 17:04:50 +0900 | [diff] [blame] | 29 | from __future__ import print_function |
| 30 | from itertools import chain |
Roger Meier | 40cc232 | 2014-06-11 11:09:14 +0200 | [diff] [blame] | 31 | import json |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 32 | import logging |
| 33 | import multiprocessing |
Nobuaki Sukegawa | 378b727 | 2016-01-03 17:04:50 +0900 | [diff] [blame] | 34 | import argparse |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 35 | import os |
| 36 | import sys |
Roger Meier | 40cc232 | 2014-06-11 11:09:14 +0200 | [diff] [blame] | 37 | |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 38 | import crossrunner |
Nobuaki Sukegawa | 378b727 | 2016-01-03 17:04:50 +0900 | [diff] [blame] | 39 | from crossrunner.compat import path_join |
Roger Meier | 40cc232 | 2014-06-11 11:09:14 +0200 | [diff] [blame] | 40 | |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 41 | TEST_DIR = os.path.realpath(os.path.dirname(__file__)) |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 42 | FEATURE_DIR = path_join(TEST_DIR, 'features') |
Nobuaki Sukegawa | 378b727 | 2016-01-03 17:04:50 +0900 | [diff] [blame] | 43 | CONFIG_FILE = 'tests.json' |
cdwijayarathna | d104165 | 2014-08-15 23:42:20 +0530 | [diff] [blame] | 44 | |
Roger Meier | 40cc232 | 2014-06-11 11:09:14 +0200 | [diff] [blame] | 45 | |
Nobuaki Sukegawa | 378b727 | 2016-01-03 17:04:50 +0900 | [diff] [blame] | 46 | def run_tests(collect_func, basedir, server_match, client_match, jobs, skip): |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 47 | logger = multiprocessing.get_logger() |
| 48 | logger.debug('Collecting tests') |
Nobuaki Sukegawa | 378b727 | 2016-01-03 17:04:50 +0900 | [diff] [blame] | 49 | with open(path_join(basedir, CONFIG_FILE), 'r') as fp: |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 50 | j = json.load(fp) |
Nobuaki Sukegawa | 378b727 | 2016-01-03 17:04:50 +0900 | [diff] [blame] | 51 | tests = collect_func(j, server_match, client_match) |
| 52 | if not tests: |
| 53 | print('No test found that matches the criteria', file=sys.stderr) |
| 54 | # print(' servers: %s' % server_match, file=sys.stderr) |
| 55 | # print(' clients: %s' % client_match, file=sys.stderr) |
| 56 | return False |
| 57 | if skip: |
| 58 | logger.debug('Skipping known failures') |
| 59 | known = crossrunner.load_known_failures(basedir) |
| 60 | tests = list(filter(lambda t: crossrunner.test_name(**t) not in known, tests)) |
| 61 | |
| 62 | dispatcher = crossrunner.TestDispatcher(TEST_DIR, basedir, jobs) |
| 63 | logger.debug('Executing %d tests' % len(tests)) |
| 64 | try: |
| 65 | for r in [dispatcher.dispatch(test) for test in tests]: |
| 66 | r.wait() |
| 67 | logger.debug('Waiting for completion') |
| 68 | return dispatcher.wait() |
| 69 | except (KeyboardInterrupt, SystemExit): |
| 70 | logger.debug('Interrupted, shutting down') |
| 71 | dispatcher.terminate() |
| 72 | return False |
| 73 | |
| 74 | |
| 75 | def run_cross_tests(server_match, client_match, jobs, skip_known_failures): |
| 76 | logger = multiprocessing.get_logger() |
| 77 | logger.debug('Collecting tests') |
| 78 | with open(path_join(TEST_DIR, CONFIG_FILE), 'r') as fp: |
| 79 | j = json.load(fp) |
| 80 | tests = crossrunner.collect_cross_tests(j, server_match, client_match) |
| 81 | if not tests: |
| 82 | print('No test found that matches the criteria', file=sys.stderr) |
| 83 | print(' servers: %s' % server_match, file=sys.stderr) |
| 84 | print(' clients: %s' % client_match, file=sys.stderr) |
| 85 | return False |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 86 | if skip_known_failures: |
Nobuaki Sukegawa | 378b727 | 2016-01-03 17:04:50 +0900 | [diff] [blame] | 87 | logger.debug('Skipping known failures') |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 88 | known = crossrunner.load_known_failures(TEST_DIR) |
| 89 | tests = list(filter(lambda t: crossrunner.test_name(**t) not in known, tests)) |
| 90 | |
Nobuaki Sukegawa | 378b727 | 2016-01-03 17:04:50 +0900 | [diff] [blame] | 91 | dispatcher = crossrunner.TestDispatcher(TEST_DIR, TEST_DIR, jobs) |
| 92 | logger.debug('Executing %d tests' % len(tests)) |
| 93 | try: |
| 94 | for r in [dispatcher.dispatch(test) for test in tests]: |
| 95 | r.wait() |
| 96 | logger.debug('Waiting for completion') |
| 97 | return dispatcher.wait() |
| 98 | except (KeyboardInterrupt, SystemExit): |
| 99 | logger.debug('Interrupted, shutting down') |
| 100 | dispatcher.terminate() |
| 101 | return False |
| 102 | |
| 103 | |
| 104 | def run_feature_tests(server_match, feature_match, jobs, skip_known_failures): |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 105 | basedir = FEATURE_DIR |
Nobuaki Sukegawa | 378b727 | 2016-01-03 17:04:50 +0900 | [diff] [blame] | 106 | logger = multiprocessing.get_logger() |
| 107 | logger.debug('Collecting tests') |
| 108 | with open(path_join(TEST_DIR, CONFIG_FILE), 'r') as fp: |
| 109 | j = json.load(fp) |
| 110 | with open(path_join(basedir, CONFIG_FILE), 'r') as fp: |
| 111 | j2 = json.load(fp) |
| 112 | tests = crossrunner.collect_feature_tests(j, j2, server_match, feature_match) |
| 113 | if not tests: |
| 114 | print('No test found that matches the criteria', file=sys.stderr) |
| 115 | print(' servers: %s' % server_match, file=sys.stderr) |
| 116 | print(' features: %s' % feature_match, file=sys.stderr) |
| 117 | return False |
| 118 | if skip_known_failures: |
| 119 | logger.debug('Skipping known failures') |
| 120 | known = crossrunner.load_known_failures(basedir) |
| 121 | tests = list(filter(lambda t: crossrunner.test_name(**t) not in known, tests)) |
| 122 | |
| 123 | dispatcher = crossrunner.TestDispatcher(TEST_DIR, basedir, jobs) |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 124 | logger.debug('Executing %d tests' % len(tests)) |
| 125 | try: |
| 126 | for r in [dispatcher.dispatch(test) for test in tests]: |
| 127 | r.wait() |
| 128 | logger.debug('Waiting for completion') |
| 129 | return dispatcher.wait() |
| 130 | except (KeyboardInterrupt, SystemExit): |
| 131 | logger.debug('Interrupted, shutting down') |
| 132 | dispatcher.terminate() |
| 133 | return False |
| 134 | |
| 135 | |
| 136 | def default_concurrenty(): |
| 137 | try: |
| 138 | return int(os.environ.get('THRIFT_CROSSTEST_CONCURRENCY')) |
| 139 | except (TypeError, ValueError): |
| 140 | # Since much time is spent sleeping, use many threads |
| 141 | return int(multiprocessing.cpu_count() * 1.25) + 1 |
| 142 | |
| 143 | |
| 144 | def main(argv): |
Nobuaki Sukegawa | 378b727 | 2016-01-03 17:04:50 +0900 | [diff] [blame] | 145 | parser = argparse.ArgumentParser() |
| 146 | parser.add_argument('--server', default='', nargs='*', |
| 147 | help='list of servers to test') |
| 148 | parser.add_argument('--client', default='', nargs='*', |
| 149 | help='list of clients to test') |
| 150 | parser.add_argument('-s', '--skip-known-failures', action='store_true', dest='skip_known_failures', |
| 151 | help='do not execute tests that are known to fail') |
| 152 | parser.add_argument('-j', '--jobs', type=int, |
| 153 | default=default_concurrenty(), |
| 154 | help='number of concurrent test executions') |
| 155 | parser.add_argument('-F', '--features', nargs='*', default=None, |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 156 | help='run server feature tests instead of cross language tests') |
Nobuaki Sukegawa | 378b727 | 2016-01-03 17:04:50 +0900 | [diff] [blame] | 157 | |
| 158 | g = parser.add_argument_group(title='Advanced') |
| 159 | g.add_argument('-v', '--verbose', action='store_const', |
| 160 | dest='log_level', const=logging.DEBUG, default=logging.WARNING, |
| 161 | help='show debug output for test runner') |
| 162 | g.add_argument('-P', '--print-expected-failures', choices=['merge', 'overwrite'], |
| 163 | dest='print_failures', |
| 164 | help="generate expected failures based on last result and print to stdout") |
| 165 | g.add_argument('-U', '--update-expected-failures', choices=['merge', 'overwrite'], |
| 166 | dest='update_failures', |
| 167 | help="generate expected failures based on last result and save to default file location") |
| 168 | options = parser.parse_args(argv) |
| 169 | |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 170 | logger = multiprocessing.log_to_stderr() |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 171 | logger.setLevel(options.log_level) |
| 172 | |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 173 | if options.features is not None and options.client: |
| 174 | print('Cannot specify both --features and --client ', file=sys.stderr) |
| 175 | return 1 |
| 176 | |
Nobuaki Sukegawa | 378b727 | 2016-01-03 17:04:50 +0900 | [diff] [blame] | 177 | # Allow multiple args separated with ',' for backward compatibility |
| 178 | server_match = list(chain(*[x.split(',') for x in options.server])) |
| 179 | client_match = list(chain(*[x.split(',') for x in options.client])) |
| 180 | |
| 181 | if options.update_failures or options.print_failures: |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 182 | dire = FEATURE_DIR if options.features is not None else TEST_DIR |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 183 | res = crossrunner.generate_known_failures( |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 184 | dire, options.update_failures == 'overwrite', |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 185 | options.update_failures, options.print_failures) |
Nobuaki Sukegawa | 378b727 | 2016-01-03 17:04:50 +0900 | [diff] [blame] | 186 | elif options.features is not None: |
| 187 | features = options.features or ['.*'] |
| 188 | res = run_feature_tests(server_match, features, options.jobs, options.skip_known_failures) |
Roger Meier | e8bafb6 | 2014-08-01 23:39:32 +0200 | [diff] [blame] | 189 | else: |
Nobuaki Sukegawa | 378b727 | 2016-01-03 17:04:50 +0900 | [diff] [blame] | 190 | res = run_cross_tests(server_match, client_match, options.jobs, options.skip_known_failures) |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 191 | return 0 if res else 1 |
Roger Meier | e8bafb6 | 2014-08-01 23:39:32 +0200 | [diff] [blame] | 192 | |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 193 | if __name__ == '__main__': |
| 194 | sys.exit(main(sys.argv[1:])) |