[PATCH] D109574: Add bazel lit test macros.

Christian Sigg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 10 05:53:16 PDT 2021


csigg updated this revision to Diff 371902.
csigg added a comment.

Wrap repo-local targets in 'Label()'.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109574/new/

https://reviews.llvm.org/D109574

Files:
  utils/bazel/llvm-project-overlay/llvm/lit.bzl


Index: utils/bazel/llvm-project-overlay/llvm/lit.bzl
===================================================================
--- /dev/null
+++ utils/bazel/llvm-project-overlay/llvm/lit.bzl
@@ -0,0 +1,76 @@
+# 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
+
+"""Lit runner macros"""
+
+def glob_lit_tests(
+        test_file_exts = [],
+        exclude = [],
+        data = [],
+        per_test_extra_data = {},
+        default_size = "small",
+        size_override = {},
+        default_tags = [],
+        tags_override = {},
+        **kwargs):
+    """Creates all plausible Lit tests (and their inputs) in this package.
+
+    Args:
+      test_file_exts: [str], extensions for files that are tests.
+      exclude: [str], paths to exclude (for tests and inputs).
+      data: [str], additional input data to the test.
+      per_test_extra_data: {str: [str]}, extra data to attach to a given file.
+      default_size: str, the test size for targets not in "size_override".
+      size_override: {str: str}, sizes to use for specific tests.
+      default_tags: [str], additional tags to attach to the test.
+      tags_override: {str: str}, tags to add to specific tests.
+      **kwargs: arguments to pass on to lit_test()
+    """
+
+    include = ["**/*." + ext for ext in test_file_exts]
+    for test in native.glob(include, exclude):
+        lit_test(
+            name = test,
+            data = data + per_test_extra_data.get(test, []),
+            size = size_override.get(test, default_size),
+            tags = default_tags + tags_override.get(test, []),
+            **kwargs
+        )
+
+def lit_test(
+        name,
+        data = [],
+        size = "small",
+        features = [],
+        driver = None,
+        **kwargs):
+    """Runs test files under lit.
+
+    Args:
+      name: str, the relative path to the file to test.
+      data: [label], labels that should be provided as data inputs.
+      size: str, the size of the test.
+      features: [str], list of extra arguments to pass to lit.
+      driver: unsupported, must be None.
+      **kwargs: arguments to pass on to py_test.
+    """
+    if driver:
+        fail("lit_test() does not currently support a custom driver.")
+
+    native.py_test(
+        name = name + ".test",
+        srcs = [Label("//llvm:lit")],
+        args = [
+            "$(location " + name + ")",
+        ] + features,
+        data = [
+            name,
+            Label("//llvm:FileCheck"),
+            Label("//llvm:count"),
+            Label("//llvm:not"),
+        ] + data,
+        size = size,
+        main = "lit.py",
+        **kwargs
+    )


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109574.371902.patch
Type: text/x-patch
Size: 2784 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210910/da3981d2/attachment.bin>


More information about the llvm-commits mailing list