xref: /petsc/config/petsc_harness.sh (revision 5ab1ac2bae2c53bf5666daef2efaf6cb34bd2dd4)
1
2
3scriptname=`basename $0`
4rundir=${scriptname%.sh}
5TIMEOUT=60
6
7if test "$PWD"!=`dirname $0`; then
8  cd `dirname $0`
9  abspath_scriptdir=$PWD
10fi
11if test -d "${rundir}" && test -n "${rundir}"; then
12  rm -f ${rundir}/*.tmp ${rundir}/*.err ${rundir}/*.out
13fi
14mkdir -p ${rundir}
15if test -n "${runfiles}"; then
16  for runfile in ${runfiles}; do
17      subdir=`dirname ${runfile}`
18      mkdir -p ${rundir}/${subdir}
19      cp -r ${runfile} ${rundir}/${subdir}
20  done
21fi
22cd ${rundir}
23
24#
25# Method to print out general and script specific options
26#
27print_usage() {
28
29cat >&2 <<EOF
30Usage: $0 [options]
31
32OPTIONS
33  -a <args> ......... Override default arguments
34  -c ................ Cleanup (remove generated files)
35  -C ................ Compile
36  -d ................ Launch in debugger
37  -e <args> ......... Add extra arguments to default
38  -f ................ force attempt to run test that would otherwise be skipped
39  -h ................ help: print this message
40  -n <integer> ...... Override the number of processors to use
41  -j ................ Pass -j to petscdiff (just use diff)
42  -J <arg> .......... Pass -J to petscdiff (just use diff with arg)
43  -m ................ Update results using petscdiff
44  -M ................ Update alt files using petscdiff
45  -o <arg> .......... Output format: 'interactive', 'err_only'
46  -p ................ Print command:  Print first command and exit
47  -t ................ Override the default timeout (default=$TIMEOUT sec)
48  -V ................ run Valgrind
49  -v ................ Verbose: Print commands
50EOF
51
52  if declare -f extrausage > /dev/null; then extrausage; fi
53  exit $1
54}
55###
56##  Arguments for overriding things
57#
58output_fmt="interactive"
59verbose=false
60cleanup=false
61compile=false
62debugger=false
63printcmd=false
64force=false
65diff_flags=""
66while getopts "a:cCde:fhjJ:mMn:o:pt:vV" arg
67do
68  case $arg in
69    a ) args="$OPTARG"       ;;
70    c ) cleanup=true         ;;
71    C ) compile=true         ;;
72    d ) debugger=true        ;;
73    e ) extra_args="$OPTARG" ;;
74    f ) force=true           ;;
75    h ) print_usage; exit    ;;
76    n ) nsize="$OPTARG"      ;;
77    j ) diff_flags=$diff_flags" -j"      ;;
78    J ) diff_flags=$diff_flags" -J $OPTARG" ;;
79    m ) diff_flags=$diff_flags" -m"      ;;
80    M ) diff_flags=$diff_flags" -M"      ;;
81    o ) output_fmt=$OPTARG   ;;
82    p ) printcmd=true        ;;
83    t ) TIMEOUT=$OPTARG      ;;
84    V ) mpiexec="petsc_mpiexec_valgrind $mpiexec" ;;
85    v ) verbose=true         ;;
86    *)  # To take care of any extra args
87      if test -n "$OPTARG"; then
88        eval $arg=\"$OPTARG\"
89      else
90        eval $arg=found
91      fi
92      ;;
93  esac
94done
95shift $(( $OPTIND - 1 ))
96
97# Individual tests can extend the default
98export MPIEXEC_TIMEOUT=$((TIMEOUT*timeoutfactor))
99STARTTIME=`date +%s`
100
101if test -n "$extra_args"; then
102  args="$args $extra_args"
103fi
104if $debugger; then
105  args="-start_in_debugger $args"
106fi
107if test -n "$filter"; then
108  diff_flags=$diff_flags" -F \$'$filter'"
109fi
110if test -n "$filter_output"; then
111  diff_flags=$diff_flags" -f \$'$filter_output'"
112fi
113
114
115# Init
116success=0; failed=0; failures=""; rmfiles=""
117total=0
118todo=-1; skip=-1
119job_level=0
120
121function petsc_report_tapoutput() {
122  notornot=$1
123  test_label=$2
124  comment=$3
125  if test -n "$comment"; then
126    comment=" # ${comment}"
127  fi
128
129  tap_message="${notornot} ok ${test_label}${comment}"
130
131  # Log messages
132  printf "${tap_message}\n" >> ${testlogtapfile}
133
134  if test ${output_fmt} == "err_only"; then
135     if test -n "${notornot}"; then
136        printf "${tap_message}\n" | tee -a ${testlogerrfile}
137     fi
138  else
139     printf "${tap_message}\n"
140  fi
141}
142
143function printcmd() {
144  # Print command that can be run from PETSC_DIR
145  cmd="$1"
146  basedir=`dirname ${PWD} | sed "s#${petsc_dir}/##"`
147  modcmd=`echo ${cmd} | sed -e "s#\.\.#${basedir}#" | sed s#\>.*##`
148  printf "${modcmd}\n"
149  exit
150}
151
152function petsc_testrun() {
153  # First arg = Basic command
154  # Second arg = stdout file
155  # Third arg = stderr file
156  # Fourth arg = label for reporting
157  rmfiles="${rmfiles} $2 $3"
158  tlabel=$4
159  error=$5
160  cmd="$1 > $2 2> $3"
161  if test -n "$error"; then
162    cmd="$1 2>&1 | cat > $2"
163  fi
164  echo "$cmd" > ${tlabel}.sh; chmod 755 ${tlabel}.sh
165  if $printcmd; then
166     printcmd "$cmd"
167  fi
168
169  eval "{ time -p $cmd ; } 2>> timing.out"
170  cmd_res=$?
171  touch "$2" "$3"
172  # ETIMEDOUT=110 on most systems (used by Open MPI 3.0).  MPICH uses
173  # 255.  Earlier Open MPI returns 1 but outputs about MPIEXEC_TIMEOUT.
174  if [ $cmd_res -eq 110 -o $cmd_res -eq 255 ] || \
175        fgrep -q -s 'APPLICATION TIMED OUT' "$2" "$3" || \
176        fgrep -q -s MPIEXEC_TIMEOUT "$2" "$3" || \
177        fgrep -q -s 'APPLICATION TERMINATED WITH THE EXIT STRING: job ending due to timeout' "$2" "$3" || \
178        grep -q -s "Timeout after [0-9]* seconds. Terminating job" "$2" "$3"; then
179    timed_out=1
180    # If timed out, then ensure non-zero error code
181    if [ $cmd_res -eq 0 ]; then
182      cmd_res=1
183    fi
184  fi
185
186  # Report errors
187  comment=""
188  if test $cmd_res == 0; then
189     if "${verbose}"; then
190        comment="${cmd}"
191     fi
192    petsc_report_tapoutput "" "$tlabel" "$comment"
193    let success=$success+1
194  else
195    if [ -n "$timed_out" ]; then
196      comment="Exceeded timeout limit of $MPIEXEC_TIMEOUT s"
197    else
198      comment="Error code: ${cmd_res}"
199    fi
200    petsc_report_tapoutput "not" "$tlabel" "$comment"
201
202    # Report errors in detail
203    if [ -z "$timed_out" ]; then
204      # We've had tests fail but stderr->stdout, as well as having
205      # mpi_abort go to stderr which throws this test off.  Show both
206      # with stdout first
207      awk '{print "#\t" $0}' < $2 | tee -a ${testlogerrfile}
208      # if statement is for diff tests
209      if test "$2" != "$3"; then
210        awk '{print "#\t" $0}' < $3 | tee -a ${testlogerrfile}
211      fi
212    fi
213    let failed=$failed+1
214    failures="$failures $tlabel"
215  fi
216  let total=$success+$failed
217  return $cmd_res
218}
219
220function petsc_testend() {
221  logfile=$1/counts/${label}.counts
222  logdir=`dirname $logfile`
223  if ! test -d "$logdir"; then
224    mkdir -p $logdir
225  fi
226  if ! test -e "$logfile"; then
227    touch $logfile
228  fi
229  printf "total $total\n" > $logfile
230  printf "success $success\n" >> $logfile
231  printf "failed $failed\n" >> $logfile
232  printf "failures $failures\n" >> $logfile
233  if test ${todo} -gt 0; then
234    printf "todo $todo\n" >> $logfile
235  fi
236  if test ${skip} -gt 0; then
237    printf "skip $skip\n" >> $logfile
238  fi
239  ENDTIME=`date +%s`
240  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}'`
241  printf "time $timing\n" >> $logfile
242  if $cleanup; then
243    echo "Cleaning up"
244    /bin/rm -f $rmfiles
245  fi
246}
247
248function petsc_mpiexec_valgrind() {
249  _mpiexec=$1;shift
250  npopt=$1;shift
251  np=$1;shift
252
253  valgrind="valgrind -q --tool=memcheck --leak-check=yes --num-callers=20 --track-origins=yes --suppressions=$petsc_bindir/maint/petsc-val.supp --error-exitcode=10"
254
255  $_mpiexec $npopt $np $valgrind $*
256}
257export LC_ALL=C
258
259if $compile; then
260    curexec=`basename ${exec}`
261    (cd $petsc_dir && make -f gmakefile.test ${abspath_scriptdir}/${curexec})
262fi
263
264