Newer
Older
#
# --> collect test directories/files
# --> create tests (ctest)
#
# Those tests will be run after a call to 'make test'
# or a call to ctest.
enable_testing()
find_python_module(pytest REQUIRED)
# Choose python build dir as directory where tests will be run.
# --> get build dir for python
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "import distutils.util as ut ; import distutils.sysconfig as sy; print 'lib.'+ut.get_platform()+'-'+sy.get_python_version()"
OUTPUT_VARIABLE ${PROJECT_NAME}_PYTHON_BUILD_DIR)
string(STRIP ${${PROJECT_NAME}_PYTHON_BUILD_DIR} ${PROJECT_NAME}_PYTHON_BUILD_DIR)
# --> set test dir
set(testDir ${CMAKE_BINARY_DIR}/build/${${PROJECT_NAME}_PYTHON_BUILD_DIR})
# 1 - Collect files for Python unitary tests (user-defined) -----
# We create a new test for each test_XXX.py found in each directory (i.e. module) of hysop listed below
Franck Pérignon
committed
set(py_src_dirs
fields
domain
operator
Franck Pérignon
committed
numerics
Franck Pérignon
committed
problem
Franck Pérignon
committed
)
# If mpi is on, we add test_XXX.py files of hysop/mpi directory
Franck Pérignon
committed
set(py_src_dirs
${py_src_dirs} mpi)
# If GPU is on, we add test_XXX.py files of hysop/gpu directory
if(WITH_GPU)
set(py_src_dirs
${py_src_dirs} gpu)
endif()
# Copy the OpenCL sources files to build dir (required since only python files are copied by setup.py)
Jean-Matthieu Etancelin
committed
set(clfiles)
file(GLOB clfilestmp RELATIVE ${CMAKE_SOURCE_DIR} hysop/gpu/cl_src/[a-z]*.cl)
Jean-Matthieu Etancelin
committed
set(clfiles ${clfiles} ${clfilestmp})
file(GLOB clfilestmp RELATIVE ${CMAKE_SOURCE_DIR} hysop/gpu/cl_src/kernels/[a-z]*.cl)
Jean-Matthieu Etancelin
committed
set(clfiles ${clfiles} ${clfilestmp})
file(GLOB clfilestmp RELATIVE ${CMAKE_SOURCE_DIR} hysop/gpu/cl_src/advection/[a-z]*.cl)
Jean-Matthieu Etancelin
committed
set(clfiles ${clfiles} ${clfilestmp})
file(GLOB clfilestmp RELATIVE ${CMAKE_SOURCE_DIR} hysop/gpu/cl_src/remeshing/[a-z]*.cl)
Jean-Matthieu Etancelin
committed
set(clfiles ${clfiles} ${clfilestmp})
foreach(_F ${clfiles})
configure_file(${_F} ${testDir}/${_F} COPYONLY)
endforeach()
# Build a list of test_*.py files for each directory of hysop/${py_src_dirs}
set(py_test_files)
foreach(testdir ${py_src_dirs})
file(GLOB testfiles RELATIVE ${CMAKE_SOURCE_DIR} hysop/${testdir}/tests/test_*.py)
set(py_test_files ${py_test_files} ${testfiles})
file(GLOB datfiles hysop/${testdir}/tests/*.dat)
file(GLOB mapfiles hysop/${testdir}/tests/*.map)
file(GLOB reffiles hysop/${testdir}/tests/ref_files/*)
set(datafiles ${mapfiles} ${datfiles})
file(COPY ${reffiles} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/dataForTests)
foreach(_F ${datafiles})
get_filename_component(fname ${_F} NAME)
configure_file(${_F} ${CMAKE_CURRENT_BINARY_DIR}/dataForTests/${fname} COPYONLY)
endforeach()
# Handling doctest in *.py files recursively for each directory of hysop/${py_src_dirs}
# excluding __init__ or test_ files.
# Doctest are run for every line which contains '>>>'
Franck Pérignon
committed
foreach(testdir ${py_src_dirs})
file(STRINGS ${testfile} test_doctest REGEX ">>>")
if(NOT "${test_doctest}" STREQUAL "")
set(py_doctest_files ${py_doctest_files} ${testfile})
Franck Pérignon
committed
endforeach()
Franck Pérignon
committed
foreach(testfile ${py_test_files})
get_filename_component(testName ${testfile} NAME_WE)
set(testExe ${testDir}/${testfile})
message(STATUS "Add test ${testfile} ...")
add_test(NAME ${testName} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/dataForTests
COMMAND py.test -v --pep8 ${testExe})
add_test(NAME ${testName} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/dataForTests
COMMAND py.test -v ${testExe})
# Run the same test using mpi multi process run.
# The number of processes used is set with NBPROCS_FOR_TESTS variable (user option for cmake, default=8)
message(STATUS "Add test mpi_${testName}.")
add_test(
NAME mpi_${testName}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/dataForTests
COMMAND mpirun -np ${NBPROCS_FOR_TESTS} ${PYTHON_EXECUTABLE} ${testExe}
)
set_tests_properties(mpi_${testName}
PROPERTIES ENVIRONMENT "PYTHONPATH=${testDir}")
Franck Pérignon
committed
endforeach()
foreach(testfile ${py_doctest_files})
get_filename_component(testName ${testfile} NAME_WE)
message(STATUS "Add test from doc doctest_${testName} ...")
Jean-Matthieu Etancelin
committed
add_test("doctest_${testName}" py.test -v --doctest-modules ${testfile})
endforeach()
message(STATUS "===")