xref: /petsc/config/petsc_harness.sh (revision 5e71baeff2f3138f93cd4f5927dfd596eb8325cc)
1
2
3scriptname=`basename $0`
4rundir=${scriptname%.sh}
5TIMEOUT=60
6
7if test "$PWD"!=`dirname $0`; then
8  cd `dirname $0`
9fi
10mkdir -p ${rundir}
11if test -n "${runfiles}"; then
12  cp ${runfiles} ${rundir}
13fi
14cd ${rundir}
15
16#
17# Method to print out general and script specific options
18#
19print_usage() {
20
21cat >&2 <<EOF
22Usage: $0 [options]
23
24OPTIONS
25  -a <args> ......... Override default arguments
26  -c <cleanup> ...... Cleanup (remove generated files)
27  -d ................ Launch in debugger
28  -e <args> ......... Add extra arguments to default
29  -f ................ force attempt to run test that would otherwise be skipped
30  -h ................ help: print this message
31  -n <integer> ...... Override the number of processors to use
32  -j ................ Pass -j to petscdiff (just use diff)
33  -J <arg> .......... Pass -J to petscdiff (just use diff with arg)
34  -m ................ Update results using petscdiff
35  -t ................ Override the default timeout (default=$TIMEOUT sec)
36  -V ................ run Valgrind
37  -v ................ Verbose: Print commands
38EOF
39
40  if declare -f extrausage > /dev/null; then extrausage; fi
41  exit $1
42}
43###
44##  Arguments for overriding things
45#
46verbose=false
47cleanup=false
48debugger=false
49force=false
50diff_flags=""
51while getopts "a:cde:fhjJ:mn:t:vV" arg
52do
53  case $arg in
54    a ) args="$OPTARG"       ;;
55    c ) cleanup=true         ;;
56    d ) debugger=true        ;;
57    e ) extra_args="$OPTARG" ;;
58    f ) force=true           ;;
59    h ) print_usage; exit    ;;
60    n ) nsize="$OPTARG"      ;;
61    j ) diff_flags="-j"      ;;
62    J ) diff_flags="-J $OPTARG" ;;
63    m ) diff_flags="-m"      ;;
64    t ) TIMEOUT=$OPTARG      ;;
65    V ) mpiexec="petsc_mpiexec_valgrind $mpiexec" ;;
66    v ) verbose=true         ;;
67    *)  # To take care of any extra args
68      if test -n "$OPTARG"; then
69        eval $arg=\"$OPTARG\"
70      else
71        eval $arg=found
72      fi
73      ;;
74  esac
75done
76shift $(( $OPTIND - 1 ))
77
78# Individual tests can extend the default
79TIMEOUT=$((TIMEOUT*timeoutfactor))
80
81if test -n "$extra_args"; then
82  args="$args $extra_args"
83fi
84if $debugger; then
85  args="-start_in_debugger $args"
86fi
87
88
89# Init
90success=0; failed=0; failures=""; rmfiles=""
91total=0
92todo=-1; skip=-1
93job_level=0
94
95function petsc_testrun() {
96  # First arg = Basic command
97  # Second arg = stdout file
98  # Third arg = stderr file
99  # Fourth arg = label for reporting
100  # Fifth arg = Filter
101  rmfiles="${rmfiles} $2 $3"
102  tlabel=$4
103  filter=$5
104  job_control=true
105  cmd="$1 > $2 2> $3"
106  if test -n "$filter"; then
107    if test "${filter:0:6}"=="Error:"; then
108      job_control=false      # redirection error method causes job control probs
109      filter=${filter##Error:}
110      cmd="$1 2>&1 | cat > $2 2> $3"
111    fi
112  fi
113  echo "$cmd" > ${tlabel}.sh; chmod 755 ${tlabel}.sh
114
115  if $job_control; then
116    # The action:
117    eval "($cmd) &"
118    pid=$!
119    # Put a watcher process in that will kill a job that exceeds limit
120    $config_dir/watchtime.sh $pid $TIMEOUT &
121    watcher=$!
122
123    # See if the job we want finishes
124    wait $pid 2> /dev/null
125    cmd_res=$?
126    if ps -p $watcher > /dev/null; then
127      # Keep processes tidy by killing watcher
128      pkill -13 -P $watcher
129      wait $watcher 2>/dev/null  # Wait used here to capture the kill message
130    else
131      # Timeout
132      cmd_res=1
133      echo "Exceeded timeout limit of $TIMEOUT s" > $3
134    fi
135  else
136    # The action -- assume no timeout needed
137    eval "$cmd"
138    # We are testing error codes so just make it pass
139    cmd_res=0
140  fi
141
142  # Handle filters separately and assume no timeout check needed
143  if test -n "$filter"; then
144    cmd="cat $2 | $filter > $2.tmp 2>> $3 && mv $2.tmp $2"
145    echo "$cmd" >> ${tlabel}.sh
146    eval "$cmd"
147    let cmd_res+=$?
148  fi
149
150  # Report errors
151  if test $cmd_res == 0; then
152    if "${verbose}"; then
153     printf "ok $tlabel $cmd\n" | tee -a ${testlogfile}
154    else
155     printf "ok $tlabel\n" | tee -a ${testlogfile}
156    fi
157    let success=$success+1
158  else
159    if "${verbose}"; then
160      printf "not ok $tlabel $cmd\n" | tee -a ${testlogfile}
161    else
162      printf "not ok $tlabel\n" | tee -a ${testlogfile}
163    fi
164    awk '{print "#\t" $0}' < $3 | tee -a ${testlogfile}
165    let failed=$failed+1
166    failures="$failures $tlabel"
167  fi
168  let total=$success+$failed
169  return $cmd_res
170}
171
172function petsc_testend() {
173  logfile=$1/counts/${label}.counts
174  logdir=`dirname $logfile`
175  if ! test -d "$logdir"; then
176    mkdir -p $logdir
177  fi
178  if ! test -e "$logfile"; then
179    touch $logfile
180  fi
181  printf "total $total\n" > $logfile
182  printf "success $success\n" >> $logfile
183  printf "failed $failed\n" >> $logfile
184  printf "failures $failures\n" >> $logfile
185  if test ${todo} -gt 0; then
186    printf "todo $todo\n" >> $logfile
187  fi
188  if test ${skip} -gt 0; then
189    printf "skip $skip\n" >> $logfile
190  fi
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