Skip to content

Commit b3e90e5

Browse files
committed
test(co_max): report diagnostics for test failures
1 parent 277c746 commit b3e90e5

File tree

1 file changed

+75
-35
lines changed

1 file changed

+75
-35
lines changed

test/prif_co_max_test_m.F90

Lines changed: 75 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module prif_co_max_test_m
88
use iso_c_binding, only: c_size_t, c_ptr, c_intmax_t, c_null_funptr
99
use prif, only : prif_co_max, prif_num_images, prif_this_image_no_coarray, prif_num_images
1010
use prif_test_m, only : prif_test_t, test_description_substring
11-
use julienne_m, only : test_result_t, test_description_t
11+
use julienne_m, only : test_result_t, test_description_t, test_diagnosis_t, string_t, operator(.csv.)
1212
#if ! HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
13-
use julienne_m, only : test_function_i
13+
use julienne_m, only : diagnosis_function_i
1414
#endif
1515
implicit none
1616

@@ -47,7 +47,7 @@ function results() result(test_results)
4747
,test_description_t("default-character variables with no optional arguments", reverse_alphabetize_default_characters) &
4848
]
4949
#else
50-
procedure(test_function_i), pointer :: &
50+
procedure(diagnosis_function_i), pointer :: &
5151
max_default_integer_scalars_ptr => max_default_integer_scalars &
5252
,max_c_int64_scalars_ptr => max_c_int64_scalars &
5353
,max_default_integer_1D_array_ptr => max_default_integer_1D_array &
@@ -76,20 +76,24 @@ function results() result(test_results)
7676
test_results = test_descriptions%run()
7777
end function
7878

79-
function max_default_integer_scalars() result(test_passes)
80-
logical test_passes
79+
function max_default_integer_scalars() result(test_diagnosis)
80+
type(test_diagnosis_t) test_diagnosis
8181
integer i, status_, n
8282

8383
status_ = -1
8484
call prif_this_image_no_coarray(this_image=i)
8585
call prif_co_max(i, stat=status_)
8686
call prif_num_images(num_images=n)
87-
test_passes = i == n .and. status_ == 0
87+
test_diagnosis = test_diagnosis_t( &
88+
test_passed = (i==n) .and. (status_==0) &
89+
,diagnostics_string = "expected i = " // string_t(i) // ", status_ = 0" &
90+
// "; actual i = " // string_t(n) // ", status_ = " // string_t(status_) &
91+
)
8892
end function
8993

90-
function max_c_int64_scalars() result(test_passes)
94+
function max_c_int64_scalars() result(test_diagnosis)
9195
use iso_c_binding, only : c_int64_t
92-
logical test_passes
96+
type(test_diagnosis_t) test_diagnosis
9397
integer(c_int64_t) i
9498
integer me, status_, n
9599

@@ -98,11 +102,15 @@ function max_c_int64_scalars() result(test_passes)
98102
i = me
99103
call prif_co_max(i, stat=status_)
100104
call prif_num_images(num_images=n)
101-
test_passes = i == int(n)
105+
test_diagnosis = test_diagnosis_t( &
106+
test_passed = (i == int(n,c_int64_t)) .and. (status_ == 0) &
107+
,diagnostics_string = "expected i = " // string_t(int(i)) // ", status = 0" &
108+
// "; actual i = " // string_t(n) // ", status = " // string_t(status_) &
109+
)
102110
end function
103111

104-
function max_default_integer_1D_array() result(test_passes)
105-
logical test_passes
112+
function max_default_integer_1D_array() result(test_diagnosis)
113+
type(test_diagnosis_t) test_diagnosis
106114
integer i, me, n
107115
integer, allocatable :: array(:)
108116

@@ -112,73 +120,102 @@ function max_default_integer_1D_array() result(test_passes)
112120
array = sequence_
113121
call prif_co_max(array)
114122
associate(max_sequence => n*[(i, i=1, n)])
115-
test_passes = all(max_sequence == array)
123+
test_diagnosis = test_diagnosis_t( &
124+
test_passed = all(max_sequence == array), &
125+
diagnostics_string = "expected element values " // .csv. string_t(max_sequence) &
126+
// "; actual element values " // .csv. string_t(array) &
127+
)
116128
end associate
117129
end associate
118130
end function
119131

120-
function max_default_integer_7D_array() result(test_passes)
121-
logical test_passes
122-
integer array(2,1,1, 1,1,1, 2), status_, me, n
132+
function max_default_integer_7D_array() result(test_diagnosis)
133+
type(test_diagnosis_t) test_diagnosis
134+
integer, target :: array(2,1,1, 1,1,1, 2)
135+
integer, pointer :: array_1D_ptr(:)
136+
integer status_, me, n
123137

124138
status_ = -1
125139
call prif_this_image_no_coarray(this_image=me)
126140
array = 3 - me
127141
call prif_co_max(array, stat=status_)
128142
call prif_num_images(num_images=n)
129-
test_passes = all(array == 3 - 1) .and. status_ == 0
143+
array_1D_ptr(1:size(array)) => array
144+
test_diagnosis = test_diagnosis_t( &
145+
test_passed = all(array == 3 - 1) .and. status_ == 0 &
146+
,diagnostics_string = "expected element values " // string_t(3 - 1) &
147+
// "; actual element values " // .csv. string_t(array_1D_ptr) &
148+
)
130149
end function
131150

132-
function max_default_real_scalars() result(test_passes)
133-
logical test_passes
151+
function max_default_real_scalars() result(test_diagnosis)
152+
type(test_diagnosis_t) test_diagnosis
134153
real scalar
135-
real, parameter :: pi = 3.141592654
154+
real, parameter :: pi = 3.141592654, tolerance = 1E-7, expected = -pi
136155
integer status_, me, n
137156

138157
status_ = -1
139158
call prif_this_image_no_coarray(this_image=me)
140159
scalar = -pi*me
141160
call prif_co_max(scalar, stat=status_)
142161
call prif_num_images(num_images=n)
143-
test_passes = -dble(pi*1) == dble(scalar) .and. status_ == 0
162+
test_diagnosis = test_diagnosis_t( &
163+
test_passed = (abs(scalar-expected) < tolerance) .and. (status_ == 0) &
164+
,diagnostics_string = "expected scalar " // string_t(expected) // ", status = 0" &
165+
// "; actual scalar " // string_t(scalar) // ", status = " // string_t(status_) &
166+
)
144167
end function
145168

146-
function max_double_precision_2D_array() result(test_passes)
147-
logical test_passes
148-
double precision, allocatable :: array(:,:)
149-
double precision, parameter :: tent(*,*) = dble(reshape(-[0,1,2,3,2,1], [3,2]))
169+
function max_double_precision_2D_array() result(test_diagnosis)
170+
type(test_diagnosis_t) test_diagnosis
171+
double precision, dimension(:,:), allocatable, target :: array, expected
172+
double precision, dimension(:), pointer :: array_1D_ptr, expected_1D_ptr
173+
double precision, parameter :: tent(*,*) = dble(reshape(-[0,1,2,3,2,1], [3,2])), tolerance = 1D-14
150174
integer :: me, n
151175

152176
call prif_this_image_no_coarray(this_image=me)
153177
array = tent*dble(me)
154178
call prif_co_max(array)
155179
call prif_num_images(num_images=n)
156-
test_passes = all(array==tent*dble(1))
180+
expected = tent*dble(1)
181+
array_1D_ptr(1:size(array)) => array
182+
expected_1D_ptr(1:size(expected)) => expected
183+
test_diagnosis = test_diagnosis_t( &
184+
test_passed = all(abs(array-expected) < tolerance) &
185+
,diagnostics_string = "expected element values " // .csv. string_t(expected_1D_ptr) &
186+
// "; actual element values " // .csv. string_t(array_1D_ptr) &
187+
)
157188
end function
158189

159-
function max_elements_in_2D_string_arrays() result(test_passes)
160-
logical test_passes
190+
function max_elements_in_2D_string_arrays() result(test_diagnosis)
191+
type(test_diagnosis_t) test_diagnosis
161192
character(len=*), parameter :: script(*,*,*) = reshape( &
162193
[ "To be ","or not " & ! odd images get
163194
, "to ","be. " & ! this slice: script(:,:,1)
164195
!--------------------------
165196
, "that ","is " & ! even images get
166197
, "the ","question"], & ! this slice: script(:,:,2)
167198
[2,2,2])
168-
character(len=len(script)), dimension(size(script,1),size(script,2)) :: slice
199+
character(len=len(script)), dimension(size(script,1),size(script,2)), target :: slice, expected
200+
character(len=len(script)), dimension(:), pointer :: slice_1D_ptr, expected_1D_ptr
169201
integer me, ni
170202

171203
call prif_this_image_no_coarray(this_image=me)
172204
call prif_num_images(ni)
173205
slice = script(:,:,mod(me-1,size(script,3))+1)
174206
call prif_co_max(slice)
175-
associate(expected => maxval(script(:,:,1:min(ni,size(script,3))), dim=3))
176-
test_passes = all(expected == slice)
177-
end associate
207+
expected = maxval(script(:,:,1:min(ni,size(script,3))), dim=3)
208+
expected_1D_ptr(1:size(expected)) => expected
209+
slice_1D_ptr(1:size(slice)) => slice
210+
test_diagnosis = test_diagnosis_t( &
211+
test_passed = all(expected == slice) &
212+
,diagnostics_string = "expected slice " // .csv. string_t(expected_1D_ptr) &
213+
// "; actual slice " // .csv. string_t(slice_1D_ptr) &
214+
)
178215
end function
179216

180-
function reverse_alphabetize_default_characters() result(test_passes)
181-
logical test_passes
217+
function reverse_alphabetize_default_characters() result(test_diagnosis)
218+
type(test_diagnosis_t) test_diagnosis
182219
integer, parameter :: length = len("to party!")
183220
character(len=length), parameter :: words(*) = [character(len=length):: "Loddy","doddy","we","like","to party!"]
184221
character(len=:), allocatable :: my_word, expected_word
@@ -192,7 +229,10 @@ function reverse_alphabetize_default_characters() result(test_passes)
192229

193230
call prif_num_images(num_images=n)
194231
expected_word = maxval(words(1:min(n, size(words)))) ! this line exposes a flang bug
195-
test_passes = expected_word == my_word
232+
test_diagnosis = test_diagnosis_t( &
233+
test_passed = expected_word == my_word &
234+
,diagnostics_string = "expected " // expected_word // "; actual " // my_word &
235+
)
196236
end function
197237

198-
end module prif_co_max_test_m
238+
end module prif_co_max_test_m

0 commit comments

Comments
 (0)