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