# # RTEMS Tools Project (http://www.rtems.org/) # Copyright 2014 Krzysztof Miesowicz (krzysztof.miesowicz@gmail.com) # All rights reserved. # # This file is part of the RTEMS Tools package in 'rtems-tools'. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # from __future__ import print_function import datetime import shutil import os import sys try: import configparser except: import ConfigParser as configparser from rtemstoolkit import error from rtemstoolkit import path from rtemstoolkit import log from rtemstoolkit import execute from rtemstoolkit import macros from rtemstoolkit import version import options class summary: def __init__(self, p_summary_dir): self.summary_file_path = path.join(p_summary_dir, 'summary.txt') self.index_file_path = path.join(p_summary_dir, 'index.html') self.bytes_analyzed = 0 self.bytes_not_executed = 0 self.percentage_executed = 0.0 self.percentage_not_executed = 100.0 self.ranges_uncovered = 0 self.branches_uncovered = 0 self.branches_total = 0 self.branches_always_taken = 0 self.branches_never_taken = 0 self.percentage_branches_covered = 0.0 self.is_failure = False def parse(self): if not path.exists(self.summary_file_path): log.output('coverage: summary file %s does not exist!' % (self.summary_file_path)) self.is_failure = True with open(self.summary_file_path, 'r') as summary_file: self.bytes_analyzed = self._get_next_with_colon(summary_file) self.bytes_not_executed = self._get_next_with_colon(summary_file) self.percentage_executed = self._get_next_with_colon(summary_file) self.percentage_not_executed = self._get_next_with_colon(summary_file) self.ranges_uncovered = self._get_next_with_colon(summary_file) self.branches_total = self._get_next_with_colon(summary_file) self.branches_uncovered = self._get_next_with_colon(summary_file) self.branches_always_taken = self._get_next_without_colon(summary_file) self.branches_never_taken = self._get_next_without_colon(summary_file) if len(self.branches_uncovered) > 0 and len(self.branches_total) > 0: self.percentage_branches_covered = \ 1.0 - (float(self.branches_uncovered) / float(self.branches_total)) else: self.percentage_branches_covered = 0.0 return def _get_next_with_colon(self, summary_file): line = summary_file.readline() if ':' in line: return line.split(':')[1].strip() else: return '' def _get_next_without_colon(self, summary_file): line = summary_file.readline() return line.strip().split(' ')[0] class report_gen_html: def __init__(self, symbol_sets, build_dir, rtdir, bsp): self.symbol_sets = symbol_sets self.build_dir = build_dir self.partial_reports_files = list(['index.html', 'summary.txt']) self.number_of_columns = 1 self.covoar_src_path = path.join(rtdir, 'covoar') self.bsp = bsp def _find_partial_reports(self): partial_reports = {} for symbol_set in self.symbol_sets: set_summary = summary(path.join(self.bsp + "-coverage", symbol_set)) set_summary.parse() partial_reports[symbol_set] = set_summary return partial_reports def _prepare_head_section(self): head_section = '
' + os.linesep head_section += '