Skip to content

Commit

Permalink
Feature/add build test (#156)
Browse files Browse the repository at this point in the history
* Add test/build.sh to build all executables for supported compilers on platforms Cheyenne, Hera and Jet.
Add test/README.md file for usage.
All builds succeed on Cheyenne.

* Address Gerard's and Christina's comments:

- Remove -l from top of script
- Use ${BIN_DIR} for cmake command
- Use $() for easier debugging

* Use the devbuild.sh script for the build tests.

* Fix typo
Remove irrelevent comment block
  • Loading branch information
JulieSchramm committed Aug 11, 2021
1 parent 3e50d4e commit 8c2e016
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Build test for the UFS Short-Range Weather App

## Description

This script builds the executables for the UFS Short-Range Weather Application (SRW App)
for the current code in the users ufs-srweather-app directory. It consists of the following steps:

* Build all of the executables for the supported compilers on the given machine

* Check for the existence of all executables

* Print out a PASS/FAIL message

Currently, the following configurations are supported:

Machine | Cheyenne | Hera | Jet |
------------| ---------------|----------------|----------------|
Compiler(s) | Intel, GNU | Intel | Intel |

The CMake build is done in the ``build_${compiler}`` directory.
The executables for each build are installed under the ``bin_${compiler}`` directory.

NOTE: To run the regional workflow using these executables, the ``EXECDIR`` variable in the
``${SR_WX_APP_TOP_DIR}/regional_workflow/ush/setup.sh`` file must be set to the
appropiate directory, for example: ``EXECDIR="${SR_WX_APP_TOP_DIR}/bin_intel/bin"``,
where ``${SR_WX_APP_TOP_DIR}`` is the top-level directory of the cloned ufs-srweather-app repository.

## Usage

To run the tests, specify the machine name on the command line, for example:

On cheyenne:

```
cd test
./build.sh cheyenne >& build.out &
```

Check the ``${SR_WX_APP_TOP_DIR}/test/build_test$PID.out`` file for PASS/FAIL.
134 changes: 134 additions & 0 deletions test/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/bin/bash
#=======================================================================
# Description: This script runs a build test for the
# UFS Short-Range Weather App. The executables
# built are listed below in $executables_created.
# A pass/fail message is printed at the end of the output.
#
# Necessary input parameters: machine name (jet hera or cheyenne)
#
# Usage: see function usage below
#
# Examples: ./build.sh $machine >& test.out &
#
set -eux # Uncomment for debugging
#=======================================================================

fail() { echo -e "\n$1\n" >> ${TEST_OUTPUT} && exit 1; }

function usage() {
echo
echo "Usage: $0 machine | -h"
echo
echo " machine [required] is one of: ${machines[@]}"
echo " -h display this help"
echo
exit 1
}

machines=( hera jet cheyenne )

[[ $# -eq 0 ]] && usage
if [ "$1" = "-h" ] ; then usage ; fi

export machine=${1}
machine=$(echo "${machine}" | tr '[A-Z]' '[a-z]') # scripts in sorc need lower case machine name

#-----------------------------------------------------------------------
# Check that machine is valid
#-----------------------------------------------------------------------
if [[ "${machines[@]}" =~ "$machine" ]]; then
echo "machine ${machine} is valid"
else
echo "ERROR: machine ${machine} is NOT valid"
exit 1
fi

#-----------------------------------------------------------------------
# Set compilers to be tested depending on machine
#-----------------------------------------------------------------------
if [ "${machine}" == "cheyenne" ] ; then
compilers=( intel gnu )
else
compilers=( intel )
fi

#-----------------------------------------------------------------------
# Set some directories
#-----------------------------------------------------------------------
PID=$$
TEST_DIR=$( pwd ) # Directory with this script
TOP_DIR=${TEST_DIR}/.. # Top level (umbrella repo) directory
TEST_OUTPUT=${TEST_DIR}/build_test${PID}.out

build_it=0 # Set to 1 to skip build (for testing pass/fail criteria)
#-----------------------------------------------------------------------
# Create the output file if it doesn't exist
#-----------------------------------------------------------------------
if [ ! -f "$TEST_OUTPUT" ]; then
touch ${TEST_OUTPUT}
fi

cd ${TOP_DIR}

ENV_DIR=${TOP_DIR}/env
#-----------------------------------------------------------------------
# Array of all executables built
#-----------------------------------------------------------------------
declare -a executables_created=( chgres_cube \
emcsfc_ice_blend \
emcsfc_snow2mdl \
filter_topo \
fregrid \
fvcom_to_FV3 \
global_cycle \
global_equiv_resol \
make_hgrid \
make_solo_mosaic \
ncep_post \
orog \
orog_gsl \
regional_esg_grid \
sfc_climo_gen \
shave \
ufs_model \
vcoord_gen )

#-----------------------------------------------------------------------
# Set up the build environment and run the build script.
#-----------------------------------------------------------------------
for compiler in "${compilers[@]}"; do
BUILD_DIR=${TOP_DIR}/build_${compiler}
BIN_DIR=${TOP_DIR}/bin_${compiler}
EXEC_DIR=${BIN_DIR}/bin
if [ $build_it -eq 0 ] ; then
./devbuild.sh ${machine} --compiler=${compiler} --build-dir=${BUILD_DIR} --install-dir=${BIN_DIR} \
--clean || fail "Build ${machine} ${compiler} FAILED"
fi # End of skip build for testing

#-----------------------------------------------------------------------
# check for existence of executables.
#-----------------------------------------------------------------------
n_fail=0
for file in "${executables_created[@]}" ; do
exec_file=${EXEC_DIR}/${file}
if [ -f ${exec_file} ]; then
echo "SUCCEED: ${compiler} executable file ${exec_file} exists" >> ${TEST_OUTPUT}
else
echo "FAIL: ${compiler} executable file ${exec_file} does NOT exist" >> ${TEST_OUTPUT}
let "n_fail=n_fail+1"
fi
done
done # End compiler loop
#-----------------------------------------------------------------------
# Set message for output
#-----------------------------------------------------------------------
msg="????"
if [[ $n_fail -gt 0 ]] ; then
echo "BUILD(S) FAILED" >> ${TEST_OUTPUT}
msg="FAIL"
else
echo "ALL BUILDS SUCCEEDED" >> ${TEST_OUTPUT}
msg="PASS"
fi
echo "$msg" >> ${TEST_OUTPUT}

0 comments on commit 8c2e016

Please sign in to comment.