diff --git a/cmake/AkantuTestsMacros.cmake b/cmake/AkantuTestsMacros.cmake index 85bc9cdea..135036895 100644 --- a/cmake/AkantuTestsMacros.cmake +++ b/cmake/AkantuTestsMacros.cmake @@ -1,474 +1,537 @@ #=============================================================================== # @file AkantuTestsMacros.cmake # # @author Nicolas Richart <nicolas.richart@epfl.ch> # # @date creation: Fri Sep 03 2010 # @date last modification: Fri Jan 22 2016 # # @brief macros for tests # # @section LICENSE # # Copyright (©) 2010-2012, 2014, 2015 EPFL (Ecole Polytechnique Fédérale de # Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des # Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see <http://www.gnu.org/licenses/>. # #=============================================================================== #[=======================================================================[.rst: AkantuTestsMacros ----------------- This modules provides the functions to helper to declare tests and folders containing tests in akantu .. command:: add_test_tree - add_test_tree(<test_direcotry>) +add_test_tree(<test_direcotry>) - ``<test_directory>`` is the entry direcroty of the full structure of - subfolders containing tests +``<test_directory>`` is the entry direcroty of the full structure of +subfolders containing tests .. command:: add_akantu_test - add_akantu_test(<dir> <desc>) +add_akantu_test(<dir> <desc>) - This function add a subdirectory ``<dir>`` of tests that will be conditionnaly - activable and will be visible only if the parent folder as been activated An - option ``AKANTU_BUILD_TEST_<dir>`` will appear in ccmake with the description - ``<desc>``. The compilation of all tests can be forced with the option - ``AKANTU_BUILD_ALL_TESTS`` +This function add a subdirectory ``<dir>`` of tests that will be conditionnaly +activable and will be visible only if the parent folder as been activated An +option ``AKANTU_BUILD_TEST_<dir>`` will appear in ccmake with the description +``<desc>``. The compilation of all tests can be forced with the option +``AKANTU_BUILD_ALL_TESTS`` .. command:: register_test - register_test(<test_name> - SOURCES <sources>... - PACKAGE <akantu_packages>... - SCRIPT <scirpt> - [FILES_TO_COPY <filenames>...] - [DEPENDS <targets>...] - [DIRECTORIES_TO_CREATE <directories>...] - [COMPILE_OPTIONS <flags>...] - [EXTRA_FILES <filnames>...] - [LINK_LIBRARIES <libraries>...] - [UNSABLE] - [PARALLEL] - [PARALLEL_LEVEL <procs>...] - ) - - This function defines a test ``<test_name>_run`` this test could be of - different nature depending on the context. If Just sources are provided the - test consist of running the executable generated. If a file ``<test_name>.sh`` - is present the test will execute the script. And if a ``<test_name>.verified`` - exists the output of the test will be compared to this reference file - - The options are: - - ``SOURCES <sources>...`` - The list of source files to compile to generate the executable of the test - - ``PACKAGE <akantu_packages>...`` - The list of package to which this test belongs. The test will be activable - only of all the packages listed are activated - - ``SCRIPT <script>`` - The script to execute instead of the executable - - ``FILES_TO_COPY <filenames>...`` - List of files to copy from the source directory to the build directory - - ``DEPENDS <targets>...`` - List of targets the test depends on, for example if a mesh as to be generated - - ``DIRECTORIES_TO_CREATE <directories>...`` - Obsolete. This specifies a list of directories that have to be created in - the build folder - - ``COMPILE_OPTIONS <flags>...`` - List of extra compilations options to pass to the compiler - - ``EXTRA_FILES <filnames>...`` - Files to consider when generating a package_source - - ``UNSABLE`` - If this option is specified the test can be unacitivated by the glocal option - ``AKANTU_BUILD_UNSTABLE_TESTS``, this is mainly intendeed to remove test - under developement from the continious integration - - ``PARALLEL`` - This specifies that this test should be run in parallel. It will generate a - series of test for different number of processors. This automaticaly adds a - dependency to the package ``AKANTU_PARALLEL`` - - ``PARALLEL_LEVEL`` - This defines the different processor numbers to use, if not defined the - macro tries to determine it in a "clever" way +register_test(<test_name> + SOURCES <sources>... + PACKAGE <akantu_packages>... + SCRIPT <scirpt> + [FILES_TO_COPY <filenames>...] + [DEPENDS <targets>...] + [DIRECTORIES_TO_CREATE <directories>...] + [COMPILE_OPTIONS <flags>...] + [EXTRA_FILES <filnames>...] + [LINK_LIBRARIES <libraries>...] + [UNSABLE] + [PARALLEL] + [PARALLEL_LEVEL <procs>...] + ) + +This function defines a test ``<test_name>_run`` this test could be of +different nature depending on the context. If Just sources are provided the +test consist of running the executable generated. If a file ``<test_name>.sh`` +is present the test will execute the script. And if a ``<test_name>.verified`` +exists the output of the test will be compared to this reference file + +The options are: + +``SOURCES <sources>...`` +The list of source files to compile to generate the executable of the test + +``PACKAGE <akantu_packages>...`` +The list of package to which this test belongs. The test will be activable +only of all the packages listed are activated + +``SCRIPT <script>`` +The script to execute instead of the executable + +``FILES_TO_COPY <filenames>...`` +List of files to copy from the source directory to the build directory + +``DEPENDS <targets>...`` +List of targets the test depends on, for example if a mesh as to be generated + +``DIRECTORIES_TO_CREATE <directories>...`` +Obsolete. This specifies a list of directories that have to be created in +the build folder + +``COMPILE_OPTIONS <flags>...`` +List of extra compilations options to pass to the compiler + +``EXTRA_FILES <filnames>...`` +Files to consider when generating a package_source + +``UNSABLE`` +If this option is specified the test can be unacitivated by the glocal option +``AKANTU_BUILD_UNSTABLE_TESTS``, this is mainly intendeed to remove test +under developement from the continious integration + +``PARALLEL`` +This specifies that this test should be run in parallel. It will generate a +series of test for different number of processors. This automaticaly adds a +dependency to the package ``AKANTU_PARALLEL`` + +``PARALLEL_LEVEL`` +This defines the different processor numbers to use, if not defined the +macro tries to determine it in a "clever" way ]=======================================================================] set(AKANTU_DRIVER_SCRIPT ${AKANTU_CMAKE_DIR}/akantu_test_driver.sh) # ============================================================================== macro(add_test_tree dir) if(AKANTU_TESTS) enable_testing() include(CTest) mark_as_advanced(BUILD_TESTING) - + set(_akantu_current_parent_test ${dir} CACHE INTERNAL "Current test folder" FORCE) set(_akantu_${dir}_tests_count 0 CACHE INTERNAL "" FORCE) string(TOUPPER ${dir} _u_dir) set(AKANTU_BUILD_${_u_dir} ON CACHE INTERNAL "${desc}" FORCE) package_get_all_test_folders(_test_dirs) foreach(_dir ${_test_dirs}) add_subdirectory(${_dir}) endforeach() endif() endmacro() + +set(_test_flags + UNSTABLE + PARALLEL + ) + +set(_test_one_variables + POSTPROCESS + SCRIPT + ) + +set(_test_multi_variables + SOURCES + FILES_TO_COPY + DEPENDS + DIRECTORIES_TO_CREATE + COMPILE_OPTIONS + EXTRA_FILES + LINK_LIBRARIES + PACKAGE + PARALLEL_LEVEL + ) + + # ============================================================================== function(add_akantu_test dir desc) if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}) return() endif() set(_my_parent_dir ${_akantu_current_parent_test}) - + # initialize variables set(_akantu_current_parent_test ${dir} CACHE INTERNAL "Current test folder" FORCE) set(_akantu_${dir}_tests_count 0 CACHE INTERNAL "" FORCE) # set the option for this directory string(TOUPPER ${dir} _u_dir) option(AKANTU_BUILD_${_u_dir} "${desc}") mark_as_advanced(AKANTU_BUILD_${_u_dir}) - set(AKANTU_${_u_dir}_GTEST_SOURCE "" CACHE INTERNAL "") - # add the sub-directory add_subdirectory(${dir}) - - if(AKANTU_${_u_dir}_GTEST_SOURCE) - set(_srcs) - foreach(_src ${AKANTU_${_u_dir}_GTEST_SOURCE}) - list(APPEND _srcs ${dir}/${_src}) - endforeach() - - add_executable(${dir}_gtest_all ${PROJECT_SOURCE_DIR}/test/test_gtest_main.cc ${_srcs}) - target_link_libraries(${dir}_gtest_all akantu GTest::GTest GTest::Main) - target_include_directories(${dir}_gtest_all PRIVATE ${PROJECT_SOURCE_DIR}/test) - set_property(TARGET ${dir}_gtest_all PROPERTY OUTPUT_NAME ${dir}/gtest_all) - - add_test(NAME ${dir}_gtest COMMAND ${AKANTU_DRIVER_SCRIPT} -n "${dir}" -e "gtest_all" -w "${CMAKE_CURRENT_BINARY_DIR}/${dir}") - endif() # if no test can be activated make the option disappear set(_force_deactivate_count FALSE) if(${_akantu_${dir}_tests_count} EQUAL 0) set(_force_deactivate_count TRUE) endif() # if parent off make the option disappear set(_force_deactivate_parent FALSE) string(TOUPPER ${_my_parent_dir} _u_parent_dir) if(NOT AKANTU_BUILD_${_u_parent_dir}) set(_force_deactivate_parent TRUE) endif() if(_force_deactivate_parent OR _force_deactivate_count OR AKANTU_BUILD_ALL_TESTS) if(NOT DEFINED _AKANTU_BUILD_${_u_dir}_SAVE) set(_AKANTU_BUILD_${_u_dir}_SAVE ${AKANTU_BUILD_${_u_dir}} CACHE INTERNAL "" FORCE) endif() unset(AKANTU_BUILD_${_u_dir} CACHE) if(AKANTU_BUILD_ALL_TESTS AND NOT _force_deactivate_count) set(AKANTU_BUILD_${_u_dir} ON CACHE INTERNAL "${desc}" FORCE) else() set(AKANTU_BUILD_${_u_dir} OFF CACHE INTERNAL "${desc}" FORCE) endif() else() if(DEFINED _AKANTU_BUILD_${_u_dir}_SAVE) unset(AKANTU_BUILD_${_u_dir} CACHE) set(AKANTU_BUILD_${_u_dir} ${_AKANTU_BUILD_${_u_dir}_SAVE} CACHE BOOL "${desc}") unset(_AKANTU_BUILD_${_u_dir}_SAVE CACHE) endif() endif() # adding up to the parent count math(EXPR _tmp_parent_count "${_akantu_${dir}_tests_count} + ${_akantu_${_my_parent_dir}_tests_count}") set(_akantu_${_my_parent_dir}_tests_count ${_tmp_parent_count} CACHE INTERNAL "" FORCE) # restoring the parent current dir set(_akantu_current_parent_test ${_my_parent_dir} CACHE INTERNAL "Current test folder" FORCE) endfunction() - -# ============================================================================== -function(register_test test_name) - set(flags - GTEST - UNSTABLE - PARALLEL - ) - set(one_variables - POSTPROCESS - SCRIPT - ) - set(multi_variables - SOURCES - FILES_TO_COPY - DEPENDS - DIRECTORIES_TO_CREATE - COMPILE_OPTIONS - EXTRA_FILES - LINK_LIBRARIES - PACKAGE - PARALLEL_LEVEL - ) - +function(is_test_active is_active) cmake_parse_arguments(_register_test - "${flags}" - "${one_variables}" - "${multi_variables}" + "${_test_flags}" + "${_test_one_variables}" + "${_test_multi_variables}" ${ARGN} ) if(NOT _register_test_PACKAGE) message(FATAL_ERROR "No reference package was defined for the test" " ${test_name} in folder ${CMAKE_CURRENT_SOURCE_DIR}") endif() set(_test_act TRUE) # Activate the test anly if all packages associated to the test are activated foreach(_package ${_register_test_PACKAGE}) package_is_activated(${_package} _act) if(NOT _act) set(_test_act FALSE) endif() endforeach() # check if the test is marked unstable and if the unstable test should be run if(_register_test_UNSTABLE AND NOT AKANTU_BUILD_UNSTABLE_TESTS) set(_test_act FALSE) endif() + if(_test_act) + # todo this should be checked for the build package_sources since the file will not be listed. + math(EXPR _tmp_parent_count "${_akantu_${_akantu_current_parent_test}_tests_count} + 1") + set(_akantu_${_akantu_current_parent_test}_tests_count ${_tmp_parent_count} CACHE INTERNAL "" FORCE) + endif() + + string(TOUPPER ${_akantu_current_parent_test} _u_parent) + if(NOT (AKANTU_BUILD_${_u_parent} OR AKANTU_BUILD_ALL_TESTS)) + set(_test_act FALSE) + endif() + + set(${is_active} ${_test_act} PARENT_SCOPE) +endfunction() + +# ------------------------------------------------------------------------------ +function(register_gtest_sources) + cmake_parse_arguments(_register_test + "${_test_flags}" + "${_test_one_variables}" + "${_test_multi_variables}" + ${ARGN} + ) + + is_test_active(_is_active ${ARGN}) + register_test_files_to_package(${ARGN}) + + if(NOT _is_active) + return() + endif() + + foreach (_var ${_test_flags}) + if(_register_test_${_var}) + set(_gtest_${_var} ON PARENT_SCOPE) + else() + if(_gtest_${_var}) + message("Another gtest file required ${_var} to be ON it will be globally set for this folder...") + endif() + endif() + endforeach() + + if(_register_test_UNPARSED_ARGUMENTS) + list(APPEND _register_test_SOURCES ${_register_test_UNPARSED_ARGUMENTS}) + endif() + + foreach (_var ${_test_multi_variables}) + if(_register_test_${_var}) + set(_list ${_gtest_${_var}}) + list(APPEND _list ${_register_test_${_var}}) + set(_gtest_${_var} ${_list} PARENT_SCOPE) + endif() + endforeach() +endfunction() + + +function(register_gtest_test test_name) + set(_argn ${test_name}_gtest) + + register_gtest_sources(${ARGN} + SOURCES ${PROJECT_SOURCE_DIR}/test/test_gtest_main.cc + LINK_LIBRARIES GTest::GTest GTest::Main + PACKAGE ${_gtest_PACKAGE} + ) + + foreach (_var ${_test_flags}) + if(_gtest_${_var}) + list(APPEND _argn ${_var}) + unset(_gtest_${_var}) + endif() + endforeach() + + foreach (_var ${_test_multi_variables}) + if(_gtest_${_var}) + list(APPEND _argn ${_var} ${_gtest_${_var}}) + unset(_gtest_${_var}) + endif() + endforeach() + + register_test(${_argn}) + target_include_directories(${test_name}_gtest PRIVATE ${PROJECT_SOURCE_DIR}/test) +endfunction() + +# ============================================================================== +function(register_test test_name) + cmake_parse_arguments(_register_test + "${_test_flags}" + "${_test_one_variables}" + "${_test_multi_variables}" + ${ARGN} + ) + + register_test_files_to_package(${ARGN}) + is_test_active(_test_act ${ARGN}) + if(NOT _test_act) + return() + endif() + # check that the sources are files that need to be compiled if(_register_test_SOURCES} OR _register_test_UNPARSED_ARGUMENTS) set(_need_to_compile TRUE) else() set(_need_to_compile FALSE) endif() set(_compile_source) foreach(_file ${_register_test_SOURCES} ${_register_test_UNPARSED_ARGUMENTS}) if(_file MATCHES "\\.cc$" OR _file MATCHES "\\.hh$") list(APPEND _compile_source ${_file}) endif() endforeach() - # todo this should be checked for the build package_sources since the file will not be listed. - if(_test_act) - math(EXPR _tmp_parent_count "${_akantu_${_akantu_current_parent_test}_tests_count} + 1") - set(_akantu_${_akantu_current_parent_test}_tests_count ${_tmp_parent_count} CACHE INTERNAL "" FORCE) + if(_compile_source) + # get the include directories for sources in activated directories + package_get_all_include_directories( + AKANTU_LIBRARY_INCLUDE_DIRS + ) - string(TOUPPER ${_akantu_current_parent_test} _u_parent) - - if(AKANTU_BUILD_${_u_parent} OR AKANTU_BUILD_ALL_TESTS) - if(_compile_source) - # get the include directories for sources in activated directories - package_get_all_include_directories( - AKANTU_LIBRARY_INCLUDE_DIRS - ) - - # get the external packages compilation and linking informations - package_get_all_external_informations( - AKANTU_EXTERNAL_INCLUDE_DIR - AKANTU_EXTERNAL_LIBRARIES - ) - - - if(NOT _register_test_GTEST) - # Register the executable to compile - add_executable(${test_name} ${_compile_source}) - - # set the proper includes to build most of the tests - target_include_directories(${test_name} - PRIVATE ${AKANTU_LIBRARY_INCLUDE_DIRS} ${AKANTU_EXTERNAL_INCLUDE_DIR} ${PROJECT_BINARY_DIR}/src) - target_link_libraries(${test_name} akantu ${_register_test_LINK_LIBRARIES}) - - if(_register_test_DEPENDS) - add_dependencies(${test_name} ${_register_test_DEPENDS}) - endif() - - # add the extra compilation options - if(_register_test_COMPILE_OPTIONS) - set_target_properties(${test_name} - PROPERTIES COMPILE_DEFINITIONS "${_register_test_COMPILE_OPTIONS}") - endif() - - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_BUILD_TYPE STREQUAL "Debug") - set(AKANTU_EXTRA_CXX_FLAGS "${AKANTU_EXTRA_CXX_FLAGS} -no-pie") - endif() - if(AKANTU_EXTRA_CXX_FLAGS) - set_target_properties(${test_name} - PROPERTIES COMPILE_FLAGS "${AKANTU_EXTRA_CXX_FLAGS}") - endif() - else() - set(_list ${AKANTU_${_u_parent}_GTEST_SOURCE}) - list(APPEND _list ${_compile_source}) - set(AKANTU_${_u_parent}_GTEST_SOURCE ${_list} CACHE INTERNAL "") - endif() - else() - if(_register_test_UNPARSED_ARGUMENTS AND NOT _register_test_SCRIPT) - set(_register_test_SCRIPT ${_register_test_UNPARSED_ARGUMENTS}) - endif() - endif() + # get the external packages compilation and linking informations + package_get_all_external_informations( + AKANTU_EXTERNAL_INCLUDE_DIR + AKANTU_EXTERNAL_LIBRARIES + ) - # copy the needed files to the build folder - if(_register_test_FILES_TO_COPY) - foreach(_file ${_register_test_FILES_TO_COPY}) - file(COPY "${_file}" DESTINATION .) - endforeach() - endif() + # Register the executable to compile + add_executable(${test_name} ${_compile_source}) - # create the needed folders in the build folder - if(_register_test_DIRECTORIES_TO_CREATE) - foreach(_dir ${_register_test_DIRECTORIES_TO_CREATE}) - if(IS_ABSOLUTE ${dir}) - file(MAKE_DIRECTORY "${_dir}") - else() - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${_dir}") - endif() - endforeach() - endif() + # set the proper includes to build most of the tests + target_include_directories(${test_name} + PRIVATE ${AKANTU_LIBRARY_INCLUDE_DIRS} ${AKANTU_EXTERNAL_INCLUDE_DIR} ${PROJECT_BINARY_DIR}/src) + target_link_libraries(${test_name} akantu ${_register_test_LINK_LIBRARIES}) - # register the test for ctest - set(_arguments -n "${test_name}") - if(_register_test_SCRIPT) - file(COPY ${_register_test_SCRIPT} - FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE - DESTINATION .) - list(APPEND _arguments -e "${_register_test_SCRIPT}") - elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${test_name}.sh") - file(COPY ${test_name}.sh DESTINATION .) - list(APPEND _arguments -e "${test_name}.sh") - else() - list(APPEND _arguments -e "${test_name}") - endif() + if(_register_test_DEPENDS) + add_dependencies(${test_name} ${_register_test_DEPENDS}) + endif() + + # add the extra compilation options + if(_register_test_COMPILE_OPTIONS) + set_target_properties(${test_name} + PROPERTIES COMPILE_DEFINITIONS "${_register_test_COMPILE_OPTIONS}") + endif() - list(APPEND _arguments -E "${PROJECT_BINARY_DIR}/akantu_environement.sh") + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_BUILD_TYPE STREQUAL "Debug") + set(AKANTU_EXTRA_CXX_FLAGS "${AKANTU_EXTRA_CXX_FLAGS} -no-pie") + endif() + if(AKANTU_EXTRA_CXX_FLAGS) + set_target_properties(${test_name} + PROPERTIES COMPILE_FLAGS "${AKANTU_EXTRA_CXX_FLAGS}") + endif() + else() + if(_register_test_UNPARSED_ARGUMENTS AND NOT _register_test_SCRIPT) + set(_register_test_SCRIPT ${_register_test_UNPARSED_ARGUMENTS}) + endif() + endif() - package_is_activated(parallel _is_parallel) + # copy the needed files to the build folder + if(_register_test_FILES_TO_COPY) + foreach(_file ${_register_test_FILES_TO_COPY}) + file(COPY "${_file}" DESTINATION .) + endforeach() + endif() - if(_is_parallel AND AKANTU_TESTS_ALWAYS_USE_MPI AND NOT _register_test_PARALLEL) - set(_register_test_PARALLEL TRUE) - set(_register_test_PARALLEL_LEVEL 1) + # create the needed folders in the build folder + if(_register_test_DIRECTORIES_TO_CREATE) + foreach(_dir ${_register_test_DIRECTORIES_TO_CREATE}) + if(IS_ABSOLUTE ${dir}) + file(MAKE_DIRECTORY "${_dir}") + else() + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${_dir}") endif() + endforeach() + endif() - if(_register_test_PARALLEL) - list(APPEND _arguments -p "${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG}") - if(_register_test_PARALLEL_LEVEL) - set(_procs "${_register_test_PARALLEL_LEVEL}") - elseif(CMAKE_VERSION VERSION_GREATER "3.0") - set(_procs) - include(ProcessorCount) - ProcessorCount(N) - while(N GREATER 1) - list(APPEND _procs ${N}) - math(EXPR N "${N} / 2") - endwhile() - endif() - - if(NOT _procs) - set(_procs 2) - endif() - endif() + # register the test for ctest + set(_arguments -n "${test_name}") + if(_register_test_SCRIPT) + file(COPY ${_register_test_SCRIPT} + FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE + DESTINATION .) + list(APPEND _arguments -e "${_register_test_SCRIPT}") + elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${test_name}.sh") + file(COPY ${test_name}.sh DESTINATION .) + list(APPEND _arguments -e "${test_name}.sh") + else() + list(APPEND _arguments -e "${test_name}") + endif() - if(_register_test_POSTPROCESS) - list(APPEND _arguments -s "${_register_test_POSTPROCESS}") - file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${_register_test_POSTPROCESS} - FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE - DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) - endif() + list(APPEND _arguments -E "${PROJECT_BINARY_DIR}/akantu_environement.sh") - list(APPEND _arguments -w "${CMAKE_CURRENT_BINARY_DIR}") + package_is_activated(parallel _is_parallel) + if(_is_parallel AND AKANTU_TESTS_ALWAYS_USE_MPI AND NOT _register_test_PARALLEL) + set(_register_test_PARALLEL TRUE) + set(_register_test_PARALLEL_LEVEL 1) + endif() - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${test_name}.verified") - list(APPEND _arguments -r "${CMAKE_CURRENT_SOURCE_DIR}/${test_name}.verified") - endif() + if(_register_test_PARALLEL) + list(APPEND _arguments -p "${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG}") + if(_register_test_PARALLEL_LEVEL) + set(_procs "${_register_test_PARALLEL_LEVEL}") + elseif(CMAKE_VERSION VERSION_GREATER "3.0") + set(_procs) + include(ProcessorCount) + ProcessorCount(N) + while(N GREATER 1) + list(APPEND _procs ${N}) + math(EXPR N "${N} / 2") + endwhile() + endif() - string(REPLACE ";" " " _command "${_arguments}") - - if(NOT _register_test_GTEST) - - # register them test - if(_procs) - foreach(p ${_procs}) - add_test(NAME ${test_name}_${p} COMMAND ${AKANTU_DRIVER_SCRIPT} ${_arguments} -N ${p}) - endforeach() - else() - add_test(NAME ${test_name} COMMAND ${AKANTU_DRIVER_SCRIPT} ${_arguments}) - endif() - endif() + if(NOT _procs) + set(_procs 2) endif() endif() + if(_register_test_POSTPROCESS) + list(APPEND _arguments -s "${_register_test_POSTPROCESS}") + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${_register_test_POSTPROCESS} + FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + endif() + + list(APPEND _arguments -w "${CMAKE_CURRENT_BINARY_DIR}") + + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${test_name}.verified") + list(APPEND _arguments -r "${CMAKE_CURRENT_SOURCE_DIR}/${test_name}.verified") + endif() + + string(REPLACE ";" " " _command "${_arguments}") + + # register them test + if(_procs) + foreach(p ${_procs}) + add_test(NAME ${test_name}_${p} COMMAND ${AKANTU_DRIVER_SCRIPT} ${_arguments} -N ${p}) + endforeach() + else() + add_test(NAME ${test_name} COMMAND ${AKANTU_DRIVER_SCRIPT} ${_arguments}) + endif() +endfunction() + + +function(register_test_files_to_package) set(_test_all_files) # add the source files in the list of all files foreach(_file ${_register_test_SOURCES} ${_register_test_UNPARSED_ARGUMENTS} ${_register_test_EXTRA_FILES} ${_register_test_SOURCES} ${_register_test_SCRIPT} ${_register_test_POSTPROCESS} ${_register_test_FILES_TO_COPY}) - if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_file}) + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_file} OR EXISTS ${_file}) list(APPEND _test_all_files "${_file}") else() message("The file \"${_file}\" registred by the test \"${test_name}\" does not exists") endif() endforeach() # add the different dependencies files (meshes, local libraries, ...) foreach(_dep ${_register_test_DEPENDS}) get_target_list_of_associated_files(${_dep} _dep_ressources) if(_dep_ressources) list(APPEND _test_all_files "${_dep_ressources}") endif() endforeach() - - # add estra files to the list of files referenced by a given test + + # add extra files to the list of files referenced by a given test if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${test_name}.sh") list(APPEND _test_all_files "${test_name}.sh") endif() if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${test_name}.verified") list(APPEND _test_all_files "${test_name}.verified") endif() if(_register_test_SCRIPT) list(APPEND _test_all_files "${_register_test_SCRIPT}") endif() # clean the list of all files for this test and add them in the total list foreach(_file ${_test_all_files}) get_filename_component(_full ${_file} ABSOLUTE) file(RELATIVE_PATH __file ${PROJECT_SOURCE_DIR} ${_full}) list(APPEND _tmp "${__file}") endforeach() foreach(_pkg ${_register_test_PACKAGE}) package_get_name(${_pkg} _pkg_name) _package_add_to_variable(TESTS_FILES ${_pkg_name} ${_tmp}) endforeach() endfunction() diff --git a/cmake/Modules/FindGMSH.cmake b/cmake/Modules/FindGMSH.cmake index acde537bf..d5308fcc0 100644 --- a/cmake/Modules/FindGMSH.cmake +++ b/cmake/Modules/FindGMSH.cmake @@ -1,97 +1,103 @@ #=============================================================================== # @file FindGMSH.cmake # # @author Nicolas Richart <nicolas.richart@epfl.ch> # # @date creation: Mon Dec 08 2014 # @date last modification: Tue Jan 19 2016 # # @brief Find gmsh and delacre the add_mesh macro # # @section LICENSE # # Copyright (©) 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne) Laboratory # (LSMS - Laboratoire de Simulation en Mécanique des Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see <http://www.gnu.org/licenses/>. # #=============================================================================== find_program(GMSH gmsh DOC "The mesh generetor gmsh") mark_as_advanced(GMSH) if (GMSH) execute_process(COMMAND ${GMSH} --version ERROR_VARIABLE GMSH_VERSION ERROR_STRIP_TRAILING_WHITESPACE) endif() find_package(PackageHandleStandardArgs) find_package_handle_standard_args(GMSH DEFAULT_MSG GMSH) - find_package_handle_standard_args(GMSH - REQUIRED_VARS GMSH - VERSION_VAR GMSH_VERSION) +find_package_handle_standard_args(GMSH + REQUIRED_VARS GMSH + VERSION_VAR GMSH_VERSION) #=============================================================================== -function(ADD_MESH MESH_TARGET GEO_FILE DIM ORDER) - if(GMSH_FOUND) - set(arguments - ${MESH_TARGET} ${GEO_FILE} ${DIM} ${ORDER} - ${ARGN} - ) +function(ADD_MESH MESH_TARGET GEO_FILE) + if(NOT GMSH_FOUND) + return() + endif() + set(arguments + ${MESH_TARGET} ${GEO_FILE} + ${ARGN} + ) - cmake_parse_arguments(ADD_MESH - "" - "OUTPUT" - "" - ${arguments} - ) + cmake_parse_arguments(_add_mesh + "" + "OUTPUT;DIM;ORDER" + "" + ${arguments} + ) - set(_geo_file ${CMAKE_CURRENT_SOURCE_DIR}/${GEO_FILE}) + if(NOT _add_mesh_DIM AND NOT _add_mesh_ORDER) + list(GET _add_mesh_UNPARSED_ARGUMENTS 2 _add_mesh_DIM) + list(GET _add_mesh_UNPARSED_ARGUMENTS 3 _add_mesh_ORDER) + endif() - set(_r_geo_file "${GEO_FILE}") + set(_geo_file ${CMAKE_CURRENT_SOURCE_DIR}/${GEO_FILE}) - if(ADD_MESH_OUTPUT) - set(_msh_file ${CMAKE_CURRENT_BINARY_DIR}/${ADD_MESH_OUTPUT}) - set(_r_msh_file "${ADD_MESH_OUTPUT}") - else(ADD_MESH_OUTPUT) - get_filename_component(_msh_file "${GEO_FILE}" NAME_WE) - set(_msh_file ${CMAKE_CURRENT_BINARY_DIR}/${_msh_file}.msh) - set(_r_msh_file "${_msh_file.msh}") - endif(ADD_MESH_OUTPUT) + set(_r_geo_file "${GEO_FILE}") - if(GMSH_VERSION VERSION_LESS 3.0.0) - set(OPTIMIZE -optimize) - endif() + if(_add_mesh_OUTPUT) + set(_msh_file ${CMAKE_CURRENT_BINARY_DIR}/${_add_mesh_OUTPUT}) + set(_r_msh_file "${_add_mesh_OUTPUT}") + else(_add_mesh_OUTPUT) + get_filename_component(_msh_file "${GEO_FILE}" NAME_WE) + set(_r_msh_file "${_msh_file}.msh") + set(_msh_file ${CMAKE_CURRENT_BINARY_DIR}/${_msh_file}.msh) + endif(_add_mesh_OUTPUT) - if(EXISTS ${_geo_file}) - add_custom_command( - OUTPUT ${_msh_file} - DEPENDS ${_geo_file} - COMMAND ${GMSH} - ARGS -${DIM} -order ${ORDER} ${OPTIMIZE} -o ${_msh_file} ${_geo_file} 2>&1 > /dev/null - COMMENT "Generating the ${DIM}D mesh ${_r_msh_file} (order ${ORDER}) form the geometry ${_r_geo_file}" - ) + if(GMSH_VERSION VERSION_LESS 3.0.0) + set(OPTIMIZE -optimize) + endif() + + if(EXISTS ${_geo_file}) + add_custom_command( + OUTPUT ${_msh_file} + DEPENDS ${_geo_file} + COMMAND ${GMSH} + ARGS -${_add_mesh_DIM} -order ${_add_mesh_ORDER} ${OPTIMIZE} -o ${_msh_file} ${_geo_file} 2>&1 > /dev/null + COMMENT "Generating the ${_add_mesh_DIM}D mesh ${_r_msh_file} (order ${_add_mesh_ORDER}) form the geometry ${_r_geo_file}" + ) - add_custom_target(${MESH_TARGET} - DEPENDS ${_msh_file}) - set_target_properties(${MESH_TARGET} PROPERTIES RESSOURCES ${_geo_file}) - else(EXISTS ${_geo_file}) - message(WARNING - "File ${_geo_file} not found for target ${MESH_TARGET}") - endif(EXISTS ${_geo_file}) - endif(GMSH_FOUND) -endfunction(ADD_MESH) + add_custom_target(${MESH_TARGET} + DEPENDS ${_msh_file}) + set_target_properties(${MESH_TARGET} PROPERTIES RESSOURCES ${_geo_file}) + else(EXISTS ${_geo_file}) + message(WARNING + "File ${_geo_file} not found for target ${MESH_TARGET}") + endif(EXISTS ${_geo_file}) +endfunction() diff --git a/test/test_common/CMakeLists.txt b/test/test_common/CMakeLists.txt index 7985f28f3..5f8d5e30d 100644 --- a/test/test_common/CMakeLists.txt +++ b/test/test_common/CMakeLists.txt @@ -1,48 +1,50 @@ #=============================================================================== # @file CMakeLists.txt # # @author Nicolas Richart <nicolas.richart@epfl.ch> # # @date creation: Fri Sep 03 2010 # @date last modification: Mon Dec 07 2015 # # @brief configurations for common tests # # @section LICENSE # # Copyright (©) 2010-2012, 2014, 2015 EPFL (Ecole Polytechnique Fédérale de # Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des # Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see <http://www.gnu.org/licenses/>. # #=============================================================================== add_akantu_test(test_vector "Test akantu vector") add_mesh(test_grid_mesh circle.geo 2 1) register_test(test_csr test_csr.cc PACKAGE core) register_test(test_grid test_grid.cc DEPENDS test_grid_mesh PACKAGE core) register_test(test_math test_math.cc PACKAGE core) register_test(test_types test_types.cc PACKAGE core) register_test(test_zip_iterator test_zip_iterator.cc PACKAGE core) register_test(test_arange_iterator test_arange_iterator.cc PACKAGE core) -register_test(test_array test_array.cc PACKAGE core GTEST) -register_test(test_tensors test_tensors.cc PACKAGE core GTEST) +register_gtest_sources(SOURCES test_array.cc PACKAGE core) +register_gtest_sources(SOURCES test_tensors.cc PACKAGE core) + +register_gtest_test(test_common) diff --git a/test/test_fe_engine/CMakeLists.txt b/test/test_fe_engine/CMakeLists.txt index 57a63303a..318d1a315 100644 --- a/test/test_fe_engine/CMakeLists.txt +++ b/test/test_fe_engine/CMakeLists.txt @@ -1,113 +1,113 @@ #=============================================================================== # @file CMakeLists.txt # # @author Guillaume Anciaux <guillaume.anciaux@epfl.ch> # # @date creation: Fri Sep 03 2010 # @date last modification: Mon Dec 07 2015 # # @brief configuration for FEM tests # # @section LICENSE # # Copyright (©) 2010-2012, 2014, 2015 EPFL (Ecole Polytechnique Fédérale de # Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des # Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see <http://www.gnu.org/licenses/>. # # @section DESCRIPTION # #=============================================================================== #=============================================================================== function(register_fem_test operation type) set(_target test_${operation}${type}) register_test(${_target} SOURCES test_${operation}.cc FILES_TO_COPY ${type}.msh COMPILE_OPTIONS TYPE=${type} PACKAGE core ) endfunction() #=============================================================================== package_get_element_types(core _types) foreach(_type ${_types}) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_type}.msh) + list(APPEND _meshes ${_type}.msh) register_fem_test(fe_engine_precomputation ${_type}) else() if(NOT ${_type} STREQUAL _point_1) message("The mesh ${_type}.msh is missing, the fe_engine test cannot be activated without it") endif() endif() endforeach() #register_test(test_interpolate_bernoulli_beam_2 test_interpolate_bernoulli_beam_2.cc) #add_mesh(test_fem_circle_1_mesh circle.geo 2 1 OUTPUT circle1.msh) #add_mesh(test_fem_circle_2_mesh circle.geo 2 2 OUTPUT circle2.msh) # Tests for class MeshData macro(register_typed_test test_name type value1 value2) set(target test_${test_name}_${type}) register_test(${target} SOURCES test_${test_name}.cc COMPILE_OPTIONS "TYPE=${type};VALUE1=${value1};VALUE2=${value2}" PACKAGE core ) endmacro() register_typed_test(mesh_data string \"5\" \"10\") register_typed_test(mesh_data UInt 5 10) add_mesh(test_boundary_msh cube.geo 3 1) add_mesh(test_boundary_msh_physical_names cube_physical_names.geo 3 1) register_test(test_mesh_boundary SOURCES test_mesh_boundary.cc DEPENDS test_boundary_msh test_boundary_msh_physical_names PACKAGE core) register_test(test_facet_element_mapping SOURCES test_facet_element_mapping.cc DEPENDS test_boundary_msh_physical_names PACKAGE core) -register_test(test_fe_engine_gauss_integration +register_gtest_sources( SOURCES test_fe_engine_gauss_integration.cc PACKAGE core - GTEST ) -register_test(test_gradient +register_gtest_sources( SOURCES test_gradient.cc PACKAGE core - GTEST ) -register_test(test_integrate +register_gtest_sources( SOURCES test_integrate.cc PACKAGE core - GTEST ) -register_test(test_inverse_map +register_gtest_sources( SOURCES test_inverse_map.cc PACKAGE core - GTEST ) + +register_gtest_test(test_fe_engine + FILES_TO_COPY ${_meshes}) diff --git a/test/test_model/test_solid_mechanics_model/CMakeLists.txt b/test/test_model/test_solid_mechanics_model/CMakeLists.txt index f6ed1b5f3..453e4c2d8 100644 --- a/test/test_model/test_solid_mechanics_model/CMakeLists.txt +++ b/test/test_model/test_solid_mechanics_model/CMakeLists.txt @@ -1,284 +1,292 @@ #=============================================================================== # @file CMakeLists.txt # # @author Guillaume Anciaux <guillaume.anciaux@epfl.ch> # # @date creation: Fri Sep 03 2010 # @date last modification: Tue Jan 19 2016 # # @brief configuratio for SolidMechanicsModel tests # # @section LICENSE # # Copyright (©) 2010-2012, 2014, 2015 EPFL (Ecole Polytechnique Fédérale de # Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des # Solides) # # Akantu is free software: you can redistribute it and/or modify it under the # terms of the GNU Lesser General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Akantu is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with Akantu. If not, see <http://www.gnu.org/licenses/>. # # @section DESCRIPTION # #=============================================================================== add_akantu_test(test_materials "test_materials") add_akantu_test(patch_tests "patch_tests") add_akantu_test(test_cohesive "cohesive_test") add_akantu_test(test_embedded_interface "test_embedded_interface") #=============================================================================== #merged in test_solid_mechanics_model_dynamics #add_mesh(test_solid_mechanics_model_square_mesh square.geo 2 1) #merged in test_solid_mechanics_model_dynamics #add_mesh(test_solid_mechanics_model_circle_mesh1 circle.geo 2 1 OUTPUT circle1.msh) #merged in test_solid_mechanics_model_dynamics #add_mesh(test_solid_mechanics_model_circle_mesh2 circle.geo 2 2 OUTPUT circle2.msh) #merged in test_solid_mechanics_model_dynamics #register_test(test_solid_mechanics_model_square # SOURCES test_solid_mechanics_model_square.cc # DEPENDS test_solid_mechanics_model_square_mesh # FILES_TO_COPY material.dat test_cst_energy.pl # DIRECTORIES_TO_CREATE paraview # PACKAGE core # ) # #register_test(test_solid_mechanics_model_circle_2 # SOURCES test_solid_mechanics_model_circle_2.cc # DEPENDS test_solid_mechanics_model_circle_mesh2 # FILES_TO_COPY material.dat # DIRECTORIES_TO_CREATE paraview # PACKAGE core # ) # #=============================================================================== #merged in test_solid_mechanics_model_dynamics #add_mesh(test_bar_traction_2d_mesh1 bar.geo 2 1 OUTPUT bar1.msh) #add_mesh(test_bar_traction_2d_mesh2 bar.geo 2 2 OUTPUT bar2.msh) #add_mesh(test_bar_traction_2d_mesh_structured1 bar_structured.geo 2 1 OUTPUT bar_structured1.msh) #register_test(test_solid_mechanics_model_bar_traction2d # SOURCES test_solid_mechanics_model_bar_traction2d.cc # DEPENDS test_bar_traction_2d_mesh1 test_bar_traction_2d_mesh2 # FILES_TO_COPY material.dat test_cst_energy.pl # DIRECTORIES_TO_CREATE paraview # PACKAGE core # ) # #register_test(test_solid_mechanics_model_bar_traction2d_structured # SOURCES test_solid_mechanics_model_bar_traction2d_structured.cc # DEPENDS test_bar_traction_2d_mesh_structured1 # FILES_TO_COPY material.dat test_cst_energy.pl # DIRECTORIES_TO_CREATE paraview # PACKAGE core # ) # #=============================================================================== #merged in test_solid_mechanics_model_dynamics #add_mesh(test_solid_mechanics_model_segment_mesh segment.geo 1 2) # #register_test(test_solid_mechanics_model_bar_traction2d_parallel # SOURCES test_solid_mechanics_model_bar_traction2d_parallel.cc # DEPENDS test_bar_traction_2d_mesh2 # FILES_TO_COPY material.dat test_cst_energy.pl # DIRECTORIES_TO_CREATE paraview # PACKAGE parallel # ) # #register_test(test_solid_mechanics_model_segment_parallel # SOURCES test_solid_mechanics_model_segment_parallel.cc # DEPENDS test_solid_mechanics_model_segment_mesh # FILES_TO_COPY material.dat test_cst_energy.pl # DIRECTORIES_TO_CREATE paraview # PACKAGE parallel # ) # #=============================================================================== #register_test(test_solid_mechanics_model_bar_traction2d_mass_not_lumped # SOURCES test_solid_mechanics_model_bar_traction2d_mass_not_lumped.cc # DEPENDS test_bar_traction_2d_mesh1 test_bar_traction_2d_mesh2 # FILES_TO_COPY material.dat # DIRECTORIES_TO_CREATE paraview # PACKAGE implicit # ) #=============================================================================== add_mesh(test_solid_mechanics_model_segment_mesh1 segment.geo 1 1 OUTPUT segment1.msh) add_mesh(test_implicit_mesh1 square_implicit.geo 2 1 OUTPUT square_implicit1.msh) add_mesh(test_implicit_mesh2 square_implicit.geo 2 2 OUTPUT square_implicit2.msh) register_test(test_solid_mechanics_model_implicit_1d SOURCES test_solid_mechanics_model_implicit_1d.cc DEPENDS test_solid_mechanics_model_segment_mesh1 FILES_TO_COPY material.dat DIRECTORIES_TO_CREATE paraview PACKAGE implicit ) register_test(test_solid_mechanics_model_implicit_2d SOURCES test_solid_mechanics_model_implicit_2d.cc DEPENDS test_implicit_mesh1 test_implicit_mesh2 FILES_TO_COPY material_implicit.dat DIRECTORIES_TO_CREATE paraview PACKAGE implicit ) #=============================================================================== #merged in test_solid_mechanics_model_dynamics #add_mesh(test_implicit_beam_2d_1 beam_2d.geo 2 1 OUTPUT beam_2d_lin.msh) #add_mesh(test_implicit_beam_2d_2 beam_2d.geo 2 2 OUTPUT beam_2d_quad.msh) #add_mesh(test_implicit_beam_3d_2 beam_3d.geo 3 2 OUTPUT beam_3d_quad.msh) #add_mesh(test_implicit_beam_3d_1 beam_3d.geo 3 1 OUTPUT beam_3d_lin.msh) #register_test(test_solid_mechanics_model_implicit_dynamic_2d # SOURCES test_solid_mechanics_model_implicit_dynamic_2d.cc # DEPENDS test_implicit_beam_2d_1 test_implicit_beam_2d_2 test_implicit_beam_3d_2 test_implicit_beam_3d_1 # FILES_TO_COPY material_implicit_dynamic.dat # DIRECTORIES_TO_CREATE paraview # PACKAGE implicit # ) # #=============================================================================== # register_test(test_solid_mechanics_model_bar_traction2d_structured_pbc # SOURCES test_solid_mechanics_model_bar_traction2d_structured_pbc.cc # DEPENDS test_bar_traction_2d_mesh_structured1 # FILES_TO_COPY material.dat test_cst_energy.pl # DIRECTORIES_TO_CREATE paraview # PACKAGE core # ) #add_mesh(test_pbc_parallel_mesh square_structured.geo 2 1 OUTPUT square_structured.msh) #register_test(test_solid_mechanics_model_pbc_parallel # SOURCES test_solid_mechanics_model_pbc_parallel.cc # DEPENDS test_pbc_parallel_mesh # FILES_TO_COPY material.dat # DIRECTORIES_TO_CREATE paraview # PACKAGE parallel # ) #=============================================================================== #add_mesh(test_cube3d_mesh1 cube.geo 3 1 OUTPUT cube1.msh) #add_mesh(test_cube3d_mesh2 cube.geo 3 2 OUTPUT cube2.msh) #add_mesh(test_cube3d_mesh_structured cube_structured.geo 3 1 OUTPUT cube_structured.msh) # #register_test(test_solid_mechanics_model_cube3d # SOURCES test_solid_mechanics_model_cube3d.cc # DEPENDS test_cube3d_mesh1 # FILES_TO_COPY material.dat # DIRECTORIES_TO_CREATE paraview # PACKAGE core # ) # #register_test(test_solid_mechanics_model_cube3d_tetra10 # SOURCES test_solid_mechanics_model_cube3d_tetra10.cc # DEPENDS test_cube3d_mesh2 # FILES_TO_COPY material.dat # DIRECTORIES_TO_CREATE paraview # PACKAGE core # ) # # register_test(test_solid_mechanics_model_cube3d_pbc # SOURCES test_solid_mechanics_model_cube3d_pbc.cc # DEPENDS test_cube3d_mesh_structured # FILES_TO_COPY material.dat # DIRECTORIES_TO_CREATE paraview # PACKAGE core # ) #add_mesh(test_solid_mechanics_model_boundary_condition_mesh cube_physical_names.geo 3 1) # register_test(test_solid_mechanics_model_boundary_condition # SOURCES test_solid_mechanics_model_boundary_condition.cc # DEPENDS test_cube3d_mesh1 # FILES_TO_COPY material.dat # PACKAGE core # ) #=============================================================================== add_mesh(test_cube3d_two_mat_mesh cube_two_materials.geo 3 1) register_test(test_solid_mechanics_model_reassign_material SOURCES test_solid_mechanics_model_reassign_material.cc DEPENDS test_cube3d_two_mat_mesh FILES_TO_COPY two_materials.dat PACKAGE parallel PARALLEL ) #=============================================================================== register_test(test_solid_mechanics_model_material_eigenstrain SOURCES test_solid_mechanics_model_material_eigenstrain.cc FILES_TO_COPY cube_3d_tet_4.msh; material_elastic_plane_strain.dat PACKAGE core ) #=============================================================================== register_test(test_material_selector SOURCES test_material_selector.cc FILES_TO_COPY material_selector.dat material_selector.msh PACKAGE core ) +#=============================================================================== +# Energy tests +#=============================================================================== +set(_meshes) package_get_variable(ET_ELEMENT_TYPES core _element_list) foreach(_et ${_element_list}) - if(_et STREQUAL _point_1) - continue() + if(NOT _et STREQUAL _point_1) + list(APPEND _meshes patch_tests/data/${_et}.msh) endif() - - execute_process(COMMAND - ${CMAKE_COMMAND} -E copy_if_different ${_et}.msh ${CMAKE_CURRENT_BINARY_DIR} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/patch_tests/data) endforeach() - -#=============================================================================== -register_test(test_solid_mechanics_model_linear_elastic_potential_energy +register_gtest_sources( SOURCES test_solid_mechanics_model_linear_elastic_potential_energy.cc FILES_TO_COPY test_solid_mechanics_model_linear_elastic_potential_energy_material.dat PACKAGE implicit - GTEST ) -register_test(test_solid_mechanics_model_kinetic_energy +register_gtest_sources( SOURCES test_solid_mechanics_model_kinetic_energy.cc FILES_TO_COPY test_solid_mechanics_model_kinetic_energy_material.dat PACKAGE implicit - GTEST ) #=============================================================================== # dynamics tests #=============================================================================== +add_mesh(bar_segment_2 patch_tests/data/bar_segment.geo + DIM 1 ORDER 1 OUTPUT bar_segment_2.msh) +add_mesh(bar_segment_3 patch_tests/data/bar_segment.geo + DIM 1 ORDER 2 OUTPUT bar_segment_3.msh) +add_mesh(bar_triangle_3 patch_tests/data/bar_triangle.geo + DIM 2 ORDER 1 OUTPUT bar_triangle_3.msh) +add_mesh(bar_triangle_6 patch_tests/data/bar_triangle.geo + DIM 2 ORDER 2 OUTPUT bar_triangle_6.msh) +add_mesh(bar_quadrangle_4 patch_tests/data/bar_quadrangle.geo + DIM 2 ORDER 1 OUTPUT bar_quadrangle_4.msh) +add_mesh(bar_quadrangle_8 patch_tests/data/bar_quadrangle.geo + DIM 2 ORDER 2 OUTPUT bar_quadrangle_8.msh) +add_mesh(bar_tetrahedron_4 patch_tests/data/bar_tetrahedron.geo + DIM 3 ORDER 1 OUTPUT bar_tetrahedron_4.msh) +add_mesh(bar_tetrahedron_10 patch_tests/data/bar_tetrahedron.geo + DIM 3 ORDER 2 OUTPUT bar_tetrahedron_10.msh) +add_mesh(bar_hexahedron_8 patch_tests/data/bar_hexahedron.geo + DIM 3 ORDER 1 OUTPUT bar_hexahedron_8.msh) +add_mesh(bar_hexahedron_20 patch_tests/data/bar_hexahedron.geo + DIM 3 ORDER 2 OUTPUT bar_hexahedron_20.msh) -add_mesh(bar_segment_2 patch_tests/data/bar_segment.geo 1 1 OUTPUT bar_segment_2.msh) -add_mesh(bar_segment_3 patch_tests/data/bar_segment.geo 1 2 OUTPUT bar_segment_3.msh) -add_mesh(bar_triangle_3 patch_tests/data/bar_triangle.geo 2 1 OUTPUT bar_triangle_3.msh) -add_mesh(bar_triangle_6 patch_tests/data/bar_triangle.geo 2 2 OUTPUT bar_triangle_6.msh) -add_mesh(bar_quadrangle_4 patch_tests/data/bar_quadrangle.geo 2 1 OUTPUT bar_quadrangle_4.msh) -add_mesh(bar_quadrangle_8 patch_tests/data/bar_quadrangle.geo 2 2 OUTPUT bar_quadrangle_8.msh) -add_mesh(bar_tetrahedron_4 patch_tests/data/bar_tetrahedron.geo 3 1 OUTPUT bar_tetrahedron_4.msh) -add_mesh(bar_tetrahedron_10 patch_tests/data/bar_tetrahedron.geo 3 2 OUTPUT bar_tetrahedron_10.msh) -add_mesh(bar_hexahedron_8 patch_tests/data/bar_hexahedron.geo 3 1 OUTPUT bar_hexahedron_8.msh) -add_mesh(bar_hexahedron_20 patch_tests/data/bar_hexahedron.geo 3 2 OUTPUT bar_hexahedron_20.msh) - -add_custom_target(patch-test-dynamics-meshes ALL DEPENDS bar_segment_2 bar_segment_3 bar_triangle_3 bar_triangle_6 bar_quadrangle_4 bar_quadrangle_8 bar_tetrahedron_4 bar_tetrahedron_10 bar_hexahedron_8 bar_hexahedron_20) - -register_test(test_solid_mechanics_model_dynamics +register_gtest_sources( SOURCES test_solid_mechanics_model_dynamics.cc FILES_TO_COPY test_solid_mechanics_model_dynamics_material.dat PACKAGE core - GTEST + DEPENDS bar_segment_2 bar_segment_3 bar_triangle_3 bar_triangle_6 + bar_quadrangle_4 bar_quadrangle_8 bar_tetrahedron_4 + bar_tetrahedron_10 bar_hexahedron_8 bar_hexahedron_20 ) + +register_gtest_test(test_solid_mechanics_model + FILES_TO_COPY ${_meshes})