| 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 | 12 |
| 13 import flakiness_dashboard_results_uploader | 13 import flakiness_dashboard_results_uploader |
| 14 | 14 |
| 15 | 15 |
| 16 def _LogToFile(results, test_type, test_suite, build_type): | 16 def _LogToFile(results, test_type, suite_name, build_type): |
| 17 """Log results to local files which can be used for aggregation later.""" | 17 """Log results to local files which can be used for aggregation later.""" |
| 18 log_file_path = os.path.join(constants.DIR_SOURCE_ROOT, 'out', | 18 log_file_path = os.path.join(constants.DIR_SOURCE_ROOT, 'out', |
| 19 build_type, 'test_logs') | 19 build_type, 'test_logs') |
| 20 if not os.path.exists(log_file_path): | 20 if not os.path.exists(log_file_path): |
| 21 os.mkdir(log_file_path) | 21 os.mkdir(log_file_path) |
| 22 full_file_name = os.path.join( | 22 full_file_name = os.path.join( |
| 23 log_file_path, re.sub('\W', '_', test_type).lower() + '.log') | 23 log_file_path, re.sub('\W', '_', test_type).lower() + '.log') |
| 24 if not os.path.exists(full_file_name): | 24 if not os.path.exists(full_file_name): |
| 25 with open(full_file_name, 'w') as log_file: | 25 with open(full_file_name, 'w') as log_file: |
| 26 print >> log_file, '\n%s results for %s build %s:' % ( | 26 print >> log_file, '\n%s results for %s build %s:' % ( |
| 27 test_type, os.environ.get('BUILDBOT_BUILDERNAME'), | 27 test_type, os.environ.get('BUILDBOT_BUILDERNAME'), |
| 28 os.environ.get('BUILDBOT_BUILDNUMBER')) | 28 os.environ.get('BUILDBOT_BUILDNUMBER')) |
| 29 logging.info('Writing results to %s.' % full_file_name) | 29 logging.info('Writing results to %s.' % full_file_name) |
| 30 | 30 |
| 31 logging.info('Writing results to %s.' % full_file_name) | 31 logging.info('Writing results to %s.' % full_file_name) |
| 32 with open(full_file_name, 'a') as log_file: | 32 with open(full_file_name, 'a') as log_file: |
| 33 shortened_suite_name = test_suite[:25] + (test_suite[25:] and '...') | 33 shortened_suite_name = suite_name[:25] + (suite_name[25:] and '...') |
| 34 print >> log_file, '%s%s' % (shortened_suite_name.ljust(30), | 34 print >> log_file, '%s%s' % (shortened_suite_name.ljust(30), |
| 35 results.GetShortForm()) | 35 results.GetShortForm()) |
| 36 | 36 |
| 37 | 37 |
| 38 def _LogToFlakinessDashboard(results, test_type, test_package, | 38 def _LogToFlakinessDashboard(results, test_type, test_package, |
| 39 flakiness_server): | 39 flakiness_server): |
| 40 """Upload results to the flakiness dashboard""" | 40 """Upload results to the flakiness dashboard""" |
| 41 logging.info('Upload results for test type "%s", test package "%s" to %s' % | 41 logging.info('Upload results for test type "%s", test package "%s" to %s' % |
| 42 (test_type, test_package, flakiness_server)) | 42 (test_type, test_package, flakiness_server)) |
| 43 | 43 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 logging.critical('Summary') | 94 logging.critical('Summary') |
| 95 logging.critical('*' * 80) | 95 logging.critical('*' * 80) |
| 96 for line in results.GetLongForm().splitlines(): | 96 for line in results.GetLongForm().splitlines(): |
| 97 logging.critical(line) | 97 logging.critical(line) |
| 98 logging.critical('*' * 80) | 98 logging.critical('*' * 80) |
| 99 | 99 |
| 100 if os.environ.get('BUILDBOT_BUILDERNAME'): | 100 if os.environ.get('BUILDBOT_BUILDERNAME'): |
| 101 # It is possible to have multiple buildbot steps for the same | 101 # It is possible to have multiple buildbot steps for the same |
| 102 # instrumenation test package using different annotations. | 102 # instrumenation test package using different annotations. |
| 103 if annotation and len(annotation) == 1: | 103 if annotation and len(annotation) == 1: |
| 104 test_suite = annotation[0] | 104 suite_name = annotation[0] |
| 105 else: | 105 else: |
| 106 test_suite = test_package | 106 suite_name = test_package |
| 107 _LogToFile(results, test_type, test_suite, build_type) | 107 _LogToFile(results, test_type, suite_name, build_type) |
| 108 | 108 |
| 109 if flakiness_server: | 109 if flakiness_server: |
| 110 _LogToFlakinessDashboard(results, test_type, test_package, | 110 _LogToFlakinessDashboard(results, test_type, test_package, |
| 111 flakiness_server) | 111 flakiness_server) |
| OLD | NEW |