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