Skip to content

Commit

Permalink
separate tests/ dir
Browse files Browse the repository at this point in the history
  • Loading branch information
billyzs committed Jul 10, 2024
1 parent 411af42 commit 25691fe
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 69 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/cmake-ninja-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
-D CMAKE_CXX_COMPILER_LAUNCHER="${{ steps.variables.outputs.tools-cache-dir }}/bin/ccache"
-D CPM_SOURCE_CACHE=${{ steps.variables.outputs.ccache-cache-dir }}
-D CMAKE_BUILD_TYPE=${{ matrix.build_type }}
-D BUILD_TESTING=ON
-B ${{ steps.variables.outputs.build-output-dir }}
-S ${{ github.workspace }}
Expand All @@ -102,4 +103,4 @@ jobs:
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: >
ctest --progress --output-on-failure --schedule-random --build-config ${{ matrix.build_type }}
ctest --progress --output-on-failure --schedule-random --no-tests=error --test-dir tests --build-config ${{ matrix.build_type }}
75 changes: 8 additions & 67 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ project(
)
message(
STATUS
"Using CMake version: ${CMAKE_VERSION}"
"Using CMake version: ${CMAKE_VERSION} on ${CMAKE_SYSTEM_PROCESSOR}"
)
message(
STATUS
Expand Down Expand Up @@ -169,73 +169,14 @@ endif()

include(cmake/CompileOptions.cmake)
set_project_compile_options()

add_library(
tutorial
STATIC
tutorial.cpp
)
target_link_libraries(
tutorial
PUBLIC
$<BUILD_INTERFACE:mlx>
PRIVATE
bench_compile_opts
target_include_directories(
bench_compile_opts
INTERFACE
"include/"
)

if(TARGET
Eigen3::Eigen
)
add_library(
test_eigen
STATIC
test_eigen.cpp
)
target_link_libraries(
test_eigen
PRIVATE
Eigen3::Eigen bench_compile_opts benchmark::benchmark
)
endif()

if(OpenMP_CXX_FOUND)
add_library(
test_openmp
STATIC
test_openmp.cpp
)
target_link_libraries(
test_openmp
PRIVATE
OpenMP::OpenMP_CXX bench_compile_opts benchmark::benchmark
)
endif()

add_executable(
main
test_mlx.cpp
main.cpp
)
add_subdirectory(src)

target_link_libraries(
main
PRIVATE
bench_compile_opts tutorial $<TARGET_NAME_IF_EXISTS::test_openmp>
$<TARGET_NAME_IF_EXISTS:test_eigen> benchmark::benchmark
)
if(CMAKE_CXX_COMPILER_ID
STREQUAL
"AppleClang"
)
add_dependencies(
main
test_openmp
) # HACK until #3 is solved
if(BUILD_TESTING)
add_subdirectory(tests)
endif()

enable_testing()
add_test(
NAME benchmark_main.list_tests
COMMAND
main --benchmark_list_tests=true
)
2 changes: 1 addition & 1 deletion cmake/download-build-tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ set(TMP

message(
WARNING
"Using host CMake version: ${CMAKE_VERSION} on architecture ${CMAKE_HOST_SYSTEM_PROCESSOR}"
"Using host CMake version: ${CMAKE_VERSION} on architecture ${CMAKE_SYSTEM_PROCESSOR}"
)

if(${CMAKE_HOST_SYSTEM_NAME}
Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
add_library(
mlx_tutorial
STATIC
tutorial.cpp
)
target_link_libraries(
mlx_tutorial
PUBLIC
$<BUILD_INTERFACE:mlx>
PRIVATE
bench_compile_opts
)
File renamed without changes.
63 changes: 63 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
if(TARGET
Eigen3::Eigen
)
add_library(
test_eigen
STATIC
test_eigen.cpp
)
target_link_libraries(
test_eigen
PRIVATE
Eigen3::Eigen bench_compile_opts benchmark::benchmark
)
endif()

if(OpenMP_CXX_FOUND)
add_library(
test_openmp
STATIC
test_openmp.cpp
)
target_link_libraries(
test_openmp
PRIVATE
OpenMP::OpenMP_CXX bench_compile_opts benchmark::benchmark
)
endif()

add_executable(
main
test_mlx.cpp
main.cpp
)

target_include_directories(
main
PRIVATE
../
)

target_link_libraries(
main
PRIVATE
bench_compile_opts mlx_tutorial $<TARGET_NAME_IF_EXISTS::test_openmp>
$<TARGET_NAME_IF_EXISTS:test_eigen> benchmark::benchmark
)

if(CMAKE_CXX_COMPILER_ID
STREQUAL
"AppleClang"
)
add_dependencies(
main
test_openmp
) # HACK until #3 is solved
endif()

enable_testing()
add_test(
NAME benchmark_main.smoke_test
COMMAND
main --benchmark_list_tests=true
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 25691fe

Please sign in to comment.