| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Convenience script for expect_tests""" | 6 """Convenience script for expect_tests""" |
| 7 | 7 |
| 8 assert __name__ == '__main__' | 8 assert __name__ == '__main__' |
| 9 | 9 |
| 10 import itertools | 10 import itertools |
| 11 import os | 11 import os |
| 12 import subprocess | 12 import subprocess |
| 13 import sys | 13 import sys |
| 14 | 14 |
| 15 | 15 |
| 16 def usage(): | 16 def usage(): |
| 17 print """\nUsage: %s <action> [<expect_tests options>] [<test names>] | 17 print """\nUsage: %s <action> [<test names>] [<expect_tests options>] |
| 18 | 18 |
| 19 where <action> is one of: list, test, train, debug. | 19 where <action> is one of: list, test, train, debug. |
| 20 | 20 |
| 21 Examples: | 21 Examples: |
| 22 Run all tests: | 22 Run all tests: |
| 23 ./test.py test | 23 ./test.py test |
| 24 Run all tests in the infra package: | 24 Run all tests in the infra package: |
| 25 ./test.py test infra | 25 ./test.py test infra |
| 26 Run all tests and generate an HTML report: |
| 27 ./test.py test infra --html-report /path/to/report/folder |
| 26 Run one given test in the infra package: | 28 Run one given test in the infra package: |
| 27 ./test.py test infra/libs/git2/test:*testCommitBogus | 29 ./test.py test infra/libs/git2/test:*testCommitBogus |
| 28 | 30 |
| 29 See expect_tests documentation for more details | 31 See expect_tests documentation for more details |
| 30 """ % sys.argv[0] | 32 """ % sys.argv[0] |
| 31 sys.exit(1) | |
| 32 | 33 |
| 33 | 34 |
| 34 INFRA_ROOT = os.path.dirname(os.path.abspath(__file__)) | 35 INFRA_ROOT = os.path.dirname(os.path.abspath(__file__)) |
| 35 | 36 |
| 36 # Whitelist of packages to test on Windows. | 37 # Whitelist of packages to test on Windows. |
| 37 WIN_ENABLED_PACKAGES = [ | 38 WIN_ENABLED_PACKAGES = [ |
| 38 'infra/libs/buildbot', | 39 'infra/libs/buildbot', |
| 39 'infra/libs/decorators', | 40 'infra/libs/decorators', |
| 40 'infra/libs/gitiles', | 41 'infra/libs/gitiles', |
| 41 'infra/libs/process_invocation', | 42 'infra/libs/process_invocation', |
| 42 'infra/libs/service_utils', | 43 'infra/libs/service_utils', |
| 43 'infra/libs/state_machine', | 44 'infra/libs/state_machine', |
| 44 | 45 |
| 45 'infra/services/service_manager', | 46 'infra/services/service_manager', |
| 46 'infra/services/sysmon', | 47 'infra/services/sysmon', |
| 47 | 48 |
| 48 'infra_libs/event_mon', | 49 'infra_libs/event_mon', |
| 49 'infra_libs/infra_types', | 50 'infra_libs/infra_types', |
| 50 'infra_libs/logs', | 51 'infra_libs/logs', |
| 51 'infra_libs/time_functions', | 52 'infra_libs/time_functions', |
| 52 'infra_libs/ts_mon', | 53 'infra_libs/ts_mon', |
| 53 | 54 |
| 54 'infra_libs:infra_libs.test.*', | 55 'infra_libs:infra_libs.test.*', |
| 55 ] | 56 ] |
| 56 | 57 |
| 57 | 58 |
| 58 # Parse command-line arguments | 59 # Parse command-line arguments |
| 59 if len(sys.argv) == 1: | 60 if len(sys.argv) == 1: |
| 60 usage() | 61 usage() |
| 62 sys.exit(1) |
| 61 else: | 63 else: |
| 62 if not sys.argv[1] in ('list', 'train', 'test', 'debug'): | 64 if not sys.argv[1] in ('list', 'train', 'test', 'debug'): |
| 63 usage() | 65 usage() |
| 66 sys.exit(1) |
| 64 | 67 |
| 65 if sys.platform == 'win32': | 68 if sys.platform == 'win32': |
| 66 python_bin = os.path.join('ENV', 'Scripts', 'python') | 69 python_bin = os.path.join('ENV', 'Scripts', 'python') |
| 67 expect_tests_path = os.path.join('ENV', 'Scripts', 'expect_tests') | 70 expect_tests_path = os.path.join('ENV', 'Scripts', 'expect_tests') |
| 68 else: | 71 else: |
| 69 python_bin = os.path.join('ENV', 'bin', 'python') | 72 python_bin = os.path.join('ENV', 'bin', 'python') |
| 70 expect_tests_path = os.path.join('ENV', 'bin', 'expect_tests') | 73 expect_tests_path = os.path.join('ENV', 'bin', 'expect_tests') |
| 71 | 74 |
| 72 args = sys.argv[1:] | 75 command = sys.argv[1] |
| 76 args = sys.argv[2:] |
| 77 |
| 78 modules = [] |
| 79 flags = [] |
| 80 for arg in args: |
| 81 if arg.startswith('-'): |
| 82 flags.append(arg) |
| 83 continue |
| 84 if flags: |
| 85 flags.append(arg) |
| 86 else: |
| 87 modules.append(arg) |
| 73 | 88 |
| 74 # Set up default list of packages/directories if none have been provided. | 89 # Set up default list of packages/directories if none have been provided. |
| 75 if all([arg.startswith('--') for arg in sys.argv[2:]]): | 90 if not modules: |
| 76 if sys.platform == 'win32': | 91 if sys.platform == 'win32': |
| 77 args.extend(WIN_ENABLED_PACKAGES) | 92 modules.extend(WIN_ENABLED_PACKAGES) |
| 78 else: | 93 else: |
| 79 args.extend(['infra', 'infra_libs']) # TODO(pgervais): add 'test/' | 94 modules.extend(['infra', 'infra_libs']) # TODO(pgervais): add 'test/' |
| 80 appengine_dir = os.path.join(INFRA_ROOT, 'appengine') | 95 appengine_dir = os.path.join(INFRA_ROOT, 'appengine') |
| 81 if sys.platform != 'win32' and os.path.isdir(appengine_dir): | 96 if sys.platform != 'win32' and os.path.isdir(appengine_dir): |
| 82 args.extend(['appengine_module']) | 97 modules.extend(['appengine_module']) |
| 83 appengine_dirs = [ | 98 appengine_dirs = [ |
| 84 os.path.join('appengine', d) | 99 os.path.join('appengine', d) |
| 85 for d in os.listdir(appengine_dir) | 100 for d in os.listdir(appengine_dir) |
| 86 ] | 101 ] |
| 87 # Use relative paths to shorten the command-line | 102 # Use relative paths to shorten the command-line |
| 88 args.extend(itertools.chain( | 103 modules.extend(itertools.chain( |
| 89 [d for d in appengine_dirs if os.path.isfile(os.path.join(d, 'app.yaml'))] | 104 [d for d in appengine_dirs if os.path.isfile(os.path.join(d, 'app.yaml'))] |
| 90 )) | 105 )) |
| 91 | 106 |
| 92 os.environ['PYTHONPATH'] = '' | 107 os.environ['PYTHONPATH'] = '' |
| 93 os.chdir(INFRA_ROOT) | 108 os.chdir(INFRA_ROOT) |
| 94 if '--help' not in sys.argv and '-h' not in sys.argv: | 109 if '--help' not in flags and '-h' not in flags: |
| 95 subprocess.check_call( | 110 subprocess.check_call( |
| 96 [python_bin, os.path.join('bootstrap', 'remove_orphaned_pycs.py')]) | 111 [python_bin, os.path.join('bootstrap', 'remove_orphaned_pycs.py')]) |
| 97 if sys.platform == 'win32' and '--force-coverage' not in args: | 112 else: |
| 98 args.append('--no-coverage') | 113 usage() |
| 99 sys.exit(subprocess.call([python_bin, expect_tests_path] + args)) | 114 sys.exit(subprocess.call([python_bin, expect_tests_path, command, '--help'])) |
| 115 |
| 116 if sys.platform == 'win32' and '--force-coverage' not in flags: |
| 117 flags.append('--no-coverage') |
| 118 |
| 119 exit_code = 0 |
| 120 failed_modules = [] |
| 121 for module in modules: |
| 122 print 'Running %s...' % module |
| 123 module_flags = flags[:] |
| 124 module_flags.append('--coveragerc=%s' % os.path.join( |
| 125 INFRA_ROOT, module, '.coveragerc')) |
| 126 module_flags.append('--html-report-subdir=%s' % module) |
| 127 cmd = [python_bin, expect_tests_path, command, module] + module_flags |
| 128 module_exit_code = subprocess.call(cmd) |
| 129 exit_code = module_exit_code or exit_code |
| 130 if module_exit_code: |
| 131 failed_modules.append(module) |
| 132 |
| 133 if exit_code: |
| 134 print 'Tests failed in modules:\n %s' % '\n '.join(failed_modules) |
| 135 else: |
| 136 print 'All tests passed.' |
| 137 |
| 138 sys.exit(exit_code) |
| OLD | NEW |