Skip to content

Commit

Permalink
refactor unit test to hopefully prevent unit test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
uramirez8707 committed Sep 26, 2024
1 parent e0ddce0 commit 32db3c0
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 50 deletions.
18 changes: 16 additions & 2 deletions test_fms/data_override/test_data_override2_mono.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
output_dir
[ ! -d "INPUT" ] && mkdir -p "INPUT"

cat <<_EOF > input.nml
cat <<_EOF > input_base.nml
&test_data_override_ongrid_nml
test_case = 2
write_only = .False.
/
_EOF

Expand All @@ -41,16 +42,23 @@ _EOF
for KIND in r4 r8
do
rm -rf INPUT/*
sed 's/write_only = .False./write_only = .True./g' input_base.nml > input.nml
test_expect_success "Creating input files (${KIND})" '
mpirun -n 6 ../test_data_override_ongrid_${KIND}
'

cp input_base.nml input.nml
test_expect_success "test_data_override with monotonically increasing and decreasing data sets (${KIND})" '
mpirun -n 6 ../test_data_override_ongrid_${KIND}
'
done

rm -rf data_table

cat <<_EOF > input.nml
cat <<_EOF > input_base.nml
&test_data_override_ongrid_nml
test_case = 2
write_only = .False.
/
&data_override_nml
use_data_table_yaml = .True.
Expand Down Expand Up @@ -80,6 +88,12 @@ if [ -z $parser_skip ]; then
for KIND in r4 r8
do
rm -rf INPUT/*
sed 's/write_only = .False./write_only = .True./g' input_base.nml > input.nml
test_expect_success "Creating input files (${KIND})" '
mpirun -n 6 ../test_data_override_ongrid_${KIND}
'

cp input_base.nml input.nml
test_expect_success "test_data_override with monotonically increasing and decreasing data sets -yaml (${KIND})" '
mpirun -n 6 ../test_data_override_ongrid_${KIND}
'
Expand Down
10 changes: 8 additions & 2 deletions test_fms/data_override/test_data_override2_ongrid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use_data_table_yaml=.False.
&test_data_override_ongrid_nml
nhalox=halo_size
nhaloy=halo_size
write_only = .False.
/
_EOF
printf '"OCN", "runoff", "runoff", "./INPUT/runoff.daitren.clim.1440x1080.v20180328.nc", "none" , 1.0' | cat > data_table
Expand All @@ -48,6 +49,7 @@ use_data_table_yaml=.True.
&test_data_override_ongrid_nml
nhalox=halo_size
nhaloy=halo_size
write_only = .False.
/
_EOF
cat <<_EOF > data_table.yaml
Expand All @@ -66,18 +68,22 @@ fi
for KIND in r4 r8
do
rm -rf INPUT/*
sed -e 's/halo_size/2/g ; s/write_only = .False./write_only = .True./g' input_base.nml > input.nml

test_expect_success "Creating input files (${KIND})" '
mpirun -n 6 ../test_data_override_ongrid_${KIND}
'

sed 's/halo_size/2/g' input_base.nml > input.nml
test_expect_success "data_override on grid with 2 halos in x and y (${KIND})" '
mpirun -n 6 ../test_data_override_ongrid_${KIND}
'

rm -rf INPUT/*
sed 's/halo_size/0/g' input_base.nml > input.nml
test_expect_success "data_override on grid with 0 halos in x and y (${KIND})" '
mpirun -n 6 ../test_data_override_ongrid_${KIND}
'

rm -rf INPUT/*
test_expect_success "data_override get_grid_v1 (${KIND})" '
mpirun -n 1 ../test_get_grid_v1_${KIND}
'
Expand Down
13 changes: 10 additions & 3 deletions test_fms/data_override/test_data_override2_scalar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,24 @@ output_dir
rm -rf data_table data_table.yaml input.nml input_base.nml

if [ ! -z $parser_skip ]; then
cat <<_EOF > input.nml
cat <<_EOF > input_base.nml
&data_override_nml
use_data_table_yaml=.False.
/
&test_data_override_ongrid_nml
test_case = 3
write_only = .False.
/
_EOF
printf '"OCN", "co2", "co2", "./INPUT/scalar.nc", "none" , 1.0' | cat > data_table
else
cat <<_EOF > input.nml
cat <<_EOF > input_base.nml
&data_override_nml
use_data_table_yaml=.True.
/
&test_data_override_ongrid_nml
test_case = 3
write_only = .False.
/
_EOF
cat <<_EOF > data_table.yaml
Expand All @@ -62,10 +64,15 @@ fi
for KIND in r4 r8
do
rm -rf INPUT/*
test_expect_success "data_override scalar field (${KIND})" '
sed 's/write_only = .False./write_only = .True./g' input_base.nml > input.nml
test_expect_success "Creating input files (${KIND})" '
mpirun -n 6 ../test_data_override_ongrid_${KIND}
'

cp input_base.nml input.nml
test_expect_success "data_override scalar field (${KIND})" '
mpirun -n 6 ../test_data_override_ongrid_${KIND}
'
done
rm -rf INPUT *.nc # remove any leftover files to reduce size

Expand Down
9 changes: 8 additions & 1 deletion test_fms/data_override/test_data_override_ensembles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ data_table:
factor: 1.0
_EOF

cat <<_EOF > input.nml
cat <<_EOF > input_base.nml
&data_override_nml
use_data_table_yaml = .True.
/
&test_data_override_ongrid_nml
test_case = 5
write_only = .False.
/
&ensemble_nml
Expand All @@ -68,6 +69,12 @@ if [ -z $parser_skip ]; then
for KIND in r4 r8
do
rm -rf INPUT/.
sed 's/write_only = .False./write_only = .True./g' input_base.nml > input.nml
test_expect_success "Creating input files (${KIND})" '
mpirun -n 12 ../test_data_override_ongrid_${KIND}
'

cp input_base.nml input.nml
test_expect_success "test_data_override with two ensembles -yaml (${KIND})" '
mpirun -n 12 ../test_data_override_ongrid_${KIND}
'
Expand Down
87 changes: 46 additions & 41 deletions test_fms/data_override/test_data_override_ongrid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ program test_data_override_ongrid
nf90_double, nf90_unlimited
use ensemble_manager_mod, only: get_ensemble_size, ensemble_manager_init

use fms_mod, only: string
use fms_mod, only: string, fms_init, fms_end

implicit none

Expand All @@ -61,10 +61,12 @@ program test_data_override_ongrid
integer, allocatable :: pelist(:)
integer, allocatable :: pelist_ens(:)
integer :: ensemble_id
logical :: write_only=.false. !< True if creating the input files only
!! False if running the tests only

namelist / test_data_override_ongrid_nml / nhalox, nhaloy, test_case, nlon, nlat, layout
namelist / test_data_override_ongrid_nml / nhalox, nhaloy, test_case, nlon, nlat, layout, write_only

call mpp_init
call fms_init
call fms2_io_init

read (input_nml_file, test_data_override_ongrid_nml, iostat=io_status)
Expand Down Expand Up @@ -98,46 +100,49 @@ program test_data_override_ongrid
call mpp_set_current_pelist(pelist)
end select

select case (test_case)
case (ongrid)
call generate_ongrid_input_file ()
case (bilinear)
call generate_bilinear_input_file ()
case (scalar)
call generate_scalar_input_file ()
case (weight_file)
call generate_weight_input_file ()
case (ensemble_case)
call generate_ensemble_input_file()
end select

call mpp_sync()
call mpp_error(NOTE, "Finished creating INPUT Files")

select case (test_case)
case (ensemble_case)
!< Go back to the ensemble pelist
call mpp_set_current_pelist(pelist_ens)
end select

!< Initiliaze data_override
call data_override_init(Ocean_domain_in=Domain, mode=lkind)
if (write_only) then
select case (test_case)
case (ongrid)
call generate_ongrid_input_file ()
case (bilinear)
call generate_bilinear_input_file ()
case (scalar)
call generate_scalar_input_file ()
case (weight_file)
call generate_weight_input_file ()
case (ensemble_case)
call generate_ensemble_input_file()
end select

select case (test_case)
case (ongrid)
call ongrid_test()
case (bilinear)
call bilinear_test()
case (scalar)
call scalar_test()
case (weight_file)
call weight_file_test()
case (ensemble_case)
call ensemble_test()
call mpp_set_current_pelist(pelist)
end select
call mpp_sync()
call mpp_error(NOTE, "Finished creating INPUT Files")

call mpp_exit
else
select case (test_case)
case (ensemble_case)
!< Go back to the ensemble pelist
call mpp_set_current_pelist(pelist_ens)
end select

!< Initiliaze data_override
call data_override_init(Ocean_domain_in=Domain, mode=lkind)

select case (test_case)
case (ongrid)
call ongrid_test()
case (bilinear)
call bilinear_test()
case (scalar)
call scalar_test()
case (weight_file)
call weight_file_test()
case (ensemble_case)
call ensemble_test()
call mpp_set_current_pelist(pelist)
end select
endif

call fms_end

contains

Expand Down
9 changes: 8 additions & 1 deletion test_fms/data_override/test_data_override_weights.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ data_table:
factor: 1.0
_EOF

cat <<_EOF > input.nml
cat <<_EOF > input_base.nml
&data_override_nml
use_data_table_yaml = .True.
/
Expand All @@ -58,6 +58,7 @@ cat <<_EOF > input.nml
nlon = 5
nlat = 6
layout = 1, 2
write_only = .False.
/
_EOF

Expand All @@ -66,6 +67,12 @@ if [ -z $parser_skip ]; then
for KIND in r4 r8
do
rm -rf INPUT/.
sed 's/write_only = .False./write_only = .True./g' input_base.nml > input.nml
test_expect_success "Creating input files (${KIND})" '
mpirun -n 2 ../test_data_override_ongrid_${KIND}
'

cp input_base.nml input.nml
test_expect_success "test_data_override with and without weight files -yaml (${KIND})" '
mpirun -n 2 ../test_data_override_ongrid_${KIND}
'
Expand Down

0 comments on commit 32db3c0

Please sign in to comment.