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 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 # while each list of TestRunResults contains all tries in a single | 734 # while each list of TestRunResults contains all tries in a single |
733 # iteration. | 735 # iteration. |
734 all_raw_results = [] | 736 all_raw_results = [] |
735 | 737 |
736 # all_iteration_results is a list of base_test_result.TestRunResults | 738 # all_iteration_results is a list of base_test_result.TestRunResults |
737 # objects. Each instance of TestRunResults contains the last test | 739 # objects. Each instance of TestRunResults contains the last test |
738 # result for each test run in that iteration. | 740 # result for each test run in that iteration. |
739 all_iteration_results = [] | 741 all_iteration_results = [] |
740 | 742 |
741 @contextlib.contextmanager | 743 @contextlib.contextmanager |
742 def noop(): | 744 def write_json_file(): |
743 yield | 745 try: |
| 746 yield |
| 747 finally: |
| 748 json_results.GenerateJsonResultsFile( |
| 749 all_raw_results, args.json_results_file) |
744 | 750 |
745 json_writer = noop() | 751 json_writer = contextlib_ext.Optional( |
746 if args.json_results_file: | 752 write_json_file(), |
747 @contextlib.contextmanager | 753 args.json_results_file) |
748 def write_json_file(): | |
749 try: | |
750 yield | |
751 finally: | |
752 json_results.GenerateJsonResultsFile( | |
753 all_raw_results, args.json_results_file) | |
754 | |
755 json_writer = write_json_file() | |
756 | 754 |
757 ### Set up test objects. | 755 ### Set up test objects. |
758 | 756 |
759 env = environment_factory.CreateEnvironment(args, infra_error) | 757 env = environment_factory.CreateEnvironment(args, infra_error) |
760 test_instance = test_instance_factory.CreateTestInstance(args, infra_error) | 758 test_instance = test_instance_factory.CreateTestInstance(args, infra_error) |
761 test_run = test_run_factory.CreateTestRun( | 759 test_run = test_run_factory.CreateTestRun( |
762 args, env, test_instance, infra_error) | 760 args, env, test_instance, infra_error) |
763 | 761 |
764 ### Run. | 762 ### Run. |
765 | 763 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 if e.is_infra_error: | 880 if e.is_infra_error: |
883 return constants.INFRA_EXIT_CODE | 881 return constants.INFRA_EXIT_CODE |
884 return constants.ERROR_EXIT_CODE | 882 return constants.ERROR_EXIT_CODE |
885 except: # pylint: disable=W0702 | 883 except: # pylint: disable=W0702 |
886 logging.exception('Unrecognized error occurred.') | 884 logging.exception('Unrecognized error occurred.') |
887 return constants.ERROR_EXIT_CODE | 885 return constants.ERROR_EXIT_CODE |
888 | 886 |
889 | 887 |
890 if __name__ == '__main__': | 888 if __name__ == '__main__': |
891 sys.exit(main()) | 889 sys.exit(main()) |
OLD | NEW |