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 |
11 import contextlib | 11 import contextlib |
12 import itertools | 12 import itertools |
13 import logging | 13 import logging |
14 import os | 14 import os |
15 import shutil | |
16 import signal | 15 import signal |
17 import sys | 16 import sys |
18 import threading | 17 import threading |
19 import traceback | 18 import traceback |
20 import unittest | 19 import unittest |
21 | 20 |
22 from pylib.constants import host_paths | 21 from pylib.constants import host_paths |
23 | 22 |
24 if host_paths.DEVIL_PATH not in sys.path: | 23 if host_paths.DEVIL_PATH not in sys.path: |
25 sys.path.append(host_paths.DEVIL_PATH) | 24 sys.path.append(host_paths.DEVIL_PATH) |
26 | 25 |
27 from devil import base_error | 26 from devil import base_error |
28 from devil.utils import reraiser_thread | 27 from devil.utils import reraiser_thread |
29 from devil.utils import run_tests_helper | 28 from devil.utils import run_tests_helper |
30 | 29 |
31 from pylib import constants | 30 from pylib import constants |
32 from pylib.base import base_test_result | 31 from pylib.base import base_test_result |
33 from pylib.base import environment_factory | 32 from pylib.base import environment_factory |
34 from pylib.base import test_instance_factory | 33 from pylib.base import test_instance_factory |
35 from pylib.base import test_run_factory | 34 from pylib.base import test_run_factory |
36 from pylib.results import json_results | 35 from pylib.results import json_results |
37 from pylib.results import report_results | 36 from pylib.results import report_results |
38 from pylib.utils import logdog_helper | |
39 | 37 |
40 from py_utils import contextlib_ext | 38 from py_utils import contextlib_ext |
41 | 39 |
42 | 40 |
43 _DEVIL_STATIC_CONFIG_FILE = os.path.abspath(os.path.join( | 41 _DEVIL_STATIC_CONFIG_FILE = os.path.abspath(os.path.join( |
44 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'devil_config.json')) | 42 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'devil_config.json')) |
45 | 43 |
46 | 44 |
47 def AddTestLauncherArgs(parser): | 45 def AddTestLauncherArgs(parser): |
48 """Adds arguments mirroring //base/test/launcher. | 46 """Adds arguments mirroring //base/test/launcher. |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 type=os.path.realpath, | 201 type=os.path.realpath, |
204 help='Path to file with json list of device serials to ' | 202 help='Path to file with json list of device serials to ' |
205 'run tests on. When not specified, all available ' | 203 'run tests on. When not specified, all available ' |
206 'devices are used.') | 204 'devices are used.') |
207 parser.add_argument( | 205 parser.add_argument( |
208 '--tool', | 206 '--tool', |
209 dest='tool', | 207 dest='tool', |
210 help='Run the test under a tool ' | 208 help='Run the test under a tool ' |
211 '(use --tool help to list them)') | 209 '(use --tool help to list them)') |
212 | 210 |
213 parser.add_argument( | |
214 '--upload-logcats-file', | |
215 action='store_true', | |
216 dest='upload_logcats_file', | |
217 help='Whether to upload logcat file to logdog.') | |
218 | |
219 logcat_output_group = parser.add_mutually_exclusive_group() | 211 logcat_output_group = parser.add_mutually_exclusive_group() |
220 logcat_output_group.add_argument( | 212 logcat_output_group.add_argument( |
221 '--logcat-output-dir', type=os.path.realpath, | 213 '--logcat-output-dir', type=os.path.realpath, |
222 help='If set, will dump logcats recorded during test run to directory. ' | 214 help='If set, will dump logcats recorded during test run to directory. ' |
223 'File names will be the device ids with timestamps.') | 215 'File names will be the device ids with timestamps.') |
224 logcat_output_group.add_argument( | 216 logcat_output_group.add_argument( |
225 '--logcat-output-file', type=os.path.realpath, | 217 '--logcat-output-file', type=os.path.realpath, |
226 help='If set, will merge logcats recorded during test run and dump them ' | 218 help='If set, will merge logcats recorded during test run and dump them ' |
227 'to the specified file.') | 219 'to the specified file.') |
228 | 220 |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 try: | 718 try: |
727 yield | 719 yield |
728 finally: | 720 finally: |
729 json_results.GenerateJsonResultsFile( | 721 json_results.GenerateJsonResultsFile( |
730 all_raw_results, args.json_results_file) | 722 all_raw_results, args.json_results_file) |
731 | 723 |
732 json_writer = contextlib_ext.Optional( | 724 json_writer = contextlib_ext.Optional( |
733 write_json_file(), | 725 write_json_file(), |
734 args.json_results_file) | 726 args.json_results_file) |
735 | 727 |
736 @contextlib.contextmanager | |
737 def upload_logcats_file(): | |
738 try: | |
739 yield | |
740 finally: | |
741 if not args.logcat_output_file: | |
742 logging.critical('Cannot upload logcats file. ' | |
743 'File to save logcat is not specified.') | |
744 else: | |
745 with open(args.logcat_output_file) as src: | |
746 dst = logdog_helper.open_text('unified_logcats') | |
747 if dst: | |
748 shutil.copyfileobj(src, dst) | |
749 | |
750 logcats_uploader = contextlib_ext.Optional( | |
751 upload_logcats_file(), | |
752 'upload_logcats_file' in args and args.upload_logcats_file) | |
753 | |
754 ### Set up test objects. | 728 ### Set up test objects. |
755 | 729 |
756 env = environment_factory.CreateEnvironment(args, infra_error) | 730 env = environment_factory.CreateEnvironment(args, infra_error) |
757 test_instance = test_instance_factory.CreateTestInstance(args, infra_error) | 731 test_instance = test_instance_factory.CreateTestInstance(args, infra_error) |
758 test_run = test_run_factory.CreateTestRun( | 732 test_run = test_run_factory.CreateTestRun( |
759 args, env, test_instance, infra_error) | 733 args, env, test_instance, infra_error) |
760 | 734 |
761 ### Run. | 735 ### Run. |
762 | 736 |
763 with json_writer, logcats_uploader, env, test_instance, test_run: | 737 with json_writer, env, test_instance, test_run: |
764 | 738 |
765 repetitions = (xrange(args.repeat + 1) if args.repeat >= 0 | 739 repetitions = (xrange(args.repeat + 1) if args.repeat >= 0 |
766 else itertools.count()) | 740 else itertools.count()) |
767 result_counts = collections.defaultdict( | 741 result_counts = collections.defaultdict( |
768 lambda: collections.defaultdict(int)) | 742 lambda: collections.defaultdict(int)) |
769 iteration_count = 0 | 743 iteration_count = 0 |
770 for _ in repetitions: | 744 for _ in repetitions: |
771 raw_results = test_run.RunTests() | 745 raw_results = test_run.RunTests() |
772 if not raw_results: | 746 if not raw_results: |
773 continue | 747 continue |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 if e.is_infra_error: | 869 if e.is_infra_error: |
896 return constants.INFRA_EXIT_CODE | 870 return constants.INFRA_EXIT_CODE |
897 return constants.ERROR_EXIT_CODE | 871 return constants.ERROR_EXIT_CODE |
898 except: # pylint: disable=W0702 | 872 except: # pylint: disable=W0702 |
899 logging.exception('Unrecognized error occurred.') | 873 logging.exception('Unrecognized error occurred.') |
900 return constants.ERROR_EXIT_CODE | 874 return constants.ERROR_EXIT_CODE |
901 | 875 |
902 | 876 |
903 if __name__ == '__main__': | 877 if __name__ == '__main__': |
904 sys.exit(main()) | 878 sys.exit(main()) |
OLD | NEW |