| 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, suite_name, build_type): | 16 def _LogToFile(results, test_type, suite_name): |
| 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 constants.GetBuildType(), '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) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 57 else: | 57 else: |
| 58 dashboard_test_type = 'Chromium_Android_Instrumentation' | 58 dashboard_test_type = 'Chromium_Android_Instrumentation' |
| 59 | 59 |
| 60 flakiness_dashboard_results_uploader.Upload( | 60 flakiness_dashboard_results_uploader.Upload( |
| 61 results, flakiness_server, dashboard_test_type) | 61 results, flakiness_server, dashboard_test_type) |
| 62 except Exception as e: | 62 except Exception as e: |
| 63 logging.error(e) | 63 logging.error(e) |
| 64 | 64 |
| 65 | 65 |
| 66 def LogFull(results, test_type, test_package, annotation=None, | 66 def LogFull(results, test_type, test_package, annotation=None, |
| 67 build_type='Debug', flakiness_server=None): | 67 flakiness_server=None): |
| 68 """Log the tests results for the test suite. | 68 """Log the tests results for the test suite. |
| 69 | 69 |
| 70 The results will be logged three different ways: | 70 The results will be logged three different ways: |
| 71 1. Log to stdout. | 71 1. Log to stdout. |
| 72 2. Log to local files for aggregating multiple test steps | 72 2. Log to local files for aggregating multiple test steps |
| 73 (on buildbots only). | 73 (on buildbots only). |
| 74 3. Log to flakiness dashboard (on buildbots only). | 74 3. Log to flakiness dashboard (on buildbots only). |
| 75 | 75 |
| 76 Args: | 76 Args: |
| 77 results: An instance of TestRunResults object. | 77 results: An instance of TestRunResults object. |
| 78 test_type: Type of the test (e.g. 'Instrumentation', 'Unit test', etc.). | 78 test_type: Type of the test (e.g. 'Instrumentation', 'Unit test', etc.). |
| 79 test_package: Test package name (e.g. 'ipc_tests' for gtests, | 79 test_package: Test package name (e.g. 'ipc_tests' for gtests, |
| 80 'ContentShellTest' for instrumentation tests) | 80 'ContentShellTest' for instrumentation tests) |
| 81 annotation: If instrumenation test type, this is a list of annotations | 81 annotation: If instrumenation test type, this is a list of annotations |
| 82 (e.g. ['Smoke', 'SmallTest']). | 82 (e.g. ['Smoke', 'SmallTest']). |
| 83 build_type: Release/Debug | |
| 84 flakiness_server: If provider, upload the results to flakiness dashboard | 83 flakiness_server: If provider, upload the results to flakiness dashboard |
| 85 with this URL. | 84 with this URL. |
| 86 """ | 85 """ |
| 87 if not results.DidRunPass(): | 86 if not results.DidRunPass(): |
| 88 logging.critical('*' * 80) | 87 logging.critical('*' * 80) |
| 89 logging.critical('Detailed Logs') | 88 logging.critical('Detailed Logs') |
| 90 logging.critical('*' * 80) | 89 logging.critical('*' * 80) |
| 91 for line in results.GetLogs().splitlines(): | 90 for line in results.GetLogs().splitlines(): |
| 92 logging.critical(line) | 91 logging.critical(line) |
| 93 logging.critical('*' * 80) | 92 logging.critical('*' * 80) |
| 94 logging.critical('Summary') | 93 logging.critical('Summary') |
| 95 logging.critical('*' * 80) | 94 logging.critical('*' * 80) |
| 96 for line in results.GetLongForm().splitlines(): | 95 for line in results.GetLongForm().splitlines(): |
| 97 logging.critical(line) | 96 logging.critical(line) |
| 98 logging.critical('*' * 80) | 97 logging.critical('*' * 80) |
| 99 | 98 |
| 100 if os.environ.get('BUILDBOT_BUILDERNAME'): | 99 if os.environ.get('BUILDBOT_BUILDERNAME'): |
| 101 # It is possible to have multiple buildbot steps for the same | 100 # It is possible to have multiple buildbot steps for the same |
| 102 # instrumenation test package using different annotations. | 101 # instrumenation test package using different annotations. |
| 103 if annotation and len(annotation) == 1: | 102 if annotation and len(annotation) == 1: |
| 104 suite_name = annotation[0] | 103 suite_name = annotation[0] |
| 105 else: | 104 else: |
| 106 suite_name = test_package | 105 suite_name = test_package |
| 107 _LogToFile(results, test_type, suite_name, build_type) | 106 _LogToFile(results, test_type, suite_name, constants.GetBuildType()) |
| 108 | 107 |
| 109 if flakiness_server: | 108 if flakiness_server: |
| 110 _LogToFlakinessDashboard(results, test_type, test_package, | 109 _LogToFlakinessDashboard(results, test_type, test_package, |
| 111 flakiness_server) | 110 flakiness_server) |
| OLD | NEW |