xref: /petsc/config/petsc_harness.sh (revision 4e4bbfaa3814cc83b5851d85be69070845f5653e)
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="-j"      ;;
72    J ) diff_flags="-J $OPTARG" ;;
73    m ) diff_flags="-m"      ;;
74    M ) 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
100
101
102# Init
103success=0; failed=0; failures=""; rmfiles=""
104total=0
105todo=-1; skip=-1
106job_level=0
107
108function petsc_report_tapoutput() {
109  notornot=$1
110  test_label=$2
111  comment=$3
112  if test -n "$comment"; then
113    comment=" # ${comment}"
114  fi
115
116  tap_message="${notornot} ok ${test_label}${comment}"
117
118  # Log messages
119  printf "${tap_message}\n" >> ${testlogtapfile}
120
121  if test ${output_fmt} == "err_only"; then
122     if test -n "${notornot}"; then
123        printf "${tap_message}\n" | tee -a ${testlogerrfile}
124     fi
125  else
126     printf "${tap_message}\n"
127  fi
128}
129
130function petsc_testrun() {
131  # First arg = Basic command
132  # Second arg = stdout file
133  # Third arg = stderr file
134  # Fourth arg = label for reporting
135  # Fifth arg = Filter
136  rmfiles="${rmfiles} $2 $3"
137  tlabel=$4
138  filter=$5
139  cmd="$1 > $2 2> $3"
140  if test -n "$filter"; then
141    if test "${filter:0:6}"=="Error:"; then
142      filter=${filter##Error:}
143      cmd="$1 2>&1 | cat > $2"
144    fi
145  fi
146  echo "$cmd" > ${tlabel}.sh; chmod 755 ${tlabel}.sh
147
148  eval "{ time -p $cmd ; } 2>> timing.out"
149  cmd_res=$?
150  touch "$2" "$3"
151  # ETIMEDOUT=110 on most systems (used by Open MPI 3.0).  MPICH uses
152  # 255.  Earlier Open MPI returns 1 but outputs about MPIEXEC_TIMEOUT.
153  if [ $cmd_res -eq 110 -o $cmd_res -eq 255 ] || \
154        fgrep -q -s 'APPLICATION TIMED OUT' "$2" "$3" || \
155        fgrep -q -s MPIEXEC_TIMEOUT "$2" "$3" || \
156        fgrep -q -s 'APPLICATION TERMINATED WITH THE EXIT STRING: job ending due to timeout' "$2" "$3" || \
157        grep -q -s "Timeout after [0-9]* seconds. Terminating job" "$2" "$3"; then
158    timed_out=1
159    # If timed out, then ensure non-zero error code
160    if [ $cmd_res -eq 0 ]; then
161      cmd_res=1
162    fi
163  fi
164
165  # Handle filters separately and assume no timeout check needed
166  if test -n "$filter"; then
167    cmd="cat $2 | $filter > $2.tmp 2>> $3 ; mv $2.tmp $2"
168    echo "$cmd" >> ${tlabel}.sh
169    eval "$cmd"
170  fi
171
172  # Report errors
173  comment=""
174  if test $cmd_res == 0; then
175     if "${verbose}"; then
176        comment="${cmd}"
177     fi
178    petsc_report_tapoutput "" "$tlabel" "$comment"
179    let success=$success+1
180  else
181    if [ -n "$timed_out" ]; then
182      comment="Exceeded timeout limit of $MPIEXEC_TIMEOUT s"
183    else
184      comment="Error code: ${cmd_res}"
185    fi
186    petsc_report_tapoutput "not" "$tlabel" "$comment"
187
188    # Report errors in detail
189    if [ -z "$timed_out" ]; then
190      # We've had tests fail but stderr->stdout. Fix with this test.
191      if test -s $3; then
192        awk '{print "#\t" $0}' < $3 | tee -a ${testlogerrfile}
193      else
194        awk '{print "#\t" $0}' < $2 | tee -a ${testlogerrfile}
195      fi
196    fi
197    let failed=$failed+1
198    failures="$failures $tlabel"
199  fi
200  let total=$success+$failed
201  return $cmd_res
202}
203
204function petsc_testend() {
205  logfile=$1/counts/${label}.counts
206  logdir=`dirname $logfile`
207  if ! test -d "$logdir"; then
208    mkdir -p $logdir
209  fi
210  if ! test -e "$logfile"; then
211    touch $logfile
212  fi
213  printf "total $total\n" > $logfile
214  printf "success $success\n" >> $logfile
215  printf "failed $failed\n" >> $logfile
216  printf "failures $failures\n" >> $logfile
217  if test ${todo} -gt 0; then
218    printf "todo $todo\n" >> $logfile
219  fi
220  if test ${skip} -gt 0; then
221    printf "skip $skip\n" >> $logfile
222  fi
223  ENDTIME=`date +%s`
224  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}'`
225  printf "time $timing\n" >> $logfile
226  if $cleanup; then
227    echo "Cleaning up"
228    /bin/rm -f $rmfiles
229  fi
230}
231
232function petsc_mpiexec_valgrind() {
233  mpiexec=$1;shift
234  npopt=$1;shift
235  np=$1;shift
236
237  valgrind="valgrind -q --tool=memcheck --leak-check=yes --num-callers=20 --track-origins=yes --suppressions=$petsc_bindir/maint/petsc-val.supp"
238
239  $mpiexec $npopt $np $valgrind $*
240}
241export LC_ALL=C
242