Skip to content

Commit

Permalink
Initial inunit test and coverage frastructure setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaxmonsky committed Oct 24, 2024
1 parent e95c172 commit dbdab4d
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 0 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/code-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: code-coverage

on:
push:
branch: development
workflow_dispatch:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

jobs:
gcc:
runs-on: ubuntu-latest
steps:
- name: Checkout atmospheric_physics
uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt update && sudo apt -y install libopenmpi-dev openmpi-bin
- name: Build pFUnit
run: |
git clone --depth 1 --branch v4.10.0 https://github.com/Goddard-Fortran-Ecosystem/pFUnit.git
cd pFUnit
cmake -B./build -S.
cd build
make install
- name: Build ccpp-framework
run: |
git clone --depth 1 --branch develop https://github.com/NCAR/ccpp-framework.git
cd ccpp-framework
- name: Build atmospheric_physics
run: |
cmake \
-DCMAKE_PREFIX_PATH=/home/runner/work/atmospheric_physics/atmospheric_physics/pFUnit/build/installed \
-DHISTORY_ENABLE_CODE_COVERAGE=ON \
-B./build \
-S.
cd build
make
- name: Run tests
run: |
cd build && ctest -V --output-on-failure --output-junit test_results.xml
- name: Upload unit test results
uses: actions/upload-artifact@v4
with:
name: unit-test-results
path: build/test_results.xml

- name: Setup GCov
run: |
python3 -m venv venv
source venv/bin/activate
pip3 install gcovr
- name: Run Gcov
run: |
source venv/bin/activate
cd build
gcovr -r .. --filter '\.\./src' --html atmospheric_physics_code_coverage.html --txt
- name: Upload code coverage results
uses: actions/upload-artifact@v4
with:
name: code-coverage-results
path: build/atmospheric_physics_code_coverage.html

42 changes: 42 additions & 0 deletions test/unit-test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.17)

project(atmospheric_physics VERSION 0.0.1 LANGUAGES Fortran)

find_package(PFUNIT REQUIRED)

set(CMAKE_Fortran_FLAGS "-O0 --coverage")
if(NOT ATMOSPHERIC_PHYSICS_IS_TOP_LEVEL)
message(WARNING "atmospheric-physics is not integrated into the CMake build of any top level "
"project yet and this CMake is for testing purposes only. "
"Making a change to this project's CMake will not impact the build of "
"a parent project at this time.")
endif()

option(ATMOSPHERIC_PHYSICS_ENABLE_TESTS "Run pFUnit unit tests" OFF)
option(ATMOSPHERIC_PHYSICS_ENABLE_CODE_COVERAGE "Run code coverage tool" OFF)

if(ATMOSPHERIC_PHYSICS_ENABLE_CODE_COVERAGE)
add_compile_options(-O0 --coverage)
add_link_options(-lgcov)
endif()

set(CMAKE_BUILD_TYPE Debug)

# add_subdirectory(include)
# add_subdirectory(../../schemes/utilities utilities)

set(UTILITIES_SRC
../../schemes/utilities/state_converters.F90
../../schemes/utilities/static_energy.F90
../../schemes/utilities/physics_tendency_updaters.F90
include/ccpp_kinds.F90
)

add_library(utilities ${UTILITIES_SRC})
target_compile_options(utilities PRIVATE -ffree-line-length-none)
target_include_directories(utilities PUBLIC ${CMAKE_CURRENT_BINARY_DIR})

if(ATMOSPHERIC_PHYSICS_ENABLE_TESTS OR ATMOSPHERIC_PHYSICS_ENABLE_CODE_COVERAGE)
enable_testing()
add_subdirectory(tests)
endif()
11 changes: 11 additions & 0 deletions test/unit-test/include/ccpp_kinds.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module ccpp_kinds

use ISO_FORTRAN_ENV, only: kind_phys => REAL64

implicit none
private

public :: kind_phys

end module ccpp_kinds

1 change: 1 addition & 0 deletions test/unit-test/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(utilities-tests)
4 changes: 4 additions & 0 deletions test/unit-test/tests/utilities-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_pfunit_ctest(utilities_tests
TEST_SOURCES test_state_converters.pf
LINK_LIBRARIES utilities
)
27 changes: 27 additions & 0 deletions test/unit-test/tests/utilities-tests/test_state_converters.pf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@test
subroutine test_temp_to_potential_temp()
use funit
use state_converters, only : temp_to_potential_temp_run
use ccpp_kinds, only: kind_phys

integer, parameter :: ncol = 5
integer, parameter :: nz = 5

real(kind_phys) :: temp(ncol, nz)
real(kind_phys) :: exner(ncol, nz)
real(kind_phys) :: theta(ncol, nz)
character(len=512) :: errmsg
integer :: errflg

temp = 1
exner = 1
theta = 1

errmsg = ""
errflg = 0

call temp_to_potential_temp_run(ncol, nz, temp, exner, theta, errmsg, errflg)

@assertEqual(0, errflg)

end subroutine test_temp_to_potential_temp

0 comments on commit dbdab4d

Please sign in to comment.