Roll src/third_party/WebKit a3b4a2e:7441784 (svn 202551:202552)
[chromium-blink-merge.git] / build / android / pylib / results / report_results.py
blob76e4bb5444333a63faaf1e600f75c83cb3ec38e4
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.
5 """Module containing utility functions for reporting results."""
7 import logging
8 import os
9 import re
11 from pylib import constants
12 from pylib.results.flakiness_dashboard import results_uploader
15 def _LogToFile(results, test_type, suite_name):
16 """Log results to local files which can be used for aggregation later."""
17 log_file_path = os.path.join(constants.GetOutDirectory(), 'test_logs')
18 if not os.path.exists(log_file_path):
19 os.mkdir(log_file_path)
20 full_file_name = os.path.join(
21 log_file_path, re.sub(r'\W', '_', test_type).lower() + '.log')
22 if not os.path.exists(full_file_name):
23 with open(full_file_name, 'w') as log_file:
24 print >> log_file, '\n%s results for %s build %s:' % (
25 test_type, os.environ.get('BUILDBOT_BUILDERNAME'),
26 os.environ.get('BUILDBOT_BUILDNUMBER'))
27 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:
31 shortened_suite_name = suite_name[:25] + (suite_name[25:] and '...')
32 print >> log_file, '%s%s' % (shortened_suite_name.ljust(30),
33 results.GetShortForm())
36 def _LogToFlakinessDashboard(results, test_type, test_package,
37 flakiness_server):
38 """Upload results to the flakiness dashboard"""
39 logging.info('Upload results for test type "%s", test package "%s" to %s',
40 test_type, test_package, flakiness_server)
42 try:
43 if test_type == 'Instrumentation':
44 if flakiness_server == constants.UPSTREAM_FLAKINESS_SERVER:
45 assert test_package in ['ContentShellTest',
46 'ChromePublicTest',
47 'ChromeSyncShellTest',
48 'AndroidWebViewTest']
49 dashboard_test_type = ('%s_instrumentation_tests' %
50 test_package.lower().rstrip('test'))
51 # Downstream server.
52 else:
53 dashboard_test_type = 'Chromium_Android_Instrumentation'
55 elif test_type == 'Unit test':
56 dashboard_test_type = test_package
58 else:
59 logging.warning('Invalid test type')
60 return
62 results_uploader.Upload(
63 results, flakiness_server, dashboard_test_type)
65 except Exception: # pylint: disable=broad-except
66 logging.exception('Failure while logging to %s', flakiness_server)
69 def LogFull(results, test_type, test_package, annotation=None,
70 flakiness_server=None):
71 """Log the tests results for the test suite.
73 The results will be logged three different ways:
74 1. Log to stdout.
75 2. Log to local files for aggregating multiple test steps
76 (on buildbots only).
77 3. Log to flakiness dashboard (on buildbots only).
79 Args:
80 results: An instance of TestRunResults object.
81 test_type: Type of the test (e.g. 'Instrumentation', 'Unit test', etc.).
82 test_package: Test package name (e.g. 'ipc_tests' for gtests,
83 'ContentShellTest' for instrumentation tests)
84 annotation: If instrumenation test type, this is a list of annotations
85 (e.g. ['Smoke', 'SmallTest']).
86 flakiness_server: If provider, upload the results to flakiness dashboard
87 with this URL.
88 """
89 if not results.DidRunPass():
90 logging.critical('*' * 80)
91 logging.critical('Detailed Logs')
92 logging.critical('*' * 80)
93 for line in results.GetLogs().splitlines():
94 logging.critical(line)
95 logging.critical('*' * 80)
96 logging.critical('Summary')
97 logging.critical('*' * 80)
98 for line in results.GetGtestForm().splitlines():
99 logging.critical(line)
100 logging.critical('*' * 80)
102 if os.environ.get('BUILDBOT_BUILDERNAME'):
103 # It is possible to have multiple buildbot steps for the same
104 # instrumenation test package using different annotations.
105 if annotation and len(annotation) == 1:
106 suite_name = annotation[0]
107 else:
108 suite_name = test_package
109 _LogToFile(results, test_type, suite_name)
111 if flakiness_server:
112 _LogToFlakinessDashboard(results, test_type, test_package,
113 flakiness_server)