xref: /petsc/config/petsc_harness.sh (revision 5295adeefcdc54783dd7ea14e34a9f3d61af6b9d)
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 -d "${runfiles}"; then
15  cp -r ${runfiles} ${rundir}
16elif test -n "${runfiles}"; then
17  cp ${runfiles} ${rundir}
18fi
19cd ${rundir}
20
21#
22# Method to print out general and script specific options
23#
24print_usage() {
25
26cat >&2 <<EOF
27Usage: $0 [options]
28
29OPTIONS
30  -a <args> ......... Override default arguments
31  -c <cleanup> ...... Cleanup (remove generated files)
32  -d ................ Launch in debugger
33  -e <args> ......... Add extra arguments to default
34  -f ................ force attempt to run test that would otherwise be skipped
35  -h ................ help: print this message
36  -n <integer> ...... Override the number of processors to use
37  -j ................ Pass -j to petscdiff (just use diff)
38  -J <arg> .......... Pass -J to petscdiff (just use diff with arg)
39  -m ................ Update results using petscdiff
40  -M ................ Update alt files using petscdiff
41  -t ................ Override the default timeout (default=$TIMEOUT sec)
42  -V ................ run Valgrind
43  -v ................ Verbose: Print commands
44EOF
45
46  if declare -f extrausage > /dev/null; then extrausage; fi
47  exit $1
48}
49###
50##  Arguments for overriding things
51#
52verbose=false
53cleanup=false
54debugger=false
55force=false
56diff_flags=""
57while getopts "a:cde:fhjJ:mMn:t:vV" arg
58do
59  case $arg in
60    a ) args="$OPTARG"       ;;
61    c ) cleanup=true         ;;
62    d ) debugger=true        ;;
63    e ) extra_args="$OPTARG" ;;
64    f ) force=true           ;;
65    h ) print_usage; exit    ;;
66    n ) nsize="$OPTARG"      ;;
67    j ) diff_flags="-j"      ;;
68    J ) diff_flags="-J $OPTARG" ;;
69    m ) diff_flags="-m"      ;;
70    M ) diff_flags="-M"      ;;
71    t ) TIMEOUT=$OPTARG      ;;
72    V ) mpiexec="petsc_mpiexec_valgrind $mpiexec" ;;
73    v ) verbose=true         ;;
74    *)  # To take care of any extra args
75      if test -n "$OPTARG"; then
76        eval $arg=\"$OPTARG\"
77      else
78        eval $arg=found
79      fi
80      ;;
81  esac
82done
83shift $(( $OPTIND - 1 ))
84
85# Individual tests can extend the default
86TIMEOUT=$((TIMEOUT*timeoutfactor))
87STARTTIME=`date +%s`
88
89if test -n "$extra_args"; then
90  args="$args $extra_args"
91fi
92if $debugger; then
93  args="-start_in_debugger $args"
94fi
95
96
97# Init
98success=0; failed=0; failures=""; rmfiles=""
99total=0
100todo=-1; skip=-1
101job_level=0
102
103function petsc_testrun() {
104  # First arg = Basic command
105  # Second arg = stdout file
106  # Third arg = stderr file
107  # Fourth arg = label for reporting
108  # Fifth arg = Filter
109  rmfiles="${rmfiles} $2 $3"
110  tlabel=$4
111  filter=$5
112  job_control=true
113  cmd="$1 > $2 2> $3"
114  if test -n "$filter"; then
115    if test "${filter:0:6}"=="Error:"; then
116      job_control=false      # redirection error method causes job control probs
117      filter=${filter##Error:}
118      cmd="$1 2>&1 | cat > $2"
119    fi
120  fi
121  # disable job_control on cygwin
122  if [[ `uname` =~ ^CYGWIN ]] ; then
123      job_control=false
124  fi
125  echo "$cmd" > ${tlabel}.sh; chmod 755 ${tlabel}.sh
126
127  if $job_control; then
128    # The action:
129    ( ulimit -St $TIMEOUT && eval "$cmd" )
130    cmd_res=$?
131    # SIGXCPU=24, but some systems give our shell 128+24=152
132    test $cmd_res -eq 24 -o $cmd_res -eq 152 && echo "Exceeded timeout limit of $TIMEOUT s" >> $3
133  else
134    # The action -- assume no timeout needed
135    eval "$cmd"
136    # We are testing error codes so just make it pass
137    cmd_res=$?
138  fi
139
140  # Handle filters separately and assume no timeout check needed
141  if test -n "$filter"; then
142    cmd="cat $2 | $filter > $2.tmp 2>> $3 && mv $2.tmp $2"
143    echo "$cmd" >> ${tlabel}.sh
144    eval "$cmd"
145  fi
146
147  # Report errors
148  if test $cmd_res == 0; then
149    if "${verbose}"; then
150     printf "ok $tlabel $cmd\n" | tee -a ${testlogfile}
151    else
152     printf "ok $tlabel\n" | tee -a ${testlogfile}
153    fi
154    let success=$success+1
155  else
156    if "${verbose}"; then
157      printf "not ok $tlabel $cmd\n" | tee -a ${testlogfile}
158    else
159      printf "not ok $tlabel\n" | tee -a ${testlogfile}
160    fi
161    # We've had tests fail but stderr->stdout. Fix with this test.
162    if test -s $3; then
163       awk '{print "#\t" $0}' < $3 | tee -a ${testlogfile}
164    else
165       awk '{print "#\t" $0}' < $2 | tee -a ${testlogfile}
166    fi
167    let failed=$failed+1
168    failures="$failures $tlabel"
169  fi
170  let total=$success+$failed
171  return $cmd_res
172}
173
174function petsc_testend() {
175  logfile=$1/counts/${label}.counts
176  logdir=`dirname $logfile`
177  if ! test -d "$logdir"; then
178    mkdir -p $logdir
179  fi
180  if ! test -e "$logfile"; then
181    touch $logfile
182  fi
183  printf "total $total\n" > $logfile
184  printf "success $success\n" >> $logfile
185  printf "failed $failed\n" >> $logfile
186  printf "failures $failures\n" >> $logfile
187  if test ${todo} -gt 0; then
188    printf "todo $todo\n" >> $logfile
189  fi
190  if test ${skip} -gt 0; then
191    printf "skip $skip\n" >> $logfile
192  fi
193  ENDTIME=`date +%s`
194  printf "time $(($ENDTIME - $STARTTIME))\n" >> $logfile
195  if $cleanup; then
196    echo "Cleaning up"
197    /bin/rm -f $rmfiles
198  fi
199}
200
201function petsc_mpiexec_valgrind() {
202  mpiexec=$1;shift
203  npopt=$1;shift
204  np=$1;shift
205
206  valgrind="valgrind -q --tool=memcheck --leak-check=yes --num-callers=20 --track-origins=yes --suppressions=$petsc_bindir/maint/petsc-val.supp"
207
208  $mpiexec $npopt $np $valgrind $*
209}
210export LC_ALL=C
211