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 cmd="$1 > $2 2> $3" 90 else 91 cmd="$1 2>&1 | $filter > $2 2> $3" 92 fi 93 eval $cmd 94 if test $? == 0; then 95 if "${verbose}"; then 96 printf "ok $tlabel $cmd\n" 97 else 98 printf "ok $tlabel\n" 99 fi 100 let success=$success+1 101 else 102 if "${verbose}"; then 103 printf "not ok $tlabel $cmd\n" 104 else 105 printf "not ok $tlabel\n" 106 fi 107 awk '{print "#\t" $0}' < $3 108 let failed=$failed+1 109 failures="$failures $tlabel" 110 fi 111 let total=$success+$failed 112} 113 114function petsc_testend() { 115 logfile=$1/counts/${label}.counts 116 logdir=`dirname $logfile` 117 if ! test -d "$logdir"; then 118 mkdir -p $logdir 119 fi 120 if ! test -e "$logfile"; then 121 touch $logfile 122 fi 123 printf "total $total\n" > $logfile 124 printf "success $success\n" >> $logfile 125 printf "failed $failed\n" >> $logfile 126 printf "failures $failures\n" >> $logfile 127 if test ${todo} -gt 0; then 128 printf "todo $todo\n" >> $logfile 129 fi 130 if test ${skip} -gt 0; then 131 printf "skip $skip\n" >> $logfile 132 fi 133 if $cleanup; then 134 echo "Cleaning up" 135 /bin/rm -f $rmfiles 136 fi 137} 138 139function petsc_mpiexec_valgrind() { 140 mpiexec=$1;shift 141 npopt=$1;shift 142 np=$1;shift 143 144 valgrind="valgrind -q --tool=memcheck --leak-check=yes --num-callers=20 --track-origins=yes --suppressions=$petsc_dir/bin/maint/petsc-val.supp" 145 $mpiexec $npopt $np $valgrind $* 146} 147export LC_ALL=C 148