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` 9aec279ffSScott Kruger abspath_scriptdir=$PWD 1029921a8fSScott Krugerfi 116c91caf2SScott Krugerif test -d "${rundir}" && test -n "${rundir}"; then 1247e61e69SScott Kruger rm -f ${rundir}/*.tmp ${rundir}/*.err ${rundir}/*.out 136c91caf2SScott Krugerfi 1429921a8fSScott Krugermkdir -p ${rundir} 1580a579ceSSatish Balayif test -n "${runfiles}"; then 1680a579ceSSatish Balay for runfile in ${runfiles}; do 1780a579ceSSatish Balay subdir=`dirname ${runfile}` 1880a579ceSSatish Balay mkdir -p ${rundir}/${subdir} 1980a579ceSSatish Balay cp -r ${runfile} ${rundir}/${subdir} 2080a579ceSSatish Balay done 21d7871bd4SScott Krugerfi 2229921a8fSScott Krugercd ${rundir} 2329921a8fSScott Kruger 2429921a8fSScott Kruger# 2529921a8fSScott Kruger# Method to print out general and script specific options 2629921a8fSScott Kruger# 2729921a8fSScott Krugerprint_usage() { 2829921a8fSScott Kruger 2929921a8fSScott Krugercat >&2 <<EOF 3029921a8fSScott KrugerUsage: $0 [options] 3129921a8fSScott Kruger 3229921a8fSScott KrugerOPTIONS 3329921a8fSScott Kruger -a <args> ......... Override default arguments 34aec279ffSScott Kruger -c ................ Cleanup (remove generated files) 35aec279ffSScott Kruger -C ................ Compile 36e53dc769SScott Kruger -d ................ Launch in debugger 3729921a8fSScott Kruger -e <args> ......... Add extra arguments to default 382f2809e3SToby Isaac -f ................ force attempt to run test that would otherwise be skipped 3929921a8fSScott Kruger -h ................ help: print this message 4029921a8fSScott Kruger -n <integer> ...... Override the number of processors to use 41ba2c5286SScott Kruger -j ................ Pass -j to petscdiff (just use diff) 42ba2c5286SScott Kruger -J <arg> .......... Pass -J to petscdiff (just use diff with arg) 43ba2c5286SScott Kruger -m ................ Update results using petscdiff 44f50802fbSScott Kruger -M ................ Update alt files using petscdiff 455e361860SScott Kruger -o <arg> .......... Output format: 'interactive', 'err_only' 46a6f3f80dSScott Kruger -p ................ Print command: Print first command and exit 470a091e3eSScott Kruger -t ................ Override the default timeout (default=$TIMEOUT sec) 48b047ed2bSScott Kruger -V ................ run Valgrind 4929921a8fSScott Kruger -v ................ Verbose: Print commands 5029921a8fSScott KrugerEOF 5129921a8fSScott Kruger 5229921a8fSScott Kruger if declare -f extrausage > /dev/null; then extrausage; fi 5329921a8fSScott Kruger exit $1 5429921a8fSScott Kruger} 5529921a8fSScott Kruger### 5629921a8fSScott Kruger## Arguments for overriding things 5729921a8fSScott Kruger# 585e361860SScott Krugeroutput_fmt="interactive" 5929921a8fSScott Krugerverbose=false 6029921a8fSScott Krugercleanup=false 61aec279ffSScott Krugercompile=false 62e53dc769SScott Krugerdebugger=false 63a6f3f80dSScott Krugerprintcmd=false 642f2809e3SToby Isaacforce=false 65d4417257SScott Krugerdiff_flags="" 66aec279ffSScott Krugerwhile getopts "a:cCde:fhjJ:mMn:o:pt:vV" arg 6729921a8fSScott Krugerdo 6829921a8fSScott Kruger case $arg in 69ba2c5286SScott Kruger a ) args="$OPTARG" ;; 7029921a8fSScott Kruger c ) cleanup=true ;; 71aec279ffSScott Kruger C ) compile=true ;; 72e53dc769SScott Kruger d ) debugger=true ;; 73ba2c5286SScott Kruger e ) extra_args="$OPTARG" ;; 742f2809e3SToby Isaac f ) force=true ;; 7529921a8fSScott Kruger h ) print_usage; exit ;; 76ba2c5286SScott Kruger n ) nsize="$OPTARG" ;; 7729dac19bSScott Kruger j ) diff_flags=$diff_flags" -j" ;; 7829dac19bSScott Kruger J ) diff_flags=$diff_flags" -J $OPTARG" ;; 7929dac19bSScott Kruger m ) diff_flags=$diff_flags" -m" ;; 8029dac19bSScott Kruger M ) diff_flags=$diff_flags" -M" ;; 815e361860SScott Kruger o ) output_fmt=$OPTARG ;; 82a6f3f80dSScott Kruger p ) printcmd=true ;; 830a091e3eSScott Kruger t ) TIMEOUT=$OPTARG ;; 84b047ed2bSScott Kruger V ) mpiexec="petsc_mpiexec_valgrind $mpiexec" ;; 8529921a8fSScott Kruger v ) verbose=true ;; 8629921a8fSScott Kruger *) # To take care of any extra args 8729921a8fSScott Kruger if test -n "$OPTARG"; then 8829921a8fSScott Kruger eval $arg=\"$OPTARG\" 8929921a8fSScott Kruger else 9029921a8fSScott Kruger eval $arg=found 9129921a8fSScott Kruger fi 9229921a8fSScott Kruger ;; 9329921a8fSScott Kruger esac 9429921a8fSScott Krugerdone 9529921a8fSScott Krugershift $(( $OPTIND - 1 )) 9629921a8fSScott Kruger 970a091e3eSScott Kruger# Individual tests can extend the default 9875ea7643SJed Brownexport MPIEXEC_TIMEOUT=$((TIMEOUT*timeoutfactor)) 99bbf1c217SScott KrugerSTARTTIME=`date +%s` 1000a091e3eSScott Kruger 10129921a8fSScott Krugerif test -n "$extra_args"; then 10229921a8fSScott Kruger args="$args $extra_args" 10329921a8fSScott Krugerfi 104e53dc769SScott Krugerif $debugger; then 105e53dc769SScott Kruger args="-start_in_debugger $args" 106e53dc769SScott Krugerfi 1071725bfbfSScott Krugerif test -n "$filter"; then 1081725bfbfSScott Kruger diff_flags=$diff_flags" -F \$'$filter'" 1091725bfbfSScott Krugerfi 1101725bfbfSScott Krugerif test -n "$filter_output"; then 1111725bfbfSScott Kruger diff_flags=$diff_flags" -f \$'$filter_output'" 1121725bfbfSScott Krugerfi 113e53dc769SScott Kruger 11429921a8fSScott Kruger 11529921a8fSScott Kruger# Init 11629921a8fSScott Krugersuccess=0; failed=0; failures=""; rmfiles="" 11729921a8fSScott Krugertotal=0 11829921a8fSScott Krugertodo=-1; skip=-1 1190a091e3eSScott Krugerjob_level=0 12029921a8fSScott Kruger 1215e361860SScott Krugerfunction petsc_report_tapoutput() { 1225e361860SScott Kruger notornot=$1 1235e361860SScott Kruger test_label=$2 1245e361860SScott Kruger comment=$3 1255e361860SScott Kruger if test -n "$comment"; then 1265e361860SScott Kruger comment=" # ${comment}" 1275e361860SScott Kruger fi 1285e361860SScott Kruger 1295e361860SScott Kruger tap_message="${notornot} ok ${test_label}${comment}" 1305e361860SScott Kruger 1315e361860SScott Kruger # Log messages 1325e361860SScott Kruger printf "${tap_message}\n" >> ${testlogtapfile} 1335e361860SScott Kruger 1345e361860SScott Kruger if test ${output_fmt} == "err_only"; then 1355e361860SScott Kruger if test -n "${notornot}"; then 1365e361860SScott Kruger printf "${tap_message}\n" | tee -a ${testlogerrfile} 1375e361860SScott Kruger fi 1385e361860SScott Kruger else 1395e361860SScott Kruger printf "${tap_message}\n" 1405e361860SScott Kruger fi 1415e361860SScott Kruger} 1425e361860SScott Kruger 143a6f3f80dSScott Krugerfunction printcmd() { 144a6f3f80dSScott Kruger # Print command that can be run from PETSC_DIR 145a6f3f80dSScott Kruger cmd="$1" 146a6f3f80dSScott Kruger basedir=`dirname ${PWD} | sed "s#${petsc_dir}/##"` 147a6f3f80dSScott Kruger modcmd=`echo ${cmd} | sed -e "s#\.\.#${basedir}#" | sed s#\>.*##` 148a6f3f80dSScott Kruger printf "${modcmd}\n" 149a6f3f80dSScott Kruger exit 150a6f3f80dSScott Kruger} 151a6f3f80dSScott Kruger 15229921a8fSScott Krugerfunction petsc_testrun() { 15329921a8fSScott Kruger # First arg = Basic command 15429921a8fSScott Kruger # Second arg = stdout file 15529921a8fSScott Kruger # Third arg = stderr file 15629921a8fSScott Kruger # Fourth arg = label for reporting 15729921a8fSScott Kruger rmfiles="${rmfiles} $2 $3" 15829921a8fSScott Kruger tlabel=$4 1591725bfbfSScott Kruger error=$5 16029921a8fSScott Kruger cmd="$1 > $2 2> $3" 1611725bfbfSScott Kruger if test -n "$error"; then 162fb2b1c94SScott Kruger cmd="$1 2>&1 | cat > $2" 16329921a8fSScott Kruger fi 1641263882eSScott Kruger echo "$cmd" > ${tlabel}.sh; chmod 755 ${tlabel}.sh 165a6f3f80dSScott Kruger if $printcmd; then 166a6f3f80dSScott Kruger printcmd "$cmd" 167a6f3f80dSScott Kruger fi 1687a853109SScott Kruger 169d8e31410SScott Kruger eval "{ time -p $cmd ; } 2>> timing.out" 170679e9f5cSJed Brown cmd_res=$? 171*e57d7714SBarry Smith # If it is a lack of GPU resources, then try once more 172*e57d7714SBarry Smith # See: src/sys/error/err.c 173*e57d7714SBarry Smith if [ $cmd_res -eq 96 ]; then 174*e57d7714SBarry Smith eval "{ time -p $cmd ; } 2>> timing.out" 175*e57d7714SBarry Smith cmd_res=$? 176*e57d7714SBarry Smith fi 1770da08ecbSSatish Balay touch "$2" "$3" 178984117c4SJed Brown # ETIMEDOUT=110 on most systems (used by Open MPI 3.0). MPICH uses 179984117c4SJed Brown # 255. Earlier Open MPI returns 1 but outputs about MPIEXEC_TIMEOUT. 1807c0e31c5SScott Kruger if [ $cmd_res -eq 110 -o $cmd_res -eq 255 ] || \ 18148237715SSatish Balay fgrep -q -s 'APPLICATION TIMED OUT' "$2" "$3" || \ 1828fb2ab26SSatish Balay fgrep -q -s MPIEXEC_TIMEOUT "$2" "$3" || \ 1838fb2ab26SSatish Balay fgrep -q -s 'APPLICATION TERMINATED WITH THE EXIT STRING: job ending due to timeout' "$2" "$3" || \ 1848fb2ab26SSatish Balay grep -q -s "Timeout after [0-9]* seconds. Terminating job" "$2" "$3"; then 185984117c4SJed Brown timed_out=1 1867c0e31c5SScott Kruger # If timed out, then ensure non-zero error code 1877c0e31c5SScott Kruger if [ $cmd_res -eq 0 ]; then 1887c0e31c5SScott Kruger cmd_res=1 1897c0e31c5SScott Kruger fi 190984117c4SJed Brown fi 1910a091e3eSScott Kruger 1920a091e3eSScott Kruger # Report errors 1935e361860SScott Kruger comment="" 1947a853109SScott Kruger if test $cmd_res == 0; then 19502afe9ecSJed Brown if "${verbose}"; then 1965e361860SScott Kruger comment="${cmd}" 19702afe9ecSJed Brown fi 1985e361860SScott Kruger petsc_report_tapoutput "" "$tlabel" "$comment" 19929921a8fSScott Kruger let success=$success+1 20029921a8fSScott Kruger else 2014d9d3ee5SSatish Balay if [ -n "$timed_out" ]; then 2025e361860SScott Kruger comment="Exceeded timeout limit of $MPIEXEC_TIMEOUT s" 2034d9d3ee5SSatish Balay else 2045e361860SScott Kruger comment="Error code: ${cmd_res}" 20564ca018dSScott Kruger fi 2065e361860SScott Kruger petsc_report_tapoutput "not" "$tlabel" "$comment" 2075e361860SScott Kruger 2085e361860SScott Kruger # Report errors in detail 2095e361860SScott Kruger if [ -z "$timed_out" ]; then 210570dea68SScott Kruger # We've had tests fail but stderr->stdout, as well as having 211570dea68SScott Kruger # mpi_abort go to stderr which throws this test off. Show both 212570dea68SScott Kruger # with stdout first 2135e361860SScott Kruger awk '{print "#\t" $0}' < $2 | tee -a ${testlogerrfile} 21429dac19bSScott Kruger # if statement is for diff tests 21529dac19bSScott Kruger if test "$2" != "$3"; then 216570dea68SScott Kruger awk '{print "#\t" $0}' < $3 | tee -a ${testlogerrfile} 217984117c4SJed Brown fi 21829dac19bSScott Kruger fi 21929921a8fSScott Kruger let failed=$failed+1 22029921a8fSScott Kruger failures="$failures $tlabel" 22129921a8fSScott Kruger fi 22229921a8fSScott Kruger let total=$success+$failed 2237a853109SScott Kruger return $cmd_res 22429921a8fSScott Kruger} 22529921a8fSScott Kruger 22629921a8fSScott Krugerfunction petsc_testend() { 22729921a8fSScott Kruger logfile=$1/counts/${label}.counts 22829921a8fSScott Kruger logdir=`dirname $logfile` 22929921a8fSScott Kruger if ! test -d "$logdir"; then 23029921a8fSScott Kruger mkdir -p $logdir 23129921a8fSScott Kruger fi 23229921a8fSScott Kruger if ! test -e "$logfile"; then 23329921a8fSScott Kruger touch $logfile 23429921a8fSScott Kruger fi 23529921a8fSScott Kruger printf "total $total\n" > $logfile 23629921a8fSScott Kruger printf "success $success\n" >> $logfile 23729921a8fSScott Kruger printf "failed $failed\n" >> $logfile 23829921a8fSScott Kruger printf "failures $failures\n" >> $logfile 23929921a8fSScott Kruger if test ${todo} -gt 0; then 24029921a8fSScott Kruger printf "todo $todo\n" >> $logfile 24129921a8fSScott Kruger fi 24229921a8fSScott Kruger if test ${skip} -gt 0; then 24329921a8fSScott Kruger printf "skip $skip\n" >> $logfile 24429921a8fSScott Kruger fi 245bbf1c217SScott Kruger ENDTIME=`date +%s` 2469b757ad5SKarl 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}'` 247521be42fSScott Kruger printf "time $timing\n" >> $logfile 24829921a8fSScott Kruger if $cleanup; then 24929921a8fSScott Kruger echo "Cleaning up" 25029921a8fSScott Kruger /bin/rm -f $rmfiles 25129921a8fSScott Kruger fi 25229921a8fSScott Kruger} 253296e37cfSJed Brown 25426646c0bSSatish Balayfunction petsc_mpiexec_valgrind() { 2550f9322f4SToby Isaac _mpiexec=$1;shift 25626646c0bSSatish Balay npopt=$1;shift 25726646c0bSSatish Balay np=$1;shift 25826646c0bSSatish Balay 259ac71c9ffSScott 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" 260c173c275SScott Kruger 261080f0011SToby Isaac $_mpiexec $npopt $np $valgrind "$@" 26226646c0bSSatish Balay} 263296e37cfSJed Brownexport LC_ALL=C 264aec279ffSScott Kruger 265aec279ffSScott Krugerif $compile; then 266aec279ffSScott Kruger curexec=`basename ${exec}` 267aec279ffSScott Kruger (cd $petsc_dir && make -f gmakefile.test ${abspath_scriptdir}/${curexec}) 268aec279ffSScott Krugerfi 269aec279ffSScott Kruger 270