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