Changeset 5195eb7 in rtems-tools


Ignore:
Timestamp:
Jun 17, 2018, 11:36:38 PM (11 months ago)
Author:
Chris Johns <chrisj@…>
Branches:
master
Children:
e341a65
Parents:
8009d08
git-author:
Chris Johns <chrisj@…> (06/17/18 23:36:38)
git-committer:
Chris Johns <chrisj@…> (06/18/18 02:26:16)
Message:

tester: Clean up the coverage python code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tester/rt/coverage.py

    r8009d08 r5195eb7  
    2929#
    3030
     31from __future__ import print_function
     32
     33import datetime
     34import shutil
     35import os
     36
     37try:
     38    import configparser
     39except:
     40    import ConfigParser as configparser
     41
    3142from rtemstoolkit import error
    3243from rtemstoolkit import path
     
    3546from rtemstoolkit import macros
    3647
    37 from datetime import datetime
    3848
    3949from . import options
    40 
    41 import shutil
    42 import os
    43 
    44 try:
    45     import configparser
    46 except:
    47     import ConfigParser as configparser
    4850
    4951class summary:
     
    6466
    6567    def parse(self):
    66         if(not path.exists(self.summary_file_path)):
    67             log.notice('summary file %s does not exist!' % (self.summary_file_path))
     68        if not path.exists(self.summary_file_path):
     69            log.output('coverage: summary file %s does not exist!' % (self.summary_file_path))
    6870            self.is_failure = True
    69             return
    70 
    71         with open(self.summary_file_path,'r') as summary_file:
     71
     72        with open(self.summary_file_path, 'r') as summary_file:
    7273           self.bytes_analyzed = self._get_next_with_colon(summary_file)
    7374           self.bytes_not_executed = self._get_next_with_colon(summary_file)
     
    8182        if len(self.branches_uncovered) > 0 and len(self.branches_total) > 0:
    8283            self.percentage_branches_covered = \
    83             1 - (float(self.branches_uncovered) / float(self.branches_total))
     84                1.0 - (float(self.branches_uncovered) / float(self.branches_total))
    8485        else:
    8586            self.percentage_branches_covered = 0.0
     
    140141            table += self._row(symbol_set, partial_reports[symbol_set])
    141142        table += "</table> </br>"
    142         timestamp = "Analysis performed on " + datetime.now().ctime()
     143        timestamp = "Analysis performed on " + datetime.datetime.now().ctime()
    143144        return "<body>\n" + header + table + timestamp + "\n</body>"
    144145
     
    164165            row += " <td>" + summary.branches_total + "</td>"
    165166            row += " <td> {:.3%} </td>".format(summary.percentage_branches_covered)
    166             row += ' <td><progress value="{:.3}" max="100"></progress></td>'.format(100*summary.percentage_branches_covered)
     167            spbc = 100 * summary.percentage_branches_covered
     168            row += ' <td><progress value="{:.3}" max="100"></progress></td>'.format(spbc)
    167169            row += "</tr>\n"
    168170        return row
     
    191193
    192194    def _create_index_file(self, head_section, content):
    193         with open(path.join(self.build_dir,
    194                             self.bsp + "-report.html"),'w') as f:
     195        name = path.join(self.build_dir, self.bsp + "-report.html")
     196        with open(name, 'w') as f:
    195197            f.write(head_section)
    196198            f.write(content)
     
    229231    def run(self):
    230232        build_path = '/'
    231         Path = self.executables[0].split('/')
    232         for P in Path:
    233             if P == self.target:
    234                 break;
     233        path_ = self.executables[0].split('/')
     234        for p in path_:
     235            if p == self.target:
     236                break
    235237            else:
    236                 build_path = path.join(build_path, P)
     238                build_path = path.join(build_path, p)
    237239        return build_path
    238240
     
    241243    Parse the symbol sets ini and create custom ini file for covoar
    242244    '''
    243     def __init__(self, symbol_config_path,
    244                  symbol_select_path, coverage_arg, build_dir):
     245    def __init__(self,
     246                 symbol_config_path,
     247                 symbol_select_path,
     248                 coverage_arg,
     249                 build_dir):
    245250        self.symbol_select_file = symbol_select_path
    246251        self.symbol_file = symbol_config_path
     
    258263            else:
    259264                self.ssets = config.get('symbol-sets', 'sets').split(',')
    260                 self.ssets = [ sset.encode('utf-8') for sset in self.ssets]
     265                self.ssets = [sset.encode('utf-8') for sset in self.ssets]
    261266            for sset in self.ssets:
    262                 lib = path.join(self.build_dir,
    263                                 config.get('libraries', sset))
     267                lib = path.join(self.build_dir, config.get('libraries', sset))
    264268                self.symbol_sets[sset] = lib.encode('utf-8')
    265269        except:
     
    278282                config.write(conf)
    279283        except:
    280             raise error.general('write failed')
     284            raise error.general('symbol parser write failed')
    281285
    282286    def run(self):
     
    300304            path.mkdir(covoar_result_dir)
    301305        if (not path.exists(symbol_file)):
    302             raise error.general('symbol set file: coverage %s was not created for covoar, skipping %s'% (symbol_file, set_name))
    303         command = ('covoar -S ' + symbol_file
    304                   + ' -O ' + covoar_result_dir
    305                   + ' -E ' + self.explanations_txt
    306                   + ' -p ' + self.project_name + ' ' + self.executables)
    307         log.notice('Running covoar for %s' % (set_name))
    308         print( 'covoar results directory:\n' + covoar_result_dir )
     306            raise error.general('symbol set file: coverage %s not created, skipping %s'% (symbol_file, set_name))
     307        command = 'covoar -S ' + symbol_file + \
     308                  ' -O ' + covoar_result_dir + \
     309                  ' -E ' + self.explanations_txt + \
     310                  ' -p ' + self.project_name + ' ' + self.executables
     311        log.notice()
     312        log.notice('Running coverage analysis: %s (%s)' % (set_name, covoar_result_dir))
     313        start_time = datetime.datetime.now()
    309314        executor = execute.execute(verbose = True, output = self.output_handler)
    310315        exit_code = executor.shell(command, cwd=os.getcwd())
    311         if (exit_code[0] != 0):
    312             raise error.general('covoar failure exit code: %d' % (exit_code[0]))
    313         log.notice('Coverage run for %s finished successfully.' % (set_name))
    314         log.notice('-----------------------------------------------')
     316        if exit_code[0] != 0:
     317            raise error.general('coverage: covoar failure:: %d' % (exit_code[0]))
     318        end_time = datetime.datetime.now()
     319        log.notice('Coverage time: %s' % (str(end_time - start_time)))
    315320
    316321    def output_handler(self, text):
    317         log.notice('%s' % (text))
     322        log.output('%s' % (text))
    318323
    319324class coverage_run(object):
     
    329334        self.explanations_txt = self.macros.expand(self.macros['cov_explanations'])
    330335        self.test_dir = path.join(self.build_dir, self.macros['bsp'] + '-coverage')
    331         if (not path.exists(self.test_dir)):
     336        if not path.exists(self.test_dir):
    332337            path.mkdir(self.test_dir)
    333338        self.rtdir = path.abspath(self.macros['_rtdir'])
     
    364369
    365370    def _generate_reports(self):
    366         log.notice('Generating reports')
     371        log.notice('Coverage generating reports')
    367372        if self.report_format == 'html':
    368373            report = report_gen_html(self.symbol_sets,
     
    375380    def _cleanup(self):
    376381        if not self.no_clean:
    377             log.notice('***Cleaning tempfiles***')
     382            log.output('Coverage cleaning tempfiles')
    378383            for exe in self.executables:
    379384                trace_file = exe + '.cov'
     
    383388
    384389    def _summarize(self):
    385         log.notice('Coverage analysis finished. You can find results in %s' % (self.build_dir))
     390        log.notice('Coverage analysis finished: %s' % (self.build_dir))
Note: See TracChangeset for help on using the changeset viewer.