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

Replace parallel statements with Caffeine calls #136

Merged
merged 15 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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: 11 additions & 5 deletions example/hello.f90
bonachea marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
program hello_world
use iso_c_binding, only: c_bool
use prif, only : prif_init, this_image => prif_this_image_no_coarray, num_images => prif_num_images, prif_stop
use prif, only : &
prif_init &
,prif_this_image_no_coarray &
,prif_num_images &
,prif_stop &
,prif_error_stop
implicit none

integer :: init_exit_code, me, num_imgs
logical(kind=c_bool), parameter :: false = .false._c_bool

call prif_init(init_exit_code)
if (init_exit_code /= 0) error stop "caffeinate returned a non-zero exit code"
if (init_exit_code /= 0) call prif_error_stop(quiet=false, stop_code_char="program startup failed")

call this_image(this_image=me)
call num_images(num_images=num_imgs)
call prif_this_image_no_coarray(this_image=me)
call prif_num_images(num_images=num_imgs)
print *, "Hello from image", me, "of", num_imgs

call prif_stop(.false._c_bool, stop_code_int=0) ! normal termination
call prif_stop(quiet=false)

end program
2 changes: 1 addition & 1 deletion example/support-test/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Test Support
------------
The programs in this directory intentionally error-terminate to support the `error stop` tests in `test/caf_error_stop.f90`, which use Fortran's `execute_command_line` to run the programms in this directory and check for the expected non-zero stop codes. Running the tests in this manner enables the Vegetable tests to continue executing in the presence of error-terminating tests.
The programs in this directory intentionally terminate to support the `stop` and `error stop` unit tests, which use Fortran's `execute_command_line` to run the programs in this directory and to check for the expected non-zero stop codes. Running the tests in this manner enables the tests to continue executing the child process launced by `execute_command_line` terminates.
rouson marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 0 additions & 14 deletions example/support-test/error_stop_character_code.f90

This file was deleted.

14 changes: 0 additions & 14 deletions example/support-test/error_stop_integer_code.f90

This file was deleted.

15 changes: 15 additions & 0 deletions example/support-test/error_stop_with_character_code.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
program error_stop_with_character_code
use iso_c_binding, only: c_bool
use prif, only : &
prif_init &
,prif_stop &
,prif_error_stop
implicit none

integer init_exit_code
logical(kind=c_bool), parameter :: false = .false._c_bool

call prif_init(init_exit_code)
call prif_error_stop(quiet=false, stop_code_char="") ! a prif_error_stop unit test passes if this line executes error termination
rouson marked this conversation as resolved.
Show resolved Hide resolved
call prif_stop(quiet=false) ! a prif_error_stop unit test fails if this line runs
end program
16 changes: 16 additions & 0 deletions example/support-test/error_stop_with_integer_code.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
program error_stop_with_integer_code
use iso_c_binding, only: c_bool
use prif, only : &
prif_init &
,prif_stop &
,prif_error_stop
use unit_test_parameters_m, only : expected_error_stop_code
implicit none

integer init_exit_code
logical(kind=c_bool), parameter :: false = .false._c_bool

call prif_init(init_exit_code)
call prif_error_stop(quiet=false, stop_code_int=expected_error_stop_code) ! a prif_error_stop unit test passes if this line executes error termination
call prif_stop(quiet=false) ! a prif_error_stop unit tests fails if this line runs
end program
16 changes: 16 additions & 0 deletions example/support-test/error_stop_with_no_code.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
program error_stop_with_no_code
use iso_c_binding, only: c_bool
use prif, only : &
prif_init &
,prif_stop &
,prif_error_stop
implicit none

integer init_exit_code
logical(kind=c_bool), parameter :: false = .false._c_bool

call prif_init(init_exit_code)
call prif_error_stop(quiet=false) ! a prif_error_stop unit test passes if this line correctly executes error termination
call prif_stop(quiet=false) ! a prif_error_stop unit test fails if this line runs

end program
15 changes: 15 additions & 0 deletions example/support-test/stop_with_character_code.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
program stop_with_character_code
use iso_c_binding, only: c_bool
use prif, only : &
prif_init &
,prif_stop &
,prif_error_stop
implicit none

integer init_exit_code
logical(kind=c_bool), parameter :: false = .false._c_bool

call prif_init(init_exit_code)
call prif_stop(quiet=false, stop_code_char="") ! a prif_stop unit test passes if this line executes normal termination
rouson marked this conversation as resolved.
Show resolved Hide resolved
call prif_error_stop(quiet=false) ! a prif_stop unit test fails if this line runs
end program
18 changes: 10 additions & 8 deletions example/support-test/stop_with_integer_code.f90
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
program stop_with_no_code
program stop_with_integer_code
use iso_c_binding, only: c_bool
use prif, only : prif_init, prif_stop
use prif, only : &
prif_init &
,prif_stop &
,prif_error_stop
use unit_test_parameters_m, only : expected_stop_code
implicit none

integer :: init_exit_code
integer init_exit_code
logical(kind=c_bool), parameter :: false = .false._c_bool

call prif_init(init_exit_code)
if (init_exit_code /= 0) error stop "caffeinate returned a non-zero exit_code"

call prif_stop(.false._c_bool, 1)

stop 2 ! caffeine/test/zzz_finalization_test.f90 reports a failure if this line runs
call prif_stop(quiet=false, stop_code_int=expected_stop_code) ! a prif_stop unit test passes if this line executes normal termination
call prif_error_stop(quiet=false) ! a prif_stop unit test fails if this line runs
end program
15 changes: 8 additions & 7 deletions example/support-test/stop_with_no_code.f90
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
program stop_with_no_code
use iso_c_binding, only: c_bool
use prif, only : prif_init, prif_stop
use prif, only : &
prif_init &
,prif_stop &
,prif_error_stop
implicit none

integer :: init_exit_code
integer init_exit_code
logical(kind=c_bool), parameter :: false = .false._c_bool

call prif_init(init_exit_code)
if (init_exit_code /= 0) error stop "caffeinate returned a non-zero exit_code"

call prif_stop(.false._c_bool)

stop 1 ! caffeine/test/zzz_finalization_test.f90 reports a failure if this line runs
call prif_stop(false) ! a prif_stop test passes if this line executes normal termination
call prif_error_stop(quiet=false) ! a prif_stop test fails if this line runs
end program
4 changes: 2 additions & 2 deletions src/caffeine/program_termination_s.f90
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ subroutine prif_stop_integer(stop_code)
!! synchronize, stop the executing image, and provide the stop_code, or 0 if not present, as the process exit status
integer, intent(in), optional :: stop_code

sync all
call prif_sync_all

!write(output_unit, *) "caf_stop: stop code '", stop_code, "'"
write(output_unit, *) stop_code
Expand All @@ -39,7 +39,7 @@ subroutine prif_stop_character(stop_code)
!! synchronize, stop the executing image, and provide the stop_code as the process exit status
character(len=*), intent(in) :: stop_code

sync all
call prif_sync_all

write(output_unit, *) "caf_stop: stop code '" // stop_code // "'"
flush output_unit
Expand Down
16 changes: 16 additions & 0 deletions src/caffeine/unit_test_parameters_m.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
! Copyright (c), The Regents of the University
! Terms of use are as specified in LICENSE.txt
module unit_test_parameters_m
!! Define values for consistent use throughout the test suite
implicit none

private
public :: expected_stop_code
public :: expected_error_stop_code

enum, bind(C)
enumerator :: expected_stop_code=99, expected_error_stop_code
! used in stop/error-stop unit tests and example/test-support supporting programs
end enum

end module unit_test_parameters_m
6 changes: 6 additions & 0 deletions test/.gitignore
rouson marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a.out
*.mod
*.smod
*.exe
*.o
build
27 changes: 21 additions & 6 deletions test/caf_error_stop_test.f90
rouson marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module caf_error_stop_test
use veggies, only: test_item_t, describe, result_t, it, assert_that
use unit_test_parameters_m, only : expected_error_stop_code

implicit none
private
Expand All @@ -11,30 +12,44 @@ function test_prif_this_image() result(tests)

tests = describe( &
"A program that executes the prif_error_stop function", &
[ it("exits with a non-zero exitstat when stop code is an integer", check_integer_stop_code) &
,it("exits with a non-zero exitstat when stop code is an character", check_character_stop_code) &
[ it("exits with a non-zero exitstat when the program omits the stop code", exit_with_no_stop_code) &
,it("prints a character stop code and exits with a non-zero exitstat", exit_with_character_stop_code) &
,it("prints an integer stop code and exits with exitstat equal to the stop code", exit_with_integer_stop_code) &
])
end function

function check_integer_stop_code() result(result_)
function exit_with_no_stop_code() result(result_)
type(result_t) :: result_
integer exit_status

call execute_command_line( &
command = "./build/run-fpm.sh run --example error_stop_integer_code > /dev/null 2>&1", &
command = "./build/run-fpm.sh run --example error_stop_with_no_code > /dev/null 2>&1", &
wait = .true., &
exitstat = exit_status &
)
result_ = assert_that(exit_status /= 0)

end function

function check_character_stop_code() result(result_)
function exit_with_integer_stop_code() result(result_)
type(result_t) :: result_
integer exit_status

call execute_command_line( &
command = "./build/run-fpm.sh run --example error_stop_character_code > /dev/null 2>&1", &
command = "./build/run-fpm.sh run --example error_with_stop_integer_code > /dev/null 2>&1", &
rouson marked this conversation as resolved.
Show resolved Hide resolved
wait = .true., &
exitstat = exit_status &
)
result_ = assert_that(exit_status /= expected_error_stop_code)

end function

function exit_with_character_stop_code() result(result_)
type(result_t) :: result_
integer exit_status

call execute_command_line( &
command = "./build/run-fpm.sh run --example error_with_stop_character_code > /dev/null 2>&1", &
wait = .true., &
exitstat = exit_status &
)
Expand Down
11 changes: 5 additions & 6 deletions test/caf_stop_test.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module caf_stop_test
use veggies, only: test_item_t, describe, result_t, it, assert_that, assert_equals
use unit_test_parameters_m, only : expected_stop_code

implicit none
private
Expand All @@ -13,7 +14,7 @@ function test_prif_this_image() result(tests)
"A program that executes the prif_stop function", &
[ it("exits with a zero exitstat when the program omits the stop code", exit_with_no_stop_code) &
,it("prints an integer stop code and exits with exitstat equal to the stop code", exit_with_integer_stop_code) &
,it("prints a character stop code and exits with a non-zero existat", exit_with_character_stop_code) &
,it("prints a character stop code and exits with a non-zero exitstat", exit_with_character_stop_code) &
])
end function

Expand All @@ -25,36 +26,34 @@ function exit_with_no_stop_code() result(result_)
command = "./build/run-fpm.sh run --example stop_with_no_code > /dev/null 2>&1", &
wait = .true., &
exitstat = exit_status &
)
)
result_ = assert_equals(0, exit_status)

end function

function exit_with_integer_stop_code() result(result_)
type(result_t) :: result_
integer exit_status
integer, parameter :: expected_stop_code=1 ! defined in example/support-test/stop_with_integer_code.f90

call execute_command_line( &
command = "./build/run-fpm.sh run --example stop_with_integer_code > /dev/null 2>&1", &
wait = .true., &
exitstat = exit_status &
)
)
result_ = assert_equals(expected_stop_code, exit_status)

end function

function exit_with_character_stop_code() result(result_)
type(result_t) :: result_
integer exit_status
integer, parameter :: expected_exit_code=1 ! defined in src/caffeine/program_termination.f90

call execute_command_line( &
command = "./build/run-fpm.sh run --example stop_with_character_code > /dev/null 2>&1", &
wait = .true., &
exitstat = exit_status &
)
result_ = assert_equals(expected_exit_code, exit_status)
result_ = assert_equals(0, exit_status) ! the standard recommends zero exit status for character stop codes

end function

Expand Down
Loading