xref: /petsc/config/petsc_harness.sh (revision c1eb5a5ca9cd228c19ef6c5ae67be6af3c6f4e19)
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  -e <args> ......... Add extra arguments to default
27  -h ................ help: print this message
28  -n <integer> ...... Override the number of processors to use
29  -j ................ Pass -j to petscdiff (just use diff)
30  -J <arg> .......... Pass -J to petscdiff (just use diff with arg)
31  -m ................ Update results using petscdiff
32  -v ................ Verbose: Print commands
33EOF
34
35  if declare -f extrausage > /dev/null; then extrausage; fi
36  exit $1
37}
38###
39##  Arguments for overriding things
40#
41verbose=false
42cleanup=false
43diff_flags=""
44while getopts "a:ce:hjJ:mn:v" arg
45do
46  case $arg in
47    a ) args="$OPTARG"       ;;
48    c ) cleanup=true         ;;
49    e ) extra_args="$OPTARG" ;;
50    h ) print_usage; exit    ;;
51    n ) nsize="$OPTARG"      ;;
52    j ) diff_flags="-j"      ;;
53    J ) diff_flags="-J $OPTARG" ;;
54    m ) diff_flags="-m"      ;;
55    v ) verbose=true         ;;
56    *)  # To take care of any extra args
57      if test -n "$OPTARG"; then
58        eval $arg=\"$OPTARG\"
59      else
60        eval $arg=found
61      fi
62      ;;
63  esac
64done
65shift $(( $OPTIND - 1 ))
66
67if test -n "$extra_args"; then
68  args="$args $extra_args"
69fi
70
71# Init
72success=0; failed=0; failures=""; rmfiles=""
73total=0
74todo=-1; skip=-1
75
76function petsc_testrun() {
77  # First arg = Basic command
78  # Second arg = stdout file
79  # Third arg = stderr file
80  # Fourth arg = label for reporting
81  # Fifth arg = Filter
82  rmfiles="${rmfiles} $2 $3"
83  tlabel=$4
84  filter=$5
85
86  if test -z "$filter"; then
87    cmd="$1 > $2 2> $3"
88  else
89    cmd="$1 2>&1 | $filter > $2 2> $3"
90  fi
91  eval $cmd
92  if test $? == 0; then
93    if "${verbose}"; then
94     printf "ok $tlabel $cmd\n"
95    else
96     printf "ok $tlabel\n"
97    fi
98    let success=$success+1
99  else
100    if "${verbose}"; then
101      printf "not ok $tlabel $cmd\n"
102    else
103      printf "not ok $tlabel\n"
104    fi
105    awk '{print "#\t" $0}' < $3
106    let failed=$failed+1
107    failures="$failures $tlabel"
108  fi
109  let total=$success+$failed
110}
111
112function petsc_testend() {
113  logfile=$1/counts/${label}.counts
114  logdir=`dirname $logfile`
115  if ! test -d "$logdir"; then
116    mkdir -p $logdir
117  fi
118  if ! test -e "$logfile"; then
119    touch $logfile
120  fi
121  printf "total $total\n" > $logfile
122  printf "success $success\n" >> $logfile
123  printf "failed $failed\n" >> $logfile
124  printf "failures $failures\n" >> $logfile
125  if test ${todo} -gt 0; then
126    printf "todo $todo\n" >> $logfile
127  fi
128  if test ${skip} -gt 0; then
129    printf "skip $skip\n" >> $logfile
130  fi
131  if $cleanup; then
132    echo "Cleaning up"
133    /bin/rm -f $rmfiles
134  fi
135}
136
137function petsc_mpiexec_valgrind() {
138  mpiexec=$1;shift
139  npopt=$1;shift
140  np=$1;shift
141
142  valgrind="valgrind -q --tool=memcheck --leak-check=yes --num-callers=20 --track-origins=yes --suppressions=$petsc_dir/bin/maint/petsc-val.supp"
143  $mpiexec $npopt $np $valgrind $*
144}
145export LC_ALL=C
146