Skip to content

Commit

Permalink
test: simplify and correct Python
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed May 5, 2024
1 parent b5838db commit 65e18ef
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 121 deletions.
12 changes: 4 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.19...3.28)
cmake_minimum_required(VERSION 3.20...3.30)

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

include(CTest)
if(NOT DEFINED ${PROJECT_NAME}_BUILD_TESTING)
set(${PROJECT_NAME}_BUILD_TESTING ${BUILD_TESTING})
endif()

if(benchmark)
set(${PROJECT_NAME}_BUILD_TESTING true)
endif()
include(options.cmake)

if(${PROJECT_NAME}_BUILD_TESTING)
find_package(Python COMPONENTS Interpreter)

enable_language(CXX)
endif()

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

include(options.cmake)
include(cmake/compilers.cmake)

# if HDF5-MPI, ensure all the pieces are working together at configure time.
Expand Down
11 changes: 3 additions & 8 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14...3.24)
cmake_minimum_required(VERSION 3.21...3.30)

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

file(GENERATE OUTPUT .gitignore CONTENT "*")

if(CMAKE_VERSION VERSION_LESS 3.21)
get_property(not_top DIRECTORY PROPERTY PARENT_DIRECTORY)
if(NOT not_top)
set(PROJECT_IS_TOP_LEVEL true)
endif()
endif()

if(PROJECT_IS_TOP_LEVEL)
find_package(Python COMPONENTS Interpreter)

find_package(h5fortran CONFIG REQUIRED)

add_library(cpu_count OBJECT ${PROJECT_SOURCE_DIR}/../test/cpu_count.cpp)
Expand Down
31 changes: 11 additions & 20 deletions benchmark/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ target_link_libraries(slab_serial_write PRIVATE cli perf test_utils kernel h5for
add_executable(slab_serial_read slab_serial_read.f90)
target_link_libraries(slab_serial_read PRIVATE cli perf h5fortran::h5fortran)

if(CMAKE_VERSION VERSION_LESS 3.20)
get_filename_component(HDF5_LIBRARY_DIR ${HDF5_C_LIBRARY} DIRECTORY)
get_filename_component(HDF5_DIR ${HDF5_LIBRARY_DIR} DIRECTORY)
else()
cmake_path(GET HDF5_C_LIBRARY PARENT_PATH HDF5_LIBRARY_DIR)
cmake_path(GET HDF5_LIBRARY_DIR PARENT_PATH HDF5_DIR)
endif()
cmake_path(GET HDF5_C_LIBRARY PARENT_PATH HDF5_LIBRARY_DIR)
cmake_path(GET HDF5_LIBRARY_DIR PARENT_PATH HDF5_DIR)

find_program(H5DIFF
NAMES h5diff
HINTS ${HDF5_ROOT} ${HDF5_DIR}
Expand Down Expand Up @@ -138,19 +134,14 @@ foreach(comp_lvl 0 1)
set_property(TEST mpi-cleanup-comp${comp_lvl} PROPERTY TIMEOUT ${read_timeout})
endforeach()

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12)
set(Python_FIND_REGISTRY LAST)
find_package(Python COMPONENTS Interpreter)

if(NOT DEFINED PyOK)
execute_process(COMMAND ${Python_EXECUTABLE} -c "import h5py,numpy,pandas,matplotlib"
RESULT_VARIABLE ret
)
if(ret EQUAL 0)
set(PyOK true CACHE BOOL "Python ready")
else()
set(PyOK false CACHE BOOL "python not ready")
endif()
if(Python_Interpreter_FOUND AND NOT DEFINED PyOK)
execute_process(COMMAND ${Python_EXECUTABLE} -c "import h5py,numpy,pandas,matplotlib"
RESULT_VARIABLE ret
)
if(ret EQUAL 0)
set(PyOK true CACHE BOOL "Python ready")
else()
set(PyOK false CACHE BOOL "python not ready")
endif()
endif()

Expand Down
4 changes: 0 additions & 4 deletions cmake/ExtProj.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ include_guard()

include(ExternalProject)

if(CMAKE_VERSION VERSION_LESS 3.19)
message(FATAL_ERROR "CMake >= 3.19 required to use JSON")
endif()

file(READ ${CMAKE_CURRENT_LIST_DIR}/libraries.json json)


Expand Down
24 changes: 5 additions & 19 deletions cmake/hdf5_compression.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,8 @@ end program

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

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)
# need this if() for parser
include(CheckFortranSourceRuns)
check_fortran_source_runs(${src} hdf5_parallel_compression_run)
endif()
include(CheckSourceRuns)
check_source_runs(Fortran ${src} hdf5_parallel_compression_run)

if(hdf5_parallel_compression_run)
message(CHECK_PASS "${CMAKE_MATCH_1}")
Expand All @@ -108,13 +105,8 @@ if(DEFINED CACHE{hdf5_parallel_compression})
return()
endif()

if(CMAKE_VERSION VERSION_LESS 3.20)
get_filename_component(HDF5_LIBRARY_DIR ${HDF5_C_LIBRARY} DIRECTORY)
get_filename_component(HDF5_DIR ${HDF5_LIBRARY_DIR} DIRECTORY)
else()
cmake_path(GET HDF5_C_LIBRARY PARENT_PATH HDF5_LIBRARY_DIR)
cmake_path(GET HDF5_LIBRARY_DIR PARENT_PATH HDF5_DIR)
endif()
cmake_path(GET HDF5_C_LIBRARY PARENT_PATH HDF5_LIBRARY_DIR)
cmake_path(GET HDF5_LIBRARY_DIR PARENT_PATH HDF5_DIR)

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

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

if(${CMAKE_MATCH_1})

if(CMAKE_VERSION VERSION_LESS 3.14)
check_compression()
else()
set(hdf5_parallel_compression .true. CACHE STRING "HDF5-MPI configured for parallel compression (assumed due to CMake < 3.14)")
endif()

check_compression()
else()
message(CHECK_FAIL "NO")
set(hdf5_parallel_compression .false. CACHE STRING "HDF5-MPI does not have parallel compression")
Expand Down
6 changes: 6 additions & 0 deletions options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ message(STATUS "${PROJECT_NAME} ${PROJECT_VERSION} CMake ${CMAKE_VERSION}")
option(find_hdf5 "search for HDF5 and Zlib" true)

option(benchmark "Run benchmarks")

option(${PROJECT_NAME}_BUILD_TESTING "Build tests" ${PROJECT_IS_TOP_LEVEL})
if(benchmark)
set(${PROJECT_NAME}_BUILD_TESTING true)
endif()

option(coverage "Code coverage tests")
option(tidy "Run clang-tidy on the code")

Expand Down
18 changes: 7 additions & 11 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ target_compile_definitions(cpu_count PRIVATE $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_WA
target_include_directories(cpu_count PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

# --- Python h5py
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12)

set(Python_FIND_REGISTRY LAST)
find_package(Python COMPONENTS Interpreter)
if(NOT DEFINED h5py_ok)
if(Python_Interpreter_FOUND AND NOT DEFINED h5py_ok)
execute_process(COMMAND ${Python_EXECUTABLE} -c "import h5py"
RESULT_VARIABLE h5py_code
ERROR_VARIABLE err
Expand All @@ -22,20 +18,20 @@ if(NOT DEFINED h5py_ok)
set(h5py_ok true CACHE BOOL "h5py OK")
else()
set(h5py_ok false CACHE BOOL "h5py not OK")
message(VERBOSE "${err}")
message(VERBOSE "${Python_EXECUTABLE}: ${err}")
endif()
endif()

endif()

set(string_file ${CMAKE_CURRENT_BINARY_DIR}/test_string_py.h5)

add_test(NAME PythonString
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_string.py ${string_file}
COMMAND Python::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/test_string.py ${string_file}
)

set_property(TEST PythonString PROPERTY FIXTURES_SETUP h5str)
set_property(TEST PythonString PROPERTY DISABLED $<NOT:$<BOOL:${h5py_ok}>>)
set_tests_properties(PythonString PROPERTIES
FIXTURES_SETUP h5str
DISABLED $<NOT:$<BOOL:${h5py_ok}>>
)

# --- test subdirs

Expand Down
38 changes: 23 additions & 15 deletions test/mpi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ set_property(DIRECTORY PROPERTY LABELS mpi)

# --- helper functions

function(mpi_test names use_runner)

foreach(name IN LISTS names)
function(mpi_test name use_runner)

set(tname "${name}_mpi")

Expand All @@ -25,8 +23,6 @@ endif()

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

endforeach()

endfunction(mpi_test)

# --- test files
Expand All @@ -52,33 +48,45 @@ fill groups layout shape
string string_read write
)

mpi_test("${mpi_tests}" false)
foreach(t IN LISTS mpi_tests)
mpi_test(${t} false)
endforeach()

set(runner_tests deflate_write deflate_props deflate_read)

mpi_test("${runner_tests}" true)
foreach(t IN LISTS runner_tests)
mpi_test(${t} true)
endforeach()

# --- test dependencies

set_property(TEST write_mpi PROPERTY FIXTURES_SETUP test_files)

set_property(TEST layout_mpi shape_mpi PROPERTY FIXTURES_REQUIRED test_files)
set_property(TEST layout_mpi shape_mpi PROPERTY REQUIRED_FILES "${CMAKE_CURRENT_BINARY_DIR}/test_write.h5;${CMAKE_CURRENT_BINARY_DIR}/test_layout.h5")
set_tests_properties(layout_mpi shape_mpi PROPERTIES
FIXTURES_REQUIRED test_files
REQUIRED_FILES "${CMAKE_CURRENT_BINARY_DIR}/test_write.h5;${CMAKE_CURRENT_BINARY_DIR}/test_layout.h5"
)

set_property(TEST deflate_write_mpi PROPERTY FIXTURES_SETUP deflate_files_mpi)

set_property(TEST deflate_props_mpi deflate_read_mpi PROPERTY FIXTURES_REQUIRED deflate_files_mpi)
set_property(TEST deflate_props_mpi deflate_read_mpi PROPERTY REQUIRED_FILES ${CMAKE_CURRENT_BINARY_DIR}/deflate1.h5)
set_tests_properties(deflate_props_mpi deflate_read_mpi PROPERTIES
FIXTURES_REQUIRED deflate_files_mpi
REQUIRED_FILES ${CMAKE_CURRENT_BINARY_DIR}/deflate1.h5
)

set_property(TEST string_read_mpi PROPERTY FIXTURES_REQUIRED h5str)
set_property(TEST string_read_mpi PROPERTY DISABLED $<NOT:$<BOOL:${h5py_ok}>>)
set_tests_properties(string_read_mpi PROPERTIES
FIXTURES_REQUIRED h5str
DISABLED $<NOT:$<BOOL:${h5py_ok}>>
)

# --- test properties

get_property(test_names DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY TESTS)

set_property(TEST ${test_names} PROPERTY WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_property(TEST ${test_names} PROPERTY RESOURCE_LOCK cpu_mpi)
set_tests_properties(${test_names} PROPERTIES
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
RESOURCE_LOCK cpu_mpi
)

# --- Windows shared DLLs
if(WIN32 AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.22)
Expand Down
45 changes: 9 additions & 36 deletions test/nompi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
set_property(DIRECTORY PROPERTY LABELS nompi)

function(nompi_test names)

foreach(name IN LISTS names)
function(nompi_test name)

add_executable(test_${name} test_${name}.f90)
target_link_libraries(test_${name} PRIVATE h5fortran::h5fortran)
Expand All @@ -15,8 +13,6 @@ else()
add_test(NAME ${name} COMMAND test_${name})
endif()

endforeach()

endfunction(nompi_test)


Expand All @@ -25,7 +21,9 @@ exist fill groups layout
shape string string_read write
)

nompi_test("${nompi_tests}")
foreach(t IN LISTS nompi_tests)
nompi_test(${t})
endforeach()

# --- test dependencies

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

set_tests_properties(string_read PROPERTIES
FIXTURES_REQUIRED h5str
DISABLED $<NOT:$<BOOL:${h5py_ok}>>
)

# --- test properties

get_property(test_names DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY TESTS)
Expand All @@ -51,33 +54,3 @@ set_property(TEST ${test_names} PROPERTY
ENVIRONMENT_MODIFICATION "PATH=path_list_append:${ZLIB_INCLUDE_DIRS}/../bin;PATH=path_list_append:${ZLIB_INCLUDE_DIR}/../bin"
)
endif()

# --- Python h5py
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12)
set(Python_FIND_VIRTUALENV STANDARD)
# use order in PATH to pick Python interpreter
# this avoids unexpected old system Python getting used IF conda environment has been activated
find_package(Python COMPONENTS Interpreter)
endif()
if(NOT DEFINED h5py_ok)
execute_process(COMMAND ${Python_EXECUTABLE} -c "import h5py"
RESULT_VARIABLE h5py_code
)
if(h5py_code EQUAL 0)
set(h5py_ok true CACHE BOOL "h5py OK")
else()
set(h5py_ok false CACHE BOOL "h5py not OK")
endif()
endif()

set_property(TEST string_read PROPERTY FIXTURES_REQUIRED h5str)
set_property(TEST string_read PROPERTY REQUIRED_FILES ${string_file})

# --- String
add_test(NAME PythonString
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_string.py ${string_file}
)

set_property(TEST PythonString PROPERTY FIXTURES_SETUP h5str)

set_property(TEST string_read PythonString PROPERTY DISABLED $<NOT:$<BOOL:${h5py_ok}>>)

0 comments on commit 65e18ef

Please sign in to comment.