Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DLR-AMR
GitHub Repository: DLR-AMR/t8code
Path: blob/main/test/CMakeLists.txt
900 views
1
# This file is part of t8code.
2
# t8code is a C library to manage a collection (a forest) of multiple
3
# connected adaptive space-trees of general element types in parallel.
4
#
5
# Copyright (C) 2025 the developers
6
#
7
# t8code is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
11
#
12
# t8code is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with t8code; if not, write to the Free Software Foundation, Inc.,
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21
# Function to add a test executable and register it with CTest.
22
# The test executable is built from the provided source files.
23
function( add_t8_test )
24
set( options "" )
25
set( oneValueArgs "NAME" )
26
set( multiValueArgs "SOURCES" )
27
cmake_parse_arguments( ADD_T8_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
28
29
# Get the path of the first file listed in the SOURCES list and use it to determine the build directory.
30
list (LENGTH ADD_T8_TEST_SOURCES TEST_SOURCES_LENGTH)
31
list(GET ADD_T8_TEST_SOURCES 0 TEST_SOURCE)
32
33
get_filename_component(TEST_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/${TEST_SOURCE}" DIRECTORY)
34
file(RELATIVE_PATH TEST_RELATIVE_DIR "${CMAKE_SOURCE_DIR}" "${TEST_SOURCE_DIR}")
35
set(TEST_BUILD_DIR "${CMAKE_BINARY_DIR}/${TEST_RELATIVE_DIR}")
36
37
add_executable( ${ADD_T8_TEST_NAME} ${ADD_T8_TEST_SOURCES} )
38
39
# Link base libraries.
40
target_include_directories( ${ADD_T8_TEST_NAME} PRIVATE ${CMAKE_SOURCE_DIR} )
41
42
target_link_libraries( ${ADD_T8_TEST_NAME} PRIVATE GTest::gtest_main T8 pthread )
43
44
# Check if test is a Fortran or mesh handle file.
45
string( FIND ${ADD_T8_TEST_NAME} "fortran" is_fortran_file )
46
string( FIND ${TEST_BUILD_DIR} "mesh_handle" is_mesh_handle_file )
47
48
if ( (${is_fortran_file} GREATER_EQUAL 0) AND T8CODE_ENABLE_MPI )
49
target_link_libraries( ${ADD_T8_TEST_NAME} PRIVATE MPI::MPI_Fortran )
50
endif ()
51
if ( (${is_mesh_handle_file} GREATER_EQUAL 0) )
52
target_link_libraries( ${ADD_T8_TEST_NAME} PRIVATE T8_MESH_HANDLE )
53
endif ()
54
55
set_target_properties(${ADD_T8_TEST_NAME} PROPERTIES
56
RUNTIME_OUTPUT_DIRECTORY "${TEST_BUILD_DIR}"
57
LIBRARY_OUTPUT_DIRECTORY "${TEST_BUILD_DIR}"
58
ARCHIVE_OUTPUT_DIRECTORY "${TEST_BUILD_DIR}"
59
)
60
61
if( T8CODE_EXPORT_COMPILE_COMMANDS )
62
set_target_properties( ${ADD_T8_TEST_NAME} PROPERTIES EXPORT_COMPILE_COMMANDS ON )
63
endif( T8CODE_EXPORT_COMPILE_COMMANDS )
64
65
# Split custom test command into a list by whitespace.
66
# If MPI is enabled, and no custom test command is provided, use mpirun -np 4 as the default command.
67
# If MPI is not enabled, use the custom test command as is.
68
if ( T8CODE_ENABLE_MPI )
69
if (${ADD_T8_TEST_NAME} MATCHES "_serial")
70
separate_arguments(T8CODE_TEST_COMMAND_LIST NATIVE_COMMAND ${T8CODE_CUSTOM_SERIAL_TEST_COMMAND})
71
elseif ( T8CODE_CUSTOM_PARALLEL_TEST_COMMAND STREQUAL "" )
72
separate_arguments (T8CODE_TEST_COMMAND_LIST NATIVE_COMMAND "mpirun -np 4")
73
else ( T8CODE_CUSTOM_PARALLEL_TEST_COMMAND STREQUAL "" )
74
separate_arguments (T8CODE_TEST_COMMAND_LIST NATIVE_COMMAND ${T8CODE_CUSTOM_PARALLEL_TEST_COMMAND})
75
endif ()
76
else( T8CODE_ENABLE_MPI )
77
separate_arguments (T8CODE_TEST_COMMAND_LIST NATIVE_COMMAND ${T8CODE_CUSTOM_SERIAL_TEST_COMMAND})
78
endif ( T8CODE_ENABLE_MPI )
79
add_test( NAME ${ADD_T8_TEST_NAME} COMMAND ${T8CODE_TEST_COMMAND_LIST} ${TEST_BUILD_DIR}/${ADD_T8_TEST_NAME} )
80
if ( T8CODE_CODE_COVERAGE )
81
# Extent time that a single test is allowed to run to collect coverage information (as this naturally takes more time).
82
# The default timeout of 1500 seconds is actually exceeded for some tests.
83
# Without the collection of coverage information, an extension of the default timeout is not needed.
84
set_tests_properties(${ADD_T8_TEST_NAME} PROPERTIES TIMEOUT 3000)
85
endif ( T8CODE_CODE_COVERAGE )
86
endfunction()
87
88
# Function to add a test executable for C++ tests.
89
# This function wraps the `add_t8_test` function to include common test sources.
90
# Common test sources are t8_gtest_main.cpp and t8_gtest_memory_macros.cxx
91
function ( add_t8_cpp_test)
92
set( options "" )
93
set( oneValueArgs "NAME" )
94
set( multiValueArgs "SOURCES" )
95
cmake_parse_arguments( ADD_T8_CPP_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
96
97
# add cpp sources to SOURCES list and call add_t8_test function
98
list ( APPEND ADD_T8_CPP_TEST_SOURCES t8_gtest_main.cxx t8_gtest_memory_macros.cxx )
99
add_t8_test( NAME ${ADD_T8_CPP_TEST_NAME} SOURCES ${ADD_T8_CPP_TEST_SOURCES} )
100
endfunction()
101
102
# Copy test files to build folder so that the t8_test programs can find them.
103
function( copy_test_file TEST_FILE_NAME )
104
configure_file(${CMAKE_CURRENT_LIST_DIR}/testfiles/${TEST_FILE_NAME} ${CMAKE_CURRENT_BINARY_DIR}/testfiles/${TEST_FILE_NAME} COPYONLY)
105
endfunction()
106
107
add_t8_cpp_test( NAME t8_gtest_cmesh_bcast_parallel SOURCES t8_cmesh/t8_gtest_bcast.cxx )
108
add_t8_cpp_test( NAME t8_gtest_eclass_serial SOURCES t8_gtest_eclass.cxx )
109
add_t8_cpp_test( NAME t8_gtest_mat_serial SOURCES t8_gtest_mat.cxx )
110
add_t8_cpp_test( NAME t8_gtest_refcount_serial SOURCES t8_gtest_refcount.cxx )
111
add_t8_cpp_test( NAME t8_gtest_occ_linkage_serial SOURCES t8_gtest_occ_linkage.cxx )
112
add_t8_cpp_test( NAME t8_gtest_version_serial SOURCES t8_gtest_version.cxx )
113
add_t8_cpp_test( NAME t8_gtest_basics_serial SOURCES t8_gtest_basics.cxx )
114
add_t8_cpp_test( NAME t8_gtest_vtk_linkage_serial SOURCES t8_gtest_vtk_linkage.cxx )
115
116
add_t8_cpp_test( NAME t8_gtest_type_serial SOURCES t8_types/t8_gtest_type.cxx )
117
add_t8_cpp_test( NAME t8_gtest_random_accessible_serial SOURCES t8_types/t8_gtest_random_accessible.cxx )
118
add_t8_cpp_test( NAME t8_gtest_vec_serial SOURCES t8_types/t8_gtest_vec.cxx )
119
120
add_t8_cpp_test( NAME t8_gtest_hypercube_parallel SOURCES t8_cmesh/t8_gtest_hypercube.cxx )
121
add_t8_cpp_test( NAME t8_gtest_cmesh_readmshfile_serial SOURCES t8_cmesh/t8_gtest_cmesh_readmshfile.cxx )
122
add_t8_cpp_test( NAME t8_gtest_cmesh_copy_serial SOURCES t8_cmesh/t8_gtest_cmesh_copy.cxx )
123
add_t8_cpp_test( NAME t8_gtest_cmesh_face_is_boundary_parallel SOURCES t8_cmesh/t8_gtest_cmesh_face_is_boundary.cxx )
124
add_t8_cpp_test( NAME t8_gtest_cmesh_partition_parallel SOURCES t8_cmesh/t8_gtest_cmesh_partition.cxx )
125
add_t8_cpp_test( NAME t8_gtest_cmesh_set_partition_offsets_parallel SOURCES t8_cmesh/t8_gtest_cmesh_set_partition_offsets.cxx )
126
add_t8_cpp_test( NAME t8_gtest_cmesh_set_join_by_vertices_serial SOURCES t8_cmesh/t8_gtest_cmesh_set_join_by_vertices.cxx )
127
add_t8_cpp_test( NAME t8_gtest_cmesh_add_attributes_when_derive_parallel SOURCES t8_cmesh/t8_gtest_cmesh_add_attributes_when_derive.cxx )
128
add_t8_cpp_test( NAME t8_gtest_cmesh_vertex_conn_tree_to_vertex_parallel SOURCES t8_cmesh/t8_gtest_cmesh_vertex_conn_tree_to_vertex.cxx )
129
add_t8_cpp_test( NAME t8_gtest_cmesh_vertex_conn_vertex_to_tree_parallel SOURCES t8_cmesh/t8_gtest_cmesh_vertex_conn_vertex_to_tree.cxx )
130
add_t8_cpp_test( NAME t8_gtest_cmesh_vertex_conn_serial SOURCES t8_cmesh/t8_gtest_cmesh_vertex_conn.cxx )
131
add_t8_cpp_test( NAME t8_gtest_compute_first_element_serial SOURCES t8_cmesh/t8_gtest_compute_first_element.cxx )
132
add_t8_cpp_test( NAME t8_gtest_multiple_attributes_parallel SOURCES t8_cmesh/t8_gtest_multiple_attributes.cxx )
133
add_t8_cpp_test( NAME t8_gtest_attribute_gloidx_array_serial SOURCES t8_cmesh/t8_gtest_attribute_gloidx_array.cxx )
134
add_t8_cpp_test( NAME t8_gtest_cmesh_bounding_box_serial SOURCES t8_cmesh/t8_gtest_cmesh_bounding_box.cxx )
135
136
add_t8_cpp_test( NAME t8_gtest_shmem_parallel SOURCES t8_data/t8_gtest_shmem.cxx )
137
add_t8_cpp_test( NAME t8_gtest_data_pack_parallel SOURCES t8_data/t8_gtest_data_handler.cxx t8_data/t8_data_handler_specs.cxx)
138
139
add_t8_cpp_test( NAME t8_gtest_element_volume_serial SOURCES t8_forest/t8_gtest_element_volume.cxx )
140
add_t8_cpp_test( NAME t8_gtest_search_parallel SOURCES t8_forest/t8_gtest_search.cxx )
141
add_t8_cpp_test( NAME t8_gtest_half_neighbors_parallel SOURCES t8_forest/t8_gtest_half_neighbors.cxx )
142
add_t8_cpp_test( NAME t8_gtest_find_owner_parallel SOURCES t8_forest/t8_gtest_find_owner.cxx )
143
add_t8_cpp_test( NAME t8_gtest_user_data_parallel SOURCES t8_forest/t8_gtest_user_data.cxx )
144
add_t8_cpp_test( NAME t8_gtest_transform_serial SOURCES t8_forest/t8_gtest_transform.cxx )
145
add_t8_cpp_test( NAME t8_gtest_ghost_exchange_parallel SOURCES t8_forest/t8_gtest_ghost_exchange.cxx )
146
add_t8_cpp_test( NAME t8_gtest_ghost_delete_parallel SOURCES t8_forest/t8_gtest_ghost_delete.cxx )
147
add_t8_cpp_test( NAME t8_gtest_ghost_and_owner_parallel SOURCES t8_forest/t8_gtest_ghost_and_owner.cxx )
148
add_t8_cpp_test( NAME t8_gtest_balance_parallel SOURCES t8_forest/t8_gtest_balance.cxx )
149
add_t8_cpp_test( NAME t8_gtest_forest_commit_parallel SOURCES t8_forest/t8_gtest_forest_commit.cxx )
150
add_t8_cpp_test( NAME t8_gtest_forest_face_normal_serial SOURCES t8_forest/t8_gtest_forest_face_normal.cxx )
151
add_t8_cpp_test( NAME t8_gtest_element_is_leaf_serial SOURCES t8_forest/t8_gtest_element_is_leaf.cxx )
152
add_t8_cpp_test( NAME t8_gtest_partition_data_parallel SOURCES t8_forest/t8_gtest_partition_data.cxx )
153
add_t8_cpp_test( NAME t8_gtest_set_partition_offset_parallel SOURCES t8_forest/t8_gtest_set_partition_offset.cxx )
154
add_t8_cpp_test( NAME t8_gtest_partition_for_coarsening_parallel SOURCES t8_forest/t8_gtest_partition_for_coarsening.cxx )
155
add_t8_cpp_test( NAME t8_gtest_weighted_partitioning_parallel SOURCES t8_forest/t8_gtest_weighted_partitioning.cxx )
156
157
add_t8_cpp_test( NAME t8_gtest_permute_hole_serial SOURCES t8_forest_incomplete/t8_gtest_permute_hole.cxx )
158
add_t8_cpp_test( NAME t8_gtest_recursive_serial SOURCES t8_forest_incomplete/t8_gtest_recursive.cxx )
159
add_t8_cpp_test( NAME t8_gtest_iterate_replace_parallel SOURCES t8_forest_incomplete/t8_gtest_iterate_replace.cxx )
160
add_t8_cpp_test( NAME t8_gtest_empty_local_tree_parallel SOURCES t8_forest_incomplete/t8_gtest_empty_local_tree.cxx )
161
add_t8_cpp_test( NAME t8_gtest_empty_global_tree_parallel SOURCES t8_forest_incomplete/t8_gtest_empty_global_tree.cxx )
162
163
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
164
add_t8_cpp_test( NAME t8_gtest_geometry_negative_volume_serial SOURCES t8_geometry/t8_gtest_geometry_negative_volume.cxx )
165
endif()
166
167
if( T8_ENABLE_OCC )
168
add_t8_cpp_test( NAME t8_gtest_geometry_cad_serial SOURCES t8_geometry/t8_geometry_implementations/t8_gtest_geometry_cad.cxx )
169
endif()
170
add_t8_cpp_test( NAME t8_gtest_geometry_linear_serial SOURCES t8_geometry/t8_geometry_implementations/t8_gtest_geometry_linear.cxx )
171
add_t8_cpp_test( NAME t8_gtest_geometry_lagrange_serial SOURCES t8_geometry/t8_geometry_implementations/t8_gtest_geometry_lagrange.cxx )
172
add_t8_cpp_test( NAME t8_gtest_geometry_triangular_interpolation_serial SOURCES t8_geometry/t8_gtest_geometry_triangular_interpolation.cxx )
173
add_t8_cpp_test( NAME t8_gtest_geometry_handling_serial SOURCES t8_geometry/t8_gtest_geometry_handling.cxx )
174
add_t8_cpp_test( NAME t8_gtest_point_inside_serial SOURCES t8_geometry/t8_gtest_point_inside.cxx )
175
176
add_t8_cpp_test( NAME t8_gtest_vtk_writer_parallel SOURCES t8_IO/t8_gtest_vtk_writer.cxx )
177
if( T8CODE_ENABLE_VTK )
178
add_t8_cpp_test( NAME t8_gtest_vtk_reader_parallel SOURCES t8_IO/t8_gtest_vtk_reader.cxx )
179
endif()
180
181
add_t8_cpp_test( NAME t8_gtest_nca_serial SOURCES t8_schemes/t8_gtest_nca.cxx )
182
add_t8_cpp_test( NAME t8_gtest_pyra_connectivity_serial SOURCES t8_schemes/t8_gtest_pyra_connectivity.cxx )
183
add_t8_cpp_test( NAME t8_gtest_face_neigh_serial SOURCES t8_schemes/t8_gtest_face_neigh.cxx )
184
add_t8_cpp_test( NAME t8_gtest_get_linear_id_serial SOURCES t8_schemes/t8_gtest_get_linear_id.cxx )
185
add_t8_cpp_test( NAME t8_gtest_ancestor_serial SOURCES t8_schemes/t8_gtest_ancestor.cxx )
186
add_t8_cpp_test( NAME t8_gtest_ancestor_id_serial SOURCES t8_schemes/t8_gtest_ancestor_id.cxx )
187
add_t8_cpp_test( NAME t8_gtest_element_count_leaves_serial SOURCES t8_schemes/t8_gtest_element_count_leaves.cxx )
188
add_t8_cpp_test( NAME t8_gtest_element_ref_coords_serial SOURCES t8_schemes/t8_gtest_element_ref_coords.cxx )
189
add_t8_cpp_test( NAME t8_gtest_descendant_serial SOURCES t8_schemes/t8_gtest_descendant.cxx )
190
add_t8_cpp_test( NAME t8_gtest_find_parent_serial SOURCES t8_schemes/t8_gtest_find_parent.cxx )
191
add_t8_cpp_test( NAME t8_gtest_equal_serial SOURCES t8_schemes/t8_gtest_equal.cxx )
192
add_t8_cpp_test( NAME t8_gtest_successor_serial SOURCES t8_schemes/t8_gtest_successor.cxx )
193
add_t8_cpp_test( NAME t8_gtest_boundary_extrude_serial SOURCES t8_schemes/t8_gtest_boundary_extrude.cxx )
194
add_t8_cpp_test( NAME t8_gtest_face_descendant_serial SOURCES t8_schemes/t8_gtest_face_descendant.cxx )
195
add_t8_cpp_test( NAME t8_gtest_default_serial SOURCES t8_schemes/t8_gtest_default.cxx )
196
add_t8_cpp_test( NAME t8_gtest_child_parent_face_serial SOURCES t8_schemes/t8_gtest_child_parent_face.cxx )
197
add_t8_cpp_test( NAME t8_gtest_pack_unpack_serial SOURCES t8_schemes/t8_gtest_pack_unpack.cxx )
198
add_t8_cpp_test( NAME t8_gtest_root_serial SOURCES t8_schemes/t8_gtest_root.cxx )
199
add_t8_cpp_test( NAME t8_gtest_scheme_consistency_serial SOURCES t8_schemes/t8_gtest_scheme_consistency.cxx )
200
add_t8_cpp_test( NAME t8_gtest_input_equal_output_serial SOURCES t8_schemes/t8_gtest_input_equal_output.cxx )
201
add_t8_cpp_test( NAME t8_gtest_face_corner_serial SOURCES t8_schemes/t8_gtest_face_corner.cxx )
202
add_t8_cpp_test( NAME t8_gtest_set_linear_id_serial SOURCES t8_schemes/t8_gtest_set_linear_id.cxx )
203
add_t8_cpp_test( NAME t8_gtest_elements_are_family_serial SOURCES t8_schemes/t8_gtest_elements_are_family.cxx )
204
if( T8CODE_BUILD_FORTRAN_INTERFACE AND T8CODE_ENABLE_MPI )
205
add_t8_test( NAME t8_test_fortran_mpi_interface_init_parallel SOURCES api/t8_fortran_interface/t8_test_mpi_init.f90 )
206
endif()
207
208
add_t8_cpp_test( NAME t8_gtest_vector_split_serial SOURCES t8_helper_functions/t8_gtest_vector_split.cxx )
209
210
if( T8CODE_BUILD_MESH_HANDLE )
211
add_t8_cpp_test( NAME t8_gtest_mesh_handle_parallel SOURCES mesh_handle/t8_gtest_mesh_handle.cxx )
212
add_t8_cpp_test( NAME t8_gtest_compare_handle_to_forest_serial SOURCES mesh_handle/t8_gtest_compare_handle_to_forest.cxx )
213
add_t8_cpp_test( NAME t8_gtest_handle_ghost_parallel SOURCES mesh_handle/t8_gtest_ghost.cxx )
214
add_t8_cpp_test( NAME t8_gtest_custom_competence_serial SOURCES mesh_handle/t8_gtest_custom_competence.cxx )
215
add_t8_cpp_test( NAME t8_gtest_cache_competence_serial SOURCES mesh_handle/t8_gtest_cache_competence.cxx )
216
add_t8_cpp_test( NAME t8_gtest_handle_data_parallel SOURCES mesh_handle/t8_gtest_handle_data.cxx )
217
endif()
218
219
copy_test_file( test_cube_unstructured_1.inp )
220
copy_test_file( test_cube_unstructured_2.inp )
221
copy_test_file( test_vtk_tri.vtu )
222
copy_test_file( test_vtk_cube.vtp )
223
copy_test_file( test_parallel_file.pvtu )
224
copy_test_file( test_parallel_file_0.vtu )
225
copy_test_file( test_parallel_file_1.vtu )
226
copy_test_file( test_polydata.pvtp )
227
copy_test_file( test_polydata_0.vtp )
228
copy_test_file( test_polydata_1.vtp )
229
copy_test_file( test_msh_file_vers4_ascii.msh )
230
copy_test_file( test_msh_file_vers4_bin.msh )
231
232