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