Skip to content

Commit c4791e2

Browse files
authored
Merge pull request #136 from BerkeleyLab/call-prif_sync_all
Replace parallel statements with Caffeine calls
2 parents 9730a4a + e2a2156 commit c4791e2

16 files changed

+184
-72
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ fpm.toml
66

77
# ford-generated documentation
88
doc/html
9+
10+
# executable programs
11+
a.out
12+
*.exe
13+
14+
# compiler-generated intermediate files
15+
*.mod
16+
*.smod
17+
*.o

example/hello.f90

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
program hello_world
22
use iso_c_binding, only: c_bool
3-
use prif, only : prif_init, this_image => prif_this_image_no_coarray, num_images => prif_num_images, prif_stop
3+
use prif, only : &
4+
prif_init &
5+
,prif_this_image_no_coarray &
6+
,prif_num_images &
7+
,prif_stop &
8+
,prif_error_stop
49
implicit none
510

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

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

11-
call this_image(this_image=me)
12-
call num_images(num_images=num_imgs)
17+
call prif_this_image_no_coarray(this_image=me)
18+
call prif_num_images(num_images=num_imgs)
1319
print *, "Hello from image", me, "of", num_imgs
1420

15-
call prif_stop(.false._c_bool, stop_code_int=0) ! normal termination
21+
call prif_stop(quiet=false)
1622

1723
end program

example/support-test/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
Test Support
22
------------
3-
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.
3+
The programs in this directory intentionally terminate to support the `stop` and `error stop`
4+
unit tests, which use Fortran's `execute_command_line` to run the programs in this directory
5+
and to check for the expected non-zero stop codes. Running the tests in this manner enables
6+
the tests to continue executing after the child process launched by `execute_command_line`
7+
terminates.

example/support-test/error_stop_character_code.f90

Lines changed: 0 additions & 14 deletions
This file was deleted.

example/support-test/error_stop_integer_code.f90

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
program error_stop_with_character_code
2+
use iso_c_binding, only: c_bool
3+
use prif, only : &
4+
prif_init &
5+
,prif_stop &
6+
,prif_error_stop
7+
implicit none
8+
9+
integer init_exit_code
10+
logical(kind=c_bool), parameter :: false = .false._c_bool
11+
12+
call prif_init(init_exit_code)
13+
call prif_error_stop(quiet=false, stop_code_char="USER_PROVIDED_STRING") ! a prif_error_stop unit test passes if this line executes error termination
14+
call prif_stop(quiet=false) ! a prif_error_stop unit test fails if this line runs
15+
end program
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
program error_stop_with_integer_code
2+
use iso_c_binding, only: c_bool
3+
use prif, only : &
4+
prif_init &
5+
,prif_stop &
6+
,prif_error_stop
7+
use unit_test_parameters_m, only : expected_error_stop_code
8+
implicit none
9+
10+
integer init_exit_code
11+
logical(kind=c_bool), parameter :: false = .false._c_bool
12+
13+
call prif_init(init_exit_code)
14+
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
15+
call prif_stop(quiet=false) ! a prif_error_stop unit tests fails if this line runs
16+
end program
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
program error_stop_with_no_code
2+
use iso_c_binding, only: c_bool
3+
use prif, only : &
4+
prif_init &
5+
,prif_stop &
6+
,prif_error_stop
7+
implicit none
8+
9+
integer init_exit_code
10+
logical(kind=c_bool), parameter :: false = .false._c_bool
11+
12+
call prif_init(init_exit_code)
13+
call prif_error_stop(quiet=false) ! a prif_error_stop unit test passes if this line correctly executes error termination
14+
call prif_stop(quiet=false) ! a prif_error_stop unit test fails if this line runs
15+
16+
end program
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
program stop_with_character_code
2+
use iso_c_binding, only: c_bool
3+
use prif, only : &
4+
prif_init &
5+
,prif_stop &
6+
,prif_error_stop
7+
implicit none
8+
9+
integer init_exit_code
10+
logical(kind=c_bool), parameter :: false = .false._c_bool
11+
12+
call prif_init(init_exit_code)
13+
call prif_stop(quiet=false, stop_code_char="USER_PROVIDED_STRING") ! a prif_stop unit test passes if this line executes normal termination
14+
call prif_error_stop(quiet=false) ! a prif_stop unit test fails if this line runs
15+
end program
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
program stop_with_no_code
1+
program stop_with_integer_code
22
use iso_c_binding, only: c_bool
3-
use prif, only : prif_init, prif_stop
3+
use prif, only : &
4+
prif_init &
5+
,prif_stop &
6+
,prif_error_stop
7+
use unit_test_parameters_m, only : expected_stop_code
48
implicit none
59

6-
integer :: init_exit_code
10+
integer init_exit_code
11+
logical(kind=c_bool), parameter :: false = .false._c_bool
712

813
call prif_init(init_exit_code)
9-
if (init_exit_code /= 0) error stop "caffeinate returned a non-zero exit_code"
10-
11-
call prif_stop(.false._c_bool, 1)
12-
13-
stop 2 ! caffeine/test/zzz_finalization_test.f90 reports a failure if this line runs
14+
call prif_stop(quiet=false, stop_code_int=expected_stop_code) ! a prif_stop unit test passes if this line executes normal termination
15+
call prif_error_stop(quiet=false) ! a prif_stop unit test fails if this line runs
1416
end program
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
program stop_with_no_code
22
use iso_c_binding, only: c_bool
3-
use prif, only : prif_init, prif_stop
3+
use prif, only : &
4+
prif_init &
5+
,prif_stop &
6+
,prif_error_stop
47
implicit none
58

6-
integer :: init_exit_code
9+
integer init_exit_code
10+
logical(kind=c_bool), parameter :: false = .false._c_bool
711

812
call prif_init(init_exit_code)
9-
if (init_exit_code /= 0) error stop "caffeinate returned a non-zero exit_code"
10-
11-
call prif_stop(.false._c_bool)
12-
13-
stop 1 ! caffeine/test/zzz_finalization_test.f90 reports a failure if this line runs
13+
call prif_stop(false) ! a prif_stop test passes if this line executes normal termination
14+
call prif_error_stop(quiet=false) ! a prif_stop test fails if this line runs
1415
end program

src/caffeine/program_termination_s.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ subroutine prif_stop_integer(stop_code)
2424
!! synchronize, stop the executing image, and provide the stop_code, or 0 if not present, as the process exit status
2525
integer, intent(in), optional :: stop_code
2626

27-
sync all
27+
call prif_sync_all
2828

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

42-
sync all
42+
call prif_sync_all
4343

4444
write(output_unit, *) "caf_stop: stop code '" // stop_code // "'"
4545
flush output_unit
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
! Copyright (c), The Regents of the University
2+
! Terms of use are as specified in LICENSE.txt
3+
module unit_test_parameters_m
4+
!! Define values for consistent use throughout the test suite
5+
implicit none
6+
7+
private
8+
public :: expected_stop_code
9+
public :: expected_error_stop_code
10+
11+
enum, bind(C)
12+
enumerator :: expected_stop_code=99, expected_error_stop_code
13+
! used in stop/error-stop unit tests and example/test-support supporting programs
14+
end enum
15+
16+
end module unit_test_parameters_m

test/caf_error_stop_test.f90

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,75 @@
11
module caf_error_stop_test
2-
use veggies, only: test_item_t, describe, result_t, it, assert_that
2+
use veggies, only: test_item_t, describe, result_t, it, assert_that, assert_equals
3+
use unit_test_parameters_m, only : expected_error_stop_code
34

45
implicit none
56
private
67
public :: test_prif_this_image
78

9+
integer, parameter :: max_message_len = 128
10+
811
contains
912
function test_prif_this_image() result(tests)
1013
type(test_item_t) :: tests
1114

1215
tests = describe( &
1316
"A program that executes the prif_error_stop function", &
14-
[ it("exits with a non-zero exitstat when stop code is an integer", check_integer_stop_code) &
15-
,it("exits with a non-zero exitstat when stop code is an character", check_character_stop_code) &
17+
[ it("exits with a non-zero exitstat when the program omits the stop code", exit_with_no_stop_code) &
18+
,it("prints a character stop code and exits with a non-zero exitstat", exit_with_character_stop_code) &
19+
,it("prints an integer stop code and exits with exitstat equal to the stop code", exit_with_integer_stop_code) &
1620
])
1721
end function
1822

19-
function check_integer_stop_code() result(result_)
23+
function exit_with_no_stop_code() result(result_)
2024
type(result_t) :: result_
2125
integer exit_status
26+
integer command_status
27+
character(len=max_message_len) command_message
2228

2329
call execute_command_line( &
24-
command = "./build/run-fpm.sh run --example error_stop_integer_code > /dev/null 2>&1", &
25-
wait = .true., &
26-
exitstat = exit_status &
30+
command = "./build/run-fpm.sh run --example error_stop_with_no_code > /dev/null 2>&1" &
31+
,wait = .true. &
32+
,exitstat = exit_status &
33+
,cmdstat = command_status &
34+
,cmdmsg = command_message &
2735
)
28-
result_ = assert_that(exit_status /= 0)
36+
result_ = assert_that(exit_status /= 0) .and. assert_equals(0, command_status, command_message)
37+
38+
end function
39+
40+
function exit_with_integer_stop_code() result(result_)
41+
type(result_t) :: result_
42+
integer exit_status
43+
integer command_status
44+
character(len=max_message_len) command_message
45+
46+
call execute_command_line( &
47+
command = "./build/run-fpm.sh run --example error_stop_with_integer_code > /dev/null 2>&1" &
48+
,wait = .true. &
49+
,exitstat = exit_status &
50+
,cmdstat = command_status &
51+
,cmdmsg = command_message &
52+
)
53+
result_ = &
54+
assert_equals(expected_error_stop_code, exit_status, "exit_status") &
55+
.and. assert_equals(0, command_status, command_message)
2956

3057
end function
3158

32-
function check_character_stop_code() result(result_)
59+
function exit_with_character_stop_code() result(result_)
3360
type(result_t) :: result_
3461
integer exit_status
62+
integer command_status
63+
character(len=max_message_len) command_message
3564

3665
call execute_command_line( &
37-
command = "./build/run-fpm.sh run --example error_stop_character_code > /dev/null 2>&1", &
38-
wait = .true., &
39-
exitstat = exit_status &
66+
command = "./build/run-fpm.sh run --example error_stop_with_character_code > /dev/null 2>&1" &
67+
,wait = .true. &
68+
,exitstat = exit_status &
69+
,cmdstat = command_status &
70+
,cmdmsg = command_message &
4071
)
41-
result_ = assert_that(exit_status /= 0)
72+
result_ = assert_that(exit_status /= 0) .and. assert_equals(0, command_status, command_message)
4273

4374
end function
4475

test/caf_stop_test.f90

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module caf_stop_test
22
use veggies, only: test_item_t, describe, result_t, it, assert_that, assert_equals
3+
use unit_test_parameters_m, only : expected_stop_code
34

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

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

3132
end function
3233

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

3838
call execute_command_line( &
3939
command = "./build/run-fpm.sh run --example stop_with_integer_code > /dev/null 2>&1", &
4040
wait = .true., &
4141
exitstat = exit_status &
42-
)
42+
)
4343
result_ = assert_equals(expected_stop_code, exit_status)
4444

4545
end function
4646

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

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

5958
end function
6059

test/main.f90

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
! Generated by cart. DO NOT EDIT
1+
! This file was originally generated by cart, but then manually edited.
2+
! DO NOT REGENERATE THIS FILE!
23
program main
4+
use iso_c_binding, only : c_bool
5+
use prif, only : &
6+
prif_stop &
7+
,prif_error_stop
38
implicit none
49

5-
if (.not.run()) stop 1
10+
logical(kind=c_bool), parameter :: false = .false._c_bool
11+
12+
if (.not.run()) call prif_error_stop(quiet=false, stop_code_char = "Unit tests failed to run")
13+
14+
call prif_stop(quiet=false)
15+
616
contains
717
function run() result(passed)
818
use a00_caffeinate_test, only: &

0 commit comments

Comments
 (0)