1 2 3scriptname=`basename $0` 4rundir=${scriptname%.sh} 5TIMEOUT=60 6 7if test "$PWD"!=`dirname $0`; then 8 cd `dirname $0` 9 abspath_scriptdir=$PWD 10fi 11if test -d "${rundir}" && test -n "${rundir}"; then 12 rm -f ${rundir}/*.tmp ${rundir}/*.err ${rundir}/*.out 13fi 14mkdir -p ${rundir} 15if test -n "${runfiles}"; then 16 for runfile in ${runfiles}; do 17 subdir=`dirname ${runfile}` 18 mkdir -p ${rundir}/${subdir} 19 cp -r ${runfile} ${rundir}/${subdir} 20 done 21fi 22cd ${rundir} 23 24# 25# Method to print out general and script specific options 26# 27print_usage() { 28 29cat >&2 <<EOF 30Usage: $0 [options] 31 32OPTIONS 33 -a <args> ......... Override default arguments 34 -c ................ Cleanup (remove generated files) 35 -C ................ Compile 36 -d ................ Launch in debugger 37 -e <args> ......... Add extra arguments to default 38 -f ................ force attempt to run test that would otherwise be skipped 39 -h ................ help: print this message 40 -n <integer> ...... Override the number of processors to use 41 -j ................ Pass -j to petscdiff (just use diff) 42 -J <arg> .......... Pass -J to petscdiff (just use diff with arg) 43 -m ................ Update results using petscdiff 44 -M ................ Update alt files using petscdiff 45 -o <arg> .......... Output format: 'interactive', 'err_only' 46 -p ................ Print command: Print first command and exit 47 -t ................ Override the default timeout (default=$TIMEOUT sec) 48 -U ................ run cUda-memcheck 49 -V ................ run Valgrind 50 -v ................ Verbose: Print commands 51EOF 52 53 if declare -f extrausage > /dev/null; then extrausage; fi 54 exit $1 55} 56### 57## Arguments for overriding things 58# 59output_fmt="interactive" 60verbose=false 61cleanup=false 62compile=false 63debugger=false 64printcmd=false 65mpiexec_function=false 66force=false 67diff_flags="" 68while getopts "a:cCde:fhjJ:mMn:o:pt:UvV" arg 69do 70 case $arg in 71 a ) args="$OPTARG" ;; 72 c ) cleanup=true ;; 73 C ) compile=true ;; 74 d ) debugger=true ;; 75 e ) extra_args="$OPTARG" ;; 76 f ) force=true ;; 77 h ) print_usage; exit ;; 78 n ) nsize="$OPTARG" ;; 79 j ) diff_flags=$diff_flags" -j" ;; 80 J ) diff_flags=$diff_flags" -J $OPTARG" ;; 81 m ) diff_flags=$diff_flags" -m" ;; 82 M ) diff_flags=$diff_flags" -M" ;; 83 o ) output_fmt=$OPTARG ;; 84 p ) printcmd=true ;; 85 t ) TIMEOUT=$OPTARG ;; 86 U ) mpiexec="petsc_mpiexec_cudamemcheck $mpiexec" 87 mpiexec_function=true 88 ;; 89 V ) mpiexec="petsc_mpiexec_valgrind $mpiexec" 90 mpiexec_function=true 91 ;; 92 v ) verbose=true ;; 93 *) # To take care of any extra args 94 if test -n "$OPTARG"; then 95 eval $arg=\"$OPTARG\" 96 else 97 eval $arg=found 98 fi 99 ;; 100 esac 101done 102shift $(( $OPTIND - 1 )) 103 104# Individual tests can extend the default 105export MPIEXEC_TIMEOUT=$((TIMEOUT*timeoutfactor)) 106STARTTIME=`date +%s` 107 108if test -n "$extra_args"; then 109 args="$args $extra_args" 110fi 111if $debugger; then 112 args="-start_in_debugger $args" 113fi 114if test -n "$filter"; then 115 diff_flags=$diff_flags" -F \$'$filter'" 116fi 117if test -n "$filter_output"; then 118 diff_flags=$diff_flags" -f \$'$filter_output'" 119fi 120 121 122# Init 123success=0; failed=0; failures=""; rmfiles="" 124total=0 125todo=-1; skip=-1 126job_level=0 127 128if $compile; then 129 curexec=`basename ${exec}` 130 fullexec=${abspath_scriptdir}/${curexec} 131 maketarget=`echo ${fullexec} | sed "s#${petsc_dir}/*##"` 132 (cd $petsc_dir && make -f gmakefile.test ${maketarget}) 133fi 134 135### 136## Rest of code is functions 137# 138function petsc_report_tapoutput() { 139 notornot=$1 140 test_label=$2 141 comment=$3 142 if test -n "$comment"; then 143 comment=" # ${comment}" 144 fi 145 146 tap_message="${notornot} ok ${test_label}${comment}" 147 148 # Log messages 149 printf "${tap_message}\n" >> ${testlogtapfile} 150 151 if test ${output_fmt} == "err_only"; then 152 if test -n "${notornot}"; then 153 printf "${tap_message}\n" | tee -a ${testlogerrfile} 154 fi 155 else 156 printf "${tap_message}\n" 157 fi 158} 159 160function printcmd() { 161 # Print command that can be run from PETSC_DIR 162 cmd="$1" 163 basedir=`dirname ${PWD} | sed "s#${petsc_dir}/##"` 164 modcmd=`echo ${cmd} | sed -e "s#\.\.#${basedir}#" | sed s#\>.*## | sed s#\%#\%\%#` 165 if $mpiexec_function; then 166 # Have to expand valgrind/cudamemchk 167 modcmd=`eval "$modcmd"` 168 fi 169 printf "${modcmd}\n" 170 exit 171} 172 173function petsc_testrun() { 174 # First arg = Basic command 175 # Second arg = stdout file 176 # Third arg = stderr file 177 # Fourth arg = label for reporting 178 rmfiles="${rmfiles} $2 $3" 179 tlabel=$4 180 error=$5 181 cmd="$1 > $2 2> $3" 182 if test -n "$error"; then 183 cmd="$1 2>&1 | cat > $2" 184 fi 185 echo "$cmd" > ${tlabel}.sh; chmod 755 ${tlabel}.sh 186 if $printcmd; then 187 printcmd "$cmd" 188 fi 189 190 eval "{ time -p $cmd ; } 2>> timing.out" 191 cmd_res=$? 192 # If it is a lack of GPU resources or MPI failure (Intel) then try once more 193 # See: src/sys/error/err.c 194 # Error #134 added to handle problems with the Radeon card for hip testing 195 if [ $cmd_res -eq 96 -o $cmd_res -eq 97 -o $cmd_res -eq 98 -o $cmd_res -eq 134 ]; then 196 printf "# retrying ${tlabel}\n" | tee -a ${testlogerrfile} 197 sleep 3 198 eval "{ time -p $cmd ; } 2>> timing.out" 199 cmd_res=$? 200 fi 201 touch "$2" "$3" 202 # It appears current MPICH and OpenMPI just shut down the job executation and do not return an error code to the executable 203 # ETIMEDOUT=110 was used by OpenMPI 3.0. MPICH used 255 204 # Earlier OpenMPI versions returned 1 and the error string 205 if [ $cmd_res -eq 110 -o $cmd_res -eq 255 ] || \ 206 fgrep -q -s 'APPLICATION TIMED OUT' "$2" "$3" || \ 207 fgrep -q -s MPIEXEC_TIMEOUT "$2" "$3" || \ 208 fgrep -q -s 'APPLICATION TERMINATED WITH THE EXIT STRING: job ending due to timeout' "$2" "$3" || \ 209 grep -q -s "Timeout after [0-9]* seconds. Terminating job" "$2" "$3"; then 210 timed_out=1 211 # If timed out, then ensure non-zero error code 212 if [ $cmd_res -eq 0 ]; then 213 cmd_res=1 214 fi 215 fi 216 217 # Report errors 218 comment="" 219 if test $cmd_res == 0; then 220 if "${verbose}"; then 221 comment="${cmd}" 222 fi 223 petsc_report_tapoutput "" "$tlabel" "$comment" 224 let success=$success+1 225 else 226 if [ -n "$timed_out" ]; then 227 comment="Exceeded timeout limit of $MPIEXEC_TIMEOUT s" 228 else 229 comment="Error code: ${cmd_res}" 230 fi 231 petsc_report_tapoutput "not" "$tlabel" "$comment" 232 233 # Report errors in detail 234 if [ -z "$timed_out" ]; then 235 # We've had tests fail but stderr->stdout, as well as having 236 # mpi_abort go to stderr which throws this test off. Show both 237 # with stdout first 238 awk '{print "#\t" $0}' < $2 | tee -a ${testlogerrfile} 239 # if statement is for diff tests 240 if test "$2" != "$3"; then 241 awk '{print "#\t" $0}' < $3 | tee -a ${testlogerrfile} 242 fi 243 fi 244 let failed=$failed+1 245 failures="$failures $tlabel" 246 fi 247 let total=$success+$failed 248 return $cmd_res 249} 250 251function petsc_testend() { 252 logfile=$1/counts/${label}.counts 253 logdir=`dirname $logfile` 254 if ! test -d "$logdir"; then 255 mkdir -p $logdir 256 fi 257 if ! test -e "$logfile"; then 258 touch $logfile 259 fi 260 printf "total $total\n" > $logfile 261 printf "success $success\n" >> $logfile 262 printf "failed $failed\n" >> $logfile 263 printf "failures $failures\n" >> $logfile 264 if test ${todo} -gt 0; then 265 printf "todo $todo\n" >> $logfile 266 fi 267 if test ${skip} -gt 0; then 268 printf "skip $skip\n" >> $logfile 269 fi 270 ENDTIME=`date +%s` 271 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}'` 272 printf "time $timing\n" >> $logfile 273 if $cleanup; then 274 echo "Cleaning up" 275 /bin/rm -f $rmfiles 276 fi 277} 278 279function petsc_mpiexec_cudamemcheck() { 280 _mpiexec=$1;shift 281 npopt=$1;shift 282 np=$1;shift 283 284 cudamemchk="cuda-memcheck" 285 286 $_mpiexec $npopt $np $cudamemchk $* 287} 288 289function petsc_mpiexec_valgrind() { 290 # some systems set $1 to be the function name 291 if [[ $1 == 'petsc_mpiexec_valgrind' ]]; then 292 shift 293 fi 294 _mpiexec=$1;shift 295 npopt=$1;shift 296 np=$1;shift 297 298 valgrind="valgrind -q --tool=memcheck --leak-check=yes --num-callers=20 --track-origins=yes --keep-debuginfo=yes --suppressions=$PETSC_DIR/share/petsc/valgrind/petsc-val.supp --error-exitcode=10" 299 300 if $printcmd; then 301 echo $_mpiexec $npopt $np $valgrind "$@" 302 else 303 $_mpiexec $npopt $np $valgrind "$@" 304 fi 305} 306export LC_ALL=C 307