Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 collections | 8 import collections |
| 9 import os | 9 import os |
| 10 import stat | 10 import stat |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 # Many tests assume a English interface... | 76 # Many tests assume a English interface... |
| 77 env['LANG'] = 'en_US.UTF-8' | 77 env['LANG'] = 'en_US.UTF-8' |
| 78 # Used by base/base_paths_linux.cc as an override. Just make sure the default | 78 # Used by base/base_paths_linux.cc as an override. Just make sure the default |
| 79 # logic is used. | 79 # logic is used. |
| 80 env.pop('CR_SOURCE_ROOT', None) | 80 env.pop('CR_SOURCE_ROOT', None) |
| 81 enable_sandbox_if_required(cmd, env) | 81 enable_sandbox_if_required(cmd, env) |
| 82 | 82 |
| 83 # Copy logic from tools/build/scripts/slave/runtest.py. | 83 # Copy logic from tools/build/scripts/slave/runtest.py. |
| 84 asan = '--asan=1' in cmd | 84 asan = '--asan=1' in cmd |
| 85 lsan = '--lsan=1' in cmd | 85 lsan = '--lsan=1' in cmd |
| 86 if lsan and sys.platform == 'linux2': | |
| 87 # Use the debug version of libstdc++ under LSan. If we don't, there will | |
| 88 # be a lot of incomplete stack traces in the reports. | |
| 89 env['LD_LIBRARY_PATH'] = '/usr/lib/x86_64-linux-gnu/debug:' | |
| 90 | 86 |
| 91 if asan and sys.platform == 'darwin': | 87 if asan: |
|
M-A Ruel
2014/10/14 23:38:51
I think it's large enough I'd make it a function a
jam
2014/10/15 03:20:48
Done.
| |
| 92 isolate_output_dir = os.path.abspath(os.path.dirname(cmd[0])) | 88 # Instruct GTK to use malloc while running ASan, TSan, MSan or LSan tests. |
| 93 # This is needed because the test binary has @executable_path embedded in it | 89 env['G_SLICE'] = 'always-malloc' |
| 94 # that the OS tries to resolve to the cache directory and not the mapped | 90 env['NSS_DISABLE_ARENA_FREE_LIST'] = '1' |
| 95 # directory. | 91 env['NSS_DISABLE_UNLOAD'] = '1' |
| 96 env['DYLD_LIBRARY_PATH'] = str(isolate_output_dir) | 92 |
| 93 # TODO(glider): remove the symbolizer path once | |
| 94 # https://code.google.com/p/address-sanitizer/issues/detail?id=134 is fixed. | |
| 95 symbolizer_path = os.path.abspath(os.path.join('..', 'third_party', | |
| 96 'llvm-build', 'Release+Asserts', 'bin', 'llvm-symbolizer')) | |
| 97 | |
| 98 asan_options = [] | |
| 99 if lsan: | |
| 100 asan_options += ['detect_leaks=1'] | |
|
M-A Ruel
2014/10/14 23:38:51
I really prefer:
asan_options.append('detect_leaks
jam
2014/10/15 03:20:48
Done.
| |
| 101 if sys.platform == 'linux2': | |
| 102 # Use the debug version of libstdc++ under LSan. If we don't, there will | |
| 103 # be a lot of incomplete stack traces in the reports. | |
| 104 env['LD_LIBRARY_PATH'] = '/usr/lib/x86_64-linux-gnu/debug:' | |
|
M-A Ruel
2014/10/14 23:38:51
[General comment] It'd be nice to have these addit
jam
2014/10/15 03:20:48
Done.
| |
| 105 | |
| 106 # LSan is not sandbox-compatible, so we can use online symbolization. In | |
| 107 # fact, it needs symbolization to be able to apply suppressions. | |
| 108 symbolization_options = ['symbolize=1', | |
| 109 'external_symbolizer_path=%s' % symbolizer_path] | |
| 110 | |
| 111 lsan_options = ['suppressions=../tools/lsan/suppressions.txt', | |
|
M-A Ruel
2014/10/14 23:38:51
The relative path could be wrong; it's relative to
jam
2014/10/15 03:20:48
Done.
| |
| 112 'print_suppressions=1'] | |
| 113 env['LSAN_OPTIONS'] = ' '.join(lsan_options) | |
| 114 else: | |
| 115 # ASan uses a script for offline symbolization. | |
| 116 # Important note: when running ASan with leak detection enabled, we must | |
| 117 # use the LSan symbolization options above. | |
| 118 symbolization_options = ['symbolize=0'] | |
| 119 asan_options = symbolization_options | |
| 120 | |
| 121 env['ASAN_OPTIONS'] = ' '.join(asan_options) | |
| 122 | |
| 123 if sys.platform == 'darwin': | |
| 124 isolate_output_dir = os.path.abspath(os.path.dirname(cmd[0])) | |
| 125 # This is needed because the test binary has @executable_path embedded in | |
| 126 # it that the OS tries to resolve to the cache directory and not the | |
| 127 # mapped directory. | |
| 128 env['DYLD_LIBRARY_PATH'] = str(isolate_output_dir) | |
| 97 | 129 |
| 98 # Ensure paths are correctly separated on windows. | 130 # Ensure paths are correctly separated on windows. |
| 99 cmd[0] = cmd[0].replace('/', os.path.sep) | 131 cmd[0] = cmd[0].replace('/', os.path.sep) |
| 100 cmd = fix_python_path(cmd) | 132 cmd = fix_python_path(cmd) |
| 101 try: | 133 try: |
| 102 if asan: | 134 # See above comment regarding offline symbolization. |
| 135 if asan and not lsan: | |
| 103 # Need to pipe to the symbolizer script. | 136 # Need to pipe to the symbolizer script. |
| 104 p1 = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, | 137 p1 = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, |
| 105 stderr=sys.stdout) | 138 stderr=sys.stdout) |
| 106 p2 = subprocess.Popen(["../tools/valgrind/asan/asan_symbolize.py"], | 139 p2 = subprocess.Popen(["../tools/valgrind/asan/asan_symbolize.py"], |
| 107 stdin=p1.stdout) | 140 stdin=p1.stdout) |
| 108 p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. | 141 p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. |
| 109 p2.wait() | 142 p2.wait() |
| 110 return p2.returncode | 143 return p2.returncode |
| 111 else: | 144 else: |
| 112 return subprocess.call(cmd, env=env) | 145 return subprocess.call(cmd, env=env) |
| 113 except OSError: | 146 except OSError: |
| 114 print >> sys.stderr, 'Failed to start %s' % cmd | 147 print >> sys.stderr, 'Failed to start %s' % cmd |
| 115 raise | 148 raise |
| 116 | 149 |
| 117 | 150 |
| 118 def main(): | 151 def main(): |
| 119 return run_executable(sys.argv[1:], os.environ.copy()) | 152 return run_executable(sys.argv[1:], os.environ.copy()) |
| 120 | 153 |
| 121 | 154 |
| 122 if __name__ == '__main__': | 155 if __name__ == '__main__': |
| 123 sys.exit(main()) | 156 sys.exit(main()) |
| OLD | NEW |