Skip to content

Commit dec2d23

Browse files
committed
fix(co_reduce_test): improve logic
1 parent 3f26d78 commit dec2d23

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

test/prif_co_reduce_test_m.F90

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
! Terms of use are as specified in LICENSE.txt
33

44
#include "language-support.F90"
5+
#include "assert_macros.h"
56

67
module prif_co_reduce_test_m
78
!! Unit test fort the prif_init program inititation subroutine
8-
use prif, only : prif_co_reduce, prif_num_images, prif_this_image_no_coarray, prif_error_stop
9+
use assert_m
10+
use prif, only : prif_co_reduce, prif_num_images, prif_this_image_no_coarray, prif_error_stop, prif_co_max
911
use prif_test_m, only : prif_test_t, test_description_substring
1012
use iso_c_binding, only : c_bool, c_funloc, c_char, c_double, c_int64_t
1113
use julienne_m, only : test_result_t, test_description_t
@@ -36,15 +38,15 @@ function results() result(test_results)
3638

3739
#if HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
3840
test_descriptions = [ &
39-
test_description_t("alphabetical reduction of strings with result_image present", alphabetically_first_string) &
40-
,test_description_t("sums default integer scalars with no optional arguments", sum_default_integer_scalars) &
41-
,test_description_t("sums integer(c_int64_t) scalars with no optional arguments", sum_c_int64_t_scalars) &
42-
,test_description_t("multiplies default real scalars with all optional arguments", multiply_default_real_scalars) &
43-
,test_description_t("multiplies real(c_double) scalars with all optional arguments", multiply_c_double_scalars) &
44-
,test_description_t("performs a collective .and. operation across logical scalars", reports_on_consensus) &
45-
,test_description_t("sums default complex scalars with a stat-variable present", sum_default_complex_scalars) &
46-
,test_description_t("sums complex(c_double) scalars with a stat-variable present", sum_complex_c_double_scalars) &
47-
,test_description_t("sums default integer elements of a 2D array across images", sum_integer_array_elements) &
41+
test_description_t("sums default integer scalars with no optional arguments", sum_default_integer_scalars) &
42+
,test_description_t("sums integer(c_int64_t) scalars with no optional arguments", sum_c_int64_t_scalars) &
43+
,test_description_t("multiplies default real scalars with all optional arguments", multiply_default_real_scalars) &
44+
,test_description_t("multiplies real(c_double) scalars with all optional arguments", multiply_c_double_scalars) &
45+
,test_description_t("performs a collective .and. operation across logical scalars", reports_on_consensus) &
46+
,test_description_t("sums default complex scalars with a stat-variable present", sum_default_complex_scalars) &
47+
,test_description_t("sums complex(c_double) scalars with a stat-variable present", sum_complex_c_double_scalars) &
48+
,test_description_t("sums default integer elements of a 2D array across images", sum_integer_array_elements) &
49+
,test_description_t("alphabetical reduction of strings with result_image present", alphabetically_first_string) &
4850
]
4951
#else
5052
procedure(test_function_i), pointer :: &
@@ -59,15 +61,15 @@ function results() result(test_results)
5961
,sum_integer_array_elements_ptr => sum_integer_array_elements
6062

6163
test_descriptions = [ &
62-
test_description_t("alphabetical reduction of strings with result_image present", alphabetically_first_string_ptr) &
63-
,test_description_t("sums default integer scalars with no optional arguments", sum_default_integer_scalars_ptr) &
64+
test_description_t("sums default integer scalars with no optional arguments", sum_default_integer_scalars_ptr) &
6465
,test_description_t("sums integer(c_int64_t) scalars with no optional arguments", sum_c_int64_t_scalars_ptr) &
6566
,test_description_t("multiplies default real scalars with all optional arguments", multiply_default_real_scalars_ptr) &
6667
,test_description_t("multiplies real(c_double) scalars with all optional arguments", multiply_c_double_scalars_ptr) &
6768
,test_description_t("performs a collective .and. operation across logical scalars", reports_on_consensus_ptr) &
6869
,test_description_t("sums default complex scalars with a stat-variable present", sum_default_complex_scalars_ptr) &
6970
,test_description_t("sums complex(c_double) scalars with a stat-variable present", sum_complex_c_double_scalars_ptr) &
7071
,test_description_t("sums default integer elements of a 2D array across images", sum_integer_array_elements_ptr) &
72+
,test_description_t("alphabetical reduction of strings with result_image present", alphabetically_first_string_ptr) &
7173
]
7274
#endif
7375

@@ -81,30 +83,25 @@ function results() result(test_results)
8183
function alphabetically_first_string() result(test_passes)
8284
logical test_passes
8385
character(len=*, kind=c_char), parameter :: names(*) = ["larry","harry","carey","betty","tommy","billy"]
84-
character(len=:, kind=c_char), allocatable :: my_name(:)
85-
character(len=:), allocatable :: expected_name
86-
integer :: me, num_imgs
86+
character(len=len(names), kind=c_char) my_name, expected_name
87+
integer :: me, n
8788

8889
call prif_this_image_no_coarray(this_image=me)
8990
associate(periodic_index => 1 + mod(me-1,size(names)))
90-
my_name = [names(periodic_index)]
91+
my_name = names(periodic_index)
9192
call prif_co_reduce(my_name, c_funloc(alphabetize))
9293
end associate
9394

94-
call prif_num_images(num_images=num_imgs)
95-
expected_name = minval(names(1:min(num_imgs, size(names)))) ! this exposes a flang bug
96-
test_passes = all(expected_name == my_name)
95+
call prif_num_images(num_images=n)
96+
expected_name = minval(names(1:min(n, size(names)))) ! this exposes a flang bug
97+
test_passes = expected_name == my_name
9798

9899
contains
99100

100-
function alphabetize(lhs, rhs) result(first_alphabetically)
101+
pure function alphabetize(lhs, rhs) result(first_alphabetically)
101102
character(len=*), intent(in) :: lhs, rhs
102-
character(len=:), allocatable :: first_alphabetically
103-
104-
if (len(lhs).ne.len(rhs)) then
105-
call prif_error_stop(quiet=.false._c_bool, &
106-
stop_code_char="co_reduce_s alphabetize: LHS(" // lhs // ")/RHS(" // rhs // ") length don't match")
107-
end if
103+
character(len=len(lhs)) first_alphabetically
104+
call_assert(len(lhs) == len(rhs))
108105
first_alphabetically = min(lhs,rhs)
109106
end function
110107

0 commit comments

Comments
 (0)