xref: /petsc/config/petsc_harness.sh (revision 7a8531093c02f6f11a5c482f0626d2b5426d6fe2)
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    cmd="$1 2> $3 | $filter > $2 2>> $3"
106  fi
107  echo $cmd > ${tlabel}.sh; chmod 755 ${tlabel}.sh
108  eval "$cmd; typeset -a cmd_errstat=(\${PIPESTATUS[@]})"
109  let cmd_res=0
110  for i in ${cmd_errstat[@]}; do let cmd_res+=$i; done
111
112  if test $cmd_res == 0; then
113    if "${verbose}"; then
114     printf "ok $tlabel $cmd\n"
115    else
116     printf "ok $tlabel\n"
117    fi
118    let success=$success+1
119  else
120    if "${verbose}"; then
121      printf "not ok $tlabel $cmd\n"
122    else
123      printf "not ok $tlabel\n"
124    fi
125    awk '{print "#\t" $0}' < $3
126    let failed=$failed+1
127    failures="$failures $tlabel"
128  fi
129  let total=$success+$failed
130  return $cmd_res
131}
132
133function petsc_testend() {
134  logfile=$1/counts/${label}.counts
135  logdir=`dirname $logfile`
136  if ! test -d "$logdir"; then
137    mkdir -p $logdir
138  fi
139  if ! test -e "$logfile"; then
140    touch $logfile
141  fi
142  printf "total $total\n" > $logfile
143  printf "success $success\n" >> $logfile
144  printf "failed $failed\n" >> $logfile
145  printf "failures $failures\n" >> $logfile
146  if test ${todo} -gt 0; then
147    printf "todo $todo\n" >> $logfile
148  fi
149  if test ${skip} -gt 0; then
150    printf "skip $skip\n" >> $logfile
151  fi
152  if $cleanup; then
153    echo "Cleaning up"
154    /bin/rm -f $rmfiles
155  fi
156}
157
158function petsc_mpiexec_valgrind() {
159  mpiexec=$1;shift
160  npopt=$1;shift
161  np=$1;shift
162
163  valgrind="valgrind -q --tool=memcheck --leak-check=yes --num-callers=20 --track-origins=yes --suppressions=$petsc_dir/bin/maint/petsc-val.supp"
164  $mpiexec $npopt $np $valgrind $*
165}
166export LC_ALL=C
167