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 21 matching lines...) Expand all Loading... |
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.results import json_results | 39 from pylib.results import json_results |
40 from pylib.results import report_results | 40 from pylib.results import report_results |
41 | 41 |
| 42 from py_utils import contextlib_ext |
| 43 |
42 | 44 |
43 _DEVIL_STATIC_CONFIG_FILE = os.path.abspath(os.path.join( | 45 _DEVIL_STATIC_CONFIG_FILE = os.path.abspath(os.path.join( |
44 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'devil_config.json')) | 46 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'devil_config.json')) |
45 | 47 |
46 | 48 |
47 def AddCommonOptions(parser): | 49 def AddCommonOptions(parser): |
48 """Adds all common options to |parser|.""" | 50 """Adds all common options to |parser|.""" |
49 | 51 |
50 group = parser.add_argument_group('Common Options') | 52 group = parser.add_argument_group('Common Options') |
51 | 53 |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 # while each list of TestRunResults contains all tries in a single | 740 # while each list of TestRunResults contains all tries in a single |
739 # iteration. | 741 # iteration. |
740 all_raw_results = [] | 742 all_raw_results = [] |
741 | 743 |
742 # all_iteration_results is a list of base_test_result.TestRunResults | 744 # all_iteration_results is a list of base_test_result.TestRunResults |
743 # objects. Each instance of TestRunResults contains the last test | 745 # objects. Each instance of TestRunResults contains the last test |
744 # result for each test run in that iteration. | 746 # result for each test run in that iteration. |
745 all_iteration_results = [] | 747 all_iteration_results = [] |
746 | 748 |
747 @contextlib.contextmanager | 749 @contextlib.contextmanager |
748 def noop(): | 750 def write_json_file(): |
749 yield | 751 try: |
| 752 yield |
| 753 finally: |
| 754 json_results.GenerateJsonResultsFile( |
| 755 all_raw_results, args.json_results_file) |
750 | 756 |
751 json_writer = noop() | 757 json_writer = contextlib_ext.Optional( |
752 if args.json_results_file: | 758 write_json_file(), |
753 @contextlib.contextmanager | 759 args.json_results_file) |
754 def write_json_file(): | |
755 try: | |
756 yield | |
757 finally: | |
758 json_results.GenerateJsonResultsFile( | |
759 all_raw_results, args.json_results_file) | |
760 | |
761 json_writer = write_json_file() | |
762 | 760 |
763 ### Set up test objects. | 761 ### Set up test objects. |
764 | 762 |
765 env = environment_factory.CreateEnvironment(args, infra_error) | 763 env = environment_factory.CreateEnvironment(args, infra_error) |
766 test_instance = test_instance_factory.CreateTestInstance(args, infra_error) | 764 test_instance = test_instance_factory.CreateTestInstance(args, infra_error) |
767 test_run = test_run_factory.CreateTestRun( | 765 test_run = test_run_factory.CreateTestRun( |
768 args, env, test_instance, infra_error) | 766 args, env, test_instance, infra_error) |
769 | 767 |
770 ### Run. | 768 ### Run. |
771 | 769 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 if e.is_infra_error: | 886 if e.is_infra_error: |
889 return constants.INFRA_EXIT_CODE | 887 return constants.INFRA_EXIT_CODE |
890 return constants.ERROR_EXIT_CODE | 888 return constants.ERROR_EXIT_CODE |
891 except: # pylint: disable=W0702 | 889 except: # pylint: disable=W0702 |
892 logging.exception('Unrecognized error occurred.') | 890 logging.exception('Unrecognized error occurred.') |
893 return constants.ERROR_EXIT_CODE | 891 return constants.ERROR_EXIT_CODE |
894 | 892 |
895 | 893 |
896 if __name__ == '__main__': | 894 if __name__ == '__main__': |
897 sys.exit(main()) | 895 sys.exit(main()) |
OLD | NEW |