2012-01-10 04:34:04 -06:00
|
|
|
#! /bin/bash
|
|
|
|
#
|
|
|
|
# Runs a test from the test directory and compare the resulting VTU files.
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
#
|
2019-01-18 06:26:28 -06:00
|
|
|
# runTest.sh TEST_TYPE [TEST_ARGS]
|
2012-01-10 04:34:04 -06:00
|
|
|
#
|
2013-11-25 08:01:43 -06:00
|
|
|
MY_DIR="$(dirname "$0")"
|
2012-01-10 04:34:04 -06:00
|
|
|
|
2013-11-25 08:01:43 -06:00
|
|
|
usage() {
|
2012-01-10 04:34:04 -06:00
|
|
|
echo "Usage:"
|
|
|
|
echo
|
2021-10-13 04:44:20 -05:00
|
|
|
echo "runTest.sh TEST_TYPE -e binary -- [TEST_ARGS]"
|
2019-01-18 06:26:28 -06:00
|
|
|
echo "where TEST_TYPE can either be --plain, --simulation, --spe1 or --parallel-simulation=\$NUM_CORES (is '$TEST_TYPE')."
|
2012-01-10 04:34:04 -06:00
|
|
|
};
|
|
|
|
|
2016-10-27 04:39:12 -05:00
|
|
|
# this function clips the help message printed by an ewoms simulation
|
|
|
|
# to what is actually printed, throwing away all garbage which is
|
|
|
|
# printed before or after the "meat"
|
|
|
|
clipToHelpMessage()
|
|
|
|
{
|
|
|
|
STATUS="not started"
|
|
|
|
while read CUR_LINE; do
|
|
|
|
if echo $CUR_LINE | grep -q "Usage: "; then
|
|
|
|
STATUS="started"
|
|
|
|
elif test "$STATUS" = "started" && echo $CUR_LINE | grep -q "^--"; then
|
|
|
|
STATUS="params"
|
|
|
|
elif test "$STATUS" = "params" && echo $CUR_LINE | grep -q "^[^-]"; then
|
|
|
|
STATUS="stopped"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test "$STATUS" != "not started" && test "$STATUS" != "stopped"; then
|
|
|
|
echo "$CUR_LINE"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
2013-01-11 11:16:29 -06:00
|
|
|
|
2012-10-19 07:42:37 -05:00
|
|
|
TEST_TYPE="$1"
|
2021-10-13 04:44:20 -05:00
|
|
|
if test "$2" != "-e"; then
|
|
|
|
echo "Expects second option to be -e"
|
|
|
|
fi
|
|
|
|
TEST_NAME="$3"
|
|
|
|
TEST_ARGS="${@:5:100}"
|
2012-01-10 04:34:04 -06:00
|
|
|
|
2012-10-19 07:42:37 -05:00
|
|
|
# make sure we have at least 2 parameters
|
|
|
|
if test "$#" -lt 2; then
|
2012-01-10 04:34:04 -06:00
|
|
|
echo "Wrong number of parameters"
|
|
|
|
echo
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-01-18 06:26:28 -06:00
|
|
|
if test "$TEST_TYPE" != "--spe1"; then
|
|
|
|
# find the binary in the its folder
|
|
|
|
TEST_BINARY=$(find . -type f -perm -0111 -name "$TEST_NAME")
|
|
|
|
NUM_BINARIES=$(echo "$TEST_BINARY" | wc -w | tr -d '[:space:]')
|
|
|
|
|
|
|
|
if test "$NUM_BINARIES" != "1"; then
|
|
|
|
echo "No binary file found or binary file is non-unique (is: $TEST_BINARY)"
|
|
|
|
echo
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# make sure the binary is of the test is present
|
|
|
|
if ! test -x "$TEST_BINARY"; then
|
|
|
|
echo "$TEST_NAME does not exist or is not executable"
|
|
|
|
echo
|
|
|
|
usage
|
2012-01-10 04:34:04 -06:00
|
|
|
exit 1
|
2019-01-18 06:26:28 -06:00
|
|
|
fi
|
2012-01-10 04:34:04 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
#run the test
|
|
|
|
echo "######################"
|
2012-10-19 07:42:37 -05:00
|
|
|
echo "# Running test '$TEST_NAME'"
|
2012-01-10 04:34:04 -06:00
|
|
|
echo "######################"
|
2012-10-19 07:42:37 -05:00
|
|
|
|
2012-01-10 04:34:04 -06:00
|
|
|
|
2013-01-30 15:26:37 -06:00
|
|
|
RND="$(dd if=/dev/urandom bs=20 count=1 2> /dev/null | md5sum | cut -d" " -f1)"
|
2012-10-19 07:42:37 -05:00
|
|
|
case "$TEST_TYPE" in
|
|
|
|
"--simulation")
|
2014-05-02 09:06:46 -05:00
|
|
|
echo "executing \"$TEST_BINARY $TEST_ARGS\""
|
2012-10-23 04:55:26 -05:00
|
|
|
"$TEST_BINARY" $TEST_ARGS | tee "test-$RND.log"
|
|
|
|
RET="${PIPESTATUS[0]}"
|
|
|
|
if test "$RET" != "0"; then
|
|
|
|
echo "Executing the binary failed!"
|
|
|
|
rm "test-$RND.log"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-10-19 07:42:37 -05:00
|
|
|
# compare the results
|
|
|
|
echo "######################"
|
|
|
|
echo "# Comparing results"
|
|
|
|
echo "######################"
|
2013-02-07 03:51:06 -06:00
|
|
|
echo "RND: '$RND'"
|
|
|
|
|
2014-04-14 13:32:30 -05:00
|
|
|
SIM_NAME=$(grep "Applying the initial solution of the" "test-$RND.log" | sed "s/.*\"\(.*\)\".*/\1/" | head -n1)
|
2016-08-13 05:41:59 -05:00
|
|
|
NUM_TIMESTEPS=$(( $(grep "Time step [0-9]* done" "test-$RND.log" | wc -l)))
|
2013-01-30 08:39:10 -06:00
|
|
|
TEST_RESULT=$(printf "%s-%05i" "$SIM_NAME" "$NUM_TIMESTEPS")
|
2014-04-14 13:32:30 -05:00
|
|
|
TEST_RESULT=$(ls -- "$TEST_RESULT".*)
|
2012-10-23 04:55:26 -05:00
|
|
|
rm "test-$RND.log"
|
2012-10-19 07:42:37 -05:00
|
|
|
if ! test -r "$TEST_RESULT"; then
|
|
|
|
echo "File $TEST_RESULT does not exist or is not readable"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-01-30 08:39:10 -06:00
|
|
|
echo "Simulation name: '$SIM_NAME'"
|
|
|
|
echo "Number of timesteps: '$NUM_TIMESTEPS'"
|
|
|
|
|
2012-10-19 07:42:37 -05:00
|
|
|
exit 0
|
|
|
|
;;
|
2012-10-23 08:48:57 -05:00
|
|
|
|
2020-01-23 02:47:34 -06:00
|
|
|
"--parallel-program="*)
|
|
|
|
NUM_PROCS="${TEST_TYPE/--parallel-program=/}"
|
|
|
|
|
|
|
|
echo "executing \"mpirun -np \"$NUM_PROCS\" $TEST_BINARY $TEST_ARGS\""
|
|
|
|
mpirun -np "$NUM_PROCS" "$TEST_BINARY" $TEST_ARGS | tee "test-$RND.log"
|
|
|
|
RET="${PIPESTATUS[0]}"
|
|
|
|
if test "$RET" != "0"; then
|
|
|
|
echo "Executing the binary failed!"
|
|
|
|
rm "test-$RND.log"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
|
2014-03-06 09:42:34 -06:00
|
|
|
"--parallel-simulation="*)
|
|
|
|
NUM_PROCS="${TEST_TYPE/--parallel-simulation=/}"
|
|
|
|
|
2014-05-02 09:06:46 -05:00
|
|
|
echo "executing \"mpirun -np \"$NUM_PROCS\" $TEST_BINARY $TEST_ARGS\""
|
2014-03-06 07:37:32 -06:00
|
|
|
mpirun -np "$NUM_PROCS" "$TEST_BINARY" $TEST_ARGS | tee "test-$RND.log"
|
2012-10-23 04:55:26 -05:00
|
|
|
RET="${PIPESTATUS[0]}"
|
|
|
|
if test "$RET" != "0"; then
|
|
|
|
echo "Executing the binary failed!"
|
|
|
|
rm "test-$RND.log"
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-03-06 07:37:32 -06:00
|
|
|
|
2014-04-14 13:32:30 -05:00
|
|
|
SIM_NAME=$(grep "Applying the initial solution of the" "test-$RND.log" | sed "s/.*\"\(.*\)\".*/\1/" | head -n1)
|
2016-08-13 05:41:59 -05:00
|
|
|
NUM_TIMESTEPS=$(( $(grep "Time step [0-9]* done" "test-$RND.log" | wc -l)))
|
2012-10-22 15:44:42 -05:00
|
|
|
rm "test-$RND.log"
|
2012-10-23 04:55:26 -05:00
|
|
|
|
2014-03-06 07:37:32 -06:00
|
|
|
echo "Simulation name: '$SIM_NAME'"
|
|
|
|
echo "Number of timesteps: '$NUM_TIMESTEPS'"
|
|
|
|
for PROC_NUM in 0 1 2 3; do
|
|
|
|
REF_FILE=$(printf "s%04d-p%04d-%s" "$NUM_PROCS" "$PROC_NUM" "$SIM_NAME")
|
|
|
|
TEST_RESULT=$(printf "s%04d-p%04d-%s-%05i" "$NUM_PROCS" "$PROC_NUM" "$SIM_NAME" "$NUM_TIMESTEPS")
|
2014-04-14 13:32:30 -05:00
|
|
|
TEST_RESULT=$(ls -- "$TEST_RESULT".*)
|
2014-03-06 07:37:32 -06:00
|
|
|
if ! test -r "$TEST_RESULT"; then
|
|
|
|
echo "File $TEST_RESULT does not exist or is not readable"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
2012-10-23 04:55:26 -05:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
|
2019-01-18 06:26:28 -06:00
|
|
|
"--spe1")
|
|
|
|
echo "Running the ebos simulator for SPE1CASE1"
|
|
|
|
|
|
|
|
EBOS_COMMAND=$(find . -type f -perm -0111 -name "ebos")
|
|
|
|
|
|
|
|
NUM_BINARIES=$(echo "$EBOS_COMMAND" | wc -w | tr -d '[:space:]')
|
|
|
|
if test "$NUM_BINARIES" != "1"; then
|
|
|
|
echo "No ebos executable found (is: $EBOS_COMMAND)"
|
|
|
|
echo
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
#########
|
|
|
|
# Run the simulator
|
|
|
|
if ! "$EBOS_COMMAND" "data/SPE1CASE1" ; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
#########
|
|
|
|
|
2019-02-12 06:23:03 -06:00
|
|
|
# make sure that the simulator produced non-empty output files
|
|
|
|
for EXT in "INIT" "EGRID" "UNRST" "UNSMRY" "SMSPEC"; do
|
|
|
|
if ! test -s "SPE1CASE1.$EXT"; then
|
|
|
|
echo "The simulator did not produce a non-empty SPE1CASE1.$EXT file"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
2019-01-18 06:26:28 -06:00
|
|
|
|
2019-02-12 06:23:03 -06:00
|
|
|
exit 0
|
2019-01-18 06:26:28 -06:00
|
|
|
;;
|
|
|
|
|
2012-10-29 11:14:51 -05:00
|
|
|
"--restart")
|
2014-05-02 09:06:46 -05:00
|
|
|
echo "executing \"$TEST_BINARY $TEST_ARGS\""
|
2012-10-29 11:14:51 -05:00
|
|
|
"$TEST_BINARY" $TEST_ARGS | tee "test-$RND.log"
|
|
|
|
RET="${PIPESTATUS[0]}"
|
|
|
|
if test "$RET" != "0"; then
|
|
|
|
echo "Executing the binary failed!"
|
|
|
|
rm "test-$RND.log"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
RESTART_TIME=$(grep "Serialize" "test-$RND.log" | tail -n 1 | sed "s/.*time=\([0-9.e+\-]*\).*/\1/")
|
|
|
|
rm "test-$RND.log"
|
2019-02-12 06:23:03 -06:00
|
|
|
|
2013-01-30 15:26:37 -06:00
|
|
|
if ! "$TEST_BINARY" $TEST_ARGS --restart-time="$RESTART_TIME" --newton-write-convergence=true; then
|
2012-10-29 11:14:51 -05:00
|
|
|
echo "Restarting $TEST_BINARY failed"
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
exit 0
|
2019-02-12 06:23:03 -06:00
|
|
|
;;
|
2012-10-29 11:14:51 -05:00
|
|
|
|
2012-10-23 04:55:26 -05:00
|
|
|
"--parameters")
|
2016-10-27 04:39:12 -05:00
|
|
|
HELP_MSG="$($TEST_BINARY --help | clipToHelpMessage)"
|
2013-11-25 08:01:43 -06:00
|
|
|
if test "$(echo "$HELP_MSG" | grep -i usage)" == ''; then
|
2012-10-23 04:55:26 -05:00
|
|
|
echo "$TEST_BINARY did not accept '--help' parameter"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-10-27 04:39:12 -05:00
|
|
|
HELP_MSG2="$($TEST_BINARY -h | clipToHelpMessage)"
|
2012-10-23 04:55:26 -05:00
|
|
|
if test "$HELP_MSG" != "$HELP_MSG2"; then
|
|
|
|
echo "Output of $TEST_BINARY different when passing '--help' and '-h'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat > "paramfile-$RND.ini" <<EOF
|
2018-08-08 06:32:27 -05:00
|
|
|
EndTime=100
|
|
|
|
|
|
|
|
InitialTimeStepSize=100 # first in-line comment
|
|
|
|
|
|
|
|
# full line comment
|
|
|
|
; also a full line comment
|
2012-10-23 04:55:26 -05:00
|
|
|
EOF
|
2013-11-26 05:20:26 -06:00
|
|
|
if ! $TEST_BINARY --parameter-file="paramfile-$RND.ini" 2>&1 > /dev/null; then
|
2012-10-29 11:14:51 -05:00
|
|
|
echo "$TEST_BINARY does not correctly read a parameter file"
|
|
|
|
exit 1
|
2013-11-26 05:20:26 -06:00
|
|
|
elif $TEST_BINARY --parameter-file="foobar.ini" 2>&1 > /dev/null; then
|
2012-10-29 11:14:51 -05:00
|
|
|
echo "$TEST_BINARY does not abort even though the specified parameter file does not exist"
|
|
|
|
exit 1
|
2019-06-26 04:23:43 -05:00
|
|
|
elif $TEST_BINARY --undefined-param="bla" 2>&1 > /dev/null; then
|
|
|
|
echo "$TEST_BINARY does not signal an error even though an undefined command line parameter was passed"
|
|
|
|
exit 1
|
2018-08-08 06:32:27 -05:00
|
|
|
elif $TEST_BINARY --foo 2>&1 > /dev/null; then
|
|
|
|
echo "$TEST_BINARY accepts flag parameters besides --help"
|
2012-10-29 11:14:51 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# test some invalid parameter names
|
|
|
|
for PARAM in foo -- -0foo --0foo --foo--bar --foo- -foo --foo-bar§=abc ; do
|
2013-11-26 05:20:26 -06:00
|
|
|
if $TEST_BINARY "$PARAM" --end-time=100 2>&1 > /dev/null; then
|
2012-10-29 11:14:51 -05:00
|
|
|
echo "$TEST_BINARY accepted invalid command line option '$PARAM'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "Test successful"
|
|
|
|
exit 0
|
|
|
|
|
2012-10-23 04:55:26 -05:00
|
|
|
;;
|
|
|
|
|
|
|
|
"--plain")
|
2014-05-02 09:06:46 -05:00
|
|
|
echo "executing \"$TEST_BINARY $TEST_ARGS\""
|
2012-10-23 04:55:26 -05:00
|
|
|
if ! "$TEST_BINARY" $TEST_ARGS; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-10-19 07:42:37 -05:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|