ptlreport 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/bin/bash
  2. # coding: utf-8
  3. # Copyright (C) 1994-2018 Altair Engineering, Inc.
  4. # For more information, contact Altair at www.altair.com.
  5. #
  6. # This file is part of the PBS Professional ("PBS Pro") software.
  7. #
  8. # Open Source License Information:
  9. #
  10. # PBS Pro is free software. You can redistribute it and/or modify it under the
  11. # terms of the GNU Affero General Public License as published by the Free
  12. # Software Foundation, either version 3 of the License, or (at your option) any
  13. # later version.
  14. #
  15. # PBS Pro is distributed in the hope that it will be useful, but WITHOUT ANY
  16. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  17. # FOR A PARTICULAR PURPOSE.
  18. # See the GNU Affero General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Affero General Public License
  21. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. #
  23. # Commercial License Information:
  24. #
  25. # For a copy of the commercial license terms and conditions,
  26. # go to: (http://www.pbspro.com/UserArea/agreement.html)
  27. # or contact the Altair Legal Department.
  28. #
  29. # Altair’s dual-license business model allows companies, individuals, and
  30. # organizations to create proprietary derivative works of PBS Pro and
  31. # distribute them - whether embedded or bundled with other software -
  32. # under a commercial license agreement.
  33. #
  34. # Use of Altair’s trademarks, including but not limited to "PBS™",
  35. # "PBS Professional®", and "PBS Pro™" and Altair’s logos is subject to Altair's
  36. # trademark licensing policies.
  37. prog="`basename $0`"
  38. usage() {
  39. echo -en "${prog}\n"
  40. echo -en "\tParses the PTL test output file <ptl_test_log> and reports\n"
  41. echo -en "\tvarious counts like total, passed, failed, error-ed,\n"
  42. echo -en "\tskipped and timedout test cases from <ptl_test_log> file.\n\n"
  43. echo -en "Usage:\n\t${prog} <ptl_test_log> [OPTIONS]\n\n"
  44. echo -en "OPTIONS:\n"
  45. echo -en "\t-t | --total\t- Print total number of test cases\n"
  46. echo -en "\t-p | --passes\t- Print passed test cases\n"
  47. echo -en "\t-f | --fails\t- Print failed test cases\n"
  48. echo -en "\t-e | --errors\t- Print error-ed test cases\n"
  49. echo -en "\t-s | --skipped\t- Print skipped test cases\n"
  50. echo -en "\t-T | --timedout\t- Print timedout test cases\n"
  51. echo -en "\t-r | --runtime\t- Print total runtime of tests\n"
  52. echo -en "\t-S | --summary\t- Print summary of tests\n"
  53. echo -en "\t-v | --verbose\t- Print verbose output, can be supplied multiple times to increase verbosity\n\n"
  54. }
  55. # args: <is_asked> <count> <type>
  56. print_info() {
  57. if [ ${1} -eq 1 ]
  58. then
  59. [ ${_space} -eq 1 ] && echo " " || _space=1
  60. if [ ${verbose} -ge 1 ]
  61. then
  62. [ ${2} -le 0 ] && echo "${3^} test(s): ${2}" && return
  63. [ ${verbose} -eq 1 -o ${3} == "skipped" ] && echo "${2} test(s) ${3}:" && \
  64. sed -n "/^${3}: \(.*\)$/p" ${ptl_test_log} | awk '{ $1 = "\t"; print $0 }' && return
  65. if [ ${verbose} -gt 1 ]
  66. then
  67. lines=`sed -n "/^${3}: \(.*\)$/p" ${ptl_test_log} | awk '{ $1 = ""; gsub(/ /, "@", $0); print $0 }'`
  68. for line in ${lines}
  69. do
  70. line=${3^^}":"`echo ${line} | tr '@' ' '`
  71. echo ${line}
  72. sed -n "/${line}/,\${N;/^\n$/{P;q};P;D}" ${ptl_test_log} | \
  73. awk 'NR > 3 { sub(/.*Traceback/, "Traceback", $0); print " "$0}'
  74. done
  75. fi
  76. else
  77. echo ${2}
  78. fi
  79. fi
  80. }
  81. if [ $# -le 1 ]
  82. then
  83. usage
  84. exit 1
  85. fi
  86. ptl_test_log=$1
  87. if [ ! -r "${ptl_test_log}" ]
  88. then
  89. echo "${prog}: ${ptl_test_log} doesn't exist or does't have read permission!"
  90. exit 1
  91. fi
  92. total=0
  93. passes=0
  94. fails=0
  95. errors=0
  96. skipped=0
  97. timedout=0
  98. summary=0
  99. verbose=0
  100. runtime=0
  101. _space=0
  102. shift
  103. while [ "$1" != "" ]; do
  104. case $1 in
  105. -p | --passes) passes=1; shift;;
  106. -f | --fails) fails=1; shift;;
  107. -e | --errors) errors=1; shift;;
  108. -s | --skipped) skipped=1; shift ;;
  109. -T | --timedout) timedout=1; shift;;
  110. -v | --verbose) verbose=$((${verbose} + 1)); shift ;;
  111. -t | --total) total=1; shift;;
  112. -S | --summary) summary=1; shift;;
  113. -r | --runtime) runtime=1; shift;;
  114. -h | --help ) usage; exit 0;;
  115. * ) echo -en "Unknown Option: $1\n\n"; usage; exit 1;
  116. esac
  117. done
  118. summary_line=`sed -n '/^run:.*: [0-9]*$/p' ${ptl_test_log}`
  119. read total_ct pass_ct fail_ct err_ct skip_ct timedout_ct <<< \
  120. `echo ${summary_line} | awk -F '[,:]' \
  121. 'ORS=" " { for (i=2; i<=NF; i=i+2) { gsub(/^[ \t]+/, "", $i); print $i } }'`
  122. if [ ${total} -eq 1 ]
  123. then
  124. [ ${_space} -eq 1 ] && echo " " || _space=1
  125. [ ${verbose} -ge 1 ] && echo "Total test(s): ${total_ct}" || echo ${total_ct}
  126. fi
  127. if [ ${passes} -eq 1 ]
  128. then
  129. [ ${_space} -eq 1 ] && echo " " || _space=1
  130. [ ${verbose} -ge 1 ] && echo "Passed test(s): ${pass_ct}" || echo ${pass_ct}
  131. fi
  132. print_info ${fails} ${fail_ct} "failed"
  133. print_info ${errors} ${err_ct} "error"
  134. print_info ${skipped} ${skip_ct} "skipped"
  135. print_info ${timedout} ${timedout_ct} "timedout"
  136. if [ ${summary} -eq 1 ]
  137. then
  138. [ ${_space} -eq 1 ] && echo " " || _space=1
  139. [ ${verbose} -ge 1 ] && echo -en "Summary: \n\t "
  140. echo ${summary_line}
  141. fi
  142. if [ ${runtime} -eq 1 ]
  143. then
  144. test_run_output=`sed -n '/^Tests run in [\.:0-9]*$/p' ${ptl_test_log} | awk -F. '{print $1}'`
  145. [ ${_space} -eq 1 ] && echo " " || _space=1
  146. [ ${verbose} -ge 1 ] && echo ${test_run_output} || echo ${test_run_output} | awk '{ print $NF }'
  147. fi
  148. exit 0