| 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 argparse | 9 import argparse |
| 10 import collections | 10 import collections |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 from devil.utils import signal_handler | 29 from devil.utils import signal_handler |
| 30 | 30 |
| 31 from pylib import constants | 31 from pylib import constants |
| 32 from pylib.base import base_test_result | 32 from pylib.base import base_test_result |
| 33 from pylib.base import environment_factory | 33 from pylib.base import environment_factory |
| 34 from pylib.base import test_dispatcher | 34 from pylib.base import test_dispatcher |
| 35 from pylib.base import test_instance_factory | 35 from pylib.base import test_instance_factory |
| 36 from pylib.base import test_run_factory | 36 from pylib.base import test_run_factory |
| 37 from pylib.constants import host_paths | 37 from pylib.constants import host_paths |
| 38 from pylib.linker import setup as linker_setup | 38 from pylib.linker import setup as linker_setup |
| 39 from pylib.junit import setup as junit_setup | |
| 40 from pylib.junit import test_dispatcher as junit_dispatcher | |
| 41 from pylib.results import json_results | 39 from pylib.results import json_results |
| 42 from pylib.results import report_results | 40 from pylib.results import report_results |
| 43 | 41 |
| 44 | 42 |
| 45 _DEVIL_STATIC_CONFIG_FILE = os.path.abspath(os.path.join( | 43 _DEVIL_STATIC_CONFIG_FILE = os.path.abspath(os.path.join( |
| 46 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'devil_config.json')) | 44 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'devil_config.json')) |
| 47 | 45 |
| 48 | 46 |
| 49 def AddCommonOptions(parser): | 47 def AddCommonOptions(parser): |
| 50 """Adds all common options to |parser|.""" | 48 """Adds all common options to |parser|.""" |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 results=results, | 570 results=results, |
| 573 test_type='Linker test', | 571 test_type='Linker test', |
| 574 test_package='ChromiumLinkerTest') | 572 test_package='ChromiumLinkerTest') |
| 575 | 573 |
| 576 if args.json_results_file: | 574 if args.json_results_file: |
| 577 json_results.GenerateJsonResultsFile([results], args.json_results_file) | 575 json_results.GenerateJsonResultsFile([results], args.json_results_file) |
| 578 | 576 |
| 579 return exit_code | 577 return exit_code |
| 580 | 578 |
| 581 | 579 |
| 582 def _RunJUnitTests(args): | |
| 583 """Subcommand of RunTestsCommand which runs junit tests.""" | |
| 584 runner_factory, tests = junit_setup.Setup(args) | |
| 585 results, exit_code = junit_dispatcher.RunTests(tests, runner_factory) | |
| 586 | |
| 587 report_results.LogFull( | |
| 588 results=results, | |
| 589 test_type='JUnit', | |
| 590 test_package=args.test_suite) | |
| 591 | |
| 592 if args.json_results_file: | |
| 593 json_results.GenerateJsonResultsFile([results], args.json_results_file) | |
| 594 | |
| 595 return exit_code | |
| 596 | |
| 597 | |
| 598 def _RunPythonTests(args): | 580 def _RunPythonTests(args): |
| 599 """Subcommand of RunTestsCommand which runs python unit tests.""" | 581 """Subcommand of RunTestsCommand which runs python unit tests.""" |
| 600 suite_vars = constants.PYTHON_UNIT_TEST_SUITES[args.suite_name] | 582 suite_vars = constants.PYTHON_UNIT_TEST_SUITES[args.suite_name] |
| 601 suite_path = suite_vars['path'] | 583 suite_path = suite_vars['path'] |
| 602 suite_test_modules = suite_vars['test_modules'] | 584 suite_test_modules = suite_vars['test_modules'] |
| 603 | 585 |
| 604 sys.path = [suite_path] + sys.path | 586 sys.path = [suite_path] + sys.path |
| 605 try: | 587 try: |
| 606 suite = unittest.TestSuite() | 588 suite = unittest.TestSuite() |
| 607 suite.addTests(unittest.defaultTestLoader.loadTestsFromName(m) | 589 suite.addTests(unittest.defaultTestLoader.loadTestsFromName(m) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 637 'Did not find device %s among attached device. Attached devices: %s' | 619 'Did not find device %s among attached device. Attached devices: %s' |
| 638 % (test_device, ', '.join(attached_devices))) | 620 % (test_device, ', '.join(attached_devices))) |
| 639 return test_device | 621 return test_device |
| 640 | 622 |
| 641 else: | 623 else: |
| 642 if not attached_devices: | 624 if not attached_devices: |
| 643 raise device_errors.NoDevicesError() | 625 raise device_errors.NoDevicesError() |
| 644 return sorted(attached_devices) | 626 return sorted(attached_devices) |
| 645 | 627 |
| 646 | 628 |
| 647 _DEFAULT_PLATFORM_MODE_TESTS = ['gtest', 'instrumentation', 'monkey', 'perf'] | 629 _DEFAULT_PLATFORM_MODE_TESTS = ['gtest', 'instrumentation', 'junit', |
| 630 'monkey', 'perf'] |
| 648 | 631 |
| 649 | 632 |
| 650 def RunTestsCommand(args): # pylint: disable=too-many-return-statements | 633 def RunTestsCommand(args): # pylint: disable=too-many-return-statements |
| 651 """Checks test type and dispatches to the appropriate function. | 634 """Checks test type and dispatches to the appropriate function. |
| 652 | 635 |
| 653 Args: | 636 Args: |
| 654 args: argparse.Namespace object. | 637 args: argparse.Namespace object. |
| 655 | 638 |
| 656 Returns: | 639 Returns: |
| 657 Integer indicated exit code. | 640 Integer indicated exit code. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 675 if os.path.exists(ports._TEST_SERVER_PORT_LOCKFILE): | 658 if os.path.exists(ports._TEST_SERVER_PORT_LOCKFILE): |
| 676 os.unlink(ports._TEST_SERVER_PORT_LOCKFILE) | 659 os.unlink(ports._TEST_SERVER_PORT_LOCKFILE) |
| 677 # pylint: enable=protected-access | 660 # pylint: enable=protected-access |
| 678 | 661 |
| 679 def get_devices(): | 662 def get_devices(): |
| 680 return _GetAttachedDevices(args.blacklist_file, args.test_device, | 663 return _GetAttachedDevices(args.blacklist_file, args.test_device, |
| 681 args.enable_device_cache, args.num_retries) | 664 args.enable_device_cache, args.num_retries) |
| 682 | 665 |
| 683 if command == 'linker': | 666 if command == 'linker': |
| 684 return _RunLinkerTests(args, get_devices()) | 667 return _RunLinkerTests(args, get_devices()) |
| 685 elif command == 'junit': | |
| 686 return _RunJUnitTests(args) | |
| 687 elif command == 'python': | 668 elif command == 'python': |
| 688 return _RunPythonTests(args) | 669 return _RunPythonTests(args) |
| 689 else: | 670 else: |
| 690 raise Exception('Unknown test type.') | 671 raise Exception('Unknown test type.') |
| 691 | 672 |
| 692 | 673 |
| 693 _SUPPORTED_IN_PLATFORM_MODE = [ | 674 _SUPPORTED_IN_PLATFORM_MODE = [ |
| 694 # TODO(jbudorick): Add support for more test types. | 675 # TODO(jbudorick): Add support for more test types. |
| 695 'gtest', | 676 'gtest', |
| 696 'instrumentation', | 677 'instrumentation', |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 if e.is_infra_error: | 857 if e.is_infra_error: |
| 877 return constants.INFRA_EXIT_CODE | 858 return constants.INFRA_EXIT_CODE |
| 878 return constants.ERROR_EXIT_CODE | 859 return constants.ERROR_EXIT_CODE |
| 879 except: # pylint: disable=W0702 | 860 except: # pylint: disable=W0702 |
| 880 logging.exception('Unrecognized error occurred.') | 861 logging.exception('Unrecognized error occurred.') |
| 881 return constants.ERROR_EXIT_CODE | 862 return constants.ERROR_EXIT_CODE |
| 882 | 863 |
| 883 | 864 |
| 884 if __name__ == '__main__': | 865 if __name__ == '__main__': |
| 885 sys.exit(main()) | 866 sys.exit(main()) |
| OLD | NEW |