Skip to content

Commit 3c2627e

Browse files
author
Damian Rouson
committed
test(co_all): add unit tests
1 parent 64ad418 commit 3c2627e

File tree

4 files changed

+55
-14
lines changed

4 files changed

+55
-14
lines changed

src/emulated_intrinsics_implementation.F90

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@
1010

1111
contains
1212

13-
module procedure dummy
13+
module procedure co_all
14+
call co_reduce(boolean, both)
15+
contains
16+
pure function both(lhs,rhs) result(lhs_and_rhs)
17+
logical, intent(in) :: lhs,rhs
18+
logical lhs_and_rhs
19+
lhs_and_rhs = lhs .and. rhs
20+
end function
1421
end procedure
1522

1623
#ifdef COMPILER_LACKS_COLLECTIVE_SUBROUTINES

src/emulated_intrinsics_interface.F90

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ module emulated_intrinsics_interface
1212
implicit none
1313

1414
interface
15-
module subroutine dummy
16-
!! ensure a non-empty module
15+
module subroutine co_all(boolean)
16+
implicit none
17+
logical, intent(inout) :: boolean
1718
end subroutine
1819
end interface
1920

tests/collective_subroutines_test.f90

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
module collective_subroutines_test
2-
use Vegetables, only: Result_t, Test_Item_t, describe, it, succeed, assert_equals
2+
use Vegetables, only: Result_t, Test_Item_t, describe, it, succeed, assert_equals, assert_that, assert_not
3+
use emulated_intrinsics_interface, only : co_sum, co_all
34

45
implicit none
56
private
67

7-
public :: test_collective_subroutines
8+
public :: test_co_sum, test_co_all
89
contains
9-
function test_collective_subroutines() result(tests)
10+
function test_co_sum() result(tests)
1011
type(Test_Item_t) :: tests
1112

12-
tests = describe(&
13+
tests = describe( &
1314
"co_sum", &
1415
[it( &
15-
"gives the correct answer with result_image present", &
16+
"gives sums with result_image present", &
1617
check_co_sum_with_result_image), &
1718
it( &
18-
"gives the correct answer without result_image present", &
19+
"gives sums without result_image present", &
1920
check_co_sum_without_result_image)])
2021
end function
2122

23+
function test_co_all() result(tests)
24+
type(Test_Item_t) :: tests
25+
26+
tests = describe( &
27+
"co_all", &
28+
[it( &
29+
"sets all arguments to .true. when previously .true. on all images", &
30+
check_co_all_with_all_true), &
31+
it( &
32+
"sets all arguments to .false. when previously .false. on image 1", &
33+
check_co_all_with_one_false)])
34+
end function
35+
2236
function check_co_sum_with_result_image() result(result_)
23-
use emulated_intrinsics_interface, only : co_sum
2437
type(Result_t) :: result_
2538

2639
integer i, j
@@ -38,7 +51,6 @@ function check_co_sum_with_result_image() result(result_)
3851
end function
3952

4053
function check_co_sum_without_result_image() result(result_)
41-
use emulated_intrinsics_interface, only : co_sum
4254
type(Result_t) :: result_
4355

4456
integer i, j
@@ -51,4 +63,23 @@ function check_co_sum_without_result_image() result(result_)
5163
end associate
5264
end function
5365

66+
function check_co_all_with_all_true() result(result_)
67+
type(Result_t) :: result_
68+
logical all_true
69+
70+
all_true=.true.
71+
72+
call co_all(all_true)
73+
result_ = assert_that(all_true, "co_all argument remains .true. after call with all arguments true")
74+
end function
75+
76+
function check_co_all_with_one_false() result(result_)
77+
type(Result_t) :: result_
78+
logical all_true
79+
80+
all_true = merge(.false., .true., this_image()==1)
81+
call co_all(all_true)
82+
result_ = assert_not(all_true, "co_all argument is .false. after call with one argument false")
83+
end function
84+
5485
end module

tests/main.f90

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ program main
66
contains
77
subroutine run()
88
use collective_subroutines_test, only: &
9-
collective_subroutines_collective_subroutines => test_collective_subroutines
9+
collective_subroutines_co_sum => test_co_sum, &
10+
collective_subroutines_co_all => test_co_all
1011
use vegetables, only: test_item_t, test_that, run_tests
1112

1213
type(test_item_t) :: tests
13-
type(test_item_t) :: individual_tests(1)
14+
type(test_item_t) :: individual_tests(2)
1415

15-
individual_tests(1) = collective_subroutines_collective_subroutines()
16+
individual_tests(1) = collective_subroutines_co_sum()
17+
individual_tests(2) = collective_subroutines_co_all()
1618
tests = test_that(individual_tests)
1719

1820
call run_tests(tests)

0 commit comments

Comments
 (0)