93 lines
3.7 KiB
Python
93 lines
3.7 KiB
Python
# Copyright 2024 Volvo Car Corporation
|
|
# Licensed under Apache 2.0.
|
|
|
|
"""Unit test script for ExtDbg class."""
|
|
|
|
import unittest
|
|
from unittest.mock import MagicMock
|
|
from pathlib import Path
|
|
from powertrain_build.ext_dbg import ExtDbg
|
|
from powertrain_build.build_proj_config import BuildProjConfig
|
|
from .io_cnfg import DBG_CNFG_DICT
|
|
|
|
SRC_DIR = Path(__file__).parent
|
|
|
|
|
|
class TestExtDbg(unittest.TestCase):
|
|
"""Test case for testing the ExtDbg class."""
|
|
|
|
def setUp(self):
|
|
"""Set-up common data structures for all tests in the test case."""
|
|
self.build_cfg = MagicMock(spec_set=BuildProjConfig)
|
|
self.build_cfg.get_ecu_info = MagicMock(return_value=('Denso', 'G2'))
|
|
self.unit_cfg = MagicMock()
|
|
self.unit_cfg.base_types_headers = '#include "tl_base_types.h"\n'
|
|
|
|
self.ext_dbg = ExtDbg(DBG_CNFG_DICT['VED4_GENIII'], self.build_cfg, self.unit_cfg)
|
|
|
|
prj_out_dir = Path(SRC_DIR, 'output')
|
|
self.file_path_inputs = Path(prj_out_dir, 'VcDebug')
|
|
self.file_path_outputs = Path(prj_out_dir, 'VcDebugOutput')
|
|
self.generated_debug_files = [
|
|
self.file_path_inputs.with_suffix('.c'),
|
|
self.file_path_inputs.with_suffix('.a2l'),
|
|
self.file_path_outputs.with_suffix('.c'),
|
|
self.file_path_outputs.with_suffix('.a2l')
|
|
]
|
|
for file_path in self.generated_debug_files:
|
|
if file_path.exists():
|
|
file_path.unlink()
|
|
|
|
def test_restruct_data(self):
|
|
"""Check restructuring of variable dict."""
|
|
expected = {
|
|
'inputs': {
|
|
'1': {
|
|
'sVcAc_D_EngRunReqClim': {
|
|
'IOType': 'd',
|
|
'description': 'Engine running request (inhibit stop) from climate',
|
|
'element_index': 5,
|
|
'init': 0,
|
|
'max': 3,
|
|
'min': 0,
|
|
'type': 'UInt8',
|
|
'unit': '-'
|
|
}
|
|
}
|
|
},
|
|
'outputs': {
|
|
'1': {
|
|
'sVcAc_D_AirCondCmpsrStats': {
|
|
'IOType': 'd',
|
|
'description': 'Aircond compressor status',
|
|
'element_index': 5,
|
|
'init': 0,
|
|
'max': 7,
|
|
'min': 0,
|
|
'type': 'UInt8',
|
|
'unit': '-'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
self.assertDictEqual(self.ext_dbg.dbg_dict, expected)
|
|
|
|
def test_gen_dbg_files(self):
|
|
"""Check generation of debug files."""
|
|
self.ext_dbg.gen_dbg_files(self.file_path_inputs.as_posix(), self.file_path_outputs.as_posix())
|
|
|
|
for file_path in self.generated_debug_files:
|
|
self.assertTrue(file_path.exists(), f'File {file_path} was not created.')
|
|
with file_path.open(mode='r', encoding='utf-8') as file_handle:
|
|
result = file_handle.read()
|
|
with Path(SRC_DIR, 'reference_files', file_path.name).open(mode='r', encoding='utf-8') as file_handle:
|
|
expected = file_handle.read()
|
|
self.assertEqual(result, expected, f'Content of {file_path} does not match expected content.')
|
|
|
|
def test_gen_dbg_files_no_debug_variables(self):
|
|
"""Check generation of debug files, without any debug variables."""
|
|
self.ext_dbg.dbg_dict = {'inputs': {}, 'outputs': {}}
|
|
self.ext_dbg.gen_dbg_files(self.file_path_inputs.as_posix(), self.file_path_outputs.as_posix())
|
|
for file_path in self.generated_debug_files:
|
|
self.assertFalse(file_path.exists(), f'File {file_path} was created.')
|