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 eval $cmd 86 if test $? == 0; then 87 if "${verbose}"; then 88 printf "ok $tlabel $cmd\n" 89 else 90 printf "ok $tlabel\n" 91 fi 92 let success=$success+1 93 else 94 if "${verbose}"; then 95 printf "not ok $tlabel $cmd\n" 96 else 97 printf "not ok $tlabel\n" 98 fi 99 awk '{print "#\t" $0}' < $3 100 let failed=$failed+1 101 failures="$failures $tlabel" 102 fi 103 let total=$success+$failed 104} 105 106function petsc_testend() { 107 logfile=$1/counts/${label}.counts 108 logdir=`dirname $logfile` 109 if ! test -d "$logdir"; then 110 mkdir -p $logdir 111 fi 112 if ! test -e "$logfile"; then 113 touch $logfile 114 fi 115 printf "total $total\n" > $logfile 116 printf "success $success\n" >> $logfile 117 printf "failed $failed\n" >> $logfile 118 printf "failures $failures\n" >> $logfile 119 if test ${todo} -gt 0; then 120 printf "todo $todo\n" >> $logfile 121 fi 122 if test ${skip} -gt 0; then 123 printf "skip $skip\n" >> $logfile 124 fi 125 if $cleanup; then 126 echo "Cleaning up" 127 /bin/rm -f $rmfiles 128 fi 129} 130