OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Runs all types of tests from one unified interface.""" | 7 """Runs all types of tests from one unified interface.""" |
8 | 8 |
9 import collections | 9 import collections |
10 import logging | 10 import logging |
(...skipping 10 matching lines...) Expand all Loading... |
21 from pylib import ports | 21 from pylib import ports |
22 from pylib.base import base_test_result | 22 from pylib.base import base_test_result |
23 from pylib.base import test_dispatcher | 23 from pylib.base import test_dispatcher |
24 from pylib.gtest import gtest_config | 24 from pylib.gtest import gtest_config |
25 from pylib.gtest import setup as gtest_setup | 25 from pylib.gtest import setup as gtest_setup |
26 from pylib.gtest import test_options as gtest_test_options | 26 from pylib.gtest import test_options as gtest_test_options |
27 from pylib.linker import setup as linker_setup | 27 from pylib.linker import setup as linker_setup |
28 from pylib.host_driven import setup as host_driven_setup | 28 from pylib.host_driven import setup as host_driven_setup |
29 from pylib.instrumentation import setup as instrumentation_setup | 29 from pylib.instrumentation import setup as instrumentation_setup |
30 from pylib.instrumentation import test_options as instrumentation_test_options | 30 from pylib.instrumentation import test_options as instrumentation_test_options |
| 31 from pylib.junit import setup as junit_setup |
| 32 from pylib.junit import test_dispatcher as junit_dispatcher |
31 from pylib.monkey import setup as monkey_setup | 33 from pylib.monkey import setup as monkey_setup |
32 from pylib.monkey import test_options as monkey_test_options | 34 from pylib.monkey import test_options as monkey_test_options |
33 from pylib.perf import setup as perf_setup | 35 from pylib.perf import setup as perf_setup |
34 from pylib.perf import test_options as perf_test_options | 36 from pylib.perf import test_options as perf_test_options |
35 from pylib.perf import test_runner as perf_test_runner | 37 from pylib.perf import test_runner as perf_test_runner |
36 from pylib.uiautomator import setup as uiautomator_setup | 38 from pylib.uiautomator import setup as uiautomator_setup |
37 from pylib.uiautomator import test_options as uiautomator_test_options | 39 from pylib.uiautomator import test_options as uiautomator_test_options |
38 from pylib.utils import apk_helper | 40 from pylib.utils import apk_helper |
39 from pylib.utils import command_option_parser | 41 from pylib.utils import command_option_parser |
40 from pylib.utils import report_results | 42 from pylib.utils import report_results |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 options.exclude_annotations, | 374 options.exclude_annotations, |
373 options.test_filter, | 375 options.test_filter, |
374 options.test_data, | 376 options.test_data, |
375 options.save_perf_json, | 377 options.save_perf_json, |
376 options.screenshot_failures, | 378 options.screenshot_failures, |
377 options.uiautomator_jar, | 379 options.uiautomator_jar, |
378 options.uiautomator_info_jar, | 380 options.uiautomator_info_jar, |
379 options.package) | 381 options.package) |
380 | 382 |
381 | 383 |
| 384 def AddJUnitTestOptions(option_parser): |
| 385 """Adds junit test options to |option_parser|.""" |
| 386 option_parser.usage = '%prog junit -s [test suite name]' |
| 387 option_parser.commands_dict = {} |
| 388 |
| 389 option_parser.add_option( |
| 390 '-s', '--test-suite', dest='test_suite', |
| 391 help=('JUnit test suite to run.')) |
| 392 option_parser.add_option( |
| 393 '-f', '--test-filter', dest='test_filter', |
| 394 help='Filters tests googletest-style.') |
| 395 option_parser.add_option( |
| 396 '--package-filter', dest='package_filter', |
| 397 help='Filters tests by package.') |
| 398 option_parser.add_option( |
| 399 '--runner-filter', dest='runner_filter', |
| 400 help='Filters tests by runner class. Must be fully qualified.') |
| 401 option_parser.add_option( |
| 402 '--sdk-version', dest='sdk_version', type="int", |
| 403 help='The Android SDK version.') |
| 404 AddCommonOptions(option_parser) |
| 405 |
| 406 |
| 407 def ProcessJUnitTestOptions(options, error_func): |
| 408 """Processes all JUnit test options.""" |
| 409 if not options.test_suite: |
| 410 error_func('No test suite specified.') |
| 411 return options |
| 412 |
| 413 |
382 def AddMonkeyTestOptions(option_parser): | 414 def AddMonkeyTestOptions(option_parser): |
383 """Adds monkey test options to |option_parser|.""" | 415 """Adds monkey test options to |option_parser|.""" |
384 | 416 |
385 option_parser.usage = '%prog monkey [options]' | 417 option_parser.usage = '%prog monkey [options]' |
386 option_parser.commands_dict = {} | 418 option_parser.commands_dict = {} |
387 option_parser.example = ( | 419 option_parser.example = ( |
388 '%prog monkey --package=chrome_shell') | 420 '%prog monkey --package=chrome_shell') |
389 | 421 |
390 option_parser.add_option( | 422 option_parser.add_option( |
391 '--package', | 423 '--package', |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 report_results.LogFull( | 660 report_results.LogFull( |
629 results=results, | 661 results=results, |
630 test_type='UIAutomator', | 662 test_type='UIAutomator', |
631 test_package=os.path.basename(options.test_jar), | 663 test_package=os.path.basename(options.test_jar), |
632 annotation=options.annotations, | 664 annotation=options.annotations, |
633 flakiness_server=options.flakiness_dashboard_server) | 665 flakiness_server=options.flakiness_dashboard_server) |
634 | 666 |
635 return exit_code | 667 return exit_code |
636 | 668 |
637 | 669 |
| 670 def _RunJUnitTests(options, error_func): |
| 671 """Subcommand of RunTestsCommand which runs junit tests.""" |
| 672 junit_options = ProcessJUnitTestOptions(options, error_func) |
| 673 runner_factory, tests = junit_setup.Setup(junit_options) |
| 674 _, exit_code = junit_dispatcher.RunTests(tests, runner_factory) |
| 675 |
| 676 return exit_code |
| 677 |
| 678 |
638 def _RunMonkeyTests(options, error_func, devices): | 679 def _RunMonkeyTests(options, error_func, devices): |
639 """Subcommand of RunTestsCommands which runs monkey tests.""" | 680 """Subcommand of RunTestsCommands which runs monkey tests.""" |
640 monkey_options = ProcessMonkeyTestOptions(options, error_func) | 681 monkey_options = ProcessMonkeyTestOptions(options, error_func) |
641 | 682 |
642 runner_factory, tests = monkey_setup.Setup(monkey_options) | 683 runner_factory, tests = monkey_setup.Setup(monkey_options) |
643 | 684 |
644 results, exit_code = test_dispatcher.RunTests( | 685 results, exit_code = test_dispatcher.RunTests( |
645 tests, runner_factory, devices, shard=False, test_timeout=None, | 686 tests, runner_factory, devices, shard=False, test_timeout=None, |
646 num_retries=options.num_retries) | 687 num_retries=options.num_retries) |
647 | 688 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 raise Exception('Failed to reset test server port.') | 792 raise Exception('Failed to reset test server port.') |
752 | 793 |
753 if command == 'gtest': | 794 if command == 'gtest': |
754 return _RunGTests(options, devices) | 795 return _RunGTests(options, devices) |
755 elif command == 'linker': | 796 elif command == 'linker': |
756 return _RunLinkerTests(options, devices) | 797 return _RunLinkerTests(options, devices) |
757 elif command == 'instrumentation': | 798 elif command == 'instrumentation': |
758 return _RunInstrumentationTests(options, option_parser.error, devices) | 799 return _RunInstrumentationTests(options, option_parser.error, devices) |
759 elif command == 'uiautomator': | 800 elif command == 'uiautomator': |
760 return _RunUIAutomatorTests(options, option_parser.error, devices) | 801 return _RunUIAutomatorTests(options, option_parser.error, devices) |
| 802 elif command == 'junit': |
| 803 return _RunJUnitTests(options, option_parser.error) |
761 elif command == 'monkey': | 804 elif command == 'monkey': |
762 return _RunMonkeyTests(options, option_parser.error, devices) | 805 return _RunMonkeyTests(options, option_parser.error, devices) |
763 elif command == 'perf': | 806 elif command == 'perf': |
764 return _RunPerfTests(options, args, option_parser.error) | 807 return _RunPerfTests(options, args, option_parser.error) |
765 else: | 808 else: |
766 raise Exception('Unknown test type.') | 809 raise Exception('Unknown test type.') |
767 | 810 |
768 | 811 |
769 def HelpCommand(command, _options, args, option_parser): | 812 def HelpCommand(command, _options, args, option_parser): |
770 """Display help for a certain command, or overall help. | 813 """Display help for a certain command, or overall help. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 # syntax is a bit prettier. The tuple is two functions: (add options, run | 854 # syntax is a bit prettier. The tuple is two functions: (add options, run |
812 # command). | 855 # command). |
813 CommandFunctionTuple = collections.namedtuple( | 856 CommandFunctionTuple = collections.namedtuple( |
814 'CommandFunctionTuple', ['add_options_func', 'run_command_func']) | 857 'CommandFunctionTuple', ['add_options_func', 'run_command_func']) |
815 VALID_COMMANDS = { | 858 VALID_COMMANDS = { |
816 'gtest': CommandFunctionTuple(AddGTestOptions, RunTestsCommand), | 859 'gtest': CommandFunctionTuple(AddGTestOptions, RunTestsCommand), |
817 'instrumentation': CommandFunctionTuple( | 860 'instrumentation': CommandFunctionTuple( |
818 AddInstrumentationTestOptions, RunTestsCommand), | 861 AddInstrumentationTestOptions, RunTestsCommand), |
819 'uiautomator': CommandFunctionTuple( | 862 'uiautomator': CommandFunctionTuple( |
820 AddUIAutomatorTestOptions, RunTestsCommand), | 863 AddUIAutomatorTestOptions, RunTestsCommand), |
| 864 'junit': CommandFunctionTuple( |
| 865 AddJUnitTestOptions, RunTestsCommand), |
821 'monkey': CommandFunctionTuple( | 866 'monkey': CommandFunctionTuple( |
822 AddMonkeyTestOptions, RunTestsCommand), | 867 AddMonkeyTestOptions, RunTestsCommand), |
823 'perf': CommandFunctionTuple( | 868 'perf': CommandFunctionTuple( |
824 AddPerfTestOptions, RunTestsCommand), | 869 AddPerfTestOptions, RunTestsCommand), |
825 'linker': CommandFunctionTuple( | 870 'linker': CommandFunctionTuple( |
826 AddLinkerTestOptions, RunTestsCommand), | 871 AddLinkerTestOptions, RunTestsCommand), |
827 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand) | 872 'help': CommandFunctionTuple(lambda option_parser: None, HelpCommand) |
828 } | 873 } |
829 | 874 |
830 | 875 |
831 def DumpThreadStacks(_signal, _frame): | 876 def DumpThreadStacks(_signal, _frame): |
832 for thread in threading.enumerate(): | 877 for thread in threading.enumerate(): |
833 reraiser_thread.LogThreadStack(thread) | 878 reraiser_thread.LogThreadStack(thread) |
834 | 879 |
835 | 880 |
836 def main(): | 881 def main(): |
837 signal.signal(signal.SIGUSR1, DumpThreadStacks) | 882 signal.signal(signal.SIGUSR1, DumpThreadStacks) |
838 option_parser = command_option_parser.CommandOptionParser( | 883 option_parser = command_option_parser.CommandOptionParser( |
839 commands_dict=VALID_COMMANDS) | 884 commands_dict=VALID_COMMANDS) |
840 return command_option_parser.ParseAndExecute(option_parser) | 885 return command_option_parser.ParseAndExecute(option_parser) |
841 | 886 |
842 | 887 |
843 if __name__ == '__main__': | 888 if __name__ == '__main__': |
844 sys.exit(main()) | 889 sys.exit(main()) |
OLD | NEW |