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 88export MPIEXEC_TIMEOUT=$((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 cmd="$1 > $2 2> $3" 115 if test -n "$filter"; then 116 if test "${filter:0:6}"=="Error:"; then 117 filter=${filter##Error:} 118 cmd="$1 2>&1 | cat > $2" 119 fi 120 fi 121 echo "$cmd" > ${tlabel}.sh; chmod 755 ${tlabel}.sh 122 123 eval "{ time -p $cmd ; } 2>> timing.out" 124 cmd_res=$? 125 touch "$2" "$3" 126 # ETIMEDOUT=110 on most systems (used by Open MPI 3.0). MPICH uses 127 # 255. Earlier Open MPI returns 1 but outputs about MPIEXEC_TIMEOUT. 128 if [ $cmd_res -eq 110 -o $cmd_res -eq 255 ] || \ 129 fgrep -q -s 'APPLICATION TIMED OUT' "$2" "$3" || \ 130 fgrep -q -s MPIEXEC_TIMEOUT "$2" "$3" || \ 131 fgrep -q -s 'APPLICATION TERMINATED WITH THE EXIT STRING: job ending due to timeout' "$2" "$3" || \ 132 grep -q -s "Timeout after [0-9]* seconds. Terminating job" "$2" "$3"; then 133 timed_out=1 134 # If timed out, then ensure non-zero error code 135 if [ $cmd_res -eq 0 ]; then 136 cmd_res=1 137 fi 138 fi 139 140 # Handle filters separately and assume no timeout check needed 141 if test -n "$filter"; then 142 cmd="cat $2 | $filter > $2.tmp 2>> $3 && mv $2.tmp $2" 143 echo "$cmd" >> ${tlabel}.sh 144 eval "$cmd" 145 fi 146 147 # Report errors 148 if test $cmd_res == 0; then 149 if "${verbose}"; then 150 printf "ok $tlabel $cmd\n" | tee -a ${testlogfile} 151 else 152 printf "ok $tlabel\n" | tee -a ${testlogfile} 153 fi 154 let success=$success+1 155 else 156 if "${verbose}"; then 157 printf "not ok $tlabel $cmd\n" | tee -a ${testlogfile} 158 else 159 printf "not ok $tlabel\n" | tee -a ${testlogfile} 160 fi 161 if [ -n "$timed_out" ]; then 162 printf "#\tExceeded timeout limit of $MPIEXEC_TIMEOUT s\n" | tee -a ${testlogfile} 163 else 164 # We've had tests fail but stderr->stdout. Fix with this test. 165 if test -s $3; then 166 awk '{print "#\t" $0}' < $3 | tee -a ${testlogfile} 167 else 168 awk '{print "#\t" $0}' < $2 | tee -a ${testlogfile} 169 fi 170 fi 171 let failed=$failed+1 172 failures="$failures $tlabel" 173 fi 174 let total=$success+$failed 175 return $cmd_res 176} 177 178function petsc_testend() { 179 logfile=$1/counts/${label}.counts 180 logdir=`dirname $logfile` 181 if ! test -d "$logdir"; then 182 mkdir -p $logdir 183 fi 184 if ! test -e "$logfile"; then 185 touch $logfile 186 fi 187 printf "total $total\n" > $logfile 188 printf "success $success\n" >> $logfile 189 printf "failed $failed\n" >> $logfile 190 printf "failures $failures\n" >> $logfile 191 if test ${todo} -gt 0; then 192 printf "todo $todo\n" >> $logfile 193 fi 194 if test ${skip} -gt 0; then 195 printf "skip $skip\n" >> $logfile 196 fi 197 ENDTIME=`date +%s` 198 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}'` 199 printf "time $timing\n" >> $logfile 200 if $cleanup; then 201 echo "Cleaning up" 202 /bin/rm -f $rmfiles 203 fi 204} 205 206function petsc_mpiexec_valgrind() { 207 mpiexec=$1;shift 208 npopt=$1;shift 209 np=$1;shift 210 211 valgrind="valgrind -q --tool=memcheck --leak-check=yes --num-callers=20 --track-origins=yes --suppressions=$petsc_bindir/maint/petsc-val.supp" 212 213 $mpiexec $npopt $np $valgrind $* 214} 215export LC_ALL=C 216