Geoffrey Martin-Noble | 435c270 | 2022-01-24 15:56:56 -0800 | [diff] [blame] | 1 | # Copyright 2019 The IREE Authors |
| 2 | # |
| 3 | # Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 | # See https://llvm.org/LICENSE.txt for license information. |
| 5 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | |
| 7 | """Bazel macros for running lit tests.""" |
| 8 | |
| 9 | load(":lit_test.bzl", "lit_test", "lit_test_suite") |
| 10 | |
| 11 | def iree_lit_test( |
| 12 | name, |
Scott Todd | 748bcd2 | 2022-05-25 12:18:40 -0700 | [diff] [blame] | 13 | cfg, |
Geoffrey Martin-Noble | 435c270 | 2022-01-24 15:56:56 -0800 | [diff] [blame] | 14 | tools = None, |
| 15 | env = None, |
| 16 | **kwargs): |
| 17 | """A thin wrapper around lit_test with some opinionated settings. |
| 18 | |
| 19 | See the base lit_test for more details on argument meanings. |
| 20 | |
| 21 | Args: |
| 22 | name: name for the test. |
| 23 | cfg: string. lit config file. |
| 24 | tools: label_list. tools that should be included on the PATH. |
| 25 | llvm-symbolizer is added by default. |
| 26 | env: string_dict. Environment variables available to the test at runtime. |
| 27 | FILECHECK_OPTS=--enable-var-scope is added if FILECHECK_OPTS is not |
| 28 | already set. |
| 29 | **kwargs: additional keyword args to forward to the underyling lit_test. |
| 30 | """ |
| 31 | |
| 32 | tools = tools or [] |
| 33 | env = env or {} |
| 34 | |
| 35 | # Always include llvm-symbolizer so we get useful stack traces. Maybe it |
| 36 | # would be better to force everyone to do this explicitly, but since |
| 37 | # forgetting wouldn't cause the test to fail, only make debugging harder |
| 38 | # when it does, I think better to hardcode it here. |
| 39 | llvm_symbolizer = "@llvm-project//llvm:llvm-symbolizer" |
| 40 | if llvm_symbolizer not in tools: |
| 41 | tools.append(llvm_symbolizer) |
| 42 | |
| 43 | filecheck_env_var = "FILECHECK_OPTS" |
| 44 | if filecheck_env_var not in env: |
| 45 | env[filecheck_env_var] = "--enable-var-scope" |
| 46 | |
| 47 | lit_test( |
| 48 | name = name, |
| 49 | cfg = cfg, |
| 50 | tools = tools, |
| 51 | env = env, |
| 52 | **kwargs |
| 53 | ) |
| 54 | |
| 55 | def iree_lit_test_suite( |
| 56 | name, |
Scott Todd | 748bcd2 | 2022-05-25 12:18:40 -0700 | [diff] [blame] | 57 | cfg, |
Geoffrey Martin-Noble | 435c270 | 2022-01-24 15:56:56 -0800 | [diff] [blame] | 58 | tools = None, |
| 59 | env = None, |
| 60 | **kwargs): |
| 61 | """A thin wrapper around lit_test_suite with some opinionated settings. |
| 62 | |
| 63 | See the base lit_test for more details on argument meanings. |
| 64 | |
| 65 | Args: |
| 66 | name: name for the test suite. |
| 67 | cfg: string. lit config file. |
| 68 | tools: label_list. tools that should be included on the PATH. |
| 69 | llvm-symbolizer is added by default. |
| 70 | env: string_dict. Environment variables available to the test at runtime. |
| 71 | FILECHECK_OPTS=--enable-var-scope is added if FILECHECK_OPTS is not |
| 72 | already set. |
| 73 | **kwargs: additional keyword args to forward to the underyling |
| 74 | lit_test_suite. |
| 75 | """ |
| 76 | tools = tools or [] |
| 77 | env = env or {} |
| 78 | |
| 79 | # Always include llvm-symbolizer so we get useful stack traces. Maybe it |
| 80 | # would be better to force everyone to do this explicitly, but since |
| 81 | # forgetting wouldn't cause the test to fail, only make debugging harder |
| 82 | # when it does, I think better to hardcode it here. |
| 83 | llvm_symbolizer = "@llvm-project//llvm:llvm-symbolizer" |
| 84 | if llvm_symbolizer not in tools: |
| 85 | tools.append(llvm_symbolizer) |
| 86 | |
| 87 | filecheck_env_var = "FILECHECK_OPTS" |
| 88 | if filecheck_env_var not in env: |
| 89 | env[filecheck_env_var] = "--enable-var-scope" |
| 90 | |
| 91 | lit_test_suite( |
| 92 | name = name, |
| 93 | cfg = cfg, |
| 94 | tools = tools, |
| 95 | env = env, |
| 96 | **kwargs |
| 97 | ) |