# Copyright 2024 Volvo Car Corporation # Licensed under Apache 2.0. """Module containing classes for generation of signal consistency check report.""" from powertrain_build.signal_incons_html_rep_base import SigConsHtmlReportBase class SigConsHtmlReport(SigConsHtmlReportBase): """Generate html report from the signal consistency check result. (see :doc:`signal_interfaces`) Inherits :doc:`SigConsHtmlReportBase `. """ __intro = """

Table of contents

  1. Introduction
  2. Detailed unit information
  3. External signals
    1. Missing external signals
    2. Unused external signals
  4. Unit index

Introduction

This documents lists inconsistencies in the internal and external signal configuration.

""" def __init__(self, res_dict=None): """Initialize class instance. Args: res_dict (dict): result dict from the signal interface consistency check The dict shall have the following format:: { "sigs": { "ext": {"missing": {}, "unused": {}, "inconsistent_defs": {}}, "int": {"UNIT_NAME": {"missing": {}, "unused": {}, "multiple_defs": {} "inconsistent_defs": {}} } } """ super().__init__(res_dict) self.set_res_dict(res_dict) def _gen_unit_toc(self): """Generate a unit TOC for the unit with signal inconsistencies. Hyperlinks to more in depth unit information. """ out = '

Unit index

\n' for unit in sorted(self._ext_units | self._int_units): out += f'
{unit}
\n' return out def _gen_units(self): """Generate all the information regarding all the units.""" out = '

Detailed Unit Information

\n' for unit in sorted(self._ext_units | self._int_units): out += self._gen_unit(unit) return out def _gen_unit(self, unit): """Generate the html-report for the unit specific information.""" out = f'

{unit}

\n' if unit in self._int_units: unit_data = self._res_dict['sigs']['int'][unit] out += self._gen_missing_sigs(unit_data) out += self._gen_unused_sigs(unit_data) out += self._gen_multiple_def_sigs(unit_data) out += self._gen_int_inconsistent_defs(unit_data) if unit in self._ext_units: out += self._gen_ext_inconsistent_defs(unit) return out def _gen_missing_sigs(self, unit_data, out=''): """Generate the unit specific information for missing signal in a unit.""" out = '

Missing signals

\n' \ '

Inports whose signals are not generated in the ' \ 'listed configuration(s).

' return super()._gen_missing_sigs(unit_data, out) def _gen_unused_sigs(self, unit_data, out=''): """Generate the unit specific information for the unused signals wihtin a unit.""" out = '

Unused signals

\n' \ '

Outports that are generated, but not used in the ' \ 'listed configuration(s).

' return super()._gen_unused_sigs(unit_data, out) def _gen_multiple_def_sigs(self, unit_data, out=''): """Generate unit specific information for the signals that are generated more than once.""" out = '

Multiple defined signals

\n' \ '

Outports that are generated more than once in ' \ 'the listed configuration(s).

' return super()._gen_multiple_def_sigs(unit_data, out) def _gen_ext_inconsistent_defs(self, unit, out=''): """Generate a report of inconsistent variable definition parameters. Report inconsistencies between the producing signal definition, and the signal definitions in the external interface definition. """ out = '

External signal inconsistencies

\n' \ '

In-/Out-ports that have different variable definitions ' \ 'than in the interface definition file.

' return super()._gen_ext_inconsistent_defs(unit, out) def _gen_int_inconsistent_defs(self, unit_data, out=''): """Generate a report of inconsistent variable definition parameters. Inconsistent for between the producing signal definition, and the consuming signal definitions for SPM internal signals. """ out = '

Internal signal inconsistencies

\n' \ '

Inports that have different variable definitions ' \ 'than the producing outport.

' return super()._gen_int_inconsistent_defs(unit_data, out) def _gen_ext_signals_report(self, type_, comment): """Generate report for external signals.""" out = f'

{type_.capitalize()} external signals

\n' out += f'

{comment}

' try: ext_data = self._res_dict['sigs']['ext'][type_] out += self._table_unused for var in sorted(ext_data.keys()): configs = ext_data[var] out += ' \n' out += f' {var}\n' out += f' {self._set_to_str(configs)}\n' out += ' \n' out += ' \n' out += ' \n' except KeyError: pass return out def set_res_dict(self, res_dict): """Set the result dictionary used to generate the html-report. Args: res_dict (dict): result dict from the signal interface consistency check See class constructor for dict structure. """ self._res_dict = res_dict self._ext_units = set() self._int_units = set() if res_dict is not None and 'sigs' in res_dict: if 'ext' in res_dict['sigs'] and 'inconsistent_defs' in res_dict['sigs']['ext']: self._ext_units = set(self._res_dict['sigs']['ext']['inconsistent_defs'].keys()) if 'int' in res_dict['sigs']: self._int_units = set(self._res_dict['sigs']['int'].keys()) def gen_contents(self): """Generate report contents from the signal inconsistency check result dictionary. Overrides HtmlReport.gen_contents() """ html = [] html += self.__intro html += self._gen_units() html += '

Signals missing and unused in the ' \ 'interface definition

\n' html += self._gen_ext_signals_report('missing', 'Signals not generated by ' 'Vcc SW, but are defined in ' 'the Interface definition to be ' 'generated') html += self._gen_ext_signals_report('unused', 'Signals defined to be generated by ' 'supplier SW, but are not used ' 'by VCC SW') html += self._gen_unit_toc() return ''.join(html)