Skip to content

Commit 77182e2

Browse files
author
Damian Rouson
committed
Shorten teams_subset test; refactor to use assert
1 parent 3d06268 commit 77182e2

File tree

3 files changed

+46
-32
lines changed

3 files changed

+46
-32
lines changed

src/tests/unit/teams/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
caf_compile_executable(team_number team-number.f90)
22
caf_compile_executable(teams_subset teams_subset.f90)
3+
target_link_libraries(teams_subset opencoarrays_test_utilities)
34
caf_compile_executable(get_communicator get-communicator.f90)

src/tests/unit/teams/teams_subset.f90

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
program teams_subset
2+
!! author: Nathan Weeks
3+
!!
4+
!! Regression test for prior potential deadlock in change team/end team
25
use iso_fortran_env, only : team_type
6+
use assertions_interface, only : assert
37
implicit none
48

5-
type(team_type) :: team
6-
integer :: initial_team_image, max_image(2), min_image(2), myteam
7-
8-
initial_team_image = this_image()
9-
10-
if (initial_team_image == 1 .or. initial_team_image == num_images()) then
11-
myteam = 1
12-
else
13-
myteam = 2
14-
end if
15-
16-
form team (myteam, team)
17-
18-
if (myteam == 1) then
19-
change team(team)
20-
max_image = [initial_team_image, this_image()]
21-
call co_max(max_image)
22-
min_image = [initial_team_image, this_image()]
23-
call co_min(min_image)
24-
end team
25-
if (any(min_image /= [1, 1]) .or. any(max_image /= [num_images(), 2])) then
26-
write(*,*) "Test failed."
27-
error stop
9+
type(team_type) team
10+
11+
associate( initial_team_image => this_image())
12+
associate( myteam => merge(1,2,any(initial_team_image==[1,num_images()]) )
13+
14+
form team (myteam, team)
15+
16+
if (myteam == 1) then
17+
block
18+
integer max_image(2), min_image(2)
19+
change team(team)
20+
max_image = [initial_team_image, this_image()]
21+
call co_max(max_image)
22+
min_image = [initial_team_image, this_image()]
23+
call co_min(min_image)
24+
end team
25+
call assert( all(min_image==1), "team minimum image number is 1" )
26+
call assert( all(max_image==[num_images(), 2]), "team maximum images numbers is num_images() or 2")
27+
end block
2828
end if
29-
end if
3029

31-
sync all
30+
sync all
3231

33-
if (initial_team_image == 1) write(*,*) "Test passed."
32+
if (initial_team_image == 1) print *,"Test passed."
33+
34+
end associate; end associate
3435

3536
end program

src/tests/utilities/CMakeLists.txt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# Check support Fortran 2018 error termination in a pure procedure
1+
if ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU" )
2+
set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
3+
set(CMAKE_REQUIRED_FLAGS "-fcoarray=single -ffree-form")
4+
endif()
5+
6+
# Check support for Fortran 2018 error termination in a pure procedure
27
check_fortran_source_compiles("
38
program main
49
contains
@@ -14,7 +19,7 @@ if(HAVE_ERROR_STOP_IN_PURE)
1419
add_definitions(-DHAVE_ERROR_STOP_IN_PURE)
1520
endif()
1621

17-
# Check support Fortran 2018 variable stop code
22+
# Check support for Fortran 2018 variable stop code
1823
check_fortran_source_compiles("
1924
program main
2025
integer i
@@ -28,16 +33,23 @@ if(HAVE_VARIABLE_STOP_CODE)
2833
add_definitions(-DHAVE_VARIABLE_STOP_CODE)
2934
endif()
3035

36+
if ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU" )
37+
set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
38+
endif()
39+
3140
#Toggle C preprocessor macro for turning assertions on or off
3241
if(NO_ASSERTIONS)
33-
set_source_files_properties(assertions_interface.f90 PROPERTIES COMPILE_FLAGS "-cpp -DUSE_ASSERTIONS=.false.")
42+
target_compile_definitions( opencoarrays_test_utilities
43+
PUBLIC "-DUSE_ASSERTIONS=.false."
44+
)
3445
else()
35-
set_source_files_properties(assertions_interface.f90 PROPERTIES COMPILE_FLAGS "-cpp -DUSE_ASSERTIONS=.true.")
46+
target_compile_definitions( opencoarrays_test_utilities
47+
PUBLIC "-DUSE_ASSERTIONS=.true."
48+
)
3649
endif()
3750

38-
add_library( OpenCoarraysTestUtilities
51+
add_library( opencoarrays_test_utilities
3952
object_interface.f90
4053
assertions_interface.F90
4154
assertions_implementation.F90
4255
)
43-

0 commit comments

Comments
 (0)