xref: /petsc/config/petsc_harness.sh (revision e50b40e0a257baeffc6f12ca46316aaed9db0ca0)
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    if test "$2" == "$3"; then
88     cmd="$1 > $2 2>> $3"
89    else
90     cmd="$1 > $2 2> $3"
91    fi
92  else
93    cmd="$1 2>&1 | $filter > $2 2> $3"
94  fi
95  eval $cmd
96  if test $? == 0; then
97    if "${verbose}"; then
98     printf "ok $tlabel $cmd\n"
99    else
100     printf "ok $tlabel\n"
101    fi
102    let success=$success+1
103  else
104    if "${verbose}"; then
105      printf "not ok $tlabel $cmd\n"
106    else
107      printf "not ok $tlabel\n"
108    fi
109    awk '{print "#\t" $0}' < $3
110    let failed=$failed+1
111    failures="$failures $tlabel"
112  fi
113  let total=$success+$failed
114}
115
116function petsc_testend() {
117  logfile=$1/counts/${label}.counts
118  logdir=`dirname $logfile`
119  if ! test -d "$logdir"; then
120    mkdir -p $logdir
121  fi
122  if ! test -e "$logfile"; then
123    touch $logfile
124  fi
125  printf "total $total\n" > $logfile
126  printf "success $success\n" >> $logfile
127  printf "failed $failed\n" >> $logfile
128  printf "failures $failures\n" >> $logfile
129  if test ${todo} -gt 0; then
130    printf "todo $todo\n" >> $logfile
131  fi
132  if test ${skip} -gt 0; then
133    printf "skip $skip\n" >> $logfile
134  fi
135  if $cleanup; then
136    echo "Cleaning up"
137    /bin/rm -f $rmfiles
138  fi
139}
140
141function petsc_mpiexec_valgrind() {
142  mpiexec=$1;shift
143  npopt=$1;shift
144  np=$1;shift
145
146  valgrind="valgrind -q --tool=memcheck --leak-check=yes --num-callers=20 --track-origins=yes --suppressions=$petsc_dir/bin/maint/petsc-val.supp"
147  $mpiexec $npopt $np $valgrind $*
148}
149export LC_ALL=C
150