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

Side by Side Diff: testing/test_env.py

Issue 880053003: Remove obsolete sandbox disabling logic from testing/test_env.py. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 | « no previous file | 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Sets environment variables needed to run a chromium unit test.""" 6 """Sets environment variables needed to run a chromium unit test."""
7 7
8 import os 8 import os
9 import stat 9 import stat
10 import subprocess 10 import subprocess
11 import sys 11 import sys
12 12
13 # This is hardcoded to be src/ relative to this script. 13 # This is hardcoded to be src/ relative to this script.
14 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 14 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
15 15
16 CHROME_SANDBOX_ENV = 'CHROME_DEVEL_SANDBOX' 16 CHROME_SANDBOX_ENV = 'CHROME_DEVEL_SANDBOX'
17 CHROME_SANDBOX_PATH = '/opt/chromium/chrome_sandbox' 17 CHROME_SANDBOX_PATH = '/opt/chromium/chrome_sandbox'
18 18
19 19
20 def should_enable_sandbox(cmd, sandbox_path): 20 def get_sandbox_env(env):
21 """Return a boolean indicating that the current slave is capable of using the
22 sandbox and should enable it. This should return True iff the slave is a
23 Linux host with the sandbox file present and configured correctly."""
24 if not (sys.platform.startswith('linux') and
25 os.path.exists(sandbox_path)):
26 return False
27
28 # Copy the check in tools/build/scripts/slave/runtest.py.
29 if '--lsan=1' in cmd:
30 return False
31
32 sandbox_stat = os.stat(sandbox_path)
33 if ((sandbox_stat.st_mode & stat.S_ISUID) and
34 (sandbox_stat.st_mode & stat.S_IRUSR) and
35 (sandbox_stat.st_mode & stat.S_IXUSR) and
36 (sandbox_stat.st_uid == 0)):
37 return True
38 return False
39
40
41 def get_sandbox_env(cmd, env, verbose=False):
42 """Checks enables the sandbox if it is required, otherwise it disables it. 21 """Checks enables the sandbox if it is required, otherwise it disables it.
jln (very slow on Chromium) 2015/01/27 20:19:48 This comment doesn't seem to match what we wish to
earthdok 2015/01/27 20:44:44 Done.
43 Returns the environment flags to set.""" 22 Returns the environment flags to set."""
44 extra_env = {} 23 extra_env = {}
45 chrome_sandbox_path = env.get(CHROME_SANDBOX_ENV, CHROME_SANDBOX_PATH) 24 chrome_sandbox_path = env.get(CHROME_SANDBOX_ENV, CHROME_SANDBOX_PATH)
jln (very slow on Chromium) 2015/01/27 20:19:48 Could you add a check that CHROME_SANDBOX_ENV is n
earthdok 2015/01/27 20:44:44 Done.
46 25 extra_env[CHROME_SANDBOX_ENV] = chrome_sandbox_path
47 if should_enable_sandbox(cmd, chrome_sandbox_path):
48 if verbose:
49 print 'Enabling sandbox. Setting environment variable:'
50 print ' %s="%s"' % (CHROME_SANDBOX_ENV, chrome_sandbox_path)
51 extra_env[CHROME_SANDBOX_ENV] = chrome_sandbox_path
52 else:
53 if verbose:
54 print 'Disabling sandbox. Setting environment variable:'
55 print ' CHROME_DEVEL_SANDBOX=""'
56 extra_env['CHROME_DEVEL_SANDBOX'] = ''
57 26
58 return extra_env 27 return extra_env
59 28
60 29
61 def trim_cmd(cmd): 30 def trim_cmd(cmd):
62 """Removes internal flags from cmd since they're just used to communicate from 31 """Removes internal flags from cmd since they're just used to communicate from
63 the host machine to this script running on the swarm slaves.""" 32 the host machine to this script running on the swarm slaves."""
64 internal_flags = frozenset(['--asan=0', '--asan=1', '--lsan=0', '--lsan=1']) 33 internal_flags = frozenset(['--asan=0', '--asan=1', '--lsan=0', '--lsan=1'])
65 return [i for i in cmd if i not in internal_flags] 34 return [i for i in cmd if i not in internal_flags]
66 35
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 # directory. 97 # directory.
129 extra_env['DYLD_LIBRARY_PATH'] = str(isolate_output_dir) 98 extra_env['DYLD_LIBRARY_PATH'] = str(isolate_output_dir)
130 99
131 return extra_env 100 return extra_env
132 101
133 102
134 def run_executable(cmd, env): 103 def run_executable(cmd, env):
135 """Runs an executable with: 104 """Runs an executable with:
136 - environment variable CR_SOURCE_ROOT set to the root directory. 105 - environment variable CR_SOURCE_ROOT set to the root directory.
137 - environment variable LANGUAGE to en_US.UTF-8. 106 - environment variable LANGUAGE to en_US.UTF-8.
138 - environment variable CHROME_DEVEL_SANDBOX set if need 107 - environment variable CHROME_DEVEL_SANDBOX set
139 - Reuses sys.executable automatically. 108 - Reuses sys.executable automatically.
140 """ 109 """
141 extra_env = {} 110 extra_env = {}
142 # Many tests assume a English interface... 111 # Many tests assume a English interface...
143 extra_env['LANG'] = 'en_US.UTF-8' 112 extra_env['LANG'] = 'en_US.UTF-8'
144 # Used by base/base_paths_linux.cc as an override. Just make sure the default 113 # Used by base/base_paths_linux.cc as an override. Just make sure the default
145 # logic is used. 114 # logic is used.
146 env.pop('CR_SOURCE_ROOT', None) 115 env.pop('CR_SOURCE_ROOT', None)
147 extra_env.update(get_sandbox_env(cmd, env)) 116 extra_env.update(get_sandbox_env(env))
148 117
149 # Copy logic from tools/build/scripts/slave/runtest.py. 118 # Copy logic from tools/build/scripts/slave/runtest.py.
150 asan = '--asan=1' in cmd 119 asan = '--asan=1' in cmd
151 lsan = '--lsan=1' in cmd 120 lsan = '--lsan=1' in cmd
152 121
153 if asan: 122 if asan:
154 extra_env.update(get_asan_env(cmd, lsan)) 123 extra_env.update(get_asan_env(cmd, lsan))
155 if lsan: 124 if lsan:
156 cmd.append('--no-sandbox') 125 cmd.append('--no-sandbox')
157 126
(...skipping 27 matching lines...) Expand all
185 print >> sys.stderr, 'Failed to start %s' % cmd 154 print >> sys.stderr, 'Failed to start %s' % cmd
186 raise 155 raise
187 156
188 157
189 def main(): 158 def main():
190 return run_executable(sys.argv[1:], os.environ.copy()) 159 return run_executable(sys.argv[1:], os.environ.copy())
191 160
192 161
193 if __name__ == '__main__': 162 if __name__ == '__main__':
194 sys.exit(main()) 163 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698