OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Module containing utility functions for reporting results.""" | 5 """Module containing utility functions for reporting results.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import re | 9 import re |
10 | 10 |
11 from pylib import constants | 11 from pylib import constants |
12 from pylib.results.flakiness_dashboard import results_uploader | 12 from pylib.results.flakiness_dashboard import results_uploader |
13 | 13 |
14 | 14 |
15 def _LogToFile(results, test_type, suite_name): | 15 def _LogToFile(results, test_type, suite_name): |
16 """Log results to local files which can be used for aggregation later.""" | 16 """Log results to local files which can be used for aggregation later.""" |
17 log_file_path = os.path.join(constants.GetOutDirectory(), 'test_logs') | 17 log_file_path = os.path.join(constants.GetOutDirectory(), 'test_logs') |
18 if not os.path.exists(log_file_path): | 18 if not os.path.exists(log_file_path): |
19 os.mkdir(log_file_path) | 19 os.mkdir(log_file_path) |
20 full_file_name = os.path.join( | 20 full_file_name = os.path.join( |
21 log_file_path, re.sub(r'\W', '_', test_type).lower() + '.log') | 21 log_file_path, re.sub(r'\W', '_', test_type).lower() + '.log') |
22 if not os.path.exists(full_file_name): | 22 if not os.path.exists(full_file_name): |
23 with open(full_file_name, 'w') as log_file: | 23 with open(full_file_name, 'w') as log_file: |
24 print >> log_file, '\n%s results for %s build %s:' % ( | 24 print >> log_file, '\n%s results for %s build %s:' % ( |
25 test_type, os.environ.get('BUILDBOT_BUILDERNAME'), | 25 test_type, os.environ.get('BUILDBOT_BUILDERNAME'), |
26 os.environ.get('BUILDBOT_BUILDNUMBER')) | 26 os.environ.get('BUILDBOT_BUILDNUMBER')) |
27 logging.info('Writing results to %s.' % full_file_name) | 27 logging.info('Writing results to %s.', full_file_name) |
28 | 28 |
29 logging.info('Writing results to %s.' % full_file_name) | 29 logging.info('Writing results to %s.', full_file_name) |
30 with open(full_file_name, 'a') as log_file: | 30 with open(full_file_name, 'a') as log_file: |
31 shortened_suite_name = suite_name[:25] + (suite_name[25:] and '...') | 31 shortened_suite_name = suite_name[:25] + (suite_name[25:] and '...') |
32 print >> log_file, '%s%s' % (shortened_suite_name.ljust(30), | 32 print >> log_file, '%s%s' % (shortened_suite_name.ljust(30), |
33 results.GetShortForm()) | 33 results.GetShortForm()) |
34 | 34 |
35 | 35 |
36 def _LogToFlakinessDashboard(results, test_type, test_package, | 36 def _LogToFlakinessDashboard(results, test_type, test_package, |
37 flakiness_server): | 37 flakiness_server): |
38 """Upload results to the flakiness dashboard""" | 38 """Upload results to the flakiness dashboard""" |
39 logging.info('Upload results for test type "%s", test package "%s" to %s' % | 39 logging.info('Upload results for test type "%s", test package "%s" to %s', |
40 (test_type, test_package, flakiness_server)) | 40 test_type, test_package, flakiness_server) |
41 | 41 |
42 try: | 42 try: |
43 if test_type == 'Instrumentation': | 43 if test_type == 'Instrumentation': |
44 if flakiness_server == constants.UPSTREAM_FLAKINESS_SERVER: | 44 if flakiness_server == constants.UPSTREAM_FLAKINESS_SERVER: |
45 assert test_package in ['ContentShellTest', | 45 assert test_package in ['ContentShellTest', |
46 'ChromePublicTest', | 46 'ChromePublicTest', |
47 'ChromeSyncShellTest', | 47 'ChromeSyncShellTest', |
48 'AndroidWebViewTest'] | 48 'AndroidWebViewTest'] |
49 dashboard_test_type = ('%s_instrumentation_tests' % | 49 dashboard_test_type = ('%s_instrumentation_tests' % |
50 test_package.lower().rstrip('test')) | 50 test_package.lower().rstrip('test')) |
51 # Downstream server. | 51 # Downstream server. |
52 else: | 52 else: |
53 dashboard_test_type = 'Chromium_Android_Instrumentation' | 53 dashboard_test_type = 'Chromium_Android_Instrumentation' |
54 | 54 |
55 elif test_type == 'Unit test': | 55 elif test_type == 'Unit test': |
56 dashboard_test_type = test_package | 56 dashboard_test_type = test_package |
57 | 57 |
58 else: | 58 else: |
59 logging.warning('Invalid test type') | 59 logging.warning('Invalid test type') |
60 return | 60 return |
61 | 61 |
62 results_uploader.Upload( | 62 results_uploader.Upload( |
63 results, flakiness_server, dashboard_test_type) | 63 results, flakiness_server, dashboard_test_type) |
64 | 64 |
65 except Exception as e: | 65 except Exception: # pylint: disable=broad-except |
66 logging.error(e) | 66 logging.exception('Failure while logging to %s', flakiness_server) |
67 | 67 |
68 | 68 |
69 def LogFull(results, test_type, test_package, annotation=None, | 69 def LogFull(results, test_type, test_package, annotation=None, |
70 flakiness_server=None): | 70 flakiness_server=None): |
71 """Log the tests results for the test suite. | 71 """Log the tests results for the test suite. |
72 | 72 |
73 The results will be logged three different ways: | 73 The results will be logged three different ways: |
74 1. Log to stdout. | 74 1. Log to stdout. |
75 2. Log to local files for aggregating multiple test steps | 75 2. Log to local files for aggregating multiple test steps |
76 (on buildbots only). | 76 (on buildbots only). |
(...skipping 27 matching lines...) Expand all Loading... |
104 # instrumenation test package using different annotations. | 104 # instrumenation test package using different annotations. |
105 if annotation and len(annotation) == 1: | 105 if annotation and len(annotation) == 1: |
106 suite_name = annotation[0] | 106 suite_name = annotation[0] |
107 else: | 107 else: |
108 suite_name = test_package | 108 suite_name = test_package |
109 _LogToFile(results, test_type, suite_name) | 109 _LogToFile(results, test_type, suite_name) |
110 | 110 |
111 if flakiness_server: | 111 if flakiness_server: |
112 _LogToFlakinessDashboard(results, test_type, test_package, | 112 _LogToFlakinessDashboard(results, test_type, test_package, |
113 flakiness_server) | 113 flakiness_server) |
OLD | NEW |