Skip to content

Commit 65e18ef

Browse files
committed
test: simplify and correct Python
1 parent b5838db commit 65e18ef

File tree

9 files changed

+68
-121
lines changed

9 files changed

+68
-121
lines changed

CMakeLists.txt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.19...3.28)
1+
cmake_minimum_required(VERSION 3.20...3.30)
22

33
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
44
message(FATAL_ERROR "please use out-of-source build
@@ -16,15 +16,12 @@ VERSION 2.1.0
1616
)
1717

1818
include(CTest)
19-
if(NOT DEFINED ${PROJECT_NAME}_BUILD_TESTING)
20-
set(${PROJECT_NAME}_BUILD_TESTING ${BUILD_TESTING})
21-
endif()
2219

23-
if(benchmark)
24-
set(${PROJECT_NAME}_BUILD_TESTING true)
25-
endif()
20+
include(options.cmake)
2621

2722
if(${PROJECT_NAME}_BUILD_TESTING)
23+
find_package(Python COMPONENTS Interpreter)
24+
2825
enable_language(CXX)
2926
endif()
3027

@@ -39,7 +36,6 @@ if(DEFINED ENV{CONDA_PREFIX})
3936
# despite CMAKE_IGNORE_PREFIX_PATH
4037
endif()
4138

42-
include(options.cmake)
4339
include(cmake/compilers.cmake)
4440

4541
# if HDF5-MPI, ensure all the pieces are working together at configure time.

benchmark/CMakeLists.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.14...3.24)
1+
cmake_minimum_required(VERSION 3.21...3.30)
22

33
project(h5mpi-benchmark
44
LANGUAGES C CXX Fortran
@@ -10,14 +10,9 @@ set_property(DIRECTORY PROPERTY LABELS benchmark)
1010

1111
file(GENERATE OUTPUT .gitignore CONTENT "*")
1212

13-
if(CMAKE_VERSION VERSION_LESS 3.21)
14-
get_property(not_top DIRECTORY PROPERTY PARENT_DIRECTORY)
15-
if(NOT not_top)
16-
set(PROJECT_IS_TOP_LEVEL true)
17-
endif()
18-
endif()
19-
2013
if(PROJECT_IS_TOP_LEVEL)
14+
find_package(Python COMPONENTS Interpreter)
15+
2116
find_package(h5fortran CONFIG REQUIRED)
2217

2318
add_library(cpu_count OBJECT ${PROJECT_SOURCE_DIR}/../test/cpu_count.cpp)

benchmark/test/CMakeLists.txt

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@ target_link_libraries(slab_serial_write PRIVATE cli perf test_utils kernel h5for
1616
add_executable(slab_serial_read slab_serial_read.f90)
1717
target_link_libraries(slab_serial_read PRIVATE cli perf h5fortran::h5fortran)
1818

19-
if(CMAKE_VERSION VERSION_LESS 3.20)
20-
get_filename_component(HDF5_LIBRARY_DIR ${HDF5_C_LIBRARY} DIRECTORY)
21-
get_filename_component(HDF5_DIR ${HDF5_LIBRARY_DIR} DIRECTORY)
22-
else()
23-
cmake_path(GET HDF5_C_LIBRARY PARENT_PATH HDF5_LIBRARY_DIR)
24-
cmake_path(GET HDF5_LIBRARY_DIR PARENT_PATH HDF5_DIR)
25-
endif()
19+
cmake_path(GET HDF5_C_LIBRARY PARENT_PATH HDF5_LIBRARY_DIR)
20+
cmake_path(GET HDF5_LIBRARY_DIR PARENT_PATH HDF5_DIR)
21+
2622
find_program(H5DIFF
2723
NAMES h5diff
2824
HINTS ${HDF5_ROOT} ${HDF5_DIR}
@@ -138,19 +134,14 @@ foreach(comp_lvl 0 1)
138134
set_property(TEST mpi-cleanup-comp${comp_lvl} PROPERTY TIMEOUT ${read_timeout})
139135
endforeach()
140136

141-
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12)
142-
set(Python_FIND_REGISTRY LAST)
143-
find_package(Python COMPONENTS Interpreter)
144-
145-
if(NOT DEFINED PyOK)
146-
execute_process(COMMAND ${Python_EXECUTABLE} -c "import h5py,numpy,pandas,matplotlib"
147-
RESULT_VARIABLE ret
148-
)
149-
if(ret EQUAL 0)
150-
set(PyOK true CACHE BOOL "Python ready")
151-
else()
152-
set(PyOK false CACHE BOOL "python not ready")
153-
endif()
137+
if(Python_Interpreter_FOUND AND NOT DEFINED PyOK)
138+
execute_process(COMMAND ${Python_EXECUTABLE} -c "import h5py,numpy,pandas,matplotlib"
139+
RESULT_VARIABLE ret
140+
)
141+
if(ret EQUAL 0)
142+
set(PyOK true CACHE BOOL "Python ready")
143+
else()
144+
set(PyOK false CACHE BOOL "python not ready")
154145
endif()
155146
endif()
156147

cmake/ExtProj.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ include_guard()
44

55
include(ExternalProject)
66

7-
if(CMAKE_VERSION VERSION_LESS 3.19)
8-
message(FATAL_ERROR "CMake >= 3.19 required to use JSON")
9-
endif()
10-
117
file(READ ${CMAKE_CURRENT_LIST_DIR}/libraries.json json)
128

139

cmake/hdf5_compression.cmake

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,8 @@ end program
8585

8686
set(CMAKE_REQUIRED_LIBRARIES HDF5::HDF5 MPI::MPI_Fortran MPI::MPI_C)
8787

88-
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)
89-
# need this if() for parser
90-
include(CheckFortranSourceRuns)
91-
check_fortran_source_runs(${src} hdf5_parallel_compression_run)
92-
endif()
88+
include(CheckSourceRuns)
89+
check_source_runs(Fortran ${src} hdf5_parallel_compression_run)
9390

9491
if(hdf5_parallel_compression_run)
9592
message(CHECK_PASS "${CMAKE_MATCH_1}")
@@ -108,13 +105,8 @@ if(DEFINED CACHE{hdf5_parallel_compression})
108105
return()
109106
endif()
110107

111-
if(CMAKE_VERSION VERSION_LESS 3.20)
112-
get_filename_component(HDF5_LIBRARY_DIR ${HDF5_C_LIBRARY} DIRECTORY)
113-
get_filename_component(HDF5_DIR ${HDF5_LIBRARY_DIR} DIRECTORY)
114-
else()
115-
cmake_path(GET HDF5_C_LIBRARY PARENT_PATH HDF5_LIBRARY_DIR)
116-
cmake_path(GET HDF5_LIBRARY_DIR PARENT_PATH HDF5_DIR)
117-
endif()
108+
cmake_path(GET HDF5_C_LIBRARY PARENT_PATH HDF5_LIBRARY_DIR)
109+
cmake_path(GET HDF5_LIBRARY_DIR PARENT_PATH HDF5_DIR)
118110

119111
message(CHECK_START "Checking if HDF5 configured for parallel compression")
120112

@@ -147,13 +139,7 @@ file(READ ${hdf5_settings_file} hdf5_settings)
147139
string(REGEX MATCH "Parallel Filtered Dataset Writes:[ ]*([a-zA-Z]+)" hdf5_parallel_compression_match ${hdf5_settings})
148140

149141
if(${CMAKE_MATCH_1})
150-
151-
if(CMAKE_VERSION VERSION_LESS 3.14)
152-
check_compression()
153-
else()
154-
set(hdf5_parallel_compression .true. CACHE STRING "HDF5-MPI configured for parallel compression (assumed due to CMake < 3.14)")
155-
endif()
156-
142+
check_compression()
157143
else()
158144
message(CHECK_FAIL "NO")
159145
set(hdf5_parallel_compression .false. CACHE STRING "HDF5-MPI does not have parallel compression")

options.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ message(STATUS "${PROJECT_NAME} ${PROJECT_VERSION} CMake ${CMAKE_VERSION}")
33
option(find_hdf5 "search for HDF5 and Zlib" true)
44

55
option(benchmark "Run benchmarks")
6+
7+
option(${PROJECT_NAME}_BUILD_TESTING "Build tests" ${PROJECT_IS_TOP_LEVEL})
8+
if(benchmark)
9+
set(${PROJECT_NAME}_BUILD_TESTING true)
10+
endif()
11+
612
option(coverage "Code coverage tests")
713
option(tidy "Run clang-tidy on the code")
814

test/CMakeLists.txt

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ target_compile_definitions(cpu_count PRIVATE $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_WA
88
target_include_directories(cpu_count PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
99

1010
# --- Python h5py
11-
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12)
12-
13-
set(Python_FIND_REGISTRY LAST)
14-
find_package(Python COMPONENTS Interpreter)
15-
if(NOT DEFINED h5py_ok)
11+
if(Python_Interpreter_FOUND AND NOT DEFINED h5py_ok)
1612
execute_process(COMMAND ${Python_EXECUTABLE} -c "import h5py"
1713
RESULT_VARIABLE h5py_code
1814
ERROR_VARIABLE err
@@ -22,20 +18,20 @@ if(NOT DEFINED h5py_ok)
2218
set(h5py_ok true CACHE BOOL "h5py OK")
2319
else()
2420
set(h5py_ok false CACHE BOOL "h5py not OK")
25-
message(VERBOSE "${err}")
21+
message(VERBOSE "${Python_EXECUTABLE}: ${err}")
2622
endif()
2723
endif()
2824

29-
endif()
30-
3125
set(string_file ${CMAKE_CURRENT_BINARY_DIR}/test_string_py.h5)
3226

3327
add_test(NAME PythonString
34-
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_string.py ${string_file}
28+
COMMAND Python::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/test_string.py ${string_file}
3529
)
3630

37-
set_property(TEST PythonString PROPERTY FIXTURES_SETUP h5str)
38-
set_property(TEST PythonString PROPERTY DISABLED $<NOT:$<BOOL:${h5py_ok}>>)
31+
set_tests_properties(PythonString PROPERTIES
32+
FIXTURES_SETUP h5str
33+
DISABLED $<NOT:$<BOOL:${h5py_ok}>>
34+
)
3935

4036
# --- test subdirs
4137

test/mpi/CMakeLists.txt

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ set_property(DIRECTORY PROPERTY LABELS mpi)
22

33
# --- helper functions
44

5-
function(mpi_test names use_runner)
6-
7-
foreach(name IN LISTS names)
5+
function(mpi_test name use_runner)
86

97
set(tname "${name}_mpi")
108

@@ -25,8 +23,6 @@ endif()
2523

2624
add_test(NAME ${tname} COMMAND ${cmd})
2725

28-
endforeach()
29-
3026
endfunction(mpi_test)
3127

3228
# --- test files
@@ -52,33 +48,45 @@ fill groups layout shape
5248
string string_read write
5349
)
5450

55-
mpi_test("${mpi_tests}" false)
51+
foreach(t IN LISTS mpi_tests)
52+
mpi_test(${t} false)
53+
endforeach()
5654

5755
set(runner_tests deflate_write deflate_props deflate_read)
5856

59-
mpi_test("${runner_tests}" true)
57+
foreach(t IN LISTS runner_tests)
58+
mpi_test(${t} true)
59+
endforeach()
6060

6161
# --- test dependencies
6262

6363
set_property(TEST write_mpi PROPERTY FIXTURES_SETUP test_files)
6464

65-
set_property(TEST layout_mpi shape_mpi PROPERTY FIXTURES_REQUIRED test_files)
66-
set_property(TEST layout_mpi shape_mpi PROPERTY REQUIRED_FILES "${CMAKE_CURRENT_BINARY_DIR}/test_write.h5;${CMAKE_CURRENT_BINARY_DIR}/test_layout.h5")
65+
set_tests_properties(layout_mpi shape_mpi PROPERTIES
66+
FIXTURES_REQUIRED test_files
67+
REQUIRED_FILES "${CMAKE_CURRENT_BINARY_DIR}/test_write.h5;${CMAKE_CURRENT_BINARY_DIR}/test_layout.h5"
68+
)
6769

6870
set_property(TEST deflate_write_mpi PROPERTY FIXTURES_SETUP deflate_files_mpi)
6971

70-
set_property(TEST deflate_props_mpi deflate_read_mpi PROPERTY FIXTURES_REQUIRED deflate_files_mpi)
71-
set_property(TEST deflate_props_mpi deflate_read_mpi PROPERTY REQUIRED_FILES ${CMAKE_CURRENT_BINARY_DIR}/deflate1.h5)
72+
set_tests_properties(deflate_props_mpi deflate_read_mpi PROPERTIES
73+
FIXTURES_REQUIRED deflate_files_mpi
74+
REQUIRED_FILES ${CMAKE_CURRENT_BINARY_DIR}/deflate1.h5
75+
)
7276

73-
set_property(TEST string_read_mpi PROPERTY FIXTURES_REQUIRED h5str)
74-
set_property(TEST string_read_mpi PROPERTY DISABLED $<NOT:$<BOOL:${h5py_ok}>>)
77+
set_tests_properties(string_read_mpi PROPERTIES
78+
FIXTURES_REQUIRED h5str
79+
DISABLED $<NOT:$<BOOL:${h5py_ok}>>
80+
)
7581

7682
# --- test properties
7783

7884
get_property(test_names DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY TESTS)
7985

80-
set_property(TEST ${test_names} PROPERTY WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
81-
set_property(TEST ${test_names} PROPERTY RESOURCE_LOCK cpu_mpi)
86+
set_tests_properties(${test_names} PROPERTIES
87+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
88+
RESOURCE_LOCK cpu_mpi
89+
)
8290

8391
# --- Windows shared DLLs
8492
if(WIN32 AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.22)

test/nompi/CMakeLists.txt

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
set_property(DIRECTORY PROPERTY LABELS nompi)
22

3-
function(nompi_test names)
4-
5-
foreach(name IN LISTS names)
3+
function(nompi_test name)
64

75
add_executable(test_${name} test_${name}.f90)
86
target_link_libraries(test_${name} PRIVATE h5fortran::h5fortran)
@@ -15,8 +13,6 @@ else()
1513
add_test(NAME ${name} COMMAND test_${name})
1614
endif()
1715

18-
endforeach()
19-
2016
endfunction(nompi_test)
2117

2218

@@ -25,7 +21,9 @@ exist fill groups layout
2521
shape string string_read write
2622
)
2723

28-
nompi_test("${nompi_tests}")
24+
foreach(t IN LISTS nompi_tests)
25+
nompi_test(${t})
26+
endforeach()
2927

3028
# --- test dependencies
3129

@@ -39,6 +37,11 @@ set_property(TEST deflate_write PROPERTY FIXTURES_SETUP deflate_files)
3937
set_property(TEST deflate_props deflate_read PROPERTY FIXTURES_REQUIRED deflate_files)
4038
set_property(TEST deflate_props deflate_read PROPERTY REQUIRED_FILES ${CMAKE_CURRENT_BINARY_DIR}/deflate1.h5)
4139

40+
set_tests_properties(string_read PROPERTIES
41+
FIXTURES_REQUIRED h5str
42+
DISABLED $<NOT:$<BOOL:${h5py_ok}>>
43+
)
44+
4245
# --- test properties
4346

4447
get_property(test_names DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY TESTS)
@@ -51,33 +54,3 @@ set_property(TEST ${test_names} PROPERTY
5154
ENVIRONMENT_MODIFICATION "PATH=path_list_append:${ZLIB_INCLUDE_DIRS}/../bin;PATH=path_list_append:${ZLIB_INCLUDE_DIR}/../bin"
5255
)
5356
endif()
54-
55-
# --- Python h5py
56-
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12)
57-
set(Python_FIND_VIRTUALENV STANDARD)
58-
# use order in PATH to pick Python interpreter
59-
# this avoids unexpected old system Python getting used IF conda environment has been activated
60-
find_package(Python COMPONENTS Interpreter)
61-
endif()
62-
if(NOT DEFINED h5py_ok)
63-
execute_process(COMMAND ${Python_EXECUTABLE} -c "import h5py"
64-
RESULT_VARIABLE h5py_code
65-
)
66-
if(h5py_code EQUAL 0)
67-
set(h5py_ok true CACHE BOOL "h5py OK")
68-
else()
69-
set(h5py_ok false CACHE BOOL "h5py not OK")
70-
endif()
71-
endif()
72-
73-
set_property(TEST string_read PROPERTY FIXTURES_REQUIRED h5str)
74-
set_property(TEST string_read PROPERTY REQUIRED_FILES ${string_file})
75-
76-
# --- String
77-
add_test(NAME PythonString
78-
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_string.py ${string_file}
79-
)
80-
81-
set_property(TEST PythonString PROPERTY FIXTURES_SETUP h5str)
82-
83-
set_property(TEST string_read PythonString PROPERTY DISABLED $<NOT:$<BOOL:${h5py_ok}>>)

0 commit comments

Comments
 (0)