Enable torch-mlir LIT tests in Bazel (#1585)

Adds support to run `.mlir` LIT tests in bazel. 

```
bazel test @torch-mlir//test/...
```

Follow-on PR will contain these updates:
- Add tests to GHA CI workflow
- Add `.py` LIT tests to bazel
pull/1593/head
Sambhav Jain 2022-11-15 14:02:19 -08:00 committed by GitHub
parent 4032eeca64
commit fc4c8d4ed9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 88 additions and 1 deletions

View File

@ -63,7 +63,7 @@ llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
if "Windows" in config.host_os: if "Windows" in config.host_os:
config.python_executable = '"%s"' % (config.python_executable) config.python_executable = '"%s"' % (config.python_executable)
tool_dirs = [config.standalone_tools_dir, config.llvm_tools_dir] tool_dirs = [config.standalone_tools_dir, config.llvm_tools_dir, config.torch_mlir_obj_root]
tools = [ tools = [
'torch-mlir-opt', 'torch-mlir-opt',
ToolSubst('%PYTHON', config.python_executable, unresolved='ignore'), ToolSubst('%PYTHON', config.python_executable, unresolved='ignore'),

View File

@ -0,0 +1,42 @@
# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@llvm-project//llvm:lit_test.bzl", "lit_test", "package_path")
package(
default_visibility = [
"//visibility:public",
],
)
expand_template(
name = "lit_site_cfg_py",
testonly = True,
out = "lit.site.cfg.py",
substitutions = {
"@LIT_SITE_CFG_IN_HEADER@": "# Autogenerated, do not edit.",
"@TORCH_MLIR_SOURCE_DIR@": package_path("@torch-mlir//:BUILD"),
"\"@TORCH_MLIR_BINARY_DIR@\"": "os.path.join(os.environ['TEST_SRCDIR'], 'torch-mlir')",
"\"@LLVM_TOOLS_DIR@\"": "os.path.join(os.environ['TEST_SRCDIR'], 'llvm-project', 'llvm')",
# All disabled, but required to substituted because they are not in quotes.
"@MLIR_ENABLE_BINDINGS_PYTHON@": "0",
"@TORCH_MLIR_ENABLE_JIT_IR_IMPORTER@": "0",
"@TORCH_MLIR_ENABLE_MHLO@": "0",
},
template = "lit.site.cfg.py.in",
)
# Common data used by most lit tests.
filegroup(
name = "lit_data",
testonly = True,
data = [
"lit.cfg.py",
"lit.site.cfg.py",
"@llvm-project//llvm:FileCheck",
"@llvm-project//llvm:count",
"@llvm-project//llvm:not",
],
)

View File

@ -0,0 +1,15 @@
load("@llvm-project//llvm:lit_test.bzl", "lit_test")
package(default_visibility = ["//visibility:public"])
[
lit_test(
name = "%s.test" % src,
srcs = [src],
data = [
"@torch-mlir//:torch-mlir-opt",
"@torch-mlir//test:lit_data",
],
)
for src in glob(["**/*.mlir"])
]

View File

@ -0,0 +1,15 @@
load("@llvm-project//llvm:lit_test.bzl", "lit_test")
package(default_visibility = ["//visibility:public"])
[
lit_test(
name = "%s.test" % src,
srcs = [src],
data = [
"@torch-mlir//:torch-mlir-opt",
"@torch-mlir//test:lit_data",
],
)
for src in glob(["**/*.mlir"])
]

View File

@ -0,0 +1,15 @@
load("@llvm-project//llvm:lit_test.bzl", "lit_test")
package(default_visibility = ["//visibility:public"])
[
lit_test(
name = "%s.test" % src,
srcs = [src],
data = [
"@torch-mlir//:torch-mlir-opt",
"@torch-mlir//test:lit_data",
],
)
for src in glob(["**/*.mlir"])
]