Skip to content

Commit

Permalink
Fix ASAN execution for the MLIR Python tests
Browse files Browse the repository at this point in the history
First the leak sanitizer has to be disabled, as even an empty script
leads to leak detection with Python.
Then we need to preload the ASAN runtime, as the main binary (python)
won't be linked against it. This will only work on Linux right now.

Differential Revision: https://reviews.llvm.org/D111004
  • Loading branch information
joker-eph committed Oct 3, 2021
1 parent 86f5028 commit bce0c64
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 10 additions & 1 deletion mlir/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@

# The following tools are optional
tools.extend([
ToolSubst('%PYTHON', config.python_executable, unresolved='ignore'),
ToolSubst('toy-ch1', unresolved='ignore'),
ToolSubst('toy-ch2', unresolved='ignore'),
ToolSubst('toy-ch3', unresolved='ignore'),
Expand All @@ -80,6 +79,16 @@
ToolSubst('%vulkan_wrapper_library_dir', config.vulkan_wrapper_library_dir, unresolved='ignore'),
ToolSubst('%mlir_integration_test_dir', config.mlir_integration_test_dir, unresolved='ignore'),
])

python_executable = config.python_executable
# Python configuration with sanitizer requires some magic preloading. This will only work on clang/linux.
# TODO: detect Darwin/Windows situation (or mark these tests as unsupported on these platforms).
if "asan" in config.available_features and "Linux" in config.host_os:
python_executable = f"LD_PRELOAD=$({config.host_cxx} -print-file-name=libclang_rt.asan-{config.host_arch}.so) {config.python_executable}"
tools.extend([
ToolSubst('%PYTHON', python_executable, unresolved='ignore'),
])

llvm_config.add_tool_substitutions(tools, tool_dirs)


Expand Down
6 changes: 1 addition & 5 deletions mlir/test/python/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# Disable with sanitizers for now, this require some more setup apparently.
for san in ['asan', 'msan', 'ubsan']:
if (san in config.available_features):
config.unsupported = True

config.environment['ASAN_OPTIONS'] = 'detect_leaks=0'
if not config.enable_bindings_python:
config.unsupported = True
config.excludes.add('python_test_ops.td')

0 comments on commit bce0c64

Please sign in to comment.