forked from mom-ocean/MOM6
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MOM_file_parser unit test implementation
This patch introduces new features to support unit testing of the MOM6 source code. The patch includes two new modules (MOM_unit_testing, MOM_file_parser_tests), two new classes (UnitTest, TestSuite), and a new driver (unit_testing). A UnitTest object consists of the following: * The test subroutine * Test name (for reporting) * A flag indicating whether the test should fail (FATAL) * An optional cleanup subroutine The UnitTest objects are gathered into a TestSuite object, which provides a batch job for running all of its tests. The use of these features is demonstrated in a driver, unit_tests, which runs the tests provided in the MOM_file_parser_tests module This patch also includes changes to the ".testing" build system. * The optional FCFLAGS_COVERAGE has been removed from the testing Makefile. Instead, a new "cov" target is optionally built if one wants to check the coverage. It is currently based on "symmetric". * A new "unit" target has been added to run the unit testing driver and report its code coverage. * GitHub Actions has been modified to include the unit driver test. * The gcov output now includes branching (-b), which allows reporting of partial line coverage in some cases. * codecov.io "smart" report searching has been replaced with an explicit setting of the root directory (-R) and *.gcda paths. Other minor changes: * MOM_coms include an infra-level sync function (sync_PEs) as a wrapper to mpp_sync (or others in the future).
- Loading branch information
1 parent
9d6def6
commit cf448a1
Showing
11 changed files
with
2,411 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
program MOM_unit_tests | ||
|
||
use MPI | ||
use MOM_domains, only : MOM_infra_init | ||
use MOM_domains, only : MOM_infra_end | ||
use MOM_file_parser_tests, only : run_file_parser_tests | ||
|
||
implicit none | ||
|
||
integer, parameter :: comm = MPI_COMM_WORLD | ||
integer, parameter :: root = 0 | ||
integer :: rank | ||
logical :: file_exists_on_rank | ||
logical :: input_nml_exists, MOM_input_exists | ||
integer :: io_unit | ||
logical :: is_open, is_file | ||
integer :: rc | ||
|
||
! NOTE: Bootstrapping requires external MPI configuration. | ||
! - FMS initialization requires the presence of input.nml | ||
! - MOM initialization requires MOM_input (if unspecificed by input.nml) | ||
! - Any MPI-based I/O prior to MOM and FMS init will MPI initialization | ||
! Thus, we need to do some minimal MPI setup. | ||
call MPI_Init(rc) | ||
call MPI_Comm_rank(comm, rank, rc) | ||
|
||
inquire(file='input.nml', exist=file_exists_on_rank) | ||
call MPI_Reduce(file_exists_on_rank, input_nml_exists, 1, MPI_LOGICAL, & | ||
MPI_LOR, root, comm, rc) | ||
|
||
inquire(file='MOM_input', exist=file_exists_on_rank) | ||
call MPI_Reduce(file_exists_on_rank, MOM_input_exists, 1, MPI_LOGICAL, & | ||
MPI_LOR, root, comm, rc) | ||
|
||
if (rank == root) then | ||
! Abort if at least one rank sees either input.nml or MOM_input | ||
if (input_nml_exists) error stop "Remove existing 'input.nml' file." | ||
if (MOM_input_exists) error stop "Remove existing 'MOM_input' file." | ||
|
||
! Otherwise, create the (empty) files | ||
open(newunit=io_unit, file='input.nml', status='replace') | ||
write(io_unit, '(a)') "&fms2_io_nml /" | ||
close(io_unit) | ||
|
||
open(newunit=io_unit, file='MOM_input', status='replace') | ||
close(io_unit) | ||
endif | ||
|
||
call MOM_infra_init(comm) | ||
|
||
! Run tests | ||
call run_file_parser_tests | ||
|
||
! Cleanup | ||
call MOM_infra_end | ||
|
||
if (rank == root) then | ||
open(newunit=io_unit, file='MOM_input') | ||
close(io_unit, status='delete') | ||
|
||
open(newunit=io_unit, file='input.nml') | ||
close(io_unit, status='delete') | ||
endif | ||
|
||
end program MOM_unit_tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.