Skip to content

Commit 72f1a9b

Browse files
authored
Merge pull request #247 from bonachea/exit-cases
CI: Add more robust exit testing in GitHub CI
2 parents 427e15d + 78dd313 commit 72f1a9b

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

.github/workflows/build.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,6 @@ jobs:
200200
echo CAF_IMAGES=${CAF_IMAGES}
201201
set -x
202202
./build/run-fpm.sh run --verbose --example hello
203-
./build/run-fpm.sh run --verbose --example stop_with_no_code
204-
( set +e ; ./build/run-fpm.sh run --verbose --example stop_with_integer_code ; test $? = 99 )
205-
( set +e ; ./build/run-fpm.sh run --verbose --example error_stop_with_integer_code ; test $? = 100 )
206203
207204
- name: Run unit tests
208205
run: |
@@ -214,3 +211,20 @@ jobs:
214211
CAF_IMAGES=$(( CAF_IMAGES / 2 )) ; \
215212
done
216213
214+
- name: Run exit tests
215+
run: |
216+
echo CAF_IMAGES=${CAF_IMAGES}
217+
set -x
218+
./build/run-fpm.sh run --verbose --example stop_with_no_code
219+
( set +e ; ./build/run-fpm.sh run --verbose --example stop_with_integer_code ; test $? = 99 )
220+
( set +e ; ./build/run-fpm.sh run --verbose --example error_stop_with_integer_code ; test $? = 100 )
221+
unset GASNET_SPAWN_VERBOSE
222+
for ((i=1; i<=4; i++)); do \
223+
(set +e ; \
224+
./build/run-fpm.sh run --verbose --example exit_case -- $i 2>&1 | tee output ; \
225+
test ${PIPESTATUS[0]} = $((i + 100)) \
226+
&& grep -q "stdout from image $CAF_IMAGES" output \
227+
&& grep -q "stderr from image $CAF_IMAGES" output \
228+
) ; \
229+
done
230+

example/support-test/exit_case.F90

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
program hello_world
2+
use iso_c_binding, only: c_bool
3+
use iso_fortran_env, only: output_unit,error_unit
4+
use prif, only : &
5+
prif_init &
6+
,prif_this_image_no_coarray &
7+
,prif_num_images &
8+
,prif_stop &
9+
,prif_error_stop &
10+
,prif_sync_all
11+
implicit none
12+
13+
integer :: init_exit_code, me, num_imgs, exitcase = 1
14+
logical(kind=c_bool), parameter :: false = .false._c_bool, true = .true._c_bool
15+
character(len=256) :: arg_string
16+
17+
call prif_init(init_exit_code)
18+
if (init_exit_code /= 0) call prif_error_stop(quiet=false, stop_code_char="program startup failed")
19+
20+
call prif_this_image_no_coarray(this_image=me)
21+
call prif_num_images(num_images=num_imgs)
22+
if (command_argument_count() > 0) then
23+
call get_command_argument(1, arg_string)
24+
read(arg_string, *) exitcase
25+
end if
26+
if (me == 1) write(output_unit,*) "testing exit case ", exitcase
27+
28+
call prif_sync_all()
29+
30+
write(output_unit,'(A,I1,A,I1)') "stdout from image ", me, " of ", num_imgs
31+
write(error_unit,'(A,I1,A,I1)') "stderr from image ", me, " of ", num_imgs
32+
33+
call prif_sync_all()
34+
35+
select case (exitcase)
36+
case (1)
37+
call prif_stop(quiet=true, stop_code_int=exitcase+100)
38+
case (2)
39+
call prif_stop(quiet=false, stop_code_int=exitcase+100)
40+
case (3)
41+
if (me == num_imgs) call prif_error_stop(quiet=true, stop_code_int=exitcase+100)
42+
case default
43+
if (me == num_imgs) call prif_error_stop(quiet=false, stop_code_int=exitcase+100)
44+
end select
45+
46+
call prif_sync_all()
47+
48+
end program

0 commit comments

Comments
 (0)