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

Add unit testing #752

Closed
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
754531f
get 'uppercase' from mpp_mod in io/module_wrt_grid_comp.F90
AlexanderRichert-NOAA Dec 6, 2023
8d3927c
Add GCC-based CI build
AlexanderRichert-NOAA Dec 6, 2023
8c1fac8
note dep build time in GCC CI
AlexanderRichert-NOAA Dec 7, 2023
435bccd
Update CMakeLists.txt
AlexanderRichert-NOAA Dec 7, 2023
ca53742
Update spack.yaml
AlexanderRichert-NOAA Dec 7, 2023
08d8e10
Update CMakeLists.txt
AlexanderRichert-NOAA Dec 8, 2023
06d17f7
Update spack.yaml
AlexanderRichert-NOAA Dec 8, 2023
ca94767
switch to use fms implementation of mpp
BrianCurtis-NOAA Dec 11, 2023
630a2f7
Merge remote-tracking branch 'upstream/develop' into use_fms_mpp
jkbk2004 Jan 4, 2024
01bb3e2
revert stoch phys name change
AlexanderRichert-NOAA Jan 4, 2024
773262c
Merge remote-tracking branch 'brian/use_fms_mpp' into add_ci
AlexanderRichert-NOAA Jan 4, 2024
d0a7c24
Update GCC.yml (remove fms recipe workaround)
AlexanderRichert-NOAA Jan 4, 2024
b73d804
rename stochastic_physics repo dir->stochastic_physics_repo
AlexanderRichert-NOAA Jan 4, 2024
435f4d0
remove apt mpi installation
AlexanderRichert-NOAA Jan 4, 2024
e993d15
increment cache key
AlexanderRichert-NOAA Jan 4, 2024
764d250
Merge remote-tracking branch 'noaaemc/develop' into add_ci
AlexanderRichert-NOAA Jan 9, 2024
dfc689a
Merge remote-tracking branch 'origin/develop' into add_ci
AlexanderRichert-NOAA Jan 11, 2024
7d520aa
Add CI testing w/CTest & gcovr, + initial unit tests
AlexanderRichert-NOAA Jan 11, 2024
f4434a2
Update PR template
AlexanderRichert-NOAA Jan 11, 2024
41a9a00
Merge remote-tracking branch 'noaaemc/develop' into add_unit_testing
AlexanderRichert-NOAA Jan 12, 2024
f6cca88
complete test_fv3_io_def.F90
AlexanderRichert-NOAA Jan 13, 2024
bb31535
Update pull_request_template.md
AlexanderRichert-NOAA Jan 13, 2024
aaf587b
fix testrun build path in GCC.yml
AlexanderRichert-NOAA Jan 13, 2024
a309fb8
catch one more case in post_nems_routine unit test
AlexanderRichert-NOAA Jan 13, 2024
4360aee
fix test_post_nems_routines.F90
AlexanderRichert-NOAA Jan 13, 2024
ba5f71d
Update CMakeLists.txt
AlexanderRichert-NOAA Jan 13, 2024
a4f5a26
simplify test_fv3_io_def.F90
AlexanderRichert-NOAA Jan 13, 2024
df302ed
Merge remote-tracking branch 'noaaemc/develop' into add_unit_testing
AlexanderRichert-NOAA Jan 19, 2024
99c197f
Re-integrate developer.yml into GCC.yml
AlexanderRichert-NOAA Jan 19, 2024
e6c41db
refine cache condition in GCC.yml
AlexanderRichert-NOAA Jan 19, 2024
1b57dcc
fix up GCC.yml
AlexanderRichert-NOAA Jan 19, 2024
8723888
update doc artifact path
AlexanderRichert-NOAA Jan 19, 2024
30a9f1b
Only build gcovr report in one job
AlexanderRichert-NOAA Jan 19, 2024
0e875fe
restore gcov cmake flags
AlexanderRichert-NOAA Jan 19, 2024
e14f32c
rm developer.yml
AlexanderRichert-NOAA Jan 19, 2024
22abc64
Fix gcov cmake flags GCC.yml
AlexanderRichert-NOAA Jan 19, 2024
80e78bc
Update test_fv3_io_def.F90
AlexanderRichert-NOAA Jan 19, 2024
c6f749e
remove test_fv3_io_def.F90
AlexanderRichert-NOAA Jan 19, 2024
eed40d3
test re-removing PIO dep in ci CMake
AlexanderRichert-NOAA Feb 15, 2024
5841f80
Update CMakeLists.txt
AlexanderRichert-NOAA Feb 15, 2024
11f8572
Merge branch 'develop' into add_unit_testing
AlexanderRichert-NOAA May 13, 2024
6a8d95d
GCC.yml: fix devbuild condition
AlexanderRichert-NOAA May 13, 2024
2074d8d
GCC.yml: fix devbuild condition pt 2
AlexanderRichert-NOAA May 13, 2024
48426bf
rearrange GCC.yml
AlexanderRichert-NOAA May 13, 2024
10cd572
Update GCC.yml
AlexanderRichert-NOAA May 13, 2024
415986d
fix gcovr
AlexanderRichert-NOAA May 13, 2024
657e1a3
Update GCC.yml
AlexanderRichert-NOAA May 13, 2024
7582ab7
Update GCC.yml
AlexanderRichert-NOAA May 13, 2024
edf94e6
Update GCC.yml
AlexanderRichert-NOAA May 13, 2024
b51b1a3
Update GCC.yml
AlexanderRichert-NOAA May 13, 2024
369bf89
debug
AlexanderRichert-NOAA May 13, 2024
3f633e2
Update GCC.yml
AlexanderRichert-NOAA May 14, 2024
cc98607
Update GCC.yml
AlexanderRichert-NOAA May 14, 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
5 changes: 5 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ Do PRs in upstream repositories need to be merged first?
If so add the "waiting for other repos" label and list the upstream PRs
- waiting on noaa-emc/nems/pull/<pr_number>
- waiting on noaa-emc/fv3atm/pull/<pr_number>

# Requirements before merging
- [ ] All new code in this PR is tested by at least one unit test
- [ ] All new code in this PR includes Doxygen documentation
- [ ] All new code in this PR does not add new compilation warnings (check CI output)
59 changes: 49 additions & 10 deletions .github/workflows/GCC.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,19 @@ jobs:

steps:

- name: install-doxygen
# Only do Doxygen and gcovr build for one job
- name: decide-doc-gcovr-build
run: |
sudo apt-get install doxygen graphviz
if [[ "${{ matrix.cmake_opts }}" == "-D32BIT=ON" && "${{ matrix.gcc_ver }}" == 11 && "${{ matrix.mpi }}" == mpich ]]; then
echo 'devbuild=ON' | tee -a ${GITHUB_ENV}
echo 'gcov_cmake="-DCMAKE_Fortran_FLAGS=-fprofile-abs-path -fprofile-arcs -ftest-coverage -O0"' | tee -a ${GITHUB_ENV}
else
echo 'devbuild=OFF' | tee -a ${GITHUB_ENV}
fi

- name: apt-install
run: |
sudo apt-get install gcovr doxygen graphviz

- name: checkout-fv3atm
uses: actions/checkout@v3
Expand Down Expand Up @@ -58,6 +68,14 @@ jobs:
spack config add "packages:mpi:require:'${{ matrix.mpi }}'"
spack concretize |& tee ${SPACK_ENV}/log.concretize
spack install -j2 --fail-fast
echo "spackrc=$?" >> ${GITHUB_ENV}

- name: cache-save
uses: actions/cache/save@v3
if: ${{ (env.spackrc) == 0 }}
with:
path: ${{ github.workspace }}/spack-develop
key: spack-${{ hashFiles('fv3atm/ci/spack.yaml') }}-gcc11-2

- name: build-fv3atm
run: |
Expand All @@ -67,23 +85,44 @@ jobs:
cd ${GITHUB_WORKSPACE}/fv3atm
git clone https://github.com/NOAA-EMC/CMakeModules
git clone --recurse-submodules https://github.com/NOAA-PSL/stochastic_physics stochastic_physics_repo
mkdir ${GITHUB_WORKSPACE}/build
sed -i 's/doc /upp_doc /' upp/docs/CMakeLists.txt
cd ${GITHUB_WORKSPACE}/build
cmake ${GITHUB_WORKSPACE}/fv3atm -DBUILD_TESTING=ON ${{ matrix.cmake_opts }} -DENABLE_DOCS=ON
mkdir ${GITHUB_WORKSPACE}/fv3atm/build
cd ${GITHUB_WORKSPACE}/fv3atm/build
cmake ${GITHUB_WORKSPACE}/fv3atm -DBUILD_TESTING=ON ${{ matrix.cmake_opts }} -DENABLE_DOCS=${{ env.devbuild }} ${{ env.gcov_cmake }}
make -j2
ls -l /home/runner/work/fv3atm/fv3atm/fv3atm/io

- uses: actions/upload-artifact@v3
- name: run-tests
run: |
cd $GITHUB_WORKSPACE/fv3atm/build
ctest -j2 --output-on-failure --rerun-failed

- name: get-test-coverage
if: ${{ env.devbuild == 'ON' }}
run: |
f=${GITHUB_WORKSPACE}/fv3atm
cd $f/build
gcovr -r .. -v --html-details --exclude ${f}/tests --exclude $f/stochastic_physics_repo --exclude $f/build/ccpp --exclude $f/ccpp/physics --exclude $f/ccpp/framework --exclude $f/atmos_cubed_sphere --exclude CMakeFiles --print-summary -o test-coverage.html

- name: upload-test-coverage
uses: actions/upload-artifact@v4
if: ${{ env.devbuild == 'ON' }}
with:
name: test-coverage-fv3atm-${{ github.sha }}
path: |
${{ github.workspace }}/fv3atm/build/*.html
${{ github.workspace }}/fv3atm/build/*.css

- uses: actions/upload-artifact@v4
if: ${{ env.devbuild == 'ON' }}
with:
name: docs
path: |
build/docs/html
${{ github.workspace }}/fv3atm/build/docs/html

- name: debug-artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: ccpp_prebuild_logs
path: ${{ github.workspace }}/build/ccpp/ccpp_prebuild.*

path: ${{ github.workspace }}/fv3atm/build/ccpp/ccpp_prebuild.*
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ if(OPENMP)
target_link_libraries(fv3atm PUBLIC OpenMP::OpenMP_Fortran)
endif()

if(BUILD_TESTING)
include(CTest)
add_subdirectory(tests)
endif()

###############################################################################
### Install
###############################################################################
Expand Down
1 change: 1 addition & 0 deletions ci/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ endif()
find_package(bacio 2.4.0 REQUIRED)
find_package(sp 2.3.3 REQUIRED)
find_package(w3emc 2.9.2 REQUIRED)
find_package(PIO REQUIRED)
AlexanderRichert-NOAA marked this conversation as resolved.
Show resolved Hide resolved

find_package(Python 3.6 REQUIRED COMPONENTS Interpreter)

Expand Down
29 changes: 29 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file sets up CTest unit tests for fv3atm.
#
# Alex Richert, Jan 2024

# Stage test data
execute_process(COMMAND cmake -E create_symlink
"${CMAKE_CURRENT_SOURCE_DIR}/data"
"${CMAKE_CURRENT_BINARY_DIR}/data"
)

function(add_fv3atm_mpi_test TESTNAME)
add_executable(${TESTNAME} ${TESTNAME}.F90)
target_link_libraries(${TESTNAME} PRIVATE fv3atm MPI::MPI_Fortran PIO::PIO_Fortran)
add_test(${TESTNAME} ${MPIEXEC_EXECUTABLE} -n 2 ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME})
endfunction()

function(add_fv3atm_serial_test TESTNAME)
add_executable(${TESTNAME} ${TESTNAME}.F90)
target_link_libraries(${TESTNAME} PRIVATE fv3atm)
add_test(${TESTNAME} ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME})
endfunction()

#foreach(testname test_write_netcdf)
# add_fv3atm_mpi_test(${testname})
#endforeach()

foreach(testname test_fv3_io_def test_post_nems_routines)
add_fv3atm_serial_test(${testname})
endforeach()
20 changes: 20 additions & 0 deletions tests/data/post_namelist.nml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
&model_inputs
modelname = "DMMY"
submodelname = "SUBM"
/
&nampgb
kpo = 5
kth = 7
kpv = 9
po = 0.5 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
th = 1.0 2.0 3.0 4.0 5.0 6.0 7.0
pv = 11. 12. 13. 14. 15. 16. 17. 18. 19.
hyb_sigp = F
d3d_on = T
gocart_on = T
popascal = T
rdaod = T
nasa_on = T
gccpp_on = T
d2d_chem = T
/
4 changes: 4 additions & 0 deletions tests/data/post_namelist_empty.nml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
&model_inputs
/
&nampgb
/
130 changes: 130 additions & 0 deletions tests/test_fv3_io_def.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
! This program provides a unit test to verify that the variables in
! module_fv3_io_def.F90 are accessible.
! Alex Richert, 11 Jan 2024

program test_fv3_io_def

use module_fv3_io_def

implicit none

num_pes_fcst = 2
if (num_pes_fcst .ne. 2) stop 1
AlexanderRichert-NOAA marked this conversation as resolved.
Show resolved Hide resolved
wrttasks_per_group = 4
if (wrttasks_per_group .ne. 4) stop 2
write_groups = 8
if (write_groups .ne. 8) stop 3
n_group = 16
if (n_group .ne. 16) stop 4
num_files = 32
if (num_files .ne. 32) stop 5
nbdlphys = 64
if (nbdlphys .ne. 64) stop 6
iau_offset = 128
if (iau_offset .ne. 128) stop 7

lflname_fulltime = .true.
if (.not. lflname_fulltime) stop 8
time_unlimited = .true.
if (.not. time_unlimited) stop 9

allocate(filename_base(1))
filename_base(1)="abc"
if (trim(filename_base(1)).ne."abc") stop 10
allocate(output_file(1))
output_file(1)="def"
if (trim(output_file(1)).ne."def") stop 11

allocate(lead_wrttask(10))
lead_wrttask = 42
if (any(lead_wrttask(1:10).ne.42)) stop 12
allocate(last_wrttask(12))
last_wrttask = 43
if (any(last_wrttask(1:12).ne.43)) stop 13

allocate(output_grid(2))
output_grid(1) = "ABC"
output_grid(2) = "DEF"
if (trim(output_grid(1)).ne."ABC") stop 14
if (trim(output_grid(2)).ne."DEF") stop 15

allocate(imo(6))
imo(1:6) = 17
if (any(imo.ne.17)) stop 16
allocate(jmo(6))
jmo(1:6) = 18
if (any(jmo.ne.18)) stop 17

allocate(cen_lon(8))
cen_lon(1:8) = 2.1
if(any(cen_lon.ne.2.1)) stop 18
allocate(cen_lat(8))
cen_lat(1:8) = 3.2
if(any(cen_lat.ne.3.2)) stop 19

allocate(lon1(10))
lon1(1:10) = 4.3
if(any(lon1.ne.4.3)) stop 20
allocate(lat1(10))
lat1(1:10) = 5.4
if(any(lat1.ne.5.4)) stop 21

allocate(lon2(12))
lon2(1:12) = 6.5
if(any(lon2.ne.6.5)) stop 22
allocate(lat2(12))
lat2(1:12) = 7.6
if(any(lat2.ne.7.6)) stop 23

allocate(dlon(15))
dlon(1:15) = 8.7
if(any(dlon.ne.8.7)) stop 24
allocate(dlat(15))
dlat(1:15) = 9.8
if(any(dlat.ne.9.8)) stop 25

allocate(stdlat1(18))
stdlat1(1:18) = 10.9
if(any(stdlat1.ne.10.9)) stop 26
allocate(stdlat2(18))
stdlat2(1:18) = 11.0
if(any(stdlat2.ne.11.0)) stop 27

allocate(dx(20))
dx(1:20) = 12.1
if(any(dx.ne.12.1)) stop 28
allocate(dy(20))
dy(1:20) = 13.2
if(any(dy.ne.13.2)) stop 29

allocate(ideflate(25))
ideflate(1:25) = 123
if(any(ideflate.ne.123)) stop 30
allocate(quantize_nsd(25))
quantize_nsd(1:25) = 123
if(any(quantize_nsd.ne.123)) stop 31
allocate(zstandard_level(25))
zstandard_level(1:25) = 123
if(any(zstandard_level.ne.123)) stop 32

allocate(quantize_mode(5))
quantize_mode(1:5) = "xyz"
if(.not.trim(quantize_mode(5)).eq."xyz") stop 33

allocate(ichunk2d(30))
ichunk2d(1:30) = 50
if(any(ichunk2d.ne.50)) stop 34
allocate(jchunk2d(30))
jchunk2d(1:30) = 51
if(any(jchunk2d.ne.51)) stop 35
allocate(ichunk3d(30))
ichunk3d(1:30) = 52
if(any(ichunk3d.ne.52)) stop 36
allocate(jchunk3d(30))
jchunk3d(1:30) = 53
if(any(jchunk3d.ne.53)) stop 37
allocate(kchunk3d(30))
kchunk3d(1:30) = 54
if(any(kchunk3d.ne.54)) stop 38

end program test_fv3_io_def
55 changes: 55 additions & 0 deletions tests/test_post_nems_routines.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
! This program provides unit testing for the subroutines in io/post_nems_routines.F90
!
! Alex Richert, 11 Jan 2024
program test_post_nems_routines

use ctlblk_mod, only : komax,hyb_sigp,d3d_on,gocart_on, &
rdaod,nasa_on,gccpp_on,d2d_chem,modelname,submodelname, lsm

implicit none

character (len=*), parameter :: post_namelist_empty="data/post_namelist_empty.nml"
character (len=*), parameter :: post_namelist="data/post_namelist.nml"
integer :: kpo,kth,kpv
real(4),dimension(komax) :: po,th,pv
logical :: popascal
real, parameter :: tini=tiny(1.0)

! Verify default settings by using empty nml file
call read_postnmlt(kpo,kth,kpv,po,th,pv,trim(post_namelist_empty))
if (kpo.ne.0) stop 1
if (kth.ne.6) stop 2
if (kpv.ne.8) stop 3
if (any(po.ne.0.0)) stop 4
if (any(abs(th(1:6)-(/310.,320.,350.,450.,550.,650./)).gt.tini)) stop 5
if (any(abs(pv(1:8)-(/0.5,-0.5,1.0,-1.0,1.5,-1.5,2.0,-2.0/)).gt.tini)) stop 6
if (.not.hyb_sigp) stop 7
if (d3d_on) stop 8
if (gocart_on) stop 9
if (lsm.ne.46) stop 10 ! 'lsm' is determined by 'popascal'
if (rdaod) stop 11
if (nasa_on) stop 12
if (gccpp_on) stop 13
if (d2d_chem) stop 14

! Now use fully populated nml file
call read_postnmlt(kpo,kth,kpv,po,th,pv,trim(post_namelist))
if (kpo.ne.5) stop 101
if (kth.ne.7) stop 102
if (kpv.ne.9) stop 103
if (po(1).ne.0.5) stop 104
if (any(po(2:komax).ne.1.0)) stop 104
if (any(abs(th(1:7)-(/1.,2.,3.,4.,5.,6.,7./)).gt.tini)) stop 105
if (any(abs(pv(1:9)-(/11.,12.,13.,14.,15.,16.,17.,18.,19./)).gt.tini)) stop 106
if (hyb_sigp) stop 107
if (.not.d3d_on) stop 108
if (.not.gocart_on) stop 109
if (lsm.ne.5) stop 110 ! 'lsm' is determined by 'popascal'
if (.not.rdaod) stop 111
if (.not.nasa_on) stop 112
if (.not.gccpp_on) stop 113
if (.not.d2d_chem) stop 114
if (trim(modelname).ne."DMMY") stop 115
if (trim(submodelname).ne."SUBM") stop 116

end program test_post_nems_routines
Loading