Skip to content

Commit 7af6fa6

Browse files
krystian-andrzejewskiigcbot
authored andcommitted
Improving lit test targets
1) Adding tests to projects as source files to simplify the access to them 2) Dividing custom_target into custom_command and custom_target for lit test targets
1 parent 588adf8 commit 7af6fa6

File tree

2 files changed

+61
-7
lines changed

2 files changed

+61
-7
lines changed

IGC/Compiler/tests/CMakeLists.txt

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,39 @@ set(IGC_LIT_TEST_DEPENDS
3838
"${IGC_BUILD__PROJ__igc_opt}"
3939
)
4040

41+
42+
# Note:
43+
# This command must be consistent with lit.cfg.py in the following points:
44+
# 1) the path to tests must be consistent with config.test_source_root
45+
# 2) the suffix must be consistent with config.suffixes
46+
# The consistency can be achived by calling a process which returns the list of tests.
47+
file(GLOB_RECURSE _tests "${IGC_TEST_SOURCE_DIR}/*.ll")
48+
if(MSVC)
49+
source_group(TREE "${IGC_TEST_SOURCE_DIR}" PREFIX "tests" FILES ${_tests})
50+
endif()
51+
4152
# This will create a target called `check-igc`, which will run all tests from
4253
# IGC/Compiler/tests directory. The tests will be run on files in the source
4354
# directory, since they are not modified, there doesn't seem to be any reason
4455
# for copying them.
45-
add_lit_testsuite(check-igc "Running the IGC LIT tests"
46-
${IGC_TEST_BINARY_DIR}
47-
DEPENDS ${IGC_LIT_TEST_DEPENDS}
48-
)
56+
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17")
57+
igc_add_lit_target(check-igc "${IGC_TEST_BINARY_DIR}" "Running the IGC LIT tests"
58+
DEPENDS ${IGC_LIT_TEST_DEPENDS} ${_tests}
59+
SOURCES ${_tests} ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
60+
)
61+
else()
62+
add_lit_testsuite(check-igc "Running the IGC LIT tests"
63+
${IGC_TEST_BINARY_DIR}
64+
DEPENDS ${IGC_LIT_TEST_DEPENDS}
65+
)
66+
endif()
4967

5068
# Tests should not be excluded from "Build Solution" in VS.
5169
set_target_properties(check-igc
52-
PROPERTIES
53-
EXCLUDE_FROM_DEFAULT_BUILD OFF
54-
EXCLUDE_FROM_ALL OFF)
70+
PROPERTIES
71+
EXCLUDE_FROM_DEFAULT_BUILD OFF
72+
EXCLUDE_FROM_ALL OFF
73+
)
5574

5675
# Line below is just used to group LIT reated targets in single directory
5776
# in IDE. This is completely optional.

IGC/cmake/igc_llvm_utils.cmake

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,41 @@ function(igc_configure_lit_site_cfg in out)
9393
)
9494
endfunction()
9595

96+
function(igc_add_lit_target target binary_dir comment)
97+
cmake_parse_arguments(ARG "" "" "DEPENDS;SOURCES" ${ARGN})
98+
set(LIT_ARGS "${LLVM_LIT_ARGS}")
99+
separate_arguments(LIT_ARGS)
100+
if (NOT CMAKE_CFG_INTDIR STREQUAL ".")
101+
list(APPEND LIT_ARGS --param build_mode=${CMAKE_CFG_INTDIR})
102+
endif ()
103+
104+
# Get the path to the lit to *run* tests with. This can be overriden by
105+
# the user by specifying -DLLVM_EXTERNAL_LIT=<path-to-lit.py>
106+
get_llvm_lit_path(
107+
lit_base_dir
108+
lit_file_name
109+
ALLOW_EXTERNAL
110+
)
111+
112+
set(LIT_COMMAND "${PYTHON_EXECUTABLE};${lit_base_dir}/${lit_file_name}")
113+
list(APPEND LIT_COMMAND ${LIT_ARGS})
114+
set(run_tests_stamp_file "${binary_dir}/run_${target}.stamp")
115+
add_custom_command(
116+
OUTPUT "${run_tests_stamp_file}"
117+
COMMAND ${LIT_COMMAND} "${binary_dir}"
118+
COMMAND ${CMAKE_COMMAND} -E touch "${run_tests_stamp_file}"
119+
DEPENDS ${ARG_DEPENDS}
120+
COMMENT "${comment}"
121+
USES_TERMINAL
122+
)
123+
add_custom_target(${target}
124+
DEPENDS "${run_tests_stamp_file}"
125+
SOURCES ${ARG_SOURCES}
126+
)
127+
# Tests should be excluded from "Build Solution".
128+
set_target_properties(${target} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON)
129+
endfunction()
130+
96131
# Helper macro to set LLVM_EXTERNAL_LIT variable for LLVM lit tests.
97132
# Variable can be overridden from command line to set custom lit tool.
98133
macro(igc_find_external_lit)

0 commit comments

Comments
 (0)