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

Adds test for mpp_init_logfile #510

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Adding unit test for interface mpp_init_logfile.
  • Loading branch information
ngs333 committed Jul 10, 2020
commit c50d06dba77e9283d21f5d4ed1b4025b3d8ca64c
15 changes: 15 additions & 0 deletions mpp/include/mpp_util.inc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@
end function stdlog

!#####################################################################
! <FUNCTION NAME="mpp_init_logfile">
! <OVERVIEW>
! Initialize the logfile.
! </OVERVIEW>
! <DESCRIPTION>
! This function re-initializes the log files of the PEs. Re-initialization
! means replacing if it already exists. It does not make new files if they don't
! already exist. Only log files with names of format "<header>.pe_number.out",
! where pe_number is the digit integer represeting the PE number, such as 000000 for the
! root PE, 000001 for the next PE, etch. The <header> is the config file name prefix -
! a module global normally set elsewhere, and frequetly is the integer simulation
! timedate (e.g. 19480101).
! </DESCRIPTION>
! </FUNCTION>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any added documentation should be in doxygen format. Please reformat

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have reformatted now!

subroutine mpp_init_logfile()
integer :: p
logical :: exist
Expand Down
3 changes: 3 additions & 0 deletions mpp/mpp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ module mpp_mod
public :: read_ascii_file, read_input_nml, mpp_clock_begin, mpp_clock_end
public :: get_ascii_file_num_lines
public :: mpp_record_time_start, mpp_record_time_end
!! TODO:
public :: mpp_init_logfile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you still working on this? Are you making a private routine public?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping to not make it public. Is there a better way to get access to mpp_init_logfile from the unit test app.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may remain a problem (with both pros and cons) see the issue below concerning mpp_init_test_logfile_init

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for bringing up the issue in the meeting. Fortunately for this test is a non-issue now.


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this whitespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its removed now!


!--- public interface from mpp_comm.h ------------------------------
public :: mpp_chksum, mpp_max, mpp_min, mpp_sum, mpp_transmit, mpp_send, mpp_recv
Expand Down
10 changes: 7 additions & 3 deletions test_fms/mpp/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ check_PROGRAMS = test_mpp \
test_system_clock \
test_mpp_broadcast \
test_clock_init \
test_domains_simple
test_domains_simple \
test_mpp_init_logfile

# These are the sources for the tests.
test_mpp_SOURCES = test_mpp.F90
Expand All @@ -60,6 +61,7 @@ test_system_clock_SOURCES=test_system_clock.F90
test_mpp_broadcast_SOURCES=test_mpp_broadcast.F90
test_clock_init_SOURCES=test_clock_init.F90
test_domains_simple_SOURCES = test_domains_simple.F90
test_mpp_init_logfile_SOURCES=test_mpp_init_logfile.F90

# Run the test programs.
TESTS = test_mpp_domains2.sh \
Expand All @@ -71,7 +73,8 @@ TESTS = test_mpp_domains2.sh \
test_mpp_get_ascii_lines2.sh \
test_system_clock.sh \
test_mpp_broadcast.sh \
test_clock_init.sh
test_clock_init.sh \
test_mpp_init_logfile.sh

# These files will also be included in the distribution.
EXTRA_DIST = input_base.nml \
Expand All @@ -87,7 +90,8 @@ EXTRA_DIST = input_base.nml \
base_ascii_long \
test_system_clock.sh \
test_mpp_broadcast.sh \
test_clock_init.sh
test_clock_init.sh \
test_mpp_init_logfile.sh

# Clean up
CLEANFILES = include_files_mod.mod input.nml *.out* ascii*
44 changes: 44 additions & 0 deletions test_fms/mpp/test_mpp_init_logfile.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
!***********************************************************************
!* GNU Lesser General Public License
!*
!* This file is part of the GFDL Flexible Modeling System (FMS).
!*
!* FMS is free software: you can redistribute it and/or modify it under
!* the terms of the GNU Lesser General Public License as published by
!* the Free Software Foundation, either version 3 of the License, or (at
!* your option) any later version.
!*
!* FMS is distributed in the hope that it will be useful, but WITHOUT
!* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
!* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
!* for more details.
!*
!* You should have received a copy of the GNU Lesser General Public
!* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
!***********************************************************************

!> @file
!! @brief Tests the mpp_init_logfile interface
!! @author Miguel Zuniga
!! @email gfdl.climate.model.info@noaa.gov

program test_mpp_init_logfile
#include <fms_platform.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use platforms_mod instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats what I get for copy and pasting. I dont even use it.


use mpp_mod, only : mpp_init, mpp_init_logfile
use mpp_mod, only : mpp_init_test_logfile_init

IMPLICIT NONE

integer :: my_mpp_init_level
integer :: err_no

!Initialize mpp but have mpp_init() exit before log files are initalized.
my_mpp_init_level = mpp_init_test_logfile_init - 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you subtracting 1? Isn't there a mpp_init_test level that you can directly use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was subtracting one so that initialization stops before calling init_logfile. But given the
challenge of keeping init_logfile private, and upon inspection of the mpp_init routine, it occurs to me that I can solve both issues just by not subtracting one and not calling init_log_file.
Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure and am requesting input. If the init level is set to "mpp_init_test_logfile_init".
then mpp_init() actually does more work AFTER calling mpp_initlogfile: it writes to the logifle. So technically, to test the interface, one should isolate the interface to whatever extent possible, not after what it creates is used by another function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its changed so it not subtracting now. Corresponding changed in the shell script were made. Mpp_init_logfile was removed from public (i.e. put back to original form).

call mpp_init( test_level = my_mpp_init_level )

call mpp_init_logfile()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is anything actually tested, or is this routine just called?

Copy link
Contributor Author

@ngs333 ngs333 Jul 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the test work is actually done is done by the shell command calling this the fortran test program. The shell program creates file and checks the effects of the called app. Like many I/o routines, mpp_init_logfile() is merely a side_effect routine. So what the shell comman does is test that it makes it side effects correctly and also that it doesn't make additional side effects that it could potentially make. This means, checking the files that it should replace, and checking for the lack of existence of files that it should not make but that whose names are iterated over in the do loop of the routine. If you look at the shell command that calls it, you should be able to see that it returns a '1' when those conditions are not satisfied. (PS I checked that the CI summary shows "FAILED" is the shell command returns 1, and success if it returns 0.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the comments in both the Fortran test program and the corresponding shell script. It better explains what they are doing together.

!! With the unifinished initialization, mpp_exit() is causing crash. Use MPI_FINALIZE:
call MPI_FINALIZE(err_no)

end program test_mpp_init_logfile
89 changes: 89 additions & 0 deletions test_fms/mpp/test_mpp_init_logfile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/sh

#***********************************************************************
# GNU Lesser General Public License
#
# This file is part of the GFDL Flexible Modeling System (FMS).
#
# FMS is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# FMS is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with FMS. If not, see <http://www.gnu.org/licenses/>.
#***********************************************************************

# This is part of the GFDL FMS package. This is a shell script to
# execute tests in the test_fms/mpp directory.

# Set common test settings.
. ../test_common.sh

skip_test="no"

echo "Calling test_mp_init_logfile"

# Get the number of available CPUs on the system
if [ $(command -v nproc) ]
then
# Looks like a linux system
nProc=$(nproc)
elif [ $(command -v sysctl) ]
then
# Looks like a Mac OS X system
nProc=$(sysctl -n hw.physicalcpu)
else
nProc=-1
fi

# Do we need to oversubscribe
if [ ${nProc} -lt 0 ]
then
# Couldn't get the number of CPUs, skip the test.
skip_test="skip"
elif [ $nProc -lt 4 ]
then
# Need to oversubscribe the MPI
run_test test_mpp_init_logfile 4 $skip_test "true"
fi

fprefix="logfile.00000"
file0="${fprefix}""0.out"
file1="${fprefix}""1.out"
file2="${fprefix}""2.out"
file3="${fprefix}""3.out"

#Create two log files, each with some content.
#echo "test_log_line" > logfile.000000.out
#echo "test_log_line" > logfile.000002.out
echo "test_log_line" > ${file0}
echo "test_log_line" > ${file2}
#Make sure other possible log files are not in the system.
if test -f ${file1}; then
rm ${file1}
fi
if test -f ${file3}; then
rm ${file3}
fi

#Have mpp re-initialize the two log files created above:
run_test test_mpp_init_logfile 4 $skip_test

#Make sure the two "old" ones have been replaced and the
#two possible new ones are not present.
#TODO test number
if [ $(wc -l < ${file0}) -ge 1 ] || [ $(wc -l < ${file2}) -ge 1 ] ||
[ -f ${file1} ] || [ -f ${file3} ]
then
echo "ERROR: Test ? was unsuccessful."
exit 1
else
echo "Test ? has passed"
exit 0
fi