Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,20 @@ the need to store large test vector files in git, and instead can be generated a

To run the unit tests, from the cmake build directory run:
```sh
test/matx_test
make -j test
```

This will execute all unit tests defined. If you wish to execute a subset of tests, or run with different options, you
may run test/matx_test directly with parameters defined by [Google Test](https://github.com/google/googletest). To run matx_test
directly, you must be inside the build/test directory for the correct paths to be set. For example,
to run only tests with the name FFT:
This will execute all unit tests defined. It is also possible to build and execute a single test, for example:
```
make test_00_operators_interp_test
test/test_00_operators_interp_test
```

To run a subset of tests, it is possible to use [ctest](https://cmake.org/cmake/help/latest/manual/ctest.1.html) from inside the `build/test` directory. For example, to run only tests with the name FFT:

```sh
cd build/test
./matx_test --gtest_filter="*FFT*"
ctest -R "FFT"
```


Expand Down
15 changes: 11 additions & 4 deletions docs/_sources/basics/build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,20 @@ To build unit tests, pass the argument ``-DMATX_BUILD_TESTS=ON`` to CMake to con

make -j test

This will compile and run all unit tests. For more control over which tests to run, you may run test/matx_test directly with parameters
defined by Google Test (https://github.com/google/googletest). To run matx_test directly, you must be inside the build/test directory
for the correct paths to be set. For example, to run only tests with the name FFT:
This will execute all unit tests defined. It is also possible to build and execute a single test, for example:

.. code-block:: shell

test/matx_test --gtest_filter="*FFT*"
make test_00_operators_interp_test
test/test_00_operators_interp_test

To run a subset of tests, it is possible to use `ctest <https://cmake.org/cmake/help/latest/manual/ctest.1.html>`_ from inside the ``build/test`` directory. For example, to run only tests with the name FFT:

.. code-block:: shell

cd build/test
ctest -R "FFT"


Examples
--------
Expand Down
87 changes: 66 additions & 21 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ set (test_sources
00_sparse/Matmul.cu
00_sparse/Matvec.cu
00_sparse/Solve.cu
main.cu
)

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

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

add_executable(matx_test main.cu ${all_test_srcs})
# Create executable with main.cu and the specific test file
add_executable(${target_name} main.cu ${test_file})

# Set all the flags/other properties
set_property(TARGET matx_test PROPERTY ENABLE_EXPORTS 1)
# Set all the flags/other properties
set_property(TARGET ${target_name} PROPERTY ENABLE_EXPORTS 1)

if (DEFINED cupy_PYTHON_PACKAGE)
target_compile_definitions(matx_test PRIVATE CUPY_INSTALLED)
endif()
if (DEFINED cupy_PYTHON_PACKAGE)
target_compile_definitions(${target_name} PRIVATE CUPY_INSTALLED)
endif()

if (MSVC)
target_compile_options(matx_test PRIVATE /W4 /WX)
else()
target_compile_options(matx_test PRIVATE ${WARN_FLAGS})
#target_compile_options(matx_test PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:${WARN_FLAGS}>)
target_compile_options(matx_test PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:${MATX_CUDA_FLAGS}>)
endif()
if (MSVC)
target_compile_options(${target_name} PRIVATE /W4 /WX)
else()
target_compile_options(${target_name} PRIVATE ${WARN_FLAGS})
target_compile_options(${target_name} PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:${MATX_CUDA_FLAGS}>)
endif()

target_include_directories(matx_test PRIVATE "${target_inc}")
target_include_directories(matx_test SYSTEM PRIVATE "${system_inc}")
target_link_libraries(matx_test PRIVATE matx::matx) # Transitive properties
target_link_libraries(matx_test PRIVATE ${NVSHMEM_LIBRARY} gtest)
target_include_directories(${target_name} PRIVATE "${target_inc}")
target_include_directories(${target_name} SYSTEM PRIVATE "${system_inc}")
target_link_libraries(${target_name} PRIVATE matx::matx) # Transitive properties
target_link_libraries(${target_name} PRIVATE ${NVSHMEM_LIBRARY} gtest)

# Register the test with CTest
add_test(NAME ${target_name} COMMAND ${target_name})
set_tests_properties(${target_name} PROPERTIES
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endfunction()

# Enable CTest
enable_testing()

# Create individual executables for each test file
foreach(test_file ${test_sources})
create_test_executable(${test_file})
endforeach()

# Create individual executables for proprietary tests
foreach(test_file ${proprietary_sources})
create_test_executable(${test_file})
endforeach()

# Number of test jobs to run in parallel
set(CTEST_PARALLEL_JOBS 4)

# Create a legacy matx_test script for CI compatibility
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/matx_test.sh
${CMAKE_CURRENT_BINARY_DIR}/matx_test
COPYONLY
)
# Make the script executable
file(CHMOD ${CMAKE_CURRENT_BINARY_DIR}/matx_test
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)

# Add a custom target to run CTest from the main build directory
add_custom_target(test
DEPENDS matx_test
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/matx_test)
COMMAND ${CMAKE_CTEST_COMMAND} -j${CTEST_PARALLEL_JOBS} --output-on-failure
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Running all MatX tests in parallel (${CTEST_PARALLEL_JOBS} cores)"
VERBATIM
)
19 changes: 19 additions & 0 deletions test/matx_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

echo "MatX Test Wrapper - Running CTest in parallel..."

# Change to the directory where this script is located (test directory)
cd "$(dirname "$0")"

# Build the ctest command with parallel jobs and output on failure
CTEST_CMD="ctest -j4 --output-on-failure"

# Forward any additional arguments to ctest
if [ $# -gt 0 ]; then
CTEST_CMD="$CTEST_CMD $*"
fi

echo "Executing: $CTEST_CMD"

# Execute ctest and preserve its exit code
exec $CTEST_CMD