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