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

Side by Side Diff: tools/telemetry/telemetry/unittest_util/run_chromeos_tests.py

Issue 743463003: Attempt #4 to convert telemetry to the typ framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix run_tests_unittest failures, remove debug logging Created 6 years, 1 month 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 import logging 4 import logging
5 import os 5 import os
6 import sys
7 6
8 from telemetry.unittest_util import gtest_progress_reporter
9 from telemetry.unittest_util import run_tests 7 from telemetry.unittest_util import run_tests
10 from telemetry.core import util 8 from telemetry.core import util
11 9
12 10
13 def RunTestsForChromeOS(browser_type, unit_tests, perf_tests): 11 def RunTestsForChromeOS(browser_type, unit_tests, perf_tests):
14 stream = _LoggingOutputStream() 12 stream = _LoggingOutputStream()
15 error_string = '' 13 error_string = ''
16 14
17 logging.info('Running telemetry unit tests with browser_type "%s".' % 15 if unit_tests:
18 browser_type) 16 logging.info('Running telemetry unit tests with browser_type "%s".' %
19 ret = _RunOneSetOfTests(browser_type, 'telemetry', 17 browser_type)
20 os.path.join('telemetry', 'telemetry'), 18 ret = _RunOneSetOfTests(browser_type, 'telemetry', unit_tests, stream)
21 unit_tests, stream) 19 if ret:
22 if ret: 20 error_string += 'The unit tests failed.\n'
23 error_string += 'The unit tests failed.\n'
24 21
25 logging.info('Running telemetry perf tests with browser_type "%s".' % 22 if perf_tests:
26 browser_type) 23 logging.info('Running telemetry perf tests with browser_type "%s".' %
27 ret = _RunOneSetOfTests(browser_type, 'perf', 'perf', perf_tests, stream) 24 browser_type)
28 if ret: 25 ret = _RunOneSetOfTests(browser_type, 'perf', perf_tests, stream)
29 error_string = 'The perf tests failed.\n' 26 if ret:
27 error_string = 'The perf tests failed.\n'
30 28
31 return error_string 29 return error_string
32 30
33 31
34 def _RunOneSetOfTests(browser_type, root_dir, sub_dir, tests, stream): 32 def _RunOneSetOfTests(browser_type, dir_name, tests, stream):
35 if not tests: 33 top_level_dir = os.path.join(util.GetChromiumSrcDir(), 'tools', dir_name)
36 return 34 args = ['--browser', browser_type,
37 top_level_dir = os.path.join(util.GetChromiumSrcDir(), 'tools', root_dir) 35 '--top-level-dir', top_level_dir,
38 sub_dir = os.path.join(util.GetChromiumSrcDir(), 'tools', sub_dir) 36 '--jobs', '1'] + tests
39 37 return run_tests.RunTestsCommand.main(args, stream=stream)
40 sys.path.append(top_level_dir)
41
42 output_formatters = [gtest_progress_reporter.GTestProgressReporter(stream)]
43 run_tests.config = run_tests.Config(top_level_dir, [sub_dir],
44 output_formatters)
45 return run_tests.RunTestsCommand.main(['--browser', browser_type] + tests)
46 38
47 39
48 class _LoggingOutputStream(object): 40 class _LoggingOutputStream(object):
49 41
50 def __init__(self): 42 def __init__(self):
51 self._buffer = [] 43 self._buffer = []
52 44
53 def write(self, s): 45 def write(self, s):
54 """Buffer a string write. Log it when we encounter a newline.""" 46 """Buffer a string write. Log it when we encounter a newline."""
55 if '\n' in s: 47 if '\n' in s:
56 segments = s.split('\n') 48 segments = s.split('\n')
57 segments[0] = ''.join(self._buffer + [segments[0]]) 49 segments[0] = ''.join(self._buffer + [segments[0]])
58 log_level = logging.getLogger().getEffectiveLevel() 50 log_level = logging.getLogger().getEffectiveLevel()
59 try: # TODO(dtu): We need this because of crbug.com/394571 51 try: # TODO(dtu): We need this because of crbug.com/394571
60 logging.getLogger().setLevel(logging.INFO) 52 logging.getLogger().setLevel(logging.INFO)
61 for line in segments[:-1]: 53 for line in segments[:-1]:
62 logging.info(line) 54 logging.info(line)
63 finally: 55 finally:
64 logging.getLogger().setLevel(log_level) 56 logging.getLogger().setLevel(log_level)
65 self._buffer = [segments[-1]] 57 self._buffer = [segments[-1]]
66 else: 58 else:
67 self._buffer.append(s) 59 self._buffer.append(s)
68 60
69 def flush(self): # pylint: disable=W0612 61 def flush(self): # pylint: disable=W0612
70 pass 62 pass
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/unittest_util/json_results.py ('k') | tools/telemetry/telemetry/unittest_util/run_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698