michael@0: #!/bin/bash michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: OS=`uname -s` michael@0: ARCH=`uname -p` michael@0: SCRIPT_DIR=`pwd` michael@0: DATE=`date +%Y-%m-%d` michael@0: michael@0: if [ $# -lt 1 -o $# -gt 3 ]; then michael@0: echo "Usage: $0 [securitytip|securityjes5] " michael@0: exit 1 michael@0: fi michael@0: michael@0: BRANCH="$1" michael@0: michael@0: if [ "${BRANCH}" != "securitytip" -a "${BRANCH}" != "securityjes5" ]; then michael@0: echo "Usage: $0 [securitytip|securityjes5] " michael@0: exit 1 michael@0: fi michael@0: michael@0: if [ $# -ge 2 ]; then michael@0: DATE=$2 michael@0: fi michael@0: michael@0: if [ $# -ge 3 ]; then michael@0: ARCH=$3 michael@0: fi michael@0: michael@0: HEADER="Code Coverage - NSS - ${BRANCH} - ${OS}/${ARCH} - ${DATE}" michael@0: michael@0: COV_DIR="/share/builds/mccrel3/security/coverage" michael@0: BRANCH_DIR="${COV_DIR}/${BRANCH}" michael@0: DATE_DIR="${BRANCH_DIR}/${DATE}-${ARCH}" michael@0: CVS_DIR="${DATE_DIR}/cvs_mozilla" michael@0: TCOV_DIR="${DATE_DIR}/tcov_mozilla" michael@0: OUTPUT="${DATE_DIR}/nss.html" michael@0: michael@0: LIB_PATH="/mozilla/security/nss/lib" michael@0: CVS_PATH="${CVS_DIR}${LIB_PATH}" michael@0: TCOV_PATH="${TCOV_DIR}${LIB_PATH}" michael@0: michael@0: MIN_GREEN=70 michael@0: MIN_YELLOW=40 michael@0: michael@0: print_header() michael@0: { michael@0: echo "" michael@0: echo "${HEADER}" michael@0: echo "" michael@0: echo "" michael@0: echo "

${HEADER}


" michael@0: } michael@0: michael@0: print_footer() michael@0: { michael@0: echo "" michael@0: } michael@0: michael@0: print_notes() michael@0: { michael@0: echo "" michael@0: echo "" michael@0: echo "
Test Execution Notes

" michael@0: } michael@0: michael@0: print_legend() michael@0: { michael@0: echo "" michael@0: echo "" michael@0: echo "" michael@0: echo "" michael@0: echo "" michael@0: echo "" michael@0: echo "
Legend
${MIN_GREEN}% - 100% of blocks tested
${MIN_YELLOW}% - ${MIN_GREEN}% of blocks tested
0% - ${MIN_YELLOW}% of blocks tested
File not tested (these files are not included into statistics)
" michael@0: } michael@0: michael@0: set_color() michael@0: { michael@0: if [ ${PERCENT_INT} -le ${MIN_YELLOW} ]; then michael@0: bgcolor="ORANGE" michael@0: elif [ ${PERCENT_INT} -le ${MIN_GREEN} ]; then michael@0: bgcolor="YELLOW" michael@0: else michael@0: bgcolor="LIGHTGREEN" michael@0: fi michael@0: } michael@0: michael@0: create_table() michael@0: { michael@0: echo "" michael@0: echo "" michael@0: echo "" michael@0: echo "" michael@0: } michael@0: michael@0: close_table() michael@0: { michael@0: if [ "${LASTDIR}" != "" ]; then michael@0: if [ ${DFILES} -gt 0 ]; then michael@0: if [ ${DBLOCKS_TOTAL} -eq 0 ]; then michael@0: PERCENT_INT=0 michael@0: else michael@0: PERCENT_INT=`expr ${DBLOCKS_EXEC} \* 100 \/ ${DBLOCKS_TOTAL}` michael@0: fi michael@0: set_color michael@0: michael@0: echo "" michael@0: else michael@0: echo "" michael@0: fi michael@0: echo "
${DIR}
FileTested blocks (Tested blocks/Total blocks/Total lines)
Total: ${PERCENT_INT}% (${DBLOCKS_EXEC}/${DBLOCKS_TOTAL})
Total: Not tested

" michael@0: fi michael@0: } michael@0: michael@0: print_line() michael@0: { michael@0: LINES_TOTAL=`wc -l "${file}" | /usr/bin/awk '{print $1}'` michael@0: michael@0: if [ -r "${TCOV_PATH}/${DIR}/${FILE}" ]; then michael@0: BLOCKS_EXEC=`cat "${TCOV_PATH}/${DIR}/${FILE}" | grep "Basic blocks executed" | /usr/bin/awk '{print $1}'` michael@0: BLOCKS_TOTAL=`cat "${TCOV_PATH}/${DIR}/${FILE}" | grep "Basic blocks in this file" | /usr/bin/awk '{print $1}'` michael@0: michael@0: DBLOCKS_EXEC=`expr ${DBLOCKS_EXEC} + ${BLOCKS_EXEC}` michael@0: DBLOCKS_TOTAL=`expr ${DBLOCKS_TOTAL} + ${BLOCKS_TOTAL}` michael@0: TBLOCKS_EXEC=`expr ${TBLOCKS_EXEC} + ${BLOCKS_EXEC}` michael@0: TBLOCKS_TOTAL=`expr ${TBLOCKS_TOTAL} + ${BLOCKS_TOTAL}` michael@0: michael@0: TFILES=`expr ${TFILES} + 1` michael@0: DFILES=`expr ${DFILES} + 1` michael@0: michael@0: PERCENT_EXEC=`cat "${TCOV_PATH}/${DIR}/${FILE}" | grep "Percent of the file executed" | /usr/bin/awk '{print $1}'` michael@0: PERCENT_INT=`echo ${PERCENT_EXEC} | cut -d. -f1` michael@0: set_color michael@0: michael@0: echo "${FILE}" michael@0: echo "${PERCENT_EXEC}% (${BLOCKS_EXEC}/${BLOCKS_TOTAL}/${LINES_TOTAL})" michael@0: else michael@0: echo "${FILE}" michael@0: echo "Not tested (0/?/${LINES_TOTAL})" michael@0: fi michael@0: } michael@0: michael@0: print_total() michael@0: { michael@0: echo "" michael@0: if [ ${TFILES} -gt 0 ]; then michael@0: if [ ${TBLOCKS_TOTAL} -eq 0 ]; then michael@0: PERCENT_INT=0 michael@0: else michael@0: PERCENT_INT=`expr ${TBLOCKS_EXEC} \* 100 \/ ${TBLOCKS_TOTAL}` michael@0: fi michael@0: set_color michael@0: michael@0: echo "" michael@0: else michael@0: echo "" michael@0: fi michael@0: echo "

Total: ${PERCENT_INT}% (${TBLOCKS_EXEC}/${TBLOCKS_TOTAL})

Total: Not tested


" michael@0: } michael@0: michael@0: process_cmd() michael@0: { michael@0: LASTDIR="" michael@0: TBLOCKS_EXEC=0 michael@0: TBLOCKS_TOTAL=0 michael@0: TFILES=0 michael@0: michael@0: for dir in `find "${CVS_PATH}" -type d | sort` michael@0: do michael@0: DIR=`echo "${dir}" | sed "s:^${CVS_PATH}/::"` michael@0: for file in `ls -1 ${dir}/*.c 2> /dev/null` michael@0: do michael@0: if [ "${DIR}" != "${LASTDIR}" ]; then michael@0: close_table michael@0: create_table michael@0: michael@0: LASTDIR="${DIR}"; michael@0: DBLOCKS_EXEC=0 michael@0: DBLOCKS_TOTAL=0 michael@0: DFILES=0 michael@0: fi michael@0: michael@0: FILE=`echo "${file}" | sed "s:^.*/\(.*.c\):\1:"` michael@0: print_line michael@0: done michael@0: done michael@0: michael@0: close_table michael@0: print_total michael@0: } michael@0: michael@0: report() michael@0: { michael@0: print_header > "${OUTPUT}" michael@0: print_notes >> "${OUTPUT}" michael@0: process_cmd >> "${OUTPUT}" michael@0: print_legend >> "${OUTPUT}" michael@0: print_footer >> "${OUTPUT}" michael@0: } michael@0: michael@0: report michael@0: michael@0: exit 0