forked from ESCOMP/atmospheric_physics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial inunit test and coverage frastructure setup.
- Loading branch information
1 parent
e95c172
commit dbdab4d
Showing
6 changed files
with
161 additions
and
0 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
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 | ||
|
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,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() |
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,11 @@ | ||
module ccpp_kinds | ||
|
||
use ISO_FORTRAN_ENV, only: kind_phys => REAL64 | ||
|
||
implicit none | ||
private | ||
|
||
public :: kind_phys | ||
|
||
end module ccpp_kinds | ||
|
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 @@ | ||
add_subdirectory(utilities-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
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
27
test/unit-test/tests/utilities-tests/test_state_converters.pf
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,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 |