Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | #!/bin/bash |
michael@0 | 2 | # |
michael@0 | 3 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 6 | |
michael@0 | 7 | OS=`uname -s` |
michael@0 | 8 | ARCH=`uname -p` |
michael@0 | 9 | SCRIPT_DIR=`pwd` |
michael@0 | 10 | DATE=`date +%Y-%m-%d` |
michael@0 | 11 | |
michael@0 | 12 | if [ $# -lt 1 -o $# -gt 3 ]; then |
michael@0 | 13 | echo "Usage: $0 [securitytip|securityjes5] <date> <architecture>" |
michael@0 | 14 | exit 1 |
michael@0 | 15 | fi |
michael@0 | 16 | |
michael@0 | 17 | BRANCH="$1" |
michael@0 | 18 | |
michael@0 | 19 | if [ "${BRANCH}" != "securitytip" -a "${BRANCH}" != "securityjes5" ]; then |
michael@0 | 20 | echo "Usage: $0 [securitytip|securityjes5] <date> <architecture>" |
michael@0 | 21 | exit 1 |
michael@0 | 22 | fi |
michael@0 | 23 | |
michael@0 | 24 | if [ $# -ge 2 ]; then |
michael@0 | 25 | DATE=$2 |
michael@0 | 26 | fi |
michael@0 | 27 | |
michael@0 | 28 | if [ $# -ge 3 ]; then |
michael@0 | 29 | ARCH=$3 |
michael@0 | 30 | fi |
michael@0 | 31 | |
michael@0 | 32 | HEADER="Code Coverage - NSS - ${BRANCH} - ${OS}/${ARCH} - ${DATE}" |
michael@0 | 33 | |
michael@0 | 34 | COV_DIR="/share/builds/mccrel3/security/coverage" |
michael@0 | 35 | BRANCH_DIR="${COV_DIR}/${BRANCH}" |
michael@0 | 36 | DATE_DIR="${BRANCH_DIR}/${DATE}-${ARCH}" |
michael@0 | 37 | CVS_DIR="${DATE_DIR}/cvs_mozilla" |
michael@0 | 38 | TCOV_DIR="${DATE_DIR}/tcov_mozilla" |
michael@0 | 39 | OUTPUT="${DATE_DIR}/nss.html" |
michael@0 | 40 | |
michael@0 | 41 | LIB_PATH="/mozilla/security/nss/lib" |
michael@0 | 42 | CVS_PATH="${CVS_DIR}${LIB_PATH}" |
michael@0 | 43 | TCOV_PATH="${TCOV_DIR}${LIB_PATH}" |
michael@0 | 44 | |
michael@0 | 45 | MIN_GREEN=70 |
michael@0 | 46 | MIN_YELLOW=40 |
michael@0 | 47 | |
michael@0 | 48 | print_header() |
michael@0 | 49 | { |
michael@0 | 50 | echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final\">" |
michael@0 | 51 | echo "<HTML><HEAD><TITLE>${HEADER}</TITLE></HEAD><BODY>" |
michael@0 | 52 | echo "<TABLE ALIGN=\"CENTER\" WIDTH=\"100%\">" |
michael@0 | 53 | echo "<TR><TH BGCOLOR=\"GREY\"><H2>${HEADER}</H2></TH></TR>" |
michael@0 | 54 | echo "</TABLE><BR>" |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | print_footer() |
michael@0 | 58 | { |
michael@0 | 59 | echo "</BODY></HTML>" |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | print_notes() |
michael@0 | 63 | { |
michael@0 | 64 | echo "<TABLE ALIGN=\"CENTER\" WIDTH=\"100%\">" |
michael@0 | 65 | 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>" |
michael@0 | 66 | echo "</TABLE><BR>" |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | print_legend() |
michael@0 | 70 | { |
michael@0 | 71 | echo "<TABLE ALIGN=\"CENTER\" WIDTH=\"100%\">" |
michael@0 | 72 | echo "<TR ALIGN=\"CENTER\" BGCOLOR=\"GREY\"><TH>Legend</TH></TR>" |
michael@0 | 73 | echo "<TR ALIGN=\"CENTER\" BGCOLOR=\"LIGHTGREEN\"><TD>${MIN_GREEN}% - 100% of blocks tested</TD></TR>" |
michael@0 | 74 | echo "<TR ALIGN=\"CENTER\" BGCOLOR=\"YELLOW\"><TD>${MIN_YELLOW}% - ${MIN_GREEN}% of blocks tested</TD></TR>" |
michael@0 | 75 | echo "<TR ALIGN=\"CENTER\" BGCOLOR=\"ORANGE\"><TD>0% - ${MIN_YELLOW}% of blocks tested</TD></TR>" |
michael@0 | 76 | echo "<TR ALIGN=\"CENTER\" BGCOLOR=\"RED\"><TD>File not tested (these files are not included into statistics)</TD></TR>" |
michael@0 | 77 | echo "</TABLE>" |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | set_color() |
michael@0 | 81 | { |
michael@0 | 82 | if [ ${PERCENT_INT} -le ${MIN_YELLOW} ]; then |
michael@0 | 83 | bgcolor="ORANGE" |
michael@0 | 84 | elif [ ${PERCENT_INT} -le ${MIN_GREEN} ]; then |
michael@0 | 85 | bgcolor="YELLOW" |
michael@0 | 86 | else |
michael@0 | 87 | bgcolor="LIGHTGREEN" |
michael@0 | 88 | fi |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | create_table() |
michael@0 | 92 | { |
michael@0 | 93 | echo "<TABLE ALIGN=\"CENTER\" WIDTH=\"100%\">" |
michael@0 | 94 | echo "<TR><TH BGCOLOR=\"GREY\" COLSPAN=\"2\">${DIR}</TH></TR>" |
michael@0 | 95 | echo "<TR BGCOLOR=\"DARKGREY\"><TH WIDTH=\"50%\">File</TH>" |
michael@0 | 96 | echo "<TH>Tested blocks (Tested blocks/Total blocks/Total lines)</TR>" |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | close_table() |
michael@0 | 100 | { |
michael@0 | 101 | if [ "${LASTDIR}" != "" ]; then |
michael@0 | 102 | if [ ${DFILES} -gt 0 ]; then |
michael@0 | 103 | if [ ${DBLOCKS_TOTAL} -eq 0 ]; then |
michael@0 | 104 | PERCENT_INT=0 |
michael@0 | 105 | else |
michael@0 | 106 | PERCENT_INT=`expr ${DBLOCKS_EXEC} \* 100 \/ ${DBLOCKS_TOTAL}` |
michael@0 | 107 | fi |
michael@0 | 108 | set_color |
michael@0 | 109 | |
michael@0 | 110 | echo "<TR><TH BGCOLOR=\"${bgcolor}\" COLSPAN=\"2\">Total: ${PERCENT_INT}% (${DBLOCKS_EXEC}/${DBLOCKS_TOTAL})</TH></TR>" |
michael@0 | 111 | else |
michael@0 | 112 | echo "<TR><TH BGCOLOR=\"RED\" COLSPAN=\"2\">Total: Not tested</TH></TR>" |
michael@0 | 113 | fi |
michael@0 | 114 | echo "</TABLE><BR>" |
michael@0 | 115 | fi |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | print_line() |
michael@0 | 119 | { |
michael@0 | 120 | LINES_TOTAL=`wc -l "${file}" | /usr/bin/awk '{print $1}'` |
michael@0 | 121 | |
michael@0 | 122 | if [ -r "${TCOV_PATH}/${DIR}/${FILE}" ]; then |
michael@0 | 123 | BLOCKS_EXEC=`cat "${TCOV_PATH}/${DIR}/${FILE}" | grep "Basic blocks executed" | /usr/bin/awk '{print $1}'` |
michael@0 | 124 | BLOCKS_TOTAL=`cat "${TCOV_PATH}/${DIR}/${FILE}" | grep "Basic blocks in this file" | /usr/bin/awk '{print $1}'` |
michael@0 | 125 | |
michael@0 | 126 | DBLOCKS_EXEC=`expr ${DBLOCKS_EXEC} + ${BLOCKS_EXEC}` |
michael@0 | 127 | DBLOCKS_TOTAL=`expr ${DBLOCKS_TOTAL} + ${BLOCKS_TOTAL}` |
michael@0 | 128 | TBLOCKS_EXEC=`expr ${TBLOCKS_EXEC} + ${BLOCKS_EXEC}` |
michael@0 | 129 | TBLOCKS_TOTAL=`expr ${TBLOCKS_TOTAL} + ${BLOCKS_TOTAL}` |
michael@0 | 130 | |
michael@0 | 131 | TFILES=`expr ${TFILES} + 1` |
michael@0 | 132 | DFILES=`expr ${DFILES} + 1` |
michael@0 | 133 | |
michael@0 | 134 | PERCENT_EXEC=`cat "${TCOV_PATH}/${DIR}/${FILE}" | grep "Percent of the file executed" | /usr/bin/awk '{print $1}'` |
michael@0 | 135 | PERCENT_INT=`echo ${PERCENT_EXEC} | cut -d. -f1` |
michael@0 | 136 | set_color |
michael@0 | 137 | |
michael@0 | 138 | echo "<TR><TD BGCOLOR=\"LIGHTGREY\"><A HREF=\"${TCOV_PATH}/${DIR}/${FILE}\">${FILE}</A></TD>" |
michael@0 | 139 | echo "<TD BGCOLOR=\"${bgcolor}\">${PERCENT_EXEC}% (${BLOCKS_EXEC}/${BLOCKS_TOTAL}/${LINES_TOTAL})</TD></TR>" |
michael@0 | 140 | else |
michael@0 | 141 | echo "<TR><TD BGCOLOR=\"LIGHTGREY\"><A HREF=\"${file}\">${FILE}</A></TD>" |
michael@0 | 142 | echo "<TD BGCOLOR=\"RED\">Not tested (0/?/${LINES_TOTAL})</TD></TR>" |
michael@0 | 143 | fi |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | print_total() |
michael@0 | 147 | { |
michael@0 | 148 | echo "<TABLE ALIGN=\"CENTER\" WIDTH=\"100%\">" |
michael@0 | 149 | if [ ${TFILES} -gt 0 ]; then |
michael@0 | 150 | if [ ${TBLOCKS_TOTAL} -eq 0 ]; then |
michael@0 | 151 | PERCENT_INT=0 |
michael@0 | 152 | else |
michael@0 | 153 | PERCENT_INT=`expr ${TBLOCKS_EXEC} \* 100 \/ ${TBLOCKS_TOTAL}` |
michael@0 | 154 | fi |
michael@0 | 155 | set_color |
michael@0 | 156 | |
michael@0 | 157 | echo "<TR><TH BGCOLOR=\"${bgcolor}\"><H2>Total: ${PERCENT_INT}% (${TBLOCKS_EXEC}/${TBLOCKS_TOTAL})</H2></TH></TR>" |
michael@0 | 158 | else |
michael@0 | 159 | echo "<TR><TH BGCOLOR=\"RED\"><H2>Total: Not tested</H2></TH></TR>" |
michael@0 | 160 | fi |
michael@0 | 161 | echo "</TABLE><BR>" |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | process_cmd() |
michael@0 | 165 | { |
michael@0 | 166 | LASTDIR="" |
michael@0 | 167 | TBLOCKS_EXEC=0 |
michael@0 | 168 | TBLOCKS_TOTAL=0 |
michael@0 | 169 | TFILES=0 |
michael@0 | 170 | |
michael@0 | 171 | for dir in `find "${CVS_PATH}" -type d | sort` |
michael@0 | 172 | do |
michael@0 | 173 | DIR=`echo "${dir}" | sed "s:^${CVS_PATH}/::"` |
michael@0 | 174 | for file in `ls -1 ${dir}/*.c 2> /dev/null` |
michael@0 | 175 | do |
michael@0 | 176 | if [ "${DIR}" != "${LASTDIR}" ]; then |
michael@0 | 177 | close_table |
michael@0 | 178 | create_table |
michael@0 | 179 | |
michael@0 | 180 | LASTDIR="${DIR}"; |
michael@0 | 181 | DBLOCKS_EXEC=0 |
michael@0 | 182 | DBLOCKS_TOTAL=0 |
michael@0 | 183 | DFILES=0 |
michael@0 | 184 | fi |
michael@0 | 185 | |
michael@0 | 186 | FILE=`echo "${file}" | sed "s:^.*/\(.*.c\):\1:"` |
michael@0 | 187 | print_line |
michael@0 | 188 | done |
michael@0 | 189 | done |
michael@0 | 190 | |
michael@0 | 191 | close_table |
michael@0 | 192 | print_total |
michael@0 | 193 | } |
michael@0 | 194 | |
michael@0 | 195 | report() |
michael@0 | 196 | { |
michael@0 | 197 | print_header > "${OUTPUT}" |
michael@0 | 198 | print_notes >> "${OUTPUT}" |
michael@0 | 199 | process_cmd >> "${OUTPUT}" |
michael@0 | 200 | print_legend >> "${OUTPUT}" |
michael@0 | 201 | print_footer >> "${OUTPUT}" |
michael@0 | 202 | } |
michael@0 | 203 | |
michael@0 | 204 | report |
michael@0 | 205 | |
michael@0 | 206 | exit 0 |