xref: /petsc/config/petsc_harness.sh (revision 0983a91458060b01e5190662929b471b4e91227f)
1
2
3scriptname=`basename $0`
4rundir=${scriptname%.sh}
5
6if test "$PWD"!=`dirname $0`; then
7  cd `dirname $0`
8fi
9mkdir -p ${rundir}
10cd ${rundir}
11
12#
13# Method to print out general and script specific options
14#
15print_usage() {
16
17cat >&2 <<EOF
18Usage: $0 [options]
19
20OPTIONS
21  -a <args> ......... Override default arguments
22  -c <cleanup> ...... Cleanup (remove generated files)
23  -e <args> ......... Add extra arguments to default
24  -h ................ help: print this message
25  -n <integer> ...... Override the number of processors to use
26  -o <output file> .. Override default output file to diff with
27  -t <testname> ..... Override test name
28  -v ................ Verbose: Print commands
29EOF
30
31  if declare -f extrausage > /dev/null; then extrausage; fi
32  exit $1
33}
34###
35##  Arguments for overriding things
36#
37verbose=false
38cleanup=false
39while getopts "a:c:e:hn:o:t:v" arg
40do
41  case $arg in
42    a ) args=$OPTARG     ;;
43    c ) cleanup=true     ;;
44    e ) extra_args=$OPTARG     ;;
45    h ) print_usage; exit ;;
46    n ) nsize=$OPTARG     ;;
47    o ) output_file=$OPTARG     ;;
48    t ) testname=$OPTARG     ;;
49    v ) verbose=true     ;;
50    *)  # To take care of any extra args
51      if test -n "$OPTARG"; then
52        eval $arg=\"$OPTARG\"
53      else
54        eval $arg=found
55      fi
56      ;;
57  esac
58done
59shift $(( $OPTIND - 1 ))
60
61if test -n "$extra_args"; then
62  args="$args $extra_args"
63fi
64
65# Init
66success=0; failed=0; failures=""; rmfiles=""
67total=0
68todo=-1; skip=-1
69
70function petsc_testrun() {
71  # First arg = Basic command
72  # Second arg = stdout file
73  # Third arg = stderr file
74  # Fourth arg = label for reporting
75  # Fifth arg = Filter
76  rmfiles="${rmfiles} $2 $3"
77  tlabel=$4
78  filter=$5
79
80  if test -z "$filter"; then
81    cmd="$1 > $2 2> $3"
82  else
83    cmd="$1 | $filter > $2 2> $3"
84  fi
85  if "${verbose}"; then
86    printf "${cmd}\n"
87  fi
88  eval $cmd
89  if test $? == 0; then
90      printf "ok $tlabel $cmd\n"
91      let success=$success+1
92  else
93      printf "not ok $tlabel\n"
94      awk '{print "#\t" $0}' < $3
95      let failed=$failed+1
96      failures="$failures $tlabel"
97  fi
98  let total=$success+$failed
99}
100
101function petsc_testend() {
102  logfile=$1/counts/${label}.counts
103  logdir=`dirname $logfile`
104  if ! test -d "$logdir"; then
105    mkdir -p $logdir
106  fi
107  if ! test -e "$logfile"; then
108    touch $logfile
109  fi
110  printf "total $total\n" > $logfile
111  printf "success $success\n" >> $logfile
112  printf "failed $failed\n" >> $logfile
113  printf "failures $failures\n" >> $logfile
114  if test ${todo} -gt 0; then
115    printf "todo $todo\n" >> $logfile
116  fi
117  if test ${skip} -gt 0; then
118    printf "skip $skip\n" >> $logfile
119  fi
120  if $cleanup; then
121    echo "Cleaning up"
122    /bin/rm -f $rmfiles
123  fi
124}
125