Merge branch 'unit-test-Fortran' into 'development'

Unit test fortran

See merge request damask/DAMASK!744
This commit is contained in:
Franz Roters 2023-03-10 14:20:46 +00:00
commit 8ce51dc4d8
7 changed files with 86 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) project(damask-grid HOMEPAGE_URL https://damask.mpie.de LANGUAGES Fortran C)
elseif(DAMASK_SOLVER STREQUAL "MESH") elseif(DAMASK_SOLVER STREQUAL "MESH")
project(damask-mesh HOMEPAGE_URL https://damask.mpie.de LANGUAGES Fortran C) 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() else()
message(FATAL_ERROR "Invalid solver: DAMASK_SOLVER=${DAMASK_SOLVER}") message(FATAL_ERROR "Invalid solver: DAMASK_SOLVER=${DAMASK_SOLVER}")
endif() 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 -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 @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 .PHONY: clean
clean: clean:
@rm -rf build @rm -rf build

View File

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

View File

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

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

@ -0,0 +1,15 @@
program DAMASK_test
use parallelization
use HDF5_utilities
use test_prec
use test_HDF5_utilities
call prec_test()
call parallelization_init()
call HDF5_utilities_init()
call HDF5_utilities_test()
end program DAMASK_test

View File

@ -0,0 +1,39 @@
module test_HDF5_utilities
use prec
use HDF5
use HDF5_utilities
implicit none(type,external)
private
public :: HDF5_utilities_test
contains
subroutine HDF5_utilities_test()
print*, 'begin test HDF5_utilities'
call test_read_write()
print*, 'end test HDF5_utilities'
end subroutine HDF5_utilities_test
subroutine test_read_write()
integer(HID_T) :: f
real(pReal), dimension(3) :: d_in,d_out
call random_number(d_in)
f = HDF5_openFile('test.hdf5','w')
call HDF5_write(d_in,f,'test')
call HDF5_read(d_out,f,'test')
if (any(d_in /= d_out)) error stop 'test_read_write'
end subroutine test_read_write
end module test_HDF5_utilities

19
src/test/test_prec.f90 Normal file
View File

@ -0,0 +1,19 @@
module test_prec
use prec
implicit none(type,external)
private
public :: prec_test
contains
subroutine prec_test()
print*, 'begin test prec'
call prec_selfTest()
print*, 'end test prec'
end subroutine prec_test
end module test_prec