summaryrefslogtreecommitdiff
path: root/chromium/testing/test_env.py
diff options
context:
space:
mode:
authorZeno Albisser <zeno.albisser@theqtcompany.com>2014-12-05 15:04:29 +0100
committerAndras Becsi <andras.becsi@theqtcompany.com>2014-12-09 10:49:28 +0100
commitaf6588f8d723931a298c995fa97259bb7f7deb55 (patch)
tree060ca707847ba1735f01af2372e0d5e494dc0366 /chromium/testing/test_env.py
parent2fff84d821cc7b1c785f6404e0f8091333283e74 (diff)
downloadqtwebengine-chromium-af6588f8d723931a298c995fa97259bb7f7deb55.tar.gz
BASELINE: Update chromium to 40.0.2214.28 and ninja to 1.5.3.
Change-Id: I759465284fd64d59ad120219cbe257f7402c4181 Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Diffstat (limited to 'chromium/testing/test_env.py')
-rwxr-xr-xchromium/testing/test_env.py129
1 files changed, 115 insertions, 14 deletions
diff --git a/chromium/testing/test_env.py b/chromium/testing/test_env.py
index ec98a11ce61..4c194277bf3 100755
--- a/chromium/testing/test_env.py
+++ b/chromium/testing/test_env.py
@@ -17,13 +17,18 @@ CHROME_SANDBOX_ENV = 'CHROME_DEVEL_SANDBOX'
CHROME_SANDBOX_PATH = '/opt/chromium/chrome_sandbox'
-def should_enable_sandbox(sandbox_path):
+def should_enable_sandbox(cmd, sandbox_path):
"""Return a boolean indicating that the current slave is capable of using the
sandbox and should enable it. This should return True iff the slave is a
Linux host with the sandbox file present and configured correctly."""
if not (sys.platform.startswith('linux') and
os.path.exists(sandbox_path)):
return False
+
+ # Copy the check in tools/build/scripts/slave/runtest.py.
+ if '--lsan=1' in cmd:
+ return False
+
sandbox_stat = os.stat(sandbox_path)
if ((sandbox_stat.st_mode & stat.S_ISUID) and
(sandbox_stat.st_mode & stat.S_IRUSR) and
@@ -33,23 +38,31 @@ def should_enable_sandbox(sandbox_path):
return False
-def enable_sandbox_if_required(env, verbose=False):
- """Checks enables the sandbox if it is required, otherwise it disables it."""
+def get_sandbox_env(cmd, env, verbose=False):
+ """Checks enables the sandbox if it is required, otherwise it disables it.
+ Returns the environment flags to set."""
+ extra_env = {}
chrome_sandbox_path = env.get(CHROME_SANDBOX_ENV, CHROME_SANDBOX_PATH)
- if should_enable_sandbox(chrome_sandbox_path):
+ if should_enable_sandbox(cmd, chrome_sandbox_path):
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 'Sandbox not properly installed. Unsetting:'
- print ' %s' % CHROME_SANDBOX_ENV
- # The variable should be removed from the environment, making
- # the variable empty silently disables the sandbox.
- if env.get(CHROME_SANDBOX_ENV):
- env.pop(CHROME_SANDBOX_ENV)
+ print 'Disabling sandbox. Setting environment variable:'
+ print ' CHROME_DEVEL_SANDBOX=""'
+ extra_env['CHROME_DEVEL_SANDBOX'] = ''
+
+ return extra_env
+
+
+def trim_cmd(cmd):
+ """Removes internal flags from cmd since they're just used to communicate from
+ the host machine to this script running on the swarm slaves."""
+ internal_flags = frozenset(['--asan=0', '--asan=1', '--lsan=0', '--lsan=1'])
+ return [i for i in cmd if i not in internal_flags]
def fix_python_path(cmd):
@@ -62,6 +75,62 @@ def fix_python_path(cmd):
return out
+def get_asan_env(cmd, lsan):
+ """Returns the envirnoment flags needed for ASan and LSan."""
+
+ extra_env = {}
+
+ # Instruct GTK to use malloc while running ASan or LSan tests.
+ extra_env['G_SLICE'] = 'always-malloc'
+
+ 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:'
+
+ # 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']
+ # Set the path to llvm-symbolizer to be used by asan_symbolize.py
+ extra_env['LLVM_SYMBOLIZER_PATH'] = symbolizer_path
+
+ 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)
+
+ return extra_env
+
+
def run_executable(cmd, env):
"""Runs an executable with:
- environment variable CR_SOURCE_ROOT set to the root directory.
@@ -69,17 +138,49 @@ def run_executable(cmd, env):
- environment variable CHROME_DEVEL_SANDBOX set if need
- Reuses sys.executable automatically.
"""
+ 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(env)
+ extra_env.update(get_sandbox_env(cmd, env))
+
+ # Copy logic from tools/build/scripts/slave/runtest.py.
+ asan = '--asan=1' in cmd
+ lsan = '--lsan=1' in cmd
+
+ if asan:
+ extra_env.update(get_asan_env(cmd, lsan))
+ if lsan:
+ cmd.append('--no-sandbox')
+
+ cmd = trim_cmd(cmd)
+
# Ensure paths are correctly separated on windows.
cmd[0] = cmd[0].replace('/', os.path.sep)
cmd = fix_python_path(cmd)
+
+ print('Additional test environment:\n%s\n'
+ 'Command: %s\n' % (
+ '\n'.join(' %s=%s' %
+ (k, v) for k, v in sorted(extra_env.iteritems())),
+ ' '.join(cmd)))
+ env.update(extra_env or {})
try:
- return subprocess.call(cmd, env=env)
+ # 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)
+ p2 = subprocess.Popen(["../tools/valgrind/asan/asan_symbolize.py"],
+ env=env, stdin=p1.stdout)
+ p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
+ p1.wait()
+ p2.wait()
+ return p1.returncode
+ else:
+ return subprocess.call(cmd, env=env)
except OSError:
print >> sys.stderr, 'Failed to start %s' % cmd
raise