base framework for unit testing in Fortran

This commit is contained in:
Martin Diehl 2023-02-24 22:27:56 +01:00
parent 0a8b1040e1
commit 2147ac3a12
5 changed files with 20 additions and 5 deletions

View File

@ -22,6 +22,8 @@ if(DAMASK_SOLVER STREQUAL "GRID")
project(damask-grid HOMEPAGE_URL https://damask.mpie.de LANGUAGES Fortran C)
elseif(DAMASK_SOLVER STREQUAL "MESH")
project(damask-mesh HOMEPAGE_URL https://damask.mpie.de LANGUAGES Fortran C)
elseif(DAMASK_SOLVER STREQUAL "TEST")
project(damask-test HOMEPAGE_URL https://damask.mpie.de LANGUAGES Fortran C)
else()
message(FATAL_ERROR "Invalid solver: DAMASK_SOLVER=${DAMASK_SOLVER}")
endif()

View File

@ -17,6 +17,11 @@ mesh:
@cmake -B build/mesh -DDAMASK_SOLVER=mesh -DCMAKE_INSTALL_PREFIX=${PWD} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DBUILDCMD_POST=${BUILDCMD_POST} -DBUILDCMD_PRE=${BUILDCMD_PRE} -DOPTIMIZATION=${OPTIMIZATION} -DOPENMP=${OPENMP}
@cmake --build build/mesh --parallel --target install
.PHONY: test
test:
@cmake -B build/test -DDAMASK_SOLVER=test -DCMAKE_INSTALL_PREFIX=${PWD} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DBUILDCMD_POST=${BUILDCMD_POST} -DBUILDCMD_PRE=${BUILDCMD_PRE} -DOPTIMIZATION=${OPTIMIZATION} -DOPENMP=${OPENMP}
@cmake --build build/test --parallel --target install
.PHONY: clean
clean:
@rm -rf build

View File

@ -13,6 +13,9 @@ if(PROJECT_NAME STREQUAL "damask-grid")
elseif(PROJECT_NAME STREQUAL "damask-mesh")
set(executable-name "DAMASK_mesh")
file(GLOB solver-sources CONFIGURE_DEPENDS mesh/*.f90)
elseif(PROJECT_NAME STREQUAL "damask-test")
set(executable-name "DAMASK_test")
file(GLOB solver-sources CONFIGURE_DEPENDS test/*.f90)
endif()
foreach(solver-source ${solver-sources})

View File

@ -41,8 +41,6 @@ module prec
real(pReal), dimension(0), parameter :: emptyRealArray = [real(pReal)::]
character(len=pStringLen), dimension(0), parameter :: emptyStringArray = [character(len=pStringLen)::]
private :: &
selfTest
contains
@ -62,7 +60,7 @@ subroutine prec_init()
print'( a,e10.3)', ' epsilon value: ',PREAL_EPSILON
print'( a,i3)', ' decimal precision: ',precision(0.0_pReal)
call selfTest()
call prec_selfTest()
end subroutine prec_init
@ -247,7 +245,7 @@ end function prec_bytesToC_INT64_T
!--------------------------------------------------------------------------------------------------
!> @brief Check correctness of some prec functions.
!--------------------------------------------------------------------------------------------------
subroutine selfTest()
subroutine prec_selfTest()
integer, allocatable, dimension(:) :: realloc_lhs_test
real(pReal), dimension(1) :: f
@ -281,6 +279,6 @@ subroutine selfTest()
i = int(prec_bytesToC_INT64_T(int([+126,+23,+52,+1,0,0,0,0],C_SIGNED_CHAR)),pI64)
if (i(1) /= 20191102_pI64) error stop 'prec_bytesToC_INT64_T'
end subroutine selfTest
end subroutine prec_selfTest
end module prec

7
src/test/DAMASK_test.f90 Normal file
View File

@ -0,0 +1,7 @@
program DAMASK_test
use prec
call prec_selfTest()
end program DAMASK_test