Chromium Code Reviews| Index: testing/test_env.py |
| diff --git a/testing/test_env.py b/testing/test_env.py |
| index 2c39508c438d2e9074c10aad29f4c845c380464b..ab311c969967749d0b8817805b283fbb2ed705ff 100755 |
| --- a/testing/test_env.py |
| +++ b/testing/test_env.py |
| @@ -5,7 +5,6 @@ |
| """Sets environment variables needed to run a chromium unit test.""" |
| -import collections |
| import os |
| import stat |
| import subprocess |
| @@ -39,7 +38,7 @@ def should_enable_sandbox(cmd, sandbox_path): |
| return False |
| -def enable_sandbox_if_required(cmd, env, verbose=False): |
| +def enable_sandbox_if_required(cmd, env, extra_env, verbose=False): |
| """Checks enables the sandbox if it is required, otherwise it disables it.""" |
| chrome_sandbox_path = env.get(CHROME_SANDBOX_ENV, CHROME_SANDBOX_PATH) |
| @@ -47,12 +46,21 @@ def enable_sandbox_if_required(cmd, env, verbose=False): |
| if verbose: |
| print 'Enabling sandbox. Setting environment variable:' |
| print ' %s="%s"' % (CHROME_SANDBOX_ENV, chrome_sandbox_path) |
| - env[CHROME_SANDBOX_ENV] = chrome_sandbox_path |
| + extra_env[CHROME_SANDBOX_ENV] = chrome_sandbox_path |
| else: |
| if verbose: |
| print 'Disabling sandbox. Setting environment variable:' |
| print ' CHROME_DEVEL_SANDBOX=""' |
| - env['CHROME_DEVEL_SANDBOX'] = '' |
| + extra_env['CHROME_DEVEL_SANDBOX'] = '' |
|
earthdok
2014/10/15 14:11:45
This is not good. Please pass --no-sandbox, like w
jam
2014/10/15 15:23:25
run_test.py also unsets CHROME_DEVEL_SANDBOX. so i
earthdok
2014/10/15 17:00:37
Looking at this conditional in runtest.py, there a
jam
2014/10/15 17:23:49
good point. I added it.
|
| + |
| + |
| +def trim_cmd(cmd): |
| + # Remove these flags from cmd since they're just used to communicate from the |
| + # host machine to this script running on the swarm slaves. |
| + internal_commands = ['--asan=0', '--asan=1', '--lsan=0', '--lsan=1'] |
|
M-A Ruel
2014/10/15 13:08:00
internal_commands = frozenset(['--asan=0', '--asan
jam
2014/10/15 15:23:25
Done.
|
| + for i in internal_commands: |
| + if i in cmd: |
| + cmd.remove(i) |
|
jam
2014/10/15 03:20:48
Marc-Antoine: I added this method to remove the ex
|
| def fix_python_path(cmd): |
| @@ -65,6 +73,57 @@ def fix_python_path(cmd): |
| return out |
| +def setup_asan(cmd, extra_env, lsan): |
|
M-A Ruel
2014/10/15 13:07:59
I also prefer it to create a extra_env locally and
jam
2014/10/15 15:23:25
Done. also enable_sandbox_if_required
|
| + # Instruct GTK to use malloc while running ASan or LSan tests. |
|
M-A Ruel
2014/10/15 13:07:59
"""Instructs GTK ... "
jam
2014/10/15 15:23:25
that would be for the function comment right? this
|
| + |
| + # TODO(earthdok): enabling G_SLICE gives these leaks, locally and on swarming |
| + #0 0x62c01b in __interceptor_malloc (/tmp/run_tha_testXukBDT/out/Release/browser_tests+0x62c01b) |
| + #1 0x7fb64ab64a38 in g_malloc /build/buildd/glib2.0-2.32.4/./glib/gmem.c:159 |
| + |
| + #extra_env['G_SLICE'] = 'always-malloc' |
|
jam
2014/10/15 03:20:48
Sergey: I don't know why I get these leaks with G_
earthdok
2014/10/15 14:11:45
I'll take a look. It's possible that someone intro
earthdok
2014/10/15 19:57:35
Could you please link to a test run where they rep
|
| + extra_env['NSS_DISABLE_ARENA_FREE_LIST'] = '1' |
| + extra_env['NSS_DISABLE_UNLOAD'] = '1' |
| + |
| + # TODO(glider): remove the symbolizer path once |
| + # https://code.google.com/p/address-sanitizer/issues/detail?id=134 is fixed. |
| + symbolizer_path = os.path.abspath(os.path.join(ROOT_DIR, 'third_party', |
| + 'llvm-build', 'Release+Asserts', 'bin', 'llvm-symbolizer')) |
| + |
| + asan_options = [] |
| + if lsan: |
| + asan_options.append('detect_leaks=1') |
| + if sys.platform == 'linux2': |
| + # Use the debug version of libstdc++ under LSan. If we don't, there will |
| + # be a lot of incomplete stack traces in the reports. |
| + extra_env['LD_LIBRARY_PATH'] = '/usr/lib/x86_64-linux-gnu/debug:' |
|
earthdok
2014/10/15 14:11:45
So this is probably useless to you. This points to
earthdok
2014/10/15 14:35:56
On second thought, let's change this to point to t
jam
2014/10/15 15:23:25
I just checked and the swarm slaves, based on conn
earthdok
2014/10/15 17:00:37
But does that directory contain libstc++ DSOs?
jam
2014/10/15 17:23:49
yep
chrome-bot@swarm126-c4:~$ ls /usr/lib/x86_64-
|
| + |
| + # LSan is not sandbox-compatible, so we can use online symbolization. In |
| + # fact, it needs symbolization to be able to apply suppressions. |
| + symbolization_options = ['symbolize=1', |
| + 'external_symbolizer_path=%s' % symbolizer_path] |
| + |
| + suppressions_file = os.path.join(ROOT_DIR, 'tools', 'lsan', |
| + 'suppressions.txt') |
| + lsan_options = ['suppressions=%s' % suppressions_file, |
| + 'print_suppressions=1'] |
| + extra_env['LSAN_OPTIONS'] = ' '.join(lsan_options) |
| + else: |
| + # ASan uses a script for offline symbolization. |
| + # Important note: when running ASan with leak detection enabled, we must use |
| + # the LSan symbolization options above. |
| + symbolization_options = ['symbolize=0'] |
| + |
| + asan_options.extend(symbolization_options) |
| + |
| + extra_env['ASAN_OPTIONS'] = ' '.join(asan_options) |
| + |
| + if sys.platform == 'darwin': |
| + isolate_output_dir = os.path.abspath(os.path.dirname(cmd[0])) |
| + # This is needed because the test binary has @executable_path embedded in it |
| + # it that the OS tries to resolve to the cache directory and not the mapped |
| + # directory. |
| + extra_env['DYLD_LIBRARY_PATH'] = str(isolate_output_dir) |
| + |
|
M-A Ruel
2014/10/15 13:08:00
two lines
jam
2014/10/15 15:23:25
Done.
|
| def run_executable(cmd, env): |
| """Runs an executable with: |
| - environment variable CR_SOURCE_ROOT set to the root directory. |
| @@ -72,34 +131,33 @@ def run_executable(cmd, env): |
| - environment variable CHROME_DEVEL_SANDBOX set if need |
| - Reuses sys.executable automatically. |
| """ |
| - env = collections.defaultdict(str, env) |
| + extra_env = {} |
| # Many tests assume a English interface... |
| - env['LANG'] = 'en_US.UTF-8' |
| + extra_env['LANG'] = 'en_US.UTF-8' |
| # Used by base/base_paths_linux.cc as an override. Just make sure the default |
| # logic is used. |
| env.pop('CR_SOURCE_ROOT', None) |
| - enable_sandbox_if_required(cmd, env) |
| + enable_sandbox_if_required(cmd, env, extra_env) |
| # Copy logic from tools/build/scripts/slave/runtest.py. |
| asan = '--asan=1' in cmd |
| lsan = '--lsan=1' in cmd |
| - if lsan and sys.platform == 'linux2': |
| - # Use the debug version of libstdc++ under LSan. If we don't, there will |
| - # be a lot of incomplete stack traces in the reports. |
| - env['LD_LIBRARY_PATH'] = '/usr/lib/x86_64-linux-gnu/debug:' |
| - if asan and sys.platform == 'darwin': |
| - isolate_output_dir = os.path.abspath(os.path.dirname(cmd[0])) |
| - # This is needed because the test binary has @executable_path embedded in it |
| - # that the OS tries to resolve to the cache directory and not the mapped |
| - # directory. |
| - env['DYLD_LIBRARY_PATH'] = str(isolate_output_dir) |
| + if asan: |
| + setup_asan(cmd, extra_env, lsan) |
| + |
| + trim_cmd(cmd) |
| # Ensure paths are correctly separated on windows. |
| cmd[0] = cmd[0].replace('/', os.path.sep) |
| cmd = fix_python_path(cmd) |
| + |
| + print 'test_env.py running with\n Additional test environment: %s\n' \ |
| + ' Command: %s\n' % (str(extra_env), str(cmd)) |
|
jam
2014/10/15 03:20:48
Marc-Antoine: Sergey brought up a good point over
M-A Ruel
2014/10/15 13:08:00
Ok, I'd prefer something like:
print('test_env.py
jam
2014/10/15 15:23:25
Done.
|
| + env.update(extra_env or {}) |
| try: |
| - if asan: |
| + # See above comment regarding offline symbolization. |
| + if asan and not lsan: |
| # Need to pipe to the symbolizer script. |
| p1 = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, |
| stderr=sys.stdout) |