/security/nss/coverage/report.sh

http://github.com/zpao/v8monkey · Shell · 238 lines · 167 code · 34 blank · 37 comment · 18 complexity · fa88be2d68f8fa2c84f0cf623dfcbef8 MD5 · raw file

  1. #!/bin/bash
  2. #
  3. # ***** BEGIN LICENSE BLOCK *****
  4. # Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5. #
  6. # The contents of this file are subject to the Mozilla Public License Version
  7. # 1.1 (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. # http://www.mozilla.org/MPL/
  10. #
  11. # Software distributed under the License is distributed on an "AS IS" basis,
  12. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. # for the specific language governing rights and limitations under the
  14. # License.
  15. #
  16. # The Original Code is the Network Security Services
  17. #
  18. # The Initial Developer of the Original Code is Sun Microsystems, Inc.
  19. # Portions created by the Initial Developer are Copyright (C) 2007-2009
  20. # Sun Microsystems, Inc. All Rights Reserved.
  21. #
  22. # Contributor(s):
  23. # Slavomir Katuscak <slavomir.katuscak@sun.com>, Sun Microsystems, Inc.
  24. #
  25. # Alternatively, the contents of this file may be used under the terms of
  26. # either the GNU General Public License Version 2 or later (the "GPL"), or
  27. # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28. # in which case the provisions of the GPL or the LGPL are applicable instead
  29. # of those above. If you wish to allow use of your version of this file only
  30. # under the terms of either the GPL or the LGPL, and not to allow others to
  31. # use your version of this file under the terms of the MPL, indicate your
  32. # decision by deleting the provisions above and replace them with the notice
  33. # and other provisions required by the GPL or the LGPL. If you do not delete
  34. # the provisions above, a recipient may use your version of this file under
  35. # the terms of any one of the MPL, the GPL or the LGPL.
  36. #
  37. # ***** END LICENSE BLOCK *****
  38. OS=`uname -s`
  39. ARCH=`uname -p`
  40. SCRIPT_DIR=`pwd`
  41. DATE=`date +%Y-%m-%d`
  42. if [ $# -lt 1 -o $# -gt 3 ]; then
  43. echo "Usage: $0 [securitytip|securityjes5] <date> <architecture>"
  44. exit 1
  45. fi
  46. BRANCH="$1"
  47. if [ "${BRANCH}" != "securitytip" -a "${BRANCH}" != "securityjes5" ]; then
  48. echo "Usage: $0 [securitytip|securityjes5] <date> <architecture>"
  49. exit 1
  50. fi
  51. if [ $# -ge 2 ]; then
  52. DATE=$2
  53. fi
  54. if [ $# -ge 3 ]; then
  55. ARCH=$3
  56. fi
  57. HEADER="Code Coverage - NSS - ${BRANCH} - ${OS}/${ARCH} - ${DATE}"
  58. COV_DIR="/share/builds/mccrel3/security/coverage"
  59. BRANCH_DIR="${COV_DIR}/${BRANCH}"
  60. DATE_DIR="${BRANCH_DIR}/${DATE}-${ARCH}"
  61. CVS_DIR="${DATE_DIR}/cvs_mozilla"
  62. TCOV_DIR="${DATE_DIR}/tcov_mozilla"
  63. OUTPUT="${DATE_DIR}/nss.html"
  64. LIB_PATH="/mozilla/security/nss/lib"
  65. CVS_PATH="${CVS_DIR}${LIB_PATH}"
  66. TCOV_PATH="${TCOV_DIR}${LIB_PATH}"
  67. MIN_GREEN=70
  68. MIN_YELLOW=40
  69. print_header()
  70. {
  71. echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final\">"
  72. echo "<HTML><HEAD><TITLE>${HEADER}</TITLE></HEAD><BODY>"
  73. echo "<TABLE ALIGN=\"CENTER\" WIDTH=\"100%\">"
  74. echo "<TR><TH BGCOLOR=\"GREY\"><H2>${HEADER}</H2></TH></TR>"
  75. echo "</TABLE><BR>"
  76. }
  77. print_footer()
  78. {
  79. echo "</BODY></HTML>"
  80. }
  81. print_notes()
  82. {
  83. echo "<TABLE ALIGN=\"CENTER\" WIDTH=\"100%\">"
  84. echo "<TR ALIGN=\"CENTER\" BGCOLOR=\"LIGHTGREY\"><TD><A HREF=\"http://wikihome.sfbay.sun.com/jes-security/Wiki.jsp?page=Code_Coverage_Test_Execution\">Test Execution Notes</A></TD></TR>"
  85. echo "</TABLE><BR>"
  86. }
  87. print_legend()
  88. {
  89. echo "<TABLE ALIGN=\"CENTER\" WIDTH=\"100%\">"
  90. echo "<TR ALIGN=\"CENTER\" BGCOLOR=\"GREY\"><TH>Legend</TH></TR>"
  91. echo "<TR ALIGN=\"CENTER\" BGCOLOR=\"LIGHTGREEN\"><TD>${MIN_GREEN}% - 100% of blocks tested</TD></TR>"
  92. echo "<TR ALIGN=\"CENTER\" BGCOLOR=\"YELLOW\"><TD>${MIN_YELLOW}% - ${MIN_GREEN}% of blocks tested</TD></TR>"
  93. echo "<TR ALIGN=\"CENTER\" BGCOLOR=\"ORANGE\"><TD>0% - ${MIN_YELLOW}% of blocks tested</TD></TR>"
  94. echo "<TR ALIGN=\"CENTER\" BGCOLOR=\"RED\"><TD>File not tested (these files are not included into statistics)</TD></TR>"
  95. echo "</TABLE>"
  96. }
  97. set_color()
  98. {
  99. if [ ${PERCENT_INT} -le ${MIN_YELLOW} ]; then
  100. bgcolor="ORANGE"
  101. elif [ ${PERCENT_INT} -le ${MIN_GREEN} ]; then
  102. bgcolor="YELLOW"
  103. else
  104. bgcolor="LIGHTGREEN"
  105. fi
  106. }
  107. create_table()
  108. {
  109. echo "<TABLE ALIGN=\"CENTER\" WIDTH=\"100%\">"
  110. echo "<TR><TH BGCOLOR=\"GREY\" COLSPAN=\"2\">${DIR}</TH></TR>"
  111. echo "<TR BGCOLOR=\"DARKGREY\"><TH WIDTH=\"50%\">File</TH>"
  112. echo "<TH>Tested blocks (Tested blocks/Total blocks/Total lines)</TR>"
  113. }
  114. close_table()
  115. {
  116. if [ "${LASTDIR}" != "" ]; then
  117. if [ ${DFILES} -gt 0 ]; then
  118. if [ ${DBLOCKS_TOTAL} -eq 0 ]; then
  119. PERCENT_INT=0
  120. else
  121. PERCENT_INT=`expr ${DBLOCKS_EXEC} \* 100 \/ ${DBLOCKS_TOTAL}`
  122. fi
  123. set_color
  124. echo "<TR><TH BGCOLOR=\"${bgcolor}\" COLSPAN=\"2\">Total: ${PERCENT_INT}% (${DBLOCKS_EXEC}/${DBLOCKS_TOTAL})</TH></TR>"
  125. else
  126. echo "<TR><TH BGCOLOR=\"RED\" COLSPAN=\"2\">Total: Not tested</TH></TR>"
  127. fi
  128. echo "</TABLE><BR>"
  129. fi
  130. }
  131. print_line()
  132. {
  133. LINES_TOTAL=`wc -l "${file}" | /usr/bin/awk '{print $1}'`
  134. if [ -r "${TCOV_PATH}/${DIR}/${FILE}" ]; then
  135. BLOCKS_EXEC=`cat "${TCOV_PATH}/${DIR}/${FILE}" | grep "Basic blocks executed" | /usr/bin/awk '{print $1}'`
  136. BLOCKS_TOTAL=`cat "${TCOV_PATH}/${DIR}/${FILE}" | grep "Basic blocks in this file" | /usr/bin/awk '{print $1}'`
  137. DBLOCKS_EXEC=`expr ${DBLOCKS_EXEC} + ${BLOCKS_EXEC}`
  138. DBLOCKS_TOTAL=`expr ${DBLOCKS_TOTAL} + ${BLOCKS_TOTAL}`
  139. TBLOCKS_EXEC=`expr ${TBLOCKS_EXEC} + ${BLOCKS_EXEC}`
  140. TBLOCKS_TOTAL=`expr ${TBLOCKS_TOTAL} + ${BLOCKS_TOTAL}`
  141. TFILES=`expr ${TFILES} + 1`
  142. DFILES=`expr ${DFILES} + 1`
  143. PERCENT_EXEC=`cat "${TCOV_PATH}/${DIR}/${FILE}" | grep "Percent of the file executed" | /usr/bin/awk '{print $1}'`
  144. PERCENT_INT=`echo ${PERCENT_EXEC} | cut -d. -f1`
  145. set_color
  146. echo "<TR><TD BGCOLOR=\"LIGHTGREY\"><A HREF=\"${TCOV_PATH}/${DIR}/${FILE}\">${FILE}</A></TD>"
  147. echo "<TD BGCOLOR=\"${bgcolor}\">${PERCENT_EXEC}% (${BLOCKS_EXEC}/${BLOCKS_TOTAL}/${LINES_TOTAL})</TD></TR>"
  148. else
  149. echo "<TR><TD BGCOLOR=\"LIGHTGREY\"><A HREF=\"${file}\">${FILE}</A></TD>"
  150. echo "<TD BGCOLOR=\"RED\">Not tested (0/?/${LINES_TOTAL})</TD></TR>"
  151. fi
  152. }
  153. print_total()
  154. {
  155. echo "<TABLE ALIGN=\"CENTER\" WIDTH=\"100%\">"
  156. if [ ${TFILES} -gt 0 ]; then
  157. if [ ${TBLOCKS_TOTAL} -eq 0 ]; then
  158. PERCENT_INT=0
  159. else
  160. PERCENT_INT=`expr ${TBLOCKS_EXEC} \* 100 \/ ${TBLOCKS_TOTAL}`
  161. fi
  162. set_color
  163. echo "<TR><TH BGCOLOR=\"${bgcolor}\"><H2>Total: ${PERCENT_INT}% (${TBLOCKS_EXEC}/${TBLOCKS_TOTAL})</H2></TH></TR>"
  164. else
  165. echo "<TR><TH BGCOLOR=\"RED\"><H2>Total: Not tested</H2></TH></TR>"
  166. fi
  167. echo "</TABLE><BR>"
  168. }
  169. process_cmd()
  170. {
  171. LASTDIR=""
  172. TBLOCKS_EXEC=0
  173. TBLOCKS_TOTAL=0
  174. TFILES=0
  175. for dir in `find "${CVS_PATH}" -type d | sort`
  176. do
  177. DIR=`echo "${dir}" | sed "s:^${CVS_PATH}/::"`
  178. for file in `ls -1 ${dir}/*.c 2> /dev/null`
  179. do
  180. if [ "${DIR}" != "${LASTDIR}" ]; then
  181. close_table
  182. create_table
  183. LASTDIR="${DIR}";
  184. DBLOCKS_EXEC=0
  185. DBLOCKS_TOTAL=0
  186. DFILES=0
  187. fi
  188. FILE=`echo "${file}" | sed "s:^.*/\(.*.c\):\1:"`
  189. print_line
  190. done
  191. done
  192. close_table
  193. print_total
  194. }
  195. report()
  196. {
  197. print_header > "${OUTPUT}"
  198. print_notes >> "${OUTPUT}"
  199. process_cmd >> "${OUTPUT}"
  200. print_legend >> "${OUTPUT}"
  201. print_footer >> "${OUTPUT}"
  202. }
  203. report
  204. exit 0