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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my enrichment, what does this syntax do?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$$ is a process ID (PID) used to create a unique output filename each time the script is run so the previous output is saved.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @JulieSchramm!

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
#-----------------------------------------------------------------------
Comment thread
JulieSchramm marked this conversation as resolved.
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious why a subdirectory is needed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the top-level CMakeLists.txt file, the install directory is set as bin under what -DCMAKE_INSTALL_PREFIX is set to. To make multiple builds and save all the executables for testing, I set -DCMAKE_INSTALL_PREFIX=../bin_${compiler}, which creates ../bin_intel/bin, ../bin_gnu/bin, etc.

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}