Skip to content

Commit

Permalink
Fixes mock issue for testing with LLVM
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas L. Clune committed Aug 30, 2024
1 parent b89f209 commit 70e4d43
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 43 deletions.
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,7 @@ if (PFUNIT_FOUND)
if (NOT TARGET tests)
add_custom_target(tests COMMAND ${CMAKE_CTEST_COMMAND})
endif ()
# We found issues between LLVMFlang, tests, and MPI. Until
# this can be more fully explored, for now do not run the tests
# with LLVMFlang.
if (NOT CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
add_subdirectory(tests EXCLUDE_FROM_ALL)
endif ()
add_subdirectory(tests EXCLUDE_FROM_ALL)
endif()

add_subdirectory(examples EXCLUDE_FROM_ALL)
Expand Down
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Modified CMake logic to build entirely separate library (pflogger-with-mock) to support testing with mocks. Previous cheat to link pflogger against real MPI for runs but mock MPI for tests did not work with LLVM. Seems to be due to some encryption type protection on module info.
- Update CI to have `gfortran-10` and `gfortran-11` only on `ubuntu-22.04`
- Update CI NVIDIA to NVHPC 24.7

Expand Down
21 changes: 8 additions & 13 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,30 @@ if (MPI_FOUND)
if (SUPPORT_FOR_MPI_ALLOC_MEM_CPTR)
target_compile_definitions(${this} PRIVATE SUPPORT_FOR_MPI_ALLOC_MEM_CPTR)
endif ()
target_link_libraries (${this} PUBLIC MPI::MPI_Fortran)
endif ()


if (MPI_FOUND)
if (PFUNIT_FOUND)
add_library (pflogger-with-mock STATIC ${SRCS})
set_target_properties(pflogger-with-mock PROPERTIES Fortran_MODULE_DIRECTORY ${PFLOGGER_BINARY_DIR}/mock-mpi)
add_library (mock-mpi MockMpi.F90)
set_target_properties(mock-mpi PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mock-mpi)
# target_include_directories (mock-mpi PUBLIC ${MPI_Fortran_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}/mock-mpi)
target_include_directories (mock-mpi PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/mock-mpi)
target_include_directories (mock-mpi PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries (mock-mpi PUBLIC PFUNIT::funit)
if (SUPPORT_FOR_C_LOC_ASSUMED_SIZE)
target_compile_definitions(mock-mpi PRIVATE -DSUPPORT_FOR_C_LOC_ASSUMED_SIZE)
endif ()

# Complex linkage depending on target:
set(isTest $<STREQUAL:$<TARGET_PROPERTY:IS_TEST>,1>)
set(notTest $<NOT:${isTest}>)

target_link_libraries (pflogger PUBLIC
# $<BUILD_INTERFACE:mock-mpi>
$<${notTest}:MPI::MPI_Fortran>
$<${isTest}:mock-mpi>
$<${isTest}:PFUNIT::funit>)
target_link_libraries (mock-mpi PUBLIC PFUNIT::funit)
target_link_libraries (pflogger-with-mock
PUBLIC mock-mpi GFTL_SHARED::gftl-shared GFTL::gftl-v2 YAFYAML::yafyaml)
message("HUH: ${PFLOGGER_BINARY_DIR}/mock-mpi")
target_include_directories(pflogger-with-mock PUBLIC ${PFLOGGER_BINARY_DIR}/mock-mpi ${CMAKE_CURRENT_SOURCE_DIR})

else ()
target_link_libraries (pflogger PRIVATE MPI::MPI_Fortran)
endif ()

endif()


Expand Down
43 changes: 24 additions & 19 deletions src/MockMpi.F90
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,28 @@ module mpi
public :: set_mpi_rank
public :: set_mpi_size
public :: verify


public :: MPI_COMM_WORLD
public :: MPI_ADDRESS_KIND
public :: MPI_STATUS_SIZE
public :: MPI_STATUS_IGNORE
public :: MPI_LOGICAL
public :: MPI_SUCCESS
public :: MPI_INFO_NULL
public :: MPI_ANY_SOURCE
public :: MPI_LOCK_EXCLUSIVE

public :: MPI_WIN_CREATE

integer, parameter :: MPI_COMM_WORLD = 0
integer, parameter :: MPI_ADDRESS_KIND = INT64
integer, parameter :: MPI_STATUS_SIZE = 6
integer, parameter :: MPI_STATUS_IGNORE(MPI_STATUS_SIZE) = reshape([0], shape=[MPI_STATUS_SIZE], pad=[0])
integer, parameter :: MPI_LOGICAL = 9
integer, parameter :: MPI_SUCCESS = 0
integer, parameter :: MPI_INFO_NULL = 0
integer, parameter :: MPI_ANY_SOURCE = -1

integer, parameter :: MPI_LOCK_EXCLUSIVE = 1

public :: MPI_Alloc_mem
public :: MPI_Type_indexed
Expand Down Expand Up @@ -67,6 +72,10 @@ end subroutine MPI_Type_commit
end interface MPI_Type_Commit


interface MPI_Win_create
procedure :: win_create_1
!!$ procedure :: win_create_2
end interface MPI_Win_create

type MockMpi
integer :: rank
Expand Down Expand Up @@ -160,7 +169,19 @@ subroutine verify()
end subroutine verify



subroutine Win_create_1(base, size, disp_unit, info, comm, win, ierror)
#ifdef SUPPORT_FOR_ASSUMED_TYPE
type(*) :: base(*)
#else
logical :: base(*)
#endif
integer(kind=MPI_ADDRESS_KIND) size
integer disp_unit, info, comm, win, ierror

ierror = MPI_SUCCESS
mocker%call_count = mocker%call_count + 1

end subroutine Win_create_1

end module mpi

Expand Down Expand Up @@ -363,22 +384,6 @@ subroutine MPI_Free_mem(base, ierror)

end subroutine MPI_Free_mem

subroutine MPI_Win_create(base, size, disp_unit, info, comm, win, ierror)
use mpi
#ifdef SUPPORT_FOR_ASSUMED_TYPE
type(*) :: base(*)
#else
logical :: base(*)
#endif
integer(kind=MPI_ADDRESS_KIND) size
integer disp_unit, info, comm, win, ierror

ierror = MPI_SUCCESS
mocker%call_count = mocker%call_count + 1

end subroutine MPI_Win_create


! This one is just a stub for now
subroutine MPI_Comm_dup(comm, newcomm, ierror)
use mpi
Expand Down
6 changes: 3 additions & 3 deletions src/MpiLock.F90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module PFL_MpiLock
use PFL_Exception
use PFL_AbstractLock
use iso_fortran_env, only: INT64
use iso_c_binding, only: c_ptr, c_f_pointer
use iso_c_binding, only: c_ptr, c_f_pointer, c_bool
implicit none
private

Expand Down Expand Up @@ -90,7 +90,7 @@ subroutine init(this, rc)
if (this%rank == 0) then

block
logical, pointer :: scratchpad(:)
logical(kind=C_BOOL), pointer :: scratchpad(:)
integer :: sizeof_logical

call MPI_Type_extent(MPI_LOGICAL, sizeof_logical, status)
Expand Down Expand Up @@ -210,7 +210,7 @@ subroutine destroy(this, rc)
class (MpiLock), intent(inout) :: this
integer, optional, intent(out) :: rc

logical, pointer :: scratchpad(:)
logical(kind=C_BOOL), pointer :: scratchpad(:)
integer :: status

! Release resources
Expand Down
7 changes: 5 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ if (MPI_FOUND)
endif ()
endif ()

set (link_libraries pflogger GFTL_SHARED::gftl-shared GFTL::gftl-v2)
set (link_libraries GFTL_SHARED::gftl-shared GFTL::gftl mock-mpi)
if (MPI_FOUND)
list(APPEND link_libraries mock-mpi)
list (APPEND link_libraries pflogger-with-mock)
else ()
list (APPEND link_libraries pflogger)
endif()

message("Link libs: ${link_libraries}")
add_pfunit_ctest (pflogger_tests.x
TEST_SOURCES ${pf_tests}
OTHER_SOURCES ${srcs}
Expand Down

0 comments on commit 70e4d43

Please sign in to comment.