Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
46 changes: 45 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ project(
)

option(CABLE_MPI "Build the MPI executable" OFF)
option(CABLE_TESTS "Build CABLE tests" OFF)

# third party libs
if(CABLE_MPI)
Expand All @@ -15,6 +16,27 @@ endif()
find_package(PkgConfig REQUIRED)
pkg_check_modules(NETCDF REQUIRED IMPORTED_TARGET "netcdf-fortran")

if(CABLE_TESTS)
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel" AND CMAKE_Fortran_COMPILER_VERSION VERSION_LESS "2024.0")
message(WARNING "Intel Fortran 2024.0 or higher is recommended for building tests.")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "GNU" AND CMAKE_Fortran_COMPILER_VERSION VERSION_LESS "13.2")
message(WARNING "GNU Fortran 13.2 or higher is recommended for building tests.")
endif()
enable_testing()
option(FORTUNO_WITH_MPI "Fortuno: whether to build the MPI interface" ${CABLE_MPI})
if(CABLE_MPI)
set(fortuno_libs Fortuno::fortuno_mpi)
else()
set(fortuno_libs Fortuno::fortuno_serial)
endif ()
include(FetchContent)
FetchContent_Declare(Fortuno
GIT_REPOSITORY https://github.com/fortuno-repos/fortuno
GIT_TAG eb61214fd76d6235a3072b6f8ed83d0380c2f266
)
FetchContent_MakeAvailable(Fortuno)
endif()

set(CABLE_Intel_Fortran_FLAGS -fp-model precise)
set(CABLE_Intel_Fortran_FLAGS_DEBUG -O0 -g -traceback -fpe0)
set(CABLE_Intel_Fortran_FLAGS_RELEASE -O2)
Expand Down Expand Up @@ -138,7 +160,7 @@ if(CABLE_LIBRARY)
else()
message(STATUS "Cannot compile library with unknown compiler")
endif()

else()
message(STATUS "Specified library application does not exist")
endif()
Expand Down Expand Up @@ -308,4 +330,26 @@ else()
install(TARGETS cable RUNTIME)
endif()

if (CABLE_TESTS)
add_executable(
cable-tests
tests/testapp.F90
tests/test_example.F90
)
if(CABLE_MPI)
target_sources(cable-tests PRIVATE tests/utils/fortuno_interface_mpi.F90)
else()
target_sources(cable-tests PRIVATE tests/utils/fortuno_interface_serial.F90)
endif()
target_link_libraries(cable-tests PRIVATE cable_common ${fortuno_libs})
if(CABLE_MPI)
add_test(
NAME cable-tests
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 1 $<TARGET_FILE:cable-tests>
)
set_tests_properties(cable-tests PROPERTIES PROCESSORS 1)
else()
add_test(NAME cable-tests COMMAND $<TARGET_FILE:cable-tests>)
endif()
endif()
endif()
20 changes: 19 additions & 1 deletion build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Options:
Build just CABLE science library (libscable_science.a), for a
specified coupled application. Options for the coupled
application are ESM1.6.
-t, --tests Enable CABLE unit tests.
-h, --help Show this screen.

Enabling debug mode:
Expand All @@ -52,6 +53,9 @@ build_args=()
# Install
do_install=1

# Tests
do_tests=0

# Argument parsing adapted and stolen from http://mywiki.wooledge.org/BashFAQ/035#Complex_nonstandard_add-on_utilities
while [ ${#} -gt 0 ]; do
case ${1} in
Expand All @@ -78,6 +82,10 @@ while [ ${#} -gt 0 ]; do
CMAKE_BUILD_PARALLEL_LEVEL=${2}
shift
;;
-t|--tests)
cmake_args+=(-DCABLE_TESTS="ON")
do_tests=1
;;
-h|--help)
show_help
exit
Expand All @@ -98,7 +106,13 @@ if hostname -f | grep gadi.nci.org.au > /dev/null; then
module add netcdf/4.6.3
case ${compiler} in
intel)
module add intel-compiler/2019.5.281
if [ $do_tests -eq 1 ]; then
# This is required to as Fortuno requires Intel Fortran
# 2024.0.0 or higher
module add intel-compiler-llvm/2024.0.2
else
module add intel-compiler/2019.5.281
fi
compiler_lib_install_dir=Intel
[[ -n ${mpi} ]] && module add intel-mpi/2019.5.281
;;
Expand Down Expand Up @@ -151,3 +165,7 @@ cmake --build build "${build_args[@]}"
if [ $do_install -eq 1 ]; then
cmake --install build --prefix .
fi

if [ $do_tests -eq 1 ]; then
ctest --test-dir build --verbose
fi
28 changes: 28 additions & 0 deletions tests/test_example.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
! CSIRO Open Source Software License Agreement (variation of the BSD / MIT License)
! Copyright (c) 2015, Commonwealth Scientific and Industrial Research Organisation
! (CSIRO) ABN 41 687 119 230.

module test_example_mod
use fortuno_interface_mod, only: test_list_t
use fortuno_interface_mod, only: test_case
use fortuno_interface_mod, only: check
implicit none
private

public :: test_example

contains

function test_example() result(example_tests)
type(test_list_t) :: example_tests
example_tests = test_list_t([ &
test_case("example", example) &
])
end function test_example

subroutine example()
!! Example test.
call check(1 /= 2, msg="1 should not equal 2")
end subroutine example

end module
16 changes: 16 additions & 0 deletions tests/testapp.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
! CSIRO Open Source Software License Agreement (variation of the BSD / MIT License)
! Copyright (c) 2015, Commonwealth Scientific and Industrial Research Organisation
! (CSIRO) ABN 41 687 119 230.

!> Entry point for running Fortuno tests.
program testapp
use fortuno_interface_mod, only: execute_cmd_app
use fortuno_interface_mod, only: test_list => test_list_t
use test_example_mod, only: test_example
implicit none

call execute_cmd_app(test_list([ &
test_example() &
]))

end program testapp
33 changes: 33 additions & 0 deletions tests/utils/fortuno_interface_mpi.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
! Copyright (C) 2024 Alex Buccheri
!
! This Source Code Form is subject to the terms of the Mozilla Public
! License, v. 2.0. If a copy of the MPL was not distributed with this
! file, You can obtain one at https://mozilla.org/MPL/2.0/.

module fortuno_interface_mod
!! Expose Fortuno MPI data types and routines through common aliases.

use fortuno_mpi, only: test_case_t => mpi_case_base
Comment thread
abhaasgoyal marked this conversation as resolved.
use fortuno_mpi, only: test_item_t => test_item
use fortuno_mpi, only: test_list_t => test_list

use fortuno_mpi, only: execute_cmd_app => execute_mpi_cmd_app
use fortuno_mpi, only: test_suite => mpi_suite_item
use fortuno_mpi, only: test_case => mpi_case_item

use fortuno_mpi, only: check => mpi_check
use fortuno_mpi, only: check_failed => mpi_check_failed
use fortuno_mpi, only: skip => mpi_skip
use fortuno_mpi, only: is_equal
use fortuno_mpi, only: all_equal
use fortuno_mpi, only: all_close

use fortuno_mpi, only: global_comm
use fortuno_mpi, only: num_ranks
use fortuno_mpi, only: this_rank

implicit none

! Scope is deliberately public

end module fortuno_interface_mod
48 changes: 48 additions & 0 deletions tests/utils/fortuno_interface_serial.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
! Copyright (C) 2024 Alex Buccheri
!
! This Source Code Form is subject to the terms of the Mozilla Public
! License, v. 2.0. If a copy of the MPL was not distributed with this
! file, You can obtain one at https://mozilla.org/MPL/2.0/.

module fortuno_interface_mod
!! Expose Fortuno serial data types and routines through common aliases.

use fortuno_serial, only: test_case_t => serial_case_base
use fortuno_serial, only: test_item_t => test_item
use fortuno_serial, only: test_list_t => test_list
Comment thread
abhaasgoyal marked this conversation as resolved.

use fortuno_serial, only: execute_cmd_app => execute_serial_cmd_app
use fortuno_serial, only: test_suite => serial_suite_item
use fortuno_serial, only: test_case => serial_case_item

use fortuno_serial, only: check => serial_check
use fortuno_serial, only: check_failed => serial_check_failed
use fortuno_serial, only: skip => serial_skip
use fortuno_serial, only: is_equal
use fortuno_serial, only: all_equal
use fortuno_serial, only: all_close

implicit none

! Scope is deliberately public

contains

function global_comm()
!! Serial stub for global_comm function.
use cable_mpi_stub_types_mod, only: MPI_COMM, MPI_COMM_NULL
type(MPI_COMM) global_comm
global_comm = MPI_COMM_NULL
end function

integer function num_ranks()
!! Serial stub for num_ranks function.
num_ranks = 1
end function

integer function this_rank()
!! Serial stub for this_rank function.
this_rank = 0
end function

end module fortuno_interface_mod
Loading