1*c33452fbSAndroid Build Coastguard Worker#!/bin/bash 2*c33452fbSAndroid Build Coastguard Worker 3*c33452fbSAndroid Build Coastguard Worker# Copyright (c) 2011-2014, Intel Corporation 4*c33452fbSAndroid Build Coastguard Worker# All rights reserved. 5*c33452fbSAndroid Build Coastguard Worker# 6*c33452fbSAndroid Build Coastguard Worker# Redistribution and use in source and binary forms, with or without modification, 7*c33452fbSAndroid Build Coastguard Worker# are permitted provided that the following conditions are met: 8*c33452fbSAndroid Build Coastguard Worker# 9*c33452fbSAndroid Build Coastguard Worker# 1. Redistributions of source code must retain the above copyright notice, this 10*c33452fbSAndroid Build Coastguard Worker# list of conditions and the following disclaimer. 11*c33452fbSAndroid Build Coastguard Worker# 12*c33452fbSAndroid Build Coastguard Worker# 2. Redistributions in binary form must reproduce the above copyright notice, 13*c33452fbSAndroid Build Coastguard Worker# this list of conditions and the following disclaimer in the documentation and/or 14*c33452fbSAndroid Build Coastguard Worker# other materials provided with the distribution. 15*c33452fbSAndroid Build Coastguard Worker# 16*c33452fbSAndroid Build Coastguard Worker# 3. Neither the name of the copyright holder nor the names of its contributors 17*c33452fbSAndroid Build Coastguard Worker# may be used to endorse or promote products derived from this software without 18*c33452fbSAndroid Build Coastguard Worker# specific prior written permission. 19*c33452fbSAndroid Build Coastguard Worker# 20*c33452fbSAndroid Build Coastguard Worker# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21*c33452fbSAndroid Build Coastguard Worker# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22*c33452fbSAndroid Build Coastguard Worker# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23*c33452fbSAndroid Build Coastguard Worker# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24*c33452fbSAndroid Build Coastguard Worker# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25*c33452fbSAndroid Build Coastguard Worker# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26*c33452fbSAndroid Build Coastguard Worker# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27*c33452fbSAndroid Build Coastguard Worker# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28*c33452fbSAndroid Build Coastguard Worker# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29*c33452fbSAndroid Build Coastguard Worker# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30*c33452fbSAndroid Build Coastguard Worker 31*c33452fbSAndroid Build Coastguard Worker 32*c33452fbSAndroid Build Coastguard Workerset -euo pipefail 33*c33452fbSAndroid Build Coastguard Worker 34*c33452fbSAndroid Build Coastguard Workerxml_report_generation="$(dirname $0)/coverage.py" 35*c33452fbSAndroid Build Coastguard Workerxsl_report_formator="$(dirname $0)/coverage.xsl" 36*c33452fbSAndroid Build Coastguard Worker 37*c33452fbSAndroid Build Coastguard Workerhelp () { 38*c33452fbSAndroid Build Coastguard Worker echo "Usage: $0: [OPTION]... [LOGS_FILE]..." 39*c33452fbSAndroid Build Coastguard Worker echo "Generate domain coverage report from aplogs." 40*c33452fbSAndroid Build Coastguard Worker echo 41*c33452fbSAndroid Build Coastguard Worker echo "Supported options: 42*c33452fbSAndroid Build Coastguard Worker -h, --help Display this help 43*c33452fbSAndroid Build Coastguard Worker -d, --domains The domain xml file 44*c33452fbSAndroid Build Coastguard Worker -o, --ouput Output the report to a file instead of stdout 45*c33452fbSAndroid Build Coastguard Worker -e, --regexp A regex to filter (egrep) logs in order to keep only the PFW log lines 46*c33452fbSAndroid Build Coastguard Worker -f, --force Force log parser to continue on ignorable errors 47*c33452fbSAndroid Build Coastguard Worker -p, --parser_option Options to apply to the log parser" 48*c33452fbSAndroid Build Coastguard Worker echo 49*c33452fbSAndroid Build Coastguard Worker echo 'FIXME: Having more than one dot (".") in aplog paths is not supported.' 50*c33452fbSAndroid Build Coastguard Worker echo " - OK: log/aplog.12" 51*c33452fbSAndroid Build Coastguard Worker echo " - KO: ../aplog.12" 52*c33452fbSAndroid Build Coastguard Worker} 53*c33452fbSAndroid Build Coastguard Worker 54*c33452fbSAndroid Build Coastguard Worker# Default values 55*c33452fbSAndroid Build Coastguard WorkeroutputFile="-" 56*c33452fbSAndroid Build Coastguard Workercoverage_report_generator_ignorable_errors="\ 57*c33452fbSAndroid Build Coastguard Worker--ignore-unknown-criterion \ 58*c33452fbSAndroid Build Coastguard Worker--ignore-incoherent-criterion-state \ 59*c33452fbSAndroid Build Coastguard Worker--ignore-ineligible-configuration-application" 60*c33452fbSAndroid Build Coastguard Workercoverage_report_generator_options="" 61*c33452fbSAndroid Build Coastguard Worker 62*c33452fbSAndroid Build Coastguard Worker# Parse command line arguments 63*c33452fbSAndroid Build Coastguard WorkerARGS="$(getopt --options "hd:o:e:p:f" \ 64*c33452fbSAndroid Build Coastguard Worker --longoptions "help,domains:,ouput:,regexp:,parser_option:,force" \ 65*c33452fbSAndroid Build Coastguard Worker --name "$0" -- "$@" )" 66*c33452fbSAndroid Build Coastguard Worker 67*c33452fbSAndroid Build Coastguard Workereval set -- "$ARGS" 68*c33452fbSAndroid Build Coastguard Worker 69*c33452fbSAndroid Build Coastguard Worker 70*c33452fbSAndroid Build Coastguard Workerwhile true; 71*c33452fbSAndroid Build Coastguard Workerdo 72*c33452fbSAndroid Build Coastguard Worker case "$1" in 73*c33452fbSAndroid Build Coastguard Worker -h|--help) 74*c33452fbSAndroid Build Coastguard Worker shift 75*c33452fbSAndroid Build Coastguard Worker help 76*c33452fbSAndroid Build Coastguard Worker exit 0 77*c33452fbSAndroid Build Coastguard Worker ;; 78*c33452fbSAndroid Build Coastguard Worker -d|--domains) 79*c33452fbSAndroid Build Coastguard Worker shift 80*c33452fbSAndroid Build Coastguard Worker domainsFile="$1" 81*c33452fbSAndroid Build Coastguard Worker shift 82*c33452fbSAndroid Build Coastguard Worker ;; 83*c33452fbSAndroid Build Coastguard Worker -o|--output) 84*c33452fbSAndroid Build Coastguard Worker shift 85*c33452fbSAndroid Build Coastguard Worker outputFile="$1" 86*c33452fbSAndroid Build Coastguard Worker shift 87*c33452fbSAndroid Build Coastguard Worker ;; 88*c33452fbSAndroid Build Coastguard Worker -e|--regex) 89*c33452fbSAndroid Build Coastguard Worker shift 90*c33452fbSAndroid Build Coastguard Worker filterRegex="$1" 91*c33452fbSAndroid Build Coastguard Worker shift 92*c33452fbSAndroid Build Coastguard Worker ;; 93*c33452fbSAndroid Build Coastguard Worker -p|--parser_option) 94*c33452fbSAndroid Build Coastguard Worker shift 95*c33452fbSAndroid Build Coastguard Worker coverage_report_generator_options+="$1 " 96*c33452fbSAndroid Build Coastguard Worker shift 97*c33452fbSAndroid Build Coastguard Worker ;; 98*c33452fbSAndroid Build Coastguard Worker -f|--force) 99*c33452fbSAndroid Build Coastguard Worker shift 100*c33452fbSAndroid Build Coastguard Worker coverage_report_generator_options+="$coverage_report_generator_ignorable_errors " 101*c33452fbSAndroid Build Coastguard Worker ;; 102*c33452fbSAndroid Build Coastguard Worker --) 103*c33452fbSAndroid Build Coastguard Worker shift 104*c33452fbSAndroid Build Coastguard Worker break 105*c33452fbSAndroid Build Coastguard Worker ;; 106*c33452fbSAndroid Build Coastguard Worker esac 107*c33452fbSAndroid Build Coastguard Workerdone 108*c33452fbSAndroid Build Coastguard Worker 109*c33452fbSAndroid Build Coastguard Workerif ! test "${domainsFile:-}" 110*c33452fbSAndroid Build Coastguard Workerthen 111*c33452fbSAndroid Build Coastguard Worker echo "Please provide a xml domain file." 112*c33452fbSAndroid Build Coastguard Worker exit 2 113*c33452fbSAndroid Build Coastguard Workerfi 114*c33452fbSAndroid Build Coastguard Worker 115*c33452fbSAndroid Build Coastguard Workerif ! test "${filterRegex:-}" 116*c33452fbSAndroid Build Coastguard Workerthen 117*c33452fbSAndroid Build Coastguard Worker echo "Please provide a regex to filter log." 118*c33452fbSAndroid Build Coastguard Worker echo "Other PFW instances log lines must not be matched by this regex." 119*c33452fbSAndroid Build Coastguard Worker exit 3 120*c33452fbSAndroid Build Coastguard Workerfi 121*c33452fbSAndroid Build Coastguard Worker 122*c33452fbSAndroid Build Coastguard Workerprintf "%s\0" "$@" | 123*c33452fbSAndroid Build Coastguard Worker # Sort aplogs in chronological order 124*c33452fbSAndroid Build Coastguard Worker sort --key=2 --field-separator=. --numeric-sort --zero-terminated --reverse | 125*c33452fbSAndroid Build Coastguard Worker # Filter log to leave only PFW log lines 126*c33452fbSAndroid Build Coastguard Worker xargs --null grep --extended-regexp "$filterRegex" | 127*c33452fbSAndroid Build Coastguard Worker # Generate the xml report 128*c33452fbSAndroid Build Coastguard Worker $xml_report_generation --xml $coverage_report_generator_options "$domainsFile" | 129*c33452fbSAndroid Build Coastguard Worker # Generate the html report 130*c33452fbSAndroid Build Coastguard Worker xsltproc --output "$outputFile" $xsl_report_formator - 131*c33452fbSAndroid Build Coastguard Worker 132