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 | # |
| 28 | # TODO: eliminate a few 2.7 occurrences to support 2.6 ? |
| 29 | # |
| 30 | |
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 |
| 34 | import optparse |
| 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 |
Roger Meier | 40cc232 | 2014-06-11 11:09:14 +0200 | [diff] [blame] | 39 | |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame^] | 40 | TEST_DIR = os.path.realpath(os.path.dirname(__file__)) |
| 41 | CONFIG_PATH = os.path.join(TEST_DIR, 'tests.json') |
cdwijayarathna | d104165 | 2014-08-15 23:42:20 +0530 | [diff] [blame] | 42 | |
Roger Meier | 40cc232 | 2014-06-11 11:09:14 +0200 | [diff] [blame] | 43 | |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame^] | 44 | def prepare(server_match, client_match): |
| 45 | with open(CONFIG_PATH, 'r') as fp: |
| 46 | j = json.load(fp) |
| 47 | return crossrunner.prepare(j, TEST_DIR, server_match, client_match) |
cdwijayarathna | 3f67978 | 2014-07-09 14:00:33 +0530 | [diff] [blame] | 48 | |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame^] | 49 | |
| 50 | def run_tests(server_match, client_match, jobs, skip_known_failures): |
| 51 | logger = multiprocessing.get_logger() |
| 52 | logger.debug('Collecting tests') |
| 53 | with open(CONFIG_PATH, 'r') as fp: |
| 54 | j = json.load(fp) |
| 55 | tests = list(crossrunner.collect_tests(j, server_match, client_match)) |
| 56 | if skip_known_failures: |
| 57 | known = crossrunner.load_known_failures(TEST_DIR) |
| 58 | tests = list(filter(lambda t: crossrunner.test_name(**t) not in known, tests)) |
| 59 | |
| 60 | dispatcher = crossrunner.TestDispatcher(TEST_DIR, jobs) |
| 61 | logger.debug('Executing %d tests' % len(tests)) |
| 62 | try: |
| 63 | for r in [dispatcher.dispatch(test) for test in tests]: |
| 64 | r.wait() |
| 65 | logger.debug('Waiting for completion') |
| 66 | return dispatcher.wait() |
| 67 | except (KeyboardInterrupt, SystemExit): |
| 68 | logger.debug('Interrupted, shutting down') |
| 69 | dispatcher.terminate() |
| 70 | return False |
| 71 | |
| 72 | |
| 73 | def default_concurrenty(): |
| 74 | try: |
| 75 | return int(os.environ.get('THRIFT_CROSSTEST_CONCURRENCY')) |
| 76 | except (TypeError, ValueError): |
| 77 | # Since much time is spent sleeping, use many threads |
| 78 | return int(multiprocessing.cpu_count() * 1.25) + 1 |
| 79 | |
| 80 | |
| 81 | def main(argv): |
| 82 | parser = optparse.OptionParser() |
| 83 | parser.add_option('--server', type='string', dest='servers', default='', |
| 84 | help='list of servers to test separated by commas, eg:- --server=cpp,java') |
| 85 | parser.add_option('--client', type='string', dest='clients', default='', |
| 86 | help='list of clients to test separated by commas, eg:- --client=cpp,java') |
| 87 | parser.add_option('-s', '--skip-known-failures', action='store_true', dest='skip_known_failures', |
| 88 | help='do not execute tests that are known to fail') |
| 89 | parser.add_option('-j', '--jobs', type='int', dest='jobs', |
| 90 | default=default_concurrenty(), |
| 91 | help='number of concurrent test executions') |
| 92 | g = optparse.OptionGroup(parser, 'Advanced') |
| 93 | g.add_option('-v', '--verbose', action='store_const', |
| 94 | dest='log_level', const=logging.DEBUG, default=logging.WARNING, |
| 95 | help='show debug output for test runner') |
| 96 | g.add_option('-P', '--print-expected-failures', choices=['merge', 'overwrite'], |
| 97 | dest='print_failures', default=None, |
| 98 | help="generate expected failures based on last result and print to stdout") |
| 99 | g.add_option('-U', '--update-expected-failures', choices=['merge', 'overwrite'], |
| 100 | dest='update_failures', default=None, |
| 101 | help="generate expected failures based on last result and save to default file location") |
| 102 | g.add_option('--prepare', action='store_true', |
| 103 | dest='prepare', |
| 104 | help="try to prepare files needed for cross test (experimental)") |
| 105 | parser.add_option_group(g) |
| 106 | logger = multiprocessing.log_to_stderr() |
| 107 | options, _ = parser.parse_args(argv) |
| 108 | server_match = options.servers.split(',') if options.servers else [] |
| 109 | client_match = options.clients.split(',') if options.clients else [] |
| 110 | logger.setLevel(options.log_level) |
| 111 | |
| 112 | if options.prepare: |
| 113 | res = prepare(server_match, client_match) |
| 114 | elif options.update_failures or options.print_failures: |
| 115 | res = crossrunner.generate_known_failures( |
| 116 | TEST_DIR, options.update_failures == 'overwrite', |
| 117 | options.update_failures, options.print_failures) |
Roger Meier | e8bafb6 | 2014-08-01 23:39:32 +0200 | [diff] [blame] | 118 | else: |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame^] | 119 | res = run_tests(server_match, client_match, options.jobs, options.skip_known_failures) |
| 120 | return 0 if res else 1 |
Roger Meier | e8bafb6 | 2014-08-01 23:39:32 +0200 | [diff] [blame] | 121 | |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame^] | 122 | if __name__ == '__main__': |
| 123 | sys.exit(main(sys.argv[1:])) |