Skip to content

Commit 9db80d0

Browse files
committed
build each test file as a separate executable
1 parent 4abc114 commit 9db80d0

File tree

1 file changed

+54
-21
lines changed

1 file changed

+54
-21
lines changed

test/CMakeLists.txt

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ set (test_sources
4747
00_sparse/Matmul.cu
4848
00_sparse/Matvec.cu
4949
00_sparse/Solve.cu
50-
main.cu
5150
)
5251

5352
# Some of <00_io> tests need csv files and binaries which all
@@ -85,30 +84,64 @@ endforeach()
8584
set(target_inc ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/../examples/ ${proprietary_inc_list})
8685
set(system_inc ${CUTLASS_INC} ${GTEST_INC_DIRS} ${pybind11_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS})
8786

88-
set(all_test_srcs ${test_sources} ${proprietary_sources})
87+
# Function to create individual test executables
88+
function(create_test_executable test_file)
89+
# Get the filename without path and extension for the target name
90+
get_filename_component(test_name ${test_file} NAME_WE)
91+
# Get the directory to make target names unique
92+
get_filename_component(test_dir ${test_file} DIRECTORY)
93+
string(REPLACE "/" "_" test_dir_clean ${test_dir})
94+
set(target_name "test_${test_dir_clean}_${test_name}")
8995

90-
add_executable(matx_test main.cu ${all_test_srcs})
96+
# Create executable with main.cu and the specific test file
97+
add_executable(${target_name} main.cu ${test_file})
9198

92-
# Set all the flags/other properties
93-
set_property(TARGET matx_test PROPERTY ENABLE_EXPORTS 1)
99+
# Set all the flags/other properties
100+
set_property(TARGET ${target_name} PROPERTY ENABLE_EXPORTS 1)
94101

95-
if (DEFINED cupy_PYTHON_PACKAGE)
96-
target_compile_definitions(matx_test PRIVATE CUPY_INSTALLED)
97-
endif()
102+
if (DEFINED cupy_PYTHON_PACKAGE)
103+
target_compile_definitions(${target_name} PRIVATE CUPY_INSTALLED)
104+
endif()
98105

99-
if (MSVC)
100-
target_compile_options(matx_test PRIVATE /W4 /WX)
101-
else()
102-
target_compile_options(matx_test PRIVATE ${WARN_FLAGS})
103-
#target_compile_options(matx_test PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:${WARN_FLAGS}>)
104-
target_compile_options(matx_test PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:${MATX_CUDA_FLAGS}>)
105-
endif()
106+
if (MSVC)
107+
target_compile_options(${target_name} PRIVATE /W4 /WX)
108+
else()
109+
target_compile_options(${target_name} PRIVATE ${WARN_FLAGS})
110+
target_compile_options(${target_name} PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:${MATX_CUDA_FLAGS}>)
111+
endif()
106112

107-
target_include_directories(matx_test PRIVATE "${target_inc}")
108-
target_include_directories(matx_test SYSTEM PRIVATE "${system_inc}")
109-
target_link_libraries(matx_test PRIVATE matx::matx) # Transitive properties
110-
target_link_libraries(matx_test PRIVATE ${NVSHMEM_LIBRARY} gtest)
113+
target_include_directories(${target_name} PRIVATE "${target_inc}")
114+
target_include_directories(${target_name} SYSTEM PRIVATE "${system_inc}")
115+
target_link_libraries(${target_name} PRIVATE matx::matx) # Transitive properties
116+
target_link_libraries(${target_name} PRIVATE ${NVSHMEM_LIBRARY} gtest)
111117

118+
# Register the test with CTest
119+
add_test(NAME ${target_name} COMMAND ${target_name})
120+
set_tests_properties(${target_name} PROPERTIES
121+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
122+
)
123+
endfunction()
124+
125+
# Enable CTest
126+
enable_testing()
127+
128+
# Create individual executables for each test file
129+
foreach(test_file ${test_sources})
130+
create_test_executable(${test_file})
131+
endforeach()
132+
133+
# Create individual executables for proprietary tests
134+
foreach(test_file ${proprietary_sources})
135+
create_test_executable(${test_file})
136+
endforeach()
137+
138+
# Number of test jobs to run in parallel
139+
set(CTEST_PARALLEL_JOBS 4)
140+
141+
# Add a custom target to run CTest from the main build directory
112142
add_custom_target(test
113-
DEPENDS matx_test
114-
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/matx_test)
143+
COMMAND ${CMAKE_CTEST_COMMAND} -j${CTEST_PARALLEL_JOBS} --output-on-failure
144+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
145+
COMMENT "Running all MatX tests in parallel (${CTEST_PARALLEL_JOBS} cores)"
146+
VERBATIM
147+
)

0 commit comments

Comments
 (0)