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

Unit test with Julienne #133

Draft
wants to merge 46 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b11575d
fix(sync_all): call prif_sync_all
rouson Sep 6, 2024
66e4b6d
fix(co_reduce): correctly set character ptr length
rouson Sep 6, 2024
8aeb5ea
fix(install.sh): if flang, add assumed-rank flags
rouson Sep 6, 2024
2f8f71e
Apply suggestions from code review
rouson Sep 6, 2024
0426d7a
test(collectives): work around flang bugs
rouson Sep 6, 2024
d2791d2
build(fpm): switch to debug builds
rouson Sep 6, 2024
886baa3
refac(c_f_string): use non-concurrent do
rouson Sep 6, 2024
d261701
test: replace veggies dependency with julienne
rouson Sep 7, 2024
b5326dd
fix(prif_allocate_test): .f90->.F90 to preprocess
rouson Sep 8, 2024
7ab646e
test(prif_init): fix test desc in gfortran code
rouson Sep 8, 2024
c3b2279
test(num_images): add refactored passing test
rouson Sep 8, 2024
5faf190
test(this_image): add refactored passing test
rouson Sep 8, 2024
0779145
test(prif_num_images_test): fix typo
rouson Sep 8, 2024
878f0d0
test(prif_allocate): better test subject text
rouson Sep 8, 2024
0be5de7
WIP: add failing error stop test
rouson Sep 8, 2024
094c780
WIP: add failing prif_stop test
rouson Sep 8, 2024
c9cd812
WIP: disable stop/error-stop tests
rouson Sep 8, 2024
dc922bd
test(co_broadcast): add passing test
rouson Sep 8, 2024
e8f92ff
test(prif_num_images): fix typo
rouson Sep 8, 2024
d961d2e
test(prif_co_broadcast): fix typo in gfortran code
rouson Sep 8, 2024
d95ab4a
test(main): run stop/error-stop tests
rouson Sep 8, 2024
027ca56
feat(prif): leverage selected_logical_kind support
rouson Sep 8, 2024
cdf2590
test(teams): add passing test
rouson Sep 8, 2024
05fdb05
WIP: add prif_image_index test - fails with flang
rouson Sep 8, 2024
1ce9151
chore(prif_image_index): whitespace edits
rouson Sep 8, 2024
c560785
WIP: add prif_co_min test - fails with flang
rouson Sep 8, 2024
a0c9812
WIP: add prif_com_ax test - fails with flang
rouson Sep 8, 2024
c60ab05
Apply suggestions from code review
rouson Sep 8, 2024
b09efc5
build(preprocess): define feature-macro values
rouson Sep 8, 2024
fc31b13
fix(prif): .f90 -> .F90 for preprocessing
rouson Sep 8, 2024
abb3c55
Revert "build(preprocess): define feature-macro values"
rouson Sep 8, 2024
d8dc653
Revert "Apply suggestions from code review "
rouson Sep 8, 2024
4007eb7
chore(include): language feature macros in 1 file
rouson Sep 8, 2024
83d73e4
chore(language-support): rm unused macro
rouson Sep 8, 2024
4239bc2
chore(prif.F90): reversing mistaken rename
rouson Sep 8, 2024
6689839
chore(prif): extension rename (retrying)
rouson Sep 8, 2024
e384e2e
build(include): rm indents to support gfortran
rouson Sep 8, 2024
0350e69
build: fix preprocessor macros
rouson Sep 8, 2024
519c707
test(co_m{in,ax}): fix gfortran workaround blocks
rouson Sep 9, 2024
e555dc8
WIP: add co_reduce test - fails with flang
rouson Sep 9, 2024
36d6213
WIP: add prif_co_sum test - fails with flang
rouson Sep 9, 2024
6466fb5
refac(test/main): reorganize declarations
rouson Sep 9, 2024
a746520
WIP: add prif_rma test -- fails with flang
rouson Sep 9, 2024
80796fd
fix(test/main): call caffeine for error termination
rouson Sep 10, 2024
0c74e9d
fix(error_stop_test): add cmdstatus arg
rouson Sep 11, 2024
1a7f302
WIP: one prif_stop test now passes.
rouson Sep 11, 2024
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
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.

18 changes: 18 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,18 @@
program error_stop_character_code
use iso_c_binding, only: c_bool
use prif, only : prif_init, prif_error_stop, prif_stop
use unit_test_parameters_m, only : unexpected_error_stop, expected_error_stop, unexpected_stop
implicit none

integer :: init_exit_code

call prif_init(init_exit_code)
if (init_exit_code /= 0) call prif_error_stop(.false._c_bool, unexpected_error_stop)
! prif_error_stop_test.f90 should report a test failure if the above line invoikes prif_error_stop

call prif_error_stop(.false._c_bool, " ")
! prif_error_stop_test.f90 should report a passing test if the above prif_error_stop call succeeds

call prif_stop(.false._c_bool, unexpected_stop)
! prif_error_stop_test.f90 should report a passing test if the above prif_stop call executes
end program
18 changes: 18 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,18 @@
program error_stop_with_integer_code
use iso_c_binding, only: c_bool
use prif, only : prif_init, prif_error_stop, prif_stop
use unit_test_parameters_m, only : unexpected_error_stop, expected_error_stop, unexpected_stop
implicit none

integer :: init_exit_code

call prif_init(init_exit_code)
if (init_exit_code /= 0) call prif_error_stop(.false._c_bool, unexpected_error_stop)
! prif_error_stop_test.f90 should report a test failure if the above line invoikes prif_error_stop

call prif_error_stop(.false._c_bool, expected_error_stop)
! prif_error_stop_test.f90 should report a passing test if the above prif_error_stop call succeeds

call prif_stop(.false._c_bool, unexpected_stop)
! prif_error_stop_test.f90 should report a passing test if the above prif_stop call executes
end program
16 changes: 10 additions & 6 deletions example/support-test/stop_with_integer_code.f90
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
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_error_stop, prif_stop
use unit_test_parameters_m, only : unexpected_error_stop, expected_stop, unexpected_stop
implicit none

integer :: init_exit_code

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(.false._c_bool, unexpected_error_stop)
! prif_stop_test.f90 should report a test failure if the above line invoikes prif_error_stop

call prif_stop(.false._c_bool, 1)
call prif_stop(.false._c_bool, expected_stop)
! prif_stop_test.f90 should report a passing test if the above prif_error_stop call succeeds

stop 2 ! caffeine/test/zzz_finalization_test.f90 reports a failure if this line runs
end program
call prif_stop(.false._c_bool, unexpected_stop)
! prif_stop_test.f90 should report a test failure if the above prif_stop call executes
end program
12 changes: 12 additions & 0 deletions src/caffeine/unit_test_parameters_m.f90

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it doesn't belong in the main library. I'd suggest instead making another fpm project in this repo, i.e. fpm new --lib caffeine-test-helpers, putting this in there, and then specifying that just the tests and those examples depend on it. I.e.

[dev-dependencies]
caffeine-test-helpers = { path = "./caffeine-test-helpers" }

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
! Copyright (c), The Regents of the University of California
! Terms of use are as specified in LICENSE.txt

module unit_test_parameters_m
!! Define values for use in the test suite, including example
!! programs that the test suite builds and runs.
implicit none

enum, bind(C)
enumerator :: expected_error_stop=99, unexpected_error_stop, expected_stop, unexpected_stop
end enum
end module
19 changes: 10 additions & 9 deletions test/main.F90
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
program main
!! Test the Caffeine implementation of the Parallel Runtime Interface for Fortran (PRIF)
use julienne_m, only : command_line_t, GitHub_CI
use prif, only : prif_this_image_no_coarray, prif_sync_all
use prif, only : &
prif_this_image_no_coarray &
,prif_sync_all &
,prif_error_stop &
,prif_stop
use prif_allocate_test_m, only : prif_allocate_test_t
use prif_co_broadcast_test_m, only : prif_co_broadcast_test_t
use prif_co_max_test_m, only : prif_co_max_test_t
Expand All @@ -30,9 +34,8 @@ program main

if (me==1) print *, new_line(''), "_________ In total, ",passes," of ",tests, " tests pass. _________"
call prif_sync_all
! PRIF sec 5.2 requires the client to eventually call prif_error_stop or prif_stop
if (passes /= tests) call prif_error_stop(quiet=.false.)
else call prif_stop(quiet=.true.)
if (passes /= tests) call prif_error_stop(quiet=.false.) ! PRIF sec 5.2 requires the client to
!call prif_stop(quiet=.true.) ! eventually call prif_error_stop or prif_stop

contains

Expand Down Expand Up @@ -75,6 +78,7 @@ subroutine run_tests_and_report(passes, tests)
call prif_this_image_test%report(passes, tests)
call prif_co_broadcast_test%report(passes, tests)
call prif_teams_test%report(passes, tests)
call prif_stop_test%report(passes, tests)
#ifdef __flang__
print *
print *,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Expand All @@ -84,20 +88,17 @@ subroutine run_tests_and_report(passes, tests)
print *," - prif_co_min_test"
print *," - prif_co_reduce_test"
print *," - prif_co_sum_test"
print *," - prif_error_stop_test"
print *," - prif_image_index_test"
print *," - prif_stop_test"
print *
print *,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
#else
call prif_image_index_test%report(passes, tests)
call prif_error_stop_test%report(passes, tests)
call prif_co_max_test%report(passes, tests)
call prif_co_min_test%report(passes, tests)
call prif_co_reduce_test%report(passes, tests)
call prif_co_sum_test%report(passes, tests)
call prif_error_stop_test%report(passes, tests)
call prif_image_index_test%report(passes, tests)
call prif_rma_test%report(passes, tests)
call prif_stop_test%report(passes, tests)
#endif

end subroutine run_tests_and_report
Expand Down
35 changes: 21 additions & 14 deletions test/prif_error_stop_test_m.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module prif_error_stop_test_m
!! Unit test for the prif_error_stop subroutine
use prif, only : prif_error_stop
use julienne_m, only : test_t, test_result_t, test_description_t, test_description_substring
use unit_test_parameters_m, only : expected_error_stop
#if ! HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
use julienne_m, only : test_function_i
#endif
Expand Down Expand Up @@ -34,8 +35,8 @@ function results() result(test_results)

#if HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
test_descriptions = [ &
test_description_t("exiting with a non-zero exitstat with an integer stop code", check_integer_stop_code) &
,test_description_t("exiting with a non-zero exitstat when a character stop code", check_character_stop_code) &
test_description_t("exiting with an integer stop code as the exitstat", check_integer_stop_code) &
,test_description_t("exiting with a characrer stop code and non-zero exitstat", check_character_stop_code) &
]
#else
procedure(test_function_i), pointer :: check_integer_stop_code_ptr, check_character_stop_code_ptr
Expand All @@ -45,7 +46,7 @@ function results() result(test_results)

test_descriptions = [ &
test_description_t("exiting with a non-zero exitstat with an integer stop code", check_integer_stop_code_ptr) &
,test_description_t("exiting with a non-zero exitstat when a character stop code", check_character_stop_code_ptr) &
,test_description_t("exiting with a non-zero exitstat with a character stop code", check_character_stop_code_ptr) &
]
#endif

Expand All @@ -58,26 +59,32 @@ function results() result(test_results)

function check_integer_stop_code() result(test_passes)
logical test_passes
integer exit_status
integer exit_status, command_status
character(len=256), command_message

call execute_command_line( &
command = "./build/run-fpm.sh run --example error_stop_integer_code > /dev/null 2>&1", &
wait = .true., &
exitstat = exit_status &
command = "./build/run-fpm.sh run --example error_stop_with_integer_code > /dev/null 2>&1" &
,wait = .true. &
,exitstat = exit_status &
,cmdstat = command_status &
,cmdmsg = command_message &
)
test_passes = exit_status /= 0
test_passes = exit_status == expected_error_stop
end function

function check_character_stop_code() result(test_passes)
logical test_passes
integer exit_status
integer exit_status, command_status
character(len=256), command_message

call execute_command_line( &
command = "./build/run-fpm.sh run --example error_stop_character_code > /dev/null 2>&1", &
wait = .true., &
exitstat = exit_status &
)
test_passes = exit_status /= 0
command = "./build/run-fpm.sh run --example error_stop_with_character_code > /dev/null 2>&1" &
,wait = .true. &
,exitstat = exit_status &
,cmdstat = command_status &
,cmdmsg = command_message &
)
test_passes = exit_status == expected_error_stop
end function

end module prif_error_stop_test_m
6 changes: 3 additions & 3 deletions test/prif_image_index_m.F90
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ function results() result(test_results)
#if HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
test_descriptions = [ &
test_description_t("returning 1 for the simplest case", check_simple_case) &
,test_description_t("returning 1 when given the lower bounds", check_lower_bounds) &
,test_description_t("returning 0 with invalid subscripts", check_invalid_subscripts) &
,test_description_t("returning the expected answer for a more complicated case", check_complicated) &
!,test_description_t("returning 1 when given the lower bounds", check_lower_bounds) &
!,test_description_t("returning 0 with invalid subscripts", check_invalid_subscripts) &
!,test_description_t("returning the expected answer for a more complicated case", check_complicated) &
]

#else
Expand Down
32 changes: 20 additions & 12 deletions test/prif_stop_test_m.F90
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
module prif_stop_test_m
!! Unit test for the prif_stop subroutine
use prif, only : prif_stop
use unit_test_parameters_m, only : expected_stop
use julienne_m, only : test_t, test_result_t, test_description_t, test_description_substring
#if ! HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
use julienne_m, only : test_function_i
Expand Down Expand Up @@ -34,9 +35,9 @@ function results() result(test_results)

#if HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
test_descriptions = [ &
test_description_t("exiting with exitstat=0 when no stop code is present", exit_with_no_stop_code) &
,test_description_t("exiting with the integer stop code exitstat", exit_with_integer_stop_code) &
,test_description_t("exiting a character stop code and non-zero exitstat", exit_with_character_stop_code) &
test_description_t("exiting with the integer stop code as the exitstat", exit_with_integer_stop_code) &
!,test_description_t("exiting with exitstat=0 when no stop code is present", exit_with_no_stop_code) &
!,test_description_t("exiting a character stop code and non-zero exitstat", exit_with_character_stop_code) &
]
#else
procedure(test_function_i), pointer :: &
Expand All @@ -62,29 +63,36 @@ function results() result(test_results)

function exit_with_no_stop_code() result(test_passes)
logical test_passes
integer exit_status
integer exit_status, command_status
character(len=256), command_message

call execute_command_line( &
command = "./build/run-fpm.sh run --example stop_with_no_code > /dev/null 2>&1", &
wait = .true., &
exitstat = exit_status &
,cmdstat = command_status &
,cmdmsg = command_message &
)
test_passes = exit_status == 0
print *, exit_status, "<------ exit_status ---------"
print *, command_status, "<----- command_status ----------"
print *, command_message, "<-------command_message ----"
test_passes = exit_status == 1

end function

function exit_with_integer_stop_code() result(test_passes)
logical test_passes
integer exit_status
integer, parameter :: expected_stop_code=1 ! defined in example/support-test/stop_with_integer_code.f90
integer exit_status, command_status
character(len=256), command_message

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

test_passes = exit_status == expected_stop
end function

function exit_with_character_stop_code() result(test_passes)
Expand Down
Loading