1 2 3scriptname=`basename $0` 4rundir=${scriptname%.sh} 5TIMEOUT=60 6 7if test "$PWD"!=`dirname $0`; then 8 cd `dirname $0` 9fi 10if test -d "${rundir}" && test -n "${rundir}"; then 11 rm -f ${rundir}/*.tmp ${rundir}/*.err ${rundir}/*.out 12fi 13mkdir -p ${rundir} 14if test -n "${runfiles}"; then 15 for runfile in ${runfiles}; do 16 subdir=`dirname ${runfile}` 17 mkdir -p ${rundir}/${subdir} 18 cp -r ${runfile} ${rundir}/${subdir} 19 done 20fi 21cd ${rundir} 22 23# 24# Method to print out general and script specific options 25# 26print_usage() { 27 28cat >&2 <<EOF 29Usage: $0 [options] 30 31OPTIONS 32 -a <args> ......... Override default arguments 33 -c <cleanup> ...... Cleanup (remove generated files) 34 -d ................ Launch in debugger 35 -e <args> ......... Add extra arguments to default 36 -f ................ force attempt to run test that would otherwise be skipped 37 -h ................ help: print this message 38 -n <integer> ...... Override the number of processors to use 39 -j ................ Pass -j to petscdiff (just use diff) 40 -J <arg> .......... Pass -J to petscdiff (just use diff with arg) 41 -m ................ Update results using petscdiff 42 -M ................ Update alt files using petscdiff 43 -t ................ Override the default timeout (default=$TIMEOUT sec) 44 -V ................ run Valgrind 45 -v ................ Verbose: Print commands 46EOF 47 48 if declare -f extrausage > /dev/null; then extrausage; fi 49 exit $1 50} 51### 52## Arguments for overriding things 53# 54verbose=false 55cleanup=false 56debugger=false 57force=false 58diff_flags="" 59while getopts "a:cde:fhjJ:mMn:t:vV" arg 60do 61 case $arg in 62 a ) args="$OPTARG" ;; 63 c ) cleanup=true ;; 64 d ) debugger=true ;; 65 e ) extra_args="$OPTARG" ;; 66 f ) force=true ;; 67 h ) print_usage; exit ;; 68 n ) nsize="$OPTARG" ;; 69 j ) diff_flags="-j" ;; 70 J ) diff_flags="-J $OPTARG" ;; 71 m ) diff_flags="-m" ;; 72 M ) diff_flags="-M" ;; 73 t ) TIMEOUT=$OPTARG ;; 74 V ) mpiexec="petsc_mpiexec_valgrind $mpiexec" ;; 75 v ) verbose=true ;; 76 *) # To take care of any extra args 77 if test -n "$OPTARG"; then 78 eval $arg=\"$OPTARG\" 79 else 80 eval $arg=found 81 fi 82 ;; 83 esac 84done 85shift $(( $OPTIND - 1 )) 86 87# Individual tests can extend the default 88TIMEOUT=$((TIMEOUT*timeoutfactor)) 89STARTTIME=`date +%s` 90 91if test -n "$extra_args"; then 92 args="$args $extra_args" 93fi 94if $debugger; then 95 args="-start_in_debugger $args" 96fi 97 98 99# Init 100success=0; failed=0; failures=""; rmfiles="" 101total=0 102todo=-1; skip=-1 103job_level=0 104 105function petsc_testrun() { 106 # First arg = Basic command 107 # Second arg = stdout file 108 # Third arg = stderr file 109 # Fourth arg = label for reporting 110 # Fifth arg = Filter 111 rmfiles="${rmfiles} $2 $3" 112 tlabel=$4 113 filter=$5 114 job_control=true 115 cmd="$1 > $2 2> $3" 116 if test -n "$filter"; then 117 if test "${filter:0:6}"=="Error:"; then 118 job_control=false # redirection error method causes job control probs 119 filter=${filter##Error:} 120 cmd="$1 2>&1 | cat > $2" 121 fi 122 fi 123 # disable job_control on cygwin 124 if [[ `uname` =~ ^CYGWIN ]] ; then 125 job_control=false 126 fi 127 echo "$cmd" > ${tlabel}.sh; chmod 755 ${tlabel}.sh 128 129 if $job_control; then 130 # The action: 131 ( ulimit -St $TIMEOUT && eval "$cmd" ) 132 cmd_res=$? 133 # SIGXCPU=24, but some systems give our shell 128+24=152 134 test $cmd_res -eq 24 -o $cmd_res -eq 152 && echo "Exceeded timeout limit of $TIMEOUT s" >> $3 135 else 136 # The action -- assume no timeout needed 137 eval "$cmd" 138 # We are testing error codes so just make it pass 139 cmd_res=$? 140 fi 141 142 # Handle filters separately and assume no timeout check needed 143 if test -n "$filter"; then 144 cmd="cat $2 | $filter > $2.tmp 2>> $3 && mv $2.tmp $2" 145 echo "$cmd" >> ${tlabel}.sh 146 eval "$cmd" 147 fi 148 149 # Report errors 150 if test $cmd_res == 0; then 151 if "${verbose}"; then 152 printf "ok $tlabel $cmd\n" | tee -a ${testlogfile} 153 else 154 printf "ok $tlabel\n" | tee -a ${testlogfile} 155 fi 156 let success=$success+1 157 else 158 if "${verbose}"; then 159 printf "not ok $tlabel $cmd\n" | tee -a ${testlogfile} 160 else 161 printf "not ok $tlabel\n" | tee -a ${testlogfile} 162 fi 163 # We've had tests fail but stderr->stdout. Fix with this test. 164 if test -s $3; then 165 awk '{print "#\t" $0}' < $3 | tee -a ${testlogfile} 166 else 167 awk '{print "#\t" $0}' < $2 | tee -a ${testlogfile} 168 fi 169 let failed=$failed+1 170 failures="$failures $tlabel" 171 fi 172 let total=$success+$failed 173 return $cmd_res 174} 175 176function petsc_testend() { 177 logfile=$1/counts/${label}.counts 178 logdir=`dirname $logfile` 179 if ! test -d "$logdir"; then 180 mkdir -p $logdir 181 fi 182 if ! test -e "$logfile"; then 183 touch $logfile 184 fi 185 printf "total $total\n" > $logfile 186 printf "success $success\n" >> $logfile 187 printf "failed $failed\n" >> $logfile 188 printf "failures $failures\n" >> $logfile 189 if test ${todo} -gt 0; then 190 printf "todo $todo\n" >> $logfile 191 fi 192 if test ${skip} -gt 0; then 193 printf "skip $skip\n" >> $logfile 194 fi 195 ENDTIME=`date +%s` 196 printf "time $(($ENDTIME - $STARTTIME))\n" >> $logfile 197 if $cleanup; then 198 echo "Cleaning up" 199 /bin/rm -f $rmfiles 200 fi 201} 202 203function petsc_mpiexec_valgrind() { 204 mpiexec=$1;shift 205 npopt=$1;shift 206 np=$1;shift 207 208 valgrind="valgrind -q --tool=memcheck --leak-check=yes --num-callers=20 --track-origins=yes --suppressions=$petsc_bindir/maint/petsc-val.supp" 209 210 $mpiexec $npopt $np $valgrind $* 211} 212export LC_ALL=C 213