Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 1 | # Copyright 2020 The IREE Authors |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 2 | # |
Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 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 |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 6 | |
| 7 | include(CMakeParseArguments) |
| 8 | |
| 9 | # iree_lit_test() |
| 10 | # |
| 11 | # Creates a lit test for the specified source file. |
| 12 | # |
| 13 | # Mirrors the bzl rule of the same name. |
| 14 | # |
| 15 | # Parameters: |
| 16 | # NAME: Name of the target |
| 17 | # TEST_FILE: Test file to run with the lit runner. |
Geoffrey Martin-Noble | 435c270 | 2022-01-24 15:56:56 -0800 | [diff] [blame] | 18 | # TOOLS: Tools that should be included on the PATH |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 19 | # DATA: Additional data dependencies invoked by the test (e.g. binaries |
| 20 | # called in the RUN line) |
Scott Todd | 2bef720 | 2024-07-30 08:14:38 -0700 | [diff] [blame] | 21 | # LABELS: Additional labels to apply to the test. Package path and |
| 22 | # "test-type=lit-test" labels are added automatically. |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 23 | function(iree_lit_test) |
Maksim Levental | 6d4eea6 | 2024-06-03 13:56:04 -0700 | [diff] [blame] | 24 | if(NOT IREE_BUILD_TESTS) |
| 25 | return() |
| 26 | endif() |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 27 | cmake_parse_arguments( |
| 28 | _RULE |
| 29 | "" |
| 30 | "NAME;TEST_FILE" |
Rob Suderman | f900f50 | 2022-06-07 12:26:06 -0700 | [diff] [blame] | 31 | "DATA;TOOLS;LABELS;TIMEOUT" |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 32 | ${ARGN} |
| 33 | ) |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 34 | |
Scott Todd | 315e238 | 2024-01-30 13:35:51 -0800 | [diff] [blame] | 35 | if(NOT TARGET FileCheck) |
| 36 | # TODO(scotttodd): mark test DISABLED instead of skipping entirely? |
| 37 | return() |
| 38 | endif() |
| 39 | |
| 40 | # TODO(scotttodd): remove this and make all lit tests "hostonly" implicitly? |
Lei Zhang | f505f59 | 2020-07-01 07:23:43 -0400 | [diff] [blame] | 41 | if(CMAKE_CROSSCOMPILING AND "hostonly" IN_LIST _RULE_LABELS) |
Scott Todd | 315e238 | 2024-01-30 13:35:51 -0800 | [diff] [blame] | 42 | # TODO(scotttodd): mark test DISABLED instead of skipping entirely? |
Lei Zhang | f505f59 | 2020-07-01 07:23:43 -0400 | [diff] [blame] | 43 | return() |
| 44 | endif() |
| 45 | |
Ben Vanik | b397015 | 2021-04-22 13:26:22 -0700 | [diff] [blame] | 46 | iree_package_ns(_PACKAGE_NS) |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 47 | iree_package_name(_PACKAGE_NAME) |
| 48 | set(_NAME "${_PACKAGE_NAME}_${_RULE_NAME}") |
| 49 | |
| 50 | get_filename_component(_TEST_FILE_PATH ${_RULE_TEST_FILE} ABSOLUTE) |
Geoffrey Martin-Noble | aa24d3e | 2020-02-04 14:38:30 -0800 | [diff] [blame] | 51 | |
Ben Vanik | b397015 | 2021-04-22 13:26:22 -0700 | [diff] [blame] | 52 | list(TRANSFORM _RULE_DATA REPLACE "^::" "${_PACKAGE_NS}::") |
Geoffrey Martin-Noble | 435c270 | 2022-01-24 15:56:56 -0800 | [diff] [blame] | 53 | list(TRANSFORM _RULE_TOOLS REPLACE "^::" "${_PACKAGE_NS}::") |
Ben Vanik | 57d5e2e | 2020-03-03 07:14:56 -0800 | [diff] [blame] | 54 | set(_DATA_DEP_PATHS) |
Geoffrey Martin-Noble | 435c270 | 2022-01-24 15:56:56 -0800 | [diff] [blame] | 55 | foreach(_DATA_DEP IN LISTS _RULE_DATA _RULE_TOOLS) |
Ben Vanik | 8a43b8d | 2021-10-21 11:41:17 -0700 | [diff] [blame] | 56 | list(APPEND _DATA_DEP_PATHS $<TARGET_FILE:${_DATA_DEP}>) |
Geoffrey Martin-Noble | 435c270 | 2022-01-24 15:56:56 -0800 | [diff] [blame] | 57 | endforeach() |
| 58 | |
| 59 | set(_LIT_PATH_ARGS) |
| 60 | foreach(_TOOL IN LISTS _RULE_TOOLS) |
| 61 | list(APPEND _LIT_PATH_ARGS "--path" "$<TARGET_FILE_DIR:${_TOOL}>") |
| 62 | endforeach() |
Ben Vanik | 57d5e2e | 2020-03-03 07:14:56 -0800 | [diff] [blame] | 63 | |
Marius Brehler | cc4328c | 2020-04-02 19:12:51 -0700 | [diff] [blame] | 64 | iree_package_ns(_PACKAGE_NS) |
| 65 | string(REPLACE "::" "/" _PACKAGE_PATH ${_PACKAGE_NS}) |
Ben Vanik | 2e9aaa4 | 2020-10-10 21:11:02 -0700 | [diff] [blame] | 66 | set(_NAME_PATH "${_PACKAGE_PATH}/${_RULE_NAME}") |
Stella Laurenzo | 2d82fb7 | 2021-10-21 20:52:33 -0700 | [diff] [blame] | 67 | add_test( |
| 68 | NAME |
| 69 | ${_NAME_PATH} |
Ben Vanik | 57d5e2e | 2020-03-03 07:14:56 -0800 | [diff] [blame] | 70 | COMMAND |
Geoffrey Martin-Noble | 435c270 | 2022-01-24 15:56:56 -0800 | [diff] [blame] | 71 | "${Python3_EXECUTABLE}" |
Stella Laurenzo | 96d959e | 2023-02-19 11:58:14 -0800 | [diff] [blame] | 72 | "${LLVM_EXTERNAL_LIT}" |
Geoffrey Martin-Noble | 435c270 | 2022-01-24 15:56:56 -0800 | [diff] [blame] | 73 | ${_LIT_PATH_ARGS} |
Ben Vanik | 57d5e2e | 2020-03-03 07:14:56 -0800 | [diff] [blame] | 74 | ${_TEST_FILE_PATH} |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 75 | ) |
Stella Laurenzo | 301e86d | 2021-08-08 13:59:26 -0700 | [diff] [blame] | 76 | |
Stella Laurenzo | 2d82fb7 | 2021-10-21 20:52:33 -0700 | [diff] [blame] | 77 | list(APPEND _RULE_LABELS "${_PACKAGE_PATH}") |
Scott Todd | 2bef720 | 2024-07-30 08:14:38 -0700 | [diff] [blame] | 78 | list(APPEND _RULE_LABELS "test-type=lit-test") |
Stella Laurenzo | 2d82fb7 | 2021-10-21 20:52:33 -0700 | [diff] [blame] | 79 | set_property(TEST ${_NAME_PATH} PROPERTY LABELS "${_RULE_LABELS}") |
| 80 | set_property(TEST ${_NAME_PATH} PROPERTY REQUIRED_FILES "${_TEST_FILE_PATH}") |
Geoffrey Martin-Noble | 5286416 | 2022-01-12 13:08:17 -0800 | [diff] [blame] | 81 | set_property(TEST ${_NAME_PATH} PROPERTY ENVIRONMENT |
Ben Vanik | 2bc1046 | 2022-01-26 18:43:38 -0800 | [diff] [blame] | 82 | "LIT_OPTS=-v" |
Geoffrey Martin-Noble | 5286416 | 2022-01-12 13:08:17 -0800 | [diff] [blame] | 83 | "FILECHECK_OPTS=--enable-var-scope") |
Rob Suderman | f900f50 | 2022-06-07 12:26:06 -0700 | [diff] [blame] | 84 | set_property(TEST ${_NAME_PATH} PROPERTY TIMEOUT ${_RULE_TIMEOUT}) |
Geoffrey Martin-Noble | 10f1822 | 2022-06-09 16:00:13 -0700 | [diff] [blame] | 85 | iree_configure_test(${_NAME_PATH}) |
Stella Laurenzo | 2d82fb7 | 2021-10-21 20:52:33 -0700 | [diff] [blame] | 86 | |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 87 | # TODO(gcmn): Figure out how to indicate a dependency on _RULE_DATA being built |
| 88 | endfunction() |
| 89 | |
| 90 | |
| 91 | # iree_lit_test_suite() |
| 92 | # |
| 93 | # Creates a suite of lit tests for a list of source files. |
| 94 | # |
| 95 | # Mirrors the bzl rule of the same name. |
| 96 | # |
| 97 | # Parameters: |
| 98 | # NAME: Name of the target |
| 99 | # SRCS: List of test files to run with the lit runner. Creates one test per source. |
Geoffrey Martin-Noble | 435c270 | 2022-01-24 15:56:56 -0800 | [diff] [blame] | 100 | # TOOLS: Tools that should be included on the PATH |
| 101 | # DATA: Additional data dependencies used by the test |
Geoffrey Martin-Noble | b5b46cb | 2020-04-01 12:12:18 -0700 | [diff] [blame] | 102 | # LABELS: Additional labels to apply to the generated tests. The package path is |
| 103 | # added automatically. |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 104 | function(iree_lit_test_suite) |
Scott Todd | 37c17e6 | 2020-12-28 11:00:01 -0800 | [diff] [blame] | 105 | if(NOT IREE_BUILD_TESTS) |
Lei Zhang | d454ee4 | 2020-06-02 11:48:57 -0700 | [diff] [blame] | 106 | return() |
| 107 | endif() |
| 108 | |
Scott Todd | 37c17e6 | 2020-12-28 11:00:01 -0800 | [diff] [blame] | 109 | # Note: we could check IREE_BUILD_COMPILER here, but cross compilation makes |
| 110 | # that a little tricky. Instead, we let iree_check_test handle the checks, |
| 111 | # meaning this function may run some configuration but generate no targets. |
| 112 | |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 113 | cmake_parse_arguments( |
| 114 | _RULE |
| 115 | "" |
| 116 | "NAME" |
Rob Suderman | f900f50 | 2022-06-07 12:26:06 -0700 | [diff] [blame] | 117 | "SRCS;DATA;TOOLS;LABELS;TIMEOUT" |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 118 | ${ARGN} |
| 119 | ) |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 120 | |
Rob Suderman | f900f50 | 2022-06-07 12:26:06 -0700 | [diff] [blame] | 121 | if (NOT DEFINED _RULE_TIMEOUT) |
| 122 | set(_RULE_TIMEOUT 60) |
| 123 | endif() |
| 124 | |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 125 | foreach(_TEST_FILE ${_RULE_SRCS}) |
| 126 | get_filename_component(_TEST_BASENAME ${_TEST_FILE} NAME) |
| 127 | iree_lit_test( |
| 128 | NAME |
Geoffrey Martin-Noble | aa24d3e | 2020-02-04 14:38:30 -0800 | [diff] [blame] | 129 | "${_TEST_BASENAME}.test" |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 130 | TEST_FILE |
| 131 | "${_TEST_FILE}" |
| 132 | DATA |
| 133 | "${_RULE_DATA}" |
Geoffrey Martin-Noble | 435c270 | 2022-01-24 15:56:56 -0800 | [diff] [blame] | 134 | TOOLS |
| 135 | "${_RULE_TOOLS}" |
Geoffrey Martin-Noble | b5b46cb | 2020-04-01 12:12:18 -0700 | [diff] [blame] | 136 | LABELS |
| 137 | "${_RULE_LABELS}" |
Rob Suderman | f900f50 | 2022-06-07 12:26:06 -0700 | [diff] [blame] | 138 | TIMEOUT |
| 139 | ${_RULE_TIMEOUT} |
Geoffrey Martin-Noble | f0eaf37 | 2020-01-28 10:03:14 -0800 | [diff] [blame] | 140 | ) |
| 141 | endforeach() |
| 142 | endfunction() |