Files
mfem/tests/scripts/runtest
T

114 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at the
# Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights reserved.
# See file COPYRIGHT for details.
#
# This file is part of the MFEM library. For more information and source code
# availability see http://mfem.org.
#
# MFEM is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License (as published by the Free
# Software Foundation) version 2.1 dated February 1999.
# Set the test and run directories
run_dir=`pwd`
test_dir=$( cd "$( dirname "$0" )" && pwd )
# Print usage information
case $1 in
-h|-help)
cat <<EOF
$0 [-h|-help] {mfem_dir} {test1} {test2} ...
where: {mfem_dir} is the MFEM source directory [default value: ../..]
{test1}... are the sequence of tests to run
-h|-help prints this usage information and exits
This script runs a sequence of tests using the code in mfem_dir (note that
specifying the directory is optional). For each test, the standard output and
standard error are saved in files test.out and test.err respectively in the
current directory [1]. The output file interleaves stdout and stderr, while
the error file is filtered by removing test-specific patterns specified in an
optional test.filters file in the test directory [2]. After filtering, empty
error files are erased, signifying that the corresponding test has passed.
[1] run directory = $run_dir
[2] test directory = $test_dir
Example usage: $0 ../..
EOF
exit
;;
esac
# Setup
if [ -d "$1" ]; then
mfem_dir="$1"
shift
fi
if [ "$mfem_dir" = "" ]; then
mfem_dir="../.."
fi
if ! [ -d "$mfem_dir" ]; then
# Very unlikely
printf "\nDirectory not found: $mfem_dir\n\n" 1>&2
exit 1
fi
# Determine current machine based on $SYS_TYPE or hostname
if [ $SYS_TYPE ]; then
host="$SYS_TYPE"
else
host=`hostname -s`
fi
runtest_check=0
# Execute the given sequence of tests
for testcmd in "$@"
do
# Run a test
eval test_cmd=(${testcmd})
test="${test_cmd[0]}"
this_test=`basename $test`
rm -f "$this_test.out" "$this_test.err"
if [ "$test" == "$this_test" ]; then
this_dir="$test_dir"
else
this_dir=`dirname $test`
fi
test_cmd[0]="$this_test"
printf "\nRunning test '${test_cmd[*]}'... "
{ $this_dir/"$this_test" "$mfem_dir" "${test_cmd[@]:1}" 2>&1 1>&3 |
tee "$this_test.err"; } > "$this_test.out" 3>&1
# Apply filters to the *.err file
if [ -s "$this_test.err" ] && [ -e "$this_dir/$this_test.filters" ]; then
mv "$this_test.err" "$this_test.tmp"
egrep -v -f "$this_dir/$this_test.filters" "$this_test.tmp" \
> "$this_test.err"
# Remove lines with only white space.
sed -e 's/^[[:space:]]*$//' "$this_test.err" > "$this_test.tmp"
mv -f "$this_test.tmp" "$this_test.err"
fi
# Print the *.err file if not empty
if [ -s "$this_test.err" ]; then
runtest_check=1
printf '\033[31m'"FAILED\n"'\033[0m'
echo "=== BEGIN error log from $this_test.err"
(cat $this_test.err) 1>&2
echo "=== END error log from $this_test.err"
# rm -f $this_test.err $this_test.out
else
printf '\033[32m'"OK\n"'\033[0m'
fi
done
printf "\n"
exit ${runtest_check}