xref: /petsc/config/petsc_harness.sh (revision ec4485d6ebb8fd2c3c1e36c227d007bdd5acb860)
1
2
3scriptname=`basename $0`
4rundir=${scriptname%.sh}
5TIMEOUT=300
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  kill_job=false
116  if $job_control; then
117    # The action:
118    eval "($cmd) &"
119    pid=$!
120    # Put a watcher process in that will kill a job that exceeds limit
121    $petsc_dir/config/watchtime.sh $pid $TIMEOUT &
122    watcher=$!
123
124    # See if the job we want finishes
125    wait $pid 2> /dev/null
126    cmd_res=$?
127    if ps -p $watcher > /dev/null; then
128      # Keep processes tidy by killing watcher
129      kill -s PIPE $watcher
130      wait $watcher 2>/dev/null  # Wait used here to capture the kill message
131    else
132      # Timeout
133      cmd_res=1
134      echo "Exceeded timeout limit of $TIMEOUT s" > $3
135    fi
136  else
137    # The action -- assume no timeout needed
138    eval $cmd
139    # We are testing error codes so just make it pass
140    cmd_res=0
141  fi
142
143  # Handle filters separately and assume no timeout check needed
144  if test -n "$filter"; then
145    cmd="cat $2 | $filter > $2.tmp 2>> $3 && mv $2.tmp $2"
146    echo $cmd >> ${tlabel}.sh
147    eval "$cmd"
148    let cmd_res+=$?
149  fi
150
151  # Report errors
152  if test $cmd_res == 0; then
153    if "${verbose}"; then
154     printf "ok $tlabel $cmd\n" | tee -a ${testlogfile}
155    else
156     printf "ok $tlabel\n" | tee -a ${testlogfile}
157    fi
158    let success=$success+1
159  else
160    if "${verbose}"; then
161      printf "not ok $tlabel $cmd\n" | tee -a ${testlogfile}
162    else
163      printf "not ok $tlabel\n" | tee -a ${testlogfile}
164    fi
165    awk '{print "#\t" $0}' < $3 | tee -a ${testlogfile}
166    let failed=$failed+1
167    failures="$failures $tlabel"
168  fi
169  let total=$success+$failed
170  return $cmd_res
171}
172
173function petsc_testend() {
174  logfile=$1/counts/${label}.counts
175  logdir=`dirname $logfile`
176  if ! test -d "$logdir"; then
177    mkdir -p $logdir
178  fi
179  if ! test -e "$logfile"; then
180    touch $logfile
181  fi
182  printf "total $total\n" > $logfile
183  printf "success $success\n" >> $logfile
184  printf "failed $failed\n" >> $logfile
185  printf "failures $failures\n" >> $logfile
186  if test ${todo} -gt 0; then
187    printf "todo $todo\n" >> $logfile
188  fi
189  if test ${skip} -gt 0; then
190    printf "skip $skip\n" >> $logfile
191  fi
192  if $cleanup; then
193    echo "Cleaning up"
194    /bin/rm -f $rmfiles
195  fi
196}
197
198function petsc_mpiexec_valgrind() {
199  mpiexec=$1;shift
200  npopt=$1;shift
201  np=$1;shift
202
203  valgrind="valgrind -q --tool=memcheck --leak-check=yes --num-callers=20 --track-origins=yes --suppressions=$petsc_dir/bin/maint/petsc-val.supp"
204  $mpiexec $npopt $np $valgrind $*
205}
206export LC_ALL=C
207