1#!/usr/bin/env python 2# 3# Filter coverage reported by lcov/genhtml 4# 5# Copyright 2012 BlueKitchen GmbH 6# 7from lxml import html 8import sys 9import os 10 11coverage_html_path = "coverage-html/index.html" 12 13summary = {} 14 15def update_category(name, value): 16 old = 0 17 if name in summary: 18 old = summary[name] 19 summary[name] = old + value 20 21def list_category_table(): 22 row = "%-11s |%11s |%11s |%11s" 23 24 print( row % ('', 'Hit', 'Total', 'Coverage')) 25 print("------------|------------|------------|------------") 26 27 categories = [ 'Line', 'Function', 'Branch']; 28 for category in categories: 29 hit = summary[category + "_hit"] 30 total = summary[category + "_total"] 31 coverage = 100.0 * hit / total 32 print ( row % ( category, hit, total, "%.1f" % coverage)) 33 34filter = sys.argv[1:] 35 36print("\nParsing HTML Coverage Report") 37 38tree = html.parse(coverage_html_path) 39files = tree.xpath("//td[@class='coverFile']") 40for file in files: 41 row = file.getparent() 42 children = row.getchildren() 43 path = children[0].text_content() 44 lineCov = children[3].text_content() 45 functionCov = children[5].text_content() 46 branchCov = children[7].text_content() 47 (lineHit, lineTotal) = [int(x) for x in lineCov.split("/")] 48 (functionHit, functionTotal) = [int(x) for x in functionCov.split("/")] 49 (branchHit, branchTotal) = [int(x) for x in branchCov.split("/")] 50 # print(path, lineHit, lineTotal, functionHit, functionTotal, branchHit, branchTotal) 51 52 # filter 53 if path in filter: 54 print("- Skipping " + path) 55 continue 56 57 print("- Adding " + path) 58 update_category('Line_hit', lineHit) 59 update_category('Line_total', lineTotal) 60 update_category('Function_hit', functionHit) 61 update_category('Function_total', functionTotal) 62 update_category('Branch_hit', branchHit) 63 update_category('Branch_total', branchTotal) 64 65print("") 66list_category_table() 67