-
Notifications
You must be signed in to change notification settings - Fork 16
Initial pFUnit Integration #326
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
Merged
mwaxmonsky
merged 52 commits into
ESCOMP:development
from
mwaxmonsky:feature/pfunit-integration
Feb 11, 2025
Merged
Changes from 50 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
65251c3
Initial unit test integration.
mwaxmonsky 70f89a3
Changing workflow name.
mwaxmonsky 5be4565
Changing action order.
mwaxmonsky aabf503
Fixing workflow file name.
mwaxmonsky 3b00619
Updating pfunit path.
mwaxmonsky caffef0
Adding code coverage and test results artifact uploads.
mwaxmonsky 235e10a
Adding test to source list and fixing compile errors.
mwaxmonsky 1dfc844
Add additional demo tests.
mwaxmonsky 275445c
Adding workflow dispatch to python tests.
mwaxmonsky b5252cd
Removing debug printing from workflow.
mwaxmonsky 698b3bc
Adding warning about top level builds not supported.
mwaxmonsky a62cb23
Fixing whitespace.
mwaxmonsky 4125fca
Updating fortran test paths from unit-fortran to unit_fortran.
mwaxmonsky 24ddbfb
Move python tests to unit_python.
mwaxmonsky b600560
Merge branch 'development' into feature/pfunit-integration
mwaxmonsky fbd77ac
Moving fortran tests from unit_fortran to unit/fortran
mwaxmonsky c30bdf1
Moving python tests from unit_python to unit/python
mwaxmonsky d3d0d9d
Fixing build path.
mwaxmonsky c28c89f
Adding workflow_dispatch to if check for python unit tests.
mwaxmonsky 2f9b484
Fixing python test path.
mwaxmonsky ff36e21
Fixing path to root of repository.
mwaxmonsky cd5b5e4
More python unit test path fixes.
mwaxmonsky 4201e18
One more path fix.
mwaxmonsky 58a8d2d
One more path fix.
mwaxmonsky d090ff3
One more path fix.
mwaxmonsky 5c08bd8
Fixing tmp file path.
mwaxmonsky 0fdebc8
Fixing tmp file path.
mwaxmonsky d882fb7
Adding top level comment to core lib cmake.
mwaxmonsky c5fe6cd
Renaming python test script.
mwaxmonsky f59b7d0
Adding missing newlines.
mwaxmonsky 0fba9fd
Merge branch 'development' into feature/pfunit-integration
mwaxmonsky 5d01c2e
Updating compile flags for unit test and adding stringify unit tests.
mwaxmonsky b3e5da0
Fix incorrect 64-bit value assignment. Remove string test from GNU r…
mwaxmonsky f522b4b
Add missing reference to core library.
mwaxmonsky bdfe560
Minor code cleanup.
mwaxmonsky 80f301f
Cleaning up and adding ifx support to cmake.
mwaxmonsky 702178e
Adding multiple gnu compiler tests.
mwaxmonsky 1d67d77
Attempt to fix workflow.
mwaxmonsky 0f29932
get list of installed gfortran compilers.
mwaxmonsky 5912455
Fixing list of compiler versions.
mwaxmonsky 297985b
Debugging line length compile error.
mwaxmonsky 9b4df84
Fixing line length compiler error.
mwaxmonsky aa01137
Removing verbose output.
mwaxmonsky ab5d34d
Fixing artifact name conflict.
mwaxmonsky eda0f52
Fix gcovr to call correct gcov version.
mwaxmonsky a0ec7a8
Removing unused variables and un-needed comment strings.
mwaxmonsky ba4f9e9
Merge branch 'development' into feature/pfunit-integration
mwaxmonsky 2c31ebd
Updating from review feedback.
mwaxmonsky b89f2ad
Updating comment with compiler version information.
mwaxmonsky 1629ad2
Merge branch 'development' into feature/pfunit-integration
mwaxmonsky 231073a
Adding missing newlines at end of new files.
mwaxmonsky 50a76fd
Merge branch 'development' into feature/pfunit-integration
mwaxmonsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,73 @@ | ||
name: Fortran Unit Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- development | ||
- main | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
gcc-toolchain: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
version: [12, 13, 14] | ||
env: | ||
CC: gcc-${{ matrix.version }} | ||
CXX: g++-${{ matrix.version }} | ||
FC: gfortran-${{ matrix.version }} | ||
steps: | ||
- name: Checkout cam-sima | ||
uses: actions/checkout@v4 | ||
|
||
- 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 cam-sima | ||
run: | | ||
cmake \ | ||
-DCMAKE_PREFIX_PATH=/home/runner/work/CAM-SIMA/CAM-SIMA/pFUnit/build/installed \ | ||
-DCAM_SIMA_ENABLE_CODE_COVERAGE=ON \ | ||
-B./build \ | ||
-S./test/unit/fortran | ||
cd build | ||
make | ||
|
||
- name: Run fortran unit 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-${{ env.FC }} | ||
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 --gcov-executable gcov-${{ matrix.version }} -r .. --filter '\.\./src' --html cam_sima_code_coverage.html --txt | ||
|
||
- name: Upload code coverage results | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: code-coverage-results-${{ env.FC }} | ||
path: build/cam_sima_code_coverage.html |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,8 @@ | ||
set(CORE_UTILS_SRC string_core_utils.F90) | ||
nusbaume marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# core_utils 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. | ||
add_library(core_utils ${CORE_UTILS_SRC}) | ||
target_include_directories(core_utils PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) |
This file contains hidden or 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,162 @@ | ||
module string_core_utils | ||
|
||
implicit none | ||
private | ||
|
||
public :: core_to_str ! Convert integer to left justified string | ||
public :: core_int_date_to_yyyymmdd ! Convert encoded date integer to "yyyy-mm-dd" format | ||
public :: core_int_seconds_to_hhmmss ! Convert integer seconds past midnight to "hh:mm:ss" format | ||
public :: core_stringify ! Convert one or more values of any intrinsic data types to a character string for pretty printing | ||
|
||
CONTAINS | ||
|
||
character(len=10) pure function core_to_str(n) | ||
! return default integer as a left justified string | ||
|
||
integer, intent(in) :: n | ||
|
||
write(core_to_str,'(i0)') n | ||
|
||
end function core_to_str | ||
|
||
character(len=10) pure function core_int_date_to_yyyymmdd (date) | ||
! Undefined behavior if date <= 0 | ||
|
||
! Input arguments | ||
integer, intent(in) :: date | ||
|
||
! Local variables | ||
integer :: year ! year of yyyy-mm-dd | ||
integer :: month ! month of yyyy-mm-dd | ||
integer :: day ! day of yyyy-mm-dd | ||
|
||
year = date / 10000 | ||
month = (date - year*10000) / 100 | ||
day = date - year*10000 - month*100 | ||
|
||
write(core_int_date_to_yyyymmdd, '(i4.4,A,i2.2,A,i2.2)') & | ||
year,'-',month,'-',day | ||
|
||
end function core_int_date_to_yyyymmdd | ||
|
||
character(len=8) pure function core_int_seconds_to_hhmmss (seconds) | ||
! Undefined behavior if seconds outside [0, 86400] | ||
|
||
! Input arguments | ||
integer, intent(in) :: seconds | ||
|
||
! Local variables | ||
integer :: hours ! hours of hh:mm:ss | ||
integer :: minutes ! minutes of hh:mm:ss | ||
integer :: secs ! seconds of hh:mm:ss | ||
|
||
hours = seconds / 3600 | ||
minutes = (seconds - hours*3600) / 60 | ||
secs = (seconds - hours*3600 - minutes*60) | ||
|
||
write(core_int_seconds_to_hhmmss,'(i2.2,A,i2.2,A,i2.2)') & | ||
hours,':',minutes,':',secs | ||
|
||
end function core_int_seconds_to_hhmmss | ||
|
||
!> Convert one or more values of any intrinsic data types to a character string for pretty printing. | ||
!> If `value` contains more than one element, the elements will be stringified, delimited by `separator`, then concatenated. | ||
!> If `value` contains exactly one element, the element will be stringified without using `separator`. | ||
!> If `value` contains zero element or is of unsupported data types, an empty character string is produced. | ||
!> If `separator` is not supplied, it defaults to `, ` (i.e., a comma and a space). | ||
!> (KCW, 2024-02-04) | ||
pure function core_stringify(value, separator) | ||
use, intrinsic :: iso_fortran_env, only: int32, int64, real32, real64 | ||
|
||
class(*), intent(in) :: value(:) | ||
character(*), optional, intent(in) :: separator | ||
character(:), allocatable :: core_stringify | ||
|
||
integer, parameter :: sizelimit = 1024 | ||
|
||
character(:), allocatable :: buffer, delimiter, format | ||
integer :: i, n, offset | ||
|
||
if (present(separator)) then | ||
delimiter = separator | ||
else | ||
delimiter = ', ' | ||
end if | ||
|
||
n = min(size(value), sizelimit) | ||
|
||
if (n == 0) then | ||
core_stringify = '' | ||
return | ||
end if | ||
|
||
select type (value) | ||
type is (character(*)) | ||
allocate(character(len(value) * n + len(delimiter) * (n - 1)) :: buffer) | ||
|
||
buffer(:) = '' | ||
offset = 0 | ||
|
||
do i = 1, n | ||
if (len(delimiter) > 0 .and. i > 1) then | ||
buffer(offset + 1:offset + len(delimiter)) = delimiter | ||
offset = offset + len(delimiter) | ||
end if | ||
|
||
if (len_trim(adjustl(value(i))) > 0) then | ||
buffer(offset + 1:offset + len_trim(adjustl(value(i)))) = trim(adjustl(value(i))) | ||
offset = offset + len_trim(adjustl(value(i))) | ||
end if | ||
end do | ||
type is (integer(int32)) | ||
allocate(character(11 * n + len(delimiter) * (n - 1)) :: buffer) | ||
allocate(character(17 + len(delimiter) + floor(log10(real(n))) + 1) :: format) | ||
|
||
write(format, '(a, i0, 3a)') '(ss, ', n, '(i0, :, "', delimiter, '"))' | ||
write(buffer, format) value | ||
type is (integer(int64)) | ||
allocate(character(20 * n + len(delimiter) * (n - 1)) :: buffer) | ||
allocate(character(17 + len(delimiter) + floor(log10(real(n))) + 1) :: format) | ||
|
||
write(format, '(a, i0, 3a)') '(ss, ', n, '(i0, :, "', delimiter, '"))' | ||
write(buffer, format) value | ||
type is (logical) | ||
allocate(character(1 * n + len(delimiter) * (n - 1)) :: buffer) | ||
allocate(character(13 + len(delimiter) + floor(log10(real(n))) + 1) :: format) | ||
|
||
write(format, '(a, i0, 3a)') '(', n, '(l1, :, "', delimiter, '"))' | ||
write(buffer, format) value | ||
type is (real(real32)) | ||
allocate(character(13 * n + len(delimiter) * (n - 1)) :: buffer) | ||
|
||
if (maxval(abs(value)) < 1.0e5_real32) then | ||
allocate(character(20 + len(delimiter) + floor(log10(real(n))) + 1) :: format) | ||
write(format, '(a, i0, 3a)') '(ss, ', n, '(f13.6, :, "', delimiter, '"))' | ||
else | ||
allocate(character(23 + len(delimiter) + floor(log10(real(n))) + 1) :: format) | ||
write(format, '(a, i0, 3a)') '(ss, ', n, '(es13.6e2, :, "', delimiter, '"))' | ||
end if | ||
|
||
write(buffer, format) value | ||
type is (real(real64)) | ||
allocate(character(13 * n + len(delimiter) * (n - 1)) :: buffer) | ||
|
||
if (maxval(abs(value)) < 1.0e5_real64) then | ||
allocate(character(20 + len(delimiter) + floor(log10(real(n))) + 1) :: format) | ||
write(format, '(a, i0, 3a)') '(ss, ', n, '(f13.6, :, "', delimiter, '"))' | ||
else | ||
allocate(character(23 + len(delimiter) + floor(log10(real(n))) + 1) :: format) | ||
write(format, '(a, i0, 3a)') '(ss, ', n, '(es13.6e2, :, "', delimiter, '"))' | ||
end if | ||
|
||
write(buffer, format) value | ||
class default | ||
core_stringify = '' | ||
return | ||
end select | ||
|
||
core_stringify = trim(buffer) | ||
|
||
end function core_stringify | ||
|
||
end module string_core_utils |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.