xref: /petsc/config/petsc_harness.sh (revision aec279fff732b222bc21c7b16399ba56402a3a16)
129921a8fSScott Kruger
229921a8fSScott Kruger
329921a8fSScott Krugerscriptname=`basename $0`
429921a8fSScott Krugerrundir=${scriptname%.sh}
534929e0eSSatish BalayTIMEOUT=60
629921a8fSScott Kruger
729921a8fSScott Krugerif test "$PWD"!=`dirname $0`; then
829921a8fSScott Kruger  cd `dirname $0`
9*aec279ffSScott Kruger  abspath_scriptdir=$PWD
1029921a8fSScott Krugerfi
116c91caf2SScott Krugerif test -d "${rundir}" && test -n "${rundir}"; then
1247e61e69SScott Kruger  rm -f ${rundir}/*.tmp ${rundir}/*.err ${rundir}/*.out
136c91caf2SScott Krugerfi
1429921a8fSScott Krugermkdir -p ${rundir}
1580a579ceSSatish Balayif test -n "${runfiles}"; then
1680a579ceSSatish Balay  for runfile in ${runfiles}; do
1780a579ceSSatish Balay      subdir=`dirname ${runfile}`
1880a579ceSSatish Balay      mkdir -p ${rundir}/${subdir}
1980a579ceSSatish Balay      cp -r ${runfile} ${rundir}/${subdir}
2080a579ceSSatish Balay  done
21d7871bd4SScott Krugerfi
2229921a8fSScott Krugercd ${rundir}
2329921a8fSScott Kruger
2429921a8fSScott Kruger#
2529921a8fSScott Kruger# Method to print out general and script specific options
2629921a8fSScott Kruger#
2729921a8fSScott Krugerprint_usage() {
2829921a8fSScott Kruger
2929921a8fSScott Krugercat >&2 <<EOF
3029921a8fSScott KrugerUsage: $0 [options]
3129921a8fSScott Kruger
3229921a8fSScott KrugerOPTIONS
3329921a8fSScott Kruger  -a <args> ......... Override default arguments
34*aec279ffSScott Kruger  -c ................ Cleanup (remove generated files)
35*aec279ffSScott Kruger  -C ................ Compile
36e53dc769SScott Kruger  -d ................ Launch in debugger
3729921a8fSScott Kruger  -e <args> ......... Add extra arguments to default
382f2809e3SToby Isaac  -f ................ force attempt to run test that would otherwise be skipped
3929921a8fSScott Kruger  -h ................ help: print this message
4029921a8fSScott Kruger  -n <integer> ...... Override the number of processors to use
41ba2c5286SScott Kruger  -j ................ Pass -j to petscdiff (just use diff)
42ba2c5286SScott Kruger  -J <arg> .......... Pass -J to petscdiff (just use diff with arg)
43ba2c5286SScott Kruger  -m ................ Update results using petscdiff
44f50802fbSScott Kruger  -M ................ Update alt files using petscdiff
455e361860SScott Kruger  -o <arg> .......... Output format: 'interactive', 'err_only'
46a6f3f80dSScott Kruger  -p ................ Print command:  Print first command and exit
470a091e3eSScott Kruger  -t ................ Override the default timeout (default=$TIMEOUT sec)
48b047ed2bSScott Kruger  -V ................ run Valgrind
4929921a8fSScott Kruger  -v ................ Verbose: Print commands
5029921a8fSScott KrugerEOF
5129921a8fSScott Kruger
5229921a8fSScott Kruger  if declare -f extrausage > /dev/null; then extrausage; fi
5329921a8fSScott Kruger  exit $1
5429921a8fSScott Kruger}
5529921a8fSScott Kruger###
5629921a8fSScott Kruger##  Arguments for overriding things
5729921a8fSScott Kruger#
585e361860SScott Krugeroutput_fmt="interactive"
5929921a8fSScott Krugerverbose=false
6029921a8fSScott Krugercleanup=false
61*aec279ffSScott Krugercompile=false
62e53dc769SScott Krugerdebugger=false
63a6f3f80dSScott Krugerprintcmd=false
642f2809e3SToby Isaacforce=false
65d4417257SScott Krugerdiff_flags=""
66*aec279ffSScott Krugerwhile getopts "a:cCde:fhjJ:mMn:o:pt:vV" arg
6729921a8fSScott Krugerdo
6829921a8fSScott Kruger  case $arg in
69ba2c5286SScott Kruger    a ) args="$OPTARG"       ;;
7029921a8fSScott Kruger    c ) cleanup=true         ;;
71*aec279ffSScott Kruger    C ) compile=true         ;;
72e53dc769SScott Kruger    d ) debugger=true        ;;
73ba2c5286SScott Kruger    e ) extra_args="$OPTARG" ;;
742f2809e3SToby Isaac    f ) force=true           ;;
7529921a8fSScott Kruger    h ) print_usage; exit    ;;
76ba2c5286SScott Kruger    n ) nsize="$OPTARG"      ;;
7729dac19bSScott Kruger    j ) diff_flags=$diff_flags" -j"      ;;
7829dac19bSScott Kruger    J ) diff_flags=$diff_flags" -J $OPTARG" ;;
7929dac19bSScott Kruger    m ) diff_flags=$diff_flags" -m"      ;;
8029dac19bSScott Kruger    M ) diff_flags=$diff_flags" -M"      ;;
815e361860SScott Kruger    o ) output_fmt=$OPTARG   ;;
82a6f3f80dSScott Kruger    p ) printcmd=true        ;;
830a091e3eSScott Kruger    t ) TIMEOUT=$OPTARG      ;;
84b047ed2bSScott Kruger    V ) mpiexec="petsc_mpiexec_valgrind $mpiexec" ;;
8529921a8fSScott Kruger    v ) verbose=true         ;;
8629921a8fSScott Kruger    *)  # To take care of any extra args
8729921a8fSScott Kruger      if test -n "$OPTARG"; then
8829921a8fSScott Kruger        eval $arg=\"$OPTARG\"
8929921a8fSScott Kruger      else
9029921a8fSScott Kruger        eval $arg=found
9129921a8fSScott Kruger      fi
9229921a8fSScott Kruger      ;;
9329921a8fSScott Kruger  esac
9429921a8fSScott Krugerdone
9529921a8fSScott Krugershift $(( $OPTIND - 1 ))
9629921a8fSScott Kruger
970a091e3eSScott Kruger# Individual tests can extend the default
9875ea7643SJed Brownexport MPIEXEC_TIMEOUT=$((TIMEOUT*timeoutfactor))
99bbf1c217SScott KrugerSTARTTIME=`date +%s`
1000a091e3eSScott Kruger
10129921a8fSScott Krugerif test -n "$extra_args"; then
10229921a8fSScott Kruger  args="$args $extra_args"
10329921a8fSScott Krugerfi
104e53dc769SScott Krugerif $debugger; then
105e53dc769SScott Kruger  args="-start_in_debugger $args"
106e53dc769SScott Krugerfi
1071725bfbfSScott Krugerif test -n "$filter"; then
1081725bfbfSScott Kruger  diff_flags=$diff_flags" -F \$'$filter'"
1091725bfbfSScott Krugerfi
1101725bfbfSScott Krugerif test -n "$filter_output"; then
1111725bfbfSScott Kruger  diff_flags=$diff_flags" -f \$'$filter_output'"
1121725bfbfSScott Krugerfi
113e53dc769SScott Kruger
11429921a8fSScott Kruger
11529921a8fSScott Kruger# Init
11629921a8fSScott Krugersuccess=0; failed=0; failures=""; rmfiles=""
11729921a8fSScott Krugertotal=0
11829921a8fSScott Krugertodo=-1; skip=-1
1190a091e3eSScott Krugerjob_level=0
12029921a8fSScott Kruger
1215e361860SScott Krugerfunction petsc_report_tapoutput() {
1225e361860SScott Kruger  notornot=$1
1235e361860SScott Kruger  test_label=$2
1245e361860SScott Kruger  comment=$3
1255e361860SScott Kruger  if test -n "$comment"; then
1265e361860SScott Kruger    comment=" # ${comment}"
1275e361860SScott Kruger  fi
1285e361860SScott Kruger
1295e361860SScott Kruger  tap_message="${notornot} ok ${test_label}${comment}"
1305e361860SScott Kruger
1315e361860SScott Kruger  # Log messages
1325e361860SScott Kruger  printf "${tap_message}\n" >> ${testlogtapfile}
1335e361860SScott Kruger
1345e361860SScott Kruger  if test ${output_fmt} == "err_only"; then
1355e361860SScott Kruger     if test -n "${notornot}"; then
1365e361860SScott Kruger        printf "${tap_message}\n" | tee -a ${testlogerrfile}
1375e361860SScott Kruger     fi
1385e361860SScott Kruger  else
1395e361860SScott Kruger     printf "${tap_message}\n"
1405e361860SScott Kruger  fi
1415e361860SScott Kruger}
1425e361860SScott Kruger
143a6f3f80dSScott Krugerfunction printcmd() {
144a6f3f80dSScott Kruger  # Print command that can be run from PETSC_DIR
145a6f3f80dSScott Kruger  cmd="$1"
146a6f3f80dSScott Kruger  basedir=`dirname ${PWD} | sed "s#${petsc_dir}/##"`
147a6f3f80dSScott Kruger  modcmd=`echo ${cmd} | sed -e "s#\.\.#${basedir}#" | sed s#\>.*##`
148a6f3f80dSScott Kruger  printf "${modcmd}\n"
149a6f3f80dSScott Kruger  exit
150a6f3f80dSScott Kruger}
151a6f3f80dSScott Kruger
15229921a8fSScott Krugerfunction petsc_testrun() {
15329921a8fSScott Kruger  # First arg = Basic command
15429921a8fSScott Kruger  # Second arg = stdout file
15529921a8fSScott Kruger  # Third arg = stderr file
15629921a8fSScott Kruger  # Fourth arg = label for reporting
15729921a8fSScott Kruger  rmfiles="${rmfiles} $2 $3"
15829921a8fSScott Kruger  tlabel=$4
1591725bfbfSScott Kruger  error=$5
16029921a8fSScott Kruger  cmd="$1 > $2 2> $3"
1611725bfbfSScott Kruger  if test -n "$error"; then
162fb2b1c94SScott Kruger    cmd="$1 2>&1 | cat > $2"
16329921a8fSScott Kruger  fi
1641263882eSScott Kruger  echo "$cmd" > ${tlabel}.sh; chmod 755 ${tlabel}.sh
165a6f3f80dSScott Kruger  if $printcmd; then
166a6f3f80dSScott Kruger     printcmd "$cmd"
167a6f3f80dSScott Kruger  fi
1687a853109SScott Kruger
169d8e31410SScott Kruger  eval "{ time -p $cmd ; } 2>> timing.out"
170679e9f5cSJed Brown  cmd_res=$?
1710da08ecbSSatish Balay  touch "$2" "$3"
172984117c4SJed Brown  # ETIMEDOUT=110 on most systems (used by Open MPI 3.0).  MPICH uses
173984117c4SJed Brown  # 255.  Earlier Open MPI returns 1 but outputs about MPIEXEC_TIMEOUT.
1747c0e31c5SScott Kruger  if [ $cmd_res -eq 110 -o $cmd_res -eq 255 ] || \
17548237715SSatish Balay        fgrep -q -s 'APPLICATION TIMED OUT' "$2" "$3" || \
1768fb2ab26SSatish Balay        fgrep -q -s MPIEXEC_TIMEOUT "$2" "$3" || \
1778fb2ab26SSatish Balay        fgrep -q -s 'APPLICATION TERMINATED WITH THE EXIT STRING: job ending due to timeout' "$2" "$3" || \
1788fb2ab26SSatish Balay        grep -q -s "Timeout after [0-9]* seconds. Terminating job" "$2" "$3"; then
179984117c4SJed Brown    timed_out=1
1807c0e31c5SScott Kruger    # If timed out, then ensure non-zero error code
1817c0e31c5SScott Kruger    if [ $cmd_res -eq 0 ]; then
1827c0e31c5SScott Kruger      cmd_res=1
1837c0e31c5SScott Kruger    fi
184984117c4SJed Brown  fi
1850a091e3eSScott Kruger
1860a091e3eSScott Kruger  # Report errors
1875e361860SScott Kruger  comment=""
1887a853109SScott Kruger  if test $cmd_res == 0; then
18902afe9ecSJed Brown     if "${verbose}"; then
1905e361860SScott Kruger        comment="${cmd}"
19102afe9ecSJed Brown     fi
1925e361860SScott Kruger    petsc_report_tapoutput "" "$tlabel" "$comment"
19329921a8fSScott Kruger    let success=$success+1
19429921a8fSScott Kruger  else
1954d9d3ee5SSatish Balay    if [ -n "$timed_out" ]; then
1965e361860SScott Kruger      comment="Exceeded timeout limit of $MPIEXEC_TIMEOUT s"
1974d9d3ee5SSatish Balay    else
1985e361860SScott Kruger      comment="Error code: ${cmd_res}"
19964ca018dSScott Kruger    fi
2005e361860SScott Kruger    petsc_report_tapoutput "not" "$tlabel" "$comment"
2015e361860SScott Kruger
2025e361860SScott Kruger    # Report errors in detail
2035e361860SScott Kruger    if [ -z "$timed_out" ]; then
204570dea68SScott Kruger      # We've had tests fail but stderr->stdout, as well as having
205570dea68SScott Kruger      # mpi_abort go to stderr which throws this test off.  Show both
206570dea68SScott Kruger      # with stdout first
2075e361860SScott Kruger      awk '{print "#\t" $0}' < $2 | tee -a ${testlogerrfile}
20829dac19bSScott Kruger      # if statement is for diff tests
20929dac19bSScott Kruger      if test "$2" != "$3"; then
210570dea68SScott Kruger        awk '{print "#\t" $0}' < $3 | tee -a ${testlogerrfile}
211984117c4SJed Brown      fi
21229dac19bSScott Kruger    fi
21329921a8fSScott Kruger    let failed=$failed+1
21429921a8fSScott Kruger    failures="$failures $tlabel"
21529921a8fSScott Kruger  fi
21629921a8fSScott Kruger  let total=$success+$failed
2177a853109SScott Kruger  return $cmd_res
21829921a8fSScott Kruger}
21929921a8fSScott Kruger
22029921a8fSScott Krugerfunction petsc_testend() {
22129921a8fSScott Kruger  logfile=$1/counts/${label}.counts
22229921a8fSScott Kruger  logdir=`dirname $logfile`
22329921a8fSScott Kruger  if ! test -d "$logdir"; then
22429921a8fSScott Kruger    mkdir -p $logdir
22529921a8fSScott Kruger  fi
22629921a8fSScott Kruger  if ! test -e "$logfile"; then
22729921a8fSScott Kruger    touch $logfile
22829921a8fSScott Kruger  fi
22929921a8fSScott Kruger  printf "total $total\n" > $logfile
23029921a8fSScott Kruger  printf "success $success\n" >> $logfile
23129921a8fSScott Kruger  printf "failed $failed\n" >> $logfile
23229921a8fSScott Kruger  printf "failures $failures\n" >> $logfile
23329921a8fSScott Kruger  if test ${todo} -gt 0; then
23429921a8fSScott Kruger    printf "todo $todo\n" >> $logfile
23529921a8fSScott Kruger  fi
23629921a8fSScott Kruger  if test ${skip} -gt 0; then
23729921a8fSScott Kruger    printf "skip $skip\n" >> $logfile
23829921a8fSScott Kruger  fi
239bbf1c217SScott Kruger  ENDTIME=`date +%s`
2409b757ad5SKarl Rupp  timing=`touch timing.out && egrep '(user|sys)' timing.out | awk '{if( sum1 == "" || $2 > sum1 ) { sum1=sprintf("%.2f",$2) } ; sum2 += sprintf("%.2f",$2)} END {printf "%.2f %.2f\n",sum1,sum2}'`
241521be42fSScott Kruger  printf "time $timing\n" >> $logfile
24229921a8fSScott Kruger  if $cleanup; then
24329921a8fSScott Kruger    echo "Cleaning up"
24429921a8fSScott Kruger    /bin/rm -f $rmfiles
24529921a8fSScott Kruger  fi
24629921a8fSScott Kruger}
247296e37cfSJed Brown
24826646c0bSSatish Balayfunction petsc_mpiexec_valgrind() {
2490f9322f4SToby Isaac  _mpiexec=$1;shift
25026646c0bSSatish Balay  npopt=$1;shift
25126646c0bSSatish Balay  np=$1;shift
25226646c0bSSatish Balay
253ac71c9ffSScott Kruger  valgrind="valgrind -q --tool=memcheck --leak-check=yes --num-callers=20 --track-origins=yes --suppressions=$petsc_bindir/maint/petsc-val.supp --error-exitcode=10"
254c173c275SScott Kruger
2550f9322f4SToby Isaac  $_mpiexec $npopt $np $valgrind $*
25626646c0bSSatish Balay}
257296e37cfSJed Brownexport LC_ALL=C
258*aec279ffSScott Kruger
259*aec279ffSScott Krugerif $compile; then
260*aec279ffSScott Kruger    curexec=`basename ${exec}`
261*aec279ffSScott Kruger    (cd $petsc_dir && make -f gmakefile.test ${abspath_scriptdir}/${curexec})
262*aec279ffSScott Krugerfi
263*aec279ffSScott Kruger
264