|
18 | 18 |
|
19 | 19 | # Configuration file for the 'lit' test runner. |
20 | 20 |
|
| 21 | + |
| 22 | +# Find path to the ASan runtime required for the Python interpreter. |
| 23 | +def find_asan_runtime(): |
| 24 | + if not "asan" in config.available_features or not "Linux" in config.host_os: |
| 25 | + return "" |
| 26 | + # Find the asan rt lib |
| 27 | + return ( |
| 28 | + subprocess.check_output( |
| 29 | + [ |
| 30 | + config.host_cxx.strip(), |
| 31 | + f"-print-file-name=libclang_rt.asan-{config.host_arch}.so", |
| 32 | + ] |
| 33 | + ) |
| 34 | + .decode("utf-8") |
| 35 | + .strip() |
| 36 | + ) |
| 37 | + |
| 38 | + |
21 | 39 | # name: The name of this test suite. |
22 | 40 | config.name = "TORCH_MLIR_PYTHON" |
23 | 41 |
|
|
37 | 55 | # test_exec_root: The root path where tests should be run. |
38 | 56 | config.test_exec_root = os.path.join(config.torch_mlir_obj_root, "test") |
39 | 57 |
|
| 58 | +# Python configuration with sanitizer requires some magic preloading. This will only work on clang/linux. |
| 59 | +# TODO: detect Darwin/Windows situation (or mark these tests as unsupported on these platforms). |
| 60 | +if "asan" in config.available_features and "Linux" in config.host_os: |
| 61 | + _asan_rt = find_asan_runtime() |
| 62 | + config.python_executable = f"env LD_PRELOAD={_asan_rt} {config.python_executable}" |
40 | 63 | # On Windows the path to python could contains spaces in which case it needs to |
41 | 64 | # be provided in quotes. This is the equivalent of how %python is setup in |
42 | 65 | # llvm/utils/lit/lit/llvm/config.py. |
43 | | -if "Windows" in config.host_os: |
| 66 | +elif "Windows" in config.host_os: |
44 | 67 | config.python_executable = '"%s"' % (config.python_executable) |
45 | 68 |
|
46 | 69 | config.substitutions.append(("%PATH%", config.environment["PATH"])) |
|
0 commit comments