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 -o <arg> .......... Output format: 'interactive', 'err_only' 44 -p ................ Print command: Print first command and exit 45 -t ................ Override the default timeout (default=$TIMEOUT sec) 46 -V ................ run Valgrind 47 -v ................ Verbose: Print commands 48EOF 49 50 if declare -f extrausage > /dev/null; then extrausage; fi 51 exit $1 52} 53### 54## Arguments for overriding things 55# 56output_fmt="interactive" 57verbose=false 58cleanup=false 59debugger=false 60printcmd=false 61force=false 62diff_flags="" 63while getopts "a:cde:fhjJ:mMn:o:pt:vV" arg 64do 65 case $arg in 66 a ) args="$OPTARG" ;; 67 c ) cleanup=true ;; 68 d ) debugger=true ;; 69 e ) extra_args="$OPTARG" ;; 70 f ) force=true ;; 71 h ) print_usage; exit ;; 72 n ) nsize="$OPTARG" ;; 73 j ) diff_flags=$diff_flags" -j" ;; 74 J ) diff_flags=$diff_flags" -J $OPTARG" ;; 75 m ) diff_flags=$diff_flags" -m" ;; 76 M ) diff_flags=$diff_flags" -M" ;; 77 o ) output_fmt=$OPTARG ;; 78 p ) printcmd=true ;; 79 t ) TIMEOUT=$OPTARG ;; 80 V ) mpiexec="petsc_mpiexec_valgrind $mpiexec" ;; 81 v ) verbose=true ;; 82 *) # To take care of any extra args 83 if test -n "$OPTARG"; then 84 eval $arg=\"$OPTARG\" 85 else 86 eval $arg=found 87 fi 88 ;; 89 esac 90done 91shift $(( $OPTIND - 1 )) 92 93# Individual tests can extend the default 94export MPIEXEC_TIMEOUT=$((TIMEOUT*timeoutfactor)) 95STARTTIME=`date +%s` 96 97if test -n "$extra_args"; then 98 args="$args $extra_args" 99fi 100if $debugger; then 101 args="-start_in_debugger $args" 102fi 103if test -n "$filter"; then 104 diff_flags=$diff_flags" -F \$'$filter'" 105fi 106if test -n "$filter_output"; then 107 diff_flags=$diff_flags" -f \$'$filter_output'" 108fi 109 110 111# Init 112success=0; failed=0; failures=""; rmfiles="" 113total=0 114todo=-1; skip=-1 115job_level=0 116 117function petsc_report_tapoutput() { 118 notornot=$1 119 test_label=$2 120 comment=$3 121 if test -n "$comment"; then 122 comment=" # ${comment}" 123 fi 124 125 tap_message="${notornot} ok ${test_label}${comment}" 126 127 # Log messages 128 printf "${tap_message}\n" >> ${testlogtapfile} 129 130 if test ${output_fmt} == "err_only"; then 131 if test -n "${notornot}"; then 132 printf "${tap_message}\n" | tee -a ${testlogerrfile} 133 fi 134 else 135 printf "${tap_message}\n" 136 fi 137} 138 139function printcmd() { 140 # Print command that can be run from PETSC_DIR 141 cmd="$1" 142 basedir=`dirname ${PWD} | sed "s#${petsc_dir}/##"` 143 modcmd=`echo ${cmd} | sed -e "s#\.\.#${basedir}#" | sed s#\>.*##` 144 printf "${modcmd}\n" 145 exit 146} 147 148function petsc_testrun() { 149 # First arg = Basic command 150 # Second arg = stdout file 151 # Third arg = stderr file 152 # Fourth arg = label for reporting 153 rmfiles="${rmfiles} $2 $3" 154 tlabel=$4 155 error=$5 156 cmd="$1 > $2 2> $3" 157 if test -n "$error"; then 158 cmd="$1 2>&1 | cat > $2" 159 fi 160 echo "$cmd" > ${tlabel}.sh; chmod 755 ${tlabel}.sh 161 if $printcmd; then 162 printcmd "$cmd" 163 fi 164 165 eval "{ time -p $cmd ; } 2>> timing.out" 166 cmd_res=$? 167 touch "$2" "$3" 168 # ETIMEDOUT=110 on most systems (used by Open MPI 3.0). MPICH uses 169 # 255. Earlier Open MPI returns 1 but outputs about MPIEXEC_TIMEOUT. 170 if [ $cmd_res -eq 110 -o $cmd_res -eq 255 ] || \ 171 fgrep -q -s 'APPLICATION TIMED OUT' "$2" "$3" || \ 172 fgrep -q -s MPIEXEC_TIMEOUT "$2" "$3" || \ 173 fgrep -q -s 'APPLICATION TERMINATED WITH THE EXIT STRING: job ending due to timeout' "$2" "$3" || \ 174 grep -q -s "Timeout after [0-9]* seconds. Terminating job" "$2" "$3"; then 175 timed_out=1 176 # If timed out, then ensure non-zero error code 177 if [ $cmd_res -eq 0 ]; then 178 cmd_res=1 179 fi 180 fi 181 182 # Report errors 183 comment="" 184 if test $cmd_res == 0; then 185 if "${verbose}"; then 186 comment="${cmd}" 187 fi 188 petsc_report_tapoutput "" "$tlabel" "$comment" 189 let success=$success+1 190 else 191 if [ -n "$timed_out" ]; then 192 comment="Exceeded timeout limit of $MPIEXEC_TIMEOUT s" 193 else 194 comment="Error code: ${cmd_res}" 195 fi 196 petsc_report_tapoutput "not" "$tlabel" "$comment" 197 198 # Report errors in detail 199 if [ -z "$timed_out" ]; then 200 # We've had tests fail but stderr->stdout, as well as having 201 # mpi_abort go to stderr which throws this test off. Show both 202 # with stdout first 203 awk '{print "#\t" $0}' < $2 | tee -a ${testlogerrfile} 204 # if statement is for diff tests 205 if test "$2" != "$3"; then 206 awk '{print "#\t" $0}' < $3 | tee -a ${testlogerrfile} 207 fi 208 fi 209 let failed=$failed+1 210 failures="$failures $tlabel" 211 fi 212 let total=$success+$failed 213 return $cmd_res 214} 215 216function petsc_testend() { 217 logfile=$1/counts/${label}.counts 218 logdir=`dirname $logfile` 219 if ! test -d "$logdir"; then 220 mkdir -p $logdir 221 fi 222 if ! test -e "$logfile"; then 223 touch $logfile 224 fi 225 printf "total $total\n" > $logfile 226 printf "success $success\n" >> $logfile 227 printf "failed $failed\n" >> $logfile 228 printf "failures $failures\n" >> $logfile 229 if test ${todo} -gt 0; then 230 printf "todo $todo\n" >> $logfile 231 fi 232 if test ${skip} -gt 0; then 233 printf "skip $skip\n" >> $logfile 234 fi 235 ENDTIME=`date +%s` 236 timing=`touch timing.out && egrep '(user|sys)' timing.out | awk '{if( sum1 == "" || $2 > sum1 ) { sum1=sprintf("%.2f",$2) } ; sum2 += sprintf("%.2f",$2)} END {printf "%.2f %.2f\n",sum1,sum2}'` 237 printf "time $timing\n" >> $logfile 238 if $cleanup; then 239 echo "Cleaning up" 240 /bin/rm -f $rmfiles 241 fi 242} 243 244function petsc_mpiexec_valgrind() { 245 _mpiexec=$1;shift 246 npopt=$1;shift 247 np=$1;shift 248 249 valgrind="valgrind -q --tool=memcheck --leak-check=yes --num-callers=20 --track-origins=yes --suppressions=$petsc_bindir/maint/petsc-val.supp --error-exitcode=10" 250 251 $_mpiexec $npopt $np $valgrind "$@" 252} 253export LC_ALL=C 254