<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 1 June 2018 at 02:15, Gedare Bloom <span dir="ltr"><<a href="mailto:gedare@rtems.org" target="_blank">gedare@rtems.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Thu, May 31, 2018 at 4:44 PM, Cillian O'Donnell<br>
<<a href="mailto:cpodonnell8@gmail.com">cpodonnell8@gmail.com</a>> wrote:<br>
> There is now a seperate bsp config for coverage, leon3-qemu-cov. That is<br>
> enough to trigger coverage now and --coverage could be reserved for picking<br>
> sets, probably renamed to --coverage-sets=... Or require sets to be chosen<br>
> --coverage-sets=all or specific sets --coverage-sets=score,sapi,<wbr>core<br>
><br>
</span>Yes, and it should work for more than 1 or 2.<br>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div>It can work for any number of sets. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
> On Thu, 31 May 2018, 21:29 Vijay Kumar Banerjee, <<a href="mailto:vijaykumar9597@gmail.com">vijaykumar9597@gmail.com</a>><br>
> wrote:<br>
>><br>
>> On 1 June 2018 at 01:57, Cillian O'Donnell <<a href="mailto:cpodonnell8@gmail.com">cpodonnell8@gmail.com</a>> wrote:<br>
>>><br>
>>> So is it checking whether it's --coverage or --coverage=set1,set2? Are<br>
>>> those the 2 possibilities your checking?<br>
>>><br>
>> Yes, right. :)<br>
>>><br>
>>> On Thu, 31 May 2018, 20:52 Vijay Kumar Banerjee,<br>
>>> <<a href="mailto:vijaykumar9597@gmail.com">vijaykumar9597@gmail.com</a>> wrote:<br>
>>>><br>
>>>> On 1 June 2018 at 01:19, Gedare Bloom <<a href="mailto:gedare@rtems.org">gedare@rtems.org</a>> wrote:<br>
>>>>><br>
>>>>> On Thu, May 31, 2018 at 3:47 PM, Vijay Kumar Banerjee<br>
>>>>> <<a href="mailto:vijaykumar9597@gmail.com">vijaykumar9597@gmail.com</a>> wrote:<br>
>>>>> > On 1 June 2018 at 01:07, Cillian O'Donnell <<a href="mailto:cpodonnell8@gmail.com">cpodonnell8@gmail.com</a>><br>
>>>>> > wrote:<br>
>>>>> >><br>
>>>>> >><br>
>>>>> >><br>
>>>>> >> On 31 May 2018 at 19:07, Vijay Kumar Banerjee<br>
>>>>> >> <<a href="mailto:vijaykumar9597@gmail.com">vijaykumar9597@gmail.com</a>><br>
>>>>> >> wrote:<br>
>>>>> >>><br>
>>>>> >>> Add support in tester to run covoar and generate an html report to<br>
>>>>> >>> display<br>
>>>>> >>> the summary of the coverage reports generated from covoar.<br>
>>>>> >>><br>
>>>>> >>> Co-authored-by : Cillian O'Donnell <<a href="mailto:cpodonnell8@gmail.com">cpodonnell8@gmail.com</a>><br>
>>>>> >>> ---<br>
>>>>> >>> tester/rt/coverage.py | 379<br>
>>>>> >>> ++++++++++++++++++++++++++<br>
>>>>> >>> tester/rt/test.py | 36 ++-<br>
>>>>> >>> tester/rtems/testing/bsps/<wbr>leon3-qemu-cov.ini | 3 +-<br>
>>>>> >>> tester/rtems/testing/coverage/<wbr>symbol-sets.ini | 36 +++<br>
>>>>> >>> tester/rtems/testing/qemu.cfg | 4 +-<br>
>>>>> >>> 5 files changed, 446 insertions(+), 12 deletions(-)<br>
>>>>> >>> create mode 100644 tester/rt/coverage.py<br>
>>>>> >>> create mode 100644 tester/rtems/testing/coverage/<wbr>symbol-sets.ini<br>
>>>>> >>><br>
>>>>> >>> diff --git a/tester/rt/coverage.py b/tester/rt/coverage.py<br>
>>>>> >>> new file mode 100644<br>
>>>>> >>> index 0000000..25fbb9d<br>
>>>>> >>> --- /dev/null<br>
>>>>> >>> +++ b/tester/rt/coverage.py<br>
>>>>> >>> @@ -0,0 +1,379 @@<br>
>>>>> >>> +#<br>
>>>>> >>> +# RTEMS Tools Project (<a href="http://www.rtems.org/" rel="noreferrer" target="_blank">http://www.rtems.org/</a>)<br>
>>>>> >>> +# Copyright 2014 Krzysztof Miesowicz<br>
>>>>> >>> (<a href="mailto:krzysztof.miesowicz@gmail.com">krzysztof.miesowicz@gmail.com</a><wbr>)<br>
>>>>> >>> +# All rights reserved.<br>
>>>>> >>> +#<br>
>>>>> >>> +# This file is part of the RTEMS Tools package in 'rtems-tools'.<br>
>>>>> >>> +#<br>
>>>>> >>> +# Redistribution and use in source and binary forms, with or<br>
>>>>> >>> without<br>
>>>>> >>> +# modification, are permitted provided that the following<br>
>>>>> >>> conditions are<br>
>>>>> >>> met:<br>
>>>>> >>> +#<br>
>>>>> >>> +# 1. Redistributions of source code must retain the above<br>
>>>>> >>> copyright<br>
>>>>> >>> notice,<br>
>>>>> >>> +# this list of conditions and the following disclaimer.<br>
>>>>> >>> +#<br>
>>>>> >>> +# 2. Redistributions in binary form must reproduce the above<br>
>>>>> >>> copyright<br>
>>>>> >>> notice,<br>
>>>>> >>> +# this list of conditions and the following disclaimer in the<br>
>>>>> >>> documentation<br>
>>>>> >>> +# and/or other materials provided with the distribution.<br>
>>>>> >>> +#<br>
>>>>> >>> +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND<br>
>>>>> >>> CONTRIBUTORS<br>
>>>>> >>> 'AS IS'<br>
>>>>> >>> +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT<br>
>>>>> >>> LIMITED TO,<br>
>>>>> >>> THE<br>
>>>>> >>> +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A<br>
>>>>> >>> PARTICULAR<br>
>>>>> >>> PURPOSE<br>
>>>>> >>> +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR<br>
>>>>> >>> CONTRIBUTORS<br>
>>>>> >>> BE<br>
>>>>> >>> +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,<br>
>>>>> >>> OR<br>
>>>>> >>> +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,<br>
>>>>> >>> PROCUREMENT OF<br>
>>>>> >>> +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR<br>
>>>>> >>> BUSINESS<br>
>>>>> >>> +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,<br>
>>>>> >>> WHETHER<br>
>>>>> >>> IN<br>
>>>>> >>> +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR<br>
>>>>> >>> OTHERWISE)<br>
>>>>> >>> +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF<br>
>>>>> >>> ADVISED OF<br>
>>>>> >>> THE<br>
>>>>> >>> +# POSSIBILITY OF SUCH DAMAGE.<br>
>>>>> >>> +#<br>
>>>>> >>> +<br>
>>>>> >>> +from rtemstoolkit import error<br>
>>>>> >>> +from rtemstoolkit import path<br>
>>>>> >>> +from rtemstoolkit import log<br>
>>>>> >>> +from rtemstoolkit import execute<br>
>>>>> >>> +from rtemstoolkit import macros<br>
>>>>> >>> +<br>
>>>>> >>> +from datetime import datetime<br>
>>>>> >>> +<br>
>>>>> >>> +from . import options<br>
>>>>> >>> +<br>
>>>>> >>> +import shutil<br>
>>>>> >>> +import os<br>
>>>>> >>> +<br>
>>>>> >>> +try:<br>
>>>>> >>> + import configparser<br>
>>>>> >>> +except:<br>
>>>>> >>> + import ConfigParser as configparser<br>
>>>>> >>> +<br>
>>>>> >>> +class summary:<br>
>>>>> >>> + def __init__(self, p_summary_dir):<br>
>>>>> >>> + self.summary_file_path = path.join(p_summary_dir,<br>
>>>>> >>> 'summary.txt')<br>
>>>>> >>> + self.index_file_path = path.join(p_summary_dir,<br>
>>>>> >>> 'index.html')<br>
>>>>> >>> + self.bytes_analyzed = 0<br>
>>>>> >>> + self.bytes_not_executed = 0<br>
>>>>> >>> + self.percentage_executed = 0.0<br>
>>>>> >>> + self.percentage_not_executed = 100.0<br>
>>>>> >>> + self.ranges_uncovered = 0<br>
>>>>> >>> + self.branches_uncovered = 0<br>
>>>>> >>> + self.branches_total = 0<br>
>>>>> >>> + self.branches_always_taken = 0<br>
>>>>> >>> + self.branches_never_taken = 0<br>
>>>>> >>> + self.percentage_branches_<wbr>covered = 0.0<br>
>>>>> >>> + self.is_failure = False<br>
>>>>> >>> +<br>
>>>>> >>> + def parse(self):<br>
>>>>> >>> + if(not path.exists(self.summary_file_<wbr>path)):<br>
>>>>> >>> + log.notice('summary file %s does not exist!' %<br>
>>>>> >>> (self.summary_file_path))<br>
>>>>> >>> + self.is_failure = True<br>
>>>>> >>> + return<br>
>>>>> >>> +<br>
>>>>> >>> + with open(self.summary_file_path,'<wbr>r') as summary_file:<br>
>>>>> >>> + self.bytes_analyzed =<br>
>>>>> >>> self._get_next_with_colon(<wbr>summary_file)<br>
>>>>> >>> + self.bytes_not_executed =<br>
>>>>> >>> self._get_next_with_colon(<wbr>summary_file)<br>
>>>>> >>> + self.percentage_executed =<br>
>>>>> >>> self._get_next_with_colon(<wbr>summary_file)<br>
>>>>> >>> + self.percentage_not_executed =<br>
>>>>> >>> self._get_next_with_colon(<wbr>summary_file)<br>
>>>>> >>> + self.ranges_uncovered =<br>
>>>>> >>> self._get_next_with_colon(<wbr>summary_file)<br>
>>>>> >>> + self.branches_total =<br>
>>>>> >>> self._get_next_with_colon(<wbr>summary_file)<br>
>>>>> >>> + self.branches_uncovered =<br>
>>>>> >>> self._get_next_with_colon(<wbr>summary_file)<br>
>>>>> >>> + self.branches_always_taken =<br>
>>>>> >>> self._get_next_without_colon(<wbr>summary_file)<br>
>>>>> >>> + self.branches_never_taken =<br>
>>>>> >>> self._get_next_without_colon(<wbr>summary_file)<br>
>>>>> >>> + if len(self.branches_uncovered) > 0 and<br>
>>>>> >>> len(self.branches_total)<br>
>>>>> >>> > 0:<br>
>>>>> >>> + self.percentage_branches_<wbr>covered = \<br>
>>>>> >>> + 1 - (float(self.branches_<wbr>uncovered) /<br>
>>>>> >>> float(self.branches_total))<br>
>>>>> >>> + else:<br>
>>>>> >>> + self.percentage_branches_<wbr>covered = 0.0<br>
>>>>> >>> + return<br>
>>>>> >>> +<br>
>>>>> >>> + def _get_next_with_colon(self, summary_file):<br>
>>>>> >>> + line = summary_file.readline()<br>
>>>>> >>> + if ':' in line:<br>
>>>>> >>> + return line.split(':')[1].strip()<br>
>>>>> >>> + else:<br>
>>>>> >>> + return ''<br>
>>>>> >>> +<br>
>>>>> >>> + def _get_next_without_colon(self, summary_file):<br>
>>>>> >>> + line = summary_file.readline()<br>
>>>>> >>> + return line.strip().split(' ')[0]<br>
>>>>> >>> +<br>
>>>>> >>> +class report_gen_html:<br>
>>>>> >>> + def __init__(self, p_symbol_sets_list, build_dir, rtdir):<br>
>>>>> >>> + self.symbol_sets_list = ['score']<br>
>>>>> >>> + self.build_dir = build_dir<br>
>>>>> >>> + self.partial_reports_files = list(["index.html",<br>
>>>>> >>> "summary.txt"])<br>
>>>>> >>> + self.number_of_columns = 1<br>
>>>>> >>> + self.covoar_src_path = path.join(rtdir, 'covoar')<br>
>>>>> >>> +<br>
>>>>> >>> + def _find_partial_reports(self):<br>
>>>>> >>> + partial_reports = {}<br>
>>>>> >>> + for symbol_set in self.symbol_sets_list:<br>
>>>>> >>> + set_summary = summary(path.join(self.build_<wbr>dir,<br>
>>>>> >>> "coverage",<br>
>>>>> >>> + symbol_set))<br>
>>>>> >>> + set_summary.parse()<br>
>>>>> >>> + partial_reports[symbol_set] = set_summary<br>
>>>>> >>> + return partial_reports<br>
>>>>> >>> +<br>
>>>>> >>> + def _prepare_head_section(self):<br>
>>>>> >>> + head_section = '''<br>
>>>>> >>> + <head><br>
>>>>> >>> + <title>RTEMS coverage report</title><br>
>>>>> >>> + <style type="text/css"><br>
>>>>> >>> + progress[value] {<br>
>>>>> >>> + -webkit-appearance: none;<br>
>>>>> >>> + appearance: none;<br>
>>>>> >>> +<br>
>>>>> >>> + width: 150px;<br>
>>>>> >>> + height: 15px;<br>
>>>>> >>> + }<br>
>>>>> >>> + </style><br>
>>>>> >>> + </head>'''<br>
>>>>> >>> + return head_section<br>
>>>>> >>> +<br>
>>>>> >>> + def _prepare_index_content(self, partial_reports):<br>
>>>>> >>> + header = "<h1> RTEMS coverage analysis report </h1>"<br>
>>>>> >>> + header += "<h3>Coverage reports by symbols sets:</h3>"<br>
>>>>> >>> + table = "<table>"<br>
>>>>> >>> + table += self._header_row()<br>
>>>>> >>> + for symbol_set in partial_reports:<br>
>>>>> >>> + table += self._row(symbol_set,<br>
>>>>> >>> partial_reports[symbol_set])<br>
>>>>> >>> + table += "</table> </br>"<br>
>>>>> >>> + timestamp = "Analysis performed on " +<br>
>>>>> >>> datetime.now().ctime()<br>
>>>>> >>> + return "<body>\n" + header + table + timestamp +<br>
>>>>> >>> "\n</body>"<br>
>>>>> >>> +<br>
>>>>> >>> + def _row(self, symbol_set, summary):<br>
>>>>> >>> + row = "<tr>"<br>
>>>>> >>> + row += "<td>" + symbol_set + "</td>"<br>
>>>>> >>> + if summary.is_failure:<br>
>>>>> >>> + row += ' <td colspan="' +<br>
>>>>> >>> str(self.number_of_columns-1) \<br>
>>>>> >>> + + '" style="background-color:red"><wbr>FAILURE</td>'<br>
>>>>> >>> + else:<br>
>>>>> >>> + row += " <td>" +<br>
>>>>> >>> self._link(summary.index_file_<wbr>path,"Index")<br>
>>>>> >>> \<br>
>>>>> >>> + + "</td>"<br>
>>>>> >>> + row += " <td>" +<br>
>>>>> >>> self._link(summary.summary_<wbr>file_path,"Summary") \<br>
>>>>> >>> + + "</td>"<br>
>>>>> >>> + row += " <td>" + summary.bytes_analyzed + "</td>"<br>
>>>>> >>> + row += " <td>" + summary.bytes_not_executed + "</td>"<br>
>>>>> >>> + row += " <td>" + summary.ranges_uncovered + "</td>"<br>
>>>>> >>> + row += " <td>" + summary.percentage_executed +<br>
>>>>> >>> "%</td>"<br>
>>>>> >>> + row += " <td>" + summary.percentage_not_<wbr>executed +<br>
>>>>> >>> "%</td>"<br>
>>>>> >>> + row += ' <td><progress value="' +<br>
>>>>> >>> summary.percentage_executed \<br>
>>>>> >>> + + '" max="100"></progress></td>'<br>
>>>>> >>> + row += " <td>" + summary.branches_uncovered + "</td>"<br>
>>>>> >>> + row += " <td>" + summary.branches_total + "</td>"<br>
>>>>> >>> + row += " <td> {:.3%}<br>
>>>>> >>> </td>".format(summary.<wbr>percentage_branches_covered)<br>
>>>>> >>> + row += ' <td><progress value="{:.3}"<br>
>>>>> >>><br>
>>>>> >>> max="100"></progress></td>'.<wbr>format(100*summary.percentage_<wbr>branches_covered)<br>
>>>>> >>> + row += "</tr>\n"<br>
>>>>> >>> + return row<br>
>>>>> >>> +<br>
>>>>> >>> + def _header_row(self):<br>
>>>>> >>> + row = "<tr>"<br>
>>>>> >>> + row += "<th> Symbols set name </th>"<br>
>>>>> >>> + row += "<th> Index file </th>"<br>
>>>>> >>> + row += "<th> Summary file </th>"<br>
>>>>> >>> + row += "<th> Bytes analyzed </th>"<br>
>>>>> >>> + row += "<th> Bytes not executed </th>"<br>
>>>>> >>> + row += "<th> Uncovered ranges </th>"<br>
>>>>> >>> + row += "<th> Percentage covered </th>"<br>
>>>>> >>> + row += "<th> Percentage uncovered </th>"<br>
>>>>> >>> + row += "<th> Instruction coverage </th>"<br>
>>>>> >>> + row += "<th> Branches uncovered </th>"<br>
>>>>> >>> + row += "<th> Branches total </th>"<br>
>>>>> >>> + row += "<th> Branches covered percentage </th>"<br>
>>>>> >>> + row += "<th> Branches coverage </th>"<br>
>>>>> >>> + row += "</tr>\n"<br>
>>>>> >>> + self.number_of_columns = row.count('<th>')<br>
>>>>> >>> + return row<br>
>>>>> >>> +<br>
>>>>> >>> + def _link(self, address, text):<br>
>>>>> >>> + return '<a href="' + address + '">' + text + '</a>'<br>
>>>>> >>> +<br>
>>>>> >>> + def _create_index_file(self, head_section, content):<br>
>>>>> >>> + with open(path.join(self.build_dir,<wbr>"report.html"),'w') as<br>
>>>>> >>> f:<br>
>>>>> >>> + f.write(head_section)<br>
>>>>> >>> + f.write(content)<br>
>>>>> >>> +<br>
>>>>> >>> + def generate(self):<br>
>>>>> >>> + partial_reports = self._find_partial_reports()<br>
>>>>> >>> + head_section = self._prepare_head_section()<br>
>>>>> >>> + index_content =<br>
>>>>> >>> self._prepare_index_content(<wbr>partial_reports)<br>
>>>>> >>> + self._create_index_file(head_<wbr>section,index_content)<br>
>>>>> >>> +<br>
>>>>> >>> + def add_covoar_src_path(self):<br>
>>>>> >>> + table_js_path = path.join(self.covoar_src_<wbr>path,<br>
>>>>> >>> 'table.js')<br>
>>>>> >>> + covoar_css_path = path.join(self.covoar_src_<wbr>path,<br>
>>>>> >>> 'covoar.css')<br>
>>>>> >>> + for symbol_set in self.symbol_sets_list:<br>
>>>>> >>> + symbol_set_dir = path.join(self.build_dir, "coverage",<br>
>>>>> >>> symbol_set)<br>
>>>>> >>> + html_files = os.listdir(symbol_set_dir)<br>
>>>>> >>> + for html_file in html_files:<br>
>>>>> >>> + html_file = path.join(symbol_set_dir, html_file)<br>
>>>>> >>> + if path.exists(html_file) and 'html' in html_file:<br>
>>>>> >>> + with open(html_file, 'r') as f:<br>
>>>>> >>> + file_data = f.read()<br>
>>>>> >>> + file_data = file_data.replace('table.js',<br>
>>>>> >>> table_js_path)<br>
>>>>> >>> + file_data = file_data.replace('covoar.css'<wbr>,<br>
>>>>> >>> + covoar_css_path)<br>
>>>>> >>> + with open(html_file, 'w') as f:<br>
>>>>> >>> + f.write(file_data)<br>
>>>>> >>> +<br>
>>>>> >>> +class build_path_generator(object):<br>
>>>>> >>> + '''<br>
>>>>> >>> + Generates the build path from the path to executables<br>
>>>>> >>> + '''<br>
>>>>> >>> + def __init__(self, executables, target):<br>
>>>>> >>> + self.executables = executables<br>
>>>>> >>> + self.target = target<br>
>>>>> >>> + def run(self):<br>
>>>>> >>> + build_path = '/'<br>
>>>>> >>> + Path = self.executables[0].split('/')<br>
>>>>> >>> + for P in Path:<br>
>>>>> >>> + if P == self.target:<br>
>>>>> >>> + break;<br>
>>>>> >>> + else:<br>
>>>>> >>> + build_path = path.join(build_path, P)<br>
>>>>> >>> + return build_path<br>
>>>>> >>> +<br>
>>>>> >>> +class symbol_parser(object):<br>
>>>>> >>> + '''<br>
>>>>> >>> + Parse the symbol sets ini and create custom ini file for<br>
>>>>> >>> covoar<br>
>>>>> >>> + '''<br>
>>>>> >>> + def __init__(self, symbol_config_path,<br>
>>>>> >>> + symbol_select_path, coverage_arg, build_dir):<br>
>>>>> >>> + self.symbol_select_file = symbol_select_path<br>
>>>>> >>> + self.symbol_file = symbol_config_path<br>
>>>>> >>> + self.build_dir = build_dir<br>
>>>>> >>> + self.symbol_sets = {}<br>
>>>>> >>> + self.cov_arg = coverage_arg<br>
>>>>> >>> + self.ssets = []<br>
>>>>> >>> +<br>
>>>>> >>> + def parse(self):<br>
>>>>> >>> + config = configparser.ConfigParser()<br>
>>>>> >>> + try:<br>
>>>>> >>> + config.read(self.symbol_file)<br>
>>>>> >>> + if self.cov_arg:<br>
>>>>> >>> + self.ssets = self.cov_arg.split(',')<br>
>>>>> >>> + else:<br>
>>>>> >>> + self.ssets = config.get('symbol-sets',<br>
>>>>> >>> 'sets').split(',')<br>
>>>>> >>> + self.ssets = [ sset.encode('utf-8') for sset in<br>
>>>>> >>> self.ssets]<br>
>>>>> >>> + for sset in self.ssets:<br>
>>>>> >>> + lib = path.join(self.build_dir,<br>
>>>>> >>> + config.get('libraries', sset))<br>
>>>>> >>> + self.symbol_sets[sset] = lib.encode('utf-8')<br>
>>>>> >>> + except:<br>
>>>>> >>> + raise error.general('Symbol set parsing failed')<br>
>>>>> >>> +<br>
>>>>> >>> + def _write_ini(self):<br>
>>>>> >>> + config = configparser.ConfigParser()<br>
>>>>> >>> + try:<br>
>>>>> >>> + sets = ', '.join(self.symbol_sets.keys()<wbr>)<br>
>>>>> >>> + config.add_section('symbol-<wbr>sets')<br>
>>>>> >>> + config.set('symbol-sets', 'sets', sets)<br>
>>>>> >>> + for key in self.symbol_sets.keys():<br>
>>>>> >>> + config.add_section(key)<br>
>>>>> >>> + config.set(key, 'libraries',<br>
>>>>> >>> self.symbol_sets[key])<br>
>>>>> >>> + with open(self.symbol_select_file, 'w') as conf:<br>
>>>>> >>> + config.write(conf)<br>
>>>>> >>> + except:<br>
>>>>> >>> + raise error.general('write failed')<br>
>>>>> >>> +<br>
>>>>> >>> + def run(self):<br>
>>>>> >>> + self.parse()<br>
>>>>> >>> + self._write_ini()<br>
>>>>> >>> +<br>
>>>>> >>> +class covoar(object):<br>
>>>>> >>> + '''<br>
>>>>> >>> + Covoar runner<br>
>>>>> >>> + '''<br>
>>>>> >>> + def __init__(self, base_result_dir, config_dir, executables,<br>
>>>>> >>> explanations_txt):<br>
>>>>> >>> + self.base_result_dir = base_result_dir<br>
>>>>> >>> + self.config_dir = config_dir<br>
>>>>> >>> + self.executables = ' '.join(executables)<br>
>>>>> >>> + self.explanations_txt = explanations_txt<br>
>>>>> >>> + self.project_name = 'RTEMS-5'<br>
>>>>> >>> +<br>
>>>>> >>> + def run(self, set_name, symbol_file):<br>
>>>>> >>> + covoar_result_dir = path.join(self.base_result_<wbr>dir,<br>
>>>>> >>> set_name)<br>
>>>>> >>> + if (not path.exists(covoar_result_dir)<wbr>):<br>
>>>>> >>> + path.mkdir(covoar_result_dir)<br>
>>>>> >>> + if (not path.exists(symbol_file)):<br>
>>>>> >>> + raise error.general('symbol set file: coverage %s was<br>
>>>>> >>> not<br>
>>>>> >>> created for covoar, skipping %s'% (symbol_file, set_name))<br>
>>>>> >>> + command = ('covoar -S ' + symbol_file<br>
>>>>> >>> + + ' -O ' + covoar_result_dir<br>
>>>>> >>> + + ' -E ' + self.explanations_txt<br>
>>>>> >>> + + ' -p ' + self.project_name + ' ' +<br>
>>>>> >>> self.executables)<br>
>>>>> >>> + log.notice('Running covoar for %s' % (set_name))<br>
>>>>> >>> + print( 'covoar results directory:\n' + covoar_result_dir )<br>
>>>>> >>> + executor = execute.execute(verbose = True, output =<br>
>>>>> >>> self.output_handler)<br>
>>>>> >>> + exit_code = executor.shell(command, cwd=os.getcwd())<br>
>>>>> >>> + if (exit_code[0] != 0):<br>
>>>>> >>> + raise error.general('covoar failure exit code: %d' %<br>
>>>>> >>> (exit_code[0]))<br>
>>>>> >>> + log.notice('Coverage run for %s finished successfully.' %<br>
>>>>> >>> (set_name))<br>
>>>>> >>> +<br>
>>>>> >>> log.notice('------------------<wbr>-----------------------------'<wbr>)<br>
>>>>> >>> +<br>
>>>>> >>> + def output_handler(self, text):<br>
>>>>> >>> + log.notice('%s' % (text))<br>
>>>>> >>> +<br>
>>>>> >>> +class coverage_run(object):<br>
>>>>> >>> + '''<br>
>>>>> >>> + Coverage analysis support for rtems-test<br>
>>>>> >>> + '''<br>
>>>>> >>> + def __init__(self, p_macros, coverage_arg, target):<br>
>>>>> >>> + '''<br>
>>>>> >>> + Constructor<br>
>>>>> >>> + '''<br>
>>>>> >>> + self.macros = p_macros<br>
>>>>> >>> + self.build_dir = self.macros['_cwd']<br>
>>>>> >>> + self.explanations_txt =<br>
>>>>> >>> self.macros.expand(self.<wbr>macros['cov_explanations'])<br>
>>>>> >>> + self.test_dir = path.join(self.build_dir, 'coverage')<br>
>>>>> >>> + if (not path.exists(self.test_dir)):<br>
>>>>> >>> + path.mkdir(self.test_dir)<br>
>>>>> >>> + self.rtdir = path.abspath(self.macros['_<wbr>rtdir'])<br>
>>>>> >>> + self.rtscripts =<br>
>>>>> >>> self.macros.expand(self.<wbr>macros['_rtscripts'])<br>
>>>>> >>> + self.coverage_config_path = path.join(self.rtscripts,<br>
>>>>> >>> 'coverage')<br>
>>>>> >>> + self.symbol_config_path =<br>
>>>>> >>> path.join(self.coverage_<wbr>config_path,<br>
>>>>> >>> + 'symbol-sets.ini')<br>
>>>>> >>> + self.symbol_select_path =<br>
>>>>> >>> path.join(self.coverage_<wbr>config_path,<br>
>>>>> >>> + 'symbol-select.ini')<br>
>>>>> >>> + self.executables = None<br>
>>>>> >>> + self.symbol_sets = []<br>
>>>>> >>> + self.no_clean = int(self.macros['_no_clean'])<br>
>>>>> >>> + self.report_format = self.macros['cov_report_<wbr>format']<br>
>>>>> >>> + self.coverage_arg = coverage_arg<br>
>>>>> >>> + self.target = target<br>
>>>>> >>> +<br>
>>>>> >>> + def run(self):<br>
>>>>> >>> + try:<br>
>>>>> >>> + if self.executables is None:<br>
>>>>> >>> + raise error.general('no test executables<br>
>>>>> >>> provided.')<br>
>>>>> >>> + build_dir = build_path_generator(self.<wbr>executables,<br>
>>>>> >>> self.target).run()<br>
>>>>> >>> + parser = symbol_parser(self.symbol_<wbr>config_path,<br>
>>>>> >>> + self.symbol_select_path,<br>
>>>>> >>> + self.coverage_arg,<br>
>>>>> >>> + build_dir)<br>
>>>>> >>> + parser.run()<br>
>>>>> >>> + covoar_runner = covoar(self.test_dir,<br>
>>>>> >>> self.symbol_select_path,<br>
>>>>> >>> + self.executables,<br>
>>>>> >>> self.explanations_txt)<br>
>>>>> >>> + covoar_runner.run('score', self.symbol_select_path)<br>
>>>>> >>> + self._generate_reports();<br>
>>>>> >>> + self._summarize();<br>
>>>>> >>> + finally:<br>
>>>>> >>> + self._cleanup();<br>
>>>>> >>> +<br>
>>>>> >>> + def _generate_reports(self):<br>
>>>>> >>> + log.notice('Generating reports')<br>
>>>>> >>> + if self.report_format == 'html':<br>
>>>>> >>> + report = report_gen_html(self.symbol_<wbr>sets,<br>
>>>>> >>> + self.build_dir,<br>
>>>>> >>> + self.rtdir)<br>
>>>>> >>> + report.generate()<br>
>>>>> >>> + report.add_covoar_src_path()<br>
>>>>> >>> +<br>
>>>>> >>> + def _cleanup(self):<br>
>>>>> >>> + if not self.no_clean:<br>
>>>>> >>> + log.notice('***Cleaning tempfiles***')<br>
>>>>> >>> + for exe in self.executables:<br>
>>>>> >>> + trace_file = exe + '.cov'<br>
>>>>> >>> + if path.exists(trace_file):<br>
>>>>> >>> + os.remove(trace_file)<br>
>>>>> >>> +<br>
>>>>> >>> + def _summarize(self):<br>
>>>>> >>> + log.notice('Coverage analysis finished. You can find<br>
>>>>> >>> results in<br>
>>>>> >>> %s' % (self.build_dir))<br>
>>>>> >>> diff --git a/tester/rt/test.py b/tester/rt/test.py<br>
>>>>> >>> index f4d9b5c..84dff01 100644<br>
>>>>> >>> --- a/tester/rt/test.py<br>
>>>>> >>> +++ b/tester/rt/test.py<br>
>>>>> >>> @@ -48,12 +48,14 @@ from rtemstoolkit import mailer<br>
>>>>> >>> from rtemstoolkit import reraise<br>
>>>>> >>> from rtemstoolkit import stacktraces<br>
>>>>> >>> from rtemstoolkit import version<br>
>>>>> >>> +from rtemstoolkit import check<br>
>>>>> >>><br>
>>>>> >>> from . import bsps<br>
>>>>> >>> from . import config<br>
>>>>> >>> from . import console<br>
>>>>> >>> from . import options<br>
>>>>> >>> from . import report<br>
>>>>> >>> +from . import coverage<br>
>>>>> >>><br>
>>>>> >>> class log_capture(object):<br>
>>>>> >>> def __init__(self):<br>
>>>>> >>> @@ -147,7 +149,7 @@ class test_run(object):<br>
>>>>> >>><br>
>>>>> >>> def run(self):<br>
>>>>> >>> self.thread = threading.Thread(target = self.runner,<br>
>>>>> >>> - name = 'test[%s]' %<br>
>>>>> >>> path.basename(self.executable)<wbr>)<br>
>>>>> >>> + name = 'test[%s]' %<br>
>>>>> >>> path.basename(self.executable)<wbr>)<br>
>>>>> >>> self.thread.start()<br>
>>>>> >>><br>
>>>>> >>> def is_alive(self):<br>
>>>>> >>> @@ -214,6 +216,10 @@ def killall(tests):<br>
>>>>> >>> for test in tests:<br>
>>>>> >>> test.kill()<br>
>>>>> >>><br>
>>>>> >>> +def coverage_run(opts, coverage, executables):<br>
>>>>> >>> + coverage.executables = executables<br>
>>>>> >>> + coverage.run()<br>
>>>>> >>> +<br>
>>>>> >>> def run(command_path = None):<br>
>>>>> >>> import sys<br>
>>>>> >>> tests = []<br>
>>>>> >>> @@ -221,15 +227,16 @@ def run(command_path = None):<br>
>>>>> >>> opts = None<br>
>>>>> >>> default_exefilter = '*.exe'<br>
>>>>> >>> try:<br>
>>>>> >>> - optargs = { '--rtems-tools': 'The path to the RTEMS<br>
>>>>> >>> tools',<br>
>>>>> >>> - '--rtems-bsp': 'The RTEMS BSP to run the<br>
>>>>> >>> test on',<br>
>>>>> >>> - '--user-config': 'Path to your local user<br>
>>>>> >>> configuration INI file',<br>
>>>>> >>> - '--report-mode': 'Reporting modes, failures<br>
>>>>> >>> (default),all,none',<br>
>>>>> >>> - '--list-bsps': 'List the supported BSPs',<br>
>>>>> >>> - '--debug-trace': 'Debug trace based on<br>
>>>>> >>> specific<br>
>>>>> >>> flags',<br>
>>>>> >>> - '--filter': 'Glob that executables must<br>
>>>>> >>> match<br>
>>>>> >>> to run (default: ' +<br>
>>>>> >>> + optargs = { '--rtems-tools': 'The path to the RTEMS<br>
>>>>> >>> tools',<br>
>>>>> >>> + '--rtems-bsp': 'The RTEMS BSP to run the<br>
>>>>> >>> test<br>
>>>>> >>> on',<br>
>>>>> >>> + '--user-config': 'Path to your local user<br>
>>>>> >>> configuration INI file',<br>
>>>>> >>> + '--report-mode': 'Reporting modes, failures<br>
>>>>> >>> (default),all,none',<br>
>>>>> >>> + '--list-bsps': 'List the supported BSPs',<br>
>>>>> >>> + '--debug-trace': 'Debug trace based on<br>
>>>>> >>> specific<br>
>>>>> >>> flags',<br>
>>>>> >>> + '--filter': 'Glob that executables<br>
>>>>> >>> must<br>
>>>>> >>> match to run (default: ' +<br>
>>>>> >>> default_exefilter + ')',<br>
>>>>> >>> - '--stacktrace': 'Dump a stack trace on a user<br>
>>>>> >>> termination (^C)' }<br>
>>>>> >>> + '--stacktrace': 'Dump a stack trace on a<br>
>>>>> >>> user<br>
>>>>> >>> termination (^C)',<br>
>>>>> >>> + '--coverage': 'Perform coverage analysis<br>
>>>>> >>> of<br>
>>>>> >>> test executables.'}<br>
>>>>> >>> mailer.append_options(optargs)<br>
>>>>> >>> opts = options.load(sys.argv,<br>
>>>>> >>> optargs = optargs,<br>
>>>>> >>> @@ -279,6 +286,15 @@ def run(command_path = None):<br>
>>>>> >>> raise error.general('RTEMS BSP not provided or an<br>
>>>>> >>> invalid<br>
>>>>> >>> option')<br>
>>>>> >>> bsp = config.load(bsp[1], opts)<br>
>>>>> >>> bsp_config = opts.defaults.expand(opts.<wbr>defaults['tester'])<br>
>>>>> >>> + coverage_enabled = opts.find_arg('--coverage')<br>
>>>>> >>> + if coverage_enabled:<br>
>>>>> >>> + if len(coverage_enabled) == 2:<br>
>>>>> >><br>
>>>>> >><br>
>>>>> >> Is this to check if sets have been provided to<br>
>>>>> >> --coverage=score,sapi, that<br>
>>>>> >> kind of thing? If so the variable name coverage_enabled doesn't make<br>
>>>>> >> sense<br>
>>>>> >> any more. Probably if symbol_sets and if len(symbol_sets) will make<br>
>>>>> >> more<br>
>>>>> >> sense for both cases.<br>
>>>>> ><br>
>>>>> > That's a good point.<br>
>>>>> > How about changing it to just 'coverage' instead ?<br>
>>>>> > Because it's still checking whether the option is given or<br>
>>>>> > not. symbol_sets might create confusion.<br>
>>>>> > Will that be OK ?<br>
>>>>><br>
>>>>> That name might collide with your class object (coverage)?<br>
>>>><br>
>>>> That's actually why I kept it as coverage_enabled.<br>
>>>> I think we can go for coverage_option (?)<br>
>>>>><br>
>>>>><br>
>>>>> >><br>
>>>>> >><br>
>>>>> >>> + coverage_runner =<br>
>>>>> >>> coverage.coverage_run(opts.<wbr>defaults,<br>
>>>>> >>> +<br>
>>>>> >>> coverage_enabled[1],<br>
>>>>> >>> +<br>
>>>>> >>> opts.defaults['target'])<br>
>>>>> >>> + else:<br>
>>>>> >>> + coverage_runner =<br>
>>>>> >>> coverage.coverage_run(opts.<wbr>defaults,<br>
>>>>> >>> 0,<br>
>>>>> >>> +<br>
>>>>> >>> opts.defaults['target'])<br>
>>>>> >>> report_mode = opts.find_arg('--report-mode')<br>
>>>>> >>> if report_mode:<br>
>>>>> >>> if report_mode[1] != 'failures' and \<br>
>>>>> >>> @@ -365,6 +381,8 @@ def run(command_path = None):<br>
>>>>> >>> reports.failures(),<br>
>>>>> >>> 'Log', '===', ''] + output.get()<br>
>>>>> >>> mail.send(to_addr, subject, os.linesep.join(body))<br>
>>>>> >>> + if coverage_enabled:<br>
>>>>> >>> + coverage_run(opts, coverage_runner, executables)<br>
>>>>> >>><br>
>>>>> >>> except error.general as gerr:<br>
>>>>> >>> print(gerr)<br>
>>>>> >>> diff --git a/tester/rtems/testing/bsps/<wbr>leon3-qemu-cov.ini<br>
>>>>> >>> b/tester/rtems/testing/bsps/<wbr>leon3-qemu-cov.ini<br>
>>>>> >>> index 6b5e7e6..2f89117 100644<br>
>>>>> >>> --- a/tester/rtems/testing/bsps/<wbr>leon3-qemu-cov.ini<br>
>>>>> >>> +++ b/tester/rtems/testing/bsps/<wbr>leon3-qemu-cov.ini<br>
>>>>> >>> @@ -31,9 +31,10 @@<br>
>>>>> >>> #<br>
>>>>> >>> # The Leon 3 QEMU BSP<br>
>>>>> >>> #<br>
>>>>> >>> -[leon3-qemu]<br>
>>>>> >>> +[leon3-qemu-cov]<br>
>>>>> >>> bsp = leon3-qemu<br>
>>>>> >>> arch = sparc<br>
>>>>> >>> +target = sparc-rtems5<br>
>>>>> >>> tester = %{_rtscripts}/qemu.cfg<br>
>>>>> >>> bsp_qemu_opts = %{qemu_opts_base} -M leon3_generic<br>
>>>>> >>> bsp_qemu_cov_opts = -exec-trace %{test_executable}.cov<br>
>>>>> >>> diff --git a/tester/rtems/testing/<wbr>coverage/symbol-sets.ini<br>
>>>>> >>> b/tester/rtems/testing/<wbr>coverage/symbol-sets.ini<br>
>>>>> >>> new file mode 100644<br>
>>>>> >>> index 0000000..a2ec7bc<br>
>>>>> >>> --- /dev/null<br>
>>>>> >>> +++ b/tester/rtems/testing/<wbr>coverage/symbol-sets.ini<br>
>>>>> >>> @@ -0,0 +1,36 @@<br>
>>>>> >>> +#<br>
>>>>> >>> +# RTEMS Tools Project (<a href="http://www.rtems.org/" rel="noreferrer" target="_blank">http://www.rtems.org/</a>)<br>
>>>>> >>> +# Copyright 2018 Chris Johns (<a href="mailto:chrisj@rtems.org">chrisj@rtems.org</a>)<br>
>>>>> >>> +# All rights reserved.<br>
>>>>> >>> +#<br>
>>>>> >>> +# This file is part of the RTEMS Tools package in 'rtems-tools'.<br>
>>>>> >>> +#<br>
>>>>> >>> +# Redistribution and use in source and binary forms, with or<br>
>>>>> >>> without<br>
>>>>> >>> +# modification, are permitted provided that the following<br>
>>>>> >>> conditions are<br>
>>>>> >>> met:<br>
>>>>> >>> +#<br>
>>>>> >>> +# 1. Redistributions of source code must retain the above<br>
>>>>> >>> copyright<br>
>>>>> >>> notice,<br>
>>>>> >>> +# this list of conditions and the following disclaimer.<br>
>>>>> >>> +#<br>
>>>>> >>> +# 2. Redistributions in binary form must reproduce the above<br>
>>>>> >>> copyright<br>
>>>>> >>> notice,<br>
>>>>> >>> +# this list of conditions and the following disclaimer in the<br>
>>>>> >>> documentation<br>
>>>>> >>> +# and/or other materials provided with the distribution.<br>
>>>>> >>> +#<br>
>>>>> >>> +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND<br>
>>>>> >>> CONTRIBUTORS<br>
>>>>> >>> "AS IS"<br>
>>>>> >>> +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT<br>
>>>>> >>> LIMITED TO,<br>
>>>>> >>> THE<br>
>>>>> >>> +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A<br>
>>>>> >>> PARTICULAR<br>
>>>>> >>> PURPOSE<br>
>>>>> >>> +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR<br>
>>>>> >>> CONTRIBUTORS<br>
>>>>> >>> BE<br>
>>>>> >>> +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,<br>
>>>>> >>> OR<br>
>>>>> >>> +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,<br>
>>>>> >>> PROCUREMENT OF<br>
>>>>> >>> +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR<br>
>>>>> >>> BUSINESS<br>
>>>>> >>> +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,<br>
>>>>> >>> WHETHER<br>
>>>>> >>> IN<br>
>>>>> >>> +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR<br>
>>>>> >>> OTHERWISE)<br>
>>>>> >>> +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF<br>
>>>>> >>> ADVISED OF<br>
>>>>> >>> THE<br>
>>>>> >>> +# POSSIBILITY OF SUCH DAMAGE.<br>
>>>>> >>> +#<br>
>>>>> >>> +<br>
>>>>> >>> +[symbol-sets]<br>
>>>>> >>> +sets = score,rtems<br>
>>>>> >>> +<br>
>>>>> >>> +[libraries]<br>
>>>>> >>> +score = @BUILD-TARGET@/c/@BSP@/cpukit/<wbr>score/libscore.a<br>
>>>>> >>> +rtems = @BUILD-TARGET@/c/@BSP@/cpukit/<wbr>rtems/librtems.a<br>
>>>>> >>> diff --git a/tester/rtems/testing/qemu.<wbr>cfg<br>
>>>>> >>> b/tester/rtems/testing/qemu.<wbr>cfg<br>
>>>>> >>> index bfcd2f5..52a3752 100644<br>
>>>>> >>> --- a/tester/rtems/testing/qemu.<wbr>cfg<br>
>>>>> >>> +++ b/tester/rtems/testing/qemu.<wbr>cfg<br>
>>>>> >>> @@ -51,8 +51,8 @@<br>
>>>>> >>> #<br>
>>>>> >>> # Qemu common option patterns.<br>
>>>>> >>> #<br>
>>>>> >>> -#%define qemu_opts_base -no-reboot -monitor none -serial stdio<br>
>>>>> >>> -nographic<br>
>>>>> >>> -%define qemu_opts_base -no-reboot -serial null -serial mon:stdio<br>
>>>>> >>> -nographic<br>
>>>>> >>> +%define qemu_opts_base -no-reboot -monitor none -serial stdio<br>
>>>>> >>> -nographic<br>
>>>>> >>> +#%define qemu_opts_base -no-reboot -serial null -serial<br>
>>>>> >>> mon:stdio<br>
>>>>> >>> -nographic<br>
>>>>> >>> %define qemu_opts_no_net -net none<br>
>>>>> >>><br>
>>>>> >>> #<br>
>>>>> >>> --<br>
>>>>> >>> 2.14.3<br>
>>>>> >>><br>
>>>>> >>> ______________________________<wbr>_________________<br>
>>>>> >>> devel mailing list<br>
>>>>> >>> <a href="mailto:devel@rtems.org">devel@rtems.org</a><br>
>>>>> >>> <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/<wbr>mailman/listinfo/devel</a><br>
>>>>> >><br>
>>>>> >><br>
>>>>> ><br>
>>>>> ><br>
>>>>> > ______________________________<wbr>_________________<br>
>>>>> > devel mailing list<br>
>>>>> > <a href="mailto:devel@rtems.org">devel@rtems.org</a><br>
>>>>> > <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/<wbr>mailman/listinfo/devel</a><br>
>>>><br>
>>>><br>
>><br>
><br>
</div></div></blockquote></div><br></div></div>