Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1542)

Side by Side Diff: build/android/pylib/utils/report_results.py

Issue 12544033: [Android] Rewrite base test result classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed craig's nits Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 from pylib.utils import flakiness_dashboard_results_uploader
14
15
16 def _LogToFile(results, test_type, test_suite, build_type):
craigdh 2013/03/25 19:08:45 full of race conditions, remove it or at least sti
frankf 2013/03/25 22:37:39 This is not called from multiple threads. On 2013
17 """Log results to local files which can be used for aggregation later."""
18 log_file_path = os.path.join(constants.CHROME_DIR, 'out',
19 build_type, 'test_logs')
20 if not os.path.exists(log_file_path):
21 os.mkdir(log_file_path)
22 full_file_name = os.path.join(
23 log_file_path, re.sub('\W', '_', test_type).lower() + '.log')
24 if not os.path.exists(full_file_name):
25 with open(full_file_name, 'w') as log_file:
26 print >> log_file, '\n%s results for %s build %s:' % (
27 test_type, os.environ.get('BUILDBOT_BUILDERNAME'),
28 os.environ.get('BUILDBOT_BUILDNUMBER'))
29 logging.info('Writing results to %s.' % full_file_name)
30
31 logging.info('Writing results to %s.' % full_file_name)
32 with open(full_file_name, 'a') as log_file:
33 print >> log_file, results.GetShortForm()
34
35
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))
41
42 # TODO(frankf): Enable uploading for gtests.
43 if test_type != 'Instrumentation':
44 logging.warning('Invalid test type.')
45 return
46
47 try:
48 if flakiness_server == constants.UPSTREAM_FLAKINESS_SERVER:
49 assert test_package in ['ContentShellTest',
50 'ChromiumTestShellTest',
51 'AndroidWebViewTest']
52 dashboard_test_type = ('%s_instrumentation_tests' %
53 test_package.lower().rstrip('test'))
54 # Downstream server.
55 else:
56 dashboard_test_type = 'Chromium_Android_Instrumentation'
57
58 flakiness_dashboard_results_uploader.Upload(
59 results, flakiness_server, dashboard_test_type)
60 except Exception as e:
61 logging.error(e)
62
63
64 def LogFull(results, test_type, test_package, annotation=None,
65 build_type='Debug', flakiness_server=None):
66 """Log the tests results for the test suite.
67
68 The results will be logged three different ways:
69 1. Log to stdout.
70 2. Log to local files for aggregating multiple test steps
71 (on buildbots only).
72 3. Log to flakiness dashboard (on buildbots only).
73
74 Args:
75 results: An instance of TestRunResults object.
76 test_type: Type of the test (e.g. 'Instrumentation', 'Unit test', etc.).
77 test_package: Test package name (e.g. 'ipc_tests' for gtests,
78 'ContentShellTest' for instrumentation tests)
79 annotation: If instrumenation test type, this is a list of annotations
80 (e.g. ['Smoke', 'SmallTest']).
81 build_type: Release/Debug
82 flakiness_server: If provider, upload the results to flakiness dashboard
83 with this URL.
84 """
85 if not results.DidRunPass():
86 logging.critical('*' * 80)
87 logging.critical('Detailed Logs')
88 logging.critical('%s\n%s' % ('*' * 80, results.GetLogs()))
89 logging.critical('*' * 80)
90 logging.critical('Summary')
91 logging.critical('%s\n%s' % ('*' * 80, results))
92 logging.critical('*' * 80)
93
94 if os.environ.get('BUILDBOT_BUILDERNAME'):
95 # It is possible to have multiple buildbot steps for the same
96 # instrumenation test package using different annotations.
97 if annotation and len(annotation) == 1:
98 test_suite = annotation[0]
99 else:
100 test_suite = test_package
101 _LogToFile(results, test_type, test_suite, build_type)
102
103 if flakiness_server:
104 _LogToFlakinessDashboard(results, test_type, test_package,
105 flakiness_server)
106
107
108 def PrintAnnotation(results):
109 """Print buildbot annotations for test results."""
110 if not results.DidRunPass():
111 buildbot_report.PrintError()
112 else:
113 print 'Step success!' # No annotation needed
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698