Files
IFEM/Apps/Common/scripts/regtest.sh.in
Arne Morten Kvarving c859e4231c fixed: use a separate valgrind log for tests with IFEM_USE_MEMCHECK
to allow parallel execution
2021-09-14 08:19:12 +02:00

137 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
# This script performs a single regression.
# It is used by the 'make test' target in the buildsystems
# Usually you should use 'make test' rather than calling this script directly
#
# Parameters: -a = Application binary
# -r = Regression test file
# Optional parameters:
# -v = Valgrind binary
# -m = Number of MPI nodes
# -s = Restart step
# A regression test file is of the format:
# parameters to application
# blank line
# output from program to compare to
function atomic_log {
(
flock -x 200
echo "$1" >> @CMAKE_BINARY_DIR@/failed.log
) 200>/var/lock/ifemloglock
}
function atomic_log_file {
(
flock -x 200
cat $1 >> @CMAKE_BINARY_DIR@/failed.log
) 200>/var/lock/ifemloglock
}
OPTIND=1
while getopts "a:r:m:v:s:" OPT
do
case "${OPT}" in
a) MYSIM=${OPTARG} ;;
r) REG_FILE=${OPTARG} ;;
m) MPI_NODES=${OPTARG} ;;
v) VALGRIND=${OPTARG} ;;
s) RSTEP=${OPTARG};;
esac
done
if test -z ${MYSIM} || test -z ${REG_FILE}
then
echo "Need simulator and regression file"
exit 1
fi
cd `dirname ${REG_FILE}`
MAPFILE=`head -n1 ${REG_FILE}`
test $? -eq 0 || exit 1
hdf5=""
tmplog=`mktemp -t ifemlogXXXXXX`
faillog=`mktemp -t ifemfailXXXXXX`
if test -n "${RSTEP}"
then
REG_NAME=`head -n1 $REG_FILE | awk -F '.xinp' '{print $1}'`
if grep -q "../" <<< $REG_NAME
then
REG_NAME=`echo $REG_NAME | awk -F '../' '{print $2}'`
fi
h5file=`mktemp -t ${REG_NAME}_XXXXXX`
hdf5="-hdf5 ${h5file}"
fi
if test -n "${VALGRIND}"
then
vallog=`mktemp -t ifemvallogXXXXXX`
MYSIM="${VALGRIND} --log-file=${vallog} ${MYSIM}"
fi
test -n "${MPI_NODES}" && MYSIM="mpirun -n ${MPI_NODES} ${MYSIM}"
${MYSIM} ${hdf5} ${MAPFILE} 2>&1 | tee ${tmplog}
retcode=$?
if test ${retcode} -ne 0
then
atomic_log "Application returned error code: $retcode"
echo Application returned error code: $retcode >> /dev/stderr
exit 1
fi
if test -n "${RSTEP}"
then
MAPFILE=`echo ${MAPFILE} | sed 's/ -restartInc [1-9][0-9]*//'`
${MYSIM} ${MAPFILE} -restart ${h5file}_restart.hdf5 ${RSTEP} 2>&1 | tee $tmplog
rm -f ${h5file}.hdf5
rm -f ${h5file}_restart.hdf5
fi
appres=$?
globres=1
IFS=$'\n'
echo $REG_FILE
for line in `cat $REG_FILE`
do
test -z "$line" && continue
echo "$line" | grep -q ".inp" && continue
result=0
if grep -q "$line" $tmplog
then result=1
fi
if test $result -eq 0
then
if test $globres -eq 1
then
echo "-------- ${REG_FILE} --------" > $faillog
fi
globres=0
echo "Failed to find output: $line" >> $faillog
echo Failed to find output: $line >> /dev/stderr
fi
done
cat $tmplog >> $faillog
if test -n "$VALGRIND"
then
if ! grep -q "ERROR SUMMARY: 0 errors" $vallog
then
cat $vallog >> $faillog
appres=1
fi
rm -f $vallog
fi
if test $globres -eq 0 || test $appres -ne 0
then
atomic_log_file $faillog
rm -f $tmplog
rm -f $faillog
exit 1
fi
rm -f $tmplog
rm -f $faillog
exit 0