| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 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 | 
|  | 3 # found in the LICENSE file. | 
|  | 4 | 
|  | 5 """Module containing utility functions for reporting results.""" | 
|  | 6 | 
|  | 7 import logging | 
|  | 8 import os | 
|  | 9 import re | 
|  | 10 | 
|  | 11 from pylib import buildbot_report | 
|  | 12 from pylib import constants | 
|  | 13 | 
|  | 14 import flakiness_dashboard_results_uploader | 
|  | 15 | 
|  | 16 | 
|  | 17 def _LogToFile(results, test_type, test_suite, build_type): | 
|  | 18   """Log results to local files which can be used for aggregation later.""" | 
|  | 19   log_file_path = os.path.join(constants.CHROME_DIR, 'out', | 
|  | 20                                build_type, 'test_logs') | 
|  | 21   if not os.path.exists(log_file_path): | 
|  | 22     os.mkdir(log_file_path) | 
|  | 23   full_file_name = os.path.join( | 
|  | 24       log_file_path, re.sub('\W', '_', test_type).lower() + '.log') | 
|  | 25   if not os.path.exists(full_file_name): | 
|  | 26     with open(full_file_name, 'w') as log_file: | 
|  | 27       print >> log_file, '\n%s results for %s build %s:' % ( | 
|  | 28           test_type, os.environ.get('BUILDBOT_BUILDERNAME'), | 
|  | 29           os.environ.get('BUILDBOT_BUILDNUMBER')) | 
|  | 30     logging.info('Writing results to %s.' % full_file_name) | 
|  | 31 | 
|  | 32   logging.info('Writing results to %s.' % full_file_name) | 
|  | 33   with open(full_file_name, 'a') as log_file: | 
|  | 34     print >> log_file, '%s%s' % (test_suite.ljust(30), results.GetShortForm()) | 
|  | 35 | 
|  | 36 | 
|  | 37 def _LogToFlakinessDashboard(results, test_type, test_package, | 
|  | 38                              flakiness_server): | 
|  | 39   """Upload results to the flakiness dashboard""" | 
|  | 40   logging.info('Upload results for test type "%s", test package "%s" to %s' % | 
|  | 41                (test_type, test_package, flakiness_server)) | 
|  | 42 | 
|  | 43   # TODO(frankf): Enable uploading for gtests. | 
|  | 44   if test_type != 'Instrumentation': | 
|  | 45     logging.warning('Invalid test type.') | 
|  | 46     return | 
|  | 47 | 
|  | 48   try: | 
|  | 49     if flakiness_server == constants.UPSTREAM_FLAKINESS_SERVER: | 
|  | 50         assert test_package in ['ContentShellTest', | 
|  | 51                                 'ChromiumTestShellTest', | 
|  | 52                                 'AndroidWebViewTest'] | 
|  | 53         dashboard_test_type = ('%s_instrumentation_tests' % | 
|  | 54                                test_package.lower().rstrip('test')) | 
|  | 55     # Downstream server. | 
|  | 56     else: | 
|  | 57       dashboard_test_type = 'Chromium_Android_Instrumentation' | 
|  | 58 | 
|  | 59     flakiness_dashboard_results_uploader.Upload( | 
|  | 60         results, flakiness_server, dashboard_test_type) | 
|  | 61   except Exception as e: | 
|  | 62     logging.error(e) | 
|  | 63 | 
|  | 64 | 
|  | 65 def LogFull(results, test_type, test_package, annotation=None, | 
|  | 66             build_type='Debug', flakiness_server=None): | 
|  | 67   """Log the tests results for the test suite. | 
|  | 68 | 
|  | 69   The results will be logged three different ways: | 
|  | 70     1. Log to stdout. | 
|  | 71     2. Log to local files for aggregating multiple test steps | 
|  | 72        (on buildbots only). | 
|  | 73     3. Log to flakiness dashboard (on buildbots only). | 
|  | 74 | 
|  | 75   Args: | 
|  | 76     results: An instance of TestRunResults object. | 
|  | 77     test_type: Type of the test (e.g. 'Instrumentation', 'Unit test', etc.). | 
|  | 78     test_package: Test package name (e.g. 'ipc_tests' for gtests, | 
|  | 79                   'ContentShellTest' for instrumentation tests) | 
|  | 80     annotation: If instrumenation test type, this is a list of annotations | 
|  | 81                 (e.g. ['Smoke', 'SmallTest']). | 
|  | 82     build_type: Release/Debug | 
|  | 83     flakiness_server: If provider, upload the results to flakiness dashboard | 
|  | 84                       with this URL. | 
|  | 85     """ | 
|  | 86   if not results.DidRunPass(): | 
|  | 87     logging.critical('*' * 80) | 
|  | 88     logging.critical('Detailed Logs') | 
|  | 89     logging.critical('%s\n%s' % ('*' * 80, results.GetLogs())) | 
|  | 90   logging.critical('*' * 80) | 
|  | 91   logging.critical('Summary') | 
|  | 92   logging.critical('%s\n%s' % ('*' * 80, results)) | 
|  | 93   logging.critical('*' * 80) | 
|  | 94 | 
|  | 95   if os.environ.get('BUILDBOT_BUILDERNAME'): | 
|  | 96     # It is possible to have multiple buildbot steps for the same | 
|  | 97     # instrumenation test package using different annotations. | 
|  | 98     if annotation and len(annotation) == 1: | 
|  | 99       test_suite = annotation[0] | 
|  | 100     else: | 
|  | 101       test_suite = test_package | 
|  | 102     _LogToFile(results, test_type, test_suite, build_type) | 
|  | 103 | 
|  | 104     if flakiness_server: | 
|  | 105       _LogToFlakinessDashboard(results, test_type, test_package, | 
|  | 106                                flakiness_server) | 
|  | 107 | 
|  | 108 | 
|  | 109 def PrintAnnotation(results): | 
|  | 110   """Print buildbot annotations for test results.""" | 
|  | 111   if not results.DidRunPass(): | 
|  | 112     buildbot_report.PrintError() | 
|  | 113   else: | 
|  | 114     print 'Step success!'  # No annotation needed | 
| OLD | NEW | 
|---|