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

Side by Side Diff: mojo/tools/mopy/gtest.py

Issue 1279833003: Makes mopy turn off gtest coloring (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move to where we copy env and remove set_color Created 5 years, 4 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
« no previous file with comments | « mojo/tools/apptest_runner.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4
5 import logging 5 import logging
6 import os 6 import os
7 import Queue 7 import Queue
8 import re 8 import re
9 import subprocess 9 import subprocess
10 import sys 10 import sys
11 import threading 11 import threading
12 import time 12 import time
13 13
14 from mopy.config import Config 14 from mopy.config import Config
15 from mopy.paths import Paths 15 from mopy.paths import Paths
16 16
17 sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), 17 sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)),
18 '..', '..', '..', 'testing')) 18 '..', '..', '..', 'testing'))
19 import xvfb 19 import xvfb
20 20
21 21
22 # The DISPLAY ID number used for xvfb, incremented with each use. 22 # The DISPLAY ID number used for xvfb, incremented with each use.
23 XVFB_DISPLAY_ID = 9 23 XVFB_DISPLAY_ID = 9
24 24
25 25
26 def set_color():
27 '''Run gtests with color on TTY, unless its environment variable is set.'''
28 if sys.stdout.isatty() and 'GTEST_COLOR' not in os.environ:
29 logging.getLogger().debug('Setting GTEST_COLOR=yes')
30 os.environ['GTEST_COLOR'] = 'yes'
31
32
33 def run_apptest(config, shell, args, apptest, isolate): 26 def run_apptest(config, shell, args, apptest, isolate):
34 '''Run the apptest; optionally isolating fixtures across shell invocations. 27 '''Run the apptest; optionally isolating fixtures across shell invocations.
35 28
36 Returns the list of test fixtures run and the list of failed test fixtures. 29 Returns the list of test fixtures run and the list of failed test fixtures.
37 TODO(msw): Also return the list of DISABLED test fixtures. 30 TODO(msw): Also return the list of DISABLED test fixtures.
38 31
39 Args: 32 Args:
40 config: The mopy.config.Config for the build. 33 config: The mopy.config.Config for the build.
41 shell: The mopy.android.AndroidShell, if Android is the target platform. 34 shell: The mopy.android.AndroidShell, if Android is the target platform.
42 args: The arguments for the shell or apptest. 35 args: The arguments for the shell or apptest.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 def _build_command_line(config, args, apptest): 140 def _build_command_line(config, args, apptest):
148 '''Build the apptest command line. This value isn't executed on Android.''' 141 '''Build the apptest command line. This value isn't executed on Android.'''
149 not_list_tests = not '--gtest_list_tests' in args 142 not_list_tests = not '--gtest_list_tests' in args
150 data_dir = ['--use-temporary-user-data-dir'] if not_list_tests else [] 143 data_dir = ['--use-temporary-user-data-dir'] if not_list_tests else []
151 return Paths(config).mojo_runner + data_dir + args + [apptest] 144 return Paths(config).mojo_runner + data_dir + args + [apptest]
152 145
153 146
154 def _run_test_with_xvfb(config, shell, args, apptest): 147 def _run_test_with_xvfb(config, shell, args, apptest):
155 '''Run the test with xvfb; return the output or raise an exception.''' 148 '''Run the test with xvfb; return the output or raise an exception.'''
156 env = os.environ.copy() 149 env = os.environ.copy()
150 # Make sure gtest doesn't try to add color to the output. Color is done via
151 # escape sequences which confuses the code that searches the gtest output.
152 env['GTEST_COLOR'] = 'no'
157 if (config.target_os != Config.OS_LINUX or '--gtest_list_tests' in args 153 if (config.target_os != Config.OS_LINUX or '--gtest_list_tests' in args
158 or not xvfb.should_start_xvfb(env)): 154 or not xvfb.should_start_xvfb(env)):
159 return _run_test_with_timeout(config, shell, args, apptest, env) 155 return _run_test_with_timeout(config, shell, args, apptest, env)
160 156
161 try: 157 try:
162 # Simply prepending xvfb.py to the command line precludes direct control of 158 # Simply prepending xvfb.py to the command line precludes direct control of
163 # test subprocesses, and prevents easily getting output when tests timeout. 159 # test subprocesses, and prevents easily getting output when tests timeout.
164 xvfb_proc = None 160 xvfb_proc = None
165 openbox_proc = None 161 openbox_proc = None
166 global XVFB_DISPLAY_ID 162 global XVFB_DISPLAY_ID
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 (r, w) = os.pipe() 229 (r, w) = os.pipe()
234 with os.fdopen(r, 'r') as rf: 230 with os.fdopen(r, 'r') as rf:
235 with os.fdopen(w, 'w') as wf: 231 with os.fdopen(w, 'w') as wf:
236 arguments = args + [apptest] 232 arguments = args + [apptest]
237 shell.StartActivity('MojoShellActivity', arguments, wf, wf.close) 233 shell.StartActivity('MojoShellActivity', arguments, wf, wf.close)
238 output = rf.read() 234 output = rf.read()
239 except Exception as e: 235 except Exception as e:
240 output += (e.output + '\n') if hasattr(e, 'output') else '' 236 output += (e.output + '\n') if hasattr(e, 'output') else ''
241 exception += str(e) 237 exception += str(e)
242 result.put((output, exception)) 238 result.put((output, exception))
OLDNEW
« no previous file with comments | « mojo/tools/apptest_runner.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698