[PATCH] D109574: Add bazel lit test macros.

Christian Sigg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 10 01:01:07 PDT 2021


csigg created this revision.
csigg added a reviewer: GMNGeoffrey.
Herald added a subscriber: sanjoy.google.
csigg requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

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,78 @@
+# 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, []),
+            driver = driver,
+            features = features,
+            exec_properties = exec_properties,
+        )
+
+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 = ["//llvm:lit"],
+        args = [
+            "$(location " + name + ")",
+        ] + features,
+        data = [
+            name,
+            "//llvm:FileCheck",
+            "//llvm:count",
+            "//llvm:not",
+        ] + data,
+        size = size,
+        main = "lit.py",
+        **kwargs
+    )


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


More information about the llvm-commits mailing list