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

Implement basic checkers for integers and reals #20

Merged
merged 1 commit into from
Nov 8, 2024
Merged
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
19 changes: 13 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ jobs:
if: ${{ contains(matrix.compiler, 'intel') }}
uses: rscohn2/setup-oneapi@v0
with:
# Restricting to 2024 as fpm fails to build MPI-programs with oneAPI 2025.0
components: |
ifx
icx
impi
ifx@2024.2.1
icx@2024.2.1
impi@2021.13.1

- name: Setup Intel environment
if: ${{ contains(matrix.compiler, 'intel') }}
Expand All @@ -98,7 +99,12 @@ jobs:
run: |
echo "FC=${{ env.FC }}" >> ${GITHUB_ENV}
echo "FPM_FC=${{ env.FC }}" >> ${GITHUB_ENV}
echo "FFLAGS=-ffree-line-length-none" >> ${GITHUB_ENV}
if [[ ${{ matrix.interface }} == serial ]] && [[ ${{ matrix.os }} == ubuntu-* ]]; then
echo "FFLAGS=-ffree-line-length-none -Og -fsanitize=address" >> ${GITHUB_ENV}
echo "LDFLAGS=-fsanitize=address" >> ${GITHUB_ENV}
else
echo "FFLAGS=-ffree-line-length-none" >> ${GITHUB_ENV}
fi
echo "FPM_FFLAGS=-ffree-line-length-none" >> ${GITHUB_ENV}

- name: Setup MPICH on Ubuntu
Expand Down Expand Up @@ -162,8 +168,9 @@ jobs:
- name: Build Fortuno
run: |
cmake ${CMAKE_OPTIONS} -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -B ${BUILD_DIR} -G Ninja
cmake --build ${BUILD_DIR}
cmake --install ${BUILD_DIR}
cmake --build ${BUILD_DIR} --verbose
cmake --install ${BUILD_DIR} --verbose
ctest --test-dir ${BUILD_DIR} --verbose
rm -rf ${BUILD_DIR}

- name: Test CMake export
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ add_subdirectory(src)
if (FORTUNO_WITH_EXAMPLES)
add_subdirectory(example)
endif ()
if (FORTUNO_WITH_TESTS)
enable_testing()
add_subdirectory(test)
endif ()

#[=================================================================================================[
# Install or Export #
Expand Down
4 changes: 2 additions & 2 deletions example/coarray-fpp/test_simple_fpp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

module test_simple_fpp
use mylib, only : broadcast
use fortuno_coarray, only : as_char, test => coa_pure_case_item, context => coa_context,&
use fortuno_coarray, only : str, test => coa_pure_case_item, context => coa_context,&
& is_equal, test_list
implicit none

Expand Down Expand Up @@ -46,7 +46,7 @@ subroutine test_broadcast(ctx)
! Make every third rank fail for demonstration purposes
if (mod(this_image() - 1, 3) == 2) then
buffer = sourceval + 1
msg = "Failing on image " // as_char(this_image()) // " on purpose"
msg = "Failing on image " // str(this_image()) // " on purpose"
end if

! THEN each rank must contain source rank's value
Expand Down
4 changes: 2 additions & 2 deletions example/coarray-fypp/test_simple_fypp.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

module test_simple_fypp
use mylib, only : broadcast
use fortuno_coarray, only : as_char, context => coa_context, is_equal,&
use fortuno_coarray, only : str, context => coa_context, is_equal,&
& suite => coa_pure_suite_item, test_list
$:FORTUNO_COARRAY_IMPORTS()
implicit none
Expand Down Expand Up @@ -57,7 +57,7 @@ contains
! Make every third image fail for demonstration purposes
if (mod(this_image() - 1, 3) == 2) then
buffer = sourceval + 1
msg = "Failing on image " // as_char(this_image()) // " on purpose"
msg = "Failing on image " // str(this_image()) // " on purpose"
end if

! THEN each image must contain source image's value
Expand Down
6 changes: 3 additions & 3 deletions example/coarray/test_simple.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

module test_simple
use mylib, only : broadcast
use fortuno_coarray, only : as_char, test => coa_pure_case_item, context => coa_context,&
& is_equal, test_list
use fortuno_coarray, only : test => coa_pure_case_item, context => coa_context, is_equal, str,&
& test_list
implicit none

contains
Expand Down Expand Up @@ -44,7 +44,7 @@ subroutine test_broadcast(ctx)
! Make every third rank fail for demonstration purposes
if (mod(this_image() - 1, 3) == 2) then
buffer = sourceval + 1
msg = "Failing on image " // as_char(this_image()) // " on purpose"
msg = "Failing on image " // str(this_image()) // " on purpose"
end if

! THEN each rank must contain source rank's value
Expand Down
4 changes: 2 additions & 2 deletions example/mpi-fpp/test_simple_fpp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

module test_simple_fpp
use mylib, only : broadcast
use fortuno_mpi, only : as_char, global_comm, is_equal, test => mpi_case_item,&
use fortuno_mpi, only : str, global_comm, is_equal, test => mpi_case_item,&
& test_list, this_rank
implicit none

Expand Down Expand Up @@ -44,7 +44,7 @@ subroutine test_broadcast()
! Make every third rank fail for demonstration purposes
if (mod(this_rank(), 3) == 2) then
buffer = sourceval + 1
msg = "Failing on rank " // as_char(this_rank()) // " on purpose"
msg = "Failing on rank " // str(this_rank()) // " on purpose"
end if

! THEN each rank must contain source rank's value
Expand Down
4 changes: 2 additions & 2 deletions example/mpi-fypp/test_simple_fypp.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

module test_simple_fypp
use mylib, only : broadcast
use fortuno_mpi, only : as_char, global_comm, is_equal, suite => mpi_suite_item, test_list,&
use fortuno_mpi, only : str, global_comm, is_equal, suite => mpi_suite_item, test_list,&
& this_rank
$:FORTUNO_MPI_IMPORTS()
implicit none
Expand Down Expand Up @@ -55,7 +55,7 @@ contains
! Make every third rank fail for demonstration purposes
if (mod(this_rank(), 3) == 2) then
buffer = sourceval + 1
msg = "Failing on rank " // as_char(this_rank()) // " on purpose"
msg = "Failing on rank " // str(this_rank()) // " on purpose"
end if

! THEN each rank must contain source rank's value
Expand Down
4 changes: 2 additions & 2 deletions example/mpi/test_simple.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module test_simple
use mylib, only : broadcast
use fortuno_mpi, only : as_char, global_comm, is_equal, test => mpi_case_item,&
use fortuno_mpi, only : str, global_comm, is_equal, test => mpi_case_item,&
& check => mpi_check, test_list, this_rank
implicit none

Expand Down Expand Up @@ -42,7 +42,7 @@ subroutine test_broadcast()
! Make every third rank fail for demonstration purposes
if (mod(this_rank(), 3) == 2) then
buffer = sourceval + 1
msg = "Failing on rank " // as_char(this_rank()) // " on purpose"
msg = "Failing on rank " // str(this_rank()) // " on purpose"
end if

! THEN each rank must contain source rank's value
Expand Down
12 changes: 6 additions & 6 deletions example/serial-fpp/test_fixtured_fpp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
!> Demo for realizing fixtured tests by overriding the run() method of the test_case object.
module test_fixtured_fpp
use mylib, only : factorial
use fortuno_serial, only : char_rep_int, is_equal, named_state, named_item,&
use fortuno_serial, only : is_equal, state_dict, dict_item,&
& suite => serial_suite_item, store_state => serial_store_state, serial_case_base, test_item,&
& test_list
implicit none
Expand Down Expand Up @@ -91,15 +91,15 @@ subroutine random_test_case_run(this)
! Omit array expression to avoid memory leak
! {-
! call store_state(&
! named_state([&
! named_item("n", char_rep_int(nn))&
! state_dict([&
! dict_item("n", nn)&
! &])&
! )
! -}{+
block
type(named_item) :: nameditems(1)
nameditems(1) = named_item("n", char_rep_int(nn))
call store_state(named_state(nameditems))
type(dict_item) :: dictitems(1)
dictitems(1) = dict_item("n", nn)
call store_state(state_dict(dictitems))
end block
call this%proc(nn)
! +}
Expand Down
12 changes: 6 additions & 6 deletions example/serial-fpp/test_fixtured_suite_fpp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
!> Demo for realizing fixtured suites providing common data for all tests within the suite.
module test_fixtured_suite_fpp
use mylib, only : factorial
use fortuno_serial, only : char_rep_int, is_equal, named_state, named_item, serial_case_base,&
use fortuno_serial, only : is_equal, state_dict, dict_item, serial_case_base,&
& scope_pointers => serial_scope_pointers, store_state => serial_store_state,&
& serial_suite_base, test_item, test_list, test_ptr_item
implicit none
Expand Down Expand Up @@ -95,15 +95,15 @@ subroutine random_test_suite_set_up(this)
! Omit array expression to avoid memory leak
! {-
! call store_state(&
! named_state([&
! named_item("n", char_rep_int(this%nn))&
! state_dict([&
! dict_item("n", this%nn)&
! &])&
! )
! -}{+
block
type(named_item) :: nameditems(1)
nameditems(1) = named_item("n", char_rep_int(this%nn))
call store_state(named_state(nameditems))
type(dict_item) :: dictitems(1)
dictitems(1) = dict_item("n", this%nn)
call store_state(state_dict(dictitems))
end block
! +}

Expand Down
4 changes: 2 additions & 2 deletions example/serial-fpp/test_parametrized_fpp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
!> Demonstrates a possible realization of parametrized tests.
module test_parametrized_fpp
use mylib, only : factorial
use fortuno_serial, only : as_char, is_equal, serial_case_base, suite => serial_suite_item,&
use fortuno_serial, only : str, is_equal, serial_case_base, suite => serial_suite_item,&
& test_item, test_list
implicit none

Expand Down Expand Up @@ -59,7 +59,7 @@ function parametrized_test(prefix, argres) result(testitem)

character(:), allocatable :: name

name = prefix // "_" // as_char(argres%arg)
name = prefix // "_" // str(argres%arg)
testitem = test_item(parametrized_test_case(name=name, argres=argres))

end function parametrized_test
Expand Down
1 change: 1 addition & 0 deletions example/serial-fypp/mylib.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module mylib_fypp

contains


!> Calculates the factorial of a number
function factorial(nn) result(fact)

Expand Down
12 changes: 6 additions & 6 deletions example/serial-fypp/test_fixtured_fypp.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
!> Demonstrates the relization of fixtured tests using Fypp macros.
module test_fixtured_fypp
use mylib_fypp, only : factorial
use fortuno_serial, only : char_rep_int, is_equal, named_state, named_item,&
use fortuno_serial, only : is_equal, state_dict, dict_item,&
& suite => serial_suite_item, store_state => serial_store_state,&
& serial_case_base, test_item, test_list
$:FORTUNO_SERIAL_IMPORTS()
Expand Down Expand Up @@ -91,15 +91,15 @@ contains
! Omit array expression to avoid memory leak
! {-
! call store_state(&
! named_state([&
! named_item("n", char_rep_int(nn))&
! state_dict([&
! dict_item("n", nn)&
! &])&
! )
! -}{+
block
type(named_item) :: nameditems(1)
nameditems(1) = named_item("n", char_rep_int(nn))
call store_state(named_state(nameditems))
type(dict_item) :: dictitems(1)
dictitems(1) = dict_item("n", nn)
call store_state(state_dict(dictitems))
end block
call this%proc(nn)
! +}
Expand Down
4 changes: 2 additions & 2 deletions example/serial-fypp/test_parametrized_fypp.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
!> Demonstrates a possible realization of parametrized tests using Fypp macros.
module test_parametrized_fypp
use mylib_fypp, only : factorial
use fortuno_serial, only : as_char, is_equal, serial_case_base, suite => serial_suite_item,&
use fortuno_serial, only : str, is_equal, serial_case_base, suite => serial_suite_item,&
& test_item, test_list
$:FORTUNO_SERIAL_IMPORTS()
implicit none
Expand Down Expand Up @@ -69,7 +69,7 @@ contains

character(:), allocatable :: name

name = prefix // "_" // as_char(argres%arg)
name = prefix // "_" // str(argres%arg)
testitem = test_item(parametrized_test_case(name=name, argres=argres))

end function parametrized_test
Expand Down
18 changes: 17 additions & 1 deletion example/serial/mylib.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

!> Demo module/library to be tested
module mylib
use iso_fortran_env, only : r32 => real32
implicit none

private
public :: factorial
public :: r32
public :: factorial, cotan

contains

Expand All @@ -31,4 +33,18 @@ function factorial(nn) result(fact)

end function factorial


!> Calculates the cotangent of an angle
elemental function cotan(xx)

!> Argument to calculate the cotangent of
real(r32), intent(in) :: xx

!> Cotangent of the argument
real(r32) :: cotan

cotan = 1.0_r32 / tan(xx)

end function cotan

end module mylib
14 changes: 7 additions & 7 deletions example/serial/test_fixtured.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
!> Demo for realizing fixtured tests by overriding the run() method of the test_case object.
module test_fixtured
use mylib, only : factorial
use fortuno_serial, only : char_rep_int, check => serial_check, is_equal, named_state,&
& named_item, suite => serial_suite_item, store_state => serial_store_state,&
use fortuno_serial, only : check => serial_check, is_equal, state_dict,&
& dict_item, suite => serial_suite_item, store_state => serial_store_state,&
& serial_case_base, test_item, test_list
implicit none

Expand Down Expand Up @@ -89,15 +89,15 @@ subroutine random_test_case_run(this)
! Omit array expression to avoid memory leak
! {-
! call store_state(&
! named_state([&
! named_item("n", char_rep_int(nn))&
! state_dict([&
! dict_item("n", nn)&
! &])&
! )
! -}{+
block
type(named_item) :: nameditems(1)
nameditems(1) = named_item("n", char_rep_int(nn))
call store_state(named_state(nameditems))
type(dict_item) :: dictitems(1)
dictitems(1) = dict_item("n", nn)
call store_state(state_dict(dictitems))
end block
call this%proc(nn)
! +}
Expand Down
14 changes: 7 additions & 7 deletions example/serial/test_fixtured_suite.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
!> Demo for realizing fixtured suites providing common data for all tests within the suite.
module test_fixtured_suite
use mylib, only : factorial
use fortuno_serial, only : char_rep_int, check => serial_check, is_equal, named_state,&
& named_item, serial_case_base, scope_pointers => serial_scope_pointers,&
use fortuno_serial, only : check => serial_check, is_equal, state_dict,&
& dict_item, serial_case_base, scope_pointers => serial_scope_pointers,&
& store_state => serial_store_state, serial_suite_base, test_item, test_list, test_ptr_item
implicit none

Expand Down Expand Up @@ -93,15 +93,15 @@ subroutine random_test_suite_set_up(this)
! Omit array expression to avoid memory leak
! {-
! call store_state(&
! named_state([&
! named_item("n", char_rep_int(this%nn))&
! state_dict([&
! dict_item("n", this%nn)&
! &])&
! )
! -}{+
block
type(named_item) :: nameditems(1)
nameditems(1) = named_item("n", char_rep_int(this%nn))
call store_state(named_state(nameditems))
type(dict_item) :: dictitems(1)
dictitems(1) = dict_item("n", this%nn)
call store_state(state_dict(dictitems))
end block
! +}

Expand Down
Loading
Loading