xref: /petsc/config/petsc_harness.sh (revision 4b2e7f16238410da1f2e51bff8dd1a9ccef4b84f)
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  -o <output file> .. Override default output file to diff with
30  -t <testname> ..... Override test name
31  -v ................ Verbose: Print commands
32EOF
33
34  if declare -f extrausage > /dev/null; then extrausage; fi
35  exit $1
36}
37###
38##  Arguments for overriding things
39#
40verbose=false
41cleanup=false
42while getopts "a:c:e:hn:o:t:v" arg
43do
44  case $arg in
45    a ) args=$OPTARG     ;;
46    c ) cleanup=true     ;;
47    e ) extra_args=$OPTARG     ;;
48    h ) print_usage; exit ;;
49    n ) nsize=$OPTARG     ;;
50    o ) output_file=$OPTARG     ;;
51    t ) testname=$OPTARG     ;;
52    v ) verbose=true     ;;
53    *)  # To take care of any extra args
54      if test -n "$OPTARG"; then
55        eval $arg=\"$OPTARG\"
56      else
57        eval $arg=found
58      fi
59      ;;
60  esac
61done
62shift $(( $OPTIND - 1 ))
63
64if test -n "$extra_args"; then
65  args="$args $extra_args"
66fi
67
68# Init
69success=0; failed=0; failures=""; rmfiles=""
70total=0
71todo=-1; skip=-1
72
73function petsc_testrun() {
74  # First arg = Basic command
75  # Second arg = stdout file
76  # Third arg = stderr file
77  # Fourth arg = label for reporting
78  # Fifth arg = Filter
79  rmfiles="${rmfiles} $2 $3"
80  tlabel=$4
81  filter=$5
82
83  if test -z "$filter"; then
84    cmd="$1 > $2 2> $3"
85  else
86    cmd="$1 2>&1 | $filter > $2 2> $3"
87  fi
88  eval $cmd
89  if test $? == 0; then
90    if "${verbose}"; then
91     printf "ok $tlabel $cmd\n"
92    else
93     printf "ok $tlabel\n"
94    fi
95    let success=$success+1
96  else
97    if "${verbose}"; then
98      printf "not ok $tlabel $cmd\n"
99    else
100      printf "not ok $tlabel\n"
101    fi
102    awk '{print "#\t" $0}' < $3
103    let failed=$failed+1
104    failures="$failures $tlabel"
105  fi
106  let total=$success+$failed
107}
108
109function petsc_testend() {
110  logfile=$1/counts/${label}.counts
111  logdir=`dirname $logfile`
112  if ! test -d "$logdir"; then
113    mkdir -p $logdir
114  fi
115  if ! test -e "$logfile"; then
116    touch $logfile
117  fi
118  printf "total $total\n" > $logfile
119  printf "success $success\n" >> $logfile
120  printf "failed $failed\n" >> $logfile
121  printf "failures $failures\n" >> $logfile
122  if test ${todo} -gt 0; then
123    printf "todo $todo\n" >> $logfile
124  fi
125  if test ${skip} -gt 0; then
126    printf "skip $skip\n" >> $logfile
127  fi
128  if $cleanup; then
129    echo "Cleaning up"
130    /bin/rm -f $rmfiles
131  fi
132}
133
134export LC_ALL=C
135