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 -j ................ Pass -j to petscdiff (just use diff) 30 -J <arg> .......... Pass -J to petscdiff (just use diff with arg) 31 -m ................ Update results using petscdiff 32 -V ................ run Valgrind 33 -v ................ Verbose: Print commands 34EOF 35 36 if declare -f extrausage > /dev/null; then extrausage; fi 37 exit $1 38} 39### 40## Arguments for overriding things 41# 42verbose=false 43cleanup=false 44diff_flags="" 45while getopts "a:ce:hjJ:mn:vV" arg 46do 47 case $arg in 48 a ) args="$OPTARG" ;; 49 c ) cleanup=true ;; 50 e ) extra_args="$OPTARG" ;; 51 h ) print_usage; exit ;; 52 n ) nsize="$OPTARG" ;; 53 j ) diff_flags="-j" ;; 54 J ) diff_flags="-J $OPTARG" ;; 55 m ) diff_flags="-m" ;; 56 V ) mpiexec="petsc_mpiexec_valgrind $mpiexec" ;; 57 v ) verbose=true ;; 58 *) # To take care of any extra args 59 if test -n "$OPTARG"; then 60 eval $arg=\"$OPTARG\" 61 else 62 eval $arg=found 63 fi 64 ;; 65 esac 66done 67shift $(( $OPTIND - 1 )) 68 69if test -n "$extra_args"; then 70 args="$args $extra_args" 71fi 72 73# Init 74success=0; failed=0; failures=""; rmfiles="" 75total=0 76todo=-1; skip=-1 77 78function petsc_testrun() { 79 # First arg = Basic command 80 # Second arg = stdout file 81 # Third arg = stderr file 82 # Fourth arg = label for reporting 83 # Fifth arg = Filter 84 rmfiles="${rmfiles} $2 $3" 85 tlabel=$4 86 filter=$5 87 88 if test -z "$filter"; then 89 if test "$2" == "$3"; then 90 cmd="$1 > $2 2>> $3" 91 else 92 cmd="$1 > $2 2> $3" 93 fi 94 else 95 cmd="$1 2>&1 | $filter > $2 2> $3" 96 fi 97 eval $cmd 98 if test $? == 0; then 99 if "${verbose}"; then 100 printf "ok $tlabel $cmd\n" 101 else 102 printf "ok $tlabel\n" 103 fi 104 let success=$success+1 105 else 106 if "${verbose}"; then 107 printf "not ok $tlabel $cmd\n" 108 else 109 printf "not ok $tlabel\n" 110 fi 111 awk '{print "#\t" $0}' < $3 112 let failed=$failed+1 113 failures="$failures $tlabel" 114 fi 115 let total=$success+$failed 116} 117 118function petsc_testend() { 119 logfile=$1/counts/${label}.counts 120 logdir=`dirname $logfile` 121 if ! test -d "$logdir"; then 122 mkdir -p $logdir 123 fi 124 if ! test -e "$logfile"; then 125 touch $logfile 126 fi 127 printf "total $total\n" > $logfile 128 printf "success $success\n" >> $logfile 129 printf "failed $failed\n" >> $logfile 130 printf "failures $failures\n" >> $logfile 131 if test ${todo} -gt 0; then 132 printf "todo $todo\n" >> $logfile 133 fi 134 if test ${skip} -gt 0; then 135 printf "skip $skip\n" >> $logfile 136 fi 137 if $cleanup; then 138 echo "Cleaning up" 139 /bin/rm -f $rmfiles 140 fi 141} 142 143function petsc_mpiexec_valgrind() { 144 mpiexec=$1;shift 145 npopt=$1;shift 146 np=$1;shift 147 148 valgrind="valgrind -q --tool=memcheck --leak-check=yes --num-callers=20 --track-origins=yes --suppressions=$petsc_dir/bin/maint/petsc-val.supp" 149 $mpiexec $npopt $np $valgrind $* 150} 151export LC_ALL=C 152