xref: /petsc/config/petsc_harness.sh (revision 9b2db2227e056d74e10acbb4c7c75cbd904ecd7e)
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  echo "$cmd" > ${tlabel}.sh; chmod 755 ${tlabel}.sh
122
123  if $job_control; then
124    # The action:
125    ( ulimit -St $TIMEOUT && eval "$cmd" )
126    cmd_res=$?
127    # SIGXCPU=24, but some systems give our shell 128+24=152
128    test $cmd_res -eq 24 -o $cmd_res -eq 152 && echo "Exceeded timeout limit of $TIMEOUT s" >> $3
129  else
130    # The action -- assume no timeout needed
131    eval "$cmd"
132    # We are testing error codes so just make it pass
133    cmd_res=$?
134  fi
135
136  # Handle filters separately and assume no timeout check needed
137  if test -n "$filter"; then
138    cmd="cat $2 | $filter > $2.tmp 2>> $3 && mv $2.tmp $2"
139    echo "$cmd" >> ${tlabel}.sh
140    eval "$cmd"
141  fi
142
143  # Report errors
144  if test $cmd_res == 0; then
145    if "${verbose}"; then
146     printf "ok $tlabel $cmd\n" | tee -a ${testlogfile}
147    else
148     printf "ok $tlabel\n" | tee -a ${testlogfile}
149    fi
150    let success=$success+1
151  else
152    if "${verbose}"; then
153      printf "not ok $tlabel $cmd\n" | tee -a ${testlogfile}
154    else
155      printf "not ok $tlabel\n" | tee -a ${testlogfile}
156    fi
157    # We've had tests fail but stderr->stdout. Fix with this test.
158    if test -s $3; then
159       awk '{print "#\t" $0}' < $3 | tee -a ${testlogfile}
160    else
161       awk '{print "#\t" $0}' < $2 | tee -a ${testlogfile}
162    fi
163    let failed=$failed+1
164    failures="$failures $tlabel"
165  fi
166  let total=$success+$failed
167  return $cmd_res
168}
169
170function petsc_testend() {
171  logfile=$1/counts/${label}.counts
172  logdir=`dirname $logfile`
173  if ! test -d "$logdir"; then
174    mkdir -p $logdir
175  fi
176  if ! test -e "$logfile"; then
177    touch $logfile
178  fi
179  printf "total $total\n" > $logfile
180  printf "success $success\n" >> $logfile
181  printf "failed $failed\n" >> $logfile
182  printf "failures $failures\n" >> $logfile
183  if test ${todo} -gt 0; then
184    printf "todo $todo\n" >> $logfile
185  fi
186  if test ${skip} -gt 0; then
187    printf "skip $skip\n" >> $logfile
188  fi
189  ENDTIME=`date +%s`
190  printf "time $(($ENDTIME - $STARTTIME))\n" >> $logfile
191  if $cleanup; then
192    echo "Cleaning up"
193    /bin/rm -f $rmfiles
194  fi
195}
196
197function petsc_mpiexec_valgrind() {
198  mpiexec=$1;shift
199  npopt=$1;shift
200  np=$1;shift
201
202  valgrind="valgrind -q --tool=memcheck --leak-check=yes --num-callers=20 --track-origins=yes --suppressions=$petsc_bindir/maint/petsc-val.supp"
203
204  $mpiexec $npopt $np $valgrind $*
205}
206export LC_ALL=C
207