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 | |
15 import signal | 16 import signal |
16 import sys | 17 import sys |
17 import threading | 18 import threading |
18 import traceback | 19 import traceback |
19 import unittest | 20 import unittest |
20 | 21 |
21 import devil_chromium | 22 import devil_chromium |
22 from devil import base_error | 23 from devil import base_error |
23 from devil.android import device_blacklist | 24 from devil.android import device_blacklist |
24 from devil.android import device_errors | 25 from devil.android import device_errors |
25 from devil.android import device_utils | 26 from devil.android import device_utils |
26 from devil.android import forwarder | 27 from devil.android import forwarder |
27 from devil.android import ports | 28 from devil.android import ports |
28 from devil.utils import reraiser_thread | 29 from devil.utils import reraiser_thread |
29 from devil.utils import run_tests_helper | 30 from devil.utils import run_tests_helper |
30 | 31 |
31 from pylib import constants | 32 from pylib import constants |
32 from pylib.base import base_test_result | 33 from pylib.base import base_test_result |
33 from pylib.base import environment_factory | 34 from pylib.base import environment_factory |
34 from pylib.base import test_instance_factory | 35 from pylib.base import test_instance_factory |
35 from pylib.base import test_run_factory | 36 from pylib.base import test_run_factory |
36 from pylib.constants import host_paths | 37 from pylib.constants import host_paths |
37 from pylib.results import json_results | 38 from pylib.results import json_results |
38 from pylib.results import report_results | 39 from pylib.results import report_results |
40 from pylib.utils import logdog_helper | |
39 | 41 |
40 from py_utils import contextlib_ext | 42 from py_utils import contextlib_ext |
41 | 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|.""" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 'should be used.')) | 110 'should be used.')) |
109 group.add_argument('--json-results-file', '--test-launcher-summary-output', | 111 group.add_argument('--json-results-file', '--test-launcher-summary-output', |
110 dest='json_results_file', type=os.path.realpath, | 112 dest='json_results_file', type=os.path.realpath, |
111 help='If set, will dump results in JSON form ' | 113 help='If set, will dump results in JSON form ' |
112 'to specified file.') | 114 'to specified file.') |
113 group.add_argument('--trace-output', metavar='FILENAME', | 115 group.add_argument('--trace-output', metavar='FILENAME', |
114 type=os.path.realpath, | 116 type=os.path.realpath, |
115 help='Path to save test_runner trace data to. This option ' | 117 help='Path to save test_runner trace data to. This option ' |
116 'has been implemented for gtest, instrumentation ' | 118 'has been implemented for gtest, instrumentation ' |
117 'test and perf test.') | 119 'test and perf test.') |
120 group.add_argument('--upload-logcats-file', action='store_true', | |
121 dest='upload_logcats_file', | |
122 help='Whether to upload logcat file to logdog.') | |
118 | 123 |
119 logcat_output_group = group.add_mutually_exclusive_group() | 124 logcat_output_group = group.add_mutually_exclusive_group() |
120 logcat_output_group.add_argument( | 125 logcat_output_group.add_argument( |
121 '--logcat-output-dir', type=os.path.realpath, | 126 '--logcat-output-dir', type=os.path.realpath, |
122 help='If set, will dump logcats recorded during test run to directory. ' | 127 help='If set, will dump logcats recorded during test run to directory. ' |
123 'File names will be the device ids with timestamps.') | 128 'File names will be the device ids with timestamps.') |
124 logcat_output_group.add_argument( | 129 logcat_output_group.add_argument( |
125 '--logcat-output-file', type=os.path.realpath, | 130 '--logcat-output-file', type=os.path.realpath, |
126 help='If set, will merge logcats recorded during test run and dump them ' | 131 help='If set, will merge logcats recorded during test run and dump them ' |
127 'to the specified file.') | 132 'to the specified file.') |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
702 try: | 707 try: |
703 yield | 708 yield |
704 finally: | 709 finally: |
705 json_results.GenerateJsonResultsFile( | 710 json_results.GenerateJsonResultsFile( |
706 all_raw_results, args.json_results_file) | 711 all_raw_results, args.json_results_file) |
707 | 712 |
708 json_writer = contextlib_ext.Optional( | 713 json_writer = contextlib_ext.Optional( |
709 write_json_file(), | 714 write_json_file(), |
710 args.json_results_file) | 715 args.json_results_file) |
711 | 716 |
717 @contextlib.contextmanager | |
718 def upload_logcats_file(): | |
719 try: | |
720 yield | |
721 finally: | |
722 if not args.logcat_output_file: | |
723 logging.critical('Cannot upload logcats file. ' | |
724 'File to save logcat is not specified.') | |
725 else: | |
726 with open(args.logcat_output_file) as src: | |
jbudorick
2017/03/04 02:19:59
nit: this should eat and log any IOError it receiv
| |
727 dst = logdog_helper.open_text('unified_logcats') | |
728 if dst: | |
729 with open(dst) as dst: | |
730 shutil.copyfileobj(src, dst) | |
731 | |
732 logcats_uploader = contextlib_ext.Optional( | |
733 upload_logcats_file(), | |
734 args.upload_logcats_file) | |
735 | |
712 ### Set up test objects. | 736 ### Set up test objects. |
713 | 737 |
714 env = environment_factory.CreateEnvironment(args, infra_error) | 738 env = environment_factory.CreateEnvironment(args, infra_error) |
715 test_instance = test_instance_factory.CreateTestInstance(args, infra_error) | 739 test_instance = test_instance_factory.CreateTestInstance(args, infra_error) |
716 test_run = test_run_factory.CreateTestRun( | 740 test_run = test_run_factory.CreateTestRun( |
717 args, env, test_instance, infra_error) | 741 args, env, test_instance, infra_error) |
718 | 742 |
719 ### Run. | 743 ### Run. |
720 | 744 |
721 with json_writer, env, test_instance, test_run: | 745 with json_writer, logcats_uploader, env, test_instance, test_run: |
722 | 746 |
723 repetitions = (xrange(args.repeat + 1) if args.repeat >= 0 | 747 repetitions = (xrange(args.repeat + 1) if args.repeat >= 0 |
724 else itertools.count()) | 748 else itertools.count()) |
725 result_counts = collections.defaultdict( | 749 result_counts = collections.defaultdict( |
726 lambda: collections.defaultdict(int)) | 750 lambda: collections.defaultdict(int)) |
727 iteration_count = 0 | 751 iteration_count = 0 |
728 for _ in repetitions: | 752 for _ in repetitions: |
729 raw_results = test_run.RunTests() | 753 raw_results = test_run.RunTests() |
730 if not raw_results: | 754 if not raw_results: |
731 continue | 755 continue |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
837 if e.is_infra_error: | 861 if e.is_infra_error: |
838 return constants.INFRA_EXIT_CODE | 862 return constants.INFRA_EXIT_CODE |
839 return constants.ERROR_EXIT_CODE | 863 return constants.ERROR_EXIT_CODE |
840 except: # pylint: disable=W0702 | 864 except: # pylint: disable=W0702 |
841 logging.exception('Unrecognized error occurred.') | 865 logging.exception('Unrecognized error occurred.') |
842 return constants.ERROR_EXIT_CODE | 866 return constants.ERROR_EXIT_CODE |
843 | 867 |
844 | 868 |
845 if __name__ == '__main__': | 869 if __name__ == '__main__': |
846 sys.exit(main()) | 870 sys.exit(main()) |
OLD | NEW |