Skip to content

Commit

Permalink
CMake: enable testing via CTest. (AMReX-Codes#1362)
Browse files Browse the repository at this point in the history
  • Loading branch information
mic84 authored Sep 18, 2020
1 parent 9831ee9 commit 28a454d
Show file tree
Hide file tree
Showing 16 changed files with 277 additions and 35 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,26 @@ jobs:
./configure --dim 3 --enable-eb yes --enable-xsdk-defaults yes --with-omp yes --debug yes
make -j2 WARN_ALL=TRUE WARN_ERROR=TRUE
make install
# Build libamrex and run all tests
tests:
name: GNU@7.5 C++14 [tests]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Dependencies
run: .github/workflows/dependencies/dependencies.sh
- name: Build & Install
run: |
mkdir build
cd build
cmake .. \
-DENABLE_OMP=ON \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DAMReX_ENABLE_TESTS=ON \
-DENABLE_PARTICLES=ON
make -j 2
- name: Run tests
run: |
cd build
ctest --output-on-failure -R
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,13 @@ if (ENABLE_PLOTFILE_TOOLS)
# because it needs to get installed
add_subdirectory(Tools/Plotfile)
endif ()


#
# Enable CTests
#
option(AMReX_ENABLE_TESTS "Enable CTest suite for AMReX" NO)
if (AMReX_ENABLE_TESTS)
enable_testing()
add_subdirectory(Tests)
endif ()
11 changes: 11 additions & 0 deletions Tests/Algoim/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if (NOT ENABLE_EB)
return()
endif ()

set(_sources main.cpp)
set(_input_files )

setup_test(_sources _input_files)

unset(_sources)
unset(_input_files)
7 changes: 7 additions & 0 deletions Tests/AsyncOut/multifab/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(_sources main.cpp)
set(_input_files inputs )

setup_test(_sources _input_files)

unset(_sources)
unset(_input_files)
7 changes: 7 additions & 0 deletions Tests/BBIOBenchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(_sources BBIOTest.cpp BBIOTestDriver.cpp )
set(_input_files )

setup_test(_sources _input_files)

unset(_sources)
unset(_input_files)
7 changes: 7 additions & 0 deletions Tests/BaseFabTesting/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(_sources main.cpp)
set(_input_files inputs )

setup_test(_sources _input_files)

unset(_sources)
unset(_input_files)
137 changes: 137 additions & 0 deletions Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#
# List of subdirectories to search for CMakeLists.
#
set( AMREX_TESTS_SUBDIRS AsyncOut )

if (ENABLE_PARTICLES)
list(APPEND AMREX_TESTS_SUBDIRS Particles)
endif ()

list(TRANSFORM AMREX_TESTS_SUBDIRS PREPEND "${CMAKE_CURRENT_LIST_DIR}/")

#
# Function to setup the tutorials
#
function (setup_test _srcs _inputs)

cmake_parse_arguments( "" "HAS_FORTRAN_MODULES"
"BASE_NAME;RUNTIME_SUBDIR;EXTRA_DEFINITIONS;CMDLINE_PARAMS;NTASKS;NTHREADS" "" ${ARGN} )

if (_BASE_NAME)
set(_base_name ${_BASE_NAME})
else ()
string(REGEX REPLACE ".*Tests/" "" _base_name ${CMAKE_CURRENT_LIST_DIR})
string(REPLACE "/" "_" _base_name ${_base_name})
endif()

if (_RUNTIME_SUBDIR)
set(_exe_dir ${CMAKE_CURRENT_BINARY_DIR}/${_RUNTIME_SUBDIR})
else ()
set(_exe_dir ${CMAKE_CURRENT_BINARY_DIR})
endif ()

set( _exe_name Test_${_base_name} )
set( _test_name ${_base_name} )

add_executable( ${_exe_name} )
target_sources( ${_exe_name} PRIVATE ${${_srcs}} )
set_target_properties( ${_exe_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${_exe_dir} )

if (_EXTRA_DEFINITIONS)
target_compile_definitions(${_exe_name} PRIVATE ${_EXTRA_DEFINITIONS})
endif ()

# Find out which include directory is needed
set(_includes ${${_srcs}})
list(FILTER _includes INCLUDE REGEX "\\.H")
foreach(_item IN LISTS _includes)
get_filename_component( _include_dir ${_item} DIRECTORY )
target_include_directories( ${_exe_name} PRIVATE ${_include_dir} )
endforeach()

if (_HAS_FORTRAN_MODULES)
target_include_directories(${_exe_name}
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/mod_files)
set_target_properties( ${_exe_name}
PROPERTIES
Fortran_MODULE_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/mod_files )
endif ()

target_link_libraries( ${_exe_name} amrex )

if (ENABLE_CUDA)
setup_target_for_cuda_compilation( ${_exe_name} )
endif ()

#
# Assemble the commands sequence to launch the test
#
set(_cmd ${_exe_dir}/${_exe_name})

if (_CMDLINE_PARAMS)
list(APPEND _cmd ${_CMDLINE_PARAMS})
endif ()

if (${_inputs})
file( COPY ${${_inputs}} DESTINATION ${_exe_dir} )
list(APPEND _cmd ${${_inputs}})
endif ()

#
# Add the test
#
add_test(
NAME ${_test_name}
COMMAND ${_cmd}
WORKING_DIRECTORY ${_exe_dir}
)

#
# Add MPI test
#
if (ENABLE_MPI AND _NTASKS)
if (_NTASKS GREATER 2)
message(FATAL_ERROR "\nsetup_tests(): number of MPI tasks exceeds CI limit of 2")
endif ()

add_test(
NAME ${_test_name}_MPI
COMMAND mpiexec -n ${_NTASKS} ${_cmd}
WORKING_DIRECTORY ${_exe_dir}
)

set_tests_properties(${_test_name}_MPI PROPERTIES ENVIRONMENT OMP_NUM_THREADS=1 )
endif ()

if (ENABLE_OMP AND _NTHREADS)
if (_NTHREADS GREATER 2)
message(FATAL_ERROR "\nsetup_tests(): number of OpenMP threads exceeds CI limit of 2")
endif ()

add_test(
NAME ${_test_name}_OpenMP
COMMAND ${_cmd}
WORKING_DIRECTORY ${_exe_dir}
)

set_tests_properties(${_test_name}_OpenMP PROPERTIES ENVIRONMENT OMP_NUM_THREADS=${_NTHREADS} )
endif ()

endfunction ()


#
# Loop over subdirs and add to the build those containing CMakeLists.txt
#
foreach (_subdir IN LISTS AMREX_TESTS_SUBDIRS)

file( GLOB_RECURSE _tests "${_subdir}/*CMakeLists.txt" )

foreach ( _item IN LISTS _tests)
get_filename_component(_dir ${_item} DIRECTORY )
add_subdirectory(${_dir})
endforeach ()

endforeach ()
21 changes: 21 additions & 0 deletions Tests/C_BaseLib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

#
# Disabled for NOW
#
return()


if (NOT CMAKE_Fortran_COMPILER_LOADED)
return()
endif ()

set(_sources AMRProfTestBL.cpp tBA.cpp tDM.cpp tFillFab.cpp tParmParse.cpp TPROFILER_F.H tread.cpp tVisMF.cpp )
list(APPEND _sources AMRPROFTEST_F.H tCArena.cpp tFAC.cpp tMFcopy.cpp tProfiler.cpp tRABcast.cpp tUMap.cpp )
list(APPEND _sources fillfab.f t8BIT.cpp tDir.cpp tFB.cpp tMF.cpp TPROFILER.F tRan.cpp tVisMF2.cpp )

set(_input_files )

setup_test(_sources _input_files)

unset(_sources)
unset(_input_files)
7 changes: 7 additions & 0 deletions Tests/DataServicesTest0/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(_sources DataServicesTest0.cpp)
set(_input_files )

setup_test(_sources _input_files)

unset(_sources)
unset(_input_files)
7 changes: 7 additions & 0 deletions Tests/FillBoundaryComparison/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(_sources main.cpp)
set(_input_files ba.max)

setup_test(_sources _input_files CMDLINE_PARAMS nrounds=1)

unset(_sources)
unset(_input_files)
40 changes: 5 additions & 35 deletions Tests/Particles/NeighborParticles/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,8 @@
#
# This test requires CUDA and Particles to be enabled
#
if (NOT ENABLE_CUDA OR NOT ENABLE_PARTICLES)
return ()
endif ()
set(_sources CheckPair.H Constants.H main.cpp MDParticleContainer.cpp MDParticleContainer.H )

set( SRC_DIR ${CMAKE_CURRENT_LIST_DIR} )
set( EXENAME "gpu_nblist.exe" )
set(_input_files inputs )

add_executable( ${EXENAME} EXCLUDE_FROM_ALL "")
setup_test(_sources _input_files NTASKS 2)

target_sources( ${EXENAME}
PRIVATE
${SRC_DIR}/Constants.H
${SRC_DIR}/MDParticleContainer.H
${SRC_DIR}/MDParticleContainer.cpp
${SRC_DIR}/CheckPair.H
${SRC_DIR}/main.cpp)

target_include_directories(${EXENAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR} )
set_source_files_properties(${SRC_DIR}/main.cpp ${SRC_DIR}/MDParticleContainer.cpp PROPERTIES LANGUAGE CUDA)

# Since we are forcing the use of fortran compiler to link
# we need to specify the flags to add at link phase since
# it won't propagate amrex ones
set_target_properties( ${EXENAME}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}
CUDA_SEPARABLE_COMPILATION ON # This add -dc flag
)

target_link_libraries(${EXENAME} amrex)

file( COPY inputs DESTINATION ${CMAKE_CURRENT_BINARY_DIR} )

add_tutorial(${EXENAME})
unset(_sources)
unset(_input_files)
7 changes: 7 additions & 0 deletions Tests/Particles/ParticleMesh/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(_sources main.cpp)
set(_input_files inputs )

setup_test(_sources _input_files)

unset(_sources)
unset(_input_files)
7 changes: 7 additions & 0 deletions Tests/Particles/ParticleReduce/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(_sources main.cpp)
set(_input_files inputs )

setup_test(_sources _input_files NTHREADS 2)

unset(_sources)
unset(_input_files)
7 changes: 7 additions & 0 deletions Tests/Particles/ParticleTransformations/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(_sources main.cpp)
set(_input_files inputs )

setup_test(_sources _input_files)

unset(_sources)
unset(_input_files)
7 changes: 7 additions & 0 deletions Tests/Particles/Redistribute/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(_sources main.cpp)
set(_input_files inputs.rt ) # There are others but we use only this one for now

setup_test(_sources _input_files NTASKS 2)

unset(_sources)
unset(_input_files)
7 changes: 7 additions & 0 deletions Tests/complementIn/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(_sources main.cpp)
set(_input_files )

setup_test(_sources _input_files)

unset(_sources)
unset(_input_files)

0 comments on commit 28a454d

Please sign in to comment.