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