Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: build/android/test_runner.py

Issue 2695963003: Use logdog butler subcommand to run tests. (Closed)
Patch Set: change the missed revision of logdog Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 try: 723 try:
719 yield 724 yield
720 finally: 725 finally:
721 json_results.GenerateJsonResultsFile( 726 json_results.GenerateJsonResultsFile(
722 all_raw_results, args.json_results_file) 727 all_raw_results, args.json_results_file)
723 728
724 json_writer = contextlib_ext.Optional( 729 json_writer = contextlib_ext.Optional(
725 write_json_file(), 730 write_json_file(),
726 args.json_results_file) 731 args.json_results_file)
727 732
733 @contextlib.contextmanager
734 def upload_logcats_file():
735 try:
736 yield
737 finally:
738 if not args.logcat_output_file:
739 logging.critical('Cannot upload logcats file. '
740 'File to save logcat is not specified.')
741 else:
742 with open(args.logcat_output_file) as src:
743 dst = logdog_helper.open_text('unified_logcats')
744 if dst:
745 shutil.copyfileobj(src, dst)
746
747 logcats_uploader = contextlib_ext.Optional(
748 upload_logcats_file(),
749 args.upload_logcats_file)
750
728 ### Set up test objects. 751 ### Set up test objects.
729 752
730 env = environment_factory.CreateEnvironment(args, infra_error) 753 env = environment_factory.CreateEnvironment(args, infra_error)
731 test_instance = test_instance_factory.CreateTestInstance(args, infra_error) 754 test_instance = test_instance_factory.CreateTestInstance(args, infra_error)
732 test_run = test_run_factory.CreateTestRun( 755 test_run = test_run_factory.CreateTestRun(
733 args, env, test_instance, infra_error) 756 args, env, test_instance, infra_error)
734 757
735 ### Run. 758 ### Run.
736 759
737 with json_writer, env, test_instance, test_run: 760 with json_writer, logcats_uploader, env, test_instance, test_run:
738 761
739 repetitions = (xrange(args.repeat + 1) if args.repeat >= 0 762 repetitions = (xrange(args.repeat + 1) if args.repeat >= 0
740 else itertools.count()) 763 else itertools.count())
741 result_counts = collections.defaultdict( 764 result_counts = collections.defaultdict(
742 lambda: collections.defaultdict(int)) 765 lambda: collections.defaultdict(int))
743 iteration_count = 0 766 iteration_count = 0
744 for _ in repetitions: 767 for _ in repetitions:
745 raw_results = test_run.RunTests() 768 raw_results = test_run.RunTests()
746 if not raw_results: 769 if not raw_results:
747 continue 770 continue
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 if e.is_infra_error: 876 if e.is_infra_error:
854 return constants.INFRA_EXIT_CODE 877 return constants.INFRA_EXIT_CODE
855 return constants.ERROR_EXIT_CODE 878 return constants.ERROR_EXIT_CODE
856 except: # pylint: disable=W0702 879 except: # pylint: disable=W0702
857 logging.exception('Unrecognized error occurred.') 880 logging.exception('Unrecognized error occurred.')
858 return constants.ERROR_EXIT_CODE 881 return constants.ERROR_EXIT_CODE
859 882
860 883
861 if __name__ == '__main__': 884 if __name__ == '__main__':
862 sys.exit(main()) 885 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698