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