Skip to content

Commit 95841d4

Browse files
author
Damian Rouson
authored
Merge pull request #281 from sourceryinstitute/convert-test-hang-to-fail
set ctest to time-out on failing alloc comp test
2 parents 1e73f38 + 037b9dd commit 95841d4

File tree

4 files changed

+127
-90
lines changed

4 files changed

+127
-90
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ endfunction(add_mpi_test)
356356

357357
set(tests_root ${CMAKE_CURRENT_BINARY_DIR}/src/tests)
358358

359+
359360
if(opencoarrays_aware_compiler)
360361
# Unit tests targeting each libcaf_mpi function, argument, and branch of code
361362
add_mpi_test(initialize_mpi 2 ${tests_root}/unit/init_register/initialize_mpi)
@@ -368,7 +369,9 @@ if(opencoarrays_aware_compiler)
368369
add_mpi_test(register_alloc_comp_1 2 ${tests_root}/unit/init_register/register_alloc_comp_1)
369370
add_mpi_test(register_alloc_comp_2 2 ${tests_root}/unit/init_register/register_alloc_comp_2)
370371
add_mpi_test(register_alloc_comp_3 2 ${tests_root}/unit/init_register/register_alloc_comp_3)
371-
add_mpi_test(check_remote_alloced_comp_1 6 ${tests_root}/unit/init_register/check_remote_alloced_comp_1)
372+
add_mpi_test(async_comp_alloc 6 ${tests_root}/unit/init_register/async_comp_alloc)
373+
# Timeout async_comp_alloc test after 3 seconds to progess past the known failure
374+
set_property(TEST async_comp_alloc PROPERTY TIMEOUT_AFTER_MATCH 3 "known failure")
372375
endif()
373376
add_mpi_test(get_array 2 ${tests_root}/unit/send-get/get_array)
374377
add_mpi_test(get_self 2 ${tests_root}/unit/send-get/get_self)

src/tests/unit/init_register/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ add_executable(allocate_as_barrier_proc allocate_as_barrier_proc.f90)
1717
target_link_libraries(allocate_as_barrier_proc OpenCoarrays)
1818

1919
if (gfortran_compiler AND (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 7))
20-
add_executable(check_remote_alloced_comp_1 check_remote_alloced_comp_1.f90)
21-
target_link_libraries(check_remote_alloced_comp_1 OpenCoarrays)
20+
add_executable(async_comp_alloc async_comp_alloc.f90)
21+
target_link_libraries(async_comp_alloc OpenCoarrays)
2222

2323
add_executable(register_alloc_comp_1 register_alloc_comp_1.f90)
2424
target_link_libraries(register_alloc_comp_1 OpenCoarrays)
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
! async_comp_alloc.f90
2+
3+
! Unit test for register procedure and remote allocated test:
4+
! Test that scalar allocatable component in a derived typed coarray is
5+
! registered correctly, its allocation is deferred until the program
6+
! allocates it specifically, and it is deregisterable. The component
7+
! allocation checks are done on remote images.
8+
!
9+
! Copyright (c) 2012-2016, Sourcery, Inc.
10+
! All rights reserved.
11+
!
12+
! Redistribution and use in source and binary forms, with or without
13+
! modification, are permitted provided that the following conditions are met:
14+
! * Redistributions of source code must retain the above copyright
15+
! notice, this list of conditions and the following disclaimer.
16+
! * Redistributions in binary form must reproduce the above copyright
17+
! notice, this list of conditions and the following disclaimer in the
18+
! documentation and/or other materials provided with the distribution.
19+
! * Neither the name of the Sourcery, Inc., nor the
20+
! names of its contributors may be used to endorse or promote products
21+
! derived from this software without specific prior written permission.
22+
!
23+
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24+
! ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25+
! WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26+
! DISCLAIMED. IN NO EVENT SHALL SOURCERY, INC., BE LIABLE FOR ANY
27+
! DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28+
! (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29+
! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30+
! ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31+
! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32+
! SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
34+
program async_comp_alloc
35+
implicit none
36+
37+
type dt
38+
integer, allocatable :: i
39+
end type dt
40+
type(dt), allocatable :: obj[:]
41+
!! Container object for testing component allocation status
42+
43+
logical, parameter :: verbose=.true.
44+
!! Toggle verbose output for debugging purposes
45+
46+
integer :: allocation_status
47+
integer, parameter :: success=0
48+
!! Successful allocation status value
49+
50+
51+
associate(me=>this_image(),np=>num_images())
52+
!! Make me & np locally immutable by associating them with function results
53+
54+
call assert( np > 1, "num_images()>1")
55+
!! Ensure at least two images to simplify the test
56+
57+
allocate(obj[*],stat=allocation_status)
58+
!! Allocate only the container. obj%i must not be allocated hereafter.
59+
60+
call assert(allocation_status == success, "allocated(obj)")
61+
call assert(.not. allocated(obj%i) , ".not. allocated(obj%i)")
62+
63+
if (me==1) print *,"known failure -- ctest will timeout (see https://github.com/sourceryinstitute/opencoarrays/issues/260)."
64+
65+
block
66+
integer :: allocating_image, test_image
67+
character(len=8) :: image_number
68+
69+
loop_over_all_image_numbers: do allocating_image = 1, np
70+
!! Check that all allocations have been performed up to allocating_image and
71+
!! that no other allocations have been performed
72+
73+
if (verbose) print *, me, "/", np, ": allocating_image=", allocating_image
74+
75+
if (allocating_image /= me) then
76+
sync all
77+
!! Order allocations sequentially by image number: arrival of image 'allocating_image'
78+
!! at the sync all in the alternate branch launches the following test loop.
79+
test_allocation_status: do test_image = 1, np
80+
if (verbose) print *, me, "/", np, ": Checking", test_image, " for allocation status."
81+
write(image_number,*) test_image
82+
if (test_image <= allocating_image) then
83+
call assert(allocated(obj[test_image]%i), " allocated(obj["//image_number//"]%i)" )
84+
!! Enforce that image numbers up to mine have allocated their components
85+
else
86+
call assert(.not. allocated(obj[test_image]%i), ".not. allocated(obj["//image_number//"]%i) on image ")
87+
!! Enforce that image numbers higher than 'image' should not have allocated their components yet
88+
end if
89+
end do test_allocation_status
90+
else
91+
if (verbose) print *, me, "/", np, ": allocating..."
92+
allocate(obj%i, source = me)
93+
!! TODO: should we also ensure that implicit (re)allocation upon assignment works here?
94+
if (verbose) print *, me, "/", np, ": allocated"
95+
! Enforce that object has been allocated and obj%i is this_image():
96+
call assert( allocated(obj) , "allocated(obj)")
97+
call assert( allocated(obj%i), "allocated(obj%i)")
98+
call assert( obj%i == me , "obj%i == this_image()")
99+
sync all
100+
end if
101+
end do loop_over_all_image_numbers
102+
end block
103+
end associate
104+
contains
105+
subroutine assert(assertion,description,stat)
106+
logical, intent(in) :: assertion
107+
character(len=*), intent(in) :: description
108+
integer, intent(out), optional:: stat
109+
integer, parameter :: failure=1
110+
if (assertion) then
111+
if (present(stat)) stat=success
112+
else
113+
if (present(stat)) then
114+
stat=failure
115+
else
116+
error stop "Assertion "// description //" failed."
117+
end if
118+
end if
119+
end subroutine
120+
end program
121+

src/tests/unit/init_register/check_remote_alloced_comp_1.f90

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)