[Mlir-commits] [mlir] bce0c64 - Fix ASAN execution for the MLIR Python tests

Mehdi Amini llvmlistbot at llvm.org
Sat Oct 2 22:36:49 PDT 2021


Author: Mehdi Amini
Date: 2021-10-03T05:07:32Z
New Revision: bce0c6429ee3994a7376ab9e40d40477ef43cb31

URL: https://github.com/llvm/llvm-project/commit/bce0c6429ee3994a7376ab9e40d40477ef43cb31
DIFF: https://github.com/llvm/llvm-project/commit/bce0c6429ee3994a7376ab9e40d40477ef43cb31.diff

LOG: Fix ASAN execution for the MLIR Python tests

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

Added: 
    

Modified: 
    mlir/test/lit.cfg.py
    mlir/test/python/lit.local.cfg

Removed: 
    


################################################################################
diff  --git a/mlir/test/lit.cfg.py b/mlir/test/lit.cfg.py
index f6b8be36bbca..2307192e2d7b 100644
--- a/mlir/test/lit.cfg.py
+++ b/mlir/test/lit.cfg.py
@@ -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'),
@@ -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)
 
 

diff  --git a/mlir/test/python/lit.local.cfg b/mlir/test/python/lit.local.cfg
index fc4c9877a0e8..8a98474044e0 100644
--- a/mlir/test/python/lit.local.cfg
+++ b/mlir/test/python/lit.local.cfg
@@ -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')


        


More information about the Mlir-commits mailing list