Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests exposing co_broadcast and co_reduce bugs #72

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,15 @@ echo "Version: 0.1.0" >> $CAFFEINE_P
exit_if_pkg_config_pc_file_missing "caffeine"

RUN_FPM_SH="build/run-fpm.sh"
echo "#!/bin/sh" > $RUN_FPM_SH
echo "#-- DO NOT EDIT -- created by caffeine/install.sh" >> $RUN_FPM_SH
echo "\"${FPM}\" \"\$@\" \\" >> $RUN_FPM_SH
echo "--compiler \"`$PKG_CONFIG caffeine --variable=CAFFEINE_FPM_FC`\" \\" >> $RUN_FPM_SH
echo "--c-compiler \"`$PKG_CONFIG caffeine --variable=CAFFEINE_FPM_CC`\" \\" >> $RUN_FPM_SH
echo "--c-flag \"`$PKG_CONFIG caffeine --variable=CAFFEINE_FPM_CFLAGS`\" \\" >> $RUN_FPM_SH
echo "--link-flag \"`$PKG_CONFIG caffeine --variable=CAFFEINE_FPM_LDFLAGS`\"" >> $RUN_FPM_SH
echo "#!/bin/sh" > $RUN_FPM_SH
echo "#-- DO NOT EDIT -- created by caffeine/install.sh" >> $RUN_FPM_SH
echo "fpm_sub_cmd=\$1; shift" >> $RUN_FPM_SH
echo "\"${FPM}\" \"\$fpm_sub_cmd\" \\" >> $RUN_FPM_SH
echo "--compiler \"`$PKG_CONFIG caffeine --variable=CAFFEINE_FPM_FC`\" \\" >> $RUN_FPM_SH
echo "--c-compiler \"`$PKG_CONFIG caffeine --variable=CAFFEINE_FPM_CC`\" \\" >> $RUN_FPM_SH
echo "--c-flag \"`$PKG_CONFIG caffeine --variable=CAFFEINE_FPM_CFLAGS`\" \\" >> $RUN_FPM_SH
echo "--link-flag \"`$PKG_CONFIG caffeine --variable=CAFFEINE_FPM_LDFLAGS`\" \\" >> $RUN_FPM_SH
echo "\"\$@\"" >> $RUN_FPM_SH
chmod u+x $RUN_FPM_SH

./$RUN_FPM_SH build
Expand Down
2 changes: 1 addition & 1 deletion manifest/fpm.toml.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ maintainer = "rouson@lbl.gov"
copyright = "2021-2022 UC Regents"

[dev-dependencies]
veggies = {git = "https://gitlab.com/everythingfunctional/veggies", tag = "v1.0.5"}
veggies = {git = "https://gitlab.com/everythingfunctional/veggies", tag = "v1.1.0"}
iso_varying_string = {git = "https://gitlab.com/everythingfunctional/iso_varying_string.git", tag = "v3.0.4"}

[build]
33 changes: 33 additions & 0 deletions test/caf_co_broadcast_test.f90
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ module caf_co_broadcast_test

interface operator(==)
module procedure equals
module procedure equals_with_allocatable
end interface

type with_allocatable
integer, allocatable :: i
end type

contains

Expand All @@ -26,6 +31,7 @@ function test_prif_co_broadcast() result(tests)
"The prif_co_broadcast subroutine", &
[ it("broadcasts a default integer scalar with no optional arguments present", broadcast_default_integer_scalar) &
,it("broadcasts a derived type scalar with no allocatable components", broadcast_derived_type) &
, it("broadcasts a derived type with an allocatable component", broadcast_with_allocatable) &
])
end function

Expand All @@ -38,6 +44,19 @@ logical pure function equals(lhs, rhs)
,lhs%issues == rhs%issues &
])
end function

logical pure function equals_with_allocatable(lhs, rhs)
type(with_allocatable), intent(in) :: lhs, rhs
if (allocated(lhs%i)) then
if (allocated(rhs%i)) then
equals_with_allocatable = lhs%i == rhs%i
else
equals_with_allocatable = .false.
end if
else
equals_with_allocatable = .not.allocated(rhs%i)
end if
end function

function broadcast_default_integer_scalar() result(result_)
type(result_t) result_
Expand All @@ -64,5 +83,19 @@ function broadcast_derived_type() result(result_)
end associate

end function

function broadcast_with_allocatable() result(result_)
type(result_t) :: result_

integer, parameter :: expected_val = 42
integer :: me
type(with_allocatable) :: obj, expected

expected%i = expected_val
call prif_this_image(image_index=me)
if (me == 1) obj%i = expected_val
call prif_co_broadcast(obj, source_image=1)
result_ = assert_that(expected == obj, "co_broadcast with allocatable component")
end function

end module caf_co_broadcast_test
23 changes: 23 additions & 0 deletions test/caf_co_reduce_test.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ module caf_co_reduce_test
private
public :: test_prif_co_reduce

type my_int
integer :: val
end type
contains

function test_prif_co_reduce() result(tests)
Expand All @@ -24,6 +27,7 @@ function test_prif_co_reduce() result(tests)
,it("sums default complex scalars with a stat-variable present", sum_default_complex_scalars) &
,it("sums complex(c_double) scalars with a stat-variable present", sum_complex_c_double_scalars) &
,it("sums default integer elements of a 2D array across images", sum_integer_array_elements) &
,it("can reduce derived types", sum_derived_types) &
])
end function

Expand Down Expand Up @@ -247,4 +251,23 @@ pure function multiply(lhs, rhs) result(product_)
end function

end function

pure function add_my_ints(lhs, rhs) result(sum_)
type(my_int), intent(in) :: lhs, rhs
type(my_int) :: sum_

sum_%val = lhs%val + rhs%val
end function

function sum_derived_types() result(result_)
type(result_t) :: result_

type(my_int) :: var
integer :: num_imgs, i

call prif_this_image(image_index=var%val)
call prif_num_images(image_count=num_imgs)
call prif_co_reduce(var, c_funloc(add_my_ints))
result_ = assert_equals(sum([(i, i = 1, num_imgs)]), var%val)
end function
end module caf_co_reduce_test
Loading