Skip to content
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

Add unit tests #221

Merged
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
79 changes: 16 additions & 63 deletions .github/workflows/Intel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,84 +12,37 @@ on:
branches:
- develop

# Use custom shell with -l so .bash_profile is sourced which loads intel/oneapi/setvars.sh
# without having to do it in manually every step
defaults:
run:
shell: bash -leo pipefail {0}

jobs:
Intel:
runs-on: ubuntu-latest
strategy:
matrix:
compilers: ["CC=icc FC=ifort","CC=icx FC=ifx"]
compilers: ["oneapi", "classic"]

steps:

# See https://software.intel.com/content/www/us/en/develop/articles/oneapi-repo-instructions.html
- name: install-intel
run: |
cd /tmp
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
echo "deb https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list
sudo apt-get update
sudo apt-get install intel-oneapi-dev-utilities intel-oneapi-mpi-devel intel-oneapi-openmp intel-oneapi-compiler-fortran intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic
echo "source /opt/intel/oneapi/setvars.sh" >> ~/.bash_profile

- name: checkout-bacio
uses: actions/checkout@v3
- name: "Install Intel"
uses: NOAA-EMC/ci-install-intel-toolkit@develop
with:
repository: NOAA-EMC/NCEPLIBS-bacio
path: bacio
ref: v2.6.0

- name: build-bacio
run: |
cd bacio
mkdir build && cd build
${{ matrix.compilers }} cmake .. -DCMAKE_INSTALL_PREFIX=~/bacio
make -j2
make install
compiler-setup: ${{ matrix.compilers }}

- name: checkout-bufr
uses: actions/checkout@v3
- name: "Build dependencies"
uses: NOAA-EMC/ci-build-nceplibs@develop
with:
repository: NOAA-EMC/NCEPLIBS-bufr
path: bufr
ref: bufr_v12.0.0

- name: cache-bufr
id: cache-bufr
uses: actions/cache@v3
with:
path: ~/bufr
key: bufr-intel-${{ matrix.compilers }}-${{ runner.os }}-v12.0.0

- name: build-bufr
if: steps.cache-bufr.outputs.cache-hit != 'true'
run: |
cd bufr
mkdir build && cd build
${{ matrix.compilers }} cmake -DCMAKE_INSTALL_PREFIX=~/bufr ..
make -j2
make install
bacio-version: v2.6.0
bufr-version: bufr_v12.0.0
key-prefix: Intel-

- name: checkout
uses: actions/checkout@v3
- name: "Checkout modified code"
uses: actions/checkout@v4
with:
path: w3emc

- name: build
- name: "Build w3emc"
run: |
cd w3emc
mkdir build && cd build
${{ matrix.compilers }} cmake -DCMAKE_PREFIX_PATH="~/bacio;~/bufr" ..
make -j2
cmake -DCMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-bacio;$GITHUB_WORKSPACE/nceplibs/NCEPLIBS-bufr" -B w3emc/build -S w3emc
cmake --build w3emc/build --parallel 2 --verbose

- name: test-w3emc
- name: "Test w3emc"
run: |
cd w3emc/build
ctest --output-on-failure --rerun-failed --verbose
ctest --test-dir w3emc/build --output-on-failure --rerun-failed --verbose
25 changes: 23 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# This is the CMake build file for the test directory of NCEPLIBS-w3emc.

# Kyle Gerheiser, Ed Hartnett
# Kyle Gerheiser, Ed Hartnett, Alex Richert

execute_process(COMMAND cmake -E create_symlink
"${CMAKE_CURRENT_SOURCE_DIR}/data"
"${CMAKE_CURRENT_BINARY_DIR}/data"
)

# This function builds, links, and runs a test program.
function(create_test name kind)
add_executable(${name}_${kind} ${name}.F90)
target_link_libraries(${name}_${kind} PRIVATE w3emc_${kind})
Expand All @@ -13,6 +17,16 @@ function(create_test name kind)
target_compile_definitions(${name}_${kind} PUBLIC -DKIND_${kind})
endfunction()

function(create_test_sh name kind)
add_executable(${name}_${kind} ${name}.F90)
target_link_libraries(${name}_${kind} PRIVATE w3emc_${kind})
set_target_properties(${name}_${kind} PROPERTIES COMPILE_FLAGS "${fortran_${kind}_flags}")
set_target_properties(${name}_${kind} PROPERTIES Fortran_MODULE_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/include_${kind})
target_compile_definitions(${name}_${kind} PUBLIC -DKIND_${kind})
add_test(NAME ${name}_${kind} COMMAND ${CMAKE_SOURCE_DIR}/tests/${name}.sh ${kind})
endfunction()

# These are the tests.
foreach(kind ${kinds})
create_test(test_summary ${kind})
Expand All @@ -22,4 +36,11 @@ foreach(kind ${kinds})
# create_test(test_w3fi72 ${kind})
create_test(test_w3fi73 ${kind})
create_test(test_w3fi74 ${kind})
create_test(test_aea ${kind})
create_test(test_fparsei ${kind})
create_test(test_fparser ${kind})
create_test(test_gbyte ${kind})
create_test(test_getgbemh ${kind})
create_test_sh(test_errexit ${kind})
create_test_sh(test_errmsg ${kind})
endforeach()
Binary file added tests/data/baseline/aea
Binary file not shown.
Binary file added tests/data/baseline/getgbemh
Binary file not shown.
Binary file not shown.
22 changes: 22 additions & 0 deletions tests/test_aea.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
program test_aea
integer, parameter :: nchar=4
character*1 :: ia(nchar), ie(nchar), ie_ref(nchar)
integer nc
nc = -nchar
ia(1) = 'a'
ia(2) = 'A'
ia(3) = 'b'
ia(4) = 'B'
call aea(ia, ie, nc)
!! Uncomment to regenerate baseline data:
! open(12, file='data/baseline/aea',access='direct',recl=nchar)
! write(12, rec=1) ie
! close(12)
open(11, file='data/baseline/aea', access='direct',recl=nchar)
read(11, rec=1) ie_ref
close(11)
if (any(ie.ne.ie_ref)) stop 1
nc = nchar
call aea(ia, ie, nc)
if (ia(1).ne.'a' .or. ia(2).ne.'A' .or. ia(3).ne.'b' .or. ia(4).ne.'B') stop 2
end program
7 changes: 7 additions & 0 deletions tests/test_errexit.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
program test_errexit
character(len=1) :: iret_char
integer :: iret
call get_command_argument(1, iret_char)
read(iret_char, '(i2)') iret
call errexit(iret)
end program
9 changes: 9 additions & 0 deletions tests/test_errexit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

for i in 0 1; do
./test_errexit_${1:-"Must specify 4/d/8"} $i
if [ $? -ne $i ]; then
echo "Failure: $? != $i"
exit $i
fi
done
3 changes: 3 additions & 0 deletions tests/test_errmsg.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
program test_errmsg
call errmsg("This is an error message.")
end program
3 changes: 3 additions & 0 deletions tests/test_errmsg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

./test_errmsg_${1:-"Must specify 4/d/8"} 2>&1 | grep "This is an error message."
12 changes: 12 additions & 0 deletions tests/test_fparsei.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
program test_fparsei
implicit none
character(25) :: carg
integer :: marg
integer :: karg(4)

karg = -999
carg = '8675309,1234567 098 1234'
marg = 3
call fparsei(carg, marg, karg)
if (any(karg .ne. (/8675309,1234567,98,-999/))) stop 1
end program
13 changes: 13 additions & 0 deletions tests/test_fparser.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
program test_fparser
implicit none
character(25) :: carg
integer :: marg
real :: rarg(4)
real, parameter :: tinyreal=tiny(1.0)

rarg = -999.9
carg = '867530.9,123456.7 09.8 123.4'
marg = 3
call fparser(carg, marg, rarg)
if (any((rarg-(/867530.9,123456.7,9.8,-999.9/)).gt.tinyreal)) stop 1
end program
29 changes: 29 additions & 0 deletions tests/test_gbyte.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
program test_gbyte
implicit none
integer*4 :: iunpkd, ipackd
real*4 :: rpackd
character*4 :: kpackd

equivalence(ipackd, rpackd, kpackd)

call gbyte(99, iunpkd, 0, 1)
if (iunpkd.ne.0) stop 10

call gbyte(-99, iunpkd, 0, 1)
if (iunpkd.ne.1) stop 12
call gbyte(-99, iunpkd, 0, 32)
if (iunpkd.ne.-99) stop 13

rpackd = 999.9
call gbyte(rpackd, iunpkd, 0, 1)
if (iunpkd.ne.0) stop 20

rpackd = -999.9
call gbyte(rpackd, iunpkd, 0, 1)
if (iunpkd.ne.1) stop 21

kpackd = 'abc'
call gbyte(kpackd, iunpkd, 0, 32)
if (iunpkd.ne.543384161) stop 30

end program
43 changes: 43 additions & 0 deletions tests/test_getgbemh.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
! This program tests getgbemh().
program test_getgbemh
implicit none
character*256 cg1
integer karg(100)
integer jpds1(200)
data jpds1/200*-1/

integer, parameter :: mbuf=256*1024
character cbuf1(mbuf), cbuf_ref(mbuf)
integer jgds(200),jens(5)
integer kpds1(200),kgds1(200),kens1(5)
integer lcg1,iarg,iret,iretba,k1,kr1,kr1x
integer lg1,lx1,m1,mb,mnum1,nlen1,nnum1

cg1='data/input/ref_gdaswave.t00z.wcoast.0p16.f000.grib1'
lcg1=len_trim(cg1)
iarg=iarg+1
lg1=11
call baopenr(lg1,cg1(1:lcg1),iretba)
lx1=0

! READ GRIB HEADERS
mb=1
kr1=-1
jgds=-1
jens=-1
kpds1=0
kgds1=0
kens1=0
call getgbemh(lg1,lx1,kr1,jpds1,jgds,jens, &
mbuf,cbuf1,nlen1,nnum1,mnum1, &
k1,m1,kr1x,kpds1,kgds1,kens1,iret)
!! Uncomment to regenerate baseline data:
! open(51, file='getgbemh', form='unformatted')
! write(51) cbuf1
if(iret.ne.0) stop 1
if(m1.le.0) stop 2
open(11, file='data/baseline/getgbemh', form='unformatted')
read(11) cbuf_ref
if(any(cbuf1.ne.cbuf_ref)) stop 3

end program test_getgbemh
Loading