Skip to content

Add unit testing

Add unit testing #67

Workflow file for this run

# This is a CI workflow for the fv3atm project.
#
# This workflow builds and tests the fv3atm library using GCC, and it tests
# different CMake build options.
#
# Alex Richert, 6 Dec 2023
name: GCC
on:
push:
branches:
- develop
pull_request:
branches:
- develop
jobs:
GCC:
runs-on: ubuntu-latest
strategy:
matrix:
cmake_opts: ["-D32BIT=ON", "-D32BIT=OFF"]
gcc_ver: ["11"]
mpi: ["mpich"]
steps:
# Only do Doxygen and gcovr build for one job
- name: decide-doc-gcovr-build
run: |
if [[ "${{ matrix.cmake_opts }}" == "-D32BIT=ON" && "${{ matrix.gcc_ver }}" == 11 && "${{ matrix.mpi }}" == mpich ]]; then
echo 'devbuild=ON' | tee -a ${GITHUB_ENV}
echo 'gcov_cmake="-DCMAKE_Fortran_FLAGS=\"-fprofile-abs-path -fprofile-arcs -ftest-coverage -O0\""' | tee -a ${GITHUB_ENV}
else
echo 'devbuild=OFF' | tee -a ${GITHUB_ENV}
fi
- name: apt-install
run: |
sudo apt-get install gcovr doxygen graphviz
- name: checkout-fv3atm
uses: actions/checkout@v3
with:
path: ${{ github.workspace }}/fv3atm
submodules: recursive
- name: cache-spack
id: cache-spack
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/spack-develop
key: spack-${{ hashFiles('fv3atm/ci/spack.yaml') }}-gcc${{ matrix.gcc_ver }}-2-${{ matrix.cmake_opts }}-${{ matrix.mpich }}
# Building dependencies takes 40+ min
- name: spack-install
if: steps.cache-spack.outputs.cache-hit != 'true'
run: |
wget --no-verbose https://github.com/spack/spack/archive/refs/heads/develop.zip
unzip develop.zip -d ${GITHUB_WORKSPACE}/ &> unzip.out
. ${GITHUB_WORKSPACE}/spack-develop/share/spack/setup-env.sh
spack env create gcc${{ matrix.gcc_ver }} ${GITHUB_WORKSPACE}/fv3atm/ci/spack.yaml
spack env activate gcc${{ matrix.gcc_ver }}
spack compiler find | grep gcc@${{ matrix.gcc_ver }}
spack external find gmake cmake git git-lfs perl python ${{ matrix.mpi }}
spack config add "packages:all:require:['%gcc@${{ matrix.gcc_ver }}']"
spack config add "packages:mpi:require:'${{ matrix.mpi }}'"
spack concretize |& tee ${SPACK_ENV}/log.concretize
spack install -j2 --fail-fast
echo "spackrc=$?" >> ${GITHUB_ENV}
- name: cache-save
uses: actions/cache/save@v3
if: ${{ (env.spackrc) == 0 }}
with:
path: ${{ github.workspace }}/spack-develop
key: spack-${{ hashFiles('fv3atm/ci/spack.yaml') }}-gcc11-2
- name: build-fv3atm
run: |
. ${GITHUB_WORKSPACE}/spack-develop/share/spack/setup-env.sh
spack env activate gcc${{ matrix.gcc_ver }}
spack load $(spack find --format "{name}")
cd ${GITHUB_WORKSPACE}/fv3atm
git clone https://github.com/NOAA-EMC/CMakeModules
git clone --recurse-submodules https://github.com/NOAA-PSL/stochastic_physics stochastic_physics_repo
sed -i 's/doc /upp_doc /' upp/docs/CMakeLists.txt
mkdir ${GITHUB_WORKSPACE}/fv3atm/build
cd ${GITHUB_WORKSPACE}/fv3atm/build
cmake ${GITHUB_WORKSPACE}/fv3atm -DBUILD_TESTING=ON ${{ matrix.cmake_opts }} -DENABLE_DOCS=${{ env.devbuild }} ${{ env.gcov_cmake }}
make -j2
ls -l /home/runner/work/fv3atm/fv3atm/fv3atm/io
- name: run-tests
run: |
cd $GITHUB_WORKSPACE/fv3atm/build
ctest -j2 --output-on-failure --rerun-failed
- name: get-test-coverage
if: ${{ env.devbuild == 'ON' }}
run: |
f=${GITHUB_WORKSPACE}/fv3atm
cd $f/build
gcovr -r .. -v --html-details --exclude ${f}/tests --exclude $f/stochastic_physics_repo --exclude $f/build/ccpp --exclude $f/ccpp/physics --exclude $f/ccpp/framework --exclude $f/atmos_cubed_sphere --exclude CMakeFiles --print-summary -o test-coverage.html
- name: upload-test-coverage
uses: actions/upload-artifact@v4
if: ${{ env.devbuild == 'ON' }}
with:
name: test-coverage-fv3atm-${{ github.sha }}
path: |
${{ github.workspace }}/fv3atm/build/*.html
${{ github.workspace }}/fv3atm/build/*.css
- uses: actions/upload-artifact@v4
if: ${{ env.devbuild == 'ON' }}
with:
name: docs
path: |
${{ github.workspace }}/fv3atm/build/docs/html
- name: debug-artifacts
uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: ccpp_prebuild_logs
path: ${{ github.workspace }}/fv3atm/build/ccpp/ccpp_prebuild.*