Skip to content

Commit bb3c441

Browse files
committed
test/[nompi,mpi] dirs to allow simultaneous runs without mixing files
1 parent f0a4e03 commit bb3c441

30 files changed

+181
-172
lines changed

test/CMakeLists.txt

Lines changed: 2 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -1,175 +1,5 @@
1-
set_directory_properties(PROPERTIES LABELS unit)
2-
3-
# --- helper functions
4-
5-
function(nompi_test names)
6-
7-
foreach(name IN LISTS names)
8-
9-
add_executable(test_${name} test_${name}.f90)
10-
target_link_libraries(test_${name} PRIVATE h5fortran::h5fortran)
11-
12-
add_test(NAME ${name} COMMAND test_${name})
13-
14-
endforeach()
15-
16-
set_tests_properties(${names} PROPERTIES
17-
LABELS nompi
18-
)
19-
20-
endfunction(nompi_test)
21-
22-
23-
function(mpi_test names use_runner)
24-
25-
foreach(name IN LISTS names)
26-
27-
add_executable(test_${name} test_${name}.f90)
28-
target_link_libraries(test_${name} PRIVATE h5fortran::h5fortran)
29-
30-
if(use_runner)
31-
set(cmd test_runner -exe $<TARGET_FILE:test_${name}> -mpiexec ${MPIEXEC_EXECUTABLE} -lx 1000)
32-
else()
33-
set(cmd ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} $<TARGET_FILE:test_${name}>)
34-
# these tests could also be -n 2 instead of max_numprocs.
35-
# Just trying to keep aware of possible problems vs. MPI worker count.
36-
endif()
37-
38-
if(${name} STREQUAL "string_read")
39-
list(APPEND cmd ${string_file})
40-
endif()
41-
42-
add_test(NAME ${name} COMMAND ${cmd})
43-
44-
endforeach()
45-
46-
set_tests_properties(${names} PROPERTIES
47-
RESOURCE_LOCK cpu_mpi
48-
LABELS mpi
49-
)
50-
51-
endfunction(mpi_test)
52-
53-
# --- test files
54-
55-
cmake_path(SET string_file ${CMAKE_CURRENT_BINARY_DIR}/test_string_py.h5)
56-
57-
# --- non-MPI tests
58-
59-
set(nompi_tests array attributes cast deflate_props deflate_read deflate_write destructor
60-
exist fill
61-
)
62-
63-
nompi_test("${nompi_tests}")
64-
65-
set_tests_properties(deflate_write PROPERTIES
66-
FIXTURES_SETUP deflate_files
67-
)
68-
69-
set_tests_properties(deflate_props deflate_read PROPERTIES
70-
FIXTURES_REQUIRED deflate_files
71-
REQUIRED_FILES ${CMAKE_CURRENT_BINARY_DIR}/deflate1.h5
72-
)
73-
74-
75-
# --- runner
1+
add_subdirectory(nompi)
762

773
if(hdf5_parallel)
78-
79-
add_executable(test_runner runner.f90
80-
${PROJECT_SOURCE_DIR}/benchmark/cpu.cpp
81-
${PROJECT_SOURCE_DIR}/benchmark/partition.f90
82-
${PROJECT_SOURCE_DIR}/benchmark/cli.f90
83-
)
84-
# not linked as libraries in case benchmarks aren't built
85-
if(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
86-
set_target_properties(test_runner PROPERTIES LINKER_LANGUAGE Fortran)
87-
else()
88-
set_target_properties(test_runner PROPERTIES LINKER_LANGUAGE CXX)
89-
endif()
90-
91-
92-
# --- MPI tests
93-
94-
set(mpi_tests array_mpi attributes_mpi cast_mpi destructor_mpi exist_mpi
95-
fill_mpi groups_mpi layout shape
96-
string string_read write
97-
)
98-
99-
mpi_test("${mpi_tests}" false)
100-
101-
set(runner_tests deflate_write_mpi deflate_props_mpi deflate_read_mpi)
102-
103-
mpi_test("${runner_tests}" true)
104-
105-
# --- test dependencies
106-
107-
set_tests_properties(write PROPERTIES
108-
FIXTURES_SETUP test_files
109-
)
110-
111-
set_tests_properties(layout shape PROPERTIES
112-
FIXTURES_REQUIRED test_files
113-
REQUIRED_FILES "${CMAKE_CURRENT_BINARY_DIR}/test_write.h5;${CMAKE_CURRENT_BINARY_DIR}/test_layout.h5"
114-
)
115-
116-
set_tests_properties(deflate_write_mpi PROPERTIES
117-
FIXTURES_SETUP deflate_files_mpi
118-
)
119-
120-
set_tests_properties(deflate_props_mpi deflate_read_mpi PROPERTIES
121-
FIXTURES_REQUIRED deflate_files_mpi
122-
REQUIRED_FILES ${CMAKE_CURRENT_BINARY_DIR}/deflate1.h5
123-
)
124-
125-
if(ENABLE_COVERAGE)
126-
setup_target_for_coverage_gcovr_html(
127-
NAME coverage
128-
EXECUTABLE ${CMAKE_CTEST_COMMAND}
129-
)
130-
endif()
131-
132-
# --- Python h5py
133-
find_package(Python COMPONENTS Interpreter)
134-
if(NOT DEFINED h5py_ok)
135-
execute_process(COMMAND ${Python_EXECUTABLE} -c "import h5py"
136-
RESULT_VARIABLE h5py_code
137-
)
138-
if(h5py_code EQUAL 0)
139-
set(h5py_ok true CACHE BOOL "h5py OK")
140-
else()
141-
set(h5py_ok false CACHE BOOL "h5py not OK")
142-
endif()
143-
endif()
144-
145-
set_tests_properties(string_read PROPERTIES
146-
FIXTURES_REQUIRED h5str
147-
DISABLED $<NOT:$<BOOL:${h5py_ok}>>
148-
)
149-
150-
add_test(NAME PythonString
151-
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_string.py ${string_file}
152-
)
153-
154-
set_tests_properties(PythonString PROPERTIES
155-
FIXTURES_SETUP h5str
156-
DISABLED $<NOT:$<BOOL:${h5py_ok}>>
157-
)
158-
159-
endif(hdf5_parallel)
160-
161-
# --- test properties
162-
163-
get_property(test_names DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY TESTS)
164-
165-
set_tests_properties(${test_names} PROPERTIES
166-
TIMEOUT 30
167-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
168-
)
169-
170-
# --- Windows shared DLLs
171-
if(WIN32 AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.22)
172-
set_tests_properties(${test_names} PROPERTIES
173-
ENVIRONMENT_MODIFICATION "PATH=path_list_append:${ZLIB_INCLUDE_DIRS}/../bin;PATH=path_list_append:${ZLIB_INCLUDE_DIR}/../bin"
174-
)
4+
add_subdirectory(mpi)
1755
endif()

test/mpi/CMakeLists.txt

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
set_directory_properties(PROPERTIES LABELS mpi)
2+
3+
# --- helper functions
4+
5+
function(mpi_test names use_runner)
6+
7+
foreach(name IN LISTS names)
8+
9+
add_executable(test_${name} test_${name}.f90)
10+
target_link_libraries(test_${name} PRIVATE h5fortran::h5fortran)
11+
12+
if(use_runner)
13+
set(cmd test_runner -exe $<TARGET_FILE:test_${name}> -mpiexec ${MPIEXEC_EXECUTABLE} -lx 1000)
14+
else()
15+
set(cmd ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} $<TARGET_FILE:test_${name}>)
16+
# these tests could also be -n 2 instead of max_numprocs.
17+
# Just trying to keep aware of possible problems vs. MPI worker count.
18+
endif()
19+
20+
if(${name} STREQUAL "string_read")
21+
list(APPEND cmd ${string_file})
22+
endif()
23+
24+
add_test(NAME ${name} COMMAND ${cmd})
25+
26+
endforeach()
27+
28+
set_tests_properties(${names} PROPERTIES
29+
RESOURCE_LOCK cpu_mpi
30+
LABELS mpi
31+
)
32+
33+
endfunction(mpi_test)
34+
35+
# --- test files
36+
37+
cmake_path(SET string_file ${CMAKE_CURRENT_BINARY_DIR}/test_string_py.h5)
38+
39+
add_executable(test_runner runner.f90
40+
${PROJECT_SOURCE_DIR}/benchmark/cpu.cpp
41+
${PROJECT_SOURCE_DIR}/benchmark/partition.f90
42+
${PROJECT_SOURCE_DIR}/benchmark/cli.f90
43+
)
44+
# not linked as libraries in case benchmarks aren't built
45+
if(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
46+
set_target_properties(test_runner PROPERTIES LINKER_LANGUAGE Fortran)
47+
else()
48+
set_target_properties(test_runner PROPERTIES LINKER_LANGUAGE CXX)
49+
endif()
50+
51+
52+
# --- MPI tests
53+
54+
set(mpi_tests array_mpi attributes_mpi cast_mpi destructor_mpi exist_mpi
55+
fill_mpi groups_mpi layout shape
56+
string string_read write
57+
)
58+
59+
mpi_test("${mpi_tests}" false)
60+
61+
set(runner_tests deflate_write_mpi deflate_props_mpi deflate_read_mpi)
62+
63+
mpi_test("${runner_tests}" true)
64+
65+
# --- test dependencies
66+
67+
set_tests_properties(write PROPERTIES
68+
FIXTURES_SETUP test_files
69+
)
70+
71+
set_tests_properties(layout shape PROPERTIES
72+
FIXTURES_REQUIRED test_files
73+
REQUIRED_FILES "${CMAKE_CURRENT_BINARY_DIR}/test_write.h5;${CMAKE_CURRENT_BINARY_DIR}/test_layout.h5"
74+
)
75+
76+
set_tests_properties(deflate_write_mpi PROPERTIES
77+
FIXTURES_SETUP deflate_files_mpi
78+
)
79+
80+
set_tests_properties(deflate_props_mpi deflate_read_mpi PROPERTIES
81+
FIXTURES_REQUIRED deflate_files_mpi
82+
REQUIRED_FILES ${CMAKE_CURRENT_BINARY_DIR}/deflate1.h5
83+
)
84+
85+
if(ENABLE_COVERAGE)
86+
setup_target_for_coverage_gcovr_html(
87+
NAME coverage
88+
EXECUTABLE ${CMAKE_CTEST_COMMAND}
89+
)
90+
endif()
91+
92+
# --- Python h5py
93+
find_package(Python COMPONENTS Interpreter)
94+
if(NOT DEFINED h5py_ok)
95+
execute_process(COMMAND ${Python_EXECUTABLE} -c "import h5py"
96+
RESULT_VARIABLE h5py_code
97+
)
98+
if(h5py_code EQUAL 0)
99+
set(h5py_ok true CACHE BOOL "h5py OK")
100+
else()
101+
set(h5py_ok false CACHE BOOL "h5py not OK")
102+
endif()
103+
endif()
104+
105+
set_tests_properties(string_read PROPERTIES
106+
FIXTURES_REQUIRED h5str
107+
DISABLED $<NOT:$<BOOL:${h5py_ok}>>
108+
)
109+
110+
add_test(NAME PythonString
111+
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_string.py ${string_file}
112+
)
113+
114+
set_tests_properties(PythonString PROPERTIES
115+
FIXTURES_SETUP h5str
116+
DISABLED $<NOT:$<BOOL:${h5py_ok}>>
117+
)
118+
119+
# --- test properties
120+
121+
get_property(test_names DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY TESTS)
122+
123+
set_tests_properties(${test_names} PROPERTIES
124+
TIMEOUT 30
125+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
126+
)
127+
128+
# --- Windows shared DLLs
129+
if(WIN32 AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.22)
130+
set_tests_properties(${test_names} PROPERTIES
131+
ENVIRONMENT_MODIFICATION "PATH=path_list_append:${ZLIB_INCLUDE_DIRS}/../bin;PATH=path_list_append:${ZLIB_INCLUDE_DIR}/../bin"
132+
)
133+
endif()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)