xref: /petsc/config/petsc_harness.sh (revision 1b548e17537f7306024a2b632b088385e4abec4a)
1
2
3scriptname=`basename $0`
4rundir=${scriptname%.sh}
5
6if test "$PWD"!=`dirname $0`; then
7  cd `dirname $0`
8fi
9mkdir -p ${rundir}
10if test -n "${runfiles}"; then
11  cp ${runfiles} ${rundir}
12fi
13cd ${rundir}
14
15#
16# Method to print out general and script specific options
17#
18print_usage() {
19
20cat >&2 <<EOF
21Usage: $0 [options]
22
23OPTIONS
24  -a <args> ......... Override default arguments
25  -c <cleanup> ...... Cleanup (remove generated files)
26  -d ................ Launch in debugger
27  -e <args> ......... Add extra arguments to default
28  -f ................ force attempt to run test that would otherwise be skipped
29  -h ................ help: print this message
30  -n <integer> ...... Override the number of processors to use
31  -j ................ Pass -j to petscdiff (just use diff)
32  -J <arg> .......... Pass -J to petscdiff (just use diff with arg)
33  -m ................ Update results using petscdiff
34  -V ................ run Valgrind
35  -v ................ Verbose: Print commands
36EOF
37
38  if declare -f extrausage > /dev/null; then extrausage; fi
39  exit $1
40}
41###
42##  Arguments for overriding things
43#
44verbose=false
45cleanup=false
46debugger=false
47force=false
48diff_flags=""
49while getopts "a:cde:fhjJ:mn:vV" arg
50do
51  case $arg in
52    a ) args="$OPTARG"       ;;
53    c ) cleanup=true         ;;
54    d ) debugger=true        ;;
55    e ) extra_args="$OPTARG" ;;
56    f ) force=true           ;;
57    h ) print_usage; exit    ;;
58    n ) nsize="$OPTARG"      ;;
59    j ) diff_flags="-j"      ;;
60    J ) diff_flags="-J $OPTARG" ;;
61    m ) diff_flags="-m"      ;;
62    V ) mpiexec="petsc_mpiexec_valgrind $mpiexec" ;;
63    v ) verbose=true         ;;
64    *)  # To take care of any extra args
65      if test -n "$OPTARG"; then
66        eval $arg=\"$OPTARG\"
67      else
68        eval $arg=found
69      fi
70      ;;
71  esac
72done
73shift $(( $OPTIND - 1 ))
74
75if test -n "$extra_args"; then
76  args="$args $extra_args"
77fi
78if $debugger; then
79  args="-start_in_debugger $args"
80fi
81
82
83# Init
84success=0; failed=0; failures=""; rmfiles=""
85total=0
86todo=-1; skip=-1
87
88function petsc_testrun() {
89  # First arg = Basic command
90  # Second arg = stdout file
91  # Third arg = stderr file
92  # Fourth arg = label for reporting
93  # Fifth arg = Filter
94  rmfiles="${rmfiles} $2 $3"
95  tlabel=$4
96  filter=$5
97  # Determining whether this test passes or fails is tricky because of filters
98  # and eval.  Use sum of all parts of a potential pipe to determine status. See:
99  #  https://stackoverflow.com/questions/24734850/how-to-get-the-exit-status-of-the-first-command-in-a-pipe
100  #  http://www.unix.com/shell-programming-and-scripting/128869-creating-run-script-getting-pipestatus-eval.html
101
102  if test -z "$filter"; then
103    cmd="$1 > $2 2> $3"
104  else
105    if test "${filter:0:6}"=="Error:"; then
106      filter=${filter##Error:}
107      cmd="#!/bin/bash eval $1 2>&1  | $filter > $2 2> $3"
108    else
109      cmd="$1 2> $3 | $filter > $2 2>> $3"
110    fi
111  fi
112  echo $cmd > ${tlabel}.sh; chmod 755 ${tlabel}.sh
113  eval "$cmd; typeset -a cmd_errstat=(\${PIPESTATUS[@]})"
114  let cmd_res=0
115  for i in ${cmd_errstat[@]}; do let cmd_res+=$i; done
116
117  if test $cmd_res == 0; then
118    if "${verbose}"; then
119     printf "ok $tlabel $cmd\n"
120    else
121     printf "ok $tlabel\n"
122    fi
123    let success=$success+1
124  else
125    if "${verbose}"; then
126      printf "not ok $tlabel $cmd\n"
127    else
128      printf "not ok $tlabel\n"
129    fi
130    awk '{print "#\t" $0}' < $3
131    let failed=$failed+1
132    failures="$failures $tlabel"
133  fi
134  let total=$success+$failed
135  return $cmd_res
136}
137
138function petsc_testend() {
139  logfile=$1/counts/${label}.counts
140  logdir=`dirname $logfile`
141  if ! test -d "$logdir"; then
142    mkdir -p $logdir
143  fi
144  if ! test -e "$logfile"; then
145    touch $logfile
146  fi
147  printf "total $total\n" > $logfile
148  printf "success $success\n" >> $logfile
149  printf "failed $failed\n" >> $logfile
150  printf "failures $failures\n" >> $logfile
151  if test ${todo} -gt 0; then
152    printf "todo $todo\n" >> $logfile
153  fi
154  if test ${skip} -gt 0; then
155    printf "skip $skip\n" >> $logfile
156  fi
157  if $cleanup; then
158    echo "Cleaning up"
159    /bin/rm -f $rmfiles
160  fi
161}
162
163function petsc_mpiexec_valgrind() {
164  mpiexec=$1;shift
165  npopt=$1;shift
166  np=$1;shift
167
168  valgrind="valgrind -q --tool=memcheck --leak-check=yes --num-callers=20 --track-origins=yes --suppressions=$petsc_dir/bin/maint/petsc-val.supp"
169  $mpiexec $npopt $np $valgrind $*
170}
171export LC_ALL=C
172