129921a8fSScott Kruger 229921a8fSScott Kruger 329921a8fSScott Krugerscriptname=`basename $0` 429921a8fSScott Krugerrundir=${scriptname%.sh} 534929e0eSSatish BalayTIMEOUT=60 629921a8fSScott Kruger 729921a8fSScott Krugerif test "$PWD"!=`dirname $0`; then 829921a8fSScott Kruger cd `dirname $0` 929921a8fSScott Krugerfi 106c91caf2SScott Krugerif test -d "${rundir}" && test -n "${rundir}"; then 1147e61e69SScott Kruger rm -f ${rundir}/*.tmp ${rundir}/*.err ${rundir}/*.out 126c91caf2SScott Krugerfi 1329921a8fSScott Krugermkdir -p ${rundir} 1480a579ceSSatish Balayif test -n "${runfiles}"; then 1580a579ceSSatish Balay for runfile in ${runfiles}; do 1680a579ceSSatish Balay subdir=`dirname ${runfile}` 1780a579ceSSatish Balay mkdir -p ${rundir}/${subdir} 1880a579ceSSatish Balay cp -r ${runfile} ${rundir}/${subdir} 1980a579ceSSatish Balay done 20d7871bd4SScott Krugerfi 2129921a8fSScott Krugercd ${rundir} 2229921a8fSScott Kruger 2329921a8fSScott Kruger# 2429921a8fSScott Kruger# Method to print out general and script specific options 2529921a8fSScott Kruger# 2629921a8fSScott Krugerprint_usage() { 2729921a8fSScott Kruger 2829921a8fSScott Krugercat >&2 <<EOF 2929921a8fSScott KrugerUsage: $0 [options] 3029921a8fSScott Kruger 3129921a8fSScott KrugerOPTIONS 3229921a8fSScott Kruger -a <args> ......... Override default arguments 3329921a8fSScott Kruger -c <cleanup> ...... Cleanup (remove generated files) 34e53dc769SScott Kruger -d ................ Launch in debugger 3529921a8fSScott Kruger -e <args> ......... Add extra arguments to default 362f2809e3SToby Isaac -f ................ force attempt to run test that would otherwise be skipped 3729921a8fSScott Kruger -h ................ help: print this message 3829921a8fSScott Kruger -n <integer> ...... Override the number of processors to use 39ba2c5286SScott Kruger -j ................ Pass -j to petscdiff (just use diff) 40ba2c5286SScott Kruger -J <arg> .......... Pass -J to petscdiff (just use diff with arg) 41ba2c5286SScott Kruger -m ................ Update results using petscdiff 42f50802fbSScott Kruger -M ................ Update alt files using petscdiff 435e361860SScott Kruger -o <arg> .......... Output format: 'interactive', 'err_only' 44*a6f3f80dSScott Kruger -p ................ Print command: Print first command and exit 450a091e3eSScott Kruger -t ................ Override the default timeout (default=$TIMEOUT sec) 46b047ed2bSScott Kruger -V ................ run Valgrind 4729921a8fSScott Kruger -v ................ Verbose: Print commands 4829921a8fSScott KrugerEOF 4929921a8fSScott Kruger 5029921a8fSScott Kruger if declare -f extrausage > /dev/null; then extrausage; fi 5129921a8fSScott Kruger exit $1 5229921a8fSScott Kruger} 5329921a8fSScott Kruger### 5429921a8fSScott Kruger## Arguments for overriding things 5529921a8fSScott Kruger# 565e361860SScott Krugeroutput_fmt="interactive" 5729921a8fSScott Krugerverbose=false 5829921a8fSScott Krugercleanup=false 59e53dc769SScott Krugerdebugger=false 60*a6f3f80dSScott Krugerprintcmd=false 612f2809e3SToby Isaacforce=false 62d4417257SScott Krugerdiff_flags="" 63*a6f3f80dSScott Krugerwhile getopts "a:cde:fhjJ:mMn:o:pt:vV" arg 6429921a8fSScott Krugerdo 6529921a8fSScott Kruger case $arg in 66ba2c5286SScott Kruger a ) args="$OPTARG" ;; 6729921a8fSScott Kruger c ) cleanup=true ;; 68e53dc769SScott Kruger d ) debugger=true ;; 69ba2c5286SScott Kruger e ) extra_args="$OPTARG" ;; 702f2809e3SToby Isaac f ) force=true ;; 7129921a8fSScott Kruger h ) print_usage; exit ;; 72ba2c5286SScott Kruger n ) nsize="$OPTARG" ;; 7329dac19bSScott Kruger j ) diff_flags=$diff_flags" -j" ;; 7429dac19bSScott Kruger J ) diff_flags=$diff_flags" -J $OPTARG" ;; 7529dac19bSScott Kruger m ) diff_flags=$diff_flags" -m" ;; 7629dac19bSScott Kruger M ) diff_flags=$diff_flags" -M" ;; 775e361860SScott Kruger o ) output_fmt=$OPTARG ;; 78*a6f3f80dSScott Kruger p ) printcmd=true ;; 790a091e3eSScott Kruger t ) TIMEOUT=$OPTARG ;; 80b047ed2bSScott Kruger V ) mpiexec="petsc_mpiexec_valgrind $mpiexec" ;; 8129921a8fSScott Kruger v ) verbose=true ;; 8229921a8fSScott Kruger *) # To take care of any extra args 8329921a8fSScott Kruger if test -n "$OPTARG"; then 8429921a8fSScott Kruger eval $arg=\"$OPTARG\" 8529921a8fSScott Kruger else 8629921a8fSScott Kruger eval $arg=found 8729921a8fSScott Kruger fi 8829921a8fSScott Kruger ;; 8929921a8fSScott Kruger esac 9029921a8fSScott Krugerdone 9129921a8fSScott Krugershift $(( $OPTIND - 1 )) 9229921a8fSScott Kruger 930a091e3eSScott Kruger# Individual tests can extend the default 9475ea7643SJed Brownexport MPIEXEC_TIMEOUT=$((TIMEOUT*timeoutfactor)) 95bbf1c217SScott KrugerSTARTTIME=`date +%s` 960a091e3eSScott Kruger 9729921a8fSScott Krugerif test -n "$extra_args"; then 9829921a8fSScott Kruger args="$args $extra_args" 9929921a8fSScott Krugerfi 100e53dc769SScott Krugerif $debugger; then 101e53dc769SScott Kruger args="-start_in_debugger $args" 102e53dc769SScott Krugerfi 1031725bfbfSScott Krugerif test -n "$filter"; then 1041725bfbfSScott Kruger diff_flags=$diff_flags" -F \$'$filter'" 1051725bfbfSScott Krugerfi 1061725bfbfSScott Krugerif test -n "$filter_output"; then 1071725bfbfSScott Kruger diff_flags=$diff_flags" -f \$'$filter_output'" 1081725bfbfSScott Krugerfi 109e53dc769SScott Kruger 11029921a8fSScott Kruger 11129921a8fSScott Kruger# Init 11229921a8fSScott Krugersuccess=0; failed=0; failures=""; rmfiles="" 11329921a8fSScott Krugertotal=0 11429921a8fSScott Krugertodo=-1; skip=-1 1150a091e3eSScott Krugerjob_level=0 11629921a8fSScott Kruger 1175e361860SScott Krugerfunction petsc_report_tapoutput() { 1185e361860SScott Kruger notornot=$1 1195e361860SScott Kruger test_label=$2 1205e361860SScott Kruger comment=$3 1215e361860SScott Kruger if test -n "$comment"; then 1225e361860SScott Kruger comment=" # ${comment}" 1235e361860SScott Kruger fi 1245e361860SScott Kruger 1255e361860SScott Kruger tap_message="${notornot} ok ${test_label}${comment}" 1265e361860SScott Kruger 1275e361860SScott Kruger # Log messages 1285e361860SScott Kruger printf "${tap_message}\n" >> ${testlogtapfile} 1295e361860SScott Kruger 1305e361860SScott Kruger if test ${output_fmt} == "err_only"; then 1315e361860SScott Kruger if test -n "${notornot}"; then 1325e361860SScott Kruger printf "${tap_message}\n" | tee -a ${testlogerrfile} 1335e361860SScott Kruger fi 1345e361860SScott Kruger else 1355e361860SScott Kruger printf "${tap_message}\n" 1365e361860SScott Kruger fi 1375e361860SScott Kruger} 1385e361860SScott Kruger 139*a6f3f80dSScott Krugerfunction printcmd() { 140*a6f3f80dSScott Kruger # Print command that can be run from PETSC_DIR 141*a6f3f80dSScott Kruger cmd="$1" 142*a6f3f80dSScott Kruger basedir=`dirname ${PWD} | sed "s#${petsc_dir}/##"` 143*a6f3f80dSScott Kruger modcmd=`echo ${cmd} | sed -e "s#\.\.#${basedir}#" | sed s#\>.*##` 144*a6f3f80dSScott Kruger printf "${modcmd}\n" 145*a6f3f80dSScott Kruger exit 146*a6f3f80dSScott Kruger} 147*a6f3f80dSScott Kruger 14829921a8fSScott Krugerfunction petsc_testrun() { 14929921a8fSScott Kruger # First arg = Basic command 15029921a8fSScott Kruger # Second arg = stdout file 15129921a8fSScott Kruger # Third arg = stderr file 15229921a8fSScott Kruger # Fourth arg = label for reporting 15329921a8fSScott Kruger rmfiles="${rmfiles} $2 $3" 15429921a8fSScott Kruger tlabel=$4 1551725bfbfSScott Kruger error=$5 15629921a8fSScott Kruger cmd="$1 > $2 2> $3" 1571725bfbfSScott Kruger if test -n "$error"; then 158fb2b1c94SScott Kruger cmd="$1 2>&1 | cat > $2" 15929921a8fSScott Kruger fi 1601263882eSScott Kruger echo "$cmd" > ${tlabel}.sh; chmod 755 ${tlabel}.sh 161*a6f3f80dSScott Kruger if $printcmd; then 162*a6f3f80dSScott Kruger printcmd "$cmd" 163*a6f3f80dSScott Kruger fi 1647a853109SScott Kruger 165d8e31410SScott Kruger eval "{ time -p $cmd ; } 2>> timing.out" 166679e9f5cSJed Brown cmd_res=$? 1670da08ecbSSatish Balay touch "$2" "$3" 168984117c4SJed Brown # ETIMEDOUT=110 on most systems (used by Open MPI 3.0). MPICH uses 169984117c4SJed Brown # 255. Earlier Open MPI returns 1 but outputs about MPIEXEC_TIMEOUT. 1707c0e31c5SScott Kruger if [ $cmd_res -eq 110 -o $cmd_res -eq 255 ] || \ 17148237715SSatish Balay fgrep -q -s 'APPLICATION TIMED OUT' "$2" "$3" || \ 1728fb2ab26SSatish Balay fgrep -q -s MPIEXEC_TIMEOUT "$2" "$3" || \ 1738fb2ab26SSatish Balay fgrep -q -s 'APPLICATION TERMINATED WITH THE EXIT STRING: job ending due to timeout' "$2" "$3" || \ 1748fb2ab26SSatish Balay grep -q -s "Timeout after [0-9]* seconds. Terminating job" "$2" "$3"; then 175984117c4SJed Brown timed_out=1 1767c0e31c5SScott Kruger # If timed out, then ensure non-zero error code 1777c0e31c5SScott Kruger if [ $cmd_res -eq 0 ]; then 1787c0e31c5SScott Kruger cmd_res=1 1797c0e31c5SScott Kruger fi 180984117c4SJed Brown fi 1810a091e3eSScott Kruger 1820a091e3eSScott Kruger # Report errors 1835e361860SScott Kruger comment="" 1847a853109SScott Kruger if test $cmd_res == 0; then 18502afe9ecSJed Brown if "${verbose}"; then 1865e361860SScott Kruger comment="${cmd}" 18702afe9ecSJed Brown fi 1885e361860SScott Kruger petsc_report_tapoutput "" "$tlabel" "$comment" 18929921a8fSScott Kruger let success=$success+1 19029921a8fSScott Kruger else 1914d9d3ee5SSatish Balay if [ -n "$timed_out" ]; then 1925e361860SScott Kruger comment="Exceeded timeout limit of $MPIEXEC_TIMEOUT s" 1934d9d3ee5SSatish Balay else 1945e361860SScott Kruger comment="Error code: ${cmd_res}" 19564ca018dSScott Kruger fi 1965e361860SScott Kruger petsc_report_tapoutput "not" "$tlabel" "$comment" 1975e361860SScott Kruger 1985e361860SScott Kruger # Report errors in detail 1995e361860SScott Kruger if [ -z "$timed_out" ]; then 200570dea68SScott Kruger # We've had tests fail but stderr->stdout, as well as having 201570dea68SScott Kruger # mpi_abort go to stderr which throws this test off. Show both 202570dea68SScott Kruger # with stdout first 2035e361860SScott Kruger awk '{print "#\t" $0}' < $2 | tee -a ${testlogerrfile} 20429dac19bSScott Kruger # if statement is for diff tests 20529dac19bSScott Kruger if test "$2" != "$3"; then 206570dea68SScott Kruger awk '{print "#\t" $0}' < $3 | tee -a ${testlogerrfile} 207984117c4SJed Brown fi 20829dac19bSScott Kruger fi 20929921a8fSScott Kruger let failed=$failed+1 21029921a8fSScott Kruger failures="$failures $tlabel" 21129921a8fSScott Kruger fi 21229921a8fSScott Kruger let total=$success+$failed 2137a853109SScott Kruger return $cmd_res 21429921a8fSScott Kruger} 21529921a8fSScott Kruger 21629921a8fSScott Krugerfunction petsc_testend() { 21729921a8fSScott Kruger logfile=$1/counts/${label}.counts 21829921a8fSScott Kruger logdir=`dirname $logfile` 21929921a8fSScott Kruger if ! test -d "$logdir"; then 22029921a8fSScott Kruger mkdir -p $logdir 22129921a8fSScott Kruger fi 22229921a8fSScott Kruger if ! test -e "$logfile"; then 22329921a8fSScott Kruger touch $logfile 22429921a8fSScott Kruger fi 22529921a8fSScott Kruger printf "total $total\n" > $logfile 22629921a8fSScott Kruger printf "success $success\n" >> $logfile 22729921a8fSScott Kruger printf "failed $failed\n" >> $logfile 22829921a8fSScott Kruger printf "failures $failures\n" >> $logfile 22929921a8fSScott Kruger if test ${todo} -gt 0; then 23029921a8fSScott Kruger printf "todo $todo\n" >> $logfile 23129921a8fSScott Kruger fi 23229921a8fSScott Kruger if test ${skip} -gt 0; then 23329921a8fSScott Kruger printf "skip $skip\n" >> $logfile 23429921a8fSScott Kruger fi 235bbf1c217SScott Kruger ENDTIME=`date +%s` 2369b757ad5SKarl Rupp 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}'` 237521be42fSScott Kruger printf "time $timing\n" >> $logfile 23829921a8fSScott Kruger if $cleanup; then 23929921a8fSScott Kruger echo "Cleaning up" 24029921a8fSScott Kruger /bin/rm -f $rmfiles 24129921a8fSScott Kruger fi 24229921a8fSScott Kruger} 243296e37cfSJed Brown 24426646c0bSSatish Balayfunction petsc_mpiexec_valgrind() { 24526646c0bSSatish Balay mpiexec=$1;shift 24626646c0bSSatish Balay npopt=$1;shift 24726646c0bSSatish Balay np=$1;shift 24826646c0bSSatish Balay 249ac71c9ffSScott Kruger valgrind="valgrind -q --tool=memcheck --leak-check=yes --num-callers=20 --track-origins=yes --suppressions=$petsc_bindir/maint/petsc-val.supp --error-exitcode=10" 250c173c275SScott Kruger 25126646c0bSSatish Balay $mpiexec $npopt $np $valgrind $* 25226646c0bSSatish Balay} 253296e37cfSJed Brownexport LC_ALL=C 254