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