| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Runs each test cases as a single shard, single process execution. | 6 """Runs each test cases as a single shard, single process execution. |
| 7 | 7 |
| 8 Similar to sharding_supervisor.py but finer grained. Runs multiple instances in | 8 Similar to sharding_supervisor.py but finer grained. Runs multiple instances in |
| 9 parallel. | 9 parallel. |
| 10 """ | 10 """ |
| (...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 options.whitelist, options.blacklist = options.gtest_filter.split('-', | 805 options.whitelist, options.blacklist = options.gtest_filter.split('-', |
| 806 1) | 806 1) |
| 807 else: | 807 else: |
| 808 options.whitelist = options.gtest_filter | 808 options.whitelist = options.gtest_filter |
| 809 options.blacklist = '' | 809 options.blacklist = '' |
| 810 options.whitelist = [i for i in options.whitelist.split(':') if i] | 810 options.whitelist = [i for i in options.whitelist.split(':') if i] |
| 811 options.blacklist = [i for i in options.blacklist.split(':') if i] | 811 options.blacklist = [i for i in options.blacklist.split(':') if i] |
| 812 | 812 |
| 813 return options, args | 813 return options, args |
| 814 | 814 |
| 815 @staticmethod |
| 816 def process_gtest_options(executable, options): |
| 817 """Grabs the test cases.""" |
| 818 if options.test_case_file: |
| 819 with open(options.test_case_file, 'r') as f: |
| 820 return sorted(filter(None, f.read().splitlines())) |
| 821 else: |
| 822 return get_test_cases( |
| 823 executable, |
| 824 options.whitelist, |
| 825 options.blacklist, |
| 826 options.index, |
| 827 options.shards) |
| 828 |
| 829 |
| 830 class OptionParserTestCases(OptionParserWithTestShardingAndFiltering): |
| 831 def __init__(self, *args, **kwargs): |
| 832 OptionParserWithTestShardingAndFiltering.__init__(self, *args, **kwargs) |
| 833 self.add_option( |
| 834 '-j', '--jobs', |
| 835 type='int', |
| 836 default=num_processors(), |
| 837 help='number of parallel jobs; default=%default') |
| 838 self.add_option( |
| 839 '-t', '--timeout', |
| 840 type='int', |
| 841 default=120, |
| 842 help='Timeout for a single test case, in seconds default:%default') |
| 843 |
| 815 | 844 |
| 816 def main(argv): | 845 def main(argv): |
| 817 """CLI frontend to validate arguments.""" | 846 """CLI frontend to validate arguments.""" |
| 818 parser = OptionParserWithTestShardingAndFiltering( | 847 parser = OptionParserTestCases( |
| 819 usage='%prog <options> [gtest]', | 848 usage='%prog <options> [gtest]', |
| 820 verbose=int(os.environ.get('ISOLATE_DEBUG', 0))) | 849 verbose=int(os.environ.get('ISOLATE_DEBUG', 0))) |
| 821 parser.add_option( | 850 parser.add_option( |
| 822 '-j', '--jobs', | |
| 823 type='int', | |
| 824 default=num_processors(), | |
| 825 help='number of parallel jobs; default=%default') | |
| 826 parser.add_option( | |
| 827 '-t', '--timeout', | |
| 828 type='int', | |
| 829 default=120, | |
| 830 help='Timeout for a single test case, in seconds default:%default') | |
| 831 parser.add_option( | |
| 832 '--run-all', | 851 '--run-all', |
| 833 action='store_true', | 852 action='store_true', |
| 834 default=bool(int(os.environ.get('RUN_TEST_CASES_RUN_ALL', '0'))), | 853 default=bool(int(os.environ.get('RUN_TEST_CASES_RUN_ALL', '0'))), |
| 835 help='Do not fail early when a large number of test cases fail') | 854 help='Do not fail early when a large number of test cases fail') |
| 836 parser.add_option( | 855 parser.add_option( |
| 837 '--no-dump', | 856 '--no-dump', |
| 838 action='store_true', | 857 action='store_true', |
| 839 help='do not generate a .run_test_cases file') | 858 help='do not generate a .run_test_cases file') |
| 840 parser.add_option( | 859 parser.add_option( |
| 841 '--result', | 860 '--result', |
| 842 default=os.environ.get('RUN_TEST_CASES_RESULT_FILE', ''), | 861 default=os.environ.get('RUN_TEST_CASES_RESULT_FILE', ''), |
| 843 help='Override the default name of the generated .run_test_cases file') | 862 help='Override the default name of the generated .run_test_cases file') |
| 844 options, args = parser.parse_args(argv) | 863 options, args = parser.parse_args(argv) |
| 845 | 864 |
| 846 if len(args) != 1: | 865 if len(args) != 1: |
| 847 parser.error( | 866 parser.error( |
| 848 'Please provide the executable line to run, if you need fancy things ' | 867 'Please provide the executable line to run, if you need fancy things ' |
| 849 'like xvfb, start this script from *inside* xvfb, it\'ll be much faster' | 868 'like xvfb, start this script from *inside* xvfb, it\'ll be much faster' |
| 850 '.') | 869 '.') |
| 851 | 870 |
| 852 executable = args[0] | 871 executable = args[0] |
| 853 if not os.path.isabs(executable): | 872 if not os.path.isabs(executable): |
| 854 executable = os.path.abspath(executable) | 873 executable = os.path.abspath(executable) |
| 855 if sys.platform in ('cygwin', 'win32'): | 874 if sys.platform in ('cygwin', 'win32'): |
| 856 if not os.path.splitext(executable)[1]: | 875 if not os.path.splitext(executable)[1]: |
| 857 executable += '.exe' | 876 executable += '.exe' |
| 858 if not os.path.isfile(executable): | 877 if not os.path.isfile(executable): |
| 859 parser.error('"%s" doesn\'t exist.' % executable) | 878 parser.error('"%s" doesn\'t exist.' % executable) |
| 860 | 879 |
| 861 # Grab the test cases. | 880 test_cases = parser.process_gtest_options(executable, options) |
| 862 if options.test_case_file: | |
| 863 with open(options.test_case_file, 'r') as f: | |
| 864 test_cases = filter(None, f.read().splitlines()) | |
| 865 else: | |
| 866 test_cases = get_test_cases( | |
| 867 executable, | |
| 868 options.whitelist, | |
| 869 options.blacklist, | |
| 870 options.index, | |
| 871 options.shards) | |
| 872 | |
| 873 if not test_cases: | 881 if not test_cases: |
| 874 # If test_cases is None then there was a problem generating the tests to | 882 # If test_cases is None then there was a problem generating the tests to |
| 875 # run, so this should be considered a failure. | 883 # run, so this should be considered a failure. |
| 876 return int(test_cases is None) | 884 return int(test_cases is None) |
| 877 | 885 |
| 878 if options.no_dump: | 886 if options.no_dump: |
| 879 result_file = None | 887 result_file = None |
| 880 else: | 888 else: |
| 881 if options.result: | 889 if options.result: |
| 882 result_file = options.result | 890 result_file = options.result |
| 883 else: | 891 else: |
| 884 result_file = '%s.run_test_cases' % executable | 892 result_file = '%s.run_test_cases' % executable |
| 885 | 893 |
| 886 return run_test_cases( | 894 return run_test_cases( |
| 887 executable, | 895 executable, |
| 888 test_cases, | 896 test_cases, |
| 889 options.jobs, | 897 options.jobs, |
| 890 options.timeout, | 898 options.timeout, |
| 891 options.run_all, | 899 options.run_all, |
| 892 result_file) | 900 result_file) |
| 893 | 901 |
| 894 | 902 |
| 895 if __name__ == '__main__': | 903 if __name__ == '__main__': |
| 896 sys.exit(main(sys.argv[1:])) | 904 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |